Related Posts Thumbnails Plugin for WordPress - Version 1.8.2

Version Description

  • Please upgrade immediately - Introducing filters for developers to extend Related Posts

=

Download this release

Release Info

Developer hiddenpearls
Plugin Icon 128x128 Related Posts Thumbnails Plugin for WordPress
Version 1.8.2
Comparing to
See all releases

Code changes from version 1.8.1 to 1.8.2

Files changed (2) hide show
  1. readme.txt +10 -4
  2. related-posts-thumbnails.php +83 -21
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Related Posts Thumbnails Plugin for WordPress ===
2
- Contributors: marynixie, hiddenpearls, WPBrigade
3
  Donate link: https://wpbrigade.com/
4
  Tags: easy related posts, Related Posts thumbnails, Free Related Posts, related posts, similar related posts
5
  Requires at least: 3.6
6
  Tested up to: 5.2
7
- Stable tag: 1.8.1
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -71,11 +71,17 @@ If there are no images of the specified size in the post, or file does not exist
71
 
72
  == Upgrade Notice ==
73
 
74
- = 1.8.1 =
75
- * Please upgrade immediately - Fix thumbnails are not showing up.
76
 
77
  == Changelog ==
78
 
 
 
 
 
 
 
79
  = 1.8.1 - 2019-06-25 =
80
  * Bug Fix : Thumbnails are not showing when post thumbnail source is selected.
81
 
1
  === Related Posts Thumbnails Plugin for WordPress ===
2
+ Contributors: hiddenpearls, WPBrigade
3
  Donate link: https://wpbrigade.com/
4
  Tags: easy related posts, Related Posts thumbnails, Free Related Posts, related posts, similar related posts
5
  Requires at least: 3.6
6
  Tested up to: 5.2
7
+ Stable tag: 1.8.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
71
 
72
  == Upgrade Notice ==
73
 
74
+ = 1.8.2 =
75
+ * Please upgrade immediately - Introducing filters for developers to extend Related Posts
76
 
77
  == Changelog ==
78
 
79
+ = 1.8.2 - 2019-10-16 =
80
+ * New Feature : Filter for related post top text.
81
+ * New Feature : Filter to prevent image size check on inner post images.
82
+ * New Feature : Filter to prevent related posts on builders.
83
+ * New Feature : Filter to remove related post with empty custom field.
84
+
85
  = 1.8.1 - 2019-06-25 =
86
  * Bug Fix : Thumbnails are not showing when post thumbnail source is selected.
87
 
related-posts-thumbnails.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WordPress Related Posts Thumbnails
4
  * Plugin URI: https://wpbrigade.com/wordpress/plugins/related-posts/?utm_source=related-posts-lite&utm_medium=plugin-uri&utm_campaign=pro-upgrade-rp
5
  * Description: Showing related posts thumbnails under the posts.
6
- * Version: 1.8.1
7
  * Author: WPBrigade
8
  * Author URI: https://WPBrigade.com/?utm_source=related-posts-lite&utm_medium=author-link&utm_campaign=pro-upgrade-rp
9
  */
@@ -67,10 +67,15 @@ class RelatedPostsThumbnails {
67
  update_option( 'relpoststh_default_image', $this->default_image );
68
 
69
  if ( get_option( 'relpoststh_auto', $this->auto ) ) {
70
- $priority = apply_filters( 'rpt_content_prioirty', 10 ); // Alter priority of the related post content
71
- add_filter( 'the_content', array(
72
- $this,
73
- 'auto_show'
 
 
 
 
 
74
  ), $priority );
75
  }
76
 
@@ -105,7 +110,32 @@ class RelatedPostsThumbnails {
105
  ) );
106
 
107
  add_shortcode( 'related-posts-thumbnails', array( $this, 'related_posts_shortcode' ) );
