| 1 |
<?php |
| 2 |
/** |
| 3 |
* Contextual Related Posts. |
| 4 |
* |
| 5 |
* Contextual Related Posts is the best related posts plugin for WordPress that |
| 6 |
* allows you to display a list of related posts on your website and in your feed. |
| 7 |
* |
| 8 |
* @package Contextual_Related_Posts |
| 9 |
* @author Ajay D'Souza |
| 10 |
* @license GPL-2.0+ |
| 11 |
* @link https://webberzone.com |
| 12 |
* @copyright 2009-2026 Ajay D'Souza |
| 13 |
* |
| 14 |
* @wordpress-plugin |
| 15 |
* Plugin Name: Contextual Related Posts |
| 16 |
* Plugin URI: https://webberzone.com/plugins/contextual-related-posts/ |
| 17 |
* Description: Display related posts on your website or in your feed. Increase reader retention and reduce bounce rates. |
| 18 |
* Version: 4.4.1 |
| 19 |
* Author: WebberZone |
| 20 |
* Author URI: https://webberzone.com |
| 21 |
* License: GPL-2.0+ |
| 22 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 23 |
* Text Domain: contextual-related-posts |
| 24 |
* Domain Path: /languages |
| 25 |
*/ |
| 26 |
|
| 27 |
namespace WebberZone\Contextual_Related_Posts; |
| 28 |
|
| 29 |
if ( ! defined( 'WPINC' ) ) { |
| 30 |
die; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Holds the version of Contextual Related Posts. |
| 35 |
* |
| 36 |
* @since 2.9.3 |
| 37 |
*/ |
| 38 |
if ( ! defined( 'WZ_CRP_VERSION' ) ) { |
| 39 |
define( 'WZ_CRP_VERSION', '4.4.1' ); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* Holds the filesystem directory path (with trailing slash) for Contextual Related Posts. |
| 45 |
* |
| 46 |
* @since 2.3.0 |
| 47 |
*/ |
| 48 |
if ( ! defined( 'WZ_CRP_PLUGIN_FILE' ) ) { |
| 49 |
define( 'WZ_CRP_PLUGIN_FILE', __FILE__ ); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
/** |
| 54 |
* Holds the filesystem directory path (with trailing slash) for Contextual Related Posts. |
| 55 |
* |
| 56 |
* @since 2.3.0 |
| 57 |
*/ |
| 58 |
if ( ! defined( 'WZ_CRP_PLUGIN_DIR' ) ) { |
| 59 |
define( 'WZ_CRP_PLUGIN_DIR', plugin_dir_path( WZ_CRP_PLUGIN_FILE ) ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Holds the filesystem directory path (with trailing slash) for Contextual Related Posts. |
| 64 |
* |
| 65 |
* @since 2.3.0 |
| 66 |
*/ |
| 67 |
if ( ! defined( 'WZ_CRP_PLUGIN_URL' ) ) { |
| 68 |
define( 'WZ_CRP_PLUGIN_URL', plugin_dir_url( WZ_CRP_PLUGIN_FILE ) ); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Holds the default thumbnail URL for Contextual Related Posts. |
| 73 |
* |
| 74 |
* @since 4.2.0 |
| 75 |
*/ |
| 76 |
if ( ! defined( 'WZ_CRP_DEFAULT_THUMBNAIL_URL' ) ) { |
| 77 |
define( 'WZ_CRP_DEFAULT_THUMBNAIL_URL', WZ_CRP_PLUGIN_URL . 'default.png' ); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Maximum words to match in the content. |
| 82 |
* |
| 83 |
* @since 2.3.0 |
| 84 |
*/ |
| 85 |
if ( ! defined( 'CRP_MAX_WORDS' ) ) { |
| 86 |
define( 'CRP_MAX_WORDS', 100 ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* CRP Cache expiration time. |
| 91 |
* |
| 92 |
* @since 3.0.0 |
| 93 |
*/ |
| 94 |
if ( ! defined( 'CRP_CACHE_TIME' ) ) { |
| 95 |
define( 'CRP_CACHE_TIME', WEEK_IN_SECONDS ); |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* CRP Database version. |
| 100 |
* |
| 101 |
* @since 3.5.0 |
| 102 |
*/ |
| 103 |
if ( ! defined( 'WZ_CRP_DB_VERSION' ) ) { |
| 104 |
define( 'WZ_CRP_DB_VERSION', '1.0' ); |
| 105 |
} |
| 106 |
|
| 107 |
if ( ! function_exists( __NAMESPACE__ . '\crp_deactivate_other_instances' ) ) { |
| 108 |
/** |
| 109 |
* Deactivate other instances of CRP when this plugin is activated. |
| 110 |
* |
| 111 |
* @param string $plugin The plugin being activated. |
| 112 |
* @param bool $network_wide Whether the plugin is being activated network-wide. |
| 113 |
*/ |
| 114 |
function crp_deactivate_other_instances( $plugin, $network_wide = false ) { |
| 115 |
$free_plugin = 'contextual-related-posts/contextual-related-posts.php'; |
| 116 |
$pro_plugin = 'contextual-related-posts-pro/contextual-related-posts.php'; |
| 117 |
|
| 118 |
// Only proceed if one of our plugins is being activated. |
| 119 |
if ( ! in_array( $plugin, array( $free_plugin, $pro_plugin ), true ) ) { |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
$plugins_to_deactivate = array(); |
| 124 |
$deactivated_plugin = ''; |
| 125 |
|
| 126 |
// If pro is being activated, deactivate free. |
| 127 |
if ( $pro_plugin === $plugin ) { |
| 128 |
if ( is_plugin_active( $free_plugin ) || ( $network_wide && is_plugin_active_for_network( $free_plugin ) ) ) { |
| 129 |
$plugins_to_deactivate[] = $free_plugin; |
| 130 |
$deactivated_plugin = 'Contextual Related Posts'; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
// If free is being activated, deactivate pro. |
| 135 |
if ( $free_plugin === $plugin ) { |
| 136 |
if ( is_plugin_active( $pro_plugin ) || ( $network_wide && is_plugin_active_for_network( $pro_plugin ) ) ) { |
| 137 |
$plugins_to_deactivate[] = $pro_plugin; |
| 138 |
$deactivated_plugin = 'Contextual Related Posts Pro'; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
if ( ! empty( $plugins_to_deactivate ) ) { |
| 143 |
deactivate_plugins( $plugins_to_deactivate, false, $network_wide ); |
| 144 |
set_transient( 'crp_deactivated_notice', $deactivated_plugin, 1 * HOUR_IN_SECONDS ); |
| 145 |
} |
| 146 |
} |
| 147 |
add_action( 'activated_plugin', __NAMESPACE__ . '\crp_deactivate_other_instances', 10, 2 ); |
| 148 |
} |
| 149 |
|
| 150 |
// Show admin notice about automatic deactivation. |
| 151 |
if ( ! has_action( 'admin_notices', __NAMESPACE__ . '\crp_show_deactivation_notice' ) ) { |
| 152 |
add_action( |
| 153 |
'admin_notices', |
| 154 |
function () { |
| 155 |
$deactivated_plugin = get_transient( 'crp_deactivated_notice' ); |
| 156 |
if ( $deactivated_plugin ) { |
| 157 |
/* translators: %s: Name of the deactivated plugin */ |
| 158 |
$message = sprintf( __( "Contextual Related Posts and Contextual Related Posts PRO should not be active at the same time. We've automatically deactivated %s.", 'contextual-related-posts' ), $deactivated_plugin ); |
| 159 |
?> |
| 160 |
<div class="updated" style="border-left: 4px solid #ffba00;"> |
| 161 |
<p><?php echo esc_html( $message ); ?></p> |
| 162 |
</div> |
| 163 |
<?php |
| 164 |
delete_transient( 'crp_deactivated_notice' ); |
| 165 |
} |
| 166 |
} |
| 167 |
); |
| 168 |
} |
| 169 |
|
| 170 |
// Load the autoloader. |
| 171 |
if ( ! function_exists( __NAMESPACE__ . '\autoload' ) ) { |
| 172 |
require_once plugin_dir_path( __FILE__ ) . 'includes/autoloader.php'; |
| 173 |
} |
| 174 |
|
| 175 |
// Load Composer dependencies if available. |
| 176 |
$composer_autoload = plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
| 177 |
if ( file_exists( $composer_autoload ) ) { |
| 178 |
require_once $composer_autoload; |
| 179 |
} |
| 180 |
|
| 181 |
if ( ! function_exists( __NAMESPACE__ . '\crp_freemius' ) ) { |
| 182 |
require_once plugin_dir_path( __FILE__ ) . 'load-freemius.php'; |
| 183 |
} |
| 184 |
|
| 185 |
if ( ! function_exists( __NAMESPACE__ . '\wz_crp' ) ) { |
| 186 |
/** |
| 187 |
* Returns the instance of the Contextual Related Posts main class. |
| 188 |
* |
| 189 |
* @since 4.0.0 |
| 190 |
* |
| 191 |
* @return \WebberZone\Contextual_Related_Posts\Main The Contextual Related Posts Main instance. |
| 192 |
*/ |
| 193 |
function wz_crp() { |
| 194 |
return \WebberZone\Contextual_Related_Posts\Main::get_instance(); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
if ( ! function_exists( __NAMESPACE__ . '\load' ) ) { |
| 199 |
/** |
| 200 |
* The main function responsible for returning the one true WebberZone Contextual Related Posts instance to functions everywhere. |
| 201 |
* |
| 202 |
* @since 3.5.0 |
| 203 |
*/ |
| 204 |
function load(): void { |
| 205 |
wz_crp(); |
| 206 |
} |
| 207 |
add_action( 'plugins_loaded', __NAMESPACE__ . '\load' ); |
| 208 |
} |
| 209 |
|
| 210 |
/* |
| 211 |
*---------------------------------------------------------------------------- |
| 212 |
* Include files |
| 213 |
*---------------------------------------------------------------------------- |
| 214 |
*/ |
| 215 |
if ( ! function_exists( 'crp_get_settings' ) ) { |
| 216 |
require_once plugin_dir_path( __FILE__ ) . 'includes/options-api.php'; |
| 217 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-crp-query.php'; |
| 218 |
require_once plugin_dir_path( __FILE__ ) . 'includes/functions.php'; |
| 219 |
} |
| 220 |
|
| 221 |
// Register activation hook. |
| 222 |
register_activation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::activation_hook' ); |
| 223 |
|
| 224 |
// Register deactivation hook. |
| 225 |
register_deactivation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::deactivation_hook' ); |
| 226 |
|
| 227 |
/** |
| 228 |
* Global variable holding the current settings for Contextual Related Posts |
| 229 |
* |
| 230 |
* @since 1.8.10 |
| 231 |
* |
| 232 |
* @var array |
| 233 |
*/ |
| 234 |
global $crp_settings; |
| 235 |
$crp_settings = \crp_get_settings(); |
| 236 |
|