/** * @since 1.4 * @return object */ public static function instance($plugin) { if (!self::$instance) { self::$instance = new self($plugin); } return self::$instance; }
/** * * * @since 1.4 */ public function adminInit() { global $pagenow; add_action('admin_menu', array($this->adminDelegate, 'add_menu')); switch ($pagenow) { case 'post.php': case 'post-new.php': include $this->dirPath . '/admin/sitetree-metabox.class.php'; include $this->dirPath . '/admin/sitetree-field-view.class.php'; $metaBoxController = new SiteTreeMetaBoxController($this); add_action('add_meta_boxes', array($metaBoxController, 'register_meta_box')); add_action('edit_attachment', array($this->adminDelegate, 'catch_attachment_event'), 100); add_action('delete_attachment', array($this->adminDelegate, 'catch_attachment_event'), 100); // A priority higher then 20 sometimes causes 'process_metadata' to be discarded // when the POST action is sent from 'post-new.php' add_action('save_post', array($metaBoxController, 'process_metadata'), 20, 2); // Break omitted to force the actions below to be included also when in 'post.php' and 'post-new.php' // Break omitted to force the actions below to be included also when in 'post.php' and 'post-new.php' case 'edit.php': add_action('trashed_post', array($this->adminDelegate, 'catch_post_trash_event'), 100); add_action('untrashed_post', array($this->adminDelegate, 'catch_post_trash_event'), 100); add_action('after_delete_post', array($this->adminDelegate, 'catch_post_delete_event'), 100); break; case 'plugins.php': add_filter('plugin_action_links_' . $this->basename, array($this->adminDelegate, 'addActionLinks')); register_deactivation_hook($this->file, array($this, 'cleanUp')); break; case 'edit-tags.php': case 'admin-ajax.php': if (!isset($_REQUEST['taxonomy'])) { break; } $taxonomy = $_REQUEST['taxonomy']; if ($taxonomy == 'category' || $taxonomy == 'post_tag') { add_action('edit_' . $taxonomy, array($this->adminDelegate, 'catch_' . $taxonomy . '_event'), 100); add_action('create_' . $taxonomy, array($this->adminDelegate, 'catch_' . $taxonomy . '_event'), 100); add_action('delete_' . $taxonomy, array($this->adminDelegate, 'catch_' . $taxonomy . '_event'), 100); } break; case 'admin.php': include $this->dirPath . '/admin/sitetree-field-view.class.php'; include $this->dirPath . '/admin/sitetree-page-view.class.php'; include $this->dirPath . '/admin/page-view-delegate-protocols.php'; include $this->dirPath . '/admin/sitetree-page-view-controller.class.php'; if ($_POST && isset($_POST['option_page']) && $this->dataController->pageExists($_POST['option_page'])) { $tab = $input = null; if (!(current_user_can('manage_options') && isset($_POST['action']))) { wp_die(__('Cheatin’ uh?')); } if (is_multisite() && !is_super_admin()) { wp_die(__('Cheatin’ uh?')); } check_admin_referer('sitetree-options', '_sitetree_nonce'); if (isset($_POST['tab'])) { $tab = $_POST['tab']; if (!$this->dataController->tabExists($_POST['tab'], $_POST['option_page'])) { wp_die(__('Request sent from an invalid tab.', 'sitetree')); } } if (isset($_POST['sitetree'])) { $input =& $_POST['sitetree']; if (!($_POST['sitetree'] && is_array($_POST['sitetree']))) { wp_die(__('No data to process.', 'sitetree')); } } SiteTreePageViewController::instance($this)->processAction($_POST['action'], $_POST['option_page'], $input, $tab); } if ($_GET && isset($_GET['page']) && ($page = $this->dataController->page($_GET['page']))) { $pageView = null; $pageViewController = SiteTreePageViewController::instance($this); if (isset($_GET['tab'])) { if (!$this->dataController->tabExists($_GET['tab'], $_GET['page'])) { wp_die(__("The requested tab doesn't exists.", 'sitetree')); } $pageViewController->setActiveTab($_GET['tab']); } elseif (isset($_GET['action'])) { if (!(isset($_GET['_sitetree_nonce']) && wp_verify_nonce($_GET['_sitetree_nonce'], $_GET['action']))) { wp_die(__('Cheatin’ uh?')); } $pageViewController->processAction($_GET['action'], $_GET['page']); } elseif (isset($_GET['edit']) && $_GET['edit'] == 'config') { $pageViewController->enableConfigMode(); } if (isset($_GET['rebuilt']) || isset($_GET['settings-updated'])) { $pageViewController->setupErrorMessage(); } if (class_exists($page->class)) { $pageView = new $page->class($page); $pageView->setDelegate($pageViewController); } $this->adminDelegate->init($pageView, $_GET['page']); } break; case 'user-new.php': add_action('user_register', array($this->adminDelegate, 'catch_authors_event'), 100); break; case 'user-edit.php': case 'profile.php': add_action('profile_update', array($this->adminDelegate, 'catch_authors_event'), 100); break; case 'users.php': add_action('delete_user', array($this->adminDelegate, 'catch_authors_event'), 100); break; } }