AdminMenu.php
11 years ago
AdminSubmenu.php
11 years ago
AdminSubmenuDefault.php
11 years ago
AdminSubmenuExpander.php
11 years ago
EnabledMenus.php
11 years ago
AdminSubmenuExpander.php
101 lines
| 1 | <?php namespace NestedPages\Entities\AdminMenu; |
| 2 | |
| 3 | use NestedPages\Entities\PostType\PostTypeRepository; |
| 4 | |
| 5 | /** |
| 6 | * Opens the Submenu on child admin pages and highlights the current item |
| 7 | */ |
| 8 | class AdminSubmenuExpander { |
| 9 | |
| 10 | /** |
| 11 | * Current Page Object |
| 12 | */ |
| 13 | private $page; |
| 14 | |
| 15 | /** |
| 16 | * Post Type Repository |
| 17 | */ |
| 18 | private $post_type_repo; |
| 19 | |
| 20 | |
| 21 | public function __construct() |
| 22 | { |
| 23 | $this->post_type_repo = new PostTypeRepository; |
| 24 | $this->page = get_current_screen(); |
| 25 | $this->addHighlighting(); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * Add Highlighting to enabled Post Types who's menus are being overwritten |
| 31 | */ |
| 32 | private function addHighlighting() |
| 33 | { |
| 34 | foreach($this->post_type_repo->getPostTypesObject() as $type){ |
| 35 | if ( $type->replace_menu ){ |
| 36 | $this->newPage($type); |
| 37 | $this->nestedPagesAll($type); |
| 38 | $this->topLevelPostType($type); |
| 39 | $this->defaultLink($type); |
| 40 | $this->defaultPagesLink($type); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * New Page Screen |
| 48 | */ |
| 49 | private function newPage($type) |
| 50 | { |
| 51 | $name = ( $type->name == 'page' ) ? '' : '-' . $type->name; |
| 52 | if ( ($this->page->id == $type->name) && ($this->page->action == 'add') ){ |
| 53 | echo '<script>jQuery(document).ready(function(){jQuery("#toplevel_page_nestedpages' . $name . '").removeClass("wp-not-current-submenu").addClass("wp-has-current-submenu").addClass("wp-menu-open");jQuery("#toplevel_page_nestedpages' . $name . ' a:first").addClass("wp-has-current-submenu");var addnew = jQuery("#toplevel_page_nestedpages ul li:nth-child(3)");jQuery(addnew).addClass("current");jQuery(addnew).children("a").addClass("current");});</script>'; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * Nested Pages View |
| 60 | */ |
| 61 | private function nestedPagesAll($type) |
| 62 | { |
| 63 | if ( $this->page->id == 'toplevel_page_nestedpages' ){ |
| 64 | echo '<script>jQuery(document).ready(function(){jQuery("#toplevel_page_nestedpages").removeClass("wp-not-current-submenu").addClass("wp-has-current-submenu").addClass("wp-menu-open");jQuery("#toplevel_page_nestedpages a:first").addClass("wp-has-current-submenu");var addnew = jQuery("#toplevel_page_nestedpages ul li:nth-child(2)");jQuery(addnew).addClass("current");jQuery(addnew).children("a").addClass("current");});</script>'; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * Top Level Page for Post Type |
| 71 | */ |
| 72 | private function topLevelPostType($type) |
| 73 | { |
| 74 | if ( $this->page->id == 'toplevel_page_nestedpages-' . $type->name ){ |
| 75 | echo '<script>jQuery(document).ready(function(){jQuery("#toplevel_page_nestedpages-' . $type->name . '").removeClass("wp-not-current-submenu").addClass("wp-has-current-submenu").addClass("wp-menu-open");jQuery("#toplevel_page_nestedpages-' . $type->name . ' a:first").addClass("wp-has-current-submenu");var addnew = jQuery("#toplevel_page_nestedpages-' . $type->name . ' ul li:nth-child(2)");jQuery(addnew).addClass("current");jQuery(addnew).children("a").addClass("current");});</script>'; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * Default Link |
| 82 | */ |
| 83 | private function defaultLink($type) |
| 84 | { |
| 85 | if ( $this->page->id == 'edit-' . $type->name ){ |
| 86 | echo '<script>jQuery(document).ready(function(){jQuery("#toplevel_page_nestedpages-' . $type->name . '").removeClass("wp-not-current-submenu").addClass("wp-has-current-submenu").addClass("wp-menu-open");jQuery("#toplevel_page_nestedpages-' . $type->name . ' a:first").addClass("wp-has-current-submenu");});</script>'; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /** |
| 92 | * Default Pages Link |
| 93 | */ |
| 94 | private function defaultPagesLink($type) |
| 95 | { |
| 96 | if ( $this->page->id == 'edit-page' ){ |
| 97 | echo '<script>jQuery(document).ready(function(){jQuery("#toplevel_page_nestedpages").removeClass("wp-not-current-submenu").addClass("wp-has-current-submenu").addClass("wp-menu-open");jQuery("#toplevel_page_nestedpages a:first").addClass("wp-has-current-submenu");});</script>'; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | } |