configure(); $this->id = empty($this->id) ? str_replace('adminpage', '', strtolower( get_class($this) ) ) : $this->id; } /** * May be used to configure the page before uts usage. */ public function configure(){} /** * Includes the Factory Bootstrap assets for a current page. * * @param string $hook * @return void */ public function actionAdminBootstrapScripts( $hook ) { $this->scripts->connect('bootstrap'); $this->styles->connect('bootstrap'); } /** * Includes the assets for a current page (all assets except Factory Bootstrap assets). * * @param string $hook * @return void */ public function actionAdminScripts( $hook ) { $this->scripts->connect(); $this->styles->connect(); } public function getResultId() { if ( $this->plugin ) return $this->id . '-' . $this->plugin->pluginName; return $this->id; } /** * Registers admin page for the admin menu. */ public function connect() { $resultId = $this->getResultId(); $this->hidden = apply_filters('factory_page_is_hidden_' . $resultId, $this->hidden); if ( $this->hidden ) return; $this->internal = apply_filters('factory_page_is_internal_' . $resultId, $this->internal); if ( $this->internal ) { $this->menuTarget = null; $this->menuPostType = null; } // makes redirect to the page $controller = isset( $_GET['fy_page'] ) ? $_GET['fy_page'] : null; if ( $controller && $controller == $this->id ) { $plugin = isset( $_GET['fy_plugin'] ) ? $_GET['fy_plugin'] : null; if ( $this->plugin->pluginName == $plugin ) { $action = isset( $_GET['fy_action'] ) ? $_GET['fy_action'] : 'index'; $isAjax = isset( $_GET['fy_ajax'] ); if ( $isAjax ) { $this->executeByName( $action ); exit; } else { $params = array(); foreach ($_GET as $key => $value) { $params[$key] = $value; } unset($params['fy_page']); unset($params['fy_plugin']); unset($params['fy_action']); $this->redirectToAction($action, $params); } } } // executes an action if ( $this->current() ) { ob_start(); $action = isset( $_GET['action'] ) ? $_GET['action'] : 'index'; $this->executeByName( $action ); $this->result = ob_get_contents(); ob_end_clean(); } // calls scripts and styles, adds pages to menu if ( isset($_GET['page']) && $_GET['page'] == $resultId ) { $this->assets($this->scripts, $this->styles); if ( !$this->scripts->isEmpty('bootstrap')|| !$this->styles->isEmpty('bootstrap') ) { add_action('factory_bootstrap_enqueue_scripts_' . $this->plugin->pluginName, array($this, 'actionAdminBootstrapScripts')); } // includes styles and scripts if ( !$this->scripts->isEmpty() || !$this->styles->isEmpty() ) { add_action('admin_enqueue_scripts', array($this, 'actionAdminScripts')); } } // if this page for a custom menu page if ( $this->menuPostType ) { $this->menuTarget = 'edit.php?post_type=' . $this->menuPostType; if ( empty( $this->capabilitiy ) ) { $this->capabilitiy = 'edit_' . $this->menuPostType; } } // sets default capabilities if ( empty( $this->capabilitiy ) ) { $this->capabilitiy = 'manage_options'; } $this->pageTitle = !$this->pageTitle ? $this->menuTitle : $this->pageTitle; $this->menuTitle = !$this->menuTitle ? $this->pageTitle : $this->menuTitle; $this->pageTitle = apply_filters( 'factory_page_title_' .$resultId , $this->pageTitle ) ; $this->menuTitle = apply_filters( 'factory_menu_title_' .$resultId , $this->menuTitle ) ; // submenu if ( $this->menuTarget ) { add_submenu_page( $this->menuTarget, $this->pageTitle, $this->menuTitle, $this->capabilitiy, $resultId, array($this, 'show') ); // global menu } else { add_menu_page( $this->pageTitle, $this->menuTitle, $this->capabilitiy, $resultId, array($this, 'show'), null, $this->menuPosition ); if ( !empty( $this->menuSubTitle ) ) { add_submenu_page( $resultId, $this->menuSubTitle, $this->menuSubTitle, $this->capabilitiy, $resultId, array($this, 'show') ); } add_action( 'admin_head', array($this, 'actionAdminHead')); } } protected function current() { if (!isset($_GET['page']) ) return false; $resultId = $this->getResultId(); if ( $resultId == $_GET['page'] ) return true; return false; } protected function redirectToAction($action, $queryArgs = array()) { wp_redirect( $this->getActionUrl($action, $queryArgs) ); exit; } public function actionUrl($action = null, $queryArgs = array()) { echo $this->getActionUrl($action, $queryArgs); } public function getActionUrl($action = null, $queryArgs = array()) { $baseUrl = $this->getBaseUrl(); if ( !empty( $action )) $queryArgs['action'] = $action; $url = add_query_arg($queryArgs, $baseUrl); return $url; } protected function getBaseUrl() { $resultId = $this->getResultId(); if ( $this->menuTarget ) { if ( $this->customTarget ) return admin_url('admin.php') . '?page=' . $resultId; return $this->menuTarget . '&page=' . $resultId; } else { return 'admin.php?&page=' . $resultId; } } public function actionAdminHead() { $resultId = $this->getResultId(); if (!empty($this->menuIcon)) { if(preg_match('/\\\f\d{3}/', $this->menuIcon)) { $iconCode = $this->menuIcon; } else { $iconUrl = str_replace('~/', $this->plugin->pluginUrl . '/', $this->menuIcon); } } global $wp_version; if ( version_compare( $wp_version, '3.7.3', '>' ) ) { ?> internal) { ?>