Admin Menu Tree Page View - Version 2.3

Version Description

  • Fixed: major speedup, like 300 % faster generation of the tree
  • Fixed: added is_admin()-check to the plugin, the plugin code is only parsed when in the administration panel. This could make the public part of your site some milliseconds faster.
Download this release

Release Info

Developer eskapism
Plugin Icon wp plugin Admin Menu Tree Page View
Version 2.3
Comparing to
See all releases

Code changes from version 2.2 to 2.3

Files changed (4) hide show
  1. css/styles.css +5 -0
  2. index.php +71 -12
  3. js/scripts.js +17 -0
  4. readme.txt +6 -2
css/styles.css CHANGED
@@ -109,6 +109,7 @@ border-bottom: 1px solid #ccc;
109
  }
110
 
111
 
 
112
  li.admin-menu-tree-page-tree_headline,
113
  li.admin-menu-tree-page-filter
114
  {
@@ -122,6 +123,10 @@ li.admin-menu-tree-page-filter
122
  border-right-style: solid;
123
  border-right-width: 0px;
124
  }
 
 
 
 
125
 
126
  .wp-has-current-submenu li.admin-menu-tree-page-tree_headline,
127
  .wp-has-current-submenu li.admin-menu-tree-page-filter
109
  }
110
 
111
 
112
+ span.admin-menu-tree-page-tree_headline,
113
  li.admin-menu-tree-page-tree_headline,
114
  li.admin-menu-tree-page-filter
115
  {
123
  border-right-style: solid;
124
  border-right-width: 0px;
125
  }
126
+ span.admin-menu-tree-page-tree_headline {
127
+ position: relative;
128
+ left: -12px;
129
+ }
130
 
131
  .wp-has-current-submenu li.admin-menu-tree-page-tree_headline,
132
  .wp-has-current-submenu li.admin-menu-tree-page-filter
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Admin Menu Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/admin-menu-tree-page-view/
5
  Description: Get a tree view of all your pages directly in the admin menu. Search, edit, view and add pages - all with just one click away!
6
- Version: 2.2
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
@@ -25,6 +25,11 @@ License: GPL2
25
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
  */
27
 
 
 
 
 
 
28
  add_action("admin_head", "admin_menu_tree_page_view_admin_head");
29
  add_action('admin_menu', 'admin_menu_tree_page_view_admin_menu');
30
  add_action("admin_init", "admin_menu_tree_page_view_admin_init");
