\n";
+ }
+
+ }
+
+
+
+?>
\ No newline at end of file
diff --git a/js/cpt.js b/js/cpt.js
new file mode 100644
index 0000000..8d58b11
--- /dev/null
+++ b/js/cpt.js
@@ -0,0 +1,54 @@
+
+
+ var getUrlParameter = function getUrlParameter(sParam)
+ {
+ var sPageURL = decodeURIComponent(window.location.search.substring(1)),
+ sURLVariables = sPageURL.split('&'),
+ sParameterName,
+ i;
+
+ for (i = 0; i < sURLVariables.length; i++) {
+ sParameterName = sURLVariables[i].split('=');
+
+ if (sParameterName[0] === sParam) {
+ return sParameterName[1] === undefined ? true : sParameterName[1];
+ }
+ }
+ };
+
+ jQuery(document).ready(function()
+ {
+
+ jQuery('table.posts #the-list').sortable({
+ 'items': 'tr',
+ 'axis': 'y',
+ 'update' : function(e, ui) {
+
+ var post_type = jQuery('input[name="post_type"]').val();
+ var order = jQuery('#the-list').sortable('serialize');
+
+ var paged = getUrlParameter('paged');
+ if(typeof paged === 'undefined')
+ paged = 1;
+
+ var queryString = { "action": "update-custom-type-order-archive", "post_type" : post_type, "order" : order ,"paged": paged, "archive_sort_nonce" : CPTO.archive_sort_nonce};
+ //send the data through ajax
+ jQuery.ajax({
+ type: 'POST',
+ url: ajaxurl,
+ data: queryString,
+ cache: false,
+ dataType: "html",
+ success: function(data){
+
+ },
+ error: function(html){
+
+ }
+ });
+
+ }
+ });
+
+
+ });
diff --git a/post-types-order.php b/post-types-order.php
index bd8f35f..d69073b 100644
--- a/post-types-order.php
+++ b/post-types-order.php
@@ -1,372 +1,79 @@
-ID) && $post->ID < 1)
- { return $query; } // Stop running the function if this is a virtual page
- //--
-
- //no need if it's admin interface
- if (is_admin())
- return $query;
-
- //check for ignore_custom_sort
- if (isset($query->query_vars['ignore_custom_sort']) && $query->query_vars['ignore_custom_sort'] === TRUE)
- return $query;
-
- //ignore if "nav_menu_item"
- if(isset($query->query_vars) && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == "nav_menu_item")
- return $query;
-
- $options = cpt_get_options();
-
- //if auto sort
- if ($options['autosort'] == "1")
- {
- //remove the supresed filters;
- if (isset($query->query['suppress_filters']))
- $query->query['suppress_filters'] = FALSE;
-
-
- if (isset($query->query_vars['suppress_filters']))
- $query->query_vars['suppress_filters'] = FALSE;
-
- }
-
- return $query;
- }
-
- add_filter('posts_orderby', 'CPTOrderPosts', 99, 2);
- function CPTOrderPosts($orderBy, $query)
- {
- global $wpdb;
-
- $options = cpt_get_options();
-
- //check for ignore_custom_sort
- if (isset($query->query_vars['ignore_custom_sort']) && $query->query_vars['ignore_custom_sort'] === TRUE)
- return $orderBy;
-
- //ignore the bbpress
- if (isset($query->query_vars['post_type']) && ((is_array($query->query_vars['post_type']) && in_array("reply", $query->query_vars['post_type'])) || ($query->query_vars['post_type'] == "reply")))
- return $orderBy;
- if (isset($query->query_vars['post_type']) && ((is_array($query->query_vars['post_type']) && in_array("topic", $query->query_vars['post_type'])) || ($query->query_vars['post_type'] == "topic")))
- return $orderBy;
-
- //check for orderby GET paramether in which case return default data
- if (isset($_GET['orderby']) && $_GET['orderby'] != 'menu_order')
- return $orderBy;
-
- if (is_admin())
- {
-
- if ($options['adminsort'] == "1" ||
- //ignore when ajax Gallery Edit default functionality
- (defined('DOING_AJAX') && isset($_REQUEST['action']) && $_REQUEST['action'] == 'query-attachments')
- )
- {
-
- global $post;
-
- //temporary ignore ACF group and admin ajax calls, should be fixed within ACF plugin sometime later
- if (is_object($post) && $post->post_type == "acf-field-group"
- || (defined('DOING_AJAX') && isset($_REQUEST['action']) && strpos($_REQUEST['action'], 'acf/') < 1))
- return $orderBy;
-
- $orderBy = "{$wpdb->posts}.menu_order, {$wpdb->posts}.post_date DESC";
- }
- }
- else
- {
- //ignore search
- if($query->is_search())
- return($orderBy);
-
- if ($options['autosort'] == "1")
- {
- if(trim($orderBy) == '')
- $orderBy = "{$wpdb->posts}.menu_order ";
- else
- $orderBy = "{$wpdb->posts}.menu_order, " . $orderBy;
- }
- }
-
- return($orderBy);
- }
-
- $is_configured = get_option('CPT_configured');
- if ($is_configured == '')
- add_action( 'admin_notices', 'CPTO_admin_notices');
-
- function CPTO_admin_notices()
- {
- if (isset($_POST['form_submit']))
- return;
- ?>
-
-
-
- Post Types Order', 'manage_options', 'cpto-options', 'cpt_plugin_options');
- }
-
-
- add_action('wp_loaded', 'initCPTO' );
- function initCPTO()
- {
- global $custom_post_type_order, $userdata;
-
- $options = cpt_get_options();
-
- if (is_admin())
- {
- if(isset($options['capability']) && !empty($options['capability']))
- {
- if(current_user_can($options['capability']))
- $custom_post_type_order = new CPTO();
- }
- else if (is_numeric($options['level']))
- {
- if (userdata_get_user_level(true) >= $options['level'])
- $custom_post_type_order = new CPTO();
- }
- else
- {
- $custom_post_type_order = new CPTO();
- }
- }
- }
-
-
- add_filter('init', 'cpto_setup_theme');
- function cpto_setup_theme()
- {
- if(is_admin())
- return;
-
- //check the navigation_sort_apply option
- $options = cpt_get_options();
-
- $navigation_sort_apply = ($options['navigation_sort_apply'] == "1") ? TRUE : FALSE;
- $navigation_sort_apply = apply_filters('cpto/navigation_sort_apply', $navigation_sort_apply);
-
- if( ! $navigation_sort_apply)
- return;
-
- add_filter('get_previous_post_where', 'cpto_get_previous_post_where', 99, 3);
- add_filter('get_previous_post_sort', 'cpto_get_previous_post_sort');
- add_filter('get_next_post_where', 'cpto_get_next_post_where', 99, 3);
- add_filter('get_next_post_sort', 'cpto_get_next_post_sort');
- }
-
- function cpto_get_previous_post_where($where, $in_same_term, $excluded_terms)
- {
- global $post, $wpdb;
-
- if ( empty( $post ) )
- return $where;
-
- //?? WordPress does not pass through this varialbe, so we presume it's category..
- $taxonomy = 'category';
- if(preg_match('/ tt.taxonomy = \'([^\']+)\'/i',$where, $match))
- $taxonomy = $match[1];
-
- $_join = '';
- $_where = '';
-
- if ( $in_same_term || ! empty( $excluded_terms ) )
- {
- $_join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
- $_where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
-
- if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) )
- {
- // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
- if ( false !== strpos( $excluded_terms, ' and ' ) )
- {
- _deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
- $excluded_terms = explode( ' and ', $excluded_terms );
- }
- else
- {
- $excluded_terms = explode( ',', $excluded_terms );
- }
-
- $excluded_terms = array_map( 'intval', $excluded_terms );
- }
-
- if ( $in_same_term )
- {
- $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
-
- // Remove any exclusions from the term array to include.
- $term_array = array_diff( $term_array, (array) $excluded_terms );
- $term_array = array_map( 'intval', $term_array );
-
- $_where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
- }
-
- if ( ! empty( $excluded_terms ) ) {
- $_where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( $excluded_terms, ',' ) . ') )';
- }
- }
-
- $current_menu_order = $post->menu_order;
-
- $query = "SELECT p.* FROM $wpdb->posts AS p
- $_join
- WHERE p.post_date < '". $post->post_date ."' AND p.menu_order = '".$current_menu_order."' AND p.post_type = '". $post->post_type ."' AND p.post_status = 'publish' $_where";
- $results = $wpdb->get_results($query);
-
- if (count($results) > 0)
- {
- $where .= " AND p.menu_order = '".$current_menu_order."'";
- }
- else
- {
- $where = str_replace("p.post_date < '". $post->post_date ."'", "p.menu_order > '$current_menu_order'", $where);
- }
-
- return $where;
- }
-
- function cpto_get_previous_post_sort($sort)
- {
- global $post, $wpdb;
-
- $sort = 'ORDER BY p.menu_order ASC, p.post_date DESC LIMIT 1';
-
- return $sort;
- }
-
- function cpto_get_next_post_where($where, $in_same_term, $excluded_terms)
- {
- global $post, $wpdb;
-
- if ( empty( $post ) )
- return $where;
-
- $taxonomy = 'category';
- if(preg_match('/ tt.taxonomy = \'([^\']+)\'/i',$where, $match))
- $taxonomy = $match[1];
-
- $_join = '';
- $_where = '';
-
- if ( $in_same_term || ! empty( $excluded_terms ) )
- {
- $_join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
- $_where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
-
- if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) )
- {
- // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
- if ( false !== strpos( $excluded_terms, ' and ' ) )
- {
- _deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
- $excluded_terms = explode( ' and ', $excluded_terms );
- }
- else
- {
- $excluded_terms = explode( ',', $excluded_terms );
- }
-
- $excluded_terms = array_map( 'intval', $excluded_terms );
- }
-
- if ( $in_same_term )
- {
- $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
-
- // Remove any exclusions from the term array to include.
- $term_array = array_diff( $term_array, (array) $excluded_terms );
- $term_array = array_map( 'intval', $term_array );
-
- $_where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
- }
-
- if ( ! empty( $excluded_terms ) ) {
- $_where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( $excluded_terms, ',' ) . ') )';
- }
- }
-
- $current_menu_order = $post->menu_order;
-
- //check if there are more posts with lower menu_order
- $query = "SELECT p.* FROM $wpdb->posts AS p
- $_join
- WHERE p.post_date > '". $post->post_date ."' AND p.menu_order = '".$current_menu_order."' AND p.post_type = '". $post->post_type ."' AND p.post_status = 'publish' $_where";
- $results = $wpdb->get_results($query);
-
- if (count($results) > 0)
- {
- $where .= " AND p.menu_order = '".$current_menu_order."'";
- }
- else
- {
- $where = str_replace("p.post_date > '". $post->post_date ."'", "p.menu_order < '$current_menu_order'", $where);
- }
-
- return $where;
- }
-
- function cpto_get_next_post_sort($sort)
- {
- global $post, $wpdb;
-
- $sort = 'ORDER BY p.menu_order DESC, p.post_date ASC LIMIT 1';
-
- return $sort;
- }
-
-
+functions->get_options();
+
+ if (is_admin())
+ {
+ if(isset($options['capability']) && !empty($options['capability']))
+ {
+ if( current_user_can($options['capability']) )
+ $CPTO->init();
+ }
+ else if (is_numeric($options['level']))
+ {
+ if ( $CPTO->functions->userdata_get_user_level(true) >= $options['level'] )
+ $CPTO->init();
+ }
+ else
+ {
+ $CPTO->init();
+ }
+ }
+ }
+
+
+
?>
\ No newline at end of file
diff --git a/readme.txt b/readme.txt
index 19f8ec8..210bbb0 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,18 +1,22 @@
=== Post Types Order ===
-Contributors: Nsp Code
+Contributors: nsp-code, tdgu
Donate link: http://www.nsp-code.com/donate.php
Tags: post order, posts order, sort, post sort, posts sort, post type order, custom order, admin posts order
Requires at least: 2.8
-Tested up to: 4.3.1
-Stable tag: 1.8.5
+Tested up to: 4.7.2
+Stable tag: 1.9.3
+.
+License: GPLv2 or later
-Post Order and custom Post Type Objects (posts, any custom post types) using a Drag and Drop Sortable JavaScript AJAX interface.
+Post Order and custom Post Type Objects (custom post types) using a Drag and Drop Sortable JavaScript AJAX interface or default WordPress dashboard.
== Description ==
-Over 1.200.000 DOWNLOADS and near PERFECT ratting out of 150 REVIEWS.
-A powerful plugin, Order Posts and Post Types Objects using a Drag and Drop Sortable JavaScript capability.
-It allow to reorder the posts for any custom post types you defined, including the default Posts. Also you can have the admin posts interface sorted per your new sort. Post Order has never been easier.
+Over 2 MILLIONS DOWNLOADS and near PERFECT rating out of 150 REVIEWS.
+A powerful plugin, Order Posts and Post Types Objects using a Drag and Drop Sortable JavaScript capability.
+
+The order can be customized within **default WordPress post type archive list page** or **a separate Re-Order interface** which display all objects.
+It allow to reorder the posts for any custom post types you defined, including the default Posts. Also you can display the posts within admin interface sorted per your new sort. Post Order has never been easier.
= Usage =
This was built considering for everyone to be able to use no matter the WordPress experience, so it's very easy:
@@ -22,6 +26,7 @@ This was built considering for everyone to be able to use no matter the WordPres
* A new setting page will be created within Settings > Post Types Order, you should check with that, and make a first options save.
* Using the AutoSort option as ON you don't need to worry about any code changes, the plugin will do the post order update on fly.
* Use the Re-Order interface which appear to every custom post type (non-hierarchical) to change the post order to a new one.
+* If prefer sort apply through the code, include 'orderby' =>'menu_order' within custom query arguments, more details at http://www.nsp-code.com/sample-code-on-how-to-apply-the-sort-for-post-types-order-plugin/
= Example of Usage =
[youtube http://www.youtube.com/watch?v=VEbNKFSfhCc]
@@ -31,7 +36,7 @@ If for some reason the post order does not update on your front side, you either
Something is wrong with this plugin on your site? Just use the forum or get in touch with us at Contact and we'll check it out.
- Check out the advanced version of this plugin at Advanced Post Types Order
+ Need More? Check out the advanced version of this plugin at Advanced Post Types Order which include Hierarchically post types order, Manual / Automatic Sorting, Individual Categories Order, Conditionals to apply, Paginations for large list, Mobile ready, Enhanced Interface, Plugins compatibility (MultiSite Network Support, WPML, Polylang, WooCommerce, WP E-Commerce, Platform Pro, Genesis etc), font side re-order interface, ... and many more !!
This plugin is developed by Nsp-Code
@@ -48,13 +53,20 @@ If for some reason the post order does not update on your front side, you either
1. The ReOrder interface through which the sort can be created.
+2. Sort can be managed within default WordPress post type interface.
+
+
== Frequently Asked Questions ==
-Feel free to contact me at electronice_delphi@yahoo.com
+Feel free to contact us at electronice_delphi@yahoo.com
= I have no PHP knowledge at all, i will still be able to use this plugin? =
-Absolutely you can! Unlike many other plugins, you don't have to do any code changes to make your post order to change accordingly to custom defined post order. There is an option to autoupdate the WordPress queries so the posts order will be returned in the required order. Anyway this can be turned off to allow customized code usage.
+Absolutely you can! Unlike many other plugins, you don't have to do any code changes to make your post order to change accordingly to custom defined post order. There is an option to autoupdate the WordPress queries so the posts order will be returned in the required order. Anyway this can be turned off (Autosort) to allow customized code usage.
+
+= How to manually apply the sort on queries =
+
+Include a 'orderby' => 'menu_order' property within your custom query.
= What kind of posts/pages this plugin allow me to sort? =
@@ -70,11 +82,54 @@ All ideas are welcome and i put them on my list to be implemented into the new v
= Can i make certain queries to ignore the custom sort when Autosort is turned On? =
-This can be doe by including the ignore_custom_sort within custom query arguments. An example can be found at http://www.nsp-code.com/advanced-post-types-order-api/sample-usage/
+This can be done by including the ignore_custom_sort within custom query arguments. An example can be found at http://www.nsp-code.com/advanced-post-types-order-api/sample-usage/
+
+= How can i force sort apply for certain queries when Autosort is turned On? =
+
+A filter can be used to achieve that pto/posts_orderby. An example can be found at http://www.nsp-code.com/ignore-sort-apply-for-certain-query-on-post-types-order/
+
+= I still need more features like front sorting interface, shortcodes, filters, conditionals, advanced queries, taxonomy/ category sorting etc =
+
+Consider upgrading to our advanced version of this plugin at a very resonable price Advanced Post Types Order
== Change Log ==
+= 1.9.3 =
+ - Fix for custom post type objects per page when using default archive interface drag & drop sort
+ - Plugin code redo and re-structure
+ - Improved compatibility with other plugins
+ - Security improvments for AJAX order updates
+
+= 1.9 =
+ - Remove translations from the package
+ - Remove link for donate
+ - Wp Hide plugin availability notification
+ - New Filter pto/get_options to allow to chaneg default options; Custom capability can be set for 'capability'
+ - New Filter pto/admin/plugin_options/capability to allow custom capability option to be inserted within html
+
+= 1.8.9.2 =
+ - WPDB Prepare argument fix
+ - User preferance objects per page set to default if empty
+
+= 1.8.9 =
+ - Add Nonce for admin settings
+ - Update queries to use prepare
+ - Drag & Drop Sortable within Post Type archive interface
+ - Code cleanup
+ - Set time limit for ajax calls to attempt a code execution extend
+
+= 1.8.7 =
+ - Admin Post / Page Gallery items order fix
+ - New filter pto/posts_orderby to ignore sort apply
+
+= 1.8.6 =
+ - PHP 7 deprecated nottice fix Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP;
+ - Fix: $_REQUEST['action'] comparison evaluate as Identical instead equal
+ - New filter cpto/interface_itme_data to append additional data for items within sortable interface
+ - Slight style updates
+ - Replaced Socialize FB like page
+
= 1.8.5 =
- Text domain change to post-types-order to allow translations at https://translate.wordpress.org/projects/wp-plugins/post-types-order
- New query argument ignore_custom_sort , to be used with Autosort. Ignore any customised sort and return posts in default order.
@@ -213,6 +268,5 @@ Make sure you get the latest version.
== Localization ==
-Available in English, Brazilian Portuguese, Spanish, Romanian, Italian, Dusth, Hebrew, German, Norwegian (norsk), Turkish (t?rk?e), Swedish, Hungarian, Portuguese, Chinese, Czech
-Want to contribute with a translation to your language? Please contact us at electronice_delphi@yahoo.com
+Want to contribute with a translation to your language? Please check at https://translate.wordpress.org/projects/wp-plugins/post-types-order
http://www.nsp-code.com
diff --git a/screenshot-1.png b/screenshot-1.png
index 92f3254..743dbf0 100644
Binary files a/screenshot-1.png and b/screenshot-1.png differ
diff --git a/screenshot-2.png b/screenshot-2.png
new file mode 100644
index 0000000..d6e3a1d
Binary files /dev/null and b/screenshot-2.png differ