| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Related Post by PickPlugins |
| 4 |
Plugin URI: http://wordpress.org/plugins/related-post/ |
| 5 |
Description: Display related posts under post content on single page and excerpt on archive pages. |
| 6 |
Version: 2.0.64 |
| 7 |
Author: PickPlugins |
| 8 |
Author URI: http://pickplugins.com |
| 9 |
License: GPLv2 or later |
| 10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 11 |
*/ |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) exit; // if direct access |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class RelatedPost |
| 18 |
{ |
| 19 |
|
| 20 |
public function __construct() |
| 21 |
{ |
| 22 |
|
| 23 |
define('related_post_plugin_url', plugins_url('/', __FILE__)); |
| 24 |
define('related_post_plugin_dir', plugin_dir_path(__FILE__)); |
| 25 |
define('related_post_wp_url', 'http://wordpress.org/plugins/related-post/'); |
| 26 |
define('related_post_support_url', 'http://pickplugins.com/forum'); |
| 27 |
define('related_post_plugin_name', 'Related Post'); |
| 28 |
|
| 29 |
// Classes |
| 30 |
require_once(related_post_plugin_dir . 'includes/class-settings.php'); |
| 31 |
require_once(related_post_plugin_dir . 'includes/class-functions.php'); |
| 32 |
//require_once( related_post_plugin_dir . 'includes/class-notices.php'); |
| 33 |
require_once(related_post_plugin_dir . 'includes/class-post-meta.php'); |
| 34 |
require_once(related_post_plugin_dir . 'includes/class-settings-tabs.php'); |
| 35 |
|
| 36 |
|
| 37 |
require_once(related_post_plugin_dir . 'includes/class-data-upgrade.php'); |
| 38 |
|
| 39 |
// functions |
| 40 |
require_once(related_post_plugin_dir . 'includes/functions.php'); |
| 41 |
require_once(related_post_plugin_dir . 'includes/functions-settings.php'); |
| 42 |
|
| 43 |
// Shortcodes |
| 44 |
require_once(related_post_plugin_dir . 'includes/shortcodes.php'); |
| 45 |
|
| 46 |
|
| 47 |
// Hooks |
| 48 |
add_action('admin_enqueue_scripts', 'wp_enqueue_media'); |
| 49 |
add_action('wp_enqueue_scripts', array($this, '_front_scripts')); |
| 50 |
add_action('admin_enqueue_scripts', array($this, '_admin_scripts')); |
| 51 |
add_action('plugins_loaded', array($this, '_textdomain')); |
| 52 |
|
| 53 |
register_activation_hook(__FILE__, array($this, '_activation')); |
| 54 |
} |
| 55 |
|
| 56 |
public function _activation() |
| 57 |
{ |
| 58 |
|
| 59 |
$related_post_settings = get_option('related_post_settings'); |
| 60 |
$post_types_display = isset($related_post_settings['post_types_display']) ? $related_post_settings['post_types_display'] : array(); |
| 61 |
|
| 62 |
|
| 63 |
if (empty($post_types_display)) { |
| 64 |
$post_types = isset($related_post_settings['post_types']) ? $related_post_settings['post_types'] : array(); |
| 65 |
$content_positions = isset($related_post_settings['content_positions']) ? $related_post_settings['content_positions'] : array(); |
| 66 |
$excerpt_positions = isset($related_post_settings['excerpt_positions']) ? $related_post_settings['excerpt_positions'] : array(); |
| 67 |
$paragraph_positions = isset($related_post_settings['paragraph_positions']) ? $related_post_settings['paragraph_positions'] : ""; |
| 68 |
$headline_text = isset($related_post_settings['headline_text']) ? $related_post_settings['headline_text'] : ""; |
| 69 |
$layout_type = isset($related_post_settings['layout_type']) ? $related_post_settings['layout_type'] : ""; |
| 70 |
|
| 71 |
|
| 72 |
foreach ($post_types as $post_type) { |
| 73 |
|
| 74 |
$related_post_settings['post_types_display'][$post_type]['enable'] = 'yes'; |
| 75 |
|
| 76 |
$related_post_settings['post_types_display'][$post_type]['content_position'] = $content_positions; |
| 77 |
$related_post_settings['post_types_display'][$post_type]['excerpt_position'] = $excerpt_positions; |
| 78 |
$related_post_settings['post_types_display'][$post_type]['paragraph_positions'] = $paragraph_positions; |
| 79 |
$related_post_settings['post_types_display'][$post_type]['headline_text'] = $headline_text; |
| 80 |
$related_post_settings['post_types_display'][$post_type]['view_type'] = $layout_type; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
update_option('related_post_settings', $related_post_settings); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
global $wpdb; |
| 94 |
$charset_collate = $wpdb->get_charset_collate(); |
| 95 |
$table = $wpdb->prefix . 'related_post_stats'; |
| 96 |
|
| 97 |
$sql = "CREATE TABLE IF NOT EXISTS " . $table . " ( |
| 98 |
id int(100) NOT NULL AUTO_INCREMENT, |
| 99 |
from_id int(100) NOT NULL, |
| 100 |
to_id int(100) NOT NULL, |
| 101 |
date DATE NOT NULL, |
| 102 |
UNIQUE KEY id (id) |
| 103 |
) $charset_collate;"; |
| 104 |
|
| 105 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 106 |
|
| 107 |
dbDelta($sql); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public function _textdomain() |
| 113 |
{ |
| 114 |
|
| 115 |
// Global files |
| 116 |
$locale = apply_filters('plugin_locale', get_locale(), 'related-post'); |
| 117 |
load_textdomain('related-post', WP_LANG_DIR . '/related-post/related-post-' . $locale . '.mo'); |
| 118 |
|
| 119 |
// Plugin files |
| 120 |
load_plugin_textdomain('related-post', false, plugin_basename(dirname(__FILE__)) . '/languages/'); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
function _front_scripts() |
| 126 |
{ |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
wp_register_style('related-post', related_post_plugin_url . 'assets/front/css/related-post.css'); |
| 132 |
wp_register_style('font-awesome-5', related_post_plugin_url . 'assets/front/css/font-awesome-5.css'); |
| 133 |
wp_register_style('font-awesome-4', related_post_plugin_url . 'assets/front/css/font-awesome-4.css'); |
| 134 |
|
| 135 |
wp_register_script('owl.carousel', related_post_plugin_url . '/assets/front/js/owl.carousel.min.js', array('jquery')); |
| 136 |
wp_register_style('owl.carousel', related_post_plugin_url . 'assets/front/css/owl.carousel.min.css'); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
function _admin_scripts() |
| 141 |
{ |
| 142 |
|
| 143 |
|
| 144 |
wp_enqueue_script('related_post_js', related_post_plugin_url . 'assets/admin/js/scripts.js', array('jquery')); |
| 145 |
wp_localize_script('related_post_js', 'related_post_ajax', array('related_post_ajaxurl' => admin_url('admin-ajax.php'))); |
| 146 |
|
| 147 |
wp_register_style('font-awesome-5', related_post_plugin_url . 'assets/front/css/font-awesome-5.css'); |
| 148 |
|
| 149 |
// settings-tabs framework |
| 150 |
wp_register_script('settings-tabs', related_post_plugin_url . 'assets/settings-tabs/settings-tabs.js', array('jquery')); |
| 151 |
wp_register_style('settings-tabs', related_post_plugin_url . 'assets/settings-tabs/settings-tabs.css'); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
new RelatedPost(); |
| 156 |
|