Contextual Related Posts - Version 3.1.0

Version Description

Release post: https://webberzone.com/blog/contextual-related-posts-v3-1-0/

  • Features:

    • REST API support - you can now fetch the related posts via the REST API. Fetch posts at /contextual-related-posts/v1/posts/<id>
    • New setting in the metabox to exclude specific terms
  • Enhancements/modifications:

    • Thumbnail function uses the size instead of exact array of sizes to better select the appropriate thumbnail image size
    • Use site icon if no other thumbnail is found
    • Use both post_title and post_content fields for matching even when match content setting is off
    • Passing post_type and posts_per_page arguments will be respected instead of being overridden
  • Bug fixes:

    • Don't enqueue wp-editor on widgets.php
    • WP_Query stopwords are stripped from content that is matched
    • Manual posts are added after the automatic posts are shuffled
Download this release

Release Info

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

Code changes from version 3.0.7 to 3.1.0

README.md CHANGED
@@ -3,12 +3,12 @@
3
  [![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/contextual-related-posts.svg?style=flat-square)](https://wordpress.org/plugins/contextual-related-posts/)
4
  [![License](https://img.shields.io/badge/license-GPL_v2%2B-orange.svg?style=flat-square)](http://opensource.org/licenses/GPL-2.0)
5
  [![WordPress Tested](https://img.shields.io/wordpress/v/contextual-related-posts.svg?style=flat-square)](https://wordpress.org/plugins/contextual-related-posts/)
6
- [![Build Status](https://travis-ci.org/WebberZone/contextual-related-posts.svg?branch=master)](https://travis-ci.org/WebberZone/contextual-related-posts)
7
- [![Code Climate](https://codeclimate.com/github/WebberZone/contextual-related-posts/badges/gpa.svg)](https://codeclimate.com/github/WebberZone/contextual-related-posts)
8
 
9
- __Requires:__ 5.0
10
 
11
- __Tested up to:__ 5.7
12
 
13
  __License:__ [GPL-2.0+](http://www.gnu.org/licenses/gpl-2.0.html)
14
 
@@ -33,6 +33,7 @@ And the default inbuilt styles allow you to switch between gorgeous thumbnail-ri
33
  * **Gutenberg / Block Editor support**: You can find a block called "Related Posts [CRP]" with its own configurable set of options
34
  * **Widgets**: Add related posts to widgetized area of your theme. Lots of options available
35
  * **Shortcode**: Use `[crp]` to display the posts anywhere you want in the post content
 
36
  * **The algorithm**: Find related posts by title and/or content of the current post
37
  * **Caching**: Related posts output is automatically cached as visitors browse through your site
38
  * **Exclusions**: Exclude posts from categories from being displayed in the list. Or you can exclude posts or pages by ID
3
  [![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/contextual-related-posts.svg?style=flat-square)](https://wordpress.org/plugins/contextual-related-posts/)
4
  [![License](https://img.shields.io/badge/license-GPL_v2%2B-orange.svg?style=flat-square)](http://opensource.org/licenses/GPL-2.0)
5
  [![WordPress Tested](https://img.shields.io/wordpress/v/contextual-related-posts.svg?style=flat-square)](https://wordpress.org/plugins/contextual-related-posts/)
6
+ [![Required PHP](https://img.shields.io/wordpress/plugin/required-php/contextual-related-posts?style=flat-square)](https://wordpress.org/plugins/contextual-related-posts/)
7
+ [![Active installs](https://img.shields.io/wordpress/plugin/installs/contextual-related-posts?style=flat-square)](https://wordpress.org/plugins/contextual-related-posts/)
8
 
9
+ __Requires:__ 5.3
10
 
11
+ __Tested up to:__ 5.9
12
 
13
  __License:__ [GPL-2.0+](http://www.gnu.org/licenses/gpl-2.0.html)
14
 
33
  * **Gutenberg / Block Editor support**: You can find a block called "Related Posts [CRP]" with its own configurable set of options
34
  * **Widgets**: Add related posts to widgetized area of your theme. Lots of options available
35
  * **Shortcode**: Use `[crp]` to display the posts anywhere you want in the post content
36
+ * **REST API**: Fetch related posts at `contextual-related-posts/v1/posts/<id>/`
37
  * **The algorithm**: Find related posts by title and/or content of the current post
38
  * **Caching**: Related posts output is automatically cached as visitors browse through your site
39
  * **Exclusions**: Exclude posts from categories from being displayed in the list. Or you can exclude posts or pages by ID
changelog.txt CHANGED
@@ -2,6 +2,82 @@
2
 
3
  This is an archive of older changelog entries. Most recent entries are maintained in readme.txt
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  = 2.9.4 =
6
 
7
  Release post: [https://webberzone.com/blog/contextual-related-posts-v2-9-3/](https://webberzone.com/blog/contextual-related-posts-v2-9-3/)
2
 
3
  This is an archive of older changelog entries. Most recent entries are maintained in readme.txt
4
 
5
+ = 3.0.7 =
6
+
7
+ Release post: [https://webberzone.com/blog/contextual-related-posts-v3-0-0/](https://webberzone.com/blog/contextual-related-posts-v3-0-0/)
8
+
9
+ * Bug fix:
10
+ * Replicate old style of exclusion checking of option set in meta. Using the shortcode, manual or block will ignore the meta option to "Disable Related Posts display"
11
+
12
+ = 3.0.6 =
13
+
14
+ * Enhancement:
15
+ * Defining `CRP_CACHE_TIME` to `false` will disable expiry
16
+ * Introduced wpml-config.xml file. Title and Custom text for blank output can now be translated with Polylang (and potentially WPML)
17
+
18
+ * Bug fix:
19
+ * Exclude on categories did not work
20
+ * Posts would trigger a "SHOW FULL COLUMNS FROM" error if they had ' from' in the title
21
+ * Manual posts did not work properly - all post types and all posts are properly fetched now
22
+
23
+ = 3.0.5 =
24
+
25
+ * Bug fix:
26
+ * Certain posts would trigger a "SHOW FULL COLUMNS FROM" error
27
+ * Forced `.crp_related figure` margin to 0
28
+
29
+ = 3.0.4 =
30
+
31
+ * Enhancement/Modifications:
32
+ * `include_cat_ids` and `exclude_categories` will also accept custom taxonomy `term_taxonomy_id`s
33
+ * Thumbnail's `img` tag is wrapped in `<figure>`
34
+ * Remove extra checking for `exclude_categories` in `get_crp`
35
+ * Optimise deleting of cache entries when updating a post - post saving should be significantly faster
36
+
37
+ = 3.0.3 =
38
+
39
+ * Enhancement/Modifications:
40
+ * Grid style minimum width is now decided by the width of the thumbnail and long words are wrapped
41
+
42
+ * Bug fixes:
43
+ * Selecting No style created a 404 error
44
+ * Fixed issue with $attachment_id not being declared in some cases
45
+
46
+ = 3.0.2 =
47
+
48
+ * Bug fixes:
49
+ * Fixed issue where Related Posts newer than was set to 0 caused no posts to display
50
+ * Use the original arguments when setting the cache key for CRP_Query
51
+ * Selecting "Blank Output" didn't work
52
+
53
+ = 3.0.1 =
54
+
55
+ * Bug fixes:
56
+ * Fixed issue with help tab that broke some sites
57
+
58
+ = 3.0.0 =
59
+
60
+ * Features:
61
+ * New CRP_Query class for fetching related posts. This replaces `get_crp_posts_id()` which will be deprecated in a future version
62
+ * CRP Thumbnails now include the `loading="lazy"` attribute added in WordPress 5.5
63
+ * New parameter `more_link_text` that can be passed to `get_crp()` which holds the "read more". Recommended option to customize the more link text using the filter `crp_excerpt_more_link_text` or the more link element using `crp_excerpt_more_link`
64
+ * Three new styles: "Masonry" (like Pinterest), "Grid" and "Rounded thumbnails with CSS grid". Might not work with older browsers
65
+ * Imported settings of [Related Posts by Categories and Tags](https://webberzone.com/downloads/crp-taxonomy/). That plugin is now deprecated with this release.
66
+
67
+ * Enhancement/Modifications:
68
+ * If WPML or PolyLang are active, `get_crp_posts_id()` and `CRP_Query` will return the translated set of post IDs and external processing is no longer needed
69
+ * Use `wp_img_tag_add_srcset_and_sizes_attr()` to generate srcset and sizes attributes. The original code to display the srcset and sizes attributes will continue to be used
70
+ * Improved caching with inbuilt expiry. Use CRP_CACHE_TIME in your wp-config.php to set how long the cache should be set for. Default is one month
71
+ * CRP_MAX_WORDS has been reduced to 100
72
+ * Dropped the need for FULLTEXT index on post_content which should save some database space
73
+ * Deprecated the following filters: `get_crp_posts_id`, `crp_posts_now_date`, `crp_posts_from_date`, `crp_posts_fields`, `crp_posts_join`, `crp_posts_where`, `crp_posts_groupby`, `crp_posts_having`, `crp_posts_orderby`, `crp_posts_limits`, `get_crp_posts_id_short_circuit`
74
+
75
+ * Bug fixes:
76
+ * In the settings page, only built-in taxonomies were being incorrectly displayed
77
+ * If "before list item" is empty, then the output was blanked out
78
+ * Settings help has been fixed
79
+ * `crp_get_option` would return an incorrect value if $crp_settings global variable was not set
80
+
81
  = 2.9.4 =
82
 
83
  Release post: [https://webberzone.com/blog/contextual-related-posts-v2-9-3/](https://webberzone.com/blog/contextual-related-posts-v2-9-3/)
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: 3.0.7
19
  * Author: WebberZone
20
  * Author URI: https://webberzone.com
21
  * License: GPL-2.0+
@@ -38,7 +38,7 @@ if ( ! defined( 'WPINC' ) ) {
38
  * @var string Contextual Related Posts Version.
39
  */
40
  if ( ! defined( 'CRP_VERSION' ) ) {
41
- define( 'CRP_VERSION', '3.0.7' );
42
  }
43
 
44
 
@@ -120,6 +120,7 @@ require_once CRP_PLUGIN_DIR . 'includes/modules/cache.php';
120
  require_once CRP_PLUGIN_DIR . 'includes/modules/shortcode.php';
121
  require_once CRP_PLUGIN_DIR . 'includes/modules/taxonomies.php';
122
  require_once CRP_PLUGIN_DIR . 'includes/modules/exclusions.php';
 
123
  require_once CRP_PLUGIN_DIR . 'includes/modules/class-crp-widget.php';
124
  require_once CRP_PLUGIN_DIR . 'includes/admin/blocks/related-posts.php';
125
 
@@ -184,4 +185,3 @@ function crp_get_settings() {
184
  */
185
  return apply_filters( 'crp_get_settings', $settings );
186
  }
187
-
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: 3.1.0
19
  * Author: WebberZone
20
  * Author URI: https://webberzone.com
21
  * License: GPL-2.0+
38
  * @var string Contextual Related Posts Version.
39
  */
40
  if ( ! defined( 'CRP_VERSION' ) ) {
41
+ define( 'CRP_VERSION', '3.1.0' );
42
  }
43
 
44
 
120
  require_once CRP_PLUGIN_DIR . 'includes/modules/shortcode.php';
121
  require_once CRP_PLUGIN_DIR . 'includes/modules/taxonomies.php';
122
  require_once CRP_PLUGIN_DIR . 'includes/modules/exclusions.php';
123
+ require_once CRP_PLUGIN_DIR . 'includes/modules/class-crp-rest-api.php';
124
  require_once CRP_PLUGIN_DIR . 'includes/modules/class-crp-widget.php';
125
  require_once CRP_PLUGIN_DIR . 'includes/admin/blocks/related-posts.php';
126
 
185
  */
186
  return apply_filters( 'crp_get_settings', $settings );
187
  }
 
includes/admin/blocks/related-posts.php CHANGED
@@ -47,24 +47,27 @@ function render_crp_block( $attributes ) {
47
  * @since 2.8.0
48
  */
49
  function crp_block_init() {
 
50
  // Skip block registration if Gutenberg is not enabled/merged.
51
  if ( ! function_exists( 'register_block_type' ) ) {
52
  return;
53
  }
54
- $dir = dirname( __FILE__ );
 
55
 
56
- $index_js = 'related-posts/index.min.js';
 
 
 
 
 
 
 
 
57
  wp_register_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
58
  'related-posts-block-editor',
59
  plugins_url( $index_js, __FILE__ ),
60
- array(
61
- 'wp-blocks',
62
- 'wp-i18n',
63
- 'wp-element',
64
- 'wp-components',
65
- 'wp-block-editor',
66
- 'wp-editor',
67
- ),
68
  filemtime( "$dir/$index_js" )
69
  );
70
 
47
  * @since 2.8.0
48
  */
49
  function crp_block_init() {
50
+ global $pagenow;
51
  // Skip block registration if Gutenberg is not enabled/merged.
52
  if ( ! function_exists( 'register_block_type' ) ) {
53
  return;
54
  }
55
+ $dir = dirname( __FILE__ );
56
+ $file_prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
57
 
58
+ $dependencies = array( 'wp-element', 'wp-blocks', 'wp-components', 'wp-i18n' );
59
+
60
+ if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
61
+ array_push( $dependencies, 'wp-editor', 'wp-edit-post', 'wp-block-editor' );
62
+ } elseif ( 'widgets.php' === $pagenow ) {
63
+ array_push( $dependencies, 'wp-edit-widgets' );
64
+ }
65
+
66
+ $index_js = "related-posts/index{$file_prefix}.js";
67
  wp_register_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
68
  'related-posts-block-editor',
69
  plugins_url( $index_js, __FILE__ ),
70
+ $dependencies,
 
 
 
 
 
 
 
71
  filemtime( "$dir/$index_js" )
72
  );
73
 
includes/admin/default-settings.php CHANGED
@@ -389,7 +389,7 @@ function crp_settings_list() {
389
  'name' => esc_html__( 'Related posts should be newer than', 'contextual-related-posts' ),
390
  'desc' => esc_html__( 'This sets the cut-off period for which posts will be displayed. e.g. setting it to 365 will show related posts from the last year only. Set to 0 to disable limiting posts by date.', 'contextual-related-posts' ),
391
  'type' => 'number',
392
- 'options' => '1095',
393
  'min' => '0',
394
  ),
395
  'ordering' => array(
@@ -412,7 +412,7 @@ function crp_settings_list() {
412
  'name' => esc_html__( 'Related posts based on title and content', 'contextual-related-posts' ),
413
  'desc' => esc_html__( 'If unchecked, only posts titles are used. Enable the cache if enabling this option for better performance. Each site is different, so toggle this option to see which setting gives you better quality related posts.', 'contextual-related-posts' ),
414
  'type' => 'checkbox',
415
- 'options' => false,
416
  ),
417
  'match_content_words' => array(
418
  'id' => 'match_content_words',
389
  'name' => esc_html__( 'Related posts should be newer than', 'contextual-related-posts' ),
390
  'desc' => esc_html__( 'This sets the cut-off period for which posts will be displayed. e.g. setting it to 365 will show related posts from the last year only. Set to 0 to disable limiting posts by date.', 'contextual-related-posts' ),
391
  'type' => 'number',
392
+ 'options' => '0',
393
  'min' => '0',
394
  ),
395
  'ordering' => array(
412
  'name' => esc_html__( 'Related posts based on title and content', 'contextual-related-posts' ),
413
  'desc' => esc_html__( 'If unchecked, only posts titles are used. Enable the cache if enabling this option for better performance. Each site is different, so toggle this option to see which setting gives you better quality related posts.', 'contextual-related-posts' ),
414
  'type' => 'checkbox',
415
+ 'options' => true,
416
  ),
417
  'match_content_words' => array(
418
  'id' => 'match_content_words',
includes/admin/images/paypal_donate_button.gif ADDED
Binary file
includes/admin/modules/metabox.php CHANGED
@@ -72,39 +72,27 @@ function crp_call_meta_box() {
72
  wp_nonce_field( 'crp_meta_box', 'crp_meta_box_nonce' );
73
 
74
  // Get the thumbnail settings. The name of the meta key is defined in thumb_meta parameter of the CRP Settings array.
75
- $crp_thumb_meta = get_post_meta( $post->ID, crp_get_option( 'thumb_meta' ), true );
76
- $value = ( $crp_thumb_meta ) ? $crp_thumb_meta : '';
77
 
78
  // Get related posts specific meta.
79
- $crp_post_meta = get_post_meta( $post->ID, 'crp_post_meta', true );
80
 
81
  // Disable display option.
82
- if ( isset( $crp_post_meta['crp_disable_here'] ) ) {
83
- $disable_here = $crp_post_meta['crp_disable_here'];
84
- } else {
85
- $disable_here = 0;
86
- }
87
 
88
- if ( isset( $crp_post_meta['exclude_this_post'] ) ) {
89
- $exclude_this_post = $crp_post_meta['exclude_this_post'];
90
- } else {
91
- $exclude_this_post = 0;
92
- }
93
 
94
  // Manual related.
95
- if ( isset( $crp_post_meta['manual_related'] ) ) {
96
- $manual_related = $crp_post_meta['manual_related'];
97
- } else {
98
- $manual_related = '';
99
- }
100
  $manual_related_array = explode( ',', $manual_related );
101
 
102
  // Keyword - word or phrase.
103
- if ( isset( $crp_post_meta['keyword'] ) ) {
104
- $keyword = $crp_post_meta['keyword'];
105
- } else {
106
- $keyword = '';
107
- }
108
 
109
  ?>
110
  <p>
@@ -127,6 +115,12 @@ function crp_call_meta_box() {
127
  <em><?php esc_html_e( 'Enter either a word or a phrase that will be used to find related posts. If entered, the plugin will continue to search the `post_title` and `post_content` fields but will use this keyword instead of the values of the title and content of this post.', 'contextual-related-posts' ); ?></em>
128
  </p>
129
 
 
 
 
 
 
 
130
  <p>
131
  <label for="manual_related"><strong><?php esc_html_e( 'Manual related posts:', 'contextual-related-posts' ); ?></strong></label>
132
  <input type="text" id="manual_related" name="manual_related" value="<?php echo esc_attr( $manual_related ); ?>" style="width:100%" />
@@ -171,7 +165,7 @@ function crp_call_meta_box() {
171
  </p>
172
 
173
  <?php
174
- if ( $crp_thumb_meta ) {
175
  echo '<img src="' . esc_attr( $value ) . '" style="max-width:100%" />';
176
  }
177
  ?>
@@ -197,7 +191,7 @@ function crp_call_meta_box() {
197
  */
198
  function crp_save_meta_box( $post_id ) {
199
 
200
- $crp_post_meta = array();
201
 
202
  // Bail if we're doing an auto save.
203
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
@@ -227,19 +221,23 @@ function crp_save_meta_box( $post_id ) {
227
 
228
  // Disable posts.
229
  if ( isset( $_POST['crp_disable_here'] ) ) {
230
- $crp_post_meta['crp_disable_here'] = 1;
231
  } else {
232
- $crp_post_meta['crp_disable_here'] = 0;
233
  }
234
 
235
  if ( isset( $_POST['crp_exclude_this_post'] ) ) {
236
- $crp_post_meta['exclude_this_post'] = 1;
237
  } else {
238
- $crp_post_meta['exclude_this_post'] = 0;
239
  }
240
 
241
  if ( isset( $_POST['crp_keyword'] ) ) {
242
- $crp_post_meta['keyword'] = sanitize_text_field( wp_unslash( $_POST['crp_keyword'] ) );
 
 
 
 
243
  }
244
 
245
  // Save Manual related posts.
@@ -252,7 +250,7 @@ function crp_save_meta_box( $post_id ) {
252
  unset( $manual_related_array[ $key ] );
253
  }
254
  }
255
- $crp_post_meta['manual_related'] = implode( ',', $manual_related_array );
256
  }
257
 
258
  /**
@@ -260,18 +258,18 @@ function crp_save_meta_box( $post_id ) {
260
  *
261
  * @since 2.2.0
262
  *
263
- * @param array $crp_post_meta CRP post-specific settings
264
  * @param int $post_id Post ID
265
  */
266
- $crp_post_meta = apply_filters( 'crp_post_meta', $crp_post_meta, $post_id );
267
 
268
- $crp_post_meta_filtered = array_filter( $crp_post_meta );
269
 
270
  /**** Now we can start saving */
271
- if ( empty( $crp_post_meta_filtered ) ) { // Checks if all the array items are 0 or empty.
272
  delete_post_meta( $post_id, 'crp_post_meta' ); // Delete the post meta if no options are set.
273
  } else {
274
- update_post_meta( $post_id, 'crp_post_meta', $crp_post_meta_filtered );
275
  }
276
 
277
  /**
@@ -285,4 +283,3 @@ function crp_save_meta_box( $post_id ) {
285
  }
286
  add_action( 'save_post', 'crp_save_meta_box' );
287
  add_action( 'edit_attachment', 'crp_save_meta_box' );
288
-
72
  wp_nonce_field( 'crp_meta_box', 'crp_meta_box_nonce' );
73
 
74
  // Get the thumbnail settings. The name of the meta key is defined in thumb_meta parameter of the CRP Settings array.
75
+ $thumb_meta = get_post_meta( $post->ID, crp_get_option( 'thumb_meta' ), true );
76
+ $value = ( $thumb_meta ) ? $thumb_meta : '';
77
 
78
  // Get related posts specific meta.
79
+ $post_meta = get_post_meta( $post->ID, 'crp_post_meta', true );
80
 
81
  // Disable display option.
82
+ $disable_here = isset( $post_meta['crp_disable_here'] ) ? $post_meta['crp_disable_here'] : 0;
 
 
 
 
83
 
84
+ // Exclude this post.
85
+ $exclude_this_post = isset( $post_meta['exclude_this_post'] ) ? $post_meta['exclude_this_post'] : 0;
 
 
 
86
 
87
  // Manual related.
88
+ $manual_related = isset( $post_meta['manual_related'] ) ? $post_meta['manual_related'] : '';
 
 
 
 
89
  $manual_related_array = explode( ',', $manual_related );
90
 
91
  // Keyword - word or phrase.
92
+ $keyword = isset( $post_meta['keyword'] ) ? $post_meta['keyword'] : '';
93
+
94
+ // Exclude terms.
95
+ $exclude_words = isset( $post_meta['exclude_words'] ) ? $post_meta['exclude_words'] : '';
 
96
 
97
  ?>
98
  <p>
115
  <em><?php esc_html_e( 'Enter either a word or a phrase that will be used to find related posts. If entered, the plugin will continue to search the `post_title` and `post_content` fields but will use this keyword instead of the values of the title and content of this post.', 'contextual-related-posts' ); ?></em>
116
  </p>
117
 
118
+ <p>
119
+ <label for="exclude_words"><strong><?php esc_html_e( 'Exclude terms:', 'contextual-related-posts' ); ?></strong></label>
120
+ <textarea class="large-text" cols="50" rows="5" id="crp_exclude_words" name="crp_exclude_words"><?php echo esc_textarea( stripslashes( $exclude_words ) ); ?></textarea>
121
+ <em><?php esc_html_e( "Enter a comma-separated list of terms. If a related post's title or content contains any of these terms then it will be excluded from the results.", 'contextual-related-posts' ); ?></em>
122
+ </p>
123
+
124
  <p>
125
  <label for="manual_related"><strong><?php esc_html_e( 'Manual related posts:', 'contextual-related-posts' ); ?></strong></label>
126
  <input type="text" id="manual_related" name="manual_related" value="<?php echo esc_attr( $manual_related ); ?>" style="width:100%" />
165
  </p>
166
 
167
  <?php
168
+ if ( $thumb_meta ) {
169
  echo '<img src="' . esc_attr( $value ) . '" style="max-width:100%" />';
170
  }
171
  ?>
191
  */
192
  function crp_save_meta_box( $post_id ) {
193
 
194
+ $post_meta = array();
195
 
196
  // Bail if we're doing an auto save.
197
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
221
 
222
  // Disable posts.
223
  if ( isset( $_POST['crp_disable_here'] ) ) {
224
+ $post_meta['crp_disable_here'] = 1;
225
  } else {
226
+ $post_meta['crp_disable_here'] = 0;
227
  }
228
 
229
  if ( isset( $_POST['crp_exclude_this_post'] ) ) {
230
+ $post_meta['exclude_this_post'] = 1;
231
  } else {
232
+ $post_meta['exclude_this_post'] = 0;
233
  }
234
 
235
  if ( isset( $_POST['crp_keyword'] ) ) {
236
+ $post_meta['keyword'] = sanitize_text_field( wp_unslash( $_POST['crp_keyword'] ) );
237
+ }
238
+
239
+ if ( isset( $_POST['crp_exclude_words'] ) ) {
240
+ $post_meta['exclude_words'] = implode( ',', array_map( 'trim', explode( ',', sanitize_text_field( wp_unslash( $_POST['crp_exclude_words'] ) ) ) ) );
241
  }
242
 
243
  // Save Manual related posts.
250
  unset( $manual_related_array[ $key ] );
251
  }
252
  }
253
+ $post_meta['manual_related'] = implode( ',', $manual_related_array );
254
  }
255
 
256
  /**
258
  *
259
  * @since 2.2.0
260
  *
261
+ * @param array $post_meta CRP post-specific settings
262
  * @param int $post_id Post ID
263
  */
264
+ $post_meta = apply_filters( 'crp_post_meta', $post_meta, $post_id );
265
 
266
+ $post_meta_filtered = array_filter( $post_meta );
267
 
268
  /**** Now we can start saving */
269
+ if ( empty( $post_meta_filtered ) ) { // Checks if all the array items are 0 or empty.
270
  delete_post_meta( $post_id, 'crp_post_meta' ); // Delete the post meta if no options are set.
271
  } else {
272
+ update_post_meta( $post_id, 'crp_post_meta', $post_meta_filtered );
273
  }
274
 
275
  /**
283
  }
284
  add_action( 'save_post', 'crp_save_meta_box' );
285
  add_action( 'edit_attachment', 'crp_save_meta_box' );
 
includes/admin/settings-page.php CHANGED
@@ -274,7 +274,7 @@ function crp_textarea_callback( $args ) {
274
 
275
  $class = sanitize_html_class( $args['field_class'] );
276
 
277
- $html = sprintf( '<textarea class="%3$s" cols="50" rows="20" id="crp_settings[%1$s]" name="crp_settings[%1$s]">%2$s</textarea>', sanitize_key( $args['id'] ), esc_textarea( stripslashes( $value ) ), 'large-text ' . $class );
278
  $html .= '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
279
 
280
  /** This filter has been defined in settings-page.php */
274
 
275
  $class = sanitize_html_class( $args['field_class'] );
276
 
277
+ $html = sprintf( '<textarea class="%3$s" cols="50" rows="10" id="crp_settings[%1$s]" name="crp_settings[%1$s]">%2$s</textarea>', sanitize_key( $args['id'] ), esc_textarea( stripslashes( $value ) ), 'large-text ' . $class );
278
  $html .= '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
279
 
280
  /** This filter has been defined in settings-page.php */
includes/admin/sidebar.php CHANGED
@@ -30,7 +30,7 @@ if ( ! defined( 'WPINC' ) ) {
30
  <input type="hidden" name="currency_code" value="USD">
31
  <input type="hidden" name="button_subtype" value="services">
32
  <input type="hidden" name="bn" value="PP-BuyNowBF:btn_donate_LG.gif:NonHosted">
33
- <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="<?php esc_html_e( 'Send your donation to the author of', 'contextual-related-posts' ); ?> Contextual Related Posts">
34
  <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
35
  </form>
36
  </div>
30
  <input type="hidden" name="currency_code" value="USD">
31
  <input type="hidden" name="button_subtype" value="services">
32
  <input type="hidden" name="bn" value="PP-BuyNowBF:btn_donate_LG.gif:NonHosted">
33
+ <input type="image" src="<?php echo esc_url( CRP_PLUGIN_URL . 'includes/admin/images/paypal_donate_button.gif' ); ?>" border="0" name="submit" alt="<?php esc_html_e( 'Send your donation to the author of', 'contextual-related-posts' ); ?> Contextual Related Posts">
34
  <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
35
  </form>
36
  </div>
includes/class-crp-query.php CHANGED
@@ -179,28 +179,46 @@ if ( ! class_exists( 'CRP_Query' ) ) :
179
  }
180
  $this->random_order = $random_order;
181
 
182
- // Set the number of posts to be retrieved.
183
- $args['posts_per_page'] = ( $args['strict_limit'] ) ? $args['limit'] : ( $args['limit'] * 3 );
184
-
185
- // If post_types is empty or contains a query string then use parse_str else consider it comma-separated.
186
- if ( ! empty( $args['post_types'] ) && false === strpos( $args['post_types'], '=' ) ) {
187
- $post_types = explode( ',', $args['post_types'] );
188
- } else {
189
- parse_str( $args['post_types'], $post_types ); // Save post types in $post_types variable.
190
  }
191
 
192
- // If post_types is empty or if we want all the post types.
193
- if ( empty( $post_types ) || 'all' === $args['post_types'] ) {
194
- $post_types = get_post_types(
195
- array(
196
- 'public' => true,
197
- )
198
- );
199
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
 
201
- // If we only want posts from the same post type.
202
- if ( $args['same_post_type'] ) {
203
- $post_types = (array) $source_post->post_type;
204
  }
205
 
206
  // Tax Query.
@@ -272,18 +290,6 @@ if ( ! class_exists( 'CRP_Query' ) ) :
272
 
273
  $args['tax_query'] = $tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
274
 
275
- /**
276
- * Filter the post_types passed to the query.
277
- *
278
- * @since 2.2.0
279
- * @since 3.0.0 Changed second argument from post ID to WP_Post object.
280
- *
281
- * @param array $post_types Array of post types to filter by.
282
- * @param WP_Post $source_post Source Post instance.
283
- * @param array $args Arguments array.
284
- */
285
- $args['post_type'] = apply_filters( 'crp_posts_post_types', $post_types, $source_post, $args );
286
-
287
  // Set date_query.
288
  $args['date_query'] = array(
289
  array(
@@ -368,15 +374,15 @@ if ( ! class_exists( 'CRP_Query' ) ) :
368
  // Are we matching only the title or the post content as well?
369
  $match_fields = array(
370
  "$wpdb->posts.post_title",
 
371
  );
372
 
373
  $match_fields_content = array(
374
- str_ireplace( ' from', '', $this->source_post->post_title ),
375
  );
376
 
377
  if ( $this->query_args['match_content'] ) {
378
- $match_fields[] = "$wpdb->posts.post_content";
379
- $match_fields_content[] = str_ireplace( ' from', '', crp_excerpt( $this->source_post, min( $this->query_args['match_content_words'], CRP_MAX_WORDS ), false ) );
380
  }
381
 
382
  if ( isset( $this->crp_post_meta['keyword'] ) ) {
@@ -421,6 +427,31 @@ if ( ! class_exists( 'CRP_Query' ) ) :
421
  return $match;
422
  }
423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
  /**
425
  * Modify the SELECT clause - posts_fields.
426
  *
@@ -480,6 +511,7 @@ if ( ! class_exists( 'CRP_Query' ) ) :
480
  * @return string Updated WHERE
481
  */
482
  public function posts_where( $where, $query ) {
 
483
 
484
  // Return if it is not a CRP_Query.
485
  if ( true !== $query->get( 'crp_query' ) ) {
@@ -509,6 +541,28 @@ if ( ! class_exists( 'CRP_Query' ) ) :
509
  $where .= $match;
510
 
511
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  return $where;
513
  }
514
 
@@ -653,6 +707,11 @@ if ( ! class_exists( 'CRP_Query' ) ) :
653
  set_crp_cache( $this->source_post->ID, $meta_key, $post_ids );
654
  }
655
 
 
 
 
 
 
656
  // Manual Posts (manual_related - set via the Post Meta) or Include Posts (can be set as a parameter).
657
  $post_ids = array();
658
 
@@ -677,11 +736,6 @@ if ( ! class_exists( 'CRP_Query' ) ) :
677
  $posts = array_merge( $extra_posts, $posts );
678
  }
679
 
680
- // Shuffle posts if random order is set.
681
- if ( $this->random_order ) {
682
- shuffle( $posts );
683
- }
684
-
685
  /**
686
  * Filter array of WP_Post objects before it is returned to the CRP_Query instance.
687
  *
179
  }
180
  $this->random_order = $random_order;
181
 
182
+ // Set the number of posts to be retrieved. Use posts_per_page if set else use limit.
183
+ if ( empty( $args['posts_per_page'] ) ) {
184
+ $args['posts_per_page'] = ( $args['strict_limit'] ) ? $args['limit'] : ( $args['limit'] * 3 );
 
 
 
 
 
185
  }
186
 
187
+ if ( empty( $args['post_type'] ) ) {
188
+
189
+ // If post_types is empty or contains a query string then use parse_str else consider it comma-separated.
190
+ if ( ! empty( $args['post_types'] ) && false === strpos( $args['post_types'], '=' ) ) {
191
+ $post_types = explode( ',', $args['post_types'] );
192
+ } else {
193
+ parse_str( $args['post_types'], $post_types ); // Save post types in $post_types variable.
194
+ }
195
+
196
+ // If post_types is empty or if we want all the post types.
197
+ if ( empty( $post_types ) || 'all' === $args['post_types'] ) {
198
+ $post_types = get_post_types(
199
+ array(
200
+ 'public' => true,
201
+ )
202
+ );
203
+ }
204
+
205
+ // If we only want posts from the same post type.
206
+ if ( $args['same_post_type'] ) {
207
+ $post_types = (array) $source_post->post_type;
208
+ }
209
+
210
+ /**
211
+ * Filter the post_types passed to the query.
212
+ *
213
+ * @since 2.2.0
214
+ * @since 3.0.0 Changed second argument from post ID to WP_Post object.
215
+ *
216
+ * @param array $post_types Array of post types to filter by.
217
+ * @param WP_Post $source_post Source Post instance.
218
+ * @param array $args Arguments array.
219
+ */
220
+ $args['post_type'] = apply_filters( 'crp_posts_post_types', $post_types, $source_post, $args );
221
 
 
 
 
222
  }
223
 
224
  // Tax Query.
290
 
291
  $args['tax_query'] = $tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
292
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  // Set date_query.
294
  $args['date_query'] = array(
295
  array(
374
  // Are we matching only the title or the post content as well?
375
  $match_fields = array(
376
  "$wpdb->posts.post_title",
377
+ "$wpdb->posts.post_content",
378
  );
379
 
380
  $match_fields_content = array(
381
+ $this->strip_stopwords( $this->source_post->post_title ),
382
  );
383
 
384
  if ( $this->query_args['match_content'] ) {
385
+ $match_fields_content[] = $this->strip_stopwords( crp_excerpt( $this->source_post, min( $this->query_args['match_content_words'], CRP_MAX_WORDS ), false ) );
 
386
  }
387
 
388
  if ( isset( $this->crp_post_meta['keyword'] ) ) {
427
  return $match;
428
  }
429
 
430
+ /**
431
+ * Strip stopwords from text.
432
+ *
433
+ * @since 3.1.0
434
+ *
435
+ * @param string|array $subject The string or an array with strings to search and replace. .
436
+ * @param string|array $search The pattern to search for. It can be either a string or an array with strings.
437
+ * @param string|array $replace The string or an array with strings to replace.
438
+ */
439
+ public function strip_stopwords( $subject = '', $search = '', $replace = '' ) {
440
+
441
+ if ( empty( $search ) ) {
442
+ $search = $this->get_search_stopwords();
443
+ array_push( $search, 'from', 'where' );
444
+ }
445
+
446
+ foreach ( (array) $search as $s ) {
447
+ $pattern[] = '/\b' . $s . '\b/ui';
448
+ }
449
+ $output = preg_replace( $pattern, $replace, $subject );
450
+ $output = preg_replace( '/\s+/', ' ', $output );
451
+
452
+ return $output;
453
+ }
454
+
455
  /**
456
  * Modify the SELECT clause - posts_fields.
457
  *
511
  * @return string Updated WHERE
512
  */
513
  public function posts_where( $where, $query ) {
514
+ global $wpdb;
515
 
516
  // Return if it is not a CRP_Query.
517
  if ( true !== $query->get( 'crp_query' ) ) {
541
  $where .= $match;
542
 
543
  }
544
+
545
+ if ( isset( $this->crp_post_meta['exclude_words'] ) ) {
546
+
547
+ $n = '%';
548
+ $excludeand = '';
549
+ $exclude = '';
550
+
551
+ $exclude_words = explode( ',', $this->crp_post_meta['exclude_words'] );
552
+ $exclude_words = array_filter( $exclude_words );
553
+ foreach ( (array) $exclude_words as $word ) {
554
+ $like_op = 'NOT LIKE';
555
+ $andor_op = 'AND';
556
+ $like = $n . $wpdb->esc_like( strtolower( $word ) ) . $n;
557
+ $exclude .= $wpdb->prepare( "{$excludeand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
558
+ $excludeand = ' AND ';
559
+ }
560
+
561
+ if ( ! empty( $exclude ) ) {
562
+ $where .= " AND ({$exclude}) ";
563
+ }
564
+ }
565
+
566
  return $where;
567
  }
568
 
707
  set_crp_cache( $this->source_post->ID, $meta_key, $post_ids );
708
  }
709
 
710
+ // Shuffle posts if random order is set.
711
+ if ( $this->random_order ) {
712
+ shuffle( $posts );
713
+ }
714
+
715
  // Manual Posts (manual_related - set via the Post Meta) or Include Posts (can be set as a parameter).
716
  $post_ids = array();
717
 
736
  $posts = array_merge( $extra_posts, $posts );
737
  }
738
 
 
 
 
 
 
739
  /**
740
  * Filter array of WP_Post objects before it is returned to the CRP_Query instance.
741
  *
includes/media.php CHANGED
@@ -39,6 +39,9 @@ add_action( 'init', 'crp_add_image_sizes' );
39
  * Function to get the post thumbnail.
40
  *
41
  * @since 1.7
 
 
 
42
  *
43
  * @param array|string $args Array / Query string with arguments post thumbnails.
44
  * @return string Output with the post thumbnail
@@ -46,37 +49,30 @@ add_action( 'init', 'crp_add_image_sizes' );
46
  function crp_get_the_post_thumbnail( $args = array() ) {
47
 
48
  $defaults = array(
49
- 'postid' => '',
50
- 'thumb_height' => '150', // Max height of thumbnails.
51
- 'thumb_width' => '150', // Max width of thumbnails.
52
  'thumb_meta' => 'post-image', // Meta field that is used to store the location of default thumbnail image.
53
  'thumb_html' => 'html', // HTML / CSS for width and height attributes.
54
  'thumb_default' => '', // Default thumbnail image.
55
  'thumb_default_show' => true, // Show default thumb if none found (if false, don't show thumb at all).
56
- 'scan_images' => false, // Scan post for images.
57
  'class' => 'crp_thumb', // Class of the thumbnail.
58
  );
59
 
60
  // Parse incomming $args into an array and merge it with $defaults.
61
  $args = wp_parse_args( $args, $defaults );
62
 
63
- // Issue notice for deprecated arguments.
64
- if ( isset( $args['thumb_timthumb'] ) ) {
65
- _deprecated_argument( __FUNCTION__, '2.1', esc_html__( 'thumb_timthumb argument has been deprecated', 'contextual-related-posts' ) );
66
- }
67
-
68
- if ( isset( $args['thumb_timthumb_q'] ) ) {
69
- _deprecated_argument( __FUNCTION__, '2.1', esc_html__( 'thumb_timthumb_q argument has been deprecated', 'contextual-related-posts' ) );
70
- }
71
 
72
- if ( isset( $args['filter'] ) ) {
73
- _deprecated_argument( __FUNCTION__, '2.1', esc_html__( 'filter argument has been deprecated', 'contextual-related-posts' ) );
74
  }
75
 
76
- if ( is_int( $args['postid'] ) ) {
77
- $result = get_post( $args['postid'] );
78
  } else {
79
- $result = $args['postid'];
 
80
  }
81
 
82
  $post_title = esc_attr( $result->post_title );
@@ -92,10 +88,10 @@ function crp_get_the_post_thumbnail( $args = array() ) {
92
  if ( $postimage ) {
93
  $attachment_id = crp_get_attachment_id_from_url( $postimage );
94
 
95
- $postthumb = wp_get_attachment_image_src( $attachment_id, array( $args['thumb_width'], $args['thumb_height'] ) );
96
  if ( false !== $postthumb ) {
97
- $postimage = $postthumb[0];
98
- $pick .= 'correct';
99
  }
100
  }
101
  }
@@ -105,10 +101,10 @@ function crp_get_the_post_thumbnail( $args = array() ) {
105
  if ( false !== get_post_thumbnail_id( $result->ID ) ) {
106
  $attachment_id = ( 'attachment' === $result->post_type ) ? $result->ID : get_post_thumbnail_id( $result->ID );
107
 
108
- $postthumb = wp_get_attachment_image_src( $attachment_id, array( $args['thumb_width'], $args['thumb_height'] ) );
109
  if ( false !== $postthumb ) {
110
- $postimage = $postthumb[0];
111
- $pick = 'featured';
112
  }
113
  }
114
  $pick = 'featured';
@@ -122,10 +118,10 @@ function crp_get_the_post_thumbnail( $args = array() ) {
122
  *
123
  * A filter function can be tapped into this to execute shortcodes, modify content, etc.
124
  *
125
- * @since 2.2.2
126
  *
127
- * @param string $result->post_content Post content
128
- * @param object $result Post Object
129
  */
130
  $post_content = apply_filters( 'crp_thumb_post_content', $result->post_content, $result );
131
 
@@ -137,10 +133,10 @@ function crp_get_the_post_thumbnail( $args = array() ) {
137
  if ( $postimage ) {
138
  $attachment_id = crp_get_attachment_id_from_url( $postimage );
139
 
140
- $postthumb = wp_get_attachment_image_src( $attachment_id, array( $args['thumb_width'], $args['thumb_height'] ) );
141
  if ( false !== $postthumb ) {
142
- $postimage = $postthumb[0];
143
- $pick .= 'correct';
144
  }
145
  }
146
  }
@@ -157,6 +153,17 @@ function crp_get_the_post_thumbnail( $args = array() ) {
157
  $pick = 'video_thumb';
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
 
160
  // If no thumb found and settings permit, use default thumb.
161
  if ( ! $postimage && $args['thumb_default_show'] ) {
162
  $postimage = $args['thumb_default'];
@@ -172,14 +179,14 @@ function crp_get_the_post_thumbnail( $args = array() ) {
172
  * Use this filter to modify the thumbnail URL that is automatically created
173
  * Before v2.1 this was used for cropping the post image using timthumb
174
  *
175
- * @since 2.1.0
 
176
  *
177
- * @param string $postimage URL of the thumbnail image
178
- * @param int $thumb_width Thumbnail width
179
- * @param int $thumb_height Thumbnail height
180
- * @param object $result Post Object
181
  */
182
- $postimage = apply_filters( 'crp_thumb_url', $postimage, $args['thumb_width'], $args['thumb_height'], $result );
183
 
184
  if ( is_ssl() ) {
185
  $postimage = preg_replace( '~http://~', 'https://', $postimage );
@@ -213,8 +220,9 @@ function crp_get_the_post_thumbnail( $args = array() ) {
213
  * @since 2.6.0
214
  *
215
  * @param string $post_title Thumbnail title attribute
 
216
  */
217
- $attr['title'] = apply_filters( 'crp_thumb_title', $post_title );
218
 
219
  $attr['thumb_html'] = $args['thumb_html'];
220
  $attr['thumb_width'] = $args['thumb_width'];
@@ -467,41 +475,41 @@ function crp_get_attachment_id_from_url( $attachment_url = '' ) {
467
  * Function to get the correct height and width of the thumbnail.
468
  *
469
  * @since 2.9.0
 
470
  *
471
- * @param array $args Array of arguments.
472
- * @return array Width and height
473
  */
474
- function crp_get_thumb_size( $args ) {
 
 
 
 
 
 
475
 
476
  // Get thumbnail size.
477
- $crp_thumb_size = crp_get_all_image_sizes( $args['thumb_size'] );
478
 
479
  if ( isset( $crp_thumb_size['width'] ) ) {
480
  $thumb_width = $crp_thumb_size['width'];
481
  $thumb_height = $crp_thumb_size['height'];
482
  }
483
 
484
- if ( empty( $thumb_width ) || ( $args['is_widget'] && $thumb_width != $args['thumb_width'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
485
- $thumb_width = $args['thumb_width'];
486
- $args['thumb_html'] = 'css';
487
- }
488
-
489
- if ( empty( $thumb_height ) || ( $args['is_widget'] && $thumb_height != $args['thumb_height'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
490
- $thumb_height = $args['thumb_height'];
491
- $args['thumb_html'] = 'css';
492
  }
493
 
494
- $thumb_size = array( $thumb_width, $thumb_height );
495
-
496
  /**
497
  * Filter array of thumbnail size.
498
  *
499
- * @since 2.9.0
500
  *
501
- * @param array $thumb_size Array with width and height of thumbnail
502
- * @param array $args Array of arguments
503
  */
504
- return apply_filters( 'crp_get_thumb_size', $thumb_size, $args );
505
 
506
  }
507
 
@@ -559,4 +567,3 @@ function crp_get_all_image_sizes( $size = '' ) {
559
  */
560
  return apply_filters( 'crp_get_all_image_sizes', $sizes );
561
  }
562
-
39
  * Function to get the post thumbnail.
40
  *
41
  * @since 1.7
42
+ * @since 3.1.0 `postid` argument renamed to `post`.
43
+ * New `size` attribute added which can be a registered image size name or array of width and height.
44
+ * `thumb_width` and `thumb_height` attributes removed. These are extracted based on size.
45
  *
46
  * @param array|string $args Array / Query string with arguments post thumbnails.
47
  * @return string Output with the post thumbnail
49
  function crp_get_the_post_thumbnail( $args = array() ) {
50
 
51
  $defaults = array(
52
+ 'post' => '',
53
+ 'size' => 'post-thumbnail',
 
54
  'thumb_meta' => 'post-image', // Meta field that is used to store the location of default thumbnail image.
55
  'thumb_html' => 'html', // HTML / CSS for width and height attributes.
56
  'thumb_default' => '', // Default thumbnail image.
57
  'thumb_default_show' => true, // Show default thumb if none found (if false, don't show thumb at all).
58
+ 'scan_images' => true, // Scan post for images.
59
  'class' => 'crp_thumb', // Class of the thumbnail.
60
  );
61
 
62
  // Parse incomming $args into an array and merge it with $defaults.
63
  $args = wp_parse_args( $args, $defaults );
64
 
65
+ $result = get_post( $args['post'] );
 
 
 
 
 
 
 
66
 
67
+ if ( empty( $result ) ) {
68
+ return '';
69
  }
70
 
71
+ if ( is_string( $args['size'] ) ) {
72
+ list( $args['thumb_width'], $args['thumb_height'] ) = crp_get_thumb_size( $args['size'] );
73
  } else {
74
+ $args['thumb_width'] = $args['size'][0];
75
+ $args['thumb_height'] = $args['size'][1];
76
  }
77
 
78
  $post_title = esc_attr( $result->post_title );
88
  if ( $postimage ) {
89
  $attachment_id = crp_get_attachment_id_from_url( $postimage );
90
 
91
+ $postthumb = wp_get_attachment_image_src( $attachment_id, $args['size'] );
92
  if ( false !== $postthumb ) {
93
+ list( $postimage, $args['thumb_width'], $args['thumb_height'] ) = $postthumb;
94
+ $pick .= 'correct';
95
  }
96
  }
97
  }
101
  if ( false !== get_post_thumbnail_id( $result->ID ) ) {
102
  $attachment_id = ( 'attachment' === $result->post_type ) ? $result->ID : get_post_thumbnail_id( $result->ID );
103
 
104
+ $postthumb = wp_get_attachment_image_src( $attachment_id, $args['size'] );
105
  if ( false !== $postthumb ) {
106
+ list( $postimage, $args['thumb_width'], $args['thumb_height'] ) = $postthumb;
107
+ $pick = 'featured';
108
  }
109
  }
110
  $pick = 'featured';
118
  *
119
  * A filter function can be tapped into this to execute shortcodes, modify content, etc.
120
  *
121
+ * @since 2.2.2
122
  *
123
+ * @param string $result->post_content Post content
124
+ * @param object $result Post Object
125
  */
126
  $post_content = apply_filters( 'crp_thumb_post_content', $result->post_content, $result );
127
 
133
  if ( $postimage ) {
134
  $attachment_id = crp_get_attachment_id_from_url( $postimage );
135
 
136
+ $postthumb = wp_get_attachment_image_src( $attachment_id, $args['size'] );
137
  if ( false !== $postthumb ) {
138
+ list( $postimage, $args['thumb_width'], $args['thumb_height'] ) = $postthumb;
139
+ $pick .= 'correct';
140
  }
141
  }
142
  }
153
  $pick = 'video_thumb';
154
  }
155
 
156
+ // If no thumb found and settings permit, use site icon.
157
+ if ( ! $postimage ) {
158
+ $postimage = get_site_icon_url( max( $args['thumb_width'], $args['thumb_height'] ) );
159
+ $pick = 'site_icon_max';
160
+ }
161
+
162
+ if ( ! $postimage ) {
163
+ $postimage = get_site_icon_url( min( $args['thumb_width'], $args['thumb_height'] ) );
164
+ $pick = 'site_icon_min';
165
+ }
166
+
167
  // If no thumb found and settings permit, use default thumb.
168
  if ( ! $postimage && $args['thumb_default_show'] ) {
169
  $postimage = $args['thumb_default'];
179
  * Use this filter to modify the thumbnail URL that is automatically created
180
  * Before v2.1 this was used for cropping the post image using timthumb
181
  *
182
+ * @since 2.1.0
183
+ * @since 3.1.0 Second argument changed to $args array and third argument changed to Post object.
184
  *
185
+ * @param string $postimage URL of the thumbnail image
186
+ * @param array $args Arguments array.
187
+ * @param WP_Post $result Post Object
 
188
  */
189
+ $postimage = apply_filters( 'crp_thumb_url', $postimage, $args, $result );
190
 
191
  if ( is_ssl() ) {
192
  $postimage = preg_replace( '~http://~', 'https://', $postimage );
220
  * @since 2.6.0
221
  *
222
  * @param string $post_title Thumbnail title attribute
223
+ * @param array $args Argument array
224
  */
225
+ $attr['title'] = apply_filters( 'crp_thumb_title', $post_title, $args );
226
 
227
  $attr['thumb_html'] = $args['thumb_html'];
228
  $attr['thumb_width'] = $args['thumb_width'];
475
  * Function to get the correct height and width of the thumbnail.
476
  *
477
  * @since 2.9.0
478
+ * @since 3.1.0 First argument is a string.
479
  *
480
+ * @param string $size Image size.
481
+ * @return array Width and height. If no width and height is found, then 150 is returned for each.
482
  */
483
+ function crp_get_thumb_size( $size = 'thumbnail' ) {
484
+
485
+ if ( is_string( $size ) ) {
486
+ $thumb_size = $size;
487
+ } elseif ( isset( $size['thumb_size'] ) ) {
488
+ $thumb_size = $size['thumb_size'];
489
+ }
490
 
491
  // Get thumbnail size.
492
+ $crp_thumb_size = crp_get_all_image_sizes( $thumb_size );
493
 
494
  if ( isset( $crp_thumb_size['width'] ) ) {
495
  $thumb_width = $crp_thumb_size['width'];
496
  $thumb_height = $crp_thumb_size['height'];
497
  }
498
 
499
+ if ( isset( $thumb_width ) && isset( $thumb_height ) ) {
500
+ $thumb_size = array( $thumb_width, $thumb_height );
501
+ } else {
502
+ $thumb_size = array( 150, 150 );
 
 
 
 
503
  }
504
 
 
 
505
  /**
506
  * Filter array of thumbnail size.
507
  *
508
+ * @since 2.9.0
509
  *
510
+ * @param array $thumb_size Array with width and height of thumbnail
 
511
  */
512
+ return apply_filters( 'crp_get_thumb_size', $thumb_size );
513
 
514
  }
515
 
567
  */
568
  return apply_filters( 'crp_get_all_image_sizes', $sizes );
569
  }
 
includes/modules/class-crp-rest-api.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This class adds REST routes to update the count and return the list of related posts.
4
+ *
5
+ * @package CRP
6
+ */
7
+
8
+ // If this file is called directly, abort.
9
+ if ( ! defined( 'WPINC' ) ) {
10
+ die;
11
+ }
12
+
13
+ /**
14
+ * CRP_REST_API class.
15
+ *
16
+ * @since 3.1.0
17
+ */
18
+ class CRP_REST_API extends \WP_REST_Controller {
19
+
20
+ /**
21
+ * Main constructor.
22
+ *
23
+ * @since 3.1.0
24
+ */
25
+ public function __construct() {
26
+ $this->namespace = 'contextual-related-posts/v1';
27
+ $this->posts_route = 'posts';
28
+ }
29
+
30
+ /**
31
+ * Initialises the Top 10 REST API adding the necessary routes.
32
+ *
33
+ * @since 3.1.0
34
+ */
35
+ public function register_routes() {
36
+ register_rest_route(
37
+ $this->namespace,
38
+ '/' . $this->posts_route,
39
+ array(
40
+ 'methods' => \WP_REST_Server::READABLE,
41
+ 'callback' => array( $this, 'get_items' ),
42
+ 'permission_callback' => array( $this, 'permissions_check' ),
43
+ 'args' => $this->get_item_params(),
44
+ )
45
+ );
46
+ register_rest_route(
47
+ $this->namespace,
48
+ '/' . $this->posts_route . '/(?P<id>[\d]+)',
49
+ array(
50
+ 'methods' => \WP_REST_Server::READABLE,
51
+ 'callback' => array( $this, 'get_items' ),
52
+ 'permission_callback' => array( $this, 'permissions_check' ),
53
+ 'args' => $this->get_item_params(),
54
+ )
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Check if a given request has access to get items
60
+ *
61
+ * @param WP_REST_Request $request Full data about the request.
62
+ *
63
+ * @return WP_Error|bool
64
+ */
65
+ public function permissions_check( $request ) {
66
+ /**
67
+ * Permissions check flag for the CRP REST API.
68
+ *
69
+ * @since 3.1.0
70
+ *
71
+ * @param bool $flag Permisions flag.
72
+ * @param WP_REST_Response $request Array of post objects or post IDs.
73
+ */
74
+ return apply_filters( 'crp_rest_api_permissions_check', true, $request );
75
+ }
76
+
77
+ /**
78
+ * Get related posts.
79
+ *
80
+ * @since 3.1.0
81
+ *
82
+ * @param WP_REST_Request $request WP Rest request.
83
+ * @return mixed|\WP_REST_Response Array of post objects or post IDs.
84
+ */
85
+ public function get_items( $request ) {
86
+ $id = absint( $request->get_param( 'id' ) );
87
+
88
+ $error = new WP_Error(
89
+ 'rest_post_invalid_id',
90
+ __( 'Invalid post ID.', 'contextual-related-posts' ),
91
+ array( 'status' => 404 )
92
+ );
93
+
94
+ if ( $id <= 0 ) {
95
+ return $error;
96
+ }
97
+
98
+ $post = get_post( $id );
99
+ if ( empty( $post ) || empty( $post->ID ) || ! $this->check_read_permission( $post ) ) {
100
+ return $error;
101
+ }
102
+
103
+ $related_posts = array();
104
+
105
+ $args = $request->get_params();
106
+ $args['postid'] = $id;
107
+
108
+ /**
109
+ * Filter the REST API arguments before they passed to get_crp_posts().
110
+ *
111
+ * @since 3.1.0
112
+ *
113
+ * @param array $args Arguments array.
114
+ * @param WP_REST_Request $request WP Rest request.
115
+ */
116
+ $args = apply_filters( 'crp_rest_api_get_crp_posts_args', $args, $request );
117
+
118
+ $results = get_crp_posts( $args );
119
+
120
+ if ( is_array( $results ) && ! empty( $results ) ) {
121
+ foreach ( $results as $related_post ) {
122
+ if ( ! $this->check_read_permission( $related_post ) ) {
123
+ continue;
124
+ }
125
+
126
+ $related_posts[] = $this->prepare_item( $related_post, $request );
127
+ }
128
+ }
129
+ return rest_ensure_response( $related_posts );
130
+ }
131
+
132
+ /**
133
+ * Get a popular post by ID. Also includes the number of views.
134
+ *
135
+ * @since 3.1.0
136
+ *
137
+ * @param WP_Post $related_post Popular Post object.
138
+ * @param WP_REST_Request $request WP Rest request.
139
+ * @return array|mixed The formatted Popular Post object.
140
+ */
141
+ public function prepare_item( $related_post, $request ) {
142
+
143
+ // Need to prepare items for the rest response.
144
+ $posts_controller = new \WP_REST_Posts_Controller( $related_post->post_type, $request );
145
+ $data = $posts_controller->prepare_item_for_response( $related_post, $request );
146
+
147
+ return $this->prepare_response_for_collection( $data );
148
+ }
149
+
150
+ /**
151
+ * Get the arguments for fetching the related posts.
152
+ *
153
+ * @since 3.1.0
154
+ *
155
+ * @return array Top 10 REST API related posts arguments.
156
+ */
157
+ public function get_item_params() {
158
+ $args = array(
159
+ 'id' => array(
160
+ 'description' => __( 'Post ID.', 'contextual-related-posts' ),
161
+ 'type' => 'integer',
162
+ 'required' => true,
163
+ ),
164
+ 'limit' => array(
165
+ 'description' => __( 'Number of posts', 'contextual-related-posts' ),
166
+ 'type' => 'integer',
167
+ 'sanitize_callback' => 'absint',
168
+ ),
169
+ 'post_types' => array(
170
+ 'description' => __( 'Post types (comma separated)', 'contextual-related-posts' ),
171
+ 'type' => 'string',
172
+ ),
173
+ 'same_post_type' => array(
174
+ 'description' => __( 'Same post type', 'contextual-related-posts' ),
175
+ 'type' => 'boolean',
176
+ ),
177
+ 'same_author' => array(
178
+ 'description' => __( 'Same author', 'contextual-related-posts' ),
179
+ 'type' => 'boolean',
180
+ ),
181
+ 'exclude_post_ids' => array(
182
+ 'description' => __( 'Post/page IDs to exclude (comma separated)', 'contextual-related-posts' ),
183
+ 'type' => 'string',
184
+ ),
185
+ 'exclude_categories' => array(
186
+ 'description' => __( 'Taxonomy IDs from which posts are excluded (comma separated)', 'contextual-related-posts' ),
187
+ 'type' => 'string',
188
+ ),
189
+ );
190
+
191
+ return apply_filters( 'crp_rest_api_get_item_params', $args );
192
+ }
193
+
194
+ /**
195
+ * Checks if a given post type can be viewed or managed.
196
+ *
197
+ * @since 3.1.0
198
+ *
199
+ * @param WP_Post_Type|string $post_type Post type name or object.
200
+ * @return bool Whether the post type is allowed in REST.
201
+ */
202
+ protected function check_is_post_type_allowed( $post_type ) {
203
+ if ( ! is_object( $post_type ) ) {
204
+ $post_type = get_post_type_object( $post_type );
205
+ }
206
+
207
+ if ( ! empty( $post_type ) && ! empty( $post_type->show_in_rest ) ) {
208
+ return true;
209
+ }
210
+
211
+ return false;
212
+ }
213
+
214
+ /**
215
+ * Checks if a post can be read.
216
+ *
217
+ * Correctly handles posts with the inherit status.
218
+ *
219
+ * @since 3.1.0
220
+ *
221
+ * @param WP_Post $post Post object.
222
+ * @return bool Whether the post can be read.
223
+ */
224
+ public function check_read_permission( $post ) {
225
+ $post_type = get_post_type_object( $post->post_type );
226
+ if ( ! $this->check_is_post_type_allowed( $post_type ) ) {
227
+ return false;
228
+ }
229
+
230
+ // Is the post readable?
231
+ if ( 'publish' === $post->post_status || current_user_can( 'read_post', $post->ID ) ) {
232
+ return true;
233
+ }
234
+
235
+ $post_status_obj = get_post_status_object( $post->post_status );
236
+ if ( $post_status_obj && $post_status_obj->public ) {
237
+ return true;
238
+ }
239
+
240
+ // Can we read the parent if we're inheriting?
241
+ if ( 'inherit' === $post->post_status && $post->post_parent > 0 ) {
242
+ $parent = get_post( $post->post_parent );
243
+ if ( $parent ) {
244
+ return $this->check_read_permission( $parent );
245
+ }
246
+ }
247
+
248
+ /*
249
+ * If there isn't a parent, but the status is set to inherit, assume
250
+ * it's published (as per get_post_status()).
251
+ */
252
+ if ( 'inherit' === $post->post_status ) {
253
+ return true;
254
+ }
255
+
256
+ return false;
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Function to register our new routes from the controller.
262
+ *
263
+ * @since 3.1.0
264
+ */
265
+ function crp_register_rest_routes() {
266
+ $controller = new CRP_REST_API();
267
+ $controller->register_routes();
268
+ }
269
+ add_action( 'rest_api_init', 'crp_register_rest_routes' );
includes/output-generator.php CHANGED
@@ -305,9 +305,8 @@ function crp_list_link( $args, $result ) {
305
  $output .= '<figure>';
306
  $output .= crp_get_the_post_thumbnail(
307
  array(
308
- 'postid' => $result,
309
- 'thumb_height' => $args['thumb_height'],
310
- 'thumb_width' => $args['thumb_width'],
311
  'thumb_meta' => $args['thumb_meta'],
312
  'thumb_html' => $args['thumb_html'],
313
  'thumb_default' => $args['thumb_default'],
305
  $output .= '<figure>';
306
  $output .= crp_get_the_post_thumbnail(
307
  array(
308
+ 'post' => $result,
309
+ 'size' => $args['thumb_size'],
 
310
  'thumb_meta' => $args['thumb_meta'],
311
  'thumb_html' => $args['thumb_html'],
312
  'thumb_default' => $args['thumb_default'],
includes/tools.php CHANGED
@@ -140,6 +140,7 @@ function crp_excerpt( $post, $excerpt_length = 0, $use_excerpt = true, $more_lin
140
  function crp_trim_char( $string, $count = 60, $more = '&hellip;', $break_words = false ) {
141
 
142
  $string = wp_strip_all_tags( $string, true );
 
143
 
144
  if ( 0 === $count ) {
145
  return '';
140
  function crp_trim_char( $string, $count = 60, $more = '&hellip;', $break_words = false ) {
141
 
142
  $string = wp_strip_all_tags( $string, true );
143
+ $count = absint( $count );
144
 
145
  if ( 0 === $count ) {
146
  return '';
languages/contextual-related-posts-en_US.mo CHANGED
Binary file
languages/contextual-related-posts-en_US.po CHANGED
@@ -2,20 +2,21 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Contextual Related Posts\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2021-03-02 10:41+0000\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Ajay D'Souza\n"
8
  "Language-Team: WebberZone\n"
9
- "Language: en_US\n"
10
  "MIME-Version: 1.0\n"
11
  "Content-Type: text/plain; charset=UTF-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
13
- "X-Poedit-KeywordsList: __;_e;_c;__ngettext;esc_html__;esc_attr__;esc_html_e;"
14
- "esc_attr_e\n"
 
 
15
  "X-Poedit-Basepath: ..\n"
16
- "X-Generator: Poedit 2.4.2\n"
17
  "X-Poedit-SourceCharset: UTF-8\n"
18
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
  "X-Poedit-SearchPath-0: .\n"
20
 
21
  #: includes/admin/admin.php:31
@@ -909,31 +910,31 @@ msgstr ""
909
  msgid "Contribute"
910
  msgstr ""
911
 
912
- #: includes/admin/modules/metabox.php:111
913
  msgid "Disable Related Posts display:"
914
  msgstr ""
915
 
916
- #: includes/admin/modules/metabox.php:114
917
  msgid ""
918
  "If this is checked, then Contextual Related Posts will not automatically "
919
  "insert the related posts at the end of post content."
920
  msgstr ""
921
 
922
- #: includes/admin/modules/metabox.php:118
923
  msgid "Exclude this post from the related posts list:"
924
  msgstr ""
925
 
926
- #: includes/admin/modules/metabox.php:121
927
  msgid ""
928
  "If this is checked, then this post will be excluded from the popular posts "
929
  "list."
930
  msgstr ""
931
 
932
- #: includes/admin/modules/metabox.php:125
933
  msgid "Keyword:"
934
  msgstr ""
935
 
936
- #: includes/admin/modules/metabox.php:127
937
  msgid ""
938
  "Enter either a word or a phrase that will be used to find related posts. If "
939
  "entered, the plugin will continue to search the `post_title` and "
@@ -941,46 +942,56 @@ msgid ""
941
  "title and content of this post."
942
  msgstr ""
943
 
944
- #: includes/admin/modules/metabox.php:131
945
- #: includes/admin/modules/metabox.php:139
946
- msgid "Manual related posts:"
 
 
 
 
 
947
  msgstr ""
948
 
 
949
  #: includes/admin/modules/metabox.php:133
 
 
 
 
950
  msgid ""
951
  "Comma separated list of post, page or custom post type IDs. e.g. "
952
  "188,320,500. These will be given preference over the related posts generated "
953
  "by the plugin."
954
  msgstr ""
955
 
956
- #: includes/admin/modules/metabox.php:134
957
  msgid ""
958
  "Once you enter the list above and save this page, the plugin will display "
959
  "the titles of the posts below for your reference. Only IDs corresponding to "
960
  "published posts or custom post types will be retained."
961
  msgstr ""
962
 
963
- #: includes/admin/modules/metabox.php:150
964
  #, php-format
965
  msgid "This post type is: %s"
966
  msgstr ""
967
 
968
- #: includes/admin/modules/metabox.php:161
969
  msgid "Location of thumbnail"
970
  msgstr ""
971
 
972
- #: includes/admin/modules/metabox.php:163
973
  msgid ""
974
  "Enter the full URL to the image (JPG, PNG or GIF) you'd like to use. This "
975
  "image will be used for the post. It will be resized to the thumbnail size "
976
  "set under Settings &raquo; Related Posts &raquo; Output Options"
977
  msgstr ""
978
 
979
- #: includes/admin/modules/metabox.php:164
980
  msgid "The URL above is saved in the meta field:"
981
  msgstr ""
982
 
983
- #: includes/admin/modules/metabox.php:169
984
  msgid ""
985
  "You have Top 10 WordPress Plugin installed. If you are trying to modify the "
986
  "thumbnail, then you'll need to make the same change in the Top 10 meta box "
@@ -1156,6 +1167,11 @@ msgstr ""
1156
  msgid "Modified from default setting"
1157
  msgstr ""
1158
 
 
 
 
 
 
1159
  #: includes/admin/settings-page.php:769
1160
  msgid ""
1161
  "This option cannot be changed because of the selected related posts style. "
@@ -1224,20 +1240,40 @@ msgid ""
1224
  "Related Posts</a>"
1225
  msgstr ""
1226
 
1227
- #: includes/media.php:65
1228
- msgid "thumb_timthumb argument has been deprecated"
1229
  msgstr ""
1230
 
1231
- #: includes/media.php:69
1232
- msgid "thumb_timthumb_q argument has been deprecated"
1233
  msgstr ""
1234
 
1235
- #: includes/media.php:73
1236
- msgid "filter argument has been deprecated"
1237
  msgstr ""
1238
 
1239
- #: includes/modules/cache.php:25
1240
- msgid "Cache has been cleared"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1241
  msgstr ""
1242
 
1243
  #: includes/modules/class-crp-widget.php:31
2
  msgstr ""
3
  "Project-Id-Version: Contextual Related Posts\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2021-11-27 21:42+0000\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Ajay D'Souza\n"
8
  "Language-Team: WebberZone\n"
9
+ "Language: en\n"
10
  "MIME-Version: 1.0\n"
11
  "Content-Type: text/plain; charset=UTF-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
14
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_ex:1,2c;"
15
+ "esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;"
16
+ "translate_nooped_plural\n"
17
  "X-Poedit-Basepath: ..\n"
18
+ "X-Generator: Poedit 3.0\n"
19
  "X-Poedit-SourceCharset: UTF-8\n"
 
20
  "X-Poedit-SearchPath-0: .\n"
21
 
22
  #: includes/admin/admin.php:31
910
  msgid "Contribute"
911
  msgstr ""
912
 
913
+ #: includes/admin/modules/metabox.php:99
914
  msgid "Disable Related Posts display:"
915
  msgstr ""
916
 
917
+ #: includes/admin/modules/metabox.php:102
918
  msgid ""
919
  "If this is checked, then Contextual Related Posts will not automatically "
920
  "insert the related posts at the end of post content."
921
  msgstr ""
922
 
923
+ #: includes/admin/modules/metabox.php:106
924
  msgid "Exclude this post from the related posts list:"
925
  msgstr ""
926
 
927
+ #: includes/admin/modules/metabox.php:109
928
  msgid ""
929
  "If this is checked, then this post will be excluded from the popular posts "
930
  "list."
931
  msgstr ""
932
 
933
+ #: includes/admin/modules/metabox.php:113
934
  msgid "Keyword:"
935
  msgstr ""
936
 
937
+ #: includes/admin/modules/metabox.php:115
938
  msgid ""
939
  "Enter either a word or a phrase that will be used to find related posts. If "
940
  "entered, the plugin will continue to search the `post_title` and "
942
  "title and content of this post."
943
  msgstr ""
944
 
945
+ #: includes/admin/modules/metabox.php:119
946
+ msgid "Exclude terms:"
947
+ msgstr ""
948
+
949
+ #: includes/admin/modules/metabox.php:121
950
+ msgid ""
951
+ "Enter a comma-separated list of terms. If a related post's title or content "
952
+ "contains any of these terms then it will be excluded from the results."
953
  msgstr ""
954
 
955
+ #: includes/admin/modules/metabox.php:125
956
  #: includes/admin/modules/metabox.php:133
957
+ msgid "Manual related posts:"
958
+ msgstr ""
959
+
960
+ #: includes/admin/modules/metabox.php:127
961
  msgid ""
962
  "Comma separated list of post, page or custom post type IDs. e.g. "
963
  "188,320,500. These will be given preference over the related posts generated "
964
  "by the plugin."
965
  msgstr ""
966
 
967
+ #: includes/admin/modules/metabox.php:128
968
  msgid ""
969
  "Once you enter the list above and save this page, the plugin will display "
970
  "the titles of the posts below for your reference. Only IDs corresponding to "
971
  "published posts or custom post types will be retained."
972
  msgstr ""
973
 
974
+ #: includes/admin/modules/metabox.php:144
975
  #, php-format
976
  msgid "This post type is: %s"
977
  msgstr ""
978
 
979
+ #: includes/admin/modules/metabox.php:155
980
  msgid "Location of thumbnail"
981
  msgstr ""
982
 
983
+ #: includes/admin/modules/metabox.php:157
984
  msgid ""
985
  "Enter the full URL to the image (JPG, PNG or GIF) you'd like to use. This "
986
  "image will be used for the post. It will be resized to the thumbnail size "
987
  "set under Settings &raquo; Related Posts &raquo; Output Options"
988
  msgstr ""
989
 
990
+ #: includes/admin/modules/metabox.php:158
991
  msgid "The URL above is saved in the meta field:"
992
  msgstr ""
993
 
994
+ #: includes/admin/modules/metabox.php:163
995
  msgid ""
996
  "You have Top 10 WordPress Plugin installed. If you are trying to modify the "
997
  "thumbnail, then you'll need to make the same change in the Top 10 meta box "
1167
  msgid "Modified from default setting"
1168
  msgstr ""
1169
 
1170
+ #: includes/admin/settings-page.php:694
1171
+ msgctxt "tag delimiter"
1172
+ msgid ","
1173
+ msgstr ""
1174
+
1175
  #: includes/admin/settings-page.php:769
1176
  msgid ""
1177
  "This option cannot be changed because of the selected related posts style. "
1240
  "Related Posts</a>"
1241
  msgstr ""
1242
 
1243
+ #: includes/modules/cache.php:25
1244
+ msgid "Cache has been cleared"
1245
  msgstr ""
1246
 
1247
+ #: includes/modules/class-crp-rest-api.php:90
1248
+ msgid "Invalid post ID."
1249
  msgstr ""
1250
 
1251
+ #: includes/modules/class-crp-rest-api.php:160
1252
+ msgid "Post ID."
1253
  msgstr ""
1254
 
1255
+ #: includes/modules/class-crp-rest-api.php:165
1256
+ msgid "Number of posts"
1257
+ msgstr ""
1258
+
1259
+ #: includes/modules/class-crp-rest-api.php:170
1260
+ msgid "Post types (comma separated)"
1261
+ msgstr ""
1262
+
1263
+ #: includes/modules/class-crp-rest-api.php:174
1264
+ msgid "Same post type"
1265
+ msgstr ""
1266
+
1267
+ #: includes/modules/class-crp-rest-api.php:178
1268
+ msgid "Same author"
1269
+ msgstr ""
1270
+
1271
+ #: includes/modules/class-crp-rest-api.php:182
1272
+ msgid "Post/page IDs to exclude (comma separated)"
1273
+ msgstr ""
1274
+
1275
+ #: includes/modules/class-crp-rest-api.php:186
1276
+ msgid "Taxonomy IDs from which posts are excluded (comma separated)"
1277
  msgstr ""
1278
 
1279
  #: includes/modules/class-crp-widget.php:31
languages/contextual-related-posts-en_US.pot CHANGED
@@ -3,7 +3,7 @@ msgid ""
3
  msgstr ""
4
  "Project-Id-Version: Contextual Related Posts\n"
5
  "Report-Msgid-Bugs-To: \n"
6
- "POT-Creation-Date: 2021-03-02 10:41+0000\n"
7
  "PO-Revision-Date: \n"
8
  "Last-Translator: Ajay D'Souza\n"
9
  "Language-Team: WebberZone\n"
@@ -11,10 +11,12 @@ msgstr ""
11
  "MIME-Version: 1.0\n"
12
  "Content-Type: text/plain; charset=UTF-8\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
- "X-Poedit-KeywordsList: __;_e;_c;__ngettext;esc_html__;esc_html_e;esc_attr__;"
15
- "esc_attr_e\n"
 
 
16
  "X-Poedit-Basepath: ..\n"
17
- "X-Generator: Poedit 2.4.2\n"
18
  "X-Poedit-SourceCharset: UTF-8\n"
19
  "X-Poedit-SearchPath-0: .\n"
20
 
@@ -909,31 +911,31 @@ msgstr ""
909
  msgid "Contribute"
910
  msgstr ""
911
 
912
- #: includes/admin/modules/metabox.php:111
913
  msgid "Disable Related Posts display:"
914
  msgstr ""
915
 
916
- #: includes/admin/modules/metabox.php:114
917
  msgid ""
918
  "If this is checked, then Contextual Related Posts will not automatically "
919
  "insert the related posts at the end of post content."
920
  msgstr ""
921
 
922
- #: includes/admin/modules/metabox.php:118
923
  msgid "Exclude this post from the related posts list:"
924
  msgstr ""
925
 
926
- #: includes/admin/modules/metabox.php:121
927
  msgid ""
928
  "If this is checked, then this post will be excluded from the popular posts "
929
  "list."
930
  msgstr ""
931
 
932
- #: includes/admin/modules/metabox.php:125
933
  msgid "Keyword:"
934
  msgstr ""
935
 
936
- #: includes/admin/modules/metabox.php:127
937
  msgid ""
938
  "Enter either a word or a phrase that will be used to find related posts. If "
939
  "entered, the plugin will continue to search the `post_title` and "
@@ -941,46 +943,56 @@ msgid ""
941
  "title and content of this post."
942
  msgstr ""
943
 
944
- #: includes/admin/modules/metabox.php:131
945
- #: includes/admin/modules/metabox.php:139
946
- msgid "Manual related posts:"
 
 
 
 
 
947
  msgstr ""
948
 
 
949
  #: includes/admin/modules/metabox.php:133
 
 
 
 
950
  msgid ""
951
  "Comma separated list of post, page or custom post type IDs. e.g. "
952
  "188,320,500. These will be given preference over the related posts generated "
953
  "by the plugin."
954
  msgstr ""
955
 
956
- #: includes/admin/modules/metabox.php:134
957
  msgid ""
958
  "Once you enter the list above and save this page, the plugin will display "
959
  "the titles of the posts below for your reference. Only IDs corresponding to "
960
  "published posts or custom post types will be retained."
961
  msgstr ""
962
 
963
- #: includes/admin/modules/metabox.php:150
964
  #, php-format
965
  msgid "This post type is: %s"
966
  msgstr ""
967
 
968
- #: includes/admin/modules/metabox.php:161
969
  msgid "Location of thumbnail"
970
  msgstr ""
971
 
972
- #: includes/admin/modules/metabox.php:163
973
  msgid ""
974
  "Enter the full URL to the image (JPG, PNG or GIF) you'd like to use. This "
975
  "image will be used for the post. It will be resized to the thumbnail size "
976
  "set under Settings &raquo; Related Posts &raquo; Output Options"
977
  msgstr ""
978
 
979
- #: includes/admin/modules/metabox.php:164
980
  msgid "The URL above is saved in the meta field:"
981
  msgstr ""
982
 
983
- #: includes/admin/modules/metabox.php:169
984
  msgid ""
985
  "You have Top 10 WordPress Plugin installed. If you are trying to modify the "
986
  "thumbnail, then you'll need to make the same change in the Top 10 meta box "
@@ -1156,6 +1168,11 @@ msgstr ""
1156
  msgid "Modified from default setting"
1157
  msgstr ""
1158
 
 
 
 
 
 
1159
  #: includes/admin/settings-page.php:769
1160
  msgid ""
1161
  "This option cannot be changed because of the selected related posts style. "
@@ -1224,20 +1241,40 @@ msgid ""
1224
  "Related Posts</a>"
1225
  msgstr ""
1226
 
1227
- #: includes/media.php:65
1228
- msgid "thumb_timthumb argument has been deprecated"
1229
  msgstr ""
1230
 
1231
- #: includes/media.php:69
1232
- msgid "thumb_timthumb_q argument has been deprecated"
1233
  msgstr ""
1234
 
1235
- #: includes/media.php:73
1236
- msgid "filter argument has been deprecated"
1237
  msgstr ""
1238
 
1239
- #: includes/modules/cache.php:25
1240
- msgid "Cache has been cleared"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1241
  msgstr ""
1242
 
1243
  #: includes/modules/class-crp-widget.php:31
3
  msgstr ""
4
  "Project-Id-Version: Contextual Related Posts\n"
5
  "Report-Msgid-Bugs-To: \n"
6
+ "POT-Creation-Date: 2021-11-27 21:42+0000\n"
7
  "PO-Revision-Date: \n"
8
  "Last-Translator: Ajay D'Souza\n"
9
  "Language-Team: WebberZone\n"
11
  "MIME-Version: 1.0\n"
12
  "Content-Type: text/plain; charset=UTF-8\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
15
+ "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_ex:1,2c;"
16
+ "esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;"
17
+ "translate_nooped_plural\n"
18
  "X-Poedit-Basepath: ..\n"
19
+ "X-Generator: Poedit 3.0\n"
20
  "X-Poedit-SourceCharset: UTF-8\n"
21
  "X-Poedit-SearchPath-0: .\n"
22
 
911
  msgid "Contribute"
912
  msgstr ""
913
 
914
+ #: includes/admin/modules/metabox.php:99
915
  msgid "Disable Related Posts display:"
916
  msgstr ""
917
 
918
+ #: includes/admin/modules/metabox.php:102
919
  msgid ""
920
  "If this is checked, then Contextual Related Posts will not automatically "
921
  "insert the related posts at the end of post content."
922
  msgstr ""
923
 
924
+ #: includes/admin/modules/metabox.php:106
925
  msgid "Exclude this post from the related posts list:"
926
  msgstr ""
927
 
928
+ #: includes/admin/modules/metabox.php:109
929
  msgid ""
930
  "If this is checked, then this post will be excluded from the popular posts "
931
  "list."
932
  msgstr ""
933
 
934
+ #: includes/admin/modules/metabox.php:113
935
  msgid "Keyword:"
936
  msgstr ""
937
 
938
+ #: includes/admin/modules/metabox.php:115
939
  msgid ""
940
  "Enter either a word or a phrase that will be used to find related posts. If "
941
  "entered, the plugin will continue to search the `post_title` and "
943
  "title and content of this post."
944
  msgstr ""
945
 
946
+ #: includes/admin/modules/metabox.php:119
947
+ msgid "Exclude terms:"
948
+ msgstr ""
949
+
950
+ #: includes/admin/modules/metabox.php:121
951
+ msgid ""
952
+ "Enter a comma-separated list of terms. If a related post's title or content "
953
+ "contains any of these terms then it will be excluded from the results."
954
  msgstr ""
955
 
956
+ #: includes/admin/modules/metabox.php:125
957
  #: includes/admin/modules/metabox.php:133
958
+ msgid "Manual related posts:"
959
+ msgstr ""
960
+
961
+ #: includes/admin/modules/metabox.php:127
962
  msgid ""
963
  "Comma separated list of post, page or custom post type IDs. e.g. "
964
  "188,320,500. These will be given preference over the related posts generated "
965
  "by the plugin."
966
  msgstr ""
967
 
968
+ #: includes/admin/modules/metabox.php:128
969
  msgid ""
970
  "Once you enter the list above and save this page, the plugin will display "
971
  "the titles of the posts below for your reference. Only IDs corresponding to "
972
  "published posts or custom post types will be retained."
973
  msgstr ""
974
 
975
+ #: includes/admin/modules/metabox.php:144
976
  #, php-format
977
  msgid "This post type is: %s"
978
  msgstr ""
979
 
980
+ #: includes/admin/modules/metabox.php:155
981
  msgid "Location of thumbnail"
982
  msgstr ""
983
 
984
+ #: includes/admin/modules/metabox.php:157
985
  msgid ""
986
  "Enter the full URL to the image (JPG, PNG or GIF) you'd like to use. This "
987
  "image will be used for the post. It will be resized to the thumbnail size "
988
  "set under Settings &raquo; Related Posts &raquo; Output Options"
989
  msgstr ""
990
 
991
+ #: includes/admin/modules/metabox.php:158
992
  msgid "The URL above is saved in the meta field:"
993
  msgstr ""
994
 
995
+ #: includes/admin/modules/metabox.php:163
996
  msgid ""
997
  "You have Top 10 WordPress Plugin installed. If you are trying to modify the "
998
  "thumbnail, then you'll need to make the same change in the Top 10 meta box "
1168
  msgid "Modified from default setting"
1169
  msgstr ""
1170
 
1171
+ #: includes/admin/settings-page.php:694
1172
+ msgctxt "tag delimiter"
1173
+ msgid ","
1174
+ msgstr ""
1175
+
1176
  #: includes/admin/settings-page.php:769
1177
  msgid ""
1178
  "This option cannot be changed because of the selected related posts style. "
1241
  "Related Posts</a>"
1242
  msgstr ""
1243
 
1244
+ #: includes/modules/cache.php:25
1245
+ msgid "Cache has been cleared"
1246
  msgstr ""
1247
 
1248
+ #: includes/modules/class-crp-rest-api.php:90
1249
+ msgid "Invalid post ID."
1250
  msgstr ""
1251
 
1252
+ #: includes/modules/class-crp-rest-api.php:160
1253
+ msgid "Post ID."
1254
  msgstr ""
1255
 
1256
+ #: includes/modules/class-crp-rest-api.php:165
1257
+ msgid "Number of posts"
1258
+ msgstr ""
1259
+
1260
+ #: includes/modules/class-crp-rest-api.php:170
1261
+ msgid "Post types (comma separated)"
1262
+ msgstr ""
1263
+
1264
+ #: includes/modules/class-crp-rest-api.php:174
1265
+ msgid "Same post type"
1266
+ msgstr ""
1267
+
1268
+ #: includes/modules/class-crp-rest-api.php:178
1269
+ msgid "Same author"
1270
+ msgstr ""
1271
+
1272
+ #: includes/modules/class-crp-rest-api.php:182
1273
+ msgid "Post/page IDs to exclude (comma separated)"
1274
+ msgstr ""
1275
+
1276
+ #: includes/modules/class-crp-rest-api.php:186
1277
+ msgid "Taxonomy IDs from which posts are excluded (comma separated)"
1278
  msgstr ""
1279
 
1280
  #: includes/modules/class-crp-widget.php:31
phpcs.ruleset.xml DELETED
@@ -1,17 +0,0 @@
1
- <?xml version="1.0"?>
2
- <ruleset name="WordPress Coding Standards for Plugins">
3
- <description>Generally-applicable sniffs for WordPress plugins</description>
4
-
5
- <exclude-pattern>*/node_modules/*</exclude-pattern>
6
- <exclude-pattern>*/vendor/*</exclude-pattern>
7
- <exclude-pattern>*/tests/*</exclude-pattern>
8
- <exclude-pattern>*/index.php</exclude-pattern>
9
-
10
- <rule ref="WordPress" />
11
-
12
- <!-- Add in some extra rules from other standards. -->
13
- <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
14
- <rule ref="Generic.Commenting.Todo"/>
15
- <rule ref="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed"/>
16
-
17
- </ruleset>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
phpcs.xml.dist ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <ruleset name="WordPress Coding Standards for Plugins">
3
+ <description>Generally-applicable sniffs for WordPress plugins</description>
4
+
5
+ <file>.</file>
6
+ <exclude-pattern>*/node_modules/*</exclude-pattern>
7
+ <exclude-pattern>*/phpunit/*</exclude-pattern>
8
+ <exclude-pattern>*/vendor/*</exclude-pattern>
9
+ <exclude-pattern>*/tests/*</exclude-pattern>
10
+ <exclude-pattern>*/index.php</exclude-pattern>
11
+
12
+ <!-- Only check PHP files. -->
13
+ <arg name="extensions" value="php"/>
14
+
15
+ <!-- Show progress, show the error codes for each message (source). -->
16
+ <arg value="ps"/>
17
+
18
+ <!-- Strip the filepaths down to the relevant bit. -->
19
+ <arg name="basepath" value="./"/>
20
+
21
+ <!-- Check up to 8 files simultaneously. -->
22
+ <arg name="parallel" value="8"/>
23
+
24
+ <!-- Use WordPress ruleset. -->
25
+ <rule ref="WordPress">
26
+ <exclude name="WordPress.WP.I18n" />
27
+ </rule>
28
+ <rule ref="WordPress.Files.FileName">
29
+ <exclude-pattern>*/phpunit/tests/*\.php$</exclude-pattern>
30
+ </rule>
31
+
32
+ <!-- Add in some extra rules from other standards. -->
33
+ <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
34
+ <rule ref="Generic.Commenting.Todo"/>
35
+ <rule ref="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed"/>
36
+
37
+ </ruleset>
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  Tags: related posts, related, related articles, contextual related posts, similar posts, related posts widget
3
  Contributors: webberzone, Ajay
4
  Donate link: https://ajaydsouza.com/donate/
5
- Stable tag: 3.0.7
6
- Requires at least: 5.0
7
- Tested up to: 5.8
8
- Requires PHP: 7.0
9
  License: GPLv2 or later
10
 
11
  Add related posts to your WordPress site with inbuilt caching. Supports thumbnails, shortcodes, widgets and custom post types!
@@ -27,6 +27,7 @@ And the default inbuilt styles allow you to switch between gorgeous thumbnail-ri
27
  * **Gutenberg / Block Editor support**: You can find a block called "Related Posts [CRP]" with its own configurable set of options
28
  * **Widgets**: Add related posts to widgetized area of your theme. Lots of options available
29
  * **Shortcode**: Use `[crp]` to display the posts anywhere you want in the post content
 
30
  * **The algorithm**: Find related posts by title and/or content of the current post
31
  * **Caching**: Related posts output is automatically cached as visitors browse through your site
32
  * **Exclusions**: Exclude posts from categories from being displayed in the list. Or you can exclude posts or pages by ID
@@ -108,39 +109,27 @@ If your question isn't listed here, please create a new post at the [WordPress.o
108
 
109
  = How can I customise the output? =
110
 
111
- Several customization options are available via the Settings page in WordPress Admin. You can access this via <strong>Settings &raquo; Related Posts</strong>
112
-
113
- The plugin also provides you with a set of CSS classes that allow you to style your posts by adding code to the *style.css* sheet.
114
-
115
- The main CSS classes / IDs are:
116
-
117
- * **crp_related**: ID of the main wrapper `div`. This is only displayed on singular pages, i.e. post, page and attachment
118
-
119
- * **crp_related**: Class of the main wrapper `div`. If you are displaying the related posts on non-singular pages, then you should style this
120
-
121
- * **crp_title**: Class of the `span` tag for title of the post
122
-
123
- * **crp_excerpt**: Class of the `span` tag for excerpt (if included)
124
-
125
- * **crp_thumb**: Class of the post thumbnail `img` tag
126
-
127
 
128
  = How does the plugin select thumbnails? =
129
 
130
- The plugin selects thumbnails in the following order:
131
 
132
- 1. Post meta field: This is the meta field value you can use when editing your post. The default is `post-image`
133
 
134
- 2. Post Thumbnail image: The image that you can set while editing your post in WordPress &raquo; New Post screen
135
 
136
- 3. First image in the post: The plugin will try to fetch the first image in the post
137
 
138
- 3. Video Thumbnails: Meta field set by <a href="https://wordpress.org/extend/plugins/video-thumbnails/">Video Thumbnails</a>
139
 
140
- 4. Default Thumbnail: If enabled, it will use the default thumbnail that you specify in the Settings screen
141
 
 
142
 
143
- = Manual install =
 
 
144
 
145
  The following functions are available in case you wish to do a manual install of the posts by editing the theme files.
146
 
@@ -150,8 +139,7 @@ Echoes the list of posts wherever you add the this function. You can also use th
150
 
151
  Usage: `<?php if ( function_exists( 'echo_crp' ) ) { echo_crp(); } ?>` to your template file where you want the related posts to be displayed.
152
 
153
-
154
- **get_crp_posts_id()**
155
 
156
  Takes a post ID and returns the related post IDs as an object.
157
 
@@ -166,6 +154,7 @@ Parameters:
166
 
167
  *$limit* : Maximum number of posts to return. The actual number displayed may be lower depending on the matching algorithm and the category / post exclusion settings.
168
 
 
169
 
170
  = Shortcodes =
171
 
@@ -174,81 +163,24 @@ You can insert the related posts anywhere in your post using the `[crp]` shortco
174
 
175
  == Changelog ==
176
 
177
- = 3.0.7 =
178
-
179
- Release post: [https://webberzone.com/blog/contextual-related-posts-v3-0-0/](https://webberzone.com/blog/contextual-related-posts-v3-0-0/)
180
-
181
- * Bug fix:
182
- * Replicate old style of exclusion checking of option set in meta. Using the shortcode, manual or block will ignore the meta option to "Disable Related Posts display"
183
-
184
- = 3.0.6 =
185
-
186
- * Enhancement:
187
- * Defining `CRP_CACHE_TIME` to `false` will disable expiry
188
- * Introduced wpml-config.xml file. Title and Custom text for blank output can now be translated with Polylang (and potentially WPML)
189
-
190
- * Bug fix:
191
- * Exclude on categories did not work
192
- * Posts would trigger a "SHOW FULL COLUMNS FROM" error if they had ' from' in the title
193
- * Manual posts did not work properly - all post types and all posts are properly fetched now
194
 
195
- = 3.0.5 =
196
-
197
- * Bug fix:
198
- * Certain posts would trigger a "SHOW FULL COLUMNS FROM" error
199
- * Forced `.crp_related figure` margin to 0
200
-
201
- = 3.0.4 =
202
-
203
- * Enhancement/Modifications:
204
- * `include_cat_ids` and `exclude_categories` will also accept custom taxonomy `term_taxonomy_id`s
205
- * Thumbnail's `img` tag is wrapped in `<figure>`
206
- * Remove extra checking for `exclude_categories` in `get_crp`
207
- * Optimise deleting of cache entries when updating a post - post saving should be significantly faster
208
-
209
- = 3.0.3 =
210
-
211
- * Enhancement/Modifications:
212
- * Grid style minimum width is now decided by the width of the thumbnail and long words are wrapped
213
-
214
- * Bug fixes:
215
- * Selecting No style created a 404 error
216
- * Fixed issue with $attachment_id not being declared in some cases
217
-
218
- = 3.0.2 =
219
-
220
- * Bug fixes:
221
- * Fixed issue where Related Posts newer than was set to 0 caused no posts to display
222
- * Use the original arguments when setting the cache key for CRP_Query
223
- * Selecting "Blank Output" didn't work
224
-
225
- = 3.0.1 =
226
-
227
- * Bug fixes:
228
- * Fixed issue with help tab that broke some sites
229
-
230
- = 3.0.0 =
231
 
232
  * Features:
233
- * New CRP_Query class for fetching related posts. This replaces `get_crp_posts_id()` which will be deprecated in a future version
234
- * CRP Thumbnails now include the `loading="lazy"` attribute added in WordPress 5.5
235
- * New parameter `more_link_text` that can be passed to `get_crp()` which holds the "read more". Recommended option to customize the more link text using the filter `crp_excerpt_more_link_text` or the more link element using `crp_excerpt_more_link`
236
- * Three new styles: "Masonry" (like Pinterest), "Grid" and "Rounded thumbnails with CSS grid". Might not work with older browsers
237
- * Imported settings of [Related Posts by Categories and Tags](https://webberzone.com/downloads/crp-taxonomy/). That plugin is now deprecated with this release.
238
-
239
- * Enhancement/Modifications:
240
- * If WPML or PolyLang are active, `get_crp_posts_id()` and `CRP_Query` will return the translated set of post IDs and external processing is no longer needed
241
- * Use `wp_img_tag_add_srcset_and_sizes_attr()` to generate srcset and sizes attributes. The original code to display the srcset and sizes attributes will continue to be used
242
- * Improved caching with inbuilt expiry. Use CRP_CACHE_TIME in your wp-config.php to set how long the cache should be set for. Default is one month
243
- * CRP_MAX_WORDS has been reduced to 100
244
- * Dropped the need for FULLTEXT index on post_content which should save some database space
245
- * Deprecated the following filters: `get_crp_posts_id`, `crp_posts_now_date`, `crp_posts_from_date`, `crp_posts_fields`, `crp_posts_join`, `crp_posts_where`, `crp_posts_groupby`, `crp_posts_having`, `crp_posts_orderby`, `crp_posts_limits`, `get_crp_posts_id_short_circuit`
246
 
247
  * Bug fixes:
248
- * In the settings page, only built-in taxonomies were being incorrectly displayed
249
- * If "before list item" is empty, then the output was blanked out
250
- * Settings help has been fixed
251
- * `crp_get_option` would return an incorrect value if $crp_settings global variable was not set
252
 
253
  = Earlier versions =
254
 
@@ -257,5 +189,5 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
257
 
258
  == Upgrade Notice ==
259
 
260
- = 3.0.7 =
261
- Bug fixes. Please read the release post on https://webberzone.com
2
  Tags: related posts, related, related articles, contextual related posts, similar posts, related posts widget
3
  Contributors: webberzone, Ajay
4
  Donate link: https://ajaydsouza.com/donate/
5
+ Stable tag: 3.1.0
6
+ Requires at least: 5.3
7
+ Tested up to: 5.9
8
+ Requires PHP: 7.1
9
  License: GPLv2 or later
10
 
11
  Add related posts to your WordPress site with inbuilt caching. Supports thumbnails, shortcodes, widgets and custom post types!
27
  * **Gutenberg / Block Editor support**: You can find a block called "Related Posts [CRP]" with its own configurable set of options
28
  * **Widgets**: Add related posts to widgetized area of your theme. Lots of options available
29
  * **Shortcode**: Use `[crp]` to display the posts anywhere you want in the post content
30
+ * **REST API**: Fetch related posts at `contextual-related-posts/v1/posts/<id>/`
31
  * **The algorithm**: Find related posts by title and/or content of the current post
32
  * **Caching**: Related posts output is automatically cached as visitors browse through your site
33
  * **Exclusions**: Exclude posts from categories from being displayed in the list. Or you can exclude posts or pages by ID
109
 
110
  = How can I customise the output? =
111
 
112
+ Contextual Related Posts is highly customizable. There are several configurable options in the Settings page and you can use CSS to customize the outputs. Learn more by reading [this article](https://webberzone.com/support/knowledgebase/customising-the-output-of-contextual-related-posts/).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  = How does the plugin select thumbnails? =
115
 
116
+ If you enable thumbnails, the plugin will try to find the correct thumbnail in this order:
117
 
118
+ 1. Post meta field: This is the meta field value you can use when editing your post. The default is `post-image`. Change it in the Settings page
119
 
120
+ 2. Post Thumbnail image: The image that you can set under Featured Image
121
 
122
+ 3. First image in the post: The plugin will try to fetch the first image in the post. Toggle this in the Settings page
123
 
124
+ 4. First child image attached to the post
125
 
126
+ 5. Video Thumbnails: Meta field set by [Video Thumbnails plugin](https://wordpress.org/plugins/video-thumbnails/)
127
 
128
+ 6. Site Icon: this is typically set using Customizer
129
 
130
+ 7. Default Thumbnail: If enabled, it will use the default thumbnail that you specify in the Settings page
131
+
132
+ = Template tags =
133
 
134
  The following functions are available in case you wish to do a manual install of the posts by editing the theme files.
135
 
139
 
140
  Usage: `<?php if ( function_exists( 'echo_crp' ) ) { echo_crp(); } ?>` to your template file where you want the related posts to be displayed.
141
 
142
+ **get_crp_posts_id( $args = array() )**
 
143
 
144
  Takes a post ID and returns the related post IDs as an object.
145
 
154
 
155
  *$limit* : Maximum number of posts to return. The actual number displayed may be lower depending on the matching algorithm and the category / post exclusion settings.
156
 
157
+ This is not an exhaustive set of Parameters. For the full list of Parameters check out the shortcode FAQ below.
158
 
159
  = Shortcodes =
160
 
163
 
164
  == Changelog ==
165
 
166
+ = 3.1.0 =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
+ Release post: [https://webberzone.com/blog/contextual-related-posts-v3-1-0/](https://webberzone.com/blog/contextual-related-posts-v3-1-0/)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  * Features:
171
+ * REST API support - you can now fetch the related posts via the REST API. Fetch posts at `/contextual-related-posts/v1/posts/<id>`
172
+ * New setting in the metabox to exclude specific terms
173
+
174
+ * Enhancements/modifications:
175
+ * Thumbnail function uses the size instead of exact array of sizes to better select the appropriate thumbnail image size
176
+ * Use site icon if no other thumbnail is found
177
+ * Use both `post_title` and `post_content` fields for matching even when match content setting is off
178
+ * Passing `post_type` and `posts_per_page` arguments will be respected instead of being overridden
 
 
 
 
 
179
 
180
  * Bug fixes:
181
+ * Don't enqueue wp-editor on widgets.php
182
+ * [WP_Query stopwords](https://developer.wordpress.org/reference/classes/wp_query/get_search_stopwords/) are stripped from content that is matched
183
+ * Manual posts are added after the automatic posts are shuffled
 
184
 
185
  = Earlier versions =
186
 
189
 
190
  == Upgrade Notice ==
191
 
192
+ = 3.1.0 =
193
+ WP REST API support. Please read the release post on https://webberzone.com