108
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  function related_posts_shortcode( $atts ) {
111
  $atts = shortcode_atts( array(
@@ -602,7 +632,8 @@ class RelatedPostsThumbnails {
602
  if ( ! empty( $main_title ) ) {
603
  $output .= '<p class="relpoststh-block-title">' . $main_title . '</p>';
604
  } else {
605
- $output .= stripslashes( get_option( 'relpoststh_top_text', $this->top_text ) );
 
606
  }
607
  }
608
 
@@ -634,19 +665,22 @@ class RelatedPostsThumbnails {
634
  foreach ( $posts as $post ) {
635
  $image = '';
636
  $url = '';
637
- $alt = '';
638
 
639
  if ( $thsource == 'custom-field' ) {
640
- $custom_field = get_option( 'relpoststh_customfield', $this->custom_field );
641
- $custom_field_meta = get_post_meta( $post->ID, $custom_field, true );
642
 
643
  if ( empty( $custom_field ) ) {
644
  $debug .= 'No custom field specifield, using default thumbnail image;';
645
  $url = $this->default_image;
646
- } elseif ( empty( $custom_field_meta ) ) {
 
 
 
647
  $debug .= 'Custom field meta is empty, using default thumbnail image;';
648
  $url = $this->default_image;
649
- } else {
650
  $debug .= 'Using custom field;';
651
  $url = $custom_field_meta;
652
  $theme_resize_url = get_option( 'relpoststh_theme_resize_url', '' );
@@ -675,14 +709,19 @@ class RelatedPostsThumbnails {
675
  $debug .= 'Post has no thumbnail;';
676
  }
677
  }
678
- if ( $from_post_body ) { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
 
 
679
  $debug .= 'Getting image from post body;';
680
  $wud = wp_upload_dir();
681
- preg_match_all( '|<img.*?src=[\'"](' . $wud[ 'baseurl' ] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // search the first uploaded image in content
 
 
682
 
683
  if ( isset( $matches ) && isset( $matches[ 1 ][ 0 ] ) ) {
684
  $image = $matches[ 1 ][ 0 ];
685
  $html = $matches[ 0 ][ 0 ];
 
686
  if ( !empty( $html ) ) {
687
  preg_match( '/alt="([^"]*)"/i', $html, $array );
688
 
@@ -690,36 +729,49 @@ class RelatedPostsThumbnails {
690
  $explode_tag = explode( '"', $array[ 0 ] );
691
  $alt = $explode_tag[ 1 ];
692
  }
693
-
694
  }
 
695
  } else {
696
  $debug .= 'No image was found;';
697
  }
698
 
699
  if ( strlen( trim( $image ) ) > 0 ) {
700
  $image_sizes = @getimagesize( $image );
 
701
  if ( $image_sizes === false ) {
702
- $debug .= 'Unable to determine parsed image size';
703
  }
704
- if ( $image_sizes !== false && isset( $image_sizes[ 0 ] ) && $image_sizes[ 0 ] == $width ) { // if this image is the same size as we need
 
 
705
  $debug .= 'Image used is the required size;';
706
  $url = $image;
707
- } else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
 
 
 
 
 
 
 
708
  $debug .= 'Changing image according to Wordpress standards;';
709
  $url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
710
  }
 
711
  } else {
712
  $debug .= 'Found wrong formatted image: ' . $image . ';';
713
  }
 
714
  }
715
- }
716
-
717
  if ( strpos( $url, '/' ) === 0 ) {
718
  $url = get_bloginfo( 'url' ) . $url;
719
  $debug .= 'Relative url: ' . $url . ';';
720
  }
721
 
722
- if ( empty( $url ) ) { // parsed URL is empty or no file if can check
 
723
  $debug .= 'Image URL: ' . $url . ';';
724
  $debug .= 'Image is empty or no file. Using default image;';
725
  $url = get_option( 'relpoststh_default_image', $this->default_image );
@@ -809,6 +861,16 @@ class RelatedPostsThumbnails {
809
  return $this->finish_process( $output, $debug, $time );
810
  }
811
 
 
 
 
 
 
 
 
 
 
 
812
  function finish_process( $output, $debug, $time ) {
813
  $devmode = get_option( 'relpoststh_devmode', $this->devmode );
814
  if ( $devmode ) {
3
  * Plugin Name: WordPress Related Posts Thumbnails
4
  * Plugin URI: https://wpbrigade.com/wordpress/plugins/related-posts/?utm_source=related-posts-lite&utm_medium=plugin-uri&utm_campaign=pro-upgrade-rp
5
  * Description: Showing related posts thumbnails under the posts.
6
+ * Version: 1.8.2
7
  * Author: WPBrigade
8
  * Author URI: https://WPBrigade.com/?utm_source=related-posts-lite&utm_medium=author-link&utm_campaign=pro-upgrade-rp
9
  */
67
  update_option( 'relpoststh_default_image', $this->default_image );
68
 
69
  if ( get_option( 'relpoststh_auto', $this->auto ) ) {
70
+ $priority = apply_filters( 'rpt_content_prioirty', 10 ); // Alter priority of the related post content
71
+
72
+ if ( $this->prevent_on_editors() ) {
73
+ return;
74
+ }
75
+
76
+ add_filter( 'the_content', array(
77
+ $this,
78
+ 'auto_show'
79
  ), $priority );
80
  }
81
 
110
  ) );
111
 
112
  add_shortcode( 'related-posts-thumbnails', array( $this, 'related_posts_shortcode' ) );
113
+ }
114
+
115
+ /**
116
+ * Prevent related posts on editor screen (builders).
117
+ *
118
+ * @return bool $return
119
+ */
120
+ function prevent_on_editors() {
121
+ $return = false;
122
+ $prevent_on_edit = apply_filters( 'rpt_prevent_on_edit', array(
123
+ 'divi' => false,
124
+ ) );
125
+
126
+ foreach ( $prevent_on_edit as $key => $value ) {
127
+ switch ( $key ) {
128
+ case 'divi':
129
+ if ( $value && isset( $_GET['et_fb'] ) ) {
130
+ $return = true;
131
+ }
132
+
133
+ break;
134
+ }
135
+ }
136
+
137
+ return $return;
138
+ }
139
 
140
  function related_posts_shortcode( $atts ) {
141
  $atts = shortcode_atts( array(
632
  if ( ! empty( $main_title ) ) {
633
  $output .= '<p class="relpoststh-block-title">' . $main_title . '</p>';
634
  } else {
635
+ $top_text = stripslashes( get_option( 'relpoststh_top_text', $this->top_text ) );
636
+ $output .= stripslashes ( apply_filters( 'rpt_top_text', $top_text ) );
637
  }
638
  }
639
 
665
  foreach ( $posts as $post ) {
666
  $image = '';
667
  $url = '';
668
+ $alt = '';
669
 
670
  if ( $thsource == 'custom-field' ) {
671
+ $custom_field = get_option( 'relpoststh_customfield', $this->custom_field );
672
+ $custom_field_meta = get_post_meta( $post->ID, $custom_field, true );
673
 
674
  if ( empty( $custom_field ) ) {
675
  $debug .= 'No custom field specifield, using default thumbnail image;';
676
  $url = $this->default_image;
677
+ } elseif ( empty( $custom_field_meta ) && apply_filters( 'rpt_remove_empty_cfield', false ) ) {
678
+ $debug .= 'Custom field meta is empty, using rpt_remove_empty_cfield filter;';
679
+ continue;
680
+ } elseif ( empty( $custom_field_meta ) ) {
681
  $debug .= 'Custom field meta is empty, using default thumbnail image;';
682
  $url = $this->default_image;
683
+ } else {
684
  $debug .= 'Using custom field;';
685
  $url = $custom_field_meta;
686
  $theme_resize_url = get_option( 'relpoststh_theme_resize_url', '' );
709
  $debug .= 'Post has no thumbnail;';
710
  }
711
  }
712
+
713
+ // Theme does not support post-thumbnails, or post does not have assigned thumbnail
714
+ if ( $from_post_body ) {
715
  $debug .= 'Getting image from post body;';
716
  $wud = wp_upload_dir();
717
+
718
+ // search the first uploaded image in content
719
+ preg_match_all( '|<img.*?src=[\'"](' . $wud[ 'baseurl' ] . '.*?)[\'"].*?>|i', $post->post_content, $matches );
720
 
721
  if ( isset( $matches ) && isset( $matches[ 1 ][ 0 ] ) ) {
722
  $image = $matches[ 1 ][ 0 ];
723
  $html = $matches[ 0 ][ 0 ];
724
+
725
  if ( !empty( $html ) ) {
726
  preg_match( '/alt="([^"]*)"/i', $html, $array );
727
 
729
  $explode_tag = explode( '"', $array[ 0 ] );
730
  $alt = $explode_tag[ 1 ];
731
  }
 
732
  }
733
+
734
  } else {
735
  $debug .= 'No image was found;';
736
  }
737
 
738
  if ( strlen( trim( $image ) ) > 0 ) {
739
  $image_sizes = @getimagesize( $image );
740
+
741
  if ( $image_sizes === false ) {
742
+ $debug .= 'Unable to determine parsed image size';
743
  }
744
+
745
+ if ( ( $image_sizes !== false && isset( $image_sizes[ 0 ] ) ) && $image_sizes[ 0 ] == $width ) {
746
+ // if this image is the same size
747
  $debug .= 'Image used is the required size;';
748
  $url = $image;
749
+ }
750
+ elseif ( apply_filters( 'rpt_prevent_img_size_check', false ) && $image_sizes[ 0 ] < $width ) {
751
+ // if this image is samll than required size
752
+ $debug .= 'Image used is smaller than the required size, rpt_prevent_img_size_check filter is active;';
753
+ $url = $image;
754
+ }
755
+ else {
756
+ // search for resized thumbnail according to Wordpress thumbnails naming function
757
  $debug .= 'Changing image according to Wordpress standards;';
758
  $url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
759
  }
760
+
761
  } else {
762
  $debug .= 'Found wrong formatted image: ' . $image . ';';
763
  }
764
+
765
  }
766
+ }
767
+
768
  if ( strpos( $url, '/' ) === 0 ) {
769
  $url = get_bloginfo( 'url' ) . $url;
770
  $debug .= 'Relative url: ' . $url . ';';
771
  }
772
 
773
+ // parsed URL is empty or no image found
774
+ if ( empty( $url ) ) {
775
  $debug .= 'Image URL: ' . $url . ';';
776
  $debug .= 'Image is empty or no file. Using default image;';
777
  $url = get_option( 'relpoststh_default_image', $this->default_image );
861
  return $this->finish_process( $output, $debug, $time );
862
  }
863
 
864
+ // function is_url_404( $url ) {
865
+ // $response = wp_remote_request( $url,
866
+ // array(
867
+ // 'method' => 'GET'
868
+ // )
869
+ // );
870
+
871
+ // return $response['response']['code'];
872
+ // }
873
+
874
  function finish_process( $output, $debug, $time ) {
875
  $devmode = get_option( 'relpoststh_devmode', $this->devmode );
876
  if ( $devmode ) {