Yet Another Related Posts Plugin (YARPP) - Version 4.0.3b4

Version Description

Download this release

Release Info

Developer mitchoyoshitaka
Plugin Icon 128x128 Yet Another Related Posts Plugin (YARPP)
Version 4.0.3b4
Comparing to
See all releases

Code changes from version 4.0.3b2 to 4.0.3b4

class-admin.php CHANGED
@@ -69,8 +69,14 @@ class YARPP_Admin {
69
// new in 3.0.12: add settings link to the plugins page
70
add_filter('plugin_action_links', array( $this, 'settings_link' ), 10, 2);
71
72
- // new in 3.0: add meta box
73
- add_meta_box( 'yarpp_relatedposts', __( 'Related Posts' , 'yarpp') . ' <span class="postbox-title-action"><a href="' . esc_url( admin_url('options-general.php?page=yarpp') ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>', array( $this, 'metabox' ), 'post', 'normal' );
74
75
// new in 3.3: properly enqueue scripts for admin:
76
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
@@ -242,7 +248,9 @@ class YARPP_Admin {
242
wp_enqueue_style( 'yarpp_options', plugins_url( 'options.css', __FILE__ ), array(), $version );
243
wp_enqueue_script( 'yarpp_options', plugins_url( 'js/options.js', __FILE__ ), array('jquery'), $version );
244
}
245
- if ( !is_null($screen) && $screen->id == 'post' ) {
246
wp_enqueue_script( 'yarpp_metabox', plugins_url( 'js/metabox.js', __FILE__ ), array('jquery'), $version );
247
}
248
}
69
// new in 3.0.12: add settings link to the plugins page
70
add_filter('plugin_action_links', array( $this, 'settings_link' ), 10, 2);
71
72
+ $metabox_post_types = $this->core->get_option( 'auto_display_post_types' );
73
+ if ( !in_array( 'post', $metabox_post_types ) )
74
+ $metabox_post_types[] = 'post';
75
+
76
+ // new in 3.0: add meta box
77
+ foreach ( $metabox_post_types as $post_type ) {
78
+ add_meta_box( 'yarpp_relatedposts', __( 'Related Posts' , 'yarpp') . ' <span class="postbox-title-action"><a href="' . esc_url( admin_url('options-general.php?page=yarpp') ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>', array( $this, 'metabox' ), $post_type, 'normal' );
79
+ }
80
81
// new in 3.3: properly enqueue scripts for admin:
82
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
248
wp_enqueue_style( 'yarpp_options', plugins_url( 'options.css', __FILE__ ), array(), $version );
249
wp_enqueue_script( 'yarpp_options', plugins_url( 'js/options.js', __FILE__ ), array('jquery'), $version );
250
}
251
+
252
+ $metabox_post_types = $this->core->get_option( 'auto_display_post_types' );
253
+ if ( !is_null($screen) && ($screen->id == 'post' || in_array( $screen->id, $metabox_post_types )) ) {
254
wp_enqueue_script( 'yarpp_metabox', plugins_url( 'js/metabox.js', __FILE__ ), array('jquery'), $version );
255
}
256
}
class-core.php CHANGED
@@ -380,7 +380,7 @@ class YARPP {
380
381
public function get_template_data( $file ) {
382
$headers = array(
383
- 'name' => 'Template Name',
384
'description' => 'Description',
385
'author' => 'Author',
386
'uri' => 'Author URI',
@@ -649,6 +649,27 @@ class YARPP {
649
* UTILITIES
650
*/
651
652
private $post_types = null;
653
function get_post_types( $field = 'name' ) {
654
if ( is_null($this->post_types) ) {
@@ -821,8 +842,6 @@ class YARPP {
821
// if we're already in a YARPP loop, stop now.
822
if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
823
return false;
824
-
825
- global $wp_query, $pagenow;
826
827
$this->enforce();
828
@@ -852,10 +871,9 @@ class YARPP {
852
$this->active_cache->begin_yarpp_time($reference_ID, $args);
853
}
854
855
- // so we can return to normal later
856
- $current_query = $wp_query;
857
- $current_pagenow = $pagenow;
858
-
859
$wp_query = new WP_Query();
860
if ( YARPP_NO_RELATED == $cache_status ) {
861
// If there are no related posts, get no query
@@ -869,7 +887,7 @@ class YARPP {
869
'post_type' => ( isset($args['post_type']) ? $args['post_type'] : $this->get_post_types() )
870
));
871
}
872
- $this->prep_query( $current_query->is_feed );
873
$related_query = $wp_query; // backwards compatibility
874
$related_count = $related_query->post_count;
875
@@ -904,11 +922,9 @@ class YARPP {
904
} else {
905
$this->active_cache->end_yarpp_time(); // YARPP time is over... :(
906
}
907
-
908
- // restore the older wp_query.
909
- $wp_query = $current_query; unset($current_query); unset($related_query);
910
- wp_reset_postdata();
911
- $pagenow = $current_pagenow; unset($current_pagenow);
912
913
if ( $related_count > 0 && $promote_yarpp && $domain != 'metabox' )
914
$output .= "<p>".sprintf(__("Related posts brought to you by <a href='%s'>Yet Another Related Posts Plugin</a>.",'yarpp'), 'http://yarpp.org')."</p>\n";
@@ -1014,9 +1030,7 @@ class YARPP {
1014
* @param (array) $args
1015
* @param (bool) $echo
1016
*/
1017
- function display_demo_related($args = array(), $echo = true) {
1018
- global $wp_query;
1019
-
1020
if ( $this->cache_bypass->demo_time ) // if we're already in a demo YARPP loop, stop now.
1021
return false;
1022
@@ -1032,6 +1046,7 @@ class YARPP {
1032
$output .= "yarpp-related-{$domain}";
1033
$output .= "'>\n";
1034
1035
$wp_query = new WP_Query();
1036
$wp_query->query('');
1037
380
381
public function get_template_data( $file ) {
382
$headers = array(
383
+ 'name' => 'YARPP Template',
384
'description' => 'Description',
385
'author' => 'Author',
386
'uri' => 'Author URI',
649
* UTILITIES
650
*/
651
652
+ private $current_post;
653
+ private $current_query;
654
+ private $current_pagenow;
655
+ // so we can return to normal later
656
+ function save_post_context() {
657
+ global $wp_query, $pagenow, $post;
658
+ $this->current_query = $wp_query;
659
+ $this->current_pagenow = $pagenow;
660
+ $this->current_post = $post;
661
+ }
662
+ function restore_post_context() {
663
+ global $wp_query, $pagenow, $post;
664
+ if ( isset($this->current_post) ) {
665
+ $post = $this->current_post;
666
+ setup_postdata( $post );
667
+ unset($this->current_post);
668
+ }
669
+ $pagenow = $this->current_pagenow; unset($this->current_pagenow);
670
+ $wp_query = $this->current_query; unset($this->current_query);
671
+ }
672
+
673
private $post_types = null;
674
function get_post_types( $field = 'name' ) {
675
if ( is_null($this->post_types) ) {
842
// if we're already in a YARPP loop, stop now.
843
if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
844
return false;
845
846
$this->enforce();
847
871
$this->active_cache->begin_yarpp_time($reference_ID, $args);
872
}
873
874
+ $this->save_post_context();
875
+
876
+ global $wp_query;
877
$wp_query = new WP_Query();
878
if ( YARPP_NO_RELATED == $cache_status ) {
879
// If there are no related posts, get no query
887
'post_type' => ( isset($args['post_type']) ? $args['post_type'] : $this->get_post_types() )
888
));
889
}
890
+ $this->prep_query( $this->current_query->is_feed );
891
$related_query = $wp_query; // backwards compatibility
892
$related_count = $related_query->post_count;
893
922
} else {
923
$this->active_cache->end_yarpp_time(); // YARPP time is over... :(
924
}
925
+
926
+ unset( $related_query );
927
+ $this->restore_post_context();
928
929
if ( $related_count > 0 && $promote_yarpp && $domain != 'metabox' )
930
$output .= "<p>".sprintf(__("Related posts brought to you by <a href='%s'>Yet Another Related Posts Plugin</a>.",'yarpp'), 'http://yarpp.org')."</p>\n";
1030
* @param (array) $args
1031
* @param (bool) $echo
1032
*/
1033
+ function display_demo_related($args = array(), $echo = true) {
1034
if ( $this->cache_bypass->demo_time ) // if we're already in a demo YARPP loop, stop now.
1035
return false;
1036
1046
$output .= "yarpp-related-{$domain}";
1047
$output .= "'>\n";
1048
1049
+ global $wp_query;
1050
$wp_query = new WP_Query();
1051
$wp_query->query('');
1052
readme.txt CHANGED
@@ -260,6 +260,9 @@ If you are a bilingual speaker of English and another language and an avid user
260
= 4.0.3 =
261
* Bugfix: on sites where custom templates are not available, the "thumbnails" display option would get reset when visiting the YARPP settings page
262
* [Bugfix](http://wordpress.org/support/topic/yarpp-css-is-delayed-or-doesnt-load): the CSS for YARPP's thumbnails display would load at the foot of the page, and therefore would cause some style-flashing. This is fixed for automatic includes, but not for widgets or manual calls.
263
* Updated Polish localization
264
265
= 4.0.2 =
@@ -297,7 +300,7 @@ If you are a bilingual speaker of English and another language and an avid user
297
* A new design for the template chooser
298
* Example code display is now hidden by default; turn them back on from the "screen options" tab.
299
* A new "copy templates" button allows one-button installation of bundled templates into the current theme, if filesystem permissions make it possible.
300
- * Header information in YARPP custom templates are now displayed to users in the settings UI. Available fields are `Template Name`, `Description`, `Author`, `Author URI`, in the same format as plugin and theme file headers. See bundled templates for examples.
301
* Code cleanup:
302
* Settings screen UI have been rewritten to use `div`s rather than `table`s!
303
* Inline help in settings screen now use WordPress pointers
260
= 4.0.3 =
261
* Bugfix: on sites where custom templates are not available, the "thumbnails" display option would get reset when visiting the YARPP settings page
262
* [Bugfix](http://wordpress.org/support/topic/yarpp-css-is-delayed-or-doesnt-load): the CSS for YARPP's thumbnails display would load at the foot of the page, and therefore would cause some style-flashing. This is fixed for automatic includes, but not for widgets or manual calls.
263
+ * Restoration of the `$post` global after YARPP is now more robust. Fixes the display of incorrect metadata on some complex themes.
264
+ * YARPP template files no longer recognize `Template Name` fields in their headers, instead using `YARPP Template`. This is to avoid confusion with regular page templates.
265
+ * Added "Related Posts" meta box to other "auto display" post types
266
* Updated Polish localization
267
268
= 4.0.2 =
300
* A new design for the template chooser
301
* Example code display is now hidden by default; turn them back on from the "screen options" tab.
302
* A new "copy templates" button allows one-button installation of bundled templates into the current theme, if filesystem permissions make it possible.
303
+ * Header information in YARPP custom templates are now displayed to users in the settings UI. Available fields are `YARPP Template`, `Description`, `Author`, `Author URI`, in the same format as plugin and theme file headers. See bundled templates for examples.
304
* Code cleanup:
305
* Settings screen UI have been rewritten to use `div`s rather than `table`s!
306
* Inline help in settings screen now use WordPress pointers
yarpp-templates/yarpp-template-example.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- Template Name: Simple
4
Author: mitcho (Michael Yoshitaka Erlewine)
5
Description: A simple example YARPP template.
6
*/
1
<?php
2
/*
3
+ YARPP Template: Simple
4
Author: mitcho (Michael Yoshitaka Erlewine)
5
Description: A simple example YARPP template.
6
*/
yarpp-templates/yarpp-template-list.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- Template Name: List
4
Description: This template returns the related posts as a comma-separated list.
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/
1
<?php
2
/*
3
+ YARPP Template: List
4
Description: This template returns the related posts as a comma-separated list.
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/
yarpp-templates/yarpp-template-photoblog.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- Template Name: Yet Another Photoblog
4
Description: Requires the Yet Another Photoblog plugin
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/ ?>
1
<?php
2
/*
3
+ YARPP Template: Yet Another Photoblog
4
Description: Requires the Yet Another Photoblog plugin
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/ ?>
yarpp-templates/yarpp-template-random.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- Template Name: Random
4
Description: This template gives you a random other post in case there are no related posts
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/ ?>
1
<?php
2
/*
3
+ YARPP Template: Random
4
Description: This template gives you a random other post in case there are no related posts
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/ ?>
yarpp-templates/yarpp-template-thumbnail.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- Template Name: Thumbnails
4
Description: Requires a theme which supports post thumbnails
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/ ?>
1
<?php
2
/*
3
+ YARPP Template: Thumbnails
4
Description: Requires a theme which supports post thumbnails
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/ ?>
yarpp-templates/yarpp-template-wpml.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- Template Name: WPML
4
Description: An example template for use with the WPML plugin
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/
1
<?php
2
/*
3
+ YARPP Template: WPML
4
Description: An example template for use with the WPML plugin
5
Author: mitcho (Michael Yoshitaka Erlewine)
6
*/
yarpp.php CHANGED
@@ -3,13 +3,13 @@
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. Now with Now with thumbnail support built-in!
6
- Version: 4.0.3b2
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
- define('YARPP_VERSION', '4.0.3b2');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. Now with Now with thumbnail support built-in!
6
+ Version: 4.0.3b4
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
+ define('YARPP_VERSION', '4.0.3b4');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');