Ejemplo n.º 1
0
 /**
  * Remove plugin's all admin menu items & pages, and replace with activation page.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.1
  */
 private function override_plugin_menu_with_activation()
 {
     $this->_logger->entrance();
     $hook = false;
     if ($this->_menu->is_top_level()) {
         $hook = $this->_menu->override_menu_item(array(&$this, '_connect_page_render'));
         if (false === $hook) {
             // Create new menu item just for the opt-in.
             $hook = add_menu_page($this->get_plugin_name(), $this->get_plugin_name(), 'manage_options', $this->_menu->get_slug(), array(&$this, '_connect_page_render'));
         }
     } else {
         $menus = array($this->_menu->get_parent_slug());
         if ($this->_menu->is_override_exact()) {
             // Make sure the current page is matching the activation page.
             $activation_url = strtolower($this->get_activation_url());
             $request_url = strtolower($_SERVER['REQUEST_URI']);
             if (parse_url($activation_url, PHP_URL_PATH) !== parse_url($request_url, PHP_URL_PATH)) {
                 // Different path - DO NOT OVERRIDE PAGE.
                 return;
             }
             $activation_url_params = array();
             parse_str(parse_url($activation_url, PHP_URL_QUERY), $activation_url_params);
             $request_url_params = array();
             parse_str(parse_url($request_url, PHP_URL_QUERY), $request_url_params);
             foreach ($activation_url_params as $key => $val) {
                 if (!isset($request_url_params[$key]) || $val != $request_url_params[$key]) {
                     // Not matching query string - DO NOT OVERRIDE PAGE.
                     return;
                 }
             }
         }
         foreach ($menus as $parent_slug) {
             $hook = $this->_menu->override_submenu_action($parent_slug, $this->_menu->get_raw_slug(), array(&$this, '_connect_page_render'));
             if (false !== $hook) {
                 // Found plugin's submenu item.
                 break;
             }
         }
     }
     if ($this->_menu->is_activation_page()) {
         // Clean admin page from distracting content.
         self::_clean_admin_content_section();
     }
     if (false !== $hook) {
         if (fs_request_is_action($this->_slug . '_activate_existing')) {
             add_action("load-{$hook}", array(&$this, '_install_with_current_user'));
         } else {
             if (fs_request_is_action($this->_slug . '_activate_new')) {
                 add_action("load-{$hook}", array(&$this, '_install_with_new_user'));
             }
         }
     }
 }