Version Description
Minor bugfix: fix to more reliably ensure the navigation links appear in certain situations; fix incorrect example code for excluding post statuses; noted compatibility through WP 4.2+
Download this release
Release Info
Developer | coffee2code |
Plugin | Admin Post Navigation |
Version | 1.9.1 |
Comparing to | |
See all releases |
Code changes from version 1.9 to 1.9.1
- admin-post-navigation.php +6 -7
- readme.txt +33 -11
- tests/test-admin-post-navigation.php +25 -2
admin-post-navigation.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Admin Post Navigation
|
4 |
-
* Version: 1.9
|
5 |
* Plugin URI: http://coffee2code.com/wp-plugins/admin-post-navigation/
|
6 |
* Author: Scott Reilly
|
7 |
* Author URI: http://coffee2code.com/
|
@@ -11,7 +11,7 @@
|
|
11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
* Description: Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
|
13 |
*
|
14 |
-
* Compatible with WordPress 3.0 through 4.
|
15 |
*
|
16 |
* =>> Read the accompanying readme.txt file for instructions and documentation.
|
17 |
* =>> Also, visit the plugin's homepage for additional information and updates.
|
@@ -19,7 +19,7 @@
|
|
19 |
*
|
20 |
* @package Admin_Post_Navigation
|
21 |
* @author Scott Reilly
|
22 |
-
* @version 1.9
|
23 |
*/
|
24 |
|
25 |
/*
|
@@ -69,7 +69,7 @@ class c2c_AdminPostNavigation {
|
|
69 |
* @since 1.7
|
70 |
*/
|
71 |
public static function version() {
|
72 |
-
return '1.9';
|
73 |
}
|
74 |
|
75 |
/**
|
@@ -120,7 +120,6 @@ class c2c_AdminPostNavigation {
|
|
120 |
foreach( $post_statuses as $i => $v ) { $GLOBALS['wpdb']->escape_by_ref( $v ); $post_statuses[ $i ] = $v; }
|
121 |
self::$post_statuses_sql = "'" . implode( "', '", $post_statuses ) . "'";
|
122 |
}
|
123 |
-
$label = self::_get_post_type_label( $post_type );
|
124 |
|
125 |
if ( in_array( $post->post_status, $post_statuses ) ) {
|
126 |
add_meta_box(
|
@@ -138,7 +137,7 @@ class c2c_AdminPostNavigation {
|
|
138 |
* Adds the content for the post navigation meta_box.
|
139 |
*
|
140 |
* @param object $object
|
141 |
-
* @param array
|
142 |
*/
|
143 |
public static function add_meta_box( $object, $box ) {
|
144 |
$display = '';
|
@@ -215,7 +214,7 @@ HTML;
|
|
215 |
echo <<<JS
|
216 |
<script type="text/javascript">
|
217 |
jQuery(document).ready(function($) {
|
218 |
-
$('#admin-post-nav').appendTo($('h2:first'));
|
219 |
$('#adminpostnav, label[for="adminpostnav-hide"]').hide();
|
220 |
});
|
221 |
</script>
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Admin Post Navigation
|
4 |
+
* Version: 1.9.1
|
5 |
* Plugin URI: http://coffee2code.com/wp-plugins/admin-post-navigation/
|
6 |
* Author: Scott Reilly
|
7 |
* Author URI: http://coffee2code.com/
|
11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
* Description: Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
|
13 |
*
|
14 |
+
* Compatible with WordPress 3.0 through 4.2+.
|
15 |
*
|
16 |
* =>> Read the accompanying readme.txt file for instructions and documentation.
|
17 |
* =>> Also, visit the plugin's homepage for additional information and updates.
|
19 |
*
|
20 |
* @package Admin_Post_Navigation
|
21 |
* @author Scott Reilly
|
22 |
+
* @version 1.9.1
|
23 |
*/
|
24 |
|
25 |
/*
|
69 |
* @since 1.7
|
70 |
*/
|
71 |
public static function version() {
|
72 |
+
return '1.9.1';
|
73 |
}
|
74 |
|
75 |
/**
|
120 |
foreach( $post_statuses as $i => $v ) { $GLOBALS['wpdb']->escape_by_ref( $v ); $post_statuses[ $i ] = $v; }
|
121 |
self::$post_statuses_sql = "'" . implode( "', '", $post_statuses ) . "'";
|
122 |
}
|
|
|
123 |
|
124 |
if ( in_array( $post->post_status, $post_statuses ) ) {
|
125 |
add_meta_box(
|
137 |
* Adds the content for the post navigation meta_box.
|
138 |
*
|
139 |
* @param object $object
|
140 |
+
* @param array $box
|
141 |
*/
|
142 |
public static function add_meta_box( $object, $box ) {
|
143 |
$display = '';
|
214 |
echo <<<JS
|
215 |
<script type="text/javascript">
|
216 |
jQuery(document).ready(function($) {
|
217 |
+
$('#admin-post-nav').appendTo($('#wpbody-content .wrap:first h2:first'));
|
218 |
$('#adminpostnav, label[for="adminpostnav-hide"]').hide();
|
219 |
});
|
220 |
</script>
|
readme.txt
CHANGED
@@ -5,8 +5,8 @@ Tags: admin, navigation, post, next, previous, edit, post types, coffee2code
|
|
5 |
License: GPLv2 or later
|
6 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
7 |
Requires at least: 3.0
|
8 |
-
Tested up to: 4.
|
9 |
-
Stable tag: 1.9
|
10 |
|
11 |
Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
|
12 |
|
@@ -57,20 +57,27 @@ The 'c2c_admin_post_navigation_orderby' filter allows you to change the post fie
|
|
57 |
Arguments:
|
58 |
|
59 |
* $field (string) The current ORDER BY field
|
|
|
60 |
|
61 |
Example:
|
62 |
|
63 |
`
|
64 |
/**
|
65 |
-
* Modify how Admin Post Navigation orders posts for navigation
|
|
|
66 |
*
|
67 |
-
* @param string $field
|
|
|
68 |
* @return string
|
69 |
*/
|
70 |
-
function
|
71 |
-
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
-
add_filter( 'c2c_admin_post_navigation_orderby', '
|
74 |
`
|
75 |
|
76 |
= c2c_admin_post_navigation_post_statuses (filter) =
|
@@ -91,12 +98,16 @@ Example:
|
|
91 |
* @return array
|
92 |
*/
|
93 |
function change_apn_post_status( $post_statuses ) {
|
94 |
-
//
|
|
|
95 |
$post_statuses[] = 'trash';
|
96 |
|
97 |
-
//
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
100 |
}
|
101 |
|
102 |
return $post_statuses;
|
@@ -216,6 +227,14 @@ add_filter( 'c2c_admin_post_navigation_display', 'override_apn_display' );
|
|
216 |
|
217 |
== Changelog ==
|
218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
= 1.9 (2015-03-14) =
|
220 |
* Fix to only append navigation to the first h2 on the page. props @pomegranate
|
221 |
* Add filter 'c2c_admin_post_navigation_prev_text' to allow customization of the previous navigation link text. props @pomegranate
|
@@ -345,6 +364,9 @@ add_filter( 'c2c_admin_post_navigation_display', 'override_apn_display' );
|
|
345 |
|
346 |
== Upgrade Notice ==
|
347 |
|
|
|
|
|
|
|
348 |
= 1.9 =
|
349 |
Feature update: fix to only apply navigation to first h2 on page; added filters to facilitate customizing link text; added unit tests; noted compatibility through WP 4.1+; added plugin icon
|
350 |
|
5 |
License: GPLv2 or later
|
6 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
7 |
Requires at least: 3.0
|
8 |
+
Tested up to: 4.2
|
9 |
+
Stable tag: 1.9.1
|
10 |
|
11 |
Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
|
12 |
|
57 |
Arguments:
|
58 |
|
59 |
* $field (string) The current ORDER BY field
|
60 |
+
* $post_type (string) The post type being navigated
|
61 |
|
62 |
Example:
|
63 |
|
64 |
`
|
65 |
/**
|
66 |
+
* Modify how Admin Post Navigation orders posts for navigation by ordering
|
67 |
+
* pages by 'menu_order' and posts by 'post_date'.
|
68 |
*
|
69 |
+
* @param string $field The field used to order posts for navigation.
|
70 |
+
* @param string $post_type The post type being navigated.
|
71 |
* @return string
|
72 |
*/
|
73 |
+
function custom_order_apn( $field, $post_type ) {
|
74 |
+
if ( 'page' === $post_type ) {
|
75 |
+
return 'menu_order';
|
76 |
+
} else {
|
77 |
+
return 'post_date';
|
78 |
+
}
|
79 |
}
|
80 |
+
add_filter( 'c2c_admin_post_navigation_orderby', 'custom_order_apn', 10, 2 );
|
81 |
`
|
82 |
|
83 |
= c2c_admin_post_navigation_post_statuses (filter) =
|
98 |
* @return array
|
99 |
*/
|
100 |
function change_apn_post_status( $post_statuses ) {
|
101 |
+
// Add a post status.
|
102 |
+
// Note: by default these are already in the $post_statuses array: 'draft', 'future', 'pending', 'private', 'publish'
|
103 |
$post_statuses[] = 'trash';
|
104 |
|
105 |
+
// Remove post status(es).
|
106 |
+
$post_statuses_to_remove = array( 'draft' ); // Customize here.
|
107 |
+
foreach ( $post_statuses_to_remove as $remove ) {
|
108 |
+
if ( false !== $index = array_search( $remove, $post_statuses ) ) {
|
109 |
+
unset( $post_statuses[ $index ] );
|
110 |
+
}
|
111 |
}
|
112 |
|
113 |
return $post_statuses;
|
227 |
|
228 |
== Changelog ==
|
229 |
|
230 |
+
= 1.9.1 (2015-07-08) =
|
231 |
+
* Bugfix: Fix JS placement of navigation links to target the desired h2, which may not always be the first on the page
|
232 |
+
* Update: Add additional unit test using example for customizing post status navigation
|
233 |
+
* Update: Fix incorrect example for excluding post statuses via filter
|
234 |
+
* Update: Improve example for using hook to define custom order for navigation
|
235 |
+
* Update: Remove unused line of code.
|
236 |
+
* Update: Note compatibility through WP 4.2+
|
237 |
+
|
238 |
= 1.9 (2015-03-14) =
|
239 |
* Fix to only append navigation to the first h2 on the page. props @pomegranate
|
240 |
* Add filter 'c2c_admin_post_navigation_prev_text' to allow customization of the previous navigation link text. props @pomegranate
|
364 |
|
365 |
== Upgrade Notice ==
|
366 |
|
367 |
+
= 1.9.1 =
|
368 |
+
Minor bugfix: fix to more reliably ensure the navigation links appear in certain situations; fix incorrect example code for excluding post statuses; noted compatibility through WP 4.2+
|
369 |
+
|
370 |
= 1.9 =
|
371 |
Feature update: fix to only apply navigation to first h2 on page; added filters to facilitate customizing link text; added unit tests; noted compatibility through WP 4.1+; added plugin icon
|
372 |
|
tests/test-admin-post-navigation.php
CHANGED
@@ -68,8 +68,17 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
|
|
68 |
$this->assertEquals( 'post', $post_type );
|
69 |
$this->assertTrue( is_a( $post, 'WP_Post' ) );
|
70 |
|
|
|
71 |
$post_statuses[] = 'trash';
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
return $post_statuses;
|
74 |
}
|
75 |
|
@@ -94,7 +103,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
|
|
94 |
}
|
95 |
|
96 |
function test_version() {
|
97 |
-
$this->assertEquals( '1.9', c2c_AdminPostNavigation::version() );
|
98 |
}
|
99 |
|
100 |
/*
|
@@ -209,7 +218,7 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
|
|
209 |
$this->assertEquals( 10, has_action( 'do_meta_boxes', array( 'c2c_AdminPostNavigation', 'do_meta_box' ) ) );
|
210 |
}
|
211 |
|
212 |
-
function
|
213 |
add_filter( 'c2c_admin_post_navigation_post_statuses', array( $this, 'c2c_admin_post_navigation_post_statuses' ), 10, 3 );
|
214 |
|
215 |
$posts = $this->create_posts();
|
@@ -223,6 +232,20 @@ class Admin_Post_Navigation_Test extends WP_UnitTestCase {
|
|
223 |
$this->assertEquals( $posts[3], $next_post->ID );
|
224 |
}
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
function test_filter_c2c_admin_post_navigation_orderby() {
|
227 |
add_filter( 'c2c_admin_post_navigation_orderby', array( $this, 'c2c_admin_post_navigation_orderby' ), 10, 2 );
|
228 |
|
68 |
$this->assertEquals( 'post', $post_type );
|
69 |
$this->assertTrue( is_a( $post, 'WP_Post' ) );
|
70 |
|
71 |
+
// Add a post status.
|
72 |
$post_statuses[] = 'trash';
|
73 |
|
74 |
+
// Remove post status.
|
75 |
+
$post_statuses_to_remove = array( 'draft' );
|
76 |
+
foreach ( $post_statuses_to_remove as $remove ) {
|
77 |
+
if ( false !== $index = array_search( $remove, $post_statuses ) ) {
|
78 |
+
unset( $post_statuses[ $index ] );
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
return $post_statuses;
|
83 |
}
|
84 |
|
103 |
}
|
104 |
|
105 |
function test_version() {
|
106 |
+
$this->assertEquals( '1.9.1', c2c_AdminPostNavigation::version() );
|
107 |
}
|
108 |
|
109 |
/*
|
218 |
$this->assertEquals( 10, has_action( 'do_meta_boxes', array( 'c2c_AdminPostNavigation', 'do_meta_box' ) ) );
|
219 |
}
|
220 |
|
221 |
+
function test_filter_c2c_admin_post_navigation_post_statuses_when_adding_post_status() {
|
222 |
add_filter( 'c2c_admin_post_navigation_post_statuses', array( $this, 'c2c_admin_post_navigation_post_statuses' ), 10, 3 );
|
223 |
|
224 |
$posts = $this->create_posts();
|
232 |
$this->assertEquals( $posts[3], $next_post->ID );
|
233 |
}
|
234 |
|
235 |
+
function test_filter_c2c_admin_post_navigation_post_statuses_when_removing_post_status() {
|
236 |
+
add_filter( 'c2c_admin_post_navigation_post_statuses', array( $this, 'c2c_admin_post_navigation_post_statuses' ), 10, 3 );
|
237 |
+
|
238 |
+
$posts = $this->create_posts();
|
239 |
+
|
240 |
+
$post = get_post( $posts[3] );
|
241 |
+
$post->post_status = 'draft';
|
242 |
+
wp_update_post( $post );
|
243 |
+
$post = get_post( $posts[2] );
|
244 |
+
|
245 |
+
$next_post = c2c_AdminPostNavigation::next_post();
|
246 |
+
$this->assertEquals( $posts[4], $next_post->ID );
|
247 |
+
}
|
248 |
+
|
249 |
function test_filter_c2c_admin_post_navigation_orderby() {
|
250 |
add_filter( 'c2c_admin_post_navigation_orderby', array( $this, 'c2c_admin_post_navigation_orderby' ), 10, 2 );
|
251 |
|