| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package SheetsPilot |
| 4 |
* @author Unlimited Elements |
| 5 |
* @copyright (C) 2026 Unlimited Elements, All Rights Reserved. |
| 6 |
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
| 7 |
**/ |
| 8 |
|
| 9 |
namespace SheetsPilotUnlimitedElements\Sheetspilot; |
| 10 |
|
| 11 |
/** |
| 12 |
* Load plugin PHP dependencies (core and optional Pro). |
| 13 |
* |
| 14 |
* Declared inside the `Sheetspilot` namespace so WordPress Coding Standards |
| 15 |
* (PrefixAllGlobals) does not treat this as an unprefixed global function. |
| 16 |
* |
| 17 |
* @param string $main_file_path Absolute path to the main plugin file (sheetspilot.php). |
| 18 |
*/ |
| 19 |
function load_plugin( $main_file_path ) { |
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; |
| 22 |
} |
| 23 |
if ( ! defined( 'SHEETSPILOT_INC' ) ) { |
| 24 |
die( 'restricted access' ); |
| 25 |
} |
| 26 |
|
| 27 |
$debugDefined = false; |
| 28 |
|
| 29 |
$current_folder = dirname( $main_file_path ); |
| 30 |
$inc_php_folder = $current_folder . '/inc_php/'; |
| 31 |
$pro_inc_php_folder = $current_folder . '/pro/inc_php/'; |
| 32 |
$has_pro_folder = is_dir( $current_folder . '/pro/' ); |
| 33 |
|
| 34 |
$pro_plugin_file = 'sheetspilot-premium/sheetspilot-pro.php'; |
| 35 |
$active_plugins = get_option( 'active_plugins', array() ); |
| 36 |
$is_pro_plugin_active = in_array( $pro_plugin_file, $active_plugins, true ); |
| 37 |
$is_pro_version_match = true; |
| 38 |
$free_version = ''; |
| 39 |
$pro_version = ''; |
| 40 |
|
| 41 |
if ( false === $is_pro_plugin_active && function_exists( 'is_multisite' ) && is_multisite() ) { |
| 42 |
$network_active_plugins = get_site_option( 'active_sitewide_plugins', array() ); |
| 43 |
$is_pro_plugin_active = isset( $network_active_plugins[ $pro_plugin_file ] ); |
| 44 |
} |
| 45 |
|
| 46 |
if ( $is_pro_plugin_active ) { |
| 47 |
$free_plugin_header = get_file_data( $main_file_path, array( 'Version' => 'Version' ), 'plugin' ); |
| 48 |
$free_version = isset( $free_plugin_header['Version'] ) ? (string) $free_plugin_header['Version'] : ''; |
| 49 |
|
| 50 |
$pro_main_file = SHEETS_WPPLUGIN_DIR . $pro_plugin_file; |
| 51 |
if ( file_exists( $pro_main_file ) ) { |
| 52 |
$pro_plugin_header = get_file_data( $pro_main_file, array( 'Version' => 'Version' ), 'plugin' ); |
| 53 |
$pro_version = isset( $pro_plugin_header['Version'] ) ? (string) $pro_plugin_header['Version'] : ''; |
| 54 |
} |
| 55 |
|
| 56 |
$pro_min_compatible = defined( 'SHEETSPILOT_PRO_VERSION_COMPATABE_FROM' ) |
| 57 |
? (string) SHEETSPILOT_PRO_VERSION_COMPATABE_FROM |
| 58 |
: $free_version; |
| 59 |
|
| 60 |
// Compatible when Pro is between min compatible version and the free plugin version (inclusive). |
| 61 |
$is_pro_version_match = ( |
| 62 |
$free_version !== '' |
| 63 |
&& $pro_version !== '' |
| 64 |
&& version_compare( $pro_version, $pro_min_compatible, '>=' ) |
| 65 |
&& version_compare( $pro_version, $free_version, '<=' ) |
| 66 |
); |
| 67 |
|
| 68 |
$external_pro_plugin_folder = SHEETS_WPPLUGIN_DIR . 'sheetspilot-premium/'; |
| 69 |
$external_pro_inc_php_folder = $external_pro_plugin_folder . 'inc_php/'; |
| 70 |
if ( $is_pro_version_match && is_dir( $external_pro_inc_php_folder ) && file_exists( $external_pro_inc_php_folder . 'request_log.class.php' ) ) { |
| 71 |
$pro_inc_php_folder = $external_pro_inc_php_folder; |
| 72 |
$has_pro_folder = true; |
| 73 |
} else { |
| 74 |
$has_pro_folder = false; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
if ( $debugDefined ) { |
| 79 |
require_once $inc_php_folder . 'functions.php'; |
| 80 |
$debug_sheetspilot_includes = array( |
| 81 |
'main_file_path' => $main_file_path, |
| 82 |
'current_folder' => $current_folder, |
| 83 |
'inc_php_folder' => $inc_php_folder, |
| 84 |
'pro_inc_php_folder' => $pro_inc_php_folder, |
| 85 |
'has_pro_folder' => $has_pro_folder, |
| 86 |
'pro_plugin_file' => $pro_plugin_file, |
| 87 |
'is_pro_plugin_active' => $is_pro_plugin_active, |
| 88 |
'is_pro_version_match' => $is_pro_version_match, |
| 89 |
'free_version' => $free_version, |
| 90 |
'pro_version' => $pro_version, |
| 91 |
'active_plugins (count)' => is_array( $active_plugins ) ? count( $active_plugins ) : 0, |
| 92 |
'active_plugins (has pro file)' => is_array( $active_plugins ) && in_array( $pro_plugin_file, $active_plugins, true ), |
| 93 |
); |
| 94 |
|
| 95 |
dmp($debug_sheetspilot_includes); |
| 96 |
exit(); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
if ( ! defined( 'SHEETSPILOT_HAS_PRO_FOLDER' ) ) { |
| 101 |
define( 'SHEETSPILOT_HAS_PRO_FOLDER', $has_pro_folder ); |
| 102 |
} |
| 103 |
|
| 104 |
if ( ! defined( 'SHEETSPILOT_PRO_PLUGIN_ACTIVE' ) ) { |
| 105 |
define( 'SHEETSPILOT_PRO_PLUGIN_ACTIVE', $is_pro_plugin_active ); |
| 106 |
} |
| 107 |
if ( ! defined( 'SHEETSPILOT_PRO_VERSION_MATCH' ) ) { |
| 108 |
define( 'SHEETSPILOT_PRO_VERSION_MATCH', $is_pro_version_match ); |
| 109 |
} |
| 110 |
if ( ! defined( 'SHEETSPILOT_FREE_VERSION' ) ) { |
| 111 |
define( 'SHEETSPILOT_FREE_VERSION', $free_version ); |
| 112 |
} |
| 113 |
if ( ! defined( 'SHEETSPILOT_PRO_VERSION' ) ) { |
| 114 |
define( 'SHEETSPILOT_PRO_VERSION', $pro_version ); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
require $inc_php_folder . 'globals.class.php'; |
| 120 |
require $inc_php_folder . 'plugins_jetengine_class.php'; |
| 121 |
|
| 122 |
require $inc_php_folder . 'acf_repeater_functionality.php'; |
| 123 |
require $inc_php_folder . 'front_processing_class.php'; |
| 124 |
|
| 125 |
require_once $inc_php_folder . 'functions.php'; |
| 126 |
require $inc_php_folder . 'functions.class.php'; |
| 127 |
require $inc_php_folder . 'functions_wp.class.php'; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
require $inc_php_folder . 'helper.class.php'; |
| 133 |
require $inc_php_folder . 'helper_elementor.class.php'; |
| 134 |
require $inc_php_folder . 'ajax_session_log.class.php'; |
| 135 |
require $inc_php_folder . 'content_blocks.class.php'; |
| 136 |
require $inc_php_folder . 'query_processing.class.php'; |
| 137 |
require $inc_php_folder . 'cell_editor_functionality.class.php'; |
| 138 |
require $inc_php_folder . 'actions.class.php'; |
| 139 |
require $inc_php_folder . 'admin.class.php'; |
| 140 |
require $inc_php_folder . 'provider_db.class.php'; |
| 141 |
require $inc_php_folder . 'db.class.php'; |
| 142 |
require $inc_php_folder . 'image_processing.class.php'; |
| 143 |
|
| 144 |
if ( $has_pro_folder ) { |
| 145 |
require $pro_inc_php_folder . 'openai.responseapi.class.php'; |
| 146 |
|
| 147 |
|
| 148 |
require $pro_inc_php_folder . 'request_log.class.php'; |
| 149 |
require $pro_inc_php_folder . 'libs/openai/vendor/autoload.php'; |
| 150 |
|
| 151 |
|
| 152 |
require $pro_inc_php_folder . 'useChatGPT.class.php'; |
| 153 |
|
| 154 |
require $pro_inc_php_folder . 'prompt_history.class.php'; |
| 155 |
require $pro_inc_php_folder . 'general_settings.class.php'; |
| 156 |
require $pro_inc_php_folder . 'settings.class.php'; |
| 157 |
require $pro_inc_php_folder . 'settings_output.class.php'; |
| 158 |
require $pro_inc_php_folder . 'settings_output_wide.class.php'; |
| 159 |
require $pro_inc_php_folder . 'prompts.class.php'; |
| 160 |
require $pro_inc_php_folder . 'prompts_ui.class.php'; |
| 161 |
require $pro_inc_php_folder . 'php_error_trace.class.php'; |
| 162 |
} |
| 163 |
} |
| 164 |
|