@@ -33,7 +38,7 @@ add_action('wp_ajax_admin_menu_tree_page_view_move_page', 'admin_menu_tree_page_
33
 
34
  function admin_menu_tree_page_view_admin_init() {
35
 
36
- define( "admin_menu_tree_page_view_VERSION", "2.2" );
37
  define( "admin_menu_tree_page_view_URL", WP_PLUGIN_URL . '/admin-menu-tree-page-view/' );
38
  define( "admin_menu_tree_page_view_DIR", WP_PLUGIN_DIR . '/admin-menu-tree-page-view/' );
39
 
@@ -59,6 +64,40 @@ function admin_menu_tree_page_view_admin_head() {
59
 
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  function admin_menu_tree_page_view_get_pages($args) {
63
 
64
  $defaults = array(
@@ -73,6 +112,9 @@ function admin_menu_tree_page_view_get_pages($args) {
73
  );
74
  $args = wp_parse_args( $args, $defaults );
75
 
 
 
 
76
  $pages = get_posts($args);
77
  $output = "";
78
  $str_child_output = "";
@@ -82,14 +124,21 @@ function admin_menu_tree_page_view_get_pages($args) {
82
  $title = esc_html($title);
83
 
84
  // add num of children to the title
85
- $post_children = get_children(array(
86
- "post_parent" => $one_page->ID,
87
- "post_type" => "page"
88
- ));
89
- $post_children_count = sizeof($post_children);
90
- // var_dump($post_children_count);
91
- if ($post_children_count>0) {
 
 
 
 
 
92
  $title .= " <span class='child-count'>($post_children_count)</span>";
 
 
93
  }
94
 
95
  $class = "";
@@ -109,8 +158,13 @@ function admin_menu_tree_page_view_get_pages($args) {
109
  $args_childs["parent"] = $one_page->ID;
110
  $args_childs["post_parent"] = $one_page->ID;
111
  $args_childs["child_of"] = $one_page->ID;
112
- $str_child_output = admin_menu_tree_page_view_get_pages($args_childs);
 
 
 
 
113
  if ($post_children_count>0) {
 
114
  $class .= " admin-menu-tree-page-view-has-childs";
115
  }
116
 
@@ -127,8 +181,12 @@ function admin_menu_tree_page_view_get_pages($args) {
127
  if ($_GET["post"] != $one_page->ID) {
128
  $post_to_check_parents_for = $_GET["post"];
129
  // seems to be a problem with get_post_ancestors (yes, it's in the trac too)
130
- wp_cache_delete($post_to_check_parents_for, 'posts');
131
- $one_page_parents = get_post_ancestors($post_to_check_parents_for);
 
 
 
 
132
  if (in_array($one_page->ID, $one_page_parents)) {
133
  $isOpened = TRUE;
134
  }
@@ -207,6 +265,7 @@ function admin_menu_tree_page_view_admin_menu() {
207
  #add_menu_page( "title", "Simple Menu Pages", "edit_pages", "admin-menu-tree-page-tree_main", "bonnyFunction", null, 5);
208
 
209
  // end link that is written automatically by WP, and begin ul
 
210
  $output = "
211
  </a>
212
  <ul class='admin-menu-tree-page-tree'>
3
  Plugin Name: Admin Menu Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/admin-menu-tree-page-view/
5
  Description: Get a tree view of all your pages directly in the admin menu. Search, edit, view and add pages - all with just one click away!
6
+ Version: 2.3
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
25
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
  */
27
 
28
+ // No need to run all code if we're not on an admin page
29
+ if (!is_admin()) {
30
+ return;
31
+ }
32
+
33
  add_action("admin_head", "admin_menu_tree_page_view_admin_head");
34
  add_action('admin_menu', 'admin_menu_tree_page_view_admin_menu');
35
  add_action("admin_init", "admin_menu_tree_page_view_admin_init");
38
 
39
  function admin_menu_tree_page_view_admin_init() {
40
 
41
+ define( "admin_menu_tree_page_view_VERSION", "2.3" );
42
  define( "admin_menu_tree_page_view_URL", WP_PLUGIN_URL . '/admin-menu-tree-page-view/' );
43
  define( "admin_menu_tree_page_view_DIR", WP_PLUGIN_DIR . '/admin-menu-tree-page-view/' );
44
 
64
 
65
  }
66
 
67
+ /**
68
+ * I know, I know. Should have made a class from the beginning...
69
+ */
70
+ class admin_menu_tree_page_view {
71
+
72
+ public static $arr_all_pages_id_parent;
73
+ public static $one_page_parents;
74
+
75
+ static function get_all_pages_id_parent() {
76
+ if (!isset(admin_menu_tree_page_view::$arr_all_pages_id_parent)) {
77
+ // get all pages, once, to spare some queries looking for children
78
+ $all_pages = get_posts(array(
79
+ "numberposts" => -1,
80
+ "post_type" => "page",
81
+ "post_status" => "any",
82
+ "fields" => "id=>parent"
83
+ ));
84
+ //print_r($all_pages);exit;
85
+ admin_menu_tree_page_view::$arr_all_pages_id_parent = $all_pages;
86
+ }
87
+ return admin_menu_tree_page_view::$arr_all_pages_id_parent;
88
+ }
89
+
90
+ static function get_post_ancestors($post_to_check_parents_for) {
91
+ if (!isset(admin_menu_tree_page_view::$one_page_parents)) {
92
+ wp_cache_delete($post_to_check_parents_for, 'posts');
93
+ $one_page_parents = get_post_ancestors($post_to_check_parents_for);
94
+ admin_menu_tree_page_view::$one_page_parents = $one_page_parents;
95
+ }
96
+ return admin_menu_tree_page_view::$one_page_parents;
97
+ }
98
+
99
+ }
100
+
101
  function admin_menu_tree_page_view_get_pages($args) {
102
 
103
  $defaults = array(
112
  );
113
  $args = wp_parse_args( $args, $defaults );
114
 
115
+ // contains all page ids as keys and their parent as the val
116
+ $arr_all_pages_id_parent = admin_menu_tree_page_view::get_all_pages_id_parent();
117
+
118
  $pages = get_posts($args);
119
  $output = "";
120
  $str_child_output = "";
124
  $title = esc_html($title);
125
 
126
  // add num of children to the title
127
+ // @done: this is still being done for each page, even if it does not have children. can we check if it has before?
128
+ // we could fetch all pages once and store them in an array and then just check if the array has our id in it. yeah. let's do that.
129
+ // if our page id exists in $arr_all_pages_id_parent and has a value
130
+ // so result is from 690 queries > 474 = 216 queries less. still many..
131
+ // from 474 to 259 = 215 less
132
+ // so total from 690 to 259 = 431 queries less! grrroooovy
133
+ if (in_array($one_page->ID, $arr_all_pages_id_parent)) {
134
+ $post_children = get_children(array(
135
+ "post_parent" => $one_page->ID,
136
+ "post_type" => "page"
137
+ ));
138
+ $post_children_count = sizeof($post_children);
139
  $title .= " <span class='child-count'>($post_children_count)</span>";
140
+ } else {
141
+ $post_children_count = 0;
142
  }
143
 
144
  $class = "";
158
  $args_childs["parent"] = $one_page->ID;
159
  $args_childs["post_parent"] = $one_page->ID;
160
  $args_childs["child_of"] = $one_page->ID;
161
+
162
+ // can we run this only if the page actually has children? is there a property in the result of get_children for this?
163
+ // eh, you moron, we already got that info in $post_children_count!
164
+ // so result is from 690 queries > 474 = 216 queries less. still many..
165
+ $str_child_output = "";
166
  if ($post_children_count>0) {
167
+ $str_child_output = admin_menu_tree_page_view_get_pages($args_childs);
168
  $class .= " admin-menu-tree-page-view-has-childs";
169
  }
170
 
181
  if ($_GET["post"] != $one_page->ID) {
182
  $post_to_check_parents_for = $_GET["post"];
183
  // seems to be a problem with get_post_ancestors (yes, it's in the trac too)
184
+ // Long time since I wrote this, but perhaps this is the problem (adding for future reference):
185
+ // http://core.trac.wordpress.org/ticket/10381
186
+
187
+ // @done: this is done several times. only do it once please
188
+ // before: 441. after: 43
189
+ $one_page_parents = admin_menu_tree_page_view::get_post_ancestors($post_to_check_parents_for);
190
  if (in_array($one_page->ID, $one_page_parents)) {
191
  $isOpened = TRUE;
192
  }
265
  #add_menu_page( "title", "Simple Menu Pages", "edit_pages", "admin-menu-tree-page-tree_main", "bonnyFunction", null, 5);
266
 
267
  // end link that is written automatically by WP, and begin ul
268
+ // <!-- <span class='admin-menu-tree-page-tree_headline'>" . __("Pages", 'admin-menu-tree-page-view') . "</span> -->
269
  $output = "
270
  </a>
271
  <ul class='admin-menu-tree-page-tree'>
js/scripts.js CHANGED
@@ -410,6 +410,23 @@ jQuery(function($) {
410
  }
411
  });
412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
 
414
  });
415
 
410
  }
411
  });
412
 
413
+ // click "pages" headline to hide or show the tree
414
+ // @todo: remember state in a cookie, to be read by PHP
415
+ // @todo: also add arrow or something that shows state
416
+ $(".admin-menu-tree-page-tree_headline").live("click", function() {
417
+ var t = $(this);
418
+ var ul = t.closest("ul");
419
+ var lis = ul.find("li").not(".admin-menu-tree-page-tree_headline"); // also consider .admin-menu-tree-page-filter
420
+ if (ul.hasClass("admin-menu-tree-page-view-closed")) {
421
+ // it's closed, so open it
422
+ ul.addClass("admin-menu-tree-page-view-opened").removeClass("admin-menu-tree-page-view-closed");
423
+ lis.show();
424
+ } else {
425
+ // it's opened, so close it
426
+ ul.removeClass("admin-menu-tree-page-view-opened").addClass("admin-menu-tree-page-view-closed");
427
+ lis.hide();
428
+ }
429
+ });
430
 
431
  });
432
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: eskapism, MarsApril
3
  Donate link: http://eskapism.se/sida/donate/
4
  Tags: admin, page, pages, tree, view, admin menu, menu
5
  Requires at least: 3.0
6
- Tested up to: 3.2.1
7
- Stable tag: 2.2
8
 
9
  Get a tree view of all your pages directly in the admin menu. Search, edit, view, re-order/sort and add pages - all with just one click away!
10
 
@@ -42,6 +42,10 @@ Now the tree with the pages will be visible in the admin menu to the left.
42
 
43
  == Changelog ==
44
 
 
 
 
 
45
  = 2.2 =
46
  - Fixed: icons where misplaced when using minimized admin menu.
47
  - Fixed: page actions where not visible when using minimized admin menu.
3
  Donate link: http://eskapism.se/sida/donate/
4
  Tags: admin, page, pages, tree, view, admin menu, menu
5
  Requires at least: 3.0
6
+ Tested up to: 3.3
7
+ Stable tag: 2.3
8
 
9
  Get a tree view of all your pages directly in the admin menu. Search, edit, view, re-order/sort and add pages - all with just one click away!
10
 
42
 
43
  == Changelog ==
44
 
45
+ = 2.3 =
46
+ - Fixed: major speedup, like 300 % faster generation of the tree
47
+ - Fixed: added is_admin()-check to the plugin, the plugin code is only parsed when in the administration panel. This could make the public part of your site some milliseconds faster.
48
+
49
  = 2.2 =
50
  - Fixed: icons where misplaced when using minimized admin menu.
51
  - Fixed: page actions where not visible when using minimized admin menu.