Yet Another Related Posts Plugin (YARPP) - Version 3.6b6

Version Description

Download this release

Release Info

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

Code changes from version 3.6b5 to 3.6b6

class-admin.php CHANGED
@@ -84,7 +84,7 @@ class YARPP_Admin {
84
  current_user_can('manage_options') &&
85
  !get_user_option( 'yarpp_saw_optin' ) ) {
86
  $user = get_current_user_id();
87
- // update_user_option( $user, 'yarpp_saw_optin', true );
88
  add_action( 'admin_notices', array( $this, 'optin_notice' ) );
89
  }
90
 
@@ -340,7 +340,7 @@ jQuery(function () {
340
  // @since 3.3: default metaboxes to show:
341
  function default_hidden_meta_boxes($hidden, $screen) {
342
  if ( 'settings_page_yarpp' == $screen->id )
343
- $hidden = array( 'yarpp_pool', 'yarpp_relatedness' );
344
  return $hidden;
345
  }
346
 
@@ -476,4 +476,4 @@ jQuery(function () {
476
  echo 'ok';
477
  exit;
478
  }
479
- }
84
  current_user_can('manage_options') &&
85
  !get_user_option( 'yarpp_saw_optin' ) ) {
86
  $user = get_current_user_id();
87
+ update_user_option( $user, 'yarpp_saw_optin', true );
88
  add_action( 'admin_notices', array( $this, 'optin_notice' ) );
89
  }
90
 
340
  // @since 3.3: default metaboxes to show:
341
  function default_hidden_meta_boxes($hidden, $screen) {
342
  if ( 'settings_page_yarpp' == $screen->id )
343
+ $hidden = $this->core->default_hidden_metaboxes;
344
  return $hidden;
345
  }
346
 
476
  echo 'ok';
477
  exit;
478
  }
