Version Description
- Please upgrade immediately - Added AMP Support, fix for post sorting and custom field option.
=
Download this release
Release Info
Developer | hiddenpearls |
Plugin | Related Posts Thumbnails Plugin for WordPress |
Version | 1.8.0 |
Comparing to | |
See all releases |
Code changes from version 1.7.2 to 1.8.0
- assets/blocks/css/blocks.editor.css +0 -22
- assets/blocks/css/blocks.editor.min.css +1 -0
- assets/blocks/css/blocks.style.css +0 -32
- assets/blocks/js/{editor.blocks.js → blocks.editor.js} +0 -0
- assets/blocks/js/frontend.blocks.js +0 -75
- assets/css/front.css +1 -1
- inc/rpt-blocks.php +2 -30
- inc/rpt-settings.php +2 -2
- readme.txt +11 -3
- related-posts-thumbnails.php +148 -108
assets/blocks/css/blocks.editor.css
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
.wp-block-jsforwpblocks-static .sorry.warning {
|
2 |
-
background: #C44D58;
|
3 |
-
color: white;
|
4 |
-
font-size: 1.2rem; }
|
5 |
-
.editor-visual-editor .wp-block-jsforwpblocks-custom-toolbar p {
|
6 |
-
font-size: 1.4rem; }
|
7 |
-
.wp-block-jsforwpblocks-media-upload .image-wrapper {
|
8 |
-
position: relative; }
|
9 |
-
|
10 |
-
.wp-block-jsforwpblocks-media-upload button.remove-image {
|
11 |
-
background-color: red;
|
12 |
-
border: 2px red solid;
|
13 |
-
padding: 5px 5px 0;
|
14 |
-
position: absolute;
|
15 |
-
top: 0;
|
16 |
-
left: 0;
|
17 |
-
opacity: .9; }
|
18 |
-
.wp-block-jsforwpblocks-media-upload button.remove-image svg {
|
19 |
-
background: red;
|
20 |
-
fill: white; }
|
21 |
-
.wp-block-jsforwpblocks-media-upload button.remove-image:hover {
|
22 |
-
opacity: 1; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/blocks/css/blocks.editor.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.rpt-container{display:-ms-flexbox;display:flex;max-width:750px;-ms-flex-wrap:wrap;flex-wrap:wrap}.rpt-single{padding:10px;margin-bottom:10px;width:25%;height:150px}.rpt-img{background:#333;width:100%;height:100%}.rpt-text{font-family:Arial;font-size:13px;color:#333;border:0 none;margin:3px 0 0;padding:0;text-align:center}.rpt-represntaion-msg{font-family:Arial;font-size:16px!important;font-weight:600;text-decoration:underline}
|
assets/blocks/css/blocks.style.css
DELETED
@@ -1,32 +0,0 @@
|
|
1 |
-
.rpt-container {
|
2 |
-
display: -ms-flexbox;
|
3 |
-
display: flex;
|
4 |
-
max-width: 750px;
|
5 |
-
-ms-flex-wrap: wrap;
|
6 |
-
flex-wrap: wrap; }
|
7 |
-
|
8 |
-
.rpt-single {
|
9 |
-
padding: 10px;
|
10 |
-
margin-bottom: 10px;
|
11 |
-
width: 25%;
|
12 |
-
height: 150px; }
|
13 |
-
|
14 |
-
.rpt-img {
|
15 |
-
background: #333333;
|
16 |
-
width: 100%;
|
17 |
-
height: 100%; }
|
18 |
-
|
19 |
-
.rpt-text {
|
20 |
-
font-family: Arial;
|
21 |
-
font-size: 13px;
|
22 |
-
color: #333333;
|
23 |
-
border: 0 none;
|
24 |
-
margin: 3px 0 0;
|
25 |
-
padding: 0;
|
26 |
-
text-align: center; }
|
27 |
-
|
28 |
-
.rpt-represntaion-msg {
|
29 |
-
font-family: Arial;
|
30 |
-
font-size: 16px !important;
|
31 |
-
font-weight: 600;
|
32 |
-
text-decoration: underline; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/blocks/js/{editor.blocks.js → blocks.editor.js}
RENAMED
File without changes
|
assets/blocks/js/frontend.blocks.js
DELETED
@@ -1,75 +0,0 @@
|
|
1 |
-
/******/ (function(modules) { // webpackBootstrap
|
2 |
-
/******/ // The module cache
|
3 |
-
/******/ var installedModules = {};
|
4 |
-
/******/
|
5 |
-
/******/ // The require function
|
6 |
-
/******/ function __webpack_require__(moduleId) {
|
7 |
-
/******/
|
8 |
-
/******/ // Check if module is in cache
|
9 |
-
/******/ if(installedModules[moduleId]) {
|
10 |
-
/******/ return installedModules[moduleId].exports;
|
11 |
-
/******/ }
|
12 |
-
/******/ // Create a new module (and put it into the cache)
|
13 |
-
/******/ var module = installedModules[moduleId] = {
|
14 |
-
/******/ i: moduleId,
|
15 |
-
/******/ l: false,
|
16 |
-
/******/ exports: {}
|
17 |
-
/******/ };
|
18 |
-
/******/
|
19 |
-
/******/ // Execute the module function
|
20 |
-
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
21 |
-
/******/
|
22 |
-
/******/ // Flag the module as loaded
|
23 |
-
/******/ module.l = true;
|
24 |
-
/******/
|
25 |
-
/******/ // Return the exports of the module
|
26 |
-
/******/ return module.exports;
|
27 |
-
/******/ }
|
28 |
-
/******/
|
29 |
-
/******/
|
30 |
-
/******/ // expose the modules object (__webpack_modules__)
|
31 |
-
/******/ __webpack_require__.m = modules;
|
32 |
-
/******/
|
33 |
-
/******/ // expose the module cache
|
34 |
-
/******/ __webpack_require__.c = installedModules;
|
35 |
-
/******/
|
36 |
-
/******/ // define getter function for harmony exports
|
37 |
-
/******/ __webpack_require__.d = function(exports, name, getter) {
|
38 |
-
/******/ if(!__webpack_require__.o(exports, name)) {
|
39 |
-
/******/ Object.defineProperty(exports, name, {
|
40 |
-
/******/ configurable: false,
|
41 |
-
/******/ enumerable: true,
|
42 |
-
/******/ get: getter
|
43 |
-
/******/ });
|
44 |
-
/******/ }
|
45 |
-
/******/ };
|
46 |
-
/******/
|
47 |
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
48 |
-
/******/ __webpack_require__.n = function(module) {
|
49 |
-
/******/ var getter = module && module.__esModule ?
|
50 |
-
/******/ function getDefault() { return module['default']; } :
|
51 |
-
/******/ function getModuleExports() { return module; };
|
52 |
-
/******/ __webpack_require__.d(getter, 'a', getter);
|
53 |
-
/******/ return getter;
|
54 |
-
/******/ };
|
55 |
-
/******/
|
56 |
-
/******/ // Object.prototype.hasOwnProperty.call
|
57 |
-
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
58 |
-
/******/
|
59 |
-
/******/ // __webpack_public_path__
|
60 |
-
/******/ __webpack_require__.p = "";
|
61 |
-
/******/
|
62 |
-
/******/ // Load entry module and return exports
|
63 |
-
/******/ return __webpack_require__(__webpack_require__.s = 4);
|
64 |
-
/******/ })
|
65 |
-
/************************************************************************/
|
66 |
-
/******/ ({
|
67 |
-
|
68 |
-
/***/ 4:
|
69 |
-
/***/ (function(module, exports) {
|
70 |
-
|
71 |
-
eval("console.log('Frontend Block JS');//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNC5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy8uL2Jsb2Nrcy9mcm9udGVuZC5qcz9kMmQ1Il0sInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKCdGcm9udGVuZCBCbG9jayBKUycpO1xuXG5cbi8vLy8vLy8vLy8vLy8vLy8vL1xuLy8gV0VCUEFDSyBGT09URVJcbi8vIC4vYmxvY2tzL2Zyb250ZW5kLmpzXG4vLyBtb2R1bGUgaWQgPSA0XG4vLyBtb2R1bGUgY2h1bmtzID0gMSJdLCJtYXBwaW5ncyI6IkFBQUEiLCJzb3VyY2VSb290IjoiIn0=\n//# sourceURL=webpack-internal:///4\n");
|
72 |
-
|
73 |
-
/***/ })
|
74 |
-
|
75 |
-
/******/ });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/css/front.css
CHANGED
@@ -176,4 +176,4 @@ text-align: center;
|
|
176 |
display: block;
|
177 |
padding-top: 10px;
|
178 |
font-size: 11px;
|
179 |
-
}
|
176 |
display: block;
|
177 |
padding-top: 10px;
|
178 |
font-size: 11px;
|
179 |
+
}
|
inc/rpt-blocks.php
CHANGED
@@ -4,8 +4,8 @@
|
|
4 |
*
|
5 |
*/
|
6 |
function enqueue_block_editor_assets() {
|
7 |
-
$block_path = 'assets/blocks/js/editor.
|
8 |
-
$style_path = 'assets/blocks/css/blocks.editor.css';
|
9 |
|
10 |
// Enqueue the bundled block JS file
|
11 |
wp_enqueue_script( 'rpt-blocks-js', RELATED_POSTS_THUMBNAILS_URI.$block_path, array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-editor'), RELATED_POSTS_THUMBNAILS_VERSION );
|
@@ -16,34 +16,6 @@ function enqueue_block_editor_assets() {
|
|
16 |
|
17 |
add_action('enqueue_block_editor_assets', 'enqueue_block_editor_assets');
|
18 |
|
19 |
-
/**
|
20 |
-
* Enqueue front end and editor JavaScript and CSS assets.
|
21 |
-
*
|
22 |
-
*/
|
23 |
-
function enqueue_assets() {
|
24 |
-
$style_path = 'assets/blocks/css/blocks.style.css';
|
25 |
-
wp_enqueue_style( 'rpt-blocks', RELATED_POSTS_THUMBNAILS_URI.$style_path , null, RELATED_POSTS_THUMBNAILS_VERSION );
|
26 |
-
}
|
27 |
-
|
28 |
-
add_action('enqueue_block_assets', 'enqueue_assets');
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Enqueue frontend JavaScript and CSS assets.
|
32 |
-
*
|
33 |
-
*/
|
34 |
-
function enqueue_frontend_assets() {
|
35 |
-
// If in the backend, bail out.
|
36 |
-
if (is_admin()) {
|
37 |
-
return;
|
38 |
-
}
|
39 |
-
|
40 |
-
$block_path = 'assets/blocks/js/frontend.blocks.js';
|
41 |
-
|
42 |
-
wp_enqueue_script( 'rpt-blocks-frontend', RELATED_POSTS_THUMBNAILS_URI.$block_path, array(), RELATED_POSTS_THUMBNAILS_VERSION );
|
43 |
-
}
|
44 |
-
|
45 |
-
add_action('enqueue_block_assets', 'enqueue_frontend_assets');
|
46 |
-
|
47 |
/**
|
48 |
* Create related posts block category.
|
49 |
*
|
4 |
*
|
5 |
*/
|
6 |
function enqueue_block_editor_assets() {
|
7 |
+
$block_path = 'assets/blocks/js/blocks.editor.js';
|
8 |
+
$style_path = 'assets/blocks/css/blocks.editor.min.css';
|
9 |
|
10 |
// Enqueue the bundled block JS file
|
11 |
wp_enqueue_script( 'rpt-blocks-js', RELATED_POSTS_THUMBNAILS_URI.$block_path, array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-editor'), RELATED_POSTS_THUMBNAILS_VERSION );
|
16 |
|
17 |
add_action('enqueue_block_editor_assets', 'enqueue_block_editor_assets');
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
/**
|
20 |
* Create related posts block category.
|
21 |
*
|
inc/rpt-settings.php
CHANGED
@@ -187,8 +187,8 @@ if ( isset( $_POST[ 'action' ] ) && ( $_POST[ 'action' ] == 'update' ) ) {
|
|
187 |
}
|
188 |
}
|
189 |
$available_sizes = array(
|
190 |
-
|
191 |
-
|
192 |
);
|
193 |
if ( current_theme_supports( 'post-thumbnails' ) ) {
|
194 |
global $_wp_additional_image_sizes;
|
187 |
}
|
188 |
}
|
189 |
$available_sizes = array(
|
190 |
+
'thumbnail' => 'thumbnail',
|
191 |
+
'medium' => 'medium'
|
192 |
);
|
193 |
if ( current_theme_supports( 'post-thumbnails' ) ) {
|
194 |
global $_wp_additional_image_sizes;
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ 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 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -71,11 +71,19 @@ If there are no images of the specified size in the post, or file does not exist
|
|
71 |
|
72 |
== Upgrade Notice ==
|
73 |
|
74 |
-
= 1.
|
75 |
-
* Please upgrade immediately - fix for post sorting
|
76 |
|
77 |
== Changelog ==
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
= 1.7.2 - 2019-06-10 =
|
80 |
* Bug Fix : Sorting issue when latest posts option selected.
|
81 |
|
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.0
|
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.0 =
|
75 |
+
* Please upgrade immediately - Added AMP Support, fix for post sorting and custom field option.
|
76 |
|
77 |
== Changelog ==
|
78 |
|
79 |
+
= 1.8.0 - 2019-06-25 =
|
80 |
+
* New Feature : Added AMP support.
|
81 |
+
* New Feature : Filter to disable related posts on AMP.
|
82 |
+
* New Feature : Filter to style list for related posts on AMP.
|
83 |
+
* Refactor : Remove unused assets for gutenberg block.
|
84 |
+
* Bug Fix : Fix query for sorting latest posts.
|
85 |
+
* Bug Fix : Fix empty vairable check on custom field.
|
86 |
+
|
87 |
= 1.7.2 - 2019-06-10 =
|
88 |
* Bug Fix : Sorting issue when latest posts option selected.
|
89 |
|
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.
|
7 |
* Author: WPBrigade
|
8 |
* Author URI: https://WPBrigade.com/?utm_source=related-posts-lite&utm_medium=author-link&utm_campaign=pro-upgrade-rp
|
9 |
*/
|
@@ -376,22 +376,33 @@ class RelatedPostsThumbnails {
|
|
376 |
if ( $this->is_relpoststh_show() ) {
|
377 |
return $this->get_thumbnails( $show_top );
|
378 |
}
|
|
|
379 |
return '';
|
380 |
}
|
381 |
|
382 |
-
function get_thumbnails( $show_top = false, $
|
383 |
-
// Retrieve Related Posts HTML for output
|
384 |
$output = '';
|
385 |
$debug = 'Developer mode initialisation; Version: 1.2.9;';
|
386 |
$time = microtime( true );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
$posts_number_opt = get_option( 'relpoststh_number', $this->number );
|
388 |
-
$posts_number = !empty( $
|
389 |
$height = '';
|
390 |
$width = '';
|
391 |
// $date = '';
|
|
|
392 |
|
393 |
-
$sort_by_opt = get_option( 'rpt_post_sort') == 'latest' ? 'post_date
|
394 |
-
$sort_by = !empty( $
|
395 |
|
396 |
// rpt_content_align: add content allignment class; clases are: relpost-align-left, relpost-align-right and relpost-align-center
|
397 |
$output = '<!-- relpost-thumb-wrapper -->';
|
@@ -499,7 +510,8 @@ class RelatedPostsThumbnails {
|
|
499 |
// }
|
500 |
// $checked_post_type = rtrim( $selected_post_type, ',' );
|
501 |
|
502 |
-
$query = "SELECT distinct ID FROM $wpdb->posts ";
|
|
|
503 |
$where = " WHERE post_type = '" . $post_type . "' AND post_status = 'publish' AND ID<>" . $id; // not the current post
|
504 |
// $where = " WHERE post_type IN (" . $checked_post_type . ") AND post_status = 'publish' AND ID<>" . $id; // not the current post
|
505 |
$startdate = get_option( 'relpoststh_startdate' );
|
@@ -517,9 +529,9 @@ class RelatedPostsThumbnails {
|
|
517 |
$where .= " AND $wpdb->postmeta.meta_key = '_thumbnail_id'";
|
518 |
}
|
519 |
|
520 |
-
$
|
521 |
-
|
522 |
-
$random_posts = $wpdb->get_results( $query . $join . $where . $
|
523 |
|
524 |
/* Get posts by their IDs */
|
525 |
if ( !is_array( $random_posts ) || count( $random_posts ) < 1 ) {
|
@@ -528,10 +540,12 @@ class RelatedPostsThumbnails {
|
|
528 |
}
|
529 |
|
530 |
$posts_in = array();
|
|
|
531 |
foreach ( $random_posts as $random_post ) {
|
532 |
$posts_in[] = $random_post->ID;
|
533 |
}
|
534 |
-
|
|
|
535 |
$posts = $wpdb->get_results( $query );
|
536 |
|
537 |
if ( !( is_array( $posts ) && count( $posts ) > 0 ) ) { // no posts
|
@@ -579,13 +593,17 @@ class RelatedPostsThumbnails {
|
|
579 |
$debug .= 'Using default height;';
|
580 |
$height = get_option( 'thumbnail_size_h' );
|
581 |
}
|
|
|
582 |
$debug .= 'Got sizes ' . $width . 'x' . $height . ';';
|
583 |
|
584 |
// rendering related posts HTML
|
585 |
-
|
586 |
-
|
|
|
|
|
587 |
} else {
|
588 |
-
|
|
|
589 |
}
|
590 |
|
591 |
$relpoststh_output_style = get_option( 'relpoststh_output_style', $this->output_style );
|
@@ -614,15 +632,23 @@ class RelatedPostsThumbnails {
|
|
614 |
}
|
615 |
|
616 |
foreach ( $posts as $post ) {
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
|
|
|
|
|
|
|
|
622 |
$debug .= 'No custom field specifield, using default thumbnail image;';
|
623 |
-
$url = $this->default_image;
|
|
|
|
|
|
|
624 |
} else {
|
625 |
$debug .= 'Using custom field;';
|
|
|
626 |
$theme_resize_url = get_option( 'relpoststh_theme_resize_url', '' );
|
627 |
|
628 |
if ( strpos( $url, '/wp-content' ) !== false ) {
|
@@ -633,71 +659,71 @@ class RelatedPostsThumbnails {
|
|
633 |
$url = $theme_resize_url . '?src=' . $url . '&w=' . $width . '&h=' . $height . '&zc=1&q=90';
|
634 |
}
|
635 |
}
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
|
692 |
if ( strpos( $url, '/' ) === 0 ) {
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
|
697 |
-
$debug .= 'Image URL: ' . $url . ';';
|
698 |
if ( empty( $basic_url ) ) { // parsed URL is empty or no file if can check
|
699 |
-
|
700 |
-
|
|
|
701 |
}
|
702 |
|
703 |
$title = $this->process_text_cut( $post->post_title, $text_length );
|
@@ -710,44 +736,58 @@ class RelatedPostsThumbnails {
|
|
710 |
}
|
711 |
|
712 |
if ( empty( $alt ) ) {
|
713 |
-
|
714 |
}
|
715 |
|
716 |
$fontface = str_replace( '"', "'", stripslashes( get_option( 'relpoststh_fontfamily', $this->font_family ) ) );
|
717 |
-
|
718 |
$debug .= 'Using title with size ' . $text_length . '. Using excerpt with size ' . $excerpt_length . ';';
|
719 |
$after_content = apply_filters( 'rpth_after_content', '', $post );
|
720 |
|
721 |
-
if ( $
|
722 |
-
$
|
723 |
-
$output .= '<li ';
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
$
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
736 |
$output .= ' style="width: ' . $width . 'px;height: ' . $text_height . 'px; font-family: ' . $fontface . '; "';
|
737 |
-
|
|
|
738 |
// $output .= '><span class="rpth_list_content">' . $title . $excerpt . '</span>' . $date . '</a></li>';
|
739 |
$output .= '><span class="rpth_list_content">' . $title . $excerpt . '</span>' . $after_content . '</a></li>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
740 |
}
|
741 |
-
|
742 |
-
|
743 |
-
$output .= '<div style="width: ' . $width . 'px; height: ' . ( $height + $text_height ) . 'px;">';
|
744 |
-
$output .= '<div class="relpost-block-single-image" alt="' . $alt . '" style=" background: transparent url(' . esc_url( $url ) . ') no-repeat scroll 0% 0%; width: ' . $width . 'px; height: ' . $height . 'px; "></div>';
|
745 |
-
$output .= '<div class="relpost-block-single-text" style="font-family: ' . $fontface . '; font-size: ' . get_option( 'relpoststh_fontsize', $this->font_size ) . 'px; color: ' . get_option( 'relpoststh_fontcolor', $this->font_color ) . ';">' . $title . $excerpt . '</div>';
|
746 |
-
$output .= $after_content;
|
747 |
-
// $output .= $date;
|
748 |
-
$output .= '</div>';
|
749 |
-
$output .= '</a>';
|
750 |
-
}
|
751 |
} // end foreach
|
752 |
if ( $relpoststh_output_style == 'list' ) {
|
753 |
$output .= '</ul>';
|
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.0
|
7 |
* Author: WPBrigade
|
8 |
* Author URI: https://WPBrigade.com/?utm_source=related-posts-lite&utm_medium=author-link&utm_campaign=pro-upgrade-rp
|
9 |
*/
|
376 |
if ( $this->is_relpoststh_show() ) {
|
377 |
return $this->get_thumbnails( $show_top );
|
378 |
}
|
379 |
+
|
380 |
return '';
|
381 |
}
|
382 |
|
383 |
+
function get_thumbnails( $show_top = false, $posts_number = '', $sort_by = '', $main_title = '' ) {
|
|
|
384 |
$output = '';
|
385 |
$debug = 'Developer mode initialisation; Version: 1.2.9;';
|
386 |
$time = microtime( true );
|
387 |
+
|
388 |
+
$amp_endpoint = ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) ? true : false;
|
389 |
+
|
390 |
+
// Stop execution if RPT is disabled in AMP view
|
391 |
+
if ( ( $amp_endpoint ) && ( 'disable' === apply_filters( 'rpth_amp', true ) ) ) {
|
392 |
+
$debug .= 'AMP view disabled';
|
393 |
+
|
394 |
+
return $this->finish_process( '', $debug, $time );
|
395 |
+
}
|
396 |
+
|
397 |
$posts_number_opt = get_option( 'relpoststh_number', $this->number );
|
398 |
+
$posts_number = !empty( $posts_number ) ? $posts_number : $posts_number_opt;
|
399 |
$height = '';
|
400 |
$width = '';
|
401 |
// $date = '';
|
402 |
+
$order_by = 'DESC';
|
403 |
|
404 |
+
$sort_by_opt = get_option( 'rpt_post_sort') == 'latest' ? 'post_date '.$order_by.'': 'rand()';
|
405 |
+
$sort_by = !empty( $sort_by ) ? $sort_by : $sort_by_opt;
|
406 |
|
407 |
// rpt_content_align: add content allignment class; clases are: relpost-align-left, relpost-align-right and relpost-align-center
|
408 |
$output = '<!-- relpost-thumb-wrapper -->';
|
510 |
// }
|
511 |
// $checked_post_type = rtrim( $selected_post_type, ',' );
|
512 |
|
513 |
+
// $query = "SELECT distinct ID FROM $wpdb->posts ";
|
514 |
+
$query = "SELECT ID FROM $wpdb->posts ";
|
515 |
$where = " WHERE post_type = '" . $post_type . "' AND post_status = 'publish' AND ID<>" . $id; // not the current post
|
516 |
// $where = " WHERE post_type IN (" . $checked_post_type . ") AND post_status = 'publish' AND ID<>" . $id; // not the current post
|
517 |
$startdate = get_option( 'relpoststh_startdate' );
|
529 |
$where .= " AND $wpdb->postmeta.meta_key = '_thumbnail_id'";
|
530 |
}
|
531 |
|
532 |
+
$order_query = ' ORDER BY ' . $sort_by;
|
533 |
+
$limit_order = $order_query . ' LIMIT ' . $posts_number;
|
534 |
+
$random_posts = $wpdb->get_results( $query . $join . $where . $limit_order );
|
535 |
|
536 |
/* Get posts by their IDs */
|
537 |
if ( !is_array( $random_posts ) || count( $random_posts ) < 1 ) {
|
540 |
}
|
541 |
|
542 |
$posts_in = array();
|
543 |
+
|
544 |
foreach ( $random_posts as $random_post ) {
|
545 |
$posts_in[] = $random_post->ID;
|
546 |
}
|
547 |
+
|
548 |
+
$query = "SELECT ID, post_content, post_excerpt, post_title FROM $wpdb->posts WHERE ID IN ('" . implode( "', '", $posts_in ) . "') $order_query ";
|
549 |
$posts = $wpdb->get_results( $query );
|
550 |
|
551 |
if ( !( is_array( $posts ) && count( $posts ) > 0 ) ) { // no posts
|
593 |
$debug .= 'Using default height;';
|
594 |
$height = get_option( 'thumbnail_size_h' );
|
595 |
}
|
596 |
+
|
597 |
$debug .= 'Got sizes ' . $width . 'x' . $height . ';';
|
598 |
|
599 |
// rendering related posts HTML
|
600 |
+
|
601 |
+
if ( $show_top ) {
|
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 |
|
609 |
$relpoststh_output_style = get_option( 'relpoststh_output_style', $this->output_style );
|
632 |
}
|
633 |
|
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 = $basic_url = $this->default_image;
|
646 |
+
} elseif ( empty( $custom_field_meta ) ) {
|
647 |
+
$debug .= 'Custom field meta is empty, using default thumbnail image;';
|
648 |
+
$url = $basic_url = $this->default_image;
|
649 |
} else {
|
650 |
$debug .= 'Using custom field;';
|
651 |
+
$url = $basic_url = $custom_field_meta;
|
652 |
$theme_resize_url = get_option( 'relpoststh_theme_resize_url', '' );
|
653 |
|
654 |
if ( strpos( $url, '/wp-content' ) !== false ) {
|
659 |
$url = $theme_resize_url . '?src=' . $url . '&w=' . $width . '&h=' . $height . '&zc=1&q=90';
|
660 |
}
|
661 |
}
|
662 |
+
} else {
|
663 |
+
$from_post_body = true;
|
664 |
+
if ( current_theme_supports( 'post-thumbnails' ) ) { // using built in Wordpress feature
|
665 |
+
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
|
666 |
+
$debug .= 'Post-thumbnails enabled in theme;';
|
667 |
+
if ( !( empty( $post_thumbnail_id ) || $post_thumbnail_id === false ) ) { // post has thumbnail
|
668 |
+
$debug .= 'Post has thumbnail ' . $post_thumbnail_id . ';';
|
669 |
+
$debug .= 'Postthname: ' . $poststhname . ';';
|
670 |
+
$image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
|
671 |
+
$alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
|
672 |
+
$url = $image[ 0 ];
|
673 |
+
$from_post_body = false;
|
674 |
+
} else {
|
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 |
+
|
689 |
+
if ( !empty( $array ) && is_array( $array ) ) {
|
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 |
+
$basic_url = $url;
|
715 |
+
}
|
716 |
+
}
|
717 |
|
718 |
if ( strpos( $url, '/' ) === 0 ) {
|
719 |
+
$url = $basic_url = get_bloginfo( 'url' ) . $url;
|
720 |
+
$debug .= 'Relative url: ' . $url . ';';
|
721 |
+
}
|
722 |
|
|
|
723 |
if ( empty( $basic_url ) ) { // parsed URL is empty or no file if can check
|
724 |
+
$debug .= 'Image URL: ' . $url . ';';
|
725 |
+
$debug .= 'Image is empty or no file. Using default image;';
|
726 |
+
$url = get_option( 'relpoststh_default_image', $this->default_image );
|
727 |
}
|
728 |
|
729 |
$title = $this->process_text_cut( $post->post_title, $text_length );
|
736 |
}
|
737 |
|
738 |
if ( empty( $alt ) ) {
|
739 |
+
$alt = str_replace('"', '', $title);
|
740 |
}
|
741 |
|
742 |
$fontface = str_replace( '"', "'", stripslashes( get_option( 'relpoststh_fontfamily', $this->font_family ) ) );
|
|
|
743 |
$debug .= 'Using title with size ' . $text_length . '. Using excerpt with size ' . $excerpt_length . ';';
|
744 |
$after_content = apply_filters( 'rpth_after_content', '', $post );
|
745 |
|
746 |
+
if ( ( $amp_endpoint ) && ( true === apply_filters( 'rpth_amp', true ) ) ) {
|
747 |
+
$debug .= 'AMP view enabled';
|
748 |
+
$output .= '<li style="' . apply_filters( 'rpth_amp_list_style', 'margin: 5px 20px;' ) . '">';
|
749 |
+
$output .= '<a href="' . get_permalink( $post->ID ) . '" class="relpost_content" font-family: ' . $fontface . '>';
|
750 |
+
$output .= '<span class="rpth_amp_list_content">' . $title . $excerpt . '</span>' . $after_content . '</a></li>';
|
751 |
+
} else {
|
752 |
+
if ( $relpoststh_output_style == 'list' ) {
|
753 |
+
$link = get_permalink( $post->ID );
|
754 |
+
$output .= '<li ';
|
755 |
+
|
756 |
+
// if ( !$relpoststh_cleanhtml ) {
|
757 |
+
// $output .= ' onmouseout="this.style.backgroundColor=\'' . get_option( 'relpoststh_background', $this->background ) . '\'"';
|
758 |
+
// }
|
759 |
+
|
760 |
+
$output .= '>';
|
761 |
+
$output .= '<a href="' . $link . '" ><img class="relpost-post-image" alt="' . $alt . '" src="' . esc_url( $url ) . '" width="' . $width . '" height="' . $height . '" ';
|
762 |
+
|
763 |
+
// if ( !$relpoststh_cleanhtml ) {
|
764 |
+
// $output .= 'style="padding: 0px; margin: 0px; border: 0pt none;"';
|
765 |
+
// }
|
766 |
+
|
767 |
+
$output .= '/></a>';
|
768 |
+
|
769 |
+
if ( $text_height != '0' ) {
|
770 |
+
$output .= '<a href="' . $link . '" class="relpost_content"';
|
771 |
+
|
772 |
+
if ( !$relpoststh_cleanhtml ) {
|
773 |
$output .= ' style="width: ' . $width . 'px;height: ' . $text_height . 'px; font-family: ' . $fontface . '; "';
|
774 |
+
}
|
775 |
+
|
776 |
// $output .= '><span class="rpth_list_content">' . $title . $excerpt . '</span>' . $date . '</a></li>';
|
777 |
$output .= '><span class="rpth_list_content">' . $title . $excerpt . '</span>' . $after_content . '</a></li>';
|
778 |
+
}
|
779 |
+
} else {
|
780 |
+
$output .= '<a class="relpost-block-single" href="' . get_permalink( $post->ID ) . '">';
|
781 |
+
$output .= '<div style="width: ' . $width . 'px; height: ' . ( $height + $text_height ) . 'px;">';
|
782 |
+
$output .= '<div class="relpost-block-single-image" alt="' . $alt . '" style=" background: transparent url(' . esc_url( $url ) . ') no-repeat scroll 0% 0%; width: ' . $width . 'px; height: ' . $height . 'px; "></div>';
|
783 |
+
$output .= '<div class="relpost-block-single-text" style="font-family: ' . $fontface . '; font-size: ' . get_option( 'relpoststh_fontsize', $this->font_size ) . 'px; color: ' . get_option( 'relpoststh_fontcolor', $this->font_color ) . ';">' . $title . $excerpt . '</div>';
|
784 |
+
$output .= $after_content;
|
785 |
+
// $output .= $date;
|
786 |
+
$output .= '</div>';
|
787 |
+
$output .= '</a>';
|
788 |
}
|
789 |
+
}
|
790 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
791 |
} // end foreach
|
792 |
if ( $relpoststh_output_style == 'list' ) {
|
793 |
$output .= '</ul>';
|