Version Description
- Please upgrade immediately - Introducing Gutenberg block for Related posts.
=
Download this release
Release Info
Developer | hiddenpearls |
Plugin | Related Posts Thumbnails Plugin for WordPress |
Version | 1.7.0 |
Comparing to | |
See all releases |
Code changes from version 1.6.6 to 1.7.0
- assets/blocks/css/blocks.editor.css +22 -0
- assets/blocks/css/blocks.style.css +32 -0
- assets/blocks/js/editor.blocks.js +93 -0
- assets/blocks/js/frontend.blocks.js +75 -0
- inc/rpt-blocks.php +107 -0
- readme.txt +15 -5
- related-posts-thumbnails.php +807 -841
assets/blocks/css/blocks.editor.css
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.style.css
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = 0);
|
64 |
+
/******/ })
|
65 |
+
/************************************************************************/
|
66 |
+
/******/ ([
|
67 |
+
/* 0 */
|
68 |
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
69 |
+
|
70 |
+
"use strict";
|
71 |
+
eval("Object.defineProperty(__webpack_exports__, \"__esModule\", { value: true });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__i18n_js__ = __webpack_require__(1);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__i18n_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__i18n_js__);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__related_posts__ = __webpack_require__(2);\n\n\n/**\r\n * Import blocks\r\n */\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMC5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy8uL2Jsb2Nrcy9pbmRleC5qcz84MTkzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcIi4vaTE4bi5qc1wiO1xuXG4vKipcclxuICogSW1wb3J0IGJsb2Nrc1xyXG4gKi9cbmltcG9ydCBcIi4vcmVsYXRlZC1wb3N0c1wiO1xuXG5cbi8vLy8vLy8vLy8vLy8vLy8vL1xuLy8gV0VCUEFDSyBGT09URVJcbi8vIC4vYmxvY2tzL2luZGV4LmpzXG4vLyBtb2R1bGUgaWQgPSAwXG4vLyBtb2R1bGUgY2h1bmtzID0gMCJdLCJtYXBwaW5ncyI6IkFBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBOyIsInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///0\n");
|
72 |
+
|
73 |
+
/***/ }),
|
74 |
+
/* 1 */
|
75 |
+
/***/ (function(module, exports) {
|
76 |
+
|
77 |
+
eval("wp.i18n.setLocaleData({ '': {} }, 'related-post-thumbnails');//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMS5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy8uL2Jsb2Nrcy9pMThuLmpzP2I0MTQiXSwic291cmNlc0NvbnRlbnQiOlsid3AuaTE4bi5zZXRMb2NhbGVEYXRhKHsgJyc6IHt9IH0sICdyZWxhdGVkLXBvc3QtdGh1bWJuYWlscycpO1xuXG5cbi8vLy8vLy8vLy8vLy8vLy8vL1xuLy8gV0VCUEFDSyBGT09URVJcbi8vIC4vYmxvY2tzL2kxOG4uanNcbi8vIG1vZHVsZSBpZCA9IDFcbi8vIG1vZHVsZSBjaHVua3MgPSAwIl0sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///1\n");
|
78 |
+
|
79 |
+
/***/ }),
|
80 |
+
/* 2 */
|
81 |
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
82 |
+
|
83 |
+
"use strict";
|
84 |
+
eval("/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__style_scss__ = __webpack_require__(3);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__style_scss___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__style_scss__);\n/**\r\n * Block dependencies\r\n */\n\n\n/**\r\n * Internal block libraries\r\n */\nvar __ = wp.i18n.__;\nvar registerBlockType = wp.blocks.registerBlockType;\nvar Spinner = wp.components.Spinner;\nvar withSelect = wp.data.withSelect;\nvar _wp$editor = wp.editor,\n RichText = _wp$editor.RichText,\n AlignmentToolbar = _wp$editor.AlignmentToolbar,\n BlockControls = _wp$editor.BlockControls,\n BlockAlignmentToolbar = _wp$editor.BlockAlignmentToolbar,\n InspectorControls = _wp$editor.InspectorControls;\nvar _wp$components = wp.components,\n Toolbar = _wp$components.Toolbar,\n Button = _wp$components.Button,\n Tooltip = _wp$components.Tooltip,\n PanelBody = _wp$components.PanelBody,\n PanelRow = _wp$components.PanelRow,\n FormToggle = _wp$components.FormToggle,\n TextControl = _wp$components.TextControl,\n SelectControl = _wp$components.SelectControl,\n ServerSideRender = _wp$components.ServerSideRender;\n\n\nregisterBlockType('related-post-thumbnails/rpt-block', {\n title: __('Related Posts', 'related-post-thumbnails'),\n description: __('A related posts block', 'related-post-thumbnails'),\n icon: 'grid-view',\n category: 'related-post-thumbnails-blocks',\n attributes: {\n mainTitle: {\n type: 'string'\n },\n postNumber: {\n type: 'string',\n default: 3\n },\n postSort: {\n type: 'string',\n default: 'random'\n }\n },\n edit: function edit(props) {\n var attributes = props.attributes,\n className = props.className,\n isSelected = props.isSelected,\n setAttributes = props.setAttributes;\n\n\n var changePostNumber = function changePostNumber(e) {\n if (e < 26) {\n props.setAttributes({ postNumber: e });\n }\n };\n\n var representBlocks = function representBlocks() {\n var table = [];\n\n // Outer loop to create parent\n for (var i = 0; i < props.attributes.postNumber; i++) {\n var children = [];\n //Inner loop to create children\n for (var j = 0; j < 5; j++) {\n children.push(wp.element.createElement(\n 'td',\n null,\n 'Column ' + (j + 1)\n ));\n }\n\n //Create the parent and add the children\n table.push(wp.element.createElement(\n 'div',\n { className: 'rpt-single' },\n wp.element.createElement('div', { className: 'rpt-img' }),\n wp.element.createElement(\n 'div',\n { className: 'rpt-text' },\n __('Post Title', 'related-post-thumbnails')\n )\n ));\n }\n return table;\n };\n\n return [wp.element.createElement(\n InspectorControls,\n null,\n wp.element.createElement(\n PanelBody,\n { title: __('Related Posts', 'related-post-thumbnails') },\n wp.element.createElement(\n PanelRow,\n null,\n wp.element.createElement(\n 'strong',\n null,\n __('Related Posts Block Title', 'related-post-thumbnails')\n ),\n wp.element.createElement(TextControl, {\n value: props.attributes.mainTitle,\n onChange: function onChange(mainTitle) {\n return props.setAttributes({ mainTitle: mainTitle });\n }\n })\n ),\n wp.element.createElement(\n PanelRow,\n null,\n wp.element.createElement(\n 'strong',\n null,\n __('Number of Posts', 'related-post-thumbnails')\n ),\n wp.element.createElement(TextControl, {\n type: 'number',\n value: props.attributes.postNumber,\n onChange: changePostNumber\n })\n ),\n wp.element.createElement(\n PanelRow,\n null,\n wp.element.createElement(\n 'strong',\n null,\n __('Sort Posts Order', 'related-post-thumbnails')\n ),\n wp.element.createElement(SelectControl, {\n value: props.attributes.postSort,\n options: [{ value: \"random\", label: \"Random\" }, { value: \"latest\", label: \"Latest\" }],\n onChange: function onChange(postSort) {\n return props.setAttributes({ postSort: postSort });\n }\n })\n )\n )\n ), wp.element.createElement(\n 'p',\n { className: 'rpt-represntaion-msg' },\n __('This is the representaion of Related Post Thumbnails', 'related-post-thumbnails')\n ), wp.element.createElement(\n 'div',\n null,\n wp.element.createElement(\n 'p',\n null,\n props.attributes.mainTitle\n ),\n wp.element.createElement(\n 'div',\n { className: 'rpt-container' },\n representBlocks()\n )\n )];\n },\n save: function save() {\n // Rendering in PHP\n return null;\n }\n});//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMi5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy8uL2Jsb2Nrcy9yZWxhdGVkLXBvc3RzL2luZGV4LmpzPzZkNWYiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqXHJcbiAqIEJsb2NrIGRlcGVuZGVuY2llc1xyXG4gKi9cbmltcG9ydCAnLi9zdHlsZS5zY3NzJztcblxuLyoqXHJcbiAqIEludGVybmFsIGJsb2NrIGxpYnJhcmllc1xyXG4gKi9cbnZhciBfXyA9IHdwLmkxOG4uX187XG52YXIgcmVnaXN0ZXJCbG9ja1R5cGUgPSB3cC5ibG9ja3MucmVnaXN0ZXJCbG9ja1R5cGU7XG52YXIgU3Bpbm5lciA9IHdwLmNvbXBvbmVudHMuU3Bpbm5lcjtcbnZhciB3aXRoU2VsZWN0ID0gd3AuZGF0YS53aXRoU2VsZWN0O1xudmFyIF93cCRlZGl0b3IgPSB3cC5lZGl0b3IsXG4gICAgUmljaFRleHQgPSBfd3AkZWRpdG9yLlJpY2hUZXh0LFxuICAgIEFsaWdubWVudFRvb2xiYXIgPSBfd3AkZWRpdG9yLkFsaWdubWVudFRvb2xiYXIsXG4gICAgQmxvY2tDb250cm9scyA9IF93cCRlZGl0b3IuQmxvY2tDb250cm9scyxcbiAgICBCbG9ja0FsaWdubWVudFRvb2xiYXIgPSBfd3AkZWRpdG9yLkJsb2NrQWxpZ25tZW50VG9vbGJhcixcbiAgICBJbnNwZWN0b3JDb250cm9scyA9IF93cCRlZGl0b3IuSW5zcGVjdG9yQ29udHJvbHM7XG52YXIgX3dwJGNvbXBvbmVudHMgPSB3cC5jb21wb25lbnRzLFxuICAgIFRvb2xiYXIgPSBfd3AkY29tcG9uZW50cy5Ub29sYmFyLFxuICAgIEJ1dHRvbiA9IF93cCRjb21wb25lbnRzLkJ1dHRvbixcbiAgICBUb29sdGlwID0gX3dwJGNvbXBvbmVudHMuVG9vbHRpcCxcbiAgICBQYW5lbEJvZHkgPSBfd3AkY29tcG9uZW50cy5QYW5lbEJvZHksXG4gICAgUGFuZWxSb3cgPSBfd3AkY29tcG9uZW50cy5QYW5lbFJvdyxcbiAgICBGb3JtVG9nZ2xlID0gX3dwJGNvbXBvbmVudHMuRm9ybVRvZ2dsZSxcbiAgICBUZXh0Q29udHJvbCA9IF93cCRjb21wb25lbnRzLlRleHRDb250cm9sLFxuICAgIFNlbGVjdENvbnRyb2wgPSBfd3AkY29tcG9uZW50cy5TZWxlY3RDb250cm9sLFxuICAgIFNlcnZlclNpZGVSZW5kZXIgPSBfd3AkY29tcG9uZW50cy5TZXJ2ZXJTaWRlUmVuZGVyO1xuXG5cbnJlZ2lzdGVyQmxvY2tUeXBlKCdyZWxhdGVkLXBvc3QtdGh1bWJuYWlscy9ycHQtYmxvY2snLCB7XG4gIHRpdGxlOiBfXygnUmVsYXRlZCBQb3N0cycsICdyZWxhdGVkLXBvc3QtdGh1bWJuYWlscycpLFxuICBkZXNjcmlwdGlvbjogX18oJ0EgcmVsYXRlZCBwb3N0cyBibG9jaycsICdyZWxhdGVkLXBvc3QtdGh1bWJuYWlscycpLFxuICBpY29uOiAnZ3JpZC12aWV3JyxcbiAgY2F0ZWdvcnk6ICdyZWxhdGVkLXBvc3QtdGh1bWJuYWlscy1ibG9ja3MnLFxuICBhdHRyaWJ1dGVzOiB7XG4gICAgbWFpblRpdGxlOiB7XG4gICAgICB0eXBlOiAnc3RyaW5nJ1xuICAgIH0sXG4gICAgcG9zdE51bWJlcjoge1xuICAgICAgdHlwZTogJ3N0cmluZycsXG4gICAgICBkZWZhdWx0OiAzXG4gICAgfSxcbiAgICBwb3N0U29ydDoge1xuICAgICAgdHlwZTogJ3N0cmluZycsXG4gICAgICBkZWZhdWx0OiAncmFuZG9tJ1xuICAgIH1cbiAgfSxcbiAgZWRpdDogZnVuY3Rpb24gZWRpdChwcm9wcykge1xuICAgIHZhciBhdHRyaWJ1dGVzID0gcHJvcHMuYXR0cmlidXRlcyxcbiAgICAgICAgY2xhc3NOYW1lID0gcHJvcHMuY2xhc3NOYW1lLFxuICAgICAgICBpc1NlbGVjdGVkID0gcHJvcHMuaXNTZWxlY3RlZCxcbiAgICAgICAgc2V0QXR0cmlidXRlcyA9IHByb3BzLnNldEF0dHJpYnV0ZXM7XG5cblxuICAgIHZhciBjaGFuZ2VQb3N0TnVtYmVyID0gZnVuY3Rpb24gY2hhbmdlUG9zdE51bWJlcihlKSB7XG4gICAgICBpZiAoZSA8IDI2KSB7XG4gICAgICAgIHByb3BzLnNldEF0dHJpYnV0ZXMoeyBwb3N0TnVtYmVyOiBlIH0pO1xuICAgICAgfVxuICAgIH07XG5cbiAgICB2YXIgcmVwcmVzZW50QmxvY2tzID0gZnVuY3Rpb24gcmVwcmVzZW50QmxvY2tzKCkge1xuICAgICAgdmFyIHRhYmxlID0gW107XG5cbiAgICAgIC8vIE91dGVyIGxvb3AgdG8gY3JlYXRlIHBhcmVudFxuICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBwcm9wcy5hdHRyaWJ1dGVzLnBvc3ROdW1iZXI7IGkrKykge1xuICAgICAgICB2YXIgY2hpbGRyZW4gPSBbXTtcbiAgICAgICAgLy9Jbm5lciBsb29wIHRvIGNyZWF0ZSBjaGlsZHJlblxuICAgICAgICBmb3IgKHZhciBqID0gMDsgaiA8IDU7IGorKykge1xuICAgICAgICAgIGNoaWxkcmVuLnB1c2god3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgICAgJ3RkJyxcbiAgICAgICAgICAgIG51bGwsXG4gICAgICAgICAgICAnQ29sdW1uICcgKyAoaiArIDEpXG4gICAgICAgICAgKSk7XG4gICAgICAgIH1cblxuICAgICAgICAvL0NyZWF0ZSB0aGUgcGFyZW50IGFuZCBhZGQgdGhlIGNoaWxkcmVuXG4gICAgICAgIHRhYmxlLnB1c2god3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgICdkaXYnLFxuICAgICAgICAgIHsgY2xhc3NOYW1lOiAncnB0LXNpbmdsZScgfSxcbiAgICAgICAgICB3cC5lbGVtZW50LmNyZWF0ZUVsZW1lbnQoJ2RpdicsIHsgY2xhc3NOYW1lOiAncnB0LWltZycgfSksXG4gICAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgICAgJ2RpdicsXG4gICAgICAgICAgICB7IGNsYXNzTmFtZTogJ3JwdC10ZXh0JyB9LFxuICAgICAgICAgICAgX18oJ1Bvc3QgVGl0bGUnLCAncmVsYXRlZC1wb3N0LXRodW1ibmFpbHMnKVxuICAgICAgICAgIClcbiAgICAgICAgKSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gdGFibGU7XG4gICAgfTtcblxuICAgIHJldHVybiBbd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgSW5zcGVjdG9yQ29udHJvbHMsXG4gICAgICBudWxsLFxuICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICBQYW5lbEJvZHksXG4gICAgICAgIHsgdGl0bGU6IF9fKCdSZWxhdGVkIFBvc3RzJywgJ3JlbGF0ZWQtcG9zdC10aHVtYm5haWxzJykgfSxcbiAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgIFBhbmVsUm93LFxuICAgICAgICAgIG51bGwsXG4gICAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgICAgJ3N0cm9uZycsXG4gICAgICAgICAgICBudWxsLFxuICAgICAgICAgICAgX18oJ1JlbGF0ZWQgUG9zdHMgQmxvY2sgVGl0bGUnLCAncmVsYXRlZC1wb3N0LXRodW1ibmFpbHMnKVxuICAgICAgICAgICksXG4gICAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFRleHRDb250cm9sLCB7XG4gICAgICAgICAgICB2YWx1ZTogcHJvcHMuYXR0cmlidXRlcy5tYWluVGl0bGUsXG4gICAgICAgICAgICBvbkNoYW5nZTogZnVuY3Rpb24gb25DaGFuZ2UobWFpblRpdGxlKSB7XG4gICAgICAgICAgICAgIHJldHVybiBwcm9wcy5zZXRBdHRyaWJ1dGVzKHsgbWFpblRpdGxlOiBtYWluVGl0bGUgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSlcbiAgICAgICAgKSxcbiAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgIFBhbmVsUm93LFxuICAgICAgICAgIG51bGwsXG4gICAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgICAgJ3N0cm9uZycsXG4gICAgICAgICAgICBudWxsLFxuICAgICAgICAgICAgX18oJ051bWJlciBvZiBQb3N0cycsICdyZWxhdGVkLXBvc3QtdGh1bWJuYWlscycpXG4gICAgICAgICAgKSxcbiAgICAgICAgICB3cC5lbGVtZW50LmNyZWF0ZUVsZW1lbnQoVGV4dENvbnRyb2wsIHtcbiAgICAgICAgICAgIHR5cGU6ICdudW1iZXInLFxuICAgICAgICAgICAgdmFsdWU6IHByb3BzLmF0dHJpYnV0ZXMucG9zdE51bWJlcixcbiAgICAgICAgICAgIG9uQ2hhbmdlOiBjaGFuZ2VQb3N0TnVtYmVyXG4gICAgICAgICAgfSlcbiAgICAgICAgKSxcbiAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgIFBhbmVsUm93LFxuICAgICAgICAgIG51bGwsXG4gICAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFxuICAgICAgICAgICAgJ3N0cm9uZycsXG4gICAgICAgICAgICBudWxsLFxuICAgICAgICAgICAgX18oJ1NvcnQgUG9zdHMgT3JkZXInLCAncmVsYXRlZC1wb3N0LXRodW1ibmFpbHMnKVxuICAgICAgICAgICksXG4gICAgICAgICAgd3AuZWxlbWVudC5jcmVhdGVFbGVtZW50KFNlbGVjdENvbnRyb2wsIHtcbiAgICAgICAgICAgIHZhbHVlOiBwcm9wcy5hdHRyaWJ1dGVzLnBvc3RTb3J0LFxuICAgICAgICAgICAgb3B0aW9uczogW3sgdmFsdWU6IFwicmFuZG9tXCIsIGxhYmVsOiBcIlJhbmRvbVwiIH0sIHsgdmFsdWU6IFwibGF0ZXN0XCIsIGxhYmVsOiBcIkxhdGVzdFwiIH1dLFxuICAgICAgICAgICAgb25DaGFuZ2U6IGZ1bmN0aW9uIG9uQ2hhbmdlKHBvc3RTb3J0KSB7XG4gICAgICAgICAgICAgIHJldHVybiBwcm9wcy5zZXRBdHRyaWJ1dGVzKHsgcG9zdFNvcnQ6IHBvc3RTb3J0IH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pXG4gICAgICAgIClcbiAgICAgIClcbiAgICApLCB3cC5lbGVtZW50LmNyZWF0ZUVsZW1lbnQoXG4gICAgICAncCcsXG4gICAgICB7IGNsYXNzTmFtZTogJ3JwdC1yZXByZXNudGFpb24tbXNnJyB9LFxuICAgICAgX18oJ1RoaXMgaXMgdGhlIHJlcHJlc2VudGFpb24gb2YgUmVsYXRlZCBQb3N0IFRodW1ibmFpbHMnLCAncmVsYXRlZC1wb3N0LXRodW1ibmFpbHMnKVxuICAgICksIHdwLmVsZW1lbnQuY3JlYXRlRWxlbWVudChcbiAgICAgICdkaXYnLFxuICAgICAgbnVsbCxcbiAgICAgIHdwLmVsZW1lbnQuY3JlYXRlRWxlbWVudChcbiAgICAgICAgJ3AnLFxuICAgICAgICBudWxsLFxuICAgICAgICBwcm9wcy5hdHRyaWJ1dGVzLm1haW5UaXRsZVxuICAgICAgKSxcbiAgICAgIHdwLmVsZW1lbnQuY3JlYXRlRWxlbWVudChcbiAgICAgICAgJ2RpdicsXG4gICAgICAgIHsgY2xhc3NOYW1lOiAncnB0LWNvbnRhaW5lcicgfSxcbiAgICAgICAgcmVwcmVzZW50QmxvY2tzKClcbiAgICAgIClcbiAgICApXTtcbiAgfSxcbiAgc2F2ZTogZnVuY3Rpb24gc2F2ZSgpIHtcbiAgICAvLyBSZW5kZXJpbmcgaW4gUEhQXG4gICAgcmV0dXJuIG51bGw7XG4gIH1cbn0pO1xuXG5cbi8vLy8vLy8vLy8vLy8vLy8vL1xuLy8gV0VCUEFDSyBGT09URVJcbi8vIC4vYmxvY2tzL3JlbGF0ZWQtcG9zdHMvaW5kZXguanNcbi8vIG1vZHVsZSBpZCA9IDJcbi8vIG1vZHVsZSBjaHVua3MgPSAwIl0sIm1hcHBpbmdzIjoiQUFBQTtBQUFBO0FBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSIsInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///2\n");
|
85 |
+
|
86 |
+
/***/ }),
|
87 |
+
/* 3 */
|
88 |
+
/***/ (function(module, exports) {
|
89 |
+
|
90 |
+
eval("// removed by extract-text-webpack-plugin//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMy5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy8uL2Jsb2Nrcy9yZWxhdGVkLXBvc3RzL3N0eWxlLnNjc3M/ZGM3OCJdLCJzb3VyY2VzQ29udGVudCI6WyIvLyByZW1vdmVkIGJ5IGV4dHJhY3QtdGV4dC13ZWJwYWNrLXBsdWdpblxuXG5cbi8vLy8vLy8vLy8vLy8vLy8vL1xuLy8gV0VCUEFDSyBGT09URVJcbi8vIC4vYmxvY2tzL3JlbGF0ZWQtcG9zdHMvc3R5bGUuc2Nzc1xuLy8gbW9kdWxlIGlkID0gM1xuLy8gbW9kdWxlIGNodW5rcyA9IDAiXSwibWFwcGluZ3MiOiJBQUFBIiwic291cmNlUm9vdCI6IiJ9\n//# sourceURL=webpack-internal:///3\n");
|
91 |
+
|
92 |
+
/***/ })
|
93 |
+
/******/ ]);
|
assets/blocks/js/frontend.blocks.js
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
/******/ });
|
inc/rpt-blocks.php
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Enqueue block editor only JavaScript and CSS.
|
4 |
+
*
|
5 |
+
*/
|
6 |
+
function enqueue_block_editor_assets() {
|
7 |
+
$block_path = 'assets/blocks/js/editor.blocks.js';
|
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, ['wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-editor'], RELATED_POSTS_THUMBNAILS_VERSION );
|
12 |
+
|
13 |
+
// Enqueue optional editor only styles
|
14 |
+
wp_enqueue_style( 'rpt-blocks-editor-css', RELATED_POSTS_THUMBNAILS_URI.$style_path, [], RELATED_POSTS_THUMBNAILS_VERSION );
|
15 |
+
}
|
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, [], RELATED_POSTS_THUMBNAILS_VERSION );
|
43 |
+
}
|
44 |
+
|
45 |
+
add_action('enqueue_block_assets', 'enqueue_frontend_assets');
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Create related posts block category.
|
49 |
+
*
|
50 |
+
*/
|
51 |
+
function rpt_block_category( $categories ) {
|
52 |
+
return array_merge(
|
53 |
+
$categories,
|
54 |
+
array(
|
55 |
+
array(
|
56 |
+
'slug' => 'related-post-thumbnails-blocks',
|
57 |
+
'title' => __( 'Related Posts Thumbnails', 'related-post-thumbnails' ),
|
58 |
+
),
|
59 |
+
)
|
60 |
+
);
|
61 |
+
}
|
62 |
+
|
63 |
+
add_filter( 'block_categories', 'rpt_block_category', 10, 2);
|
64 |
+
|
65 |
+
/* * * * * * * * * *
|
66 |
+
* Dynamic Block
|
67 |
+
* * * * * * * * * */
|
68 |
+
|
69 |
+
add_action('plugins_loaded', 'register_rpt_dynamic_block');
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Register the dynamic block.
|
73 |
+
*
|
74 |
+
* @since 2.0.0
|
75 |
+
*
|
76 |
+
* @return void
|
77 |
+
*/
|
78 |
+
function register_rpt_dynamic_block() {
|
79 |
+
// Only load if Gutenberg is available.
|
80 |
+
if (!function_exists('register_block_type')) {
|
81 |
+
return;
|
82 |
+
}
|
83 |
+
|
84 |
+
// Hook server side rendering into render callback
|
85 |
+
register_block_type('related-post-thumbnails/rpt-block', [
|
86 |
+
'render_callback' => 'render_rpt_dynamic_block'
|
87 |
+
]);
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Server rendering
|
92 |
+
*/
|
93 |
+
function render_rpt_dynamic_block($atts) {
|
94 |
+
$posts_number = 3;
|
95 |
+
$posts_sort = 'random';
|
96 |
+
$main_title = '';
|
97 |
+
|
98 |
+
if ( ! empty( $atts ) ) {
|
99 |
+
$posts_number = isset($atts['postNumber']) ? $atts['postNumber'] : $posts_number;
|
100 |
+
$posts_sort = isset($atts['postSort']) ? $atts['postSort'] : $posts_sort;
|
101 |
+
$main_title = isset($atts['mainTitle']) ? str_replace( ' ', '_', $atts['mainTitle'] ) : $main_title;
|
102 |
+
}
|
103 |
+
|
104 |
+
return do_shortcode( '[related-posts-thumbnails posts_number=' . $posts_number . ' posts_sort=' . $posts_sort . ' main_title=' . $main_title . ']' );
|
105 |
+
}
|
106 |
+
|
107 |
+
?>
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ 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.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -20,6 +20,9 @@ Thumbnails are arranged in columns under the post with related posts title/excer
|
|
20 |
|
21 |
You can specify number of related posts to display, start date, categories to show on and to include, top text, style settings, default image URL. You can select type of relation - categories, tags, categories and tags, random or custom taxonomies. You can specify where to display related posts - choose page type (main or single), post type and select categories. You can turn off automatic appending to the end of post and use **<?php get_related_posts_thumbnails(); ?>** php tag in the Loop of your theme. Related Posts thumbnails sidebar widget is also available. You can use [related-posts-thumbnails] shortcode in the post body.
|
22 |
|
|
|
|
|
|
|
23 |
Contributions:
|
24 |
|
25 |
* Thanks to <a href="http://adnan.pk/?utm_source=related-posts-lite&utm_medium=readme&utm_campaign=xp">Adnan</a> for giving life to this plugin.
|
@@ -62,16 +65,23 @@ If there are no images of the specified size in the post, or file does not exist
|
|
62 |
|
63 |
== Screenshots ==
|
64 |
|
|
|
65 |
1. Plugin in action
|
66 |
1. Plugin settings page
|
67 |
|
68 |
== Upgrade Notice ==
|
69 |
|
70 |
-
= 1.
|
71 |
-
* Please upgrade immediately -
|
72 |
|
73 |
== Changelog ==
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
= 1.6.6 - 2019-03-18 =
|
76 |
* Enhancement : Add `posts_number` & `posts_sort` attributes in [related-posts-thumbnails] shortcode.
|
77 |
* Compatibility : Compatible with WordPress 5.1
|
@@ -206,4 +216,4 @@ If there are no images of the specified size in the post, or file does not exist
|
|
206 |
* added post custom field name option as a source for thumbnails
|
207 |
|
208 |
= 1.0 =
|
209 |
-
* Released plugin initial version
|
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.7.0
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
20 |
|
21 |
You can specify number of related posts to display, start date, categories to show on and to include, top text, style settings, default image URL. You can select type of relation - categories, tags, categories and tags, random or custom taxonomies. You can specify where to display related posts - choose page type (main or single), post type and select categories. You can turn off automatic appending to the end of post and use **<?php get_related_posts_thumbnails(); ?>** php tag in the Loop of your theme. Related Posts thumbnails sidebar widget is also available. You can use [related-posts-thumbnails] shortcode in the post body.
|
22 |
|
23 |
+
** This Related Posts plugin has Gutenberg block **
|
24 |
+
|
25 |
+
|
26 |
Contributions:
|
27 |
|
28 |
* Thanks to <a href="http://adnan.pk/?utm_source=related-posts-lite&utm_medium=readme&utm_campaign=xp">Adnan</a> for giving life to this plugin.
|
65 |
|
66 |
== Screenshots ==
|
67 |
|
68 |
+
1. Related Posts Gutenberg Block
|
69 |
1. Plugin in action
|
70 |
1. Plugin settings page
|
71 |
|
72 |
== Upgrade Notice ==
|
73 |
|
74 |
+
= 1.7.0 =
|
75 |
+
* Please upgrade immediately - Introducing Gutenberg block for Related posts.
|
76 |
|
77 |
== Changelog ==
|
78 |
|
79 |
+
= 1.7.0 - 2019-05-24 =
|
80 |
+
* New Feature : Added Gutenberg block for Related posts.
|
81 |
+
* Bug Fix : Empty container class name.
|
82 |
+
* Bug Fix : Unable to show related posts on empty custom field.
|
83 |
+
* Compatibility : Compatible with WordPress 5.2
|
84 |
+
|
85 |
= 1.6.6 - 2019-03-18 =
|
86 |
* Enhancement : Add `posts_number` & `posts_sort` attributes in [related-posts-thumbnails] shortcode.
|
87 |
* Compatibility : Compatible with WordPress 5.1
|
216 |
* added post custom field name option as a source for thumbnails
|
217 |
|
218 |
= 1.0 =
|
219 |
+
* Released plugin initial version
|
related-posts-thumbnails.php
CHANGED
@@ -3,13 +3,13 @@
|
|
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 |
*/
|
10 |
|
11 |
/*
|
12 |
-
Copyright 2010
|
13 |
|
14 |
This product was first developed by Maria I Shaldybina and later on maintained and developed by Adnan (WPBrigade.com)
|
15 |
|
@@ -24,961 +24,927 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
24 |
GNU General Public License for more details.
|
25 |
*/
|
26 |
class RelatedPostsThumbnails {
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
$this,
|
76 |
-
'auto_show'
|
77 |
-
), $priority );
|
78 |
-
}
|
79 |
-
|
80 |
-
add_action( 'admin_menu', array(
|
81 |
-
$this,
|
82 |
-
'admin_menu'
|
83 |
-
) );
|
84 |
-
|
85 |
-
$this->wp_version = get_bloginfo( 'version' );
|
86 |
-
|
87 |
-
add_action( 'admin_footer', array(
|
88 |
-
$this,
|
89 |
-
'add_deactive_modal'
|
90 |
-
) );
|
91 |
-
add_action( 'wp_ajax_rpt_deactivate', array(
|
92 |
-
$this,
|
93 |
-
'rpt_deactivate'
|
94 |
-
) );
|
95 |
-
|
96 |
-
add_action( 'admin_init', array(
|
97 |
-
$this,
|
98 |
-
'review_notice'
|
99 |
-
) );
|
100 |
-
add_action( 'wp_enqueue_scripts', array(
|
101 |
-
$this,
|
102 |
-
'front_scripts'
|
103 |
-
) );
|
104 |
-
|
105 |
-
add_action( 'wp_head', array(
|
106 |
-
$this,
|
107 |
-
'head_style'
|
108 |
-
) );
|
109 |
-
|
110 |
-
add_shortcode( 'related-posts-thumbnails', array( $this, 'related_posts_shortcode' ) );
|
111 |
}
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
}
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
wp_enqueue_media();
|
139 |
-
wp_enqueue_style( 'rpt_admin_css', plugins_url( 'assets/css/admin.css', __FILE__ ), false, RELATED_POSTS_THUMBNAILS_VERSION );
|
140 |
-
wp_enqueue_style( 'jquery-ui', 'http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css' );
|
141 |
-
wp_enqueue_style( 'wp-color-picker' );
|
142 |
-
wp_enqueue_script( 'rpt_admin_js', plugins_url( 'assets/js/admin.js', __FILE__ ), array(
|
143 |
-
'jquery',
|
144 |
-
'wp-color-picker',
|
145 |
-
'jquery-ui-datepicker'
|
146 |
-
), RELATED_POSTS_THUMBNAILS_VERSION );
|
147 |
-
}
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
}
|
150 |
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
-
|
|
|
|
|
|
|
|
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
}
|
156 |
|
157 |
-
|
|
|
|
|
158 |
|
159 |
-
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
162 |
|
|
|
163 |
}
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
*
|
168 |
-
* @since 1.6.2
|
169 |
-
*/
|
170 |
-
function add_deactive_modal() {
|
171 |
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
-
|
175 |
-
|
|
|
176 |
}
|
|
|
|
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
/**
|
184 |
-
* Send the user responce to api.
|
185 |
-
*
|
186 |
-
* @since 1.6.2
|
187 |
-
*/
|
188 |
-
function rpt_deactivate() {
|
189 |
-
|
190 |
-
$email = get_option( 'admin_email' );
|
191 |
-
$_reason = sanitize_text_field( wp_unslash( $_POST[ 'reason' ] ) );
|
192 |
-
$reason_detail = sanitize_text_field( wp_unslash( $_POST[ 'reason_detail' ] ) );
|
193 |
-
$reason = '';
|
194 |
-
|
195 |
-
if ( $_reason == '1' ) {
|
196 |
-
$reason = 'I only needed the plugin for a short period';
|
197 |
-
} elseif ( $_reason == '2' ) {
|
198 |
-
$reason = 'I found a better plugin';
|
199 |
-
} elseif ( $_reason == '3' ) {
|
200 |
-
$reason = 'The plugin broke my site';
|
201 |
-
} elseif ( $_reason == '4' ) {
|
202 |
-
$reason = 'The plugin suddenly stopped working';
|
203 |
-
} elseif ( $_reason == '5' ) {
|
204 |
-
$reason = 'I no longer need the plugin';
|
205 |
-
} elseif ( $_reason == '6' ) {
|
206 |
-
$reason = 'It\'s a temporary deactivation. I\'m just debugging an issue.';
|
207 |
-
} elseif ( $_reason == '7' ) {
|
208 |
-
$reason = 'Other';
|
209 |
-
}
|
210 |
-
$fields = array(
|
211 |
-
'email' => $email,
|
212 |
-
'website' => get_site_url(),
|
213 |
-
'action' => 'Deactivate',
|
214 |
-
'reason' => $reason,
|
215 |
-
'reason_detail' => $reason_detail,
|
216 |
-
'blog_language' => get_bloginfo( 'language' ),
|
217 |
-
'wordpress_version' => get_bloginfo( 'version' ),
|
218 |
-
'php_version' => PHP_VERSION,
|
219 |
-
'plugin_version' => RELATED_POSTS_THUMBNAILS_VERSION,
|
220 |
-
'plugin_name' => 'Related Post Thumbnails'
|
221 |
-
);
|
222 |
-
|
223 |
-
$response = wp_remote_post( RELATED_POSTS_THUMBNAILS_FEEDBACK_SERVER, array(
|
224 |
-
'method' => 'POST',
|
225 |
-
'timeout' => 5,
|
226 |
-
'httpversion' => '1.0',
|
227 |
-
'blocking' => false,
|
228 |
-
'headers' => array(),
|
229 |
-
'body' => $fields
|
230 |
-
) );
|
231 |
-
|
232 |
-
wp_die();
|
233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
235 |
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
}
|
250 |
|
251 |
-
$
|
252 |
-
|
253 |
-
$
|
254 |
-
|
255 |
-
|
|
|
|
|
256 |
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
}
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
*/
|
272 |
-
public function review_notice_message() {
|
273 |
-
|
274 |
-
$scheme = ( parse_url( $_SERVER[ 'REQUEST_URI' ], PHP_URL_QUERY ) ) ? '&' : '?';
|
275 |
-
$url = $_SERVER[ 'REQUEST_URI' ] . $scheme . 'rpt_review_dismiss=yes';
|
276 |
-
$dismiss_url = wp_nonce_url( $url, 'rpt-review-nonce' );
|
277 |
-
|
278 |
-
$_later_link = $_SERVER[ 'REQUEST_URI' ] . $scheme . 'ssb_review_later=yes';
|
279 |
-
$later_url = wp_nonce_url( $_later_link, 'rpt-review-nonce' );
|
280 |
-
|
281 |
-
?>
|
282 |
-
<style media="screen">
|
283 |
-
.rpt-review-notice { padding: 15px 0; background-color: #fff; border-radius: 3px; margin: 20px 20px 0 0; border-left: 4px solid transparent; } .rpt-review-notice:after { content: ''; display: table; clear: both; }
|
284 |
-
.rpt-review-thumbnail { float: left; line-height: 80px; text-align: center; width: 117px; }
|
285 |
-
.rpt-review-thumbnail img { width: 118px; vertical-align: middle; }
|
286 |
-
.rpt-review-text { overflow: hidden; }
|
287 |
-
.rpt-review-text h3 { font-size: 24px; margin: 0 0 5px; font-weight: 400; line-height: 1.3; }
|
288 |
-
.rpt-review-text p { font-size: 13px; margin: 0 0 5px; }
|
289 |
-
.rpt-review-ul { margin: 0; padding: 0; }
|
290 |
-
.rpt-review-ul li { display: inline-block; margin-right: 15px; }
|
291 |
-
.rpt-review-ul li a { display: inline-block; color: #10738B; text-decoration: none; padding-left: 26px; position: relative; }
|
292 |
-
.rpt-review-ul li a span { position: absolute; left: 0; top: -2px; }
|
293 |
-
</style>
|
294 |
-
<div class="rpt-review-notice">
|
295 |
-
<div class="rpt-review-thumbnail">
|
296 |
-
<img src="<?php
|
297 |
-
echo plugins_url( 'assets/images/rpt-logo.png', __FILE__ );
|
298 |
-
?>" alt="">
|
299 |
-
</div>
|
300 |
-
<div class="rpt-review-text">
|
301 |
-
<h3><?php
|
302 |
-
_e( 'Leave A Review?', 'related-posts-thumbnails' );
|
303 |
-
?></h3>
|
304 |
-
<p><?php
|
305 |
-
_e( 'We hope you\'ve enjoyed using Related Post Thumbnails! Would you consider leaving us a review on WordPress.org?', 'related-posts-thumbnails' );
|
306 |
-
?></p>
|
307 |
-
<ul class="rpt-review-ul">
|
308 |
-
<li>
|
309 |
-
<a href="https://wordpress.org/support/plugin/related-posts-thumbnails/reviews/?filter=5" target="_blank"><span class="dashicons dashicons-external"></span>
|
310 |
-
<?php _e( 'Sure! I\'d love to!', 'related-posts-thumbnails' ); ?>
|
311 |
-
</a>
|
312 |
-
</li>
|
313 |
-
<li>
|
314 |
-
<a href="<?php echo $dismiss_url; ?>">
|
315 |
-
<span class="dashicons dashicons-smiley"></span>
|
316 |
-
<?php _e( 'I\'ve already left a review', 'related-posts-thumbnails' ); ?>
|
317 |
-
</a>
|
318 |
-
</li>
|
319 |
-
<li>
|
320 |
-
<a href="<?php echo $later_url; ?>">
|
321 |
-
<span class="dashicons dashicons-calendar-alt"></span>
|
322 |
-
<?php _e( 'Maybe Later', 'related-posts-thumbnails' ); ?>
|
323 |
-
</a>
|
324 |
-
</li>
|
325 |
-
<li>
|
326 |
-
<a href="<?php echo $dismiss_url; ?>">
|
327 |
-
<span class="dashicons dashicons-dismiss"></span>
|
328 |
-
<?php _e( 'Never show again', 'related-posts-thumbnails' ); ?>
|
329 |
-
</a>
|
330 |
-
</li>
|
331 |
-
</ul>
|
332 |
-
</div>
|
333 |
-
</div>
|
334 |
-
|
335 |
-
<?php }
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Set time to current so review notice will popup after 15 days
|
339 |
-
*
|
340 |
-
* @since 1.8.2
|
341 |
-
*/
|
342 |
-
function review_prending() {
|
343 |
-
|
344 |
-
// delete_site_option( 'rpt_review_dismiss' );
|
345 |
-
if ( !is_admin() || !current_user_can( 'manage_options' ) || !isset( $_GET[ '_wpnonce' ] ) || !wp_verify_nonce( sanitize_key( wp_unslash( $_GET[ '_wpnonce' ] ) ), 'rpt-review-nonce' ) || !isset( $_GET[ 'ssb_review_later' ] ) ) {
|
346 |
-
|
347 |
-
return;
|
348 |
}
|
349 |
-
|
350 |
-
// Reset Time to current time.
|
351 |
-
update_option( 'rpt_active_time', time() );
|
352 |
-
|
353 |
}
|
354 |
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
|
368 |
-
|
|
|
|
|
369 |
|
|
|
|
|
|
|
|
|
370 |
}
|
371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
|
381 |
-
|
382 |
-
|
383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
}
|
385 |
}
|
386 |
-
|
387 |
}
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
}
|
|
|
395 |
|
396 |
-
|
|
|
|
|
|
|
|
|
|
|
397 |
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
}
|
402 |
-
return '';
|
403 |
|
404 |
-
}
|
405 |
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
$
|
410 |
-
|
411 |
-
$time = microtime( true );
|
412 |
-
$posts_number_opt = get_option( 'relpoststh_number', $this->number );
|
413 |
-
$posts_number = !empty( $posts_number_short ) ? $posts_number_short : $posts_number_opt;
|
414 |
-
$height = '';
|
415 |
-
$width = '';
|
416 |
-
// $date = '';
|
417 |
-
|
418 |
-
$sort_by_opt = get_option( 'rpt_post_sort') == 'latest' ? 'post_date': 'rand()';
|
419 |
-
$sort_by = !empty( $sort_by_short ) ? $sort_by_short : $sort_by_opt;
|
420 |
-
|
421 |
-
// rpt_content_align: add content allignment class; clases are: relpost-align-left, relpost-align-right and relpost-align-center
|
422 |
-
$output = '<!-- relpost-thumb-wrapper -->';
|
423 |
-
$output .= '<div class="relpost-thumb-wrapper">';
|
424 |
-
$output .= '<!-- filter-class -->';
|
425 |
-
$output .='<div class="'. apply_filters( 'rpt_content_align', '' ) . '">';
|
426 |
-
$alt = '';
|
427 |
-
|
428 |
-
if ( $posts_number <= 0 ) { // return nothing if this parameter was set to <= 0
|
429 |
-
$output = '';
|
430 |
-
return $this->finish_process( $output, $debug . 'Posts number is 0;', $time );
|
431 |
}
|
|
|
|
|
432 |
|
433 |
-
$
|
434 |
-
$relation = get_option( 'relpoststh_relation', $this->relation );
|
435 |
-
$poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
|
436 |
-
$text_length = get_option( 'relpoststh_textlength', $this->text_length );
|
437 |
-
$excerpt_length = get_option( 'relpoststh_excerptlength', $this->excerpt_length );
|
438 |
-
$thsource = get_option( 'relpoststh_thsource', $this->thsource );
|
439 |
-
$categories_show_all = get_option( 'relpoststh_show_categoriesall', get_option( 'relpoststh_categoriesall', $this->categories_all ) );
|
440 |
-
$onlywiththumbs = ( current_theme_supports( 'post-thumbnails' ) && $thsource == 'post-thumbnails' ) ? get_option( 'relpoststh_onlywiththumbs', false ) : false;
|
441 |
-
$post_type = get_post_type();
|
442 |
|
443 |
-
|
|
|
444 |
|
445 |
-
|
446 |
-
$debug .= "Relation: $relation; All categories: $categories_show_all;";
|
447 |
-
$use_filter = ( $categories_show_all != '1' || $relation != 'no' );
|
448 |
|
449 |
-
|
450 |
-
|
|
|
451 |
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
} else {
|
465 |
-
$
|
466 |
-
'category',
|
467 |
-
'post_tag'
|
468 |
-
);
|
469 |
-
}
|
470 |
-
$object_terms = wp_get_object_terms( $id, $taxonomy, array(
|
471 |
-
'fields' => 'ids'
|
472 |
-
) );
|
473 |
-
if ( empty( $object_terms ) || !is_array( $object_terms ) ) { // no terms to get taxonomy
|
474 |
-
$output = '';
|
475 |
-
return $this->finish_process( $output, $debug . __( 'No taxonomy terms to get posts;' ), $time );
|
476 |
-
}
|
477 |
-
|
478 |
-
$query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('" . implode( "', '", $object_terms ) . "')";
|
479 |
-
$object_taxonomy = $wpdb->get_results( $query );
|
480 |
-
$object_taxonomy_a = array();
|
481 |
-
if ( count( $object_taxonomy ) > 0 ) {
|
482 |
-
foreach ( $object_taxonomy as $item ) {
|
483 |
-
$object_taxonomy_a[] = $item->term_taxonomy_id;
|
484 |
-
}
|
485 |
}
|
486 |
-
$query_objects .= " AND term_taxonomy_id IN ('" . implode( "', '", $object_taxonomy_a ) . "') ";
|
487 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
|
489 |
-
if ( $categories_show_all != '1' ) {
|
490 |
-
/* Get filter terms */
|
491 |
-
$select_terms = get_option( 'relpoststh_show_categories', get_option( 'relpoststh_categories' ) );
|
492 |
-
if ( empty( $select_terms ) || !is_array( $select_terms ) ) { // if no categories were specified intentionally return nothing
|
493 |
-
$output = '';
|
494 |
-
return $this->finish_process( $output, $debug . __( 'No categories were selected;' ), $time );
|
495 |
-
}
|
496 |
-
|
497 |
-
$query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('" . implode( "', '", $select_terms ) . "')";
|
498 |
-
$taxonomy = $wpdb->get_results( $query );
|
499 |
-
$filter_taxonomy_a = array();
|
500 |
-
if ( count( $taxonomy ) > 0 ) {
|
501 |
-
foreach ( $taxonomy as $item ) {
|
502 |
-
$filter_taxonomy_a[] = $item->term_taxonomy_id;
|
503 |
}
|
504 |
-
}
|
505 |
-
if ( $relation != 'no' ) {
|
506 |
-
$query_objects .= " AND object_id IN (SELECT distinct object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ('" . implode( "', '", $filter_taxonomy_a ) . "') )";
|
507 |
} else {
|
508 |
-
$
|
509 |
}
|
510 |
-
}
|
511 |
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
}
|
518 |
}
|
|
|
519 |
}
|
520 |
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
// }
|
525 |
-
// $checked_post_type = rtrim( $selected_post_type, ',' );
|
526 |
-
|
527 |
-
$query = "SELECT distinct ID FROM $wpdb->posts ";
|
528 |
-
$where = " WHERE post_type = '" . $post_type . "' AND post_status = 'publish' AND ID<>" . $id; // not the current post
|
529 |
-
// $where = " WHERE post_type IN (" . $checked_post_type . ") AND post_status = 'publish' AND ID<>" . $id; // not the current post
|
530 |
-
$startdate = get_option( 'relpoststh_startdate' );
|
531 |
-
if ( !empty( $startdate ) && preg_match( '/^\d\d\d\d-\d\d-\d\d$/', $startdate ) ) { // If startdate was set
|
532 |
-
$debug .= "Startdate: $startdate;";
|
533 |
-
$where .= " AND post_date >= '" . $startdate . "'";
|
534 |
-
}
|
535 |
-
if ( $use_filter ) {
|
536 |
-
$where .= " AND ID IN ('" . implode( "', '", $related_objects ) . "')";
|
537 |
-
}
|
538 |
-
$join = '';
|
539 |
-
if ( $onlywiththumbs ) {
|
540 |
-
$debug .= 'Only with thumbnails;';
|
541 |
-
$join = " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)";
|
542 |
-
$where .= " AND $wpdb->postmeta.meta_key = '_thumbnail_id'";
|
543 |
}
|
544 |
|
545 |
-
$
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
if ( !is_array( $random_posts ) || count( $random_posts ) < 1 ) {
|
550 |
-
$output = '';
|
551 |
-
return $this->finish_process( $output, $debug . __( 'No posts matching relationships criteria;' ), $time );
|
552 |
}
|
553 |
|
554 |
-
$
|
555 |
-
|
556 |
-
|
557 |
-
}
|
558 |
-
$query = "SELECT ID, post_content, post_excerpt, post_title FROM $wpdb->posts WHERE ID IN ('" . implode( "', '", $posts_in ) . "')";
|
559 |
-
$posts = $wpdb->get_results( $query );
|
560 |
|
561 |
-
if ( !(
|
562 |
-
|
563 |
-
|
564 |
-
return $this->finish_process( $output, $debug, $time );
|
565 |
-
} else {
|
566 |
-
$debug .= 'Found ' . count( $posts ) . ' posts;';
|
567 |
}
|
568 |
|
569 |
-
|
570 |
-
|
571 |
-
$debug .= 'Custom sizes;';
|
572 |
-
$width = get_option( 'relpoststh_customwidth', $this->custom_width );
|
573 |
-
$height = get_option( 'relpoststh_customheight', $this->custom_height );
|
574 |
-
} else { // post-thumbnails source
|
575 |
-
if ( $poststhname == 'thumbnail' || $poststhname == 'medium' || $poststhname == 'large' ) { // get thumbnail size for basic sizes
|
576 |
-
$debug .= 'Basic sizes;';
|
577 |
-
$width = get_option( "{$poststhname}_size_w" );
|
578 |
-
$height = get_option( "{$poststhname}_size_h" );
|
579 |
-
} elseif ( current_theme_supports( 'post-thumbnails' ) ) { // get sizes for theme supported thumbnails
|
580 |
-
global $_wp_additional_image_sizes;
|
581 |
-
if ( isset( $_wp_additional_image_sizes[ $poststhname ] ) ) {
|
582 |
-
$debug .= 'Additional sizes;';
|
583 |
-
$width = $_wp_additional_image_sizes[ $poststhname ][ 'width' ];
|
584 |
-
$height = $_wp_additional_image_sizes[ $poststhname ][ 'height' ];
|
585 |
-
} else {
|
586 |
-
$debug .= 'No additional sizes;';
|
587 |
-
}
|
588 |
-
}
|
589 |
}
|
590 |
-
// displaying square if one size is not cropping
|
591 |
-
if ( $height == 9999 ) {
|
592 |
-
$height = $width;
|
593 |
-
}
|
594 |
-
if ( $width == 9999 ) {
|
595 |
-
$width = $height;
|
596 |
-
}
|
597 |
-
// theme is not supporting but settings were not changed
|
598 |
-
if ( empty( $width ) ) {
|
599 |
-
$debug .= 'Using default width;';
|
600 |
-
$width = get_option( 'thumbnail_size_w' );
|
601 |
-
}
|
602 |
-
if ( empty( $height ) ) {
|
603 |
-
$debug .= 'Using default height;';
|
604 |
-
$height = get_option( 'thumbnail_size_h' );
|
605 |
-
}
|
606 |
-
$debug .= 'Got sizes ' . $width . 'x' . $height . ';';
|
607 |
-
// rendering related posts HTML
|
608 |
-
if ( $show_top ) {
|
609 |
-
$output .= stripslashes( get_option( 'relpoststh_top_text', $this->top_text ) );
|
610 |
-
}
|
611 |
-
$relpoststh_output_style = get_option( 'relpoststh_output_style', $this->output_style );
|
612 |
-
$relpoststh_cleanhtml = get_option( 'relpoststh_cleanhtml', 0 );
|
613 |
-
$text_height = get_option( 'relpoststh_textblockheight', $this->text_block_height );
|
614 |
|
|
|
|
|
|
|
|
|
615 |
|
616 |
if ( $relpoststh_output_style == 'list' ) {
|
617 |
-
$
|
618 |
-
$output .= '<
|
619 |
-
if (
|
620 |
-
$output .= '
|
621 |
}
|
622 |
$output .= '>';
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
// $output .= '<!-- related-posts-nav -->';
|
628 |
-
// $output .= '<ul class="related-posts-nav">'; //open blocks ul
|
629 |
-
|
630 |
-
$output .= '<div style="clear: both"></div>';
|
631 |
-
|
632 |
-
$output .= '<!-- relpost-block-container -->';
|
633 |
-
$output .= '<div class="relpost-block-container">'; // open relpost-block-container div
|
634 |
-
}
|
635 |
-
|
636 |
-
foreach ( $posts as $post ) {
|
637 |
-
$image = '';
|
638 |
-
$url = '';
|
639 |
-
$alt = '';
|
640 |
-
if ( $thsource == 'custom-field' ) {
|
641 |
-
$debug .= 'Using custom field;';
|
642 |
-
$url = $basic_url = get_post_meta( $post->ID, get_option( 'relpoststh_customfield', $this->custom_field ), true );
|
643 |
-
if ( strpos( $url, '/wp-content' ) !== false ) {
|
644 |
-
$url = substr( $url, strpos( $url, '/wp-content' ) );
|
645 |
-
}
|
646 |
-
$theme_resize_url = get_option( 'relpoststh_theme_resize_url', '' );
|
647 |
-
if ( !empty( $theme_resize_url ) ) {
|
648 |
-
$url = $theme_resize_url . '?src=' . $url . '&w=' . $width . '&h=' . $height . '&zc=1&q=90';
|
649 |
-
}
|
650 |
-
} else {
|
651 |
-
$from_post_body = true;
|
652 |
-
if ( current_theme_supports( 'post-thumbnails' ) ) { // using built in Wordpress feature
|
653 |
-
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
|
654 |
-
$debug .= 'Post-thumbnails enabled in theme;';
|
655 |
-
if ( !( empty( $post_thumbnail_id ) || $post_thumbnail_id === false ) ) { // post has thumbnail
|
656 |
-
$debug .= 'Post has thumbnail ' . $post_thumbnail_id . ';';
|
657 |
-
$debug .= 'Postthname: ' . $poststhname . ';';
|
658 |
-
$image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
|
659 |
-
$alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
|
660 |
-
$url = $image[ 0 ];
|
661 |
-
$from_post_body = false;
|
662 |
-
} else {
|
663 |
-
$debug .= 'Post has no thumbnail;';
|
664 |
-
}
|
665 |
-
}
|
666 |
-
if ( $from_post_body ) { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
|
667 |
-
$debug .= 'Getting image from post body;';
|
668 |
-
$wud = wp_upload_dir();
|
669 |
-
preg_match_all( '|<img.*?src=[\'"](' . $wud[ 'baseurl' ] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // searching for the first uploaded image in text
|
670 |
-
|
671 |
-
if ( isset( $matches ) && isset( $matches[ 1 ][ 0 ] ) ) {
|
672 |
-
$image = $matches[ 1 ][ 0 ];
|
673 |
-
$html = $matches[ 0 ][ 0 ];
|
674 |
-
if ( !empty( $html ) ) {
|
675 |
-
preg_match( '/alt="([^"]*)"/i', $html, $array );
|
676 |
-
|
677 |
-
if ( !empty( $array ) && is_array( $array ) ) {
|
678 |
-
$explode_tag = explode( '"', $array[ 0 ] );
|
679 |
-
$alt = $explode_tag[ 1 ];
|
680 |
-
}
|
681 |
-
|
682 |
-
}
|
683 |
-
} else {
|
684 |
-
$debug .= 'No image was found;';
|
685 |
-
}
|
686 |
-
|
687 |
-
if ( strlen( trim( $image ) ) > 0 ) {
|
688 |
-
$image_sizes = @getimagesize( $image );
|
689 |
-
if ( $image_sizes === false ) {
|
690 |
-
$debug .= 'Unable to determine parsed image size';
|
691 |
-
}
|
692 |
-
if ( $image_sizes !== false && isset( $image_sizes[ 0 ] ) && $image_sizes[ 0 ] == $width ) { // if this image is the same size as we need
|
693 |
-
$debug .= 'Image used is the required size;';
|
694 |
-
$url = $image;
|
695 |
-
} else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
|
696 |
-
$debug .= 'Changing image according to Wordpress standards;';
|
697 |
-
$url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
|
698 |
-
}
|
699 |
-
} else {
|
700 |
-
$debug .= 'Found wrong formatted image: ' . $image . ';';
|
701 |
-
}
|
702 |
-
}
|
703 |
-
$basic_url = $url;
|
704 |
-
}
|
705 |
-
|
706 |
-
if ( strpos( $url, '/' ) === 0 ) {
|
707 |
-
$debug .= 'Relative url: ' . $url . ';';
|
708 |
-
$url = $basic_url = get_bloginfo( 'url' ) . $url;
|
709 |
-
}
|
710 |
-
|
711 |
-
$debug .= 'Image URL: ' . $url . ';';
|
712 |
-
if ( empty( $basic_url ) ) { // parsed URL is empty or no file if can check
|
713 |
-
$debug .= 'Image is empty or no file. Using default image;';
|
714 |
-
$url = get_option( 'relpoststh_default_image', $this->default_image );
|
715 |
-
}
|
716 |
-
|
717 |
-
$title = $this->process_text_cut( $post->post_title, $text_length );
|
718 |
-
$post_excerpt = ( empty( $post->post_excerpt ) ) ? $post->post_content : $post->post_excerpt;
|
719 |
-
$excerpt = $this->process_text_cut( $post_excerpt, $excerpt_length );
|
720 |
-
|
721 |
-
if ( !empty( $title ) && !empty( $excerpt ) ) {
|
722 |
-
$title = '<b>' . $title . '</b>';
|
723 |
-
$excerpt = '<br/>' . $excerpt;
|
724 |
-
}
|
725 |
-
|
726 |
-
if ( empty( $alt ) ) {
|
727 |
-
$alt = str_replace('"', '', $title);
|
728 |
}
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
// $debug .= 'Using date under posts;';
|
733 |
-
// }
|
734 |
-
|
735 |
-
$fontface = str_replace( '"', "'", stripslashes( get_option( 'relpoststh_fontfamily', $this->font_family ) ) );
|
736 |
-
|
737 |
-
$debug .= 'Using title with size ' . $text_length . '. Using excerpt with size ' . $excerpt_length . ';';
|
738 |
-
$after_content = apply_filters( 'rpth_after_content', '', $post );
|
739 |
-
|
740 |
-
if ( $relpoststh_output_style == 'list' ) {
|
741 |
-
$link = get_permalink( $post->ID );
|
742 |
-
$output .= '<li ';
|
743 |
-
if ( !$relpoststh_cleanhtml ) {
|
744 |
-
// $output .= ' onmouseout="this.style.backgroundColor=\'' . get_option( 'relpoststh_background', $this->background ) . '\'"';
|
745 |
-
}
|
746 |
-
$output .= '>';
|
747 |
-
$output .= '<a href="' . $link . '" ><img class="relpost-post-image" alt="' . $alt . '" src="' . esc_url( $url ) . '" width="' . $width . '" height="' . $height . '" ';
|
748 |
if ( !$relpoststh_cleanhtml ) {
|
749 |
-
|
750 |
}
|
751 |
-
$output .= '
|
752 |
-
|
753 |
-
$output .= '<a href="' . $link . '" class="relpost_content"';
|
754 |
-
if ( !$relpoststh_cleanhtml ) {
|
755 |
-
$output .= ' style="width: ' . $width . 'px;height: ' . $text_height . 'px; font-family: ' . $fontface . '; "';
|
756 |
-
}
|
757 |
-
// $output .= '><span class="rpth_list_content">' . $title . $excerpt . '</span>' . $date . '</a></li>';
|
758 |
-
$output .= '><span class="rpth_list_content">' . $title . $excerpt . '</span>' . $after_content . '</a></li>';
|
759 |
-
}
|
760 |
-
} else {
|
761 |
-
$output .= '<a class="relpost-block-single" href="' . get_permalink( $post->ID ) . '">';
|
762 |
-
$output .= '<div style="width: ' . $width . 'px; height: ' . ( $height + $text_height ) . 'px;">';
|
763 |
-
$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>';
|
764 |
-
$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>';
|
765 |
-
$output .= $after_content;
|
766 |
-
// $output .= $date;
|
767 |
-
$output .= '</div>';
|
768 |
-
$output .= '</a>';
|
769 |
}
|
770 |
-
|
771 |
-
|
772 |
-
$output .= '
|
773 |
-
$output .= '
|
774 |
-
|
|
|
|
|
775 |
$output .= '</div>';
|
776 |
-
$output .= '
|
777 |
-
// $output .= '</ul>';
|
778 |
-
// $output .= '<!-- close related-posts-nav -->';
|
779 |
}
|
780 |
-
|
781 |
-
|
782 |
-
|
|
|
|
|
783 |
$output .= '</div>';
|
784 |
-
$output .= '<!-- close
|
|
|
|
|
|
|
785 |
|
786 |
-
|
787 |
-
$output .= '<!-- close relpost-thumb-wrapper -->';
|
788 |
-
|
789 |
-
return $this->finish_process( $output, $debug, $time );
|
790 |
|
791 |
-
|
|
|
792 |
|
793 |
-
|
|
|
794 |
|
795 |
-
|
796 |
-
|
797 |
-
$time = microtime( true ) - $time;
|
798 |
-
$debug .= "Plugin execution time: $time sec;";
|
799 |
-
$output .= '<!-- ' . $debug . ' -->';
|
800 |
-
}
|
801 |
-
return $output;
|
802 |
|
|
|
|
|
|
|
|
|
|
|
|
|
803 |
}
|
|
|
|
|
804 |
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
|
|
|
|
|
|
809 |
} else {
|
810 |
-
$text
|
811 |
-
if ( function_exists( 'mb_strlen' ) ) {
|
812 |
-
return ( ( mb_strlen( $text ) > $length ) ? mb_substr( $text, 0, $length ) . '...' : $text );
|
813 |
-
} else {
|
814 |
-
return ( ( strlen( $text ) > $length ) ? substr( $text, 0, $length ) . '...' : $text );
|
815 |
-
}
|
816 |
}
|
817 |
-
|
818 |
}
|
|
|
819 |
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
824 |
return false;
|
825 |
}
|
826 |
-
|
827 |
-
|
828 |
-
$post_type = get_post_type();
|
829 |
-
if ( !in_array( $post_type, $post_types ) ) {
|
830 |
return false;
|
831 |
}
|
832 |
-
/* Check categories */
|
833 |
-
$id = get_the_ID();
|
834 |
-
$categories_all = get_option( 'relpoststh_categoriesall', $this->categories_all );
|
835 |
-
if ( $categories_all != '1' ) { // only specific categories were selected
|
836 |
-
$post_categories = wp_get_object_terms( $id, array(
|
837 |
-
'category'
|
838 |
-
), array(
|
839 |
-
'fields' => 'ids'
|
840 |
-
) );
|
841 |
-
$relpoststh_categories = get_option( 'relpoststh_categories' );
|
842 |
-
if ( !is_array( $relpoststh_categories ) || !is_array( $post_categories ) ) { // no categories were selcted or post doesn't belong to any
|
843 |
-
return false;
|
844 |
-
}
|
845 |
-
$common_categories = array_intersect( $relpoststh_categories, $post_categories );
|
846 |
-
if ( empty( $common_categories ) ) { // post doesn't belong to specified categories
|
847 |
-
return false;
|
848 |
-
}
|
849 |
-
}
|
850 |
-
return true;
|
851 |
-
|
852 |
-
}
|
853 |
-
|
854 |
-
function admin_menu() {
|
855 |
-
|
856 |
-
$page = add_menu_page( __( 'Related Posts Thumbnails', 'related-posts-thumbnails' ), __( 'Related Posts', 'related-posts-thumbnails' ), 'administrator', 'related-posts-thumbnails', array(
|
857 |
-
$this,
|
858 |
-
'admin_interface'
|
859 |
-
), 'dashicons-screenoptions' );
|
860 |
-
|
861 |
}
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
867 |
}
|
868 |
-
|
869 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
870 |
?>
|
871 |
-
|
872 |
-
echo $
|
873 |
-
?>"
|
874 |
-
echo $
|
875 |
-
?>
|
876 |
-
|
|
|
|
|
|
|
|
|
877 |
echo 'checked="checked"';
|
878 |
}
|
879 |
?>/>
|
880 |
<label for="<?php
|
881 |
-
echo $
|
|
|
|
|
882 |
?>"><?php
|
883 |
-
|
884 |
-
?></label
|
885 |
-
<div class="select_specific" <?php
|
886 |
-
if ( $categoriesall == '1' ):
|
887 |
-
?> style="display:none" <?php
|
888 |
-
endif;
|
889 |
-
?>>
|
890 |
-
<?php
|
891 |
-
foreach ( $categories as $category ):
|
892 |
-
?>
|
893 |
-
<input type="checkbox" name="<?php
|
894 |
-
echo $specific_name;
|
895 |
-
?>[]" id="<?php
|
896 |
-
echo $specific_name;
|
897 |
-
?>_<?php
|
898 |
-
echo $category->category_nicename;
|
899 |
-
?>" value="<?php
|
900 |
-
echo $category->cat_ID;
|
901 |
-
?>" <?php
|
902 |
-
if ( in_array( $category->cat_ID, (array) $selected_categories ) ) {
|
903 |
-
echo 'checked="checked"';
|
904 |
-
}
|
905 |
-
?>/>
|
906 |
-
<label for="<?php
|
907 |
-
echo $specific_name;
|
908 |
-
?>_<?php
|
909 |
-
echo $category->category_nicename;
|
910 |
-
?>"><?php
|
911 |
-
echo $category->cat_name;
|
912 |
-
?></label><br />
|
913 |
-
<?php
|
914 |
-
endforeach;
|
915 |
-
?>
|
916 |
-
</div>
|
917 |
-
|
918 |
-
<?php
|
919 |
-
}
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
function head_style() {
|
925 |
-
?>
|
926 |
-
<style>
|
927 |
-
#related_posts_thumbnails li{
|
928 |
-
border-right: 1px solid <?php
|
929 |
-
echo get_option( 'relpoststh_bordercolor', $this->border_color );
|
930 |
-
?>;
|
931 |
-
background-color: <?php
|
932 |
-
echo get_option( 'relpoststh_background', $this->background );
|
933 |
-
?>
|
934 |
-
}
|
935 |
-
#related_posts_thumbnails li:hover{
|
936 |
-
background-color: <?php
|
937 |
-
echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground );
|
938 |
-
?>;
|
939 |
-
}
|
940 |
-
.relpost_content{
|
941 |
-
font-size: <?php
|
942 |
-
echo get_option( 'relpoststh_fontsize', $this->font_size ) . 'px';
|
943 |
-
?>;
|
944 |
-
color: <?php
|
945 |
-
echo get_option( 'relpoststh_fontcolor', $this->font_color );
|
946 |
-
?>;
|
947 |
-
}
|
948 |
-
.relpost-block-single{
|
949 |
-
background-color: <?php
|
950 |
-
echo get_option( 'relpoststh_background', $this->background );
|
951 |
-
?>;
|
952 |
-
border-right: 1px solid <?php
|
953 |
-
echo get_option( 'relpoststh_bordercolor', $this->border_color );
|
954 |
-
?>;
|
955 |
-
border-left: 1px solid <?php
|
956 |
-
echo get_option( 'relpoststh_bordercolor', $this->border_color );
|
957 |
-
?>;
|
958 |
-
margin-right: -1px;
|
959 |
-
}
|
960 |
-
.relpost-block-single:hover{
|
961 |
-
background-color: <?php
|
962 |
-
echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground );
|
963 |
-
?>;
|
964 |
-
}
|
965 |
-
</style>
|
966 |
-
|
967 |
<?php
|
968 |
-
|
969 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
970 |
}
|
971 |
|
972 |
add_action( 'init', 'related_posts_thumbnails' );
|
973 |
|
974 |
function related_posts_thumbnails() {
|
|
|
975 |
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
}
|
980 |
|
981 |
// Include Widget File.
|
982 |
include_once plugin_dir_path( __FILE__ ) . 'inc/rpt-widget.php';
|
|
|
|
|
983 |
|
984 |
?>
|
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.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 |
*/
|
10 |
|
11 |
/*
|
12 |
+
Copyright 2010 - 2019
|
13 |
|
14 |
This product was first developed by Maria I Shaldybina and later on maintained and developed by Adnan (WPBrigade.com)
|
15 |
|
24 |
GNU General Public License for more details.
|
25 |
*/
|
26 |
class RelatedPostsThumbnails {
|
27 |
+
/* Default values. PHP 4 compatible */
|
28 |
+
public $single_only = '1';
|
29 |
+
public $auto = '1';
|
30 |
+
public $top_text = '<h3>Related posts:</h3>';
|
31 |
+
public $number = 3;
|
32 |
+
public $relation = 'categories';
|
33 |
+
public $poststhname = 'thumbnail';
|
34 |
+
public $background = '#ffffff';
|
35 |
+
public $hoverbackground = '#eeeeee';
|
36 |
+
public $border_color = '#dddddd';
|
37 |
+
public $font_color = '#333333';
|
38 |
+
public $font_family = 'Arial';
|
39 |
+
public $font_size = '12';
|
40 |
+
public $text_length = '100';
|
41 |
+
public $excerpt_length = '0';
|
42 |
+
public $custom_field = '';
|
43 |
+
public $custom_height = '100';
|
44 |
+
public $custom_width = '100';
|
45 |
+
public $text_block_height = '75';
|
46 |
+
public $thsource = 'post-thumbnails';
|
47 |
+
public $categories_all = '1';
|
48 |
+
public $devmode = '0';
|
49 |
+
public $output_style = 'div';
|
50 |
+
public $post_types = array( 'post' );
|
51 |
+
public $custom_taxonomies = array();
|
52 |
+
protected $wp_kses_rp_args = array( 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), 'strong' => array() );
|
53 |
+
|
54 |
+
function __construct() {
|
55 |
+
$this->constant();
|
56 |
+
// initialization
|
57 |
+
load_plugin_textdomain( 'related-posts-thumbnails', false, basename( dirname( __FILE__ ) ) . '/locale' );
|
58 |
+
$this->default_image = esc_url( plugins_url( 'img/default.png', __FILE__ ) );
|
59 |
+
|
60 |
+
add_action( 'admin_enqueue_scripts', array(
|
61 |
+
$this,
|
62 |
+
'admin_scripts'
|
63 |
+
) );
|
64 |
+
|
65 |
+
// Compatibility for old default image path.
|
66 |
+
if ( $this->is_old_default_img() )
|
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 |
|
77 |
+
add_action( 'admin_menu', array(
|
78 |
+
$this,
|
79 |
+
'admin_menu'
|
80 |
+
) );
|
81 |
+
|
82 |
+
$this->wp_version = get_bloginfo( 'version' );
|
83 |
+
|
84 |
+
add_action( 'admin_footer', array(
|
85 |
+
$this,
|
86 |
+
'add_deactive_modal'
|
87 |
+
) );
|
88 |
+
add_action( 'wp_ajax_rpt_deactivate', array(
|
89 |
+
$this,
|
90 |
+
'rpt_deactivate'
|
91 |
+
) );
|
92 |
+
|
93 |
+
add_action( 'admin_init', array(
|
94 |
+
$this,
|
95 |
+
'review_notice'
|
96 |
+
) );
|
97 |
+
add_action( 'wp_enqueue_scripts', array(
|
98 |
+
$this,
|
99 |
+
'front_scripts'
|
100 |
+
) );
|
101 |
+
|
102 |
+
add_action( 'wp_head', array(
|
103 |
+
$this,
|
104 |
+
'head_style'
|
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(
|
112 |
+
'posts_number' => '3',
|
113 |
+
'posts_sort' => 'random',
|
114 |
+
'main_title' => ''
|
115 |
+
), $atts, 'related-posts-thumbnails'
|
116 |
+
);
|
117 |
+
|
118 |
+
$number = $atts['posts_number'];
|
119 |
+
|
120 |
+
if ( $atts['posts_sort'] == 'random' ) {
|
121 |
+
$sort = 'rand()';
|
122 |
+
} elseif ( $atts['posts_sort'] == 'latest' ) {
|
123 |
+
$sort = 'post_date';
|
124 |
}
|
125 |
|
126 |
+
if ( !is_numeric( $number ) ) {
|
127 |
+
$number = 3;
|
128 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
+
$main_title = str_replace( '_', ' ', $atts['main_title'] );
|
131 |
+
|
132 |
+
return $this->get_thumbnails( true, $number, $sort, $main_title );
|
133 |
+
}
|
134 |
+
|
135 |
+
function admin_scripts( $page ) {
|
136 |
+
if ( 'toplevel_page_related-posts-thumbnails' === $page ) {
|
137 |
+
wp_enqueue_media();
|
138 |
+
wp_enqueue_style( 'rpt_admin_css', plugins_url( 'assets/css/admin.css', __FILE__ ), false, RELATED_POSTS_THUMBNAILS_VERSION );
|
139 |
+
wp_enqueue_style( 'jquery-ui', 'http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css' );
|
140 |
+
wp_enqueue_style( 'wp-color-picker' );
|
141 |
+
wp_enqueue_script( 'rpt_admin_js', plugins_url( 'assets/js/admin.js', __FILE__ ), array(
|
142 |
+
'jquery',
|
143 |
+
'wp-color-picker',
|
144 |
+
'jquery-ui-datepicker'
|
145 |
+
), RELATED_POSTS_THUMBNAILS_VERSION );
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
function front_scripts() {
|
150 |
+
wp_enqueue_style( 'rpt_front_style', plugins_url( 'assets/css/front.css', __FILE__ ), false, RELATED_POSTS_THUMBNAILS_VERSION );
|
151 |
+
}
|
152 |
+
|
153 |
+
function constant() {
|
154 |
+
define( 'RELATED_POSTS_THUMBNAILS_VERSION', '1.6.2' );
|
155 |
+
define( 'RELATED_POSTS_THUMBNAILS_FEEDBACK_SERVER', 'https://wpbrigade.com/' );
|
156 |
+
define( 'RELATED_POSTS_THUMBNAILS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Show the popup on pluing deactivate
|
161 |
+
*
|
162 |
+
* @since 1.6.2
|
163 |
+
*/
|
164 |
+
function add_deactive_modal() {
|
165 |
+
global $pagenow;
|
166 |
+
|
167 |
+
if ( 'plugins.php' !== $pagenow ) {
|
168 |
+
return;
|
169 |
}
|
170 |
|
171 |
+
include RELATED_POSTS_THUMBNAILS_PLUGIN_DIR . 'inc/rpt-deactivate-form.php';
|
172 |
+
}
|
173 |
+
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Send the user responce to api.
|
177 |
+
*
|
178 |
+
* @since 1.6.2
|
179 |
+
*/
|
180 |
+
function rpt_deactivate() {
|
181 |
+
$email = get_option( 'admin_email' );
|
182 |
+
$_reason = sanitize_text_field( wp_unslash( $_POST[ 'reason' ] ) );
|
183 |
+
$reason_detail = sanitize_text_field( wp_unslash( $_POST[ 'reason_detail' ] ) );
|
184 |
+
$reason = '';
|
185 |
+
|
186 |
+
if ( $_reason == '1' ) {
|
187 |
+
$reason = 'I only needed the plugin for a short period';
|
188 |
+
} elseif ( $_reason == '2' ) {
|
189 |
+
$reason = 'I found a better plugin';
|
190 |
+
} elseif ( $_reason == '3' ) {
|
191 |
+
$reason = 'The plugin broke my site';
|
192 |
+
} elseif ( $_reason == '4' ) {
|
193 |
+
$reason = 'The plugin suddenly stopped working';
|
194 |
+
} elseif ( $_reason == '5' ) {
|
195 |
+
$reason = 'I no longer need the plugin';
|
196 |
+
} elseif ( $_reason == '6' ) {
|
197 |
+
$reason = 'It\'s a temporary deactivation. I\'m just debugging an issue.';
|
198 |
+
} elseif ( $_reason == '7' ) {
|
199 |
+
$reason = 'Other';
|
200 |
+
}
|
201 |
+
$fields = array(
|
202 |
+
'email' => $email,
|
203 |
+
'website' => get_site_url(),
|
204 |
+
'action' => 'Deactivate',
|
205 |
+
'reason' => $reason,
|
206 |
+
'reason_detail' => $reason_detail,
|
207 |
+
'blog_language' => get_bloginfo( 'language' ),
|
208 |
+
'wordpress_version' => get_bloginfo( 'version' ),
|
209 |
+
'php_version' => PHP_VERSION,
|
210 |
+
'plugin_version' => RELATED_POSTS_THUMBNAILS_VERSION,
|
211 |
+
'plugin_name' => 'Related Post Thumbnails'
|
212 |
+
);
|
213 |
+
|
214 |
+
$response = wp_remote_post( RELATED_POSTS_THUMBNAILS_FEEDBACK_SERVER, array(
|
215 |
+
'method' => 'POST',
|
216 |
+
'timeout' => 5,
|
217 |
+
'httpversion' => '1.0',
|
218 |
+
'blocking' => false,
|
219 |
+
'headers' => array(),
|
220 |
+
'body' => $fields
|
221 |
+
) );
|
222 |
+
|
223 |
+
wp_die();
|
224 |
+
}
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Check either to show notice or not.
|
228 |
+
*
|
229 |
+
* @since 1.8.2
|
230 |
+
*/
|
231 |
+
public function review_notice() {
|
232 |
+
$this->review_dismissal();
|
233 |
+
$this->review_prending();
|
234 |
+
|
235 |
+
$review_dismissal = get_option( 'rpt_review_dismiss' );
|
236 |
+
if ( 'yes' == $review_dismissal ) {
|
237 |
+
return;
|
238 |
+
}
|
239 |
|
240 |
+
$activation_time = get_option( 'rpt_active_time' );
|
241 |
+
if ( !$activation_time ) {
|
242 |
+
$activation_time = time();
|
243 |
+
add_option( 'rpt_active_time', $activation_time );
|
244 |
+
}
|
245 |
|
246 |
+
// 1296000 = 15 Days in seconds.
|
247 |
+
if ( time() - $activation_time > 1296000 ) {
|
248 |
+
add_action( 'admin_notices', array(
|
249 |
+
$this,
|
250 |
+
'review_notice_message'
|
251 |
+
) );
|
252 |
+
}
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Show review Message After 15 days.
|
257 |
+
*
|
258 |
+
* @since 1.8.2
|
259 |
+
*/
|
260 |
+
public function review_notice_message() {
|
261 |
+
$scheme = ( parse_url( $_SERVER[ 'REQUEST_URI' ], PHP_URL_QUERY ) ) ? '&' : '?';
|
262 |
+
$url = $_SERVER[ 'REQUEST_URI' ] . $scheme . 'rpt_review_dismiss=yes';
|
263 |
+
$dismiss_url = wp_nonce_url( $url, 'rpt-review-nonce' );
|
264 |
+
|
265 |
+
$_later_link = $_SERVER[ 'REQUEST_URI' ] . $scheme . 'ssb_review_later=yes';
|
266 |
+
$later_url = wp_nonce_url( $_later_link, 'rpt-review-nonce' ); ?>
|
267 |
+
|
268 |
+
<style media="screen">
|
269 |
+
.rpt-review-notice { padding: 15px 0; background-color: #fff; border-radius: 3px; margin: 20px 20px 0 0; border-left: 4px solid transparent; } .rpt-review-notice:after { content: ''; display: table; clear: both; }
|
270 |
+
.rpt-review-thumbnail { float: left; line-height: 80px; text-align: center; width: 117px; }
|
271 |
+
.rpt-review-thumbnail img { width: 118px; vertical-align: middle; }
|
272 |
+
.rpt-review-text { overflow: hidden; }
|
273 |
+
.rpt-review-text h3 { font-size: 24px; margin: 0 0 5px; font-weight: 400; line-height: 1.3; }
|
274 |
+
.rpt-review-text p { font-size: 13px; margin: 0 0 5px; }
|
275 |
+
.rpt-review-ul { margin: 0; padding: 0; }
|
276 |
+
.rpt-review-ul li { display: inline-block; margin-right: 15px; }
|
277 |
+
.rpt-review-ul li a { display: inline-block; color: #10738B; text-decoration: none; padding-left: 26px; position: relative; }
|
278 |
+
.rpt-review-ul li a span { position: absolute; left: 0; top: -2px; }
|
279 |
+
</style>
|
280 |
+
<div class="rpt-review-notice">
|
281 |
+
<div class="rpt-review-thumbnail">
|
282 |
+
<img src="<?php
|
283 |
+
echo plugins_url( 'assets/images/rpt-logo.png', __FILE__ );
|
284 |
+
?>" alt="">
|
285 |
+
</div>
|
286 |
+
<div class="rpt-review-text">
|
287 |
+
<h3><?php
|
288 |
+
_e( 'Leave A Review?', 'related-posts-thumbnails' );
|
289 |
+
?></h3>
|
290 |
+
<p><?php
|
291 |
+
_e( 'We hope you\'ve enjoyed using Related Post Thumbnails! Would you consider leaving us a review on WordPress.org?', 'related-posts-thumbnails' );
|
292 |
+
?></p>
|
293 |
+
<ul class="rpt-review-ul">
|
294 |
+
<li>
|
295 |
+
<a href="https://wordpress.org/support/plugin/related-posts-thumbnails/reviews/?filter=5" target="_blank"><span class="dashicons dashicons-external"></span>
|
296 |
+
<?php _e( 'Sure! I\'d love to!', 'related-posts-thumbnails' ); ?>
|
297 |
+
</a>
|
298 |
+
</li>
|
299 |
+
<li>
|
300 |
+
<a href="<?php echo $dismiss_url; ?>">
|
301 |
+
<span class="dashicons dashicons-smiley"></span>
|
302 |
+
<?php _e( 'I\'ve already left a review', 'related-posts-thumbnails' ); ?>
|
303 |
+
</a>
|
304 |
+
</li>
|
305 |
+
<li>
|
306 |
+
<a href="<?php echo $later_url; ?>">
|
307 |
+
<span class="dashicons dashicons-calendar-alt"></span>
|
308 |
+
<?php _e( 'Maybe Later', 'related-posts-thumbnails' ); ?>
|
309 |
+
</a>
|
310 |
+
</li>
|
311 |
+
<li>
|
312 |
+
<a href="<?php echo $dismiss_url; ?>">
|
313 |
+
<span class="dashicons dashicons-dismiss"></span>
|
314 |
+
<?php _e( 'Never show again', 'related-posts-thumbnails' ); ?>
|
315 |
+
</a>
|
316 |
+
</li>
|
317 |
+
</ul>
|
318 |
+
</div>
|
319 |
+
</div>
|
320 |
+
|
321 |
+
<?php
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Set time to current so review notice will popup after 15 days
|
326 |
+
*
|
327 |
+
* @since 1.8.2
|
328 |
+
*/
|
329 |
+
function review_prending() {
|
330 |
+
// delete_site_option( 'rpt_review_dismiss' );
|
331 |
+
if ( !is_admin() || !current_user_can( 'manage_options' ) || !isset( $_GET[ '_wpnonce' ] ) || !wp_verify_nonce( sanitize_key( wp_unslash( $_GET[ '_wpnonce' ] ) ), 'rpt-review-nonce' ) || !isset( $_GET[ 'ssb_review_later' ] ) ) {
|
332 |
+
|
333 |
+
return;
|
334 |
}
|
335 |
|
336 |
+
// Reset Time to current time.
|
337 |
+
update_option( 'rpt_active_time', time() );
|
338 |
+
}
|
339 |
|
340 |
+
/**
|
341 |
+
* Check and Dismiss review message.
|
342 |
+
*
|
343 |
+
* @since 1.8.2
|
344 |
+
*/
|
345 |
+
private function review_dismissal() {
|
346 |
+
//delete_option( 'rpt_review_dismiss' );
|
347 |
+
if ( !is_admin() || !current_user_can( 'manage_options' ) || !isset( $_GET[ '_wpnonce' ] ) || !wp_verify_nonce( sanitize_key( wp_unslash( $_GET[ '_wpnonce' ] ) ), 'rpt-review-nonce' ) || !isset( $_GET[ 'rpt_review_dismiss' ] ) ) {
|
348 |
|
349 |
+
return;
|
350 |
}
|
351 |
|
352 |
+
add_option( 'rpt_review_dismiss', 'yes' );
|
353 |
+
}
|
|
|
|
|
|
|
|
|
354 |
|
355 |
+
/**
|
356 |
+
* [is_old_default_img Check the compatibility for old default image path.]
|
357 |
+
* @return boolean Return true if path is old.
|
358 |
+
*/
|
359 |
+
function is_old_default_img() {
|
360 |
+
if ( get_option( 'relpoststh_default_image' ) !== $this->default_image ) {
|
361 |
|
362 |
+
$chunks = explode( '/', get_option( 'relpoststh_default_image' ) );
|
363 |
+
if ( in_array( 'related-posts-thumbnails', $chunks ) ) {
|
364 |
+
return true;
|
365 |
}
|
366 |
+
}
|
367 |
+
}
|
368 |
|
369 |
+
function auto_show( $content ) {
|
370 |
+
// Automatically displaying related posts under post body
|
371 |
+
return $content . $this->get_html( true );
|
372 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
+
function get_html( $show_top = false ) {
|
375 |
+
// Getting related posts HTML
|
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, $posts_number_short = '', $sort_by_short = '', $main_title = '' ) {
|
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( $posts_number_short ) ? $posts_number_short : $posts_number_opt;
|
389 |
+
$height = '';
|
390 |
+
$width = '';
|
391 |
+
// $date = '';
|
392 |
+
|
393 |
+
$sort_by_opt = get_option( 'rpt_post_sort') == 'latest' ? 'post_date': 'rand()';
|
394 |
+
$sort_by = !empty( $sort_by_short ) ? $sort_by_short : $sort_by_opt;
|
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 -->';
|
398 |
+
$output .= '<div class="relpost-thumb-wrapper">';
|
399 |
+
$output .= '<!-- filter-class -->';
|
400 |
+
$output .='<div class="relpost-thumb-container'. apply_filters( 'rpt_content_align', '' ) . '">';
|
401 |
+
$alt = '';
|
402 |
+
|
403 |
+
if ( $posts_number <= 0 ) { // return nothing if this parameter was set to <= 0
|
404 |
+
$output = '';
|
405 |
+
return $this->finish_process( $output, $debug . 'Posts number is 0;', $time );
|
406 |
}
|
407 |
|
408 |
+
$id = get_the_ID();
|
409 |
+
$relation = get_option( 'relpoststh_relation', $this->relation );
|
410 |
+
$poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
|
411 |
+
$text_length = get_option( 'relpoststh_textlength', $this->text_length );
|
412 |
+
$excerpt_length = get_option( 'relpoststh_excerptlength', $this->excerpt_length );
|
413 |
+
$thsource = get_option( 'relpoststh_thsource', $this->thsource );
|
414 |
+
$categories_show_all = get_option( 'relpoststh_show_categoriesall', get_option( 'relpoststh_categoriesall', $this->categories_all ) );
|
415 |
+
$onlywiththumbs = ( current_theme_supports( 'post-thumbnails' ) && $thsource == 'post-thumbnails' ) ? get_option( 'relpoststh_onlywiththumbs', false ) : false;
|
416 |
+
$post_type = get_post_type();
|
417 |
+
|
418 |
+
global $wpdb;
|
419 |
+
|
420 |
+
/* Get taxonomy terms */
|
421 |
+
$debug .= "Relation: $relation; All categories: $categories_show_all;";
|
422 |
+
$use_filter = ( $categories_show_all != '1' || $relation != 'no' );
|
423 |
+
|
424 |
+
if ( $use_filter ) {
|
425 |
+
$query_objects = "SELECT distinct object_id FROM $wpdb->term_relationships WHERE 1=1 ";
|
426 |
+
|
427 |
+
if ( $relation != 'no' ) {
|
428 |
+
/* Get object terms */
|
429 |
+
if ( $relation == 'categories' ) {
|
430 |
+
$taxonomy = array(
|
431 |
+
'category'
|
432 |
+
);
|
433 |
+
} elseif ( $relation == 'tags' ) {
|
434 |
+
$taxonomy = array(
|
435 |
+
'post_tag'
|
436 |
+
);
|
437 |
+
} elseif ( $relation == 'custom' ) {
|
438 |
+
$taxonomy = get_option( 'relpoststh_custom_taxonomies', $this->custom_taxonomies );
|
439 |
+
} else {
|
440 |
+
$taxonomy = array(
|
441 |
+
'category',
|
442 |
+
'post_tag'
|
443 |
+
);
|
444 |
+
}
|
445 |
+
$object_terms = wp_get_object_terms( $id, $taxonomy, array(
|
446 |
+
'fields' => 'ids'
|
447 |
+
) );
|
448 |
+
if ( empty( $object_terms ) || !is_array( $object_terms ) ) { // no terms to get taxonomy
|
449 |
+
$output = '';
|
450 |
+
return $this->finish_process( $output, $debug . __( 'No taxonomy terms to get posts;' ), $time );
|
451 |
+
}
|
452 |
|
453 |
+
$query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('" . implode( "', '", $object_terms ) . "')";
|
454 |
+
$object_taxonomy = $wpdb->get_results( $query );
|
455 |
+
$object_taxonomy_a = array();
|
456 |
+
if ( count( $object_taxonomy ) > 0 ) {
|
457 |
+
foreach ( $object_taxonomy as $item ) {
|
458 |
+
$object_taxonomy_a[] = $item->term_taxonomy_id;
|
459 |
+
}
|
460 |
+
}
|
461 |
+
$query_objects .= " AND term_taxonomy_id IN ('" . implode( "', '", $object_taxonomy_a ) . "') ";
|
462 |
}
|
463 |
|
464 |
+
if ( $categories_show_all != '1' ) {
|
465 |
+
/* Get filter terms */
|
466 |
+
$select_terms = get_option( 'relpoststh_show_categories', get_option( 'relpoststh_categories' ) );
|
467 |
+
if ( empty( $select_terms ) || !is_array( $select_terms ) ) { // if no categories were specified intentionally return nothing
|
468 |
+
$output = '';
|
469 |
+
return $this->finish_process( $output, $debug . __( 'No categories were selected;' ), $time );
|
470 |
+
}
|
471 |
|
472 |
+
$query = "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id in ('" . implode( "', '", $select_terms ) . "')";
|
473 |
+
$taxonomy = $wpdb->get_results( $query );
|
474 |
+
$filter_taxonomy_a = array();
|
475 |
+
if ( count( $taxonomy ) > 0 ) {
|
476 |
+
foreach ( $taxonomy as $item ) {
|
477 |
+
$filter_taxonomy_a[] = $item->term_taxonomy_id;
|
478 |
+
}
|
479 |
+
}
|
480 |
+
if ( $relation != 'no' ) {
|
481 |
+
$query_objects .= " AND object_id IN (SELECT distinct object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ('" . implode( "', '", $filter_taxonomy_a ) . "') )";
|
482 |
+
} else {
|
483 |
+
$query_objects .= " AND term_taxonomy_id IN ('" . implode( "', '", $filter_taxonomy_a ) . "')";
|
484 |
+
}
|
485 |
}
|
486 |
|
487 |
+
$relationships = $wpdb->get_results( $query_objects );
|
488 |
+
$related_objects = array();
|
489 |
+
if ( count( $relationships ) > 0 ) {
|
490 |
+
foreach ( $relationships as $item ) {
|
491 |
+
$related_objects[] = $item->object_id;
|
492 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
}
|
|
|
|
|
|
|
|
|
494 |
}
|
495 |
|
496 |
+
// $selected_post_type = '';
|
497 |
+
// foreach( get_option ( 'relpoststh_post_types' ) as $checked_post_type ) {
|
498 |
+
// $selected_post_type .= "'".$checked_post_type."',";
|
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' );
|
506 |
+
if ( !empty( $startdate ) && preg_match( '/^\d\d\d\d-\d\d-\d\d$/', $startdate ) ) { // If startdate was set
|
507 |
+
$debug .= "Startdate: $startdate;";
|
508 |
+
$where .= " AND post_date >= '" . $startdate . "'";
|
509 |
+
}
|
510 |
+
if ( $use_filter ) {
|
511 |
+
$where .= " AND ID IN ('" . implode( "', '", $related_objects ) . "')";
|
512 |
+
}
|
513 |
+
$join = '';
|
514 |
+
if ( $onlywiththumbs ) {
|
515 |
+
$debug .= 'Only with thumbnails;';
|
516 |
+
$join = " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)";
|
517 |
+
$where .= " AND $wpdb->postmeta.meta_key = '_thumbnail_id'";
|
518 |
+
}
|
519 |
|
520 |
+
$order = ' ORDER BY ' . $sort_by . ' LIMIT ' . $posts_number;
|
521 |
+
// var_dump($order);
|
522 |
+
$random_posts = $wpdb->get_results( $query . $join . $where . $order );
|
523 |
|
524 |
+
/* Get posts by their IDs */
|
525 |
+
if ( !is_array( $random_posts ) || count( $random_posts ) < 1 ) {
|
526 |
+
$output = '';
|
527 |
+
return $this->finish_process( $output, $debug . __( 'No posts matching relationships criteria;' ), $time );
|
528 |
}
|
529 |
|
530 |
+
$posts_in = array();
|
531 |
+
foreach ( $random_posts as $random_post ) {
|
532 |
+
$posts_in[] = $random_post->ID;
|
533 |
+
}
|
534 |
+
$query = "SELECT ID, post_content, post_excerpt, post_title FROM $wpdb->posts WHERE ID IN ('" . implode( "', '", $posts_in ) . "')";
|
535 |
+
$posts = $wpdb->get_results( $query );
|
536 |
|
537 |
+
if ( !( is_array( $posts ) && count( $posts ) > 0 ) ) { // no posts
|
538 |
+
$debug .= 'No posts found;';
|
539 |
+
$output = '';
|
540 |
+
return $this->finish_process( $output, $debug, $time );
|
541 |
+
} else {
|
542 |
+
$debug .= 'Found ' . count( $posts ) . ' posts;';
|
543 |
+
}
|
544 |
|
545 |
+
/* Calculating sizes */
|
546 |
+
if ( $thsource == 'custom-field' ) {
|
547 |
+
$debug .= 'Custom sizes;';
|
548 |
+
$width = get_option( 'relpoststh_customwidth', $this->custom_width );
|
549 |
+
$height = get_option( 'relpoststh_customheight', $this->custom_height );
|
550 |
+
} else { // post-thumbnails source
|
551 |
+
if ( $poststhname == 'thumbnail' || $poststhname == 'medium' || $poststhname == 'large' ) { // get thumbnail size for basic sizes
|
552 |
+
$debug .= 'Basic sizes;';
|
553 |
+
$width = get_option( "{$poststhname}_size_w" );
|
554 |
+
$height = get_option( "{$poststhname}_size_h" );
|
555 |
+
} elseif ( current_theme_supports( 'post-thumbnails' ) ) { // get sizes for theme supported thumbnails
|
556 |
+
global $_wp_additional_image_sizes;
|
557 |
+
if ( isset( $_wp_additional_image_sizes[ $poststhname ] ) ) {
|
558 |
+
$debug .= 'Additional sizes;';
|
559 |
+
$width = $_wp_additional_image_sizes[ $poststhname ][ 'width' ];
|
560 |
+
$height = $_wp_additional_image_sizes[ $poststhname ][ 'height' ];
|
561 |
+
} else {
|
562 |
+
$debug .= 'No additional sizes;';
|
563 |
}
|
564 |
}
|
|
|
565 |
}
|
566 |
+
// displaying square if one size is not cropping
|
567 |
+
if ( $height == 9999 ) {
|
568 |
+
$height = $width;
|
569 |
+
}
|
570 |
+
if ( $width == 9999 ) {
|
571 |
+
$width = $height;
|
572 |
+
}
|
573 |
+
// theme is not supporting but settings were not changed
|
574 |
+
if ( empty( $width ) ) {
|
575 |
+
$debug .= 'Using default width;';
|
576 |
+
$width = get_option( 'thumbnail_size_w' );
|
577 |
+
}
|
578 |
+
if ( empty( $height ) ) {
|
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 |
+
if ( ! empty( $main_title ) ) {
|
586 |
+
$output .= '<p class="relpoststh-block-title">' . $main_title . '</p>';
|
587 |
+
} else {
|
588 |
+
$output .= stripslashes( get_option( 'relpoststh_top_text', $this->top_text ) );
|
589 |
+
}
|
590 |
|
591 |
+
$relpoststh_output_style = get_option( 'relpoststh_output_style', $this->output_style );
|
592 |
+
$relpoststh_cleanhtml = get_option( 'relpoststh_cleanhtml', 0 );
|
593 |
+
$text_height = get_option( 'relpoststh_textblockheight', $this->text_block_height );
|
|
|
|
|
594 |
|
|
|
595 |
|
596 |
+
if ( $relpoststh_output_style == 'list' ) {
|
597 |
+
$output .= '<!-- related_posts_thumbnails -->';
|
598 |
+
$output .= '<ul id="related_posts_thumbnails"';
|
599 |
+
if ( ! $relpoststh_cleanhtml ) {
|
600 |
+
$output .= ' style="list-style-type:none; list-style-position: inside; padding: 0; margin:0"';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
601 |
}
|
602 |
+
$output .= '>';
|
603 |
+
} else {
|
604 |
|
605 |
+
$output .= '<div style="clear: both"></div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
606 |
|
607 |
+
// $output .= '<!-- related-posts-nav -->';
|
608 |
+
// $output .= '<ul class="related-posts-nav">'; //open blocks ul
|
609 |
|
610 |
+
$output .= '<div style="clear: both"></div>';
|
|
|
|
|
611 |
|
612 |
+
$output .= '<!-- relpost-block-container -->';
|
613 |
+
$output .= '<div class="relpost-block-container">'; // open relpost-block-container div
|
614 |
+
}
|
615 |
|
616 |
+
foreach ( $posts as $post ) {
|
617 |
+
$image = '';
|
618 |
+
$url = '';
|
619 |
+
$alt = '';
|
620 |
+
if ( $thsource == 'custom-field' ) {
|
621 |
+
if ( is_array( $url ) ) {
|
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 ) {
|
629 |
+
$url = substr( $url, strpos( $url, '/wp-content' ) );
|
630 |
+
}
|
631 |
+
|
632 |
+
if ( !empty( $theme_resize_url ) ) {
|
633 |
+
$url = $theme_resize_url . '?src=' . $url . '&w=' . $width . '&h=' . $height . '&zc=1&q=90';
|
634 |
+
}
|
635 |
+
}
|
636 |
+
} else {
|
637 |
+
$from_post_body = true;
|
638 |
+
if ( current_theme_supports( 'post-thumbnails' ) ) { // using built in Wordpress feature
|
639 |
+
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
|
640 |
+
$debug .= 'Post-thumbnails enabled in theme;';
|
641 |
+
if ( !( empty( $post_thumbnail_id ) || $post_thumbnail_id === false ) ) { // post has thumbnail
|
642 |
+
$debug .= 'Post has thumbnail ' . $post_thumbnail_id . ';';
|
643 |
+
$debug .= 'Postthname: ' . $poststhname . ';';
|
644 |
+
$image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
|
645 |
+
$alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
|
646 |
+
$url = $image[ 0 ];
|
647 |
+
$from_post_body = false;
|
648 |
} else {
|
649 |
+
$debug .= 'Post has no thumbnail;';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
650 |
}
|
|
|
651 |
}
|
652 |
+
if ( $from_post_body ) { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
|
653 |
+
$debug .= 'Getting image from post body;';
|
654 |
+
$wud = wp_upload_dir();
|
655 |
+
preg_match_all( '|<img.*?src=[\'"](' . $wud[ 'baseurl' ] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // search the first uploaded image in content
|
656 |
+
|
657 |
+
if ( isset( $matches ) && isset( $matches[ 1 ][ 0 ] ) ) {
|
658 |
+
$image = $matches[ 1 ][ 0 ];
|
659 |
+
$html = $matches[ 0 ][ 0 ];
|
660 |
+
if ( !empty( $html ) ) {
|
661 |
+
preg_match( '/alt="([^"]*)"/i', $html, $array );
|
662 |
+
|
663 |
+
if ( !empty( $array ) && is_array( $array ) ) {
|
664 |
+
$explode_tag = explode( '"', $array[ 0 ] );
|
665 |
+
$alt = $explode_tag[ 1 ];
|
666 |
+
}
|
667 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
668 |
}
|
|
|
|
|
|
|
669 |
} else {
|
670 |
+
$debug .= 'No image was found;';
|
671 |
}
|
|
|
672 |
|
673 |
+
if ( strlen( trim( $image ) ) > 0 ) {
|
674 |
+
$image_sizes = @getimagesize( $image );
|
675 |
+
if ( $image_sizes === false ) {
|
676 |
+
$debug .= 'Unable to determine parsed image size';
|
677 |
+
}
|
678 |
+
if ( $image_sizes !== false && isset( $image_sizes[ 0 ] ) && $image_sizes[ 0 ] == $width ) { // if this image is the same size as we need
|
679 |
+
$debug .= 'Image used is the required size;';
|
680 |
+
$url = $image;
|
681 |
+
} else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
|
682 |
+
$debug .= 'Changing image according to Wordpress standards;';
|
683 |
+
$url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
|
684 |
+
}
|
685 |
+
} else {
|
686 |
+
$debug .= 'Found wrong formatted image: ' . $image . ';';
|
687 |
}
|
688 |
}
|
689 |
+
$basic_url = $url;
|
690 |
}
|
691 |
|
692 |
+
if ( strpos( $url, '/' ) === 0 ) {
|
693 |
+
$debug .= 'Relative url: ' . $url . ';';
|
694 |
+
$url = $basic_url = get_bloginfo( 'url' ) . $url;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
695 |
}
|
696 |
|
697 |
+
$debug .= 'Image URL: ' . $url . ';';
|
698 |
+
if ( empty( $basic_url ) ) { // parsed URL is empty or no file if can check
|
699 |
+
$debug .= 'Image is empty or no file. Using default image;';
|
700 |
+
$url = get_option( 'relpoststh_default_image', $this->default_image );
|
|
|
|
|
|
|
701 |
}
|
702 |
|
703 |
+
$title = $this->process_text_cut( $post->post_title, $text_length );
|
704 |
+
$post_excerpt = ( empty( $post->post_excerpt ) ) ? $post->post_content : $post->post_excerpt;
|
705 |
+
$excerpt = $this->process_text_cut( $post_excerpt, $excerpt_length );
|
|
|
|
|
|
|
706 |
|
707 |
+
if ( !empty( $title ) && !empty( $excerpt ) ) {
|
708 |
+
$title = '<b>' . $title . '</b>';
|
709 |
+
$excerpt = '<br/>' . $excerpt;
|
|
|
|
|
|
|
710 |
}
|
711 |
|
712 |
+
if ( empty( $alt ) ) {
|
713 |
+
$alt = str_replace('"', '', $title);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 ( $relpoststh_output_style == 'list' ) {
|
722 |
+
$link = get_permalink( $post->ID );
|
723 |
+
$output .= '<li ';
|
724 |
+
if ( !$relpoststh_cleanhtml ) {
|
725 |
+
// $output .= ' onmouseout="this.style.backgroundColor=\'' . get_option( 'relpoststh_background', $this->background ) . '\'"';
|
726 |
}
|
727 |
$output .= '>';
|
728 |
+
$output .= '<a href="' . $link . '" ><img class="relpost-post-image" alt="' . $alt . '" src="' . esc_url( $url ) . '" width="' . $width . '" height="' . $height . '" ';
|
729 |
+
if ( !$relpoststh_cleanhtml ) {
|
730 |
+
// $output .= 'style="padding: 0px; margin: 0px; border: 0pt none;"';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
731 |
}
|
732 |
+
$output .= '/></a>';
|
733 |
+
if ( $text_height != '0' ) {
|
734 |
+
$output .= '<a href="' . $link . '" class="relpost_content"';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
735 |
if ( !$relpoststh_cleanhtml ) {
|
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 |
+
} else {
|
742 |
+
$output .= '<a class="relpost-block-single" href="' . get_permalink( $post->ID ) . '">';
|
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>';
|
754 |
+
$output .= '<!-- close related_posts_thumbnails -->';
|
755 |
+
} else {
|
756 |
$output .= '</div>';
|
757 |
+
$output .= '<!-- close relpost-block-container -->';
|
758 |
+
// $output .= '</ul>';
|
759 |
+
// $output .= '<!-- close related-posts-nav -->';
|
760 |
+
}
|
761 |
|
762 |
+
$output .= '<div style="clear: both"></div>';
|
|
|
|
|
|
|
763 |
|
764 |
+
$output .= '</div>';
|
765 |
+
$output .= '<!-- close filter class -->';
|
766 |
|
767 |
+
$output .= '</div>';
|
768 |
+
$output .= '<!-- close relpost-thumb-wrapper -->';
|
769 |
|
770 |
+
return $this->finish_process( $output, $debug, $time );
|
771 |
+
}
|
|
|
|
|
|
|
|
|
|
|
772 |
|
773 |
+
function finish_process( $output, $debug, $time ) {
|
774 |
+
$devmode = get_option( 'relpoststh_devmode', $this->devmode );
|
775 |
+
if ( $devmode ) {
|
776 |
+
$time = microtime( true ) - $time;
|
777 |
+
$debug .= "Plugin execution time: $time sec;";
|
778 |
+
$output .= '<!-- ' . $debug . ' -->';
|
779 |
}
|
780 |
+
return $output;
|
781 |
+
}
|
782 |
|
783 |
+
function process_text_cut( $text, $length ) {
|
784 |
+
if ( $length == 0 ) {
|
785 |
+
return '';
|
786 |
+
} else {
|
787 |
+
$text = strip_tags( strip_shortcodes( $text ) );
|
788 |
+
if ( function_exists( 'mb_strlen' ) ) {
|
789 |
+
return ( ( mb_strlen( $text ) > $length ) ? mb_substr( $text, 0, $length ) . '...' : $text );
|
790 |
} else {
|
791 |
+
return ( ( strlen( $text ) > $length ) ? substr( $text, 0, $length ) . '...' : $text );
|
|
|
|
|
|
|
|
|
|
|
792 |
}
|
|
|
793 |
}
|
794 |
+
}
|
795 |
|
796 |
+
function is_relpoststh_show() {
|
797 |
+
// Checking display options
|
798 |
+
if ( !is_single() && get_option( 'relpoststh_single_only', $this->single_only ) ) { // single only
|
799 |
+
return false;
|
800 |
+
}
|
801 |
+
/* Check post type */
|
802 |
+
$post_types = get_option( 'relpoststh_post_types', $this->post_types );
|
803 |
+
$post_type = get_post_type();
|
804 |
+
if ( !in_array( $post_type, $post_types ) ) {
|
805 |
+
return false;
|
806 |
+
}
|
807 |
+
/* Check categories */
|
808 |
+
$id = get_the_ID();
|
809 |
+
$categories_all = get_option( 'relpoststh_categoriesall', $this->categories_all );
|
810 |
+
if ( $categories_all != '1' ) { // only specific categories were selected
|
811 |
+
$post_categories = wp_get_object_terms( $id, array(
|
812 |
+
'category'
|
813 |
+
), array(
|
814 |
+
'fields' => 'ids'
|
815 |
+
) );
|
816 |
+
$relpoststh_categories = get_option( 'relpoststh_categories' );
|
817 |
+
if ( !is_array( $relpoststh_categories ) || !is_array( $post_categories ) ) { // no categories were selcted or post doesn't belong to any
|
818 |
return false;
|
819 |
}
|
820 |
+
$common_categories = array_intersect( $relpoststh_categories, $post_categories );
|
821 |
+
if ( empty( $common_categories ) ) { // post doesn't belong to specified categories
|
|
|
|
|
822 |
return false;
|
823 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
824 |
}
|
825 |
+
return true;
|
826 |
+
}
|
827 |
+
|
828 |
+
function admin_menu() {
|
829 |
+
$page = add_menu_page( __( 'Related Posts Thumbnails', 'related-posts-thumbnails' ), __( 'Related Posts', 'related-posts-thumbnails' ), 'administrator', 'related-posts-thumbnails', array(
|
830 |
+
$this,
|
831 |
+
'admin_interface'
|
832 |
+
), 'dashicons-screenoptions' );
|
833 |
+
}
|
834 |
+
|
835 |
+
function admin_interface() {
|
836 |
+
include_once RELATED_POSTS_THUMBNAILS_PLUGIN_DIR . '/inc/rpt-settings.php';
|
837 |
+
}
|
838 |
+
|
839 |
+
function display_categories_list( $categoriesall, $categories, $selected_categories, $all_name, $specific_name ) { ?>
|
840 |
+
<input id="<?php
|
841 |
+
echo $all_name;
|
842 |
+
?>" class="select_all" type="checkbox" name="<?php
|
843 |
+
echo $all_name;
|
844 |
+
?>" value="1" <?php
|
845 |
+
if ( $categoriesall == '1' ) {
|
846 |
+
echo 'checked="checked"';
|
847 |
}
|
848 |
+
?>/>
|
849 |
+
<label for="<?php
|
850 |
+
echo $all_name;
|
851 |
+
?>"><?php
|
852 |
+
_e( 'All', 'related-posts-thumbnails' );
|
853 |
+
?></label>
|
854 |
+
<div class="select_specific" <?php
|
855 |
+
if ( $categoriesall == '1' ):
|
856 |
+
?> style="display:none" <?php
|
857 |
+
endif;
|
858 |
+
?>>
|
859 |
+
<?php
|
860 |
+
foreach ( $categories as $category ):
|
861 |
?>
|
862 |
+
<input type="checkbox" name="<?php
|
863 |
+
echo $specific_name;
|
864 |
+
?>[]" id="<?php
|
865 |
+
echo $specific_name;
|
866 |
+
?>_<?php
|
867 |
+
echo $category->category_nicename;
|
868 |
+
?>" value="<?php
|
869 |
+
echo $category->cat_ID;
|
870 |
+
?>" <?php
|
871 |
+
if ( in_array( $category->cat_ID, (array) $selected_categories ) ) {
|
872 |
echo 'checked="checked"';
|
873 |
}
|
874 |
?>/>
|
875 |
<label for="<?php
|
876 |
+
echo $specific_name;
|
877 |
+
?>_<?php
|
878 |
+
echo $category->category_nicename;
|
879 |
?>"><?php
|
880 |
+
echo $category->cat_name;
|
881 |
+
?></label><br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
882 |
<?php
|
883 |
+
endforeach;
|
884 |
+
?>
|
885 |
+
</div>
|
886 |
+
|
887 |
+
<?php
|
888 |
+
}
|
889 |
+
|
890 |
+
function head_style() { ?>
|
891 |
+
<style>
|
892 |
+
#related_posts_thumbnails li{
|
893 |
+
border-right: 1px solid <?php
|
894 |
+
echo get_option( 'relpoststh_bordercolor', $this->border_color );
|
895 |
+
?>;
|
896 |
+
background-color: <?php
|
897 |
+
echo get_option( 'relpoststh_background', $this->background );
|
898 |
+
?>
|
899 |
+
}
|
900 |
+
#related_posts_thumbnails li:hover{
|
901 |
+
background-color: <?php
|
902 |
+
echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground );
|
903 |
+
?>;
|
904 |
+
}
|
905 |
+
.relpost_content{
|
906 |
+
font-size: <?php
|
907 |
+
echo get_option( 'relpoststh_fontsize', $this->font_size ) . 'px';
|
908 |
+
?>;
|
909 |
+
color: <?php
|
910 |
+
echo get_option( 'relpoststh_fontcolor', $this->font_color );
|
911 |
+
?>;
|
912 |
+
}
|
913 |
+
.relpost-block-single{
|
914 |
+
background-color: <?php
|
915 |
+
echo get_option( 'relpoststh_background', $this->background );
|
916 |
+
?>;
|
917 |
+
border-right: 1px solid <?php
|
918 |
+
echo get_option( 'relpoststh_bordercolor', $this->border_color );
|
919 |
+
?>;
|
920 |
+
border-left: 1px solid <?php
|
921 |
+
echo get_option( 'relpoststh_bordercolor', $this->border_color );
|
922 |
+
?>;
|
923 |
+
margin-right: -1px;
|
924 |
+
}
|
925 |
+
.relpost-block-single:hover{
|
926 |
+
background-color: <?php
|
927 |
+
echo get_option( 'relpoststh_hoverbackground', $this->hoverbackground );
|
928 |
+
?>;
|
929 |
+
}
|
930 |
+
</style>
|
931 |
+
|
932 |
+
<?php
|
933 |
+
}
|
934 |
}
|
935 |
|
936 |
add_action( 'init', 'related_posts_thumbnails' );
|
937 |
|
938 |
function related_posts_thumbnails() {
|
939 |
+
define( 'RELATED_POSTS_THUMBNAILS_URI', plugin_dir_url( __FILE__ ) );
|
940 |
|
941 |
+
global $related_posts_thumbnails;
|
942 |
+
$related_posts_thumbnails = new RelatedPostsThumbnails();
|
|
|
943 |
}
|
944 |
|
945 |
// Include Widget File.
|
946 |
include_once plugin_dir_path( __FILE__ ) . 'inc/rpt-widget.php';
|
947 |
+
// Include Blocks File.
|
948 |
+
include_once plugin_dir_path( __FILE__ ) . 'inc/rpt-blocks.php';
|
949 |
|
950 |
?>
|