| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die('No direct access.'); |
| 4 |
|
| 5 |
if (!defined('UPDRAFTCENTRAL_SET_TIME_LIMIT')) define('UPDRAFTCENTRAL_SET_TIME_LIMIT', 900); |
| 6 |
|
| 7 |
// We bypass the class declaration if the class already existed. This usually happens if two or more |
| 8 |
// plugins integrated the same `UpdraftCentral` client folder. |
| 9 |
if (!class_exists('UpdraftCentral_Factory')) : |
| 10 |
|
| 11 |
/** |
| 12 |
* Returns an instance of the host plugin class where the UpdraftCentral "central" folder is being |
| 13 |
* integrated. |
| 14 |
*/ |
| 15 |
class UpdraftCentral_Factory { |
| 16 |
|
| 17 |
/** |
| 18 |
* Creates a host plugin instance |
| 19 |
* |
| 20 |
* @return object|null |
| 21 |
*/ |
| 22 |
public static function create_host() { |
| 23 |
|
| 24 |
// All other plugins that wish to integrate the "central" libraries into their |
| 25 |
// codebase must use this filter (see WP-Optimize plugin as an example). |
| 26 |
$hosts = apply_filters('updraftcentral_host_plugins', array()); |
| 27 |
|
| 28 |
// If $hosts is empty then we return null |
| 29 |
if (empty($hosts)) return null; |
| 30 |
|
| 31 |
// N.B. If multiple host plugins (e.g. updraftplus, wp-optimize, etc.) are currently |
| 32 |
// active then we only select one to handle all incoming UpdraftCentral requests for |
| 33 |
// this website in order to avoid conflicts and confusion especially when tracing or |
| 34 |
// debugging issues. |
| 35 |
// |
| 36 |
// You will know which plugin is currently serving and handling the request by checking |
| 37 |
// the "get_plugin_name" method of the global variable "$updraftcentral_host_plugin" |
| 38 |
// (e.g. $updraftcentral_host_plugin->get_plugin_name()) |
| 39 |
// |
| 40 |
// N.B. You can add additional host plugins here. Just make sure that you will create |
| 41 |
// a host class for that particular plugin (see central/wp-optimize.php as an example). |
| 42 |
$mapped_classes = array( |
| 43 |
'updraftplus' => 'UpdraftPlus_Host', |
| 44 |
'wp-optimize' => 'WP_Optimize_Host', |
| 45 |
); |
| 46 |
|
| 47 |
$path = $host_class = ''; |
| 48 |
foreach ($hosts as $plugin) { |
| 49 |
// Make sure that we have a registered host class with a valid file that exist |
| 50 |
$host_file = dirname(__FILE__).'/'.$plugin.'.php'; |
| 51 |
if (isset($mapped_classes[$plugin]) && file_exists($host_file)) { |
| 52 |
$path = $host_file; |
| 53 |
$host_class = $mapped_classes[$plugin]; |
| 54 |
break; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
// The host file was not found under this plugin thus, we let the other plugins |
| 59 |
// create or build the host plugin (global) variable instead. |
| 60 |
if (empty($path)) return null; |
| 61 |
|
| 62 |
if (!class_exists($host_class)) include_once($path); |
| 63 |
|
| 64 |
// Re-check host class once again just to make sure that we have the desired |
| 65 |
// class loaded before calling its instance method |
| 66 |
if (class_exists($host_class)) { |
| 67 |
return call_user_func(array($host_class, 'instance')); |
| 68 |
} |
| 69 |
|
| 70 |
return null; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
endif; |
| 75 |
|
| 76 |
global $updraftcentral_host_plugin; |
| 77 |
$updraftcentral_host_plugin = UpdraftCentral_Factory::create_host(); |
| 78 |
|
| 79 |
if ($updraftcentral_host_plugin) { |
| 80 |
$updraftcentral_host_plugin->load_updraftcentral(); |
| 81 |
} |
| 82 |
|