' . __( 'Go Pro', 'better-wp-security' ) . '', $capability, 'itsec-go-pro', array( $this, 'show_page' ) ); } if ( defined( 'ITSEC_DEBUG' ) && ITSEC_DEBUG ) { $page_refs[] = add_submenu_page( 'itsec', __( 'iThemes Security Debug', 'better-wp-security' ), __( 'Debug' ), $capability, 'itsec-debug', array( $this, 'show_page' ) ); } foreach ( $page_refs as $page_ref ) { add_action( "load-$page_ref", array( $this, 'load' ) ); } } private function get_page_id() { global $plugin_page; if ( isset( $this->page_id ) ) { return $this->page_id; } if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { if ( isset( $_REQUEST['action'] ) && preg_match( '/^itsec_(.+)_page$/', $_REQUEST['action'], $match ) ) { $this->page_id = $match[1]; } } else if ( 'itsec-' === substr( $plugin_page, 0, 6 ) ) { $this->page_id = substr( $plugin_page, 6 ); } else if ( 'itsec' === substr( $plugin_page, 0, 5 ) ) { $this->page_id = 'settings'; } if ( ! isset( $this->page_id ) ) { $this->page_id = ''; } return $this->page_id; } public function load() { add_action( 'admin_print_scripts', array( $this, 'add_scripts' ) ); add_action( 'admin_print_styles', array( $this, 'add_styles' ) ); $this->load_file( 'page-%s.php' ); } public function show_page() { $page_id = $this->get_page_id(); if ( 'settings' === $page_id ) { $url = network_admin_url( 'admin.php?page=itsec' ); } else { $url = network_admin_url( 'admin.php?page=itsec-' . $this->get_page_id() ); } do_action( 'itsec-page-show', $url ); } public function handle_ajax_request() { $this->load_file( 'page-%s.php' ); do_action( 'itsec-page-ajax' ); } private function load_file( $file ) { $id = $this->get_page_id(); if ( empty( $id ) ) { if ( isset( $GLOBALS['pagenow'] ) && 'admin.php' === $GLOBALS['pagenow'] && isset( $_GET['page'] ) && 'itsec-' === substr( $_GET['page'], 0, 6 ) ) { $id = substr( $_GET['page'], 6 ); } else { return; } } $id = str_replace( '_', '-', $id ); $file = dirname( __FILE__ ) . '/' . sprintf( $file, $id ); $file = apply_filters( "itsec-admin-page-file-path-$id", $file ); if ( is_file( $file ) ) { require_once( $file ); } } public function handle_user_setting() { $whitelist_settings = array( 'itsec-settings-view' ); if ( in_array( $_REQUEST['setting'], $whitelist_settings ) ) { $_REQUEST['setting'] = sanitize_title_with_dashes( $_REQUEST['setting'] ); // Verify nonce is valid and for this setting, and allow a filter to if ( wp_verify_nonce( $_REQUEST['itsec-user-setting-nonce'], 'set-user-setting-' . $_REQUEST['setting'] ) && apply_filters( 'itsec-user-setting-valid-' . $_REQUEST['setting'], true, $_REQUEST['value'] ) ) { if ( false !== update_user_meta( get_current_user_id(), $_REQUEST['setting'], $_REQUEST['value'] ) ) { wp_send_json_success(); } } } wp_send_json_error(); } public function validate_view( $valid, $view ) { return in_array( $view, array( 'grid', 'list' ) ); } } new ITSEC_Admin_Page_Loader();