| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: ThirstyAffiliates |
| 4 |
* Plugin URI: http://thirstyaffiliates.com/ |
| 5 |
* Description: ThirstyAffiliates is a revolution in affiliate link management. Collect, collate and store your affiliate links for use in your posts and pages. |
| 6 |
* Version: 3.8 |
| 7 |
* Author: Rymera Web Co |
| 8 |
* Author URI: https://rymera.com.au/ |
| 9 |
* Requires at least: 4.5 |
| 10 |
* Tested up to: 5.1.1 |
| 11 |
* |
| 12 |
* Text Domain: thirstyaffiliates |
| 13 |
* Domain Path: /languages/ |
| 14 |
* |
| 15 |
* @package ThirstyAffiliates |
| 16 |
* @category Core |
| 17 |
* @author Rymera Web Co |
| 18 |
*/ |
| 19 |
|
| 20 |
if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 21 |
|
| 22 |
use ThirstyAffiliates\Abstracts\Abstract_Main_Plugin_Class; |
| 23 |
|
| 24 |
use ThirstyAffiliates\Interfaces\Model_Interface; |
| 25 |
|
| 26 |
use ThirstyAffiliates\Helpers\Plugin_Constants; |
| 27 |
use ThirstyAffiliates\Helpers\Helper_Functions; |
| 28 |
|
| 29 |
use ThirstyAffiliates\Models\Bootstrap; |
| 30 |
use ThirstyAffiliates\Models\Migration; |
| 31 |
use ThirstyAffiliates\Models\Marketing; |
| 32 |
use ThirstyAffiliates\Models\Script_Loader; |
| 33 |
use ThirstyAffiliates\Models\Settings; |
| 34 |
use ThirstyAffiliates\Models\Stats_Reporting; |
| 35 |
use ThirstyAffiliates\Models\Affiliate_Links_CPT; |
| 36 |
use ThirstyAffiliates\Models\Affiliate_Link; |
| 37 |
use ThirstyAffiliates\Models\Affiliate_Link_Attachment; |
| 38 |
use ThirstyAffiliates\Models\Link_Fixer; |
| 39 |
use ThirstyAffiliates\Models\Rewrites_Redirection; |
| 40 |
use ThirstyAffiliates\Models\Link_Picker; |
| 41 |
use ThirstyAffiliates\Models\Shortcodes; |
| 42 |
use ThirstyAffiliates\Models\Guided_Tour; |
| 43 |
use ThirstyAffiliates\Models\REST_API; |
| 44 |
|
| 45 |
/** |
| 46 |
* Register plugin autoloader. |
| 47 |
* |
| 48 |
* @since 3.0.0 |
| 49 |
* |
| 50 |
* @param string $class_name Name of the class to load. |
| 51 |
*/ |
| 52 |
spl_autoload_register( function( $class_name ) { |
| 53 |
|
| 54 |
if ( strpos( $class_name , 'ThirstyAffiliates\\' ) === 0 ) { // Only do autoload for our plugin files |
| 55 |
|
| 56 |
$class_file = str_replace( array( '\\' , 'ThirstyAffiliates' . DIRECTORY_SEPARATOR ) , array( DIRECTORY_SEPARATOR , '' ) , $class_name ) . '.php'; |
| 57 |
|
| 58 |
require_once plugin_dir_path( __FILE__ ) . $class_file; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
} ); |
| 63 |
|
| 64 |
/** |
| 65 |
* The main plugin class. |
| 66 |
*/ |
| 67 |
class ThirstyAffiliates extends Abstract_Main_Plugin_Class { |
| 68 |
|
| 69 |
/* |
| 70 |
|-------------------------------------------------------------------------- |
| 71 |
| Class Properties |
| 72 |
|-------------------------------------------------------------------------- |
| 73 |
*/ |
| 74 |
|
| 75 |
/** |
| 76 |
* Single main instance of Plugin ThirstyAffiliates plugin. |
| 77 |
* |
| 78 |
* @since 3.0.0 |
| 79 |
* @access private |
| 80 |
* @var ThirstyAffiliates |
| 81 |
*/ |
| 82 |
private static $_instance; |
| 83 |
|
| 84 |
/** |
| 85 |
* Array of missing external plugins that this plugin is depends on. |
| 86 |
* |
| 87 |
* @since 3.0.0 |
| 88 |
* @access private |
| 89 |
* @var array |
| 90 |
*/ |
| 91 |
private $_failed_dependencies; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
/* |
| 97 |
|-------------------------------------------------------------------------- |
| 98 |
| Class Methods |
| 99 |
|-------------------------------------------------------------------------- |
| 100 |
*/ |
| 101 |
|
| 102 |
/** |
| 103 |
* ThirstyAffiliates constructor. |
| 104 |
* |
| 105 |
* @since 3.0.0 |
| 106 |
* @since 3.0.0 Added the admin_notices when the free plugins was activated 48 hours ago and the Pro version has not been installed |
| 107 |
* @access public |
| 108 |
*/ |
| 109 |
public function __construct() { |
| 110 |
|
| 111 |
register_deactivation_hook( __FILE__ , array( $this , 'general_deactivation_code' ) ); |
| 112 |
|
| 113 |
if ( $this->_check_plugin_dependencies() !== true ) { |
| 114 |
|
| 115 |
// Display notice that plugin dependency is not present. |
| 116 |
add_action( 'admin_notices' , array( $this , 'missing_plugin_dependencies_notice' ) ); |
| 117 |
|
| 118 |
} elseif ( $this->_check_plugin_dependency_version_requirements() !== true ) { |
| 119 |
|
| 120 |
// Display notice that some dependent plugin did not meet the required version. |
| 121 |
add_action( 'admin_notices' , array( $this , 'invalid_plugin_dependency_version_notice' ) ); |
| 122 |
|
| 123 |
} else { |
| 124 |
|
| 125 |
// Lock 'n Load |
| 126 |
$this->_initialize_plugin_components(); |
| 127 |
$this->_run_plugin(); |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Ensure that only one instance of Plugin Boilerplate is loaded or can be loaded (Singleton Pattern). |
| 135 |
* |
| 136 |
* @since 3.0.0 |
| 137 |
* @access public |
| 138 |
* |
| 139 |
* @return ThirstyAffiliates |
| 140 |
*/ |
| 141 |
public static function get_instance() { |
| 142 |
|
| 143 |
if ( !self::$_instance instanceof self ) |
| 144 |
self::$_instance = new self(); |
| 145 |
|
| 146 |
return self::$_instance; |
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Check for external plugin dependencies. |
| 152 |
* |
| 153 |
* @since 3.0.0 |
| 154 |
* @access private |
| 155 |
* |
| 156 |
* @return mixed Array if there are missing plugin dependencies, True if all plugin dependencies are present. |
| 157 |
*/ |
| 158 |
private function _check_plugin_dependencies() { |
| 159 |
|
| 160 |
// Makes sure the plugin is defined before trying to use it |
| 161 |
if ( !function_exists( 'is_plugin_active' ) ) |
| 162 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 163 |
|
| 164 |
$this->failed_dependencies = array(); |
| 165 |
|
| 166 |
|
| 167 |
// Sample below |
| 168 |
/* |
| 169 |
if ( !is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 170 |
|
| 171 |
$this->failed_dependencies[] = array( |
| 172 |
'plugin-key' => 'woocommerce', |
| 173 |
'plugin-name' => 'WooCommerce', // We don't translate this coz this is the plugin name |
| 174 |
'plugin-base-name' => 'woocommerce/woocommerce.php' |
| 175 |
); |
| 176 |
|
| 177 |
} |
| 178 |
*/ |
| 179 |
|
| 180 |
return !empty( $this->failed_dependencies ) ? $this->failed_dependencies : true; |
| 181 |
|
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Check plugin dependency version requirements. |
| 186 |
* |
| 187 |
* @since 3.0.0 |
| 188 |
* @access private |
| 189 |
* |
| 190 |
* @return boolean True if plugin dependency version requirement is meet, False otherwise. |
| 191 |
*/ |
| 192 |
private function _check_plugin_dependency_version_requirements() { |
| 193 |
|
| 194 |
// Sample below |
| 195 |
/* |
| 196 |
$teo_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/timed-email-offers/timed-email-offers.php' ); |
| 197 |
|
| 198 |
// TEOP 3.0.0 requires TEO 1.1.0 |
| 199 |
return version_compare( $teo_plugin_data[ 'Version' ] , '1.1.0' , ">=" ); |
| 200 |
*/ |
| 201 |
|
| 202 |
return true; |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Add notice to notify users that some plugin dependencies of this plugin is missing. |
| 208 |
* |
| 209 |
* @since 3.0.0 |
| 210 |
* @access public |
| 211 |
*/ |
| 212 |
public function missing_plugin_dependencies_notice() { |
| 213 |
|
| 214 |
if ( !empty( $this->failed_dependencies ) ) { |
| 215 |
|
| 216 |
$admin_notice_msg = ''; |
| 217 |
|
| 218 |
foreach ( $this->failed_dependencies as $failed_dependency ) { |
| 219 |
|
| 220 |
$failed_dep_plugin_file = trailingslashit( WP_PLUGIN_DIR ) . plugin_basename( $failed_dependency[ 'plugin-base-name' ] ); |
| 221 |
|
| 222 |
if ( file_exists( $failed_dep_plugin_file ) ) |
| 223 |
$failed_dep_install_text = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&plugin=' . $failed_dependency[ 'plugin-base-name' ] . '&plugin_status=all&s' , 'activate-plugin_' . $failed_dependency[ 'plugin-base-name' ] ) . '" title="' . __( 'Activate this plugin' , 'thirstyaffiliates' ) . '" class="edit">' . __( 'Click here to activate →' , 'thirstyaffiliates' ) . '</a>'; |
| 224 |
else |
| 225 |
$failed_dep_install_text = '<a href="' . wp_nonce_url( 'update.php?action=install-plugin&plugin=' . $failed_dependency[ 'plugin-key' ] , 'install-plugin_' . $failed_dependency[ 'plugin-key' ] ) . '" title="' . __( 'Install this plugin' , 'thirstyaffiliates' ) . '">' . __( 'Click here to install from WordPress.org repo →' , 'thirstyaffiliates' ) . '</a>'; |
| 226 |
|
| 227 |
$admin_notice_msg .= sprintf( __( '<br/>Please ensure you have the <a href="%1$s" target="_blank">%2$s</a> plugin installed and activated.<br/>' , 'thirstyaffiliates' ) , 'http://wordpress.org/plugins/' . $failed_dependency[ 'plugin-key' ] . '/' , $failed_dependency[ 'plugin-name' ] ); |
| 228 |
$admin_notice_msg .= $failed_dep_install_text . '<br/>'; |
| 229 |
|
| 230 |
} ?> |
| 231 |
|
| 232 |
<div class="error"> |
| 233 |
<p> |
| 234 |
<?php _e( '<b>ThirstyAffiliates</b> plugin missing dependency.<br/>' , 'thirstyaffiliates' ); ?> |
| 235 |
<?php echo $admin_notice_msg; ?> |
| 236 |
</p> |
| 237 |
</div> |
| 238 |
|
| 239 |
<?php } |
| 240 |
|
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* Add notice to notify user that some plugin dependencies did not meet the required version for the current version of this plugin. |
| 245 |
* |
| 246 |
* @since 3.0.0 |
| 247 |
* @access public |
| 248 |
*/ |
| 249 |
public function invalid_plugin_dependency_version_notice() { |
| 250 |
|
| 251 |
// Sample below |
| 252 |
/* |
| 253 |
$update_text = sprintf( __( '<a href="%1$s">Click here to update Timed Email Offers →</a>' , 'timed-email-offers-premium' ) , wp_nonce_url( 'update.php?action=upgrade-plugin&plugin=timed-email-offers' , 'upgrade-plugin_timed-email-offers' ) ); ?> |
| 254 |
|
| 255 |
<div class="error"> |
| 256 |
<p><?php echo sprintf( __( 'Please ensure you have the latest version of <a href="%1$s" target="_blank">Timed Email Offers</a> plugin installed and activated.' , 'timed-email-offers-premium' ) , 'http://wordpress.org/plugins/timed-email-offers/' ); ?></p> |
| 257 |
<p><?php echo $update_text; ?></p> |
| 258 |
</div> |
| 259 |
|
| 260 |
<?php |
| 261 |
*/ |
| 262 |
|
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* Function that get's executed always whether dependecy are present/valid or not. |
| 267 |
* |
| 268 |
* @since 3.0.0 |
| 269 |
* @access public |
| 270 |
* |
| 271 |
* @global wpdb $wpdb Object that contains a set of functions used to interact with a database. |
| 272 |
* |
| 273 |
* @param boolean $network_wide Flag that determines whether the plugin has been activated network wid ( on multi site environment ) or not. |
| 274 |
*/ |
| 275 |
public function general_deactivation_code( $network_wide ) { |
| 276 |
|
| 277 |
// Delete the flag that determines if plugin activation code is triggered |
| 278 |
global $wpdb; |
| 279 |
|
| 280 |
// check if it is a multisite network |
| 281 |
if ( is_multisite() ) { |
| 282 |
|
| 283 |
// check if the plugin has been activated on the network or on a single site |
| 284 |
if ( $network_wide ) { |
| 285 |
|
| 286 |
// get ids of all sites |
| 287 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 288 |
|
| 289 |
foreach ( $blog_ids as $blog_id ) { |
| 290 |
|
| 291 |
switch_to_blog( $blog_id ); |
| 292 |
delete_option( 'ta_activation_code_triggered' ); |
| 293 |
|
| 294 |
} |
| 295 |
|
| 296 |
restore_current_blog(); |
| 297 |
|
| 298 |
} else |
| 299 |
delete_option( 'ta_activation_code_triggered' ); // activated on a single site, in a multi-site |
| 300 |
|
| 301 |
} else |
| 302 |
delete_option( 'ta_activation_code_triggered' ); // activated on a single site |
| 303 |
|
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* Initialize plugin components. |
| 308 |
* |
| 309 |
* @since 3.0.0 |
| 310 |
* @access private |
| 311 |
*/ |
| 312 |
private function _initialize_plugin_components() { |
| 313 |
|
| 314 |
$plugin_constants = Plugin_Constants::get_instance( $this ); |
| 315 |
$helper_functions = Helper_Functions::get_instance( $this , $plugin_constants ); |
| 316 |
|
| 317 |
$settings = Settings::get_instance( $this , $plugin_constants , $helper_functions ); |
| 318 |
$migration = Migration::get_instance( $this , $plugin_constants , $helper_functions ); |
| 319 |
$marketing = Marketing::get_instance( $this , $plugin_constants , $helper_functions ); |
| 320 |
$guided_tour = Guided_Tour::get_instance( $this , $plugin_constants , $helper_functions ); |
| 321 |
$stats = Stats_Reporting::get_instance( $this , $plugin_constants , $helper_functions ); |
| 322 |
$rest_api = REST_API::get_instance( $this , $plugin_constants , $helper_functions ); |
| 323 |
$rewrites = Rewrites_Redirection::get_instance( $this , $plugin_constants , $helper_functions ); |
| 324 |
$link_picker = Link_Picker::get_instance( $this , $plugin_constants , $helper_functions ); |
| 325 |
|
| 326 |
$activatables = array( $settings , $stats , $migration , $marketing , $guided_tour ); |
| 327 |
$deactivatables = array( $rewrites ); |
| 328 |
|
| 329 |
$initiables = array( |
| 330 |
$settings, |
| 331 |
Affiliate_Links_CPT::get_instance( $this , $plugin_constants , $helper_functions ), |
| 332 |
Affiliate_Link_Attachment::get_instance( $this , $plugin_constants , $helper_functions ), |
| 333 |
Link_Fixer::get_instance( $this , $plugin_constants , $helper_functions ), |
| 334 |
$link_picker, |
| 335 |
$stats, |
| 336 |
$migration, |
| 337 |
$marketing, |
| 338 |
$guided_tour, |
| 339 |
$rest_api |
| 340 |
); |
| 341 |
|
| 342 |
Bootstrap::get_instance( $this , $plugin_constants , $helper_functions , $activatables , $initiables , $deactivatables ); |
| 343 |
Script_Loader::get_instance( $this , $plugin_constants , $helper_functions , $guided_tour ); |
| 344 |
|
| 345 |
Shortcodes::get_instance( $this , $plugin_constants , $helper_functions ); |
| 346 |
|
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* Run the plugin. ( Runs the various plugin components ). |
| 351 |
* |
| 352 |
* @since 3.0.0 |
| 353 |
* @access private |
| 354 |
*/ |
| 355 |
private function _run_plugin() { |
| 356 |
|
| 357 |
foreach ( $this->__all_models as $model ) |
| 358 |
if ( $model instanceof Model_Interface ) |
| 359 |
$model->run(); |
| 360 |
|
| 361 |
} |
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
/** |
| 366 |
* Returns the main instance of ThirstyAffiliates to prevent the need to use globals. |
| 367 |
* |
| 368 |
* @since 3.0.0 |
| 369 |
* @return ThirstyAffiliates Main instance of the plugin. |
| 370 |
*/ |
| 371 |
function ThirstyAffiliates() { |
| 372 |
|
| 373 |
return ThirstyAffiliates::get_instance(); |
| 374 |
|
| 375 |
} |
| 376 |
|
| 377 |
// Let's Roll! |
| 378 |
$GLOBALS[ 'thirstyaffiliates' ] = ThirstyAffiliates(); |
| 379 |
|