479
+ }
class-core.php CHANGED
@@ -16,6 +16,7 @@ class YARPP {
16
 
17
  // here's a list of all the options YARPP uses (except version), as well as their default values, sans the yarpp_ prefix, split up into binary options and value options. These arrays are used in updating settings (options.php) and other tasks.
18
  public $default_options = array();
 
19
 
20
  function __construct() {
21
  $this->load_default_options();
@@ -172,23 +173,19 @@ class YARPP {
172
  return $given;
173
  }
174
 
175
-
176
  /*
177
  * INFRASTRUCTURE
178
  */
179
 
180
  function enabled() {
181
  global $wpdb;
 
182
  if ( $this->cache->is_enabled() === false )
183
  return false;
184
- $indexdata = $wpdb->get_results("show index from $wpdb->posts");
185
- foreach ($indexdata as $index) {
186
- if ($index->Key_name == 'yarpp_title')
187
- return true;
188
- }
189
- return false;
190
  }
191
-
192
  // @since 3.5.2: function to enforce YARPP setup
193
  // if new install, activate; else upgrade
194
  function enforce() {
@@ -204,21 +201,19 @@ class YARPP {
204
  function activate() {
205
  global $wpdb;
206
 
207
- $wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_title'");
208
- if (!$wpdb->num_rows)
209
  $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title` )");
210
-
211
- $wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_content'");
212
- if (!$wpdb->num_rows)
213
  $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content` )");
 
214
 
215
- if ( !$this->enabled() ) {
216
- // If we are still not enabled, run the cache abstraction's setup method.
217
  $this->cache->setup();
218
- // If we're still not enabled, give up.
219
- if ( !$this->enabled() )
220
- return 0;
221
  }
 
 
 
 
222
 
223
  if ( !get_option('yarpp_version') ) {
224
  // new install
@@ -229,19 +224,54 @@ class YARPP {
229
  $this->upgrade();
230
  }
231
 
232
- return 1;
233
  }
 
 
 
 
 
234
 
235
- function myisam_check() {
236
  global $wpdb;
237
  $tables = $wpdb->get_results("show table status like '{$wpdb->posts}'");
238
  foreach ($tables as $table) {
239
- if ($table->Engine == 'MyISAM') return true;
240
- else return $table->Engine;
 
 
241
  }
242
  return 'UNKNOWN';
243
  }
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  function upgrade() {
246
  $last_version = get_option( 'yarpp_version' );
247
  if (version_compare(YARPP_VERSION, $last_version) === 0)
@@ -465,7 +495,7 @@ class YARPP {
465
  $weight = $this->default_options['weight'];
466
  // if we're still not using MyISAM
467
  if ( !yarpp_get_option('myisam_override') &&
468
- $this->myisam_check() !== true ) {
469
  unset( $weight['title'] );
470
  unset( $weight['body'] );
471
  }
@@ -544,7 +574,8 @@ class YARPP {
544
  $check_changed = array(
545
  'before_title', 'after_title', 'before_post', 'after_post',
546
  'before_related', 'after_related', 'no_results', 'order',
547
- 'rss_before_title', 'rss_after_title', 'rss_before_post', 'rss_after_post', 'rss_before_related', 'rss_after_related', 'rss_no_results', 'rss_order',
 
548
  'exclude', 'thumbnails_heading', 'thumbnails_default', 'rss_thumbnails_heading',
549
  'rss_thumbnails_default'
550
  );
@@ -559,6 +590,12 @@ class YARPP {
559
  'settings' => array_intersect_key( $settings, $collect ),
560
  'cache_engine' => YARPP_CACHE_TYPE
561
  ),
 
 
 
 
 
 
562
  'stats' => array(
563
  'counts' => array(),
564
  'terms' => array(),
@@ -570,7 +607,6 @@ class YARPP {
570
  ),
571
  'users' => $wpdb->get_var("select count(ID) from $wpdb->users"),
572
  ),
573
- 'post_thumbnails' => current_theme_supports( 'post-thumbnails', 'post' ),
574
  'locale' => get_bloginfo( 'language' ),
575
  'url' => get_bloginfo('url'),
576
  'plugins' => array(
@@ -640,16 +676,18 @@ class YARPP {
640
  * @param (bool) $echo
641
  */
642
  function display_related($reference_ID = null, $args = array(), $echo = true) {
643
- global $wp_query, $pagenow;
644
-
645
- $this->enforce();
646
-
647
  // if we're already in a YARPP loop, stop now.
648
  if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
649
  return false;
650
 
651
- $reference_ID = ( null === $reference_ID || false === $reference_ID ) ?
652
- get_the_ID() : absint($reference_ID);
 
 
 
 
 
 
653
 
654
  // @since 3.5.3: don't compute on revisions
655
  if ( $the_post = wp_is_post_revision($reference_ID) )
@@ -745,17 +783,21 @@ class YARPP {
745
  * @param (array) $args
746
  */
747
  function get_related($reference_ID = null, $args = array()) {
 
 
 
 
748
  $this->enforce();
749
 
750
- $reference_ID = ( null === $reference_ID ) ? get_the_ID() : absint($reference_ID);
 
 
 
 
751
  // @since 3.5.3: don't compute on revisions
752
  if ( $the_post = wp_is_post_revision($reference_ID) )
753
  $reference_ID = $the_post;
754
-
755
- // if we're already in a YARPP loop, stop now.
756
- if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
757
- return false;
758
-
759
  $this->setup_active_cache( $args );
760
 
761
  $options = array( 'limit', 'order' );
@@ -787,13 +829,17 @@ class YARPP {
787
  * @param (array) $args
788
  */
789
  function related_exist($reference_ID = null, $args = array()) {
790
- $this->enforce();
791
-
792
  // if we're already in a YARPP loop, stop now.
793
  if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
794
  return false;
 
 
795
 
796
- $reference_ID = ( null === $reference_ID ) ? get_the_ID() : absint($reference_ID);
 
 
 
 
797
  // @since 3.5.3: don't compute on revisions
798
  if ( $the_post = wp_is_post_revision($reference_ID) )
799
  $reference_ID = $the_post;
16
 
17
  // here's a list of all the options YARPP uses (except version), as well as their default values, sans the yarpp_ prefix, split up into binary options and value options. These arrays are used in updating settings (options.php) and other tasks.
18
  public $default_options = array();
19
+ public $default_hidden_metaboxes = array( 'yarpp_pool', 'yarpp_relatedness' );
20
 
21
  function __construct() {
22
  $this->load_default_options();
173
  return $given;
174
  }
175
 
 
176
  /*
177
  * INFRASTRUCTURE
178
  */
179
 
180
  function enabled() {
181
  global $wpdb;
182
+
183
  if ( $this->cache->is_enabled() === false )
184
  return false;
185
+
186
+ return $this->diagnostic_fulltext_indices();
 
 
 
 
187
  }
188
+
189
  // @since 3.5.2: function to enforce YARPP setup
190
  // if new install, activate; else upgrade
191
  function enforce() {
201
  function activate() {
202
  global $wpdb;
203
 
204
+ if ( !$this->diagnostic_fulltext_indices() ) {
 
205
  $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title` )");
 
 
 
206
  $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content` )");
207
+ }
208
 
209
+ if ( $this->cache->is_enabled() === false ) {
210
+ // Run the cache abstraction's setup method.
211
  $this->cache->setup();
 
 
 
212
  }
213
+
214
+ // If we're not enabled, give up.
215
+ if ( !$this->enabled() )
216
+ return false;
217
 
218
  if ( !get_option('yarpp_version') ) {
219
  // new install
224
  $this->upgrade();
225
  }
226
 
227
+ return true;
228
  }
229
+
230
+ /*
231
+ * DIAGNOSTICS
232
+ * @since 3.6 moved into separate functions. Note return value types can differ.
233
+ */
234
 
235
+ function diagnostic_myisam_posts() {
236
  global $wpdb;
237
  $tables = $wpdb->get_results("show table status like '{$wpdb->posts}'");
238
  foreach ($tables as $table) {
239
+ if ($table->Engine == 'MyISAM')
240
+ return true;
241
+ else
242
+ return $table->Engine;
243
  }
244
  return 'UNKNOWN';
245
  }
246
 
247
+ function diagnostic_fulltext_indices() {
248
+ global $wpdb;
249
+ $wpdb->get_results("show index from $wpdb->posts where Key_name = 'yarpp_title' or Key_name = 'yarpp_content'");
250
+ return ( $wpdb->num_rows >= 2 );
251
+ }
252
+
253
+ function diagnostic_hidden_metaboxes() {
254
+ global $wpdb;
255
+ $raw = $wpdb->get_var("select meta_value from $wpdb->usermeta where meta_key = 'metaboxhidden_settings_page_yarpp' order by length(meta_value) asc limit 1");
256
+
257
+ if ( !$raw )
258
+ return $this->default_hidden_metaboxes;
259
+
260
+ $list = maybe_unserialize( $raw );
261
+ if ( !is_array($list) )
262
+ return $this->default_hidden_metaboxes;
263
+
264
+ return implode('|', $list);
265
+ }
266
+
267
+ function diagnostic_post_thumbnails() {
268
+ return current_theme_supports( 'post-thumbnails', 'post' );
269
+ }
270
+
271
+ /*
272
+ * UPGRADE ROUTINES
273
+ */
274
+
275
  function upgrade() {
276
  $last_version = get_option( 'yarpp_version' );
277
  if (version_compare(YARPP_VERSION, $last_version) === 0)
495
  $weight = $this->default_options['weight'];
496
  // if we're still not using MyISAM
497
  if ( !yarpp_get_option('myisam_override') &&
498
+ $this->diagnostic_myisam_posts() !== true ) {
499
  unset( $weight['title'] );
500
  unset( $weight['body'] );
501
  }
574
  $check_changed = array(
575
  'before_title', 'after_title', 'before_post', 'after_post',
576
  'before_related', 'after_related', 'no_results', 'order',
577
+ 'rss_before_title', 'rss_after_title', 'rss_before_post', 'rss_after_post',
578
+ 'rss_before_related', 'rss_after_related', 'rss_no_results', 'rss_order',
579
  'exclude', 'thumbnails_heading', 'thumbnails_default', 'rss_thumbnails_heading',
580
  'rss_thumbnails_default'
581
  );
590
  'settings' => array_intersect_key( $settings, $collect ),
591
  'cache_engine' => YARPP_CACHE_TYPE
592
  ),
593
+ 'diagnostics' => array(
594
+ 'myisam_posts' => $this->diagnostic_myisam_posts(),
595
+ 'fulltext_indices' => $this->diagnostic_fulltext_indices(),
596
+ 'hidden_metaboxes' => $this->diagnostic_hidden_metaboxes(),
597
+ 'post_thumbnails' => $this->diagnostic_post_thumbnails()
598
+ ),
599
  'stats' => array(
600
  'counts' => array(),
601
  'terms' => array(),
607
  ),
608
  'users' => $wpdb->get_var("select count(ID) from $wpdb->users"),
609
  ),
 
610
  'locale' => get_bloginfo( 'language' ),
611
  'url' => get_bloginfo('url'),
612
  'plugins' => array(
676
  * @param (bool) $echo
677
  */
678
  function display_related($reference_ID = null, $args = array(), $echo = true) {
 
 
 
 
679
  // if we're already in a YARPP loop, stop now.
680
  if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
681
  return false;
682
 
683
+ global $wp_query, $pagenow;
684
+
685
+ $this->enforce();
686
+
687
+ if ( is_numeric( $reference_ID ) )
688
+ $reference_ID = (int) $reference_ID;
689
+ else
690
+ $reference_ID = get_the_ID();
691
 
692
  // @since 3.5.3: don't compute on revisions
693
  if ( $the_post = wp_is_post_revision($reference_ID) )
783
  * @param (array) $args
784
  */
785
  function get_related($reference_ID = null, $args = array()) {
786
+ // if we're already in a YARPP loop, stop now.
787
+ if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
788
+ return false;
789
+
790
  $this->enforce();
791
 
792
+ if ( is_numeric( $reference_ID ) )
793
+ $reference_ID = (int) $reference_ID;
794
+ else
795
+ $reference_ID = get_the_ID();
796
+
797
  // @since 3.5.3: don't compute on revisions
798
  if ( $the_post = wp_is_post_revision($reference_ID) )
799
  $reference_ID = $the_post;
800
+
 
 
 
 
801
  $this->setup_active_cache( $args );
802
 
803
  $options = array( 'limit', 'order' );
829
  * @param (array) $args
830
  */
831
  function related_exist($reference_ID = null, $args = array()) {
 
 
832
  // if we're already in a YARPP loop, stop now.
833
  if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
834
  return false;
835
+
836
+ $this->enforce();
837
 
838
+ if ( is_numeric( $reference_ID ) )
839
+ $reference_ID = (int) $reference_ID;
840
+ else
841
+ $reference_ID = get_the_ID();
842
+
843
  // @since 3.5.3: don't compute on revisions
844
  if ( $the_post = wp_is_post_revision($reference_ID) )
845
  $reference_ID = $the_post;
options-meta-boxes.php CHANGED
@@ -37,10 +37,10 @@ class YARPP_Meta_Box {
37
  echo "<div data-value='thumbnails' class='yarpp_template_button";
38
  if ( 'thumbnails' == $choice )
39
  echo ' active';
40
- if ( !current_theme_supports( 'post-thumbnails', 'post' ) )
41
  echo ' disabled';
42
  echo "'";
43
- if ( !current_theme_supports( 'post-thumbnails', 'post' ) )
44
  echo ' data-help="' . esc_attr( __( 'This option is disabled because your theme does not support post thumbnails.', 'yarpp' ) ) . '"';
45
  echo "><div class='image'></div><div class='label'>" . __('Thumbnails', 'yarpp') . "</div></div>";
46
 
37
  echo "<div data-value='thumbnails' class='yarpp_template_button";
38
  if ( 'thumbnails' == $choice )
39
  echo ' active';
40
+ if ( !$yarpp->diagnostic_post_thumbnails() )
41
  echo ' disabled';
42
  echo "'";
43
+ if ( !$yarpp->diagnostic_post_thumbnails() )
44
  echo ' data-help="' . esc_attr( __( 'This option is disabled because your theme does not support post thumbnails.', 'yarpp' ) ) . '"';
45
  echo "><div class='image'></div><div class='label'>" . __('Thumbnails', 'yarpp') . "</div></div>";
46
 
options.php CHANGED
@@ -45,14 +45,14 @@ if (isset($_POST['myisam_override'])) {
45
  }
46
 
47
  if ( !yarpp_get_option('myisam_override') ) {
48
- $yarpp_check_return = $yarpp->myisam_check();
49
  if ($yarpp_check_return !== true) { // if it's not *exactly* true
50
  echo "<div class='updated'>"
51
- .sprintf(__("YARPP's \"consider titles\" and \"consider bodies\" relatedness criteria require your <code>%s</code> table to use the <a href='http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html'>MyISAM storage engine</a>, but the table seems to be using the <code>%s</code> engine. These two options have been disabled.",'yarpp'),$wpdb->posts,$yarpp_check_return)
52
  ."<br />"
53
- .sprintf(__("To restore these features, please update your <code>%s</code> table by executing the following SQL directive: <code>ALTER TABLE `%s` ENGINE = MyISAM;</code> . No data will be erased by altering the table's engine, although there are performance implications.",'yarpp'),$wpdb->posts,$wpdb->posts)
54
  ."<br />"
55
- .sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:",'yarpp'),$wpdb->posts)
56
  ."<br />"
57
  ."<form method='post'><input type='submit' class='button' name='myisam_override' value='"
58
  .__("Trust me. Let me use MyISAM features.",'yarpp')
45
  }
46
 
47
  if ( !yarpp_get_option('myisam_override') ) {
48
+ $yarpp_check_return = $yarpp->diagnostic_myisam_posts();
49
  if ($yarpp_check_return !== true) { // if it's not *exactly* true
50
  echo "<div class='updated'>"
51
+ .sprintf(__("YARPP's \"consider titles\" and \"consider bodies\" relatedness criteria require your <code>%s</code> table to use the <a href='http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html'>MyISAM storage engine</a>, but the table seems to be using the <code>%s</code> engine. These two options have been disabled.",'yarpp'), $wpdb->posts, $yarpp_check_return)
52
  ."<br />"
53
+ .sprintf(__("To restore these features, please update your <code>%s</code> table by executing the following SQL directive: <code>ALTER TABLE `%s` ENGINE = MyISAM;</code> . No data will be erased by altering the table's engine, although there are performance implications.",'yarpp'), $wpdb->posts, $wpdb->posts)
54
  ."<br />"
55
+ .sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:",'yarpp'), $wpdb->posts)
56
  ."<br />"
57
  ."<form method='post'><input type='submit' class='button' name='myisam_override' value='"
58
  .__("Trust me. Let me use MyISAM features.",'yarpp')
readme.txt CHANGED
@@ -239,6 +239,7 @@ If you are a bilingual speaker of English and another language and an avid user
239
  * No PHP required -- just visit the settings page
240
  * Edit your theme's CSS file to modify the styling
241
  * All YARPP output is now wrapped in a `div` with class `yarpp-related`, `yarpp-related-widget`, or `yarpp-related-rss` as appropriate ([by request](https://wordpress.org/support/topic/adding-a-main-div-to-default-template)).
 
242
  * Improvements to YARPP custom template UI
243
  * A new design for the template chooser
244
  * A new "copy templates" button allows one-button installation of bundled templates into the current theme, if filesystem permissions make it possible.
239
  * No PHP required -- just visit the settings page
240
  * Edit your theme's CSS file to modify the styling
241
  * All YARPP output is now wrapped in a `div` with class `yarpp-related`, `yarpp-related-widget`, or `yarpp-related-rss` as appropriate ([by request](https://wordpress.org/support/topic/adding-a-main-div-to-default-template)).
242
+ * [Bugfix](https://wordpress.org/support/topic/related-posts-disappearing-cache-issue): uses of `related_posts_exist()` and `get_related()` without explicit reference ID parameter would incorrectly return no related posts.
243
  * Improvements to YARPP custom template UI
244
  * A new design for the template chooser
245
  * A new "copy templates" button allows one-button installation of bundled templates into the current theme, if filesystem permissions make it possible.
related-functions.php CHANGED
@@ -19,7 +19,7 @@ function yarpp_related_exist($args = array(), $reference_ID = false) {
19
  return;
20
  }
21
 
22
- return $yarpp->related_exist($reference_ID, $args, $echo);
23
  }
24
 
25
  function yarpp_get_related($args = array(), $reference_ID = false) {
19
  return;
20
  }
21
 
22
+ return $yarpp->related_exist($reference_ID, $args);
23
  }
24
 
25
  function yarpp_get_related($args = array(), $reference_ID = false) {
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 custom post type support!
6
- Version: 3.6b5
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', '3.6b5');
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 custom post type support!
6
+ Version: 3.6b6
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', '3.6b6');
13
  define('YARPP_DIR', dirname(__FILE__));
14
  define('YARPP_NO_RELATED', ':(');
15
  define('YARPP_RELATED', ':)');