Contextual Related Posts - Version 2.2.2

Version Description

  • Features:

    • Preliminary support for WPML
  • Enhancements:

    • Recreate Index and Activation will not try to alter the table engine if not needed
  • Bug fixes:

    • All thumbnail classes were not properly applied + new thumbnail class filter
    • Shortcode with "exclude_categories" argument works again
Download this release

Release Info

Developer Ajay
Plugin Icon 128x128 Contextual Related Posts
Version 2.2.2
Comparing to
See all releases

Code changes from version 2.2.1 to 2.2.2

admin/admin.php CHANGED
@@ -44,6 +44,10 @@ function crp_options() {
44
  $crp_settings['crp_styles'] = 'no_style';
45
  update_option( 'ald_crp_settings', $crp_settings );
46
  }
 
 
 
 
47
 
48
 
49
  if ( ( isset( $_POST['crp_save'] ) ) && ( check_admin_referer( 'crp-plugin-settings' ) ) ) {
44
  $crp_settings['crp_styles'] = 'no_style';
45
  update_option( 'ald_crp_settings', $crp_settings );
46
  }
47
+ if ( ( true == $crp_settings['include_default_style'] ) && ( 'rounded_thumbs' != $crp_settings['crp_styles'] ) ) {
48
+ $crp_settings['crp_styles'] = 'rounded_thumbs';
49
+ update_option( 'ald_crp_settings', $crp_settings );
50
+ }
51
 
52
 
53
  if ( ( isset( $_POST['crp_save'] ) ) && ( check_admin_referer( 'crp-plugin-settings' ) ) ) {
contextual-related-posts.php CHANGED
@@ -15,7 +15,7 @@
15
  * Plugin Name: Contextual Related Posts
16
  * Plugin URI: https://webberzone.com/plugins/contextual-related-posts/
17
  * Description: Display a set of related posts on your website or in your feed. Increase reader retention and reduce bounce rates
18
- * Version: 2.2.1
19
  * Author: WebberZone
20
  * Author URI: https://webberzone.com
21
  * Text Domain: crp
@@ -89,6 +89,12 @@ add_action( 'plugins_loaded', 'crp_lang_init' );
89
  function get_crp( $args = array() ) {
90
  global $wpdb, $post, $crp_settings;
91
 
 
 
 
 
 
 
92
  $defaults = array(
93
  'is_widget' => FALSE,
94
  'is_manual' => FALSE,
@@ -118,12 +124,10 @@ function get_crp( $args = array() ) {
118
  }
119
  }
120
 
121
- $exclude_categories = explode( ',', $args['exclude_categories'] );
122
-
123
  // Retrieve the list of posts
124
  $results = get_crp_posts_id( array_merge( $args, array(
125
  'postid' => $post->ID,
126
- 'strict_limit' => TRUE,
127
  ) ) );
128
 
129
  $output = ( is_singular() ) ? '<div id="crp_related" class="crp_related' . ( $args['is_widget'] ? '_widget' : '' ) . '">' : '<div class="crp_related' . ( $args['is_widget'] ? '_widget' : '' ) . '">';
@@ -135,8 +139,20 @@ function get_crp( $args = array() ) {
135
 
136
  $output .= crp_before_list( $args );
137
 
 
 
 
138
  foreach ( $results as $result ) {
139
 
 
 
 
 
 
 
 
 
 
140
  /**
141
  * Filter the post ID for each result. Allows a custom function to hook in and change the ID if needed.
142
  *
@@ -148,6 +164,19 @@ function get_crp( $args = array() ) {
148
 
149
  $result = get_post( $resultid ); // Let's get the Post using the ID
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  $output .= crp_before_list_item( $args, $result );
152
 
153
  $output .= crp_list_link( $args, $result );
@@ -274,7 +303,8 @@ function get_crp_posts_id( $args = array() ) {
274
 
275
  $limit = ( $args['strict_limit'] ) ? $args['limit'] : ( $args['limit'] * 3 );
276
 
277
- parse_str( $args['post_types'], $post_types ); // Save post types in $post_types variable
 
278
 
279
  /**
280
  * Filter the post_type clause of the query.
@@ -335,7 +365,7 @@ function get_crp_posts_id( $args = array() ) {
335
  $from_date = gmdate( 'Y-m-d H:i:s' , $from_date );
336
 
337
  // Create the SQL query to fetch the related posts from the database
338
- if ( ( is_int( $post->ID ) ) && ( '' != $stuff ) ) {
339
 
340
  // Fields to return
341
  $fields = " $wpdb->posts.ID ";
@@ -871,6 +901,32 @@ add_action( 'wpmu_new_blog', 'crp_activate_new_site' );
871
 
872
 
873
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
874
  /*----------------------------------------------------------------------------*
875
  * WordPress widget
876
  *----------------------------------------------------------------------------*/
@@ -894,7 +950,7 @@ add_action( 'widgets_init', 'register_crp_widget' );
894
  *----------------------------------------------------------------------------*/
895
 
896
  require_once( plugin_dir_path( __FILE__ ) . 'includes/output-generator.php' );
897
- require_once( plugin_dir_path( __FILE__ ) . 'includes/media-handler.php' );
898
  require_once( plugin_dir_path( __FILE__ ) . 'includes/tools.php' );
899
  require_once( plugin_dir_path( __FILE__ ) . 'includes/modules/manual-posts.php' );
900
  require_once( plugin_dir_path( __FILE__ ) . 'includes/modules/shortcode.php' );
15
  * Plugin Name: Contextual Related Posts
16
  * Plugin URI: https://webberzone.com/plugins/contextual-related-posts/
17
  * Description: Display a set of related posts on your website or in your feed. Increase reader retention and reduce bounce rates
18
+ * Version: 2.2.2
19
  * Author: WebberZone
20
  * Author URI: https://webberzone.com
21
  * Text Domain: crp
89
  function get_crp( $args = array() ) {
90
  global $wpdb, $post, $crp_settings;
91
 
92
+ // if set, save $exclude_categories
93
+ if ( isset( $args['exclude_categories'] ) && '' != $args['exclude_categories'] ) {
94
+ $exclude_categories = explode( ",", $args['exclude_categories'] );
95
+ $args['strict_limit'] = FALSE;
96
+ }
97
+
98
  $defaults = array(
99
  'is_widget' => FALSE,
100
  'is_manual' => FALSE,
124
  }
125
  }
126
 
 
 
127
  // Retrieve the list of posts
128
  $results = get_crp_posts_id( array_merge( $args, array(
129
  'postid' => $post->ID,
130
+ 'strict_limit' => ( isset( $args['strict_limit'] ) ) ? $args['strict_limit'] : TRUE,
131
  ) ) );
132
 
133
  $output = ( is_singular() ) ? '<div id="crp_related" class="crp_related' . ( $args['is_widget'] ? '_widget' : '' ) . '">' : '<div class="crp_related' . ( $args['is_widget'] ? '_widget' : '' ) . '">';
139
 
140
  $output .= crp_before_list( $args );
141
 
142
+ // We need this for WPML support
143
+ $processed_results = array();
144
+
145
  foreach ( $results as $result ) {
146
 
147
+ /* Support WPML */
148
+ $resultid = crp_object_id_cur_lang( $result->ID );
149
+
150
+ if ( in_array( $resultid, $processed_results ) ) {
151
+ continue;
152
+ }
153
+
154
+ array_push( $processed_results, $resultid );
155
+
156
  /**
157
  * Filter the post ID for each result. Allows a custom function to hook in and change the ID if needed.
158
  *
164
 
165
  $result = get_post( $resultid ); // Let's get the Post using the ID
166
 
167
+ // Process the category exclusion if passed in the shortcode
168
+ if ( isset( $exclude_categories ) ) {
169
+
170
+ $categorys = get_the_category( $result->ID ); //Fetch categories of the plugin
171
+
172
+ $p_in_c = false; // Variable to check if post exists in a particular category
173
+ foreach ( $categorys as $cat ) { // Loop to check if post exists in excluded category
174
+ $p_in_c = ( in_array( $cat->cat_ID, $exclude_categories ) ) ? true : false;
175
+ if ( $p_in_c ) break; // Skip loop execution and go to the next step
176
+ }
177
+ if ( $p_in_c ) continue; // Skip loop execution and go to the next step
178
+ }
179
+
180
  $output .= crp_before_list_item( $args, $result );
181
 
182
  $output .= crp_list_link( $args, $result );
303
 
304
  $limit = ( $args['strict_limit'] ) ? $args['limit'] : ( $args['limit'] * 3 );
305
 
306
+ // Save post types in $post_types variable
307
+ parse_str( $args['post_types'], $post_types );
308
 
309
  /**
310
  * Filter the post_type clause of the query.
365
  $from_date = gmdate( 'Y-m-d H:i:s' , $from_date );
366
 
367
  // Create the SQL query to fetch the related posts from the database
368
+ if ( is_int( $post->ID ) ) {
369
 
370
  // Fields to return
371
  $fields = " $wpdb->posts.ID ";
901
 
902
 
903
 
904
+ /**
905
+ * Returns the object identifier for the current language (WPML).
906
+ *
907
+ * @since 2.1.0
908
+ *
909
+ * @param $post_id Post ID
910
+ */
911
+ function crp_object_id_cur_lang( $post_id ) {
912
+
913
+ if ( function_exists( 'wpml_object_id' ) ) {
914
+ $post_id = wpml_object_id( $post_id, 'post', TRUE );
915
+ } elseif ( function_exists( 'icl_object_id' ) ) {
916
+ $post_id = icl_object_id( $post_id, 'post', TRUE );
917
+ }
918
+
919
+ /**
920
+ * Filters object ID for current language (WPML).
921
+ *
922
+ * @since 2.1.0
923
+ *
924
+ * @param int $post_id Post ID
925
+ */
926
+ return apply_filters( 'crp_object_id_cur_lang', $post_id );
927
+ }
928
+
929
+
930
  /*----------------------------------------------------------------------------*
931
  * WordPress widget
932
  *----------------------------------------------------------------------------*/
950
  *----------------------------------------------------------------------------*/
951
 
952
  require_once( plugin_dir_path( __FILE__ ) . 'includes/output-generator.php' );
953
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/media.php' );
954
  require_once( plugin_dir_path( __FILE__ ) . 'includes/tools.php' );
955
  require_once( plugin_dir_path( __FILE__ ) . 'includes/modules/manual-posts.php' );
956
  require_once( plugin_dir_path( __FILE__ ) . 'includes/modules/shortcode.php' );
includes/{media-handler.php → media.php} RENAMED
@@ -79,6 +79,16 @@ function crp_get_the_post_thumbnail( $args = array() ) {
79
  $result = get_post( $args['postid'] );
80
  $post_title = get_the_title( $args['postid'] );
81
 
 
 
 
 
 
 
 
 
 
 
82
  $output = '';
83
  $postimage = '';
84
 
@@ -99,7 +109,21 @@ function crp_get_the_post_thumbnail( $args = array() ) {
99
 
100
  // If there is no thumbnail found, fetch the first image in the post, if enabled
101
  if ( ! $postimage && $args['scan_images'] ) {
102
- preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $result->post_content, $matches );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  if ( isset( $matches[1][0] ) && $matches[1][0] ) { // any image there?
104
  $postimage = $matches[1][0]; // we need the first one only!
105
  }
@@ -192,7 +216,17 @@ function crp_get_the_post_thumbnail( $args = array() ) {
192
  $thumb_html = apply_filters( 'crp_thumb_html', $thumb_html );
193
 
194
  $class = $args['class'] . ' crp_' . $pick;
195
- $output .= '<img src="' . $postimage . '" alt="' . $post_title . '" title="' . $post_title . '" ' . $thumb_html . ' class="' . $args['class'] . '" />';
 
 
 
 
 
 
 
 
 
 
196
  }
197
 
198
  /**
79
  $result = get_post( $args['postid'] );
80
  $post_title = get_the_title( $args['postid'] );
81
 
82
+ /**
83
+ * Filters the title and alt message for thumbnails.
84
+ *
85
+ * @since 2.2.2
86
+ *
87
+ * @param string $post_title Post tile used as thumbnail alt and title
88
+ * @param object $result Post Object
89
+ */
90
+ $post_title = apply_filters( 'crp_thumb_title', $post_title, $result );
91
+
92
  $output = '';
93
  $postimage = '';
94
 
109
 
110
  // If there is no thumbnail found, fetch the first image in the post, if enabled
111
  if ( ! $postimage && $args['scan_images'] ) {
112
+
113
+ /**
114
+ * Filters the post content that is used to scan for images.
115
+ *
116
+ * A filter function can be tapped into this to execute shortcodes, modify content, etc.
117
+ *
118
+ * @since 2.2.2
119
+ *
120
+ * @param string $result->post_content Post content
121
+ * @param object $result Post Object
122
+ */
123
+ $post_content = apply_filters( 'crp_thumb_post_content', $result->post_content, $result );
124
+
125
+ preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches );
126
+
127
  if ( isset( $matches[1][0] ) && $matches[1][0] ) { // any image there?
128
  $postimage = $matches[1][0]; // we need the first one only!
129
  }
216
  $thumb_html = apply_filters( 'crp_thumb_html', $thumb_html );
217
 
218
  $class = $args['class'] . ' crp_' . $pick;
219
+
220
+ /**
221
+ * Filters the thumbnail classes and allows a filter function to add any more classes if needed.
222
+ *
223
+ * @since 2.2.2
224
+ *
225
+ * @param string $thumb_html Thumbnail HTML
226
+ */
227
+ $class = apply_filters( 'crp_thumb_class', $class );
228
+
229
+ $output .= '<img src="' . $postimage . '" alt="' . $post_title . '" title="' . $post_title . '" ' . $thumb_html . ' class="' . $class . '" />';
230
  }
231
 
232
  /**
includes/tools.php CHANGED
@@ -140,16 +140,32 @@ function crp_create_index() {
140
 
141
  // If we're running mySQL v5.6, convert the WPDB posts table to InnoDB, since InnoDB supports FULLTEXT from v5.6 onwards
142
  if ( version_compare( 5.6, $wpdb->db_version(), '<=' ) ) {
143
- $wpdb->query( 'ALTER TABLE ' . $wpdb->posts . ' ENGINE = InnoDB;' );
144
  } else {
145
- $wpdb->query( 'ALTER TABLE ' . $wpdb->posts . ' ENGINE = MYISAM;' );
146
  }
147
 
148
- $wpdb->query( 'ALTER TABLE ' . $wpdb->posts . ' ADD FULLTEXT crp_related (post_title, post_content);' );
149
- $wpdb->query( 'ALTER TABLE ' . $wpdb->posts . ' ADD FULLTEXT crp_related_title (post_title);' );
150
- $wpdb->query( 'ALTER TABLE ' . $wpdb->posts . ' ADD FULLTEXT crp_related_content (post_content);' );
 
 
151
 
152
- $wpdb->show_errors();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
  }
155
 
@@ -166,13 +182,13 @@ function crp_delete_index() {
166
  $wpdb->hide_errors();
167
 
168
  if ( $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related'" ) ) {
169
- $wpdb->query( "ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related" );
170
  }
171
  if ( $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related_title'" ) ) {
172
- $wpdb->query( "ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related_title" );
173
  }
174
  if ( $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related_content'" ) ) {
175
- $wpdb->query( "ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related_content" );
176
  }
177
 
178
  $wpdb->show_errors();
140
 
141
  // If we're running mySQL v5.6, convert the WPDB posts table to InnoDB, since InnoDB supports FULLTEXT from v5.6 onwards
142
  if ( version_compare( 5.6, $wpdb->db_version(), '<=' ) ) {
143
+ $table_engine = 'InnoDB';
144
  } else {
145
+ $table_engine = 'MyISAM';
146
  }
147
 
148
+ $current_engine = $wpdb->get_row( "
149
+ SELECT engine FROM INFORMATION_SCHEMA.TABLES
150
+ WHERE table_schema=DATABASE()
151
+ AND table_name = '{$wpdb->posts}'
152
+ " );
153
 
154
+ if ( $current_engine->engine != $table_engine ) {
155
+ $wpdb->query( "ALTER TABLE {$wpdb->posts} ENGINE = $table_engine;" );
156
+ }
157
+
158
+ if ( ! $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related'" ) ) {
159
+ $wpdb->query( "ALTER TABLE {$wpdb->posts} ADD FULLTEXT crp_related (post_title, post_content);" );
160
+ }
161
+ if ( ! $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related_title'" ) ) {
162
+ $wpdb->query( "ALTER TABLE {$wpdb->posts} ADD FULLTEXT crp_related_title (post_title);" );
163
+ }
164
+ if ( ! $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related_content'" ) ) {
165
+ $wpdb->query( "ALTER TABLE {$wpdb->posts} ADD FULLTEXT crp_related_content (post_content);" );
166
+ }
167
+
168
+ $wpdb->show_errors();
169
 
170
  }
171
 
182
  $wpdb->hide_errors();
183
 
184
  if ( $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related'" ) ) {
185
+ $wpdb->query( "ALTER TABLE {$wpdb->posts} DROP INDEX crp_related" );
186
  }
187
  if ( $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related_title'" ) ) {
188
+ $wpdb->query( "ALTER TABLE {$wpdb->posts} DROP INDEX crp_related_title" );
189
  }
190
  if ( $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related_content'" ) ) {
191
+ $wpdb->query( "ALTER TABLE {$wpdb->posts} DROP INDEX crp_related_content" );
192
  }
193
 
194
  $wpdb->show_errors();
readme.txt CHANGED
@@ -178,9 +178,21 @@ In addition to the above, the shortcode takes every option that the plugin suppo
178
 
179
  == Changelog ==
180
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  = 2.2.1 =
182
 
183
- * Bugfixes:
184
  * "No styles" would not get selected if "Rounded thumbnails' was enabled
185
  * "Recreate Index" caused a fatal error: Call to undefined function `crp_single_activate()`
186
  * Excerpt shortening was not working correctly
@@ -205,7 +217,7 @@ In addition to the above, the shortcode takes every option that the plugin suppo
205
  * `get_crp` takes an additional argument: `heading` (default is TRUE) that controls the display of the main heading (**Related Posts**)
206
  * Output of `echo_crp` will be cached in a separate meta key
207
 
208
- * Bugfixes:
209
  * First child now gets the correct thumbnail size
210
 
211
  * Deprecated:
@@ -233,14 +245,14 @@ In addition to the above, the shortcode takes every option that the plugin suppo
233
  * Meta-box will no longer be displayed on non-public post types
234
  * For first image, the plugin will attempt to seek the correct thumbnail size if available
235
 
236
- * Bugfixes:
237
  * Author link was incorrectly displayed multiple times in the list when Show Author was enabled
238
  * WP Notice Errors when using the Widget via the Customizer menu in WordPress
239
  * Incorrect thumbnail was pulled on attachment pages
240
 
241
  = 2.0.1 =
242
 
243
- * Bugfixes:
244
  * Clear Cache button which broke in 2.0.0
245
 
246
  = 2.0.0 =
@@ -258,7 +270,7 @@ In addition to the above, the shortcode takes every option that the plugin suppo
258
  * `get_crp_posts` has been deprecated. See `get_crp_posts_id` instead
259
  * Turning on the Default style will switch on thumbnails, correctly resize them and will also hide authors, excerpts and the post date
260
 
261
- * Bugfixes:
262
  * Post image will now be loaded over https if the visitor visits your site on https
263
 
264
  = Earlier versions =
@@ -268,7 +280,7 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
268
 
269
  == Upgrade Notice ==
270
 
271
- = 2.2.1 =
272
  * New features. Deprecated functions. Upgrade highly recommended. Please do verify your settings after the upgrade.
273
  Check the Changelog for more details
274
 
178
 
179
  == Changelog ==
180
 
181
+ = 2.2.2 =
182
+
183
+ * Features:
184
+ * Preliminary support for WPML
185
+
186
+ * Enhancements:
187
+ * Recreate Index and Activation will not try to alter the table engine if not needed
188
+
189
+ * Bug fixes:
190
+ * All thumbnail classes were not properly applied + new thumbnail class filter
191
+ * Shortcode with "exclude_categories" argument works again
192
+
193
  = 2.2.1 =
194
 
195
+ * Bug fixes:
196
  * "No styles" would not get selected if "Rounded thumbnails' was enabled
197
  * "Recreate Index" caused a fatal error: Call to undefined function `crp_single_activate()`
198
  * Excerpt shortening was not working correctly
217
  * `get_crp` takes an additional argument: `heading` (default is TRUE) that controls the display of the main heading (**Related Posts**)
218
  * Output of `echo_crp` will be cached in a separate meta key
219
 
220
+ * Bug fixes:
221
  * First child now gets the correct thumbnail size
222
 
223
  * Deprecated:
245
  * Meta-box will no longer be displayed on non-public post types
246
  * For first image, the plugin will attempt to seek the correct thumbnail size if available
247
 
248
+ * Bug fixes:
249
  * Author link was incorrectly displayed multiple times in the list when Show Author was enabled
250
  * WP Notice Errors when using the Widget via the Customizer menu in WordPress
251
  * Incorrect thumbnail was pulled on attachment pages
252
 
253
  = 2.0.1 =
254
 
255
+ * Bug fixes:
256
  * Clear Cache button which broke in 2.0.0
257
 
258
  = 2.0.0 =
270
  * `get_crp_posts` has been deprecated. See `get_crp_posts_id` instead
271
  * Turning on the Default style will switch on thumbnails, correctly resize them and will also hide authors, excerpts and the post date
272
 
273
+ * Bug fixes:
274
  * Post image will now be loaded over https if the visitor visits your site on https
275
 
276
  = Earlier versions =
280
 
281
  == Upgrade Notice ==
282
 
283
+ = 2.2.2 =
284
  * New features. Deprecated functions. Upgrade highly recommended. Please do verify your settings after the upgrade.
285
  Check the Changelog for more details
286