controls
9 months ago
pa-display-conditions
9 months ago
templates
9 months ago
acf-helper.php
9 months ago
addons-cross-cp.php
9 months ago
addons-integration.php
9 months ago
assets-manager.php
9 months ago
class-pa-core.php
9 months ago
class-premium-template-tags.php
9 months ago
helper-functions.php
9 months ago
live-editor-modal.php
9 months ago
module-base.php
9 months ago
pa-nav-menu-walker.php
9 months ago
papro-promotion.php
9 months ago
class-pa-core.php
245 lines
| 1 | <?php |
| 2 | /** |
| 3 | * PA Core. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Includes; |
| 7 | |
| 8 | if ( ! class_exists( 'PA_Core' ) ) { |
| 9 | |
| 10 | /** |
| 11 | * Intialize and Sets up the plugin |
| 12 | */ |
| 13 | class PA_Core { |
| 14 | |
| 15 | /** |
| 16 | * Member Variable |
| 17 | * |
| 18 | * @var instance |
| 19 | */ |
| 20 | private static $instance = null; |
| 21 | |
| 22 | /** |
| 23 | * Sets up needed actions/filters for the plug-in to initialize. |
| 24 | * |
| 25 | * @since 1.0.0 |
| 26 | * @access public |
| 27 | * |
| 28 | * @return void |
| 29 | */ |
| 30 | public function __construct() { |
| 31 | |
| 32 | // Autoloader. |
| 33 | spl_autoload_register( array( $this, 'autoload' ) ); |
| 34 | |
| 35 | // Load plugin textdomain. |
| 36 | add_action( 'init', array( $this, 'i18n' ) ); |
| 37 | |
| 38 | // Run plugin and require the necessary files. |
| 39 | add_action( 'plugins_loaded', array( $this, 'pa_init' ) ); |
| 40 | |
| 41 | add_action( 'init', array( $this, 'init' ), -999 ); |
| 42 | |
| 43 | // Register Activation hooks. |
| 44 | register_activation_hook( PREMIUM_ADDONS_FILE, array( $this, 'handle_activation' ) ); |
| 45 | register_uninstall_hook( PREMIUM_ADDONS_FILE, array( __CLASS__, 'uninstall' ) ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * AutoLoad |
| 50 | * |
| 51 | * @since 3.20.9 |
| 52 | * @param string $class class. |
| 53 | */ |
| 54 | public function autoload( $class ) { |
| 55 | |
| 56 | if ( 0 !== strpos( $class, 'PremiumAddons' ) ) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | $class_to_load = $class; |
| 61 | |
| 62 | if ( ! class_exists( $class_to_load ) ) { |
| 63 | $filename = strtolower( |
| 64 | preg_replace( |
| 65 | array( '/^PremiumAddons\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ), |
| 66 | array( '', '$1-$2', '-', DIRECTORY_SEPARATOR ), |
| 67 | $class_to_load |
| 68 | ) |
| 69 | ); |
| 70 | |
| 71 | if ( strpos( $filename, 'premium-template-tags' ) ) { |
| 72 | $filename = 'includes' . DIRECTORY_SEPARATOR . 'class-premium-template-tags'; |
| 73 | } |
| 74 | |
| 75 | $filename = PREMIUM_ADDONS_PATH . $filename . '.php'; |
| 76 | |
| 77 | if ( is_readable( $filename ) ) { |
| 78 | include $filename; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Installs translation text domain and checks if Elementor is installed |
| 85 | * |
| 86 | * @since 1.0.0 |
| 87 | * @access public |
| 88 | * |
| 89 | * @return void |
| 90 | */ |
| 91 | public function pa_init() { |
| 92 | |
| 93 | // Load plugin necessary files. |
| 94 | \PremiumAddons\Admin\Includes\Admin_Helper::get_instance(); |
| 95 | |
| 96 | $check_dynamic_assets = \PremiumAddons\Admin\Includes\Admin_Helper::check_element_by_key( 'premium-assets-generator' ); |
| 97 | |
| 98 | if ( $check_dynamic_assets ) { |
| 99 | \PremiumAddons\Includes\Assets_Manager::get_instance(); |
| 100 | } |
| 101 | |
| 102 | Addons_Integration::get_instance(); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Set transient for admin review notice |
| 107 | * |
| 108 | * @since 3.1.7 |
| 109 | * @access public |
| 110 | * |
| 111 | * @return void |
| 112 | */ |
| 113 | public function handle_activation() { |
| 114 | |
| 115 | $cache_key = 'pa_review_notice'; |
| 116 | |
| 117 | $expiration = DAY_IN_SECONDS * 7; |
| 118 | |
| 119 | set_transient( $cache_key, true, $expiration ); |
| 120 | |
| 121 | $install_time = get_option( 'pa_install_time' ); |
| 122 | |
| 123 | if ( ! $install_time ) { |
| 124 | |
| 125 | $current_time = gmdate( 'j F, Y', time() ); |
| 126 | |
| 127 | update_option( 'pa_complete_wizard', true ); |
| 128 | update_option( 'pa_install_time', $current_time ); |
| 129 | |
| 130 | $api_url = 'https://feedbackpa.leap13.com/wp-json/install/v2/add'; |
| 131 | |
| 132 | $response = wp_safe_remote_request( |
| 133 | $api_url, |
| 134 | array( |
| 135 | 'headers' => array( |
| 136 | 'Content-Type' => 'application/json', |
| 137 | ), |
| 138 | 'body' => wp_json_encode( |
| 139 | array( |
| 140 | 'time' => $current_time, |
| 141 | ) |
| 142 | ), |
| 143 | 'timeout' => 20, |
| 144 | 'method' => 'POST', |
| 145 | 'httpversion' => '1.1', |
| 146 | ) |
| 147 | ); |
| 148 | |
| 149 | set_transient( 'pa_activation_redirect', true, 30 ); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | public static function uninstall() { |
| 154 | |
| 155 | delete_option( 'pa_complete_wizard' ); |
| 156 | delete_option( 'pa_install_time' ); |
| 157 | delete_option( 'pa_review_notice' ); |
| 158 | |
| 159 | $api_url = 'https://feedbackpa.leap13.com/wp-json/uninstall/v2/add'; |
| 160 | |
| 161 | $current_time = gmdate( 'j F, Y', time() ); |
| 162 | |
| 163 | $response = wp_safe_remote_request( |
| 164 | $api_url, |
| 165 | array( |
| 166 | 'headers' => array( |
| 167 | 'Content-Type' => 'application/json', |
| 168 | ), |
| 169 | 'body' => wp_json_encode( |
| 170 | array( |
| 171 | 'time' => $current_time, |
| 172 | ) |
| 173 | ), |
| 174 | 'timeout' => 20, |
| 175 | 'method' => 'POST', |
| 176 | 'httpversion' => '1.1', |
| 177 | ) |
| 178 | ); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Load plugin translated strings using text domain |
| 183 | * |
| 184 | * @since 2.6.8 |
| 185 | * @access public |
| 186 | * |
| 187 | * @return void |
| 188 | */ |
| 189 | public function i18n() { |
| 190 | |
| 191 | load_plugin_textdomain( 'premium-addons-for-elementor' ); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Init |
| 196 | * |
| 197 | * @since 3.4.0 |
| 198 | * @access public |
| 199 | * |
| 200 | * @return void |
| 201 | */ |
| 202 | public function init() { |
| 203 | |
| 204 | if ( is_user_logged_in() && \PremiumAddons\Admin\Includes\Admin_Helper::check_premium_templates() ) { |
| 205 | require_once PREMIUM_ADDONS_PATH . 'includes/templates/templates.php'; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | |
| 210 | /** |
| 211 | * Creates and returns an instance of the class |
| 212 | * |
| 213 | * @since 2.6.8 |
| 214 | * @access public |
| 215 | * |
| 216 | * @return object |
| 217 | */ |
| 218 | public static function get_instance() { |
| 219 | |
| 220 | if ( ! isset( self::$instance ) ) { |
| 221 | |
| 222 | self::$instance = new self(); |
| 223 | |
| 224 | } |
| 225 | |
| 226 | return self::$instance; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if ( ! function_exists( 'pa_core' ) ) { |
| 232 | |
| 233 | /** |
| 234 | * Returns an instance of the plugin class. |
| 235 | * |
| 236 | * @since 1.0.0 |
| 237 | * @return object |
| 238 | */ |
| 239 | function pa_core() { |
| 240 | return PA_Core::get_instance(); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | pa_core(); |
| 245 |