CMS Tree Page View - Version 1.2.23

Version Description

  • Now only users with permission may move pages and custom posts and publish new posts. By default administrator and editors have these rights. Is checked using capability "move_cms_tree_view_page", so add that to any user you want to allow this for. Props mateuszdw, who made the very first pull request for this plugin! Thanks a lot!
Download this release

Release Info

Developer eskapism
Plugin Icon wp plugin CMS Tree Page View
Version 1.2.23
Comparing to
See all releases

Code changes from version 1.2.22 to 1.2.23

Files changed (4) hide show
  1. functions.php +87 -29
  2. index.php +4 -2
  3. readme.txt +4 -1
  4. scripts/cms_tree_page_view.js +1 -1
functions.php CHANGED
@@ -63,17 +63,17 @@ function cms_tpv_add_pages() {
63
  /*
64
  Array
65
  (
66
- [action] => cms_tpv_add_pages
67
- [cms_tpv_add_new_pages_names] => Array
68
- (
69
- [0] => xxxxx
70
- [1] => yyyy
71
- [2] =>
72
- )
73
-
74
- [cms_tpv_add_type] => inside
75
- [cms_tpv_add_status] => draft
76
- [lang] => de
77
  )
78
  */
79
 
@@ -219,7 +219,7 @@ function cms_tpv_add_pages() {
219
  $newpost_args = array(
220
  "menu_order" => $new_menu_order,
221
  "post_parent" => $post_parent_id,
222
- "post_status" => $post_status,
223
  "post_title" => $one_new_post_name,
224
  "post_type" => $ref_post->post_type
225
  );
@@ -264,19 +264,20 @@ function cms_tpv_admin_head() {
264
  var CMS_TPV_URL = "<?php echo CMS_TPV_URL ?>";
265
  var CMS_TPV_AJAXURL = "?action=cms_tpv_get_childs&view=";
266
  var CMS_TPV_VIEW = "<?php echo $cms_tpv_view ?>";
 
267
  var cms_tpv_jsondata = {};
268
  /* ]]> */
269
  </script>
270
 
271
- <!--[if IE 6]>
272
- <style>
273
- .cms_tree_view_search_form {
274
- display: none !important;
275
- }
276
  .cms_tpv_dashboard_widget .subsubsub li {
277
  }
278
- </style>
279
- <![endif]-->
280
  <?php
281
  }
282
 
@@ -1055,9 +1056,9 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
1055
 
1056
 
1057
  <div>
1058
- <?php _e("Status", "cms-tree-page-view") ?><br>
1059
  <label><input type="radio" name="cms_tpv_add_status" value="draft" checked> <?php _e("Draft", "cms-tree-page-view") ?></label>
1060
- <label><input type="radio" name="cms_tpv_add_status" value="published"> <?php _e("Published", "cms-tree-page-view") ?></label>
1061
  </div>
1062
 
1063
  <div>
@@ -1146,12 +1147,12 @@ function cms_tpv_get_pages($args = null) {
1146
 
1147
  global $wpdb;
1148
 
1149
- $defaults = array(
1150
- "post_type" => "post",
1151
  "parent" => "",
1152
  "view" => "all" // all | public | trash
1153
- );
1154
- $r = wp_parse_args( $args, $defaults );
1155
 
1156
  $get_posts_args = array(
1157
  "numberposts" => "-1",
@@ -1195,8 +1196,8 @@ function cms_tpv_get_pages($args = null) {
1195
 
1196
  // filter out pages for wpml, by applying same filter as get_pages does
1197
  // only run if wpml is available or always?
1198
- // Note: get_pages filter uses orderby comma separated and with the key sort_column
1199
- $get_posts_args["sort_column"] = str_replace(" ", ", ", $get_posts_args["orderby"]);
1200
  $pages = apply_filters('get_pages', $pages, $get_posts_args);
1201
 
1202
  return $pages;
@@ -1604,11 +1605,15 @@ function cms_tpv_move_page() {
1604
  the node that was moved,
1605
  the reference node in the move,
1606
  the new position relative to the reference node (one of "before", "after" or "inside"),
1607
- inside = man placerar den under en sida som inte har några barn?
1608
  */
1609
 
1610
  global $wpdb;
1611
-
 
 
 
 
1612
  $node_id = $_POST["node_id"]; // the node that was moved
1613
  $ref_node_id = $_POST["ref_node_id"];
1614
  $type = $_POST["type"];
@@ -1779,6 +1784,59 @@ function cms_tpv_install() {
1779
 
1780
  // set to current version
1781
  update_option('cms_tpv_version', CMS_TPV_VERSION);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1782
  }
1783
 
1784
  // cms_tpv_install();
63
  /*
64
  Array
65
  (
66
+ [action] => cms_tpv_add_pages
67
+ [cms_tpv_add_new_pages_names] => Array
68
+ (
69
+ [0] => xxxxx
70
+ [1] => yyyy
71
+ [2] =>
72
+ )
73
+
74
+ [cms_tpv_add_type] => inside
75
+ [cms_tpv_add_status] => draft
76
+ [lang] => de
77
  )
78
  */
79
 
219
  $newpost_args = array(
220
  "menu_order" => $new_menu_order,
221
  "post_parent" => $post_parent_id,
222
+ "post_status" => ( ('publish' == $post_status) && !current_user_can('publish_posts') ? 'pending' : $post_status ),
223
  "post_title" => $one_new_post_name,
224
  "post_type" => $ref_post->post_type
225
  );
264
  var CMS_TPV_URL = "<?php echo CMS_TPV_URL ?>";
265
  var CMS_TPV_AJAXURL = "?action=cms_tpv_get_childs&view=";
266
  var CMS_TPV_VIEW = "<?php echo $cms_tpv_view ?>";
267
+ var CMS_TPV_CAN_DND = "<?php echo current_user_can( CMS_TPV_MOVE_PERMISSION ) ? "dnd" : "" ?>";
268
  var cms_tpv_jsondata = {};
269
  /* ]]> */
270
  </script>
271
 
272
+ <!--[if IE 6]>
273
+ <style>
274
+ .cms_tree_view_search_form {
275
+ display: none !important;
276
+ }
277
  .cms_tpv_dashboard_widget .subsubsub li {
278
  }
279
+ </style>
280
+ <![endif]-->
281
  <?php
282
  }
283
 
1056
 
1057
 
1058
  <div>
1059
+ <?php _e("Status", "cms-tree-page-view") ?><br>
1060
  <label><input type="radio" name="cms_tpv_add_status" value="draft" checked> <?php _e("Draft", "cms-tree-page-view") ?></label>
1061
+ <label><input type="radio" name="cms_tpv_add_status" value="published"> <?php current_user_can('publish_posts') ? _e("Published", "cms-tree-page-view") : _e("Submit for Review", "cms-tree-page-view") ?></label>
1062
  </div>
1063
 
1064
  <div>
1147
 
1148
  global $wpdb;
1149
 
1150
+ $defaults = array(
1151
+ "post_type" => "post",
1152
  "parent" => "",
1153
  "view" => "all" // all | public | trash
1154
+ );
1155
+ $r = wp_parse_args( $args, $defaults );
1156
 
1157
  $get_posts_args = array(
1158
  "numberposts" => "-1",
1196
 
1197
  // filter out pages for wpml, by applying same filter as get_pages does
1198
  // only run if wpml is available or always?
1199
+ // Note: get_pages filter uses orderby comma separated and with the key sort_column
1200
+ $get_posts_args["sort_column"] = str_replace(" ", ", ", $get_posts_args["orderby"]);
1201
  $pages = apply_filters('get_pages', $pages, $get_posts_args);
1202
 
1203
  return $pages;
1605
  the node that was moved,
1606
  the reference node in the move,
1607
  the new position relative to the reference node (one of "before", "after" or "inside"),
1608
+ inside = man placerar den under en sida som inte har några barn?
1609
  */
1610
 
1611
  global $wpdb;
1612
+
1613
+ if ( !current_user_can( CMS_TPV_MOVE_PERMISSION ) )
1614
+ die("Error: you dont have permission");
1615
+
1616
+
1617
  $node_id = $_POST["node_id"]; // the node that was moved
1618
  $ref_node_id = $_POST["ref_node_id"];
1619
  $type = $_POST["type"];
1784
 
1785
  // set to current version
1786
  update_option('cms_tpv_version', CMS_TPV_VERSION);
1787
+
1788
+ // Add necessary capabilities to allow moving tree of cms_tpv
1789
+ $roles = array(
1790
+ 'administrator' => array(CMS_TPV_MOVE_PERMISSION),
1791
+ 'editor' => array(CMS_TPV_MOVE_PERMISSION),
1792
+ // 'author' => array(CMS_TPV_MOVE_PERMISSION),
1793
+ // 'contributor' => array(CMS_TPV_MOVE_PERMISSION)
1794
+ );
1795
+
1796
+ foreach ( $roles as $role => $caps ) {
1797
+ add_caps_to_role( $role, $caps );
1798
+ }
1799
+
1800
+ }
1801
+
1802
+ function cms_tpv_uninstall() {
1803
+ // Remove capabilities to disallow moving tree of cms_tpv
1804
+ $roles = array(
1805
+ 'administrator' => array(CMS_TPV_MOVE_PERMISSION),
1806
+ 'editor' => array(CMS_TPV_MOVE_PERMISSION)
1807
+ );
1808
+
1809
+ foreach ( $roles as $role => $caps ) {
1810
+ remove_caps_from_role( $role, $caps );
1811
+ }
1812
+ }
1813
+
1814
+ /**
1815
+ * Adds an array of capabilities to a role.
1816
+ */
1817
+ function add_caps_to_role( $role, $caps ) {
1818
+
1819
+ global $wp_roles;
1820
+
1821
+ if ( $wp_roles->is_role( $role ) ) {
1822
+ $role =& get_role( $role );
1823
+ foreach ( $caps as $cap )
1824
+ $role->add_cap( $cap );
1825
+ }
1826
+ }
1827
+
1828
+ /**
1829
+ * Remove an array of capabilities from role.
1830
+ */
1831
+ function remove_caps_from_role( $role, $caps ) {
1832
+
1833
+ global $wp_roles;
1834
+
1835
+ if ( $wp_roles->is_role( $role ) ) {
1836
+ $role =& get_role( $role );
1837
+ foreach ( $caps as $cap )
1838
+ $role->remove_cap( $cap );
1839
+ }
1840
  }
1841
 
1842
  // cms_tpv_install();
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: CMS Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/cms-tree-page-view/
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. Use the tree view to edit, view, add pages and search pages (very useful if you have many pages). And with drag and drop you can rearrange the order of your pages. Page management won't get any easier than this!
6
- Version: 1.2.22
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
@@ -27,7 +27,7 @@ License: GPL2
27
 
28
  #require("functions.php");
29
 
30
- define( "CMS_TPV_VERSION", "1.2.22");
31
  define( "CMS_TPV_NAME", "CMS Tree Page View");
32
 
33
  require(dirname(__FILE__) . "/functions.php");
@@ -68,7 +68,9 @@ add_action('wp_ajax_cms_tpv_add_page', 'cms_tpv_add_page');
68
  add_action('wp_ajax_cms_tpv_add_pages', 'cms_tpv_add_pages');
69
 
70
  // activation
 
71
  register_activation_hook( WP_PLUGIN_DIR . "/cms-tree-page-view/index.php" , 'cms_tpv_install' );
 
72
 
73
  // To test activation hook, uncomment function below
74
  // cms_tpv_install();
3
  Plugin Name: CMS Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/cms-tree-page-view/
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. Use the tree view to edit, view, add pages and search pages (very useful if you have many pages). And with drag and drop you can rearrange the order of your pages. Page management won't get any easier than this!
6
+ Version: 1.2.23
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
27
 
28
  #require("functions.php");
29
 
30
+ define( "CMS_TPV_VERSION", "1.2.23");
31
  define( "CMS_TPV_NAME", "CMS Tree Page View");
32
 
33
  require(dirname(__FILE__) . "/functions.php");
68
  add_action('wp_ajax_cms_tpv_add_pages', 'cms_tpv_add_pages');
69
 
70
  // activation
71
+ define( "CMS_TPV_MOVE_PERMISSION", "move_cms_tree_view_page");
72
  register_activation_hook( WP_PLUGIN_DIR . "/cms-tree-page-view/index.php" , 'cms_tpv_install' );
73
+ register_uninstall_hook( WP_PLUGIN_DIR . "/cms-tree-page-view/index.php" , 'cms_tpv_uninstall' );
74
 
75
  // To test activation hook, uncomment function below
76
  // cms_tpv_install();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://eskapism.se/sida/donate/
4
  Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and-drop, rearrange, management, manage, admin
5
  Requires at least: 3.8
6
  Tested up to: 3.9
7
- Stable tag: 1.2.22
8
 
9
  Adds a tree view of all pages & custom posts. Get a great overview + options to drag & drop to reorder & option to add multiple pages.
10
 
@@ -113,6 +113,9 @@ Now the tree with the pages will be visible both on the dashboard and in the men
113
 
114
  == Changelog ==
115
 
 
 
 
116
  = 1.2.22 =
117
  - Fixed top links being squashed in dashboard. Fixes http://wordpress.org/support/topic/bug-top-links-on-dashboard-widget-misaligned-in-wp-38. Props tim.wakeling.
118
  - Fixed: Now prevents long titles from overflowing the dashboard widget area. Prop tim.wakeling.
4
  Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and-drop, rearrange, management, manage, admin
5
  Requires at least: 3.8
6
  Tested up to: 3.9
7
+ Stable tag: 1.2.23
8
 
9
  Adds a tree view of all pages & custom posts. Get a great overview + options to drag & drop to reorder & option to add multiple pages.
10
 
113
 
114
  == Changelog ==
115
 
116
+ = 1.2.23 =
117
+ - Now only users with permission may move pages and custom posts and publish new posts. By default administrator and editors have these rights. Is checked using capability "move_cms_tree_view_page", so add that to any user you want to allow this for. Props mateuszdw, who made [the very first pull request for this plugin](https://github.com/bonny/WordPress-CMS-Tree-Page-View/pull/1)! Thanks a lot!
118
+
119
  = 1.2.22 =
120
  - Fixed top links being squashed in dashboard. Fixes http://wordpress.org/support/topic/bug-top-links-on-dashboard-widget-misaligned-in-wp-38. Props tim.wakeling.
121
  - Fixed: Now prevents long titles from overflowing the dashboard widget area. Prop tim.wakeling.
scripts/cms_tree_page_view.js CHANGED
@@ -199,7 +199,7 @@ jQuery(function($) {
199
  });
200
 
201
  treeOptions = {
202
- plugins: ["themes","json_data","cookies","search","dnd", "types"],
203
  core: {
204
  "html_titles": true
205
  },
199
  });
200
 
201
  treeOptions = {
202
+ plugins: ["themes","json_data","cookies","search",CMS_TPV_CAN_DND, "types"],
203
  core: {
204
  "html_titles": true
205
  },