compatibility
2 years ago
controls
2 years ago
pa-display-conditions
2 years ago
templates
2 years ago
acf-helper.php
2 years ago
addons-cross-cp.php
2 years ago
addons-integration.php
2 years ago
assets-manager.php
2 years ago
class-pa-core.php
2 years ago
class-premium-template-tags.php
2 years ago
helper-functions.php
2 years ago
live-editor-modal.php
2 years ago
module-base.php
2 years ago
pa-nav-menu-walker.php
2 years ago
class-pa-core.php
237 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 | // Run plugin and require the necessary files. |
| 36 | add_action( 'plugins_loaded', array( $this, 'premium_addons_elementor_setup' ) ); |
| 37 | |
| 38 | // Load Elementor files. |
| 39 | add_action( 'elementor/init', array( $this, 'elementor_init' ) ); |
| 40 | |
| 41 | add_action( 'elementor/elements/categories_registered', array( $this, 'register_widgets_category' ), 9 ); |
| 42 | add_action( 'init', array( $this, 'init' ), -999 ); |
| 43 | |
| 44 | // Register Activation hooks. |
| 45 | register_activation_hook( PREMIUM_ADDONS_FILE, array( $this, 'set_transient' ) ); |
| 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 | $filename = PREMIUM_ADDONS_PATH . $filename . '.php'; |
| 72 | |
| 73 | if ( is_readable( $filename ) ) { |
| 74 | include $filename; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Installs translation text domain and checks if Elementor is installed |
| 81 | * |
| 82 | * @since 1.0.0 |
| 83 | * @access public |
| 84 | * |
| 85 | * @return void |
| 86 | */ |
| 87 | public function premium_addons_elementor_setup() { |
| 88 | |
| 89 | // Load plugin textdomain. |
| 90 | $this->load_domain(); |
| 91 | |
| 92 | // load plugin necessary files. |
| 93 | $this->load_files(); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Set transient for admin review notice |
| 98 | * |
| 99 | * @since 3.1.7 |
| 100 | * @access public |
| 101 | * |
| 102 | * @return void |
| 103 | */ |
| 104 | public function set_transient() { |
| 105 | |
| 106 | $cache_key = 'premium_notice_' . PREMIUM_ADDONS_VERSION; |
| 107 | |
| 108 | $expiration = 3600 * 72; |
| 109 | |
| 110 | set_transient( $cache_key, true, $expiration ); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /** |
| 115 | * Require initial necessary files |
| 116 | * |
| 117 | * @since 2.6.8 |
| 118 | * @access public |
| 119 | * |
| 120 | * @return void |
| 121 | */ |
| 122 | public function load_files() { |
| 123 | |
| 124 | \PremiumAddons\Admin\Includes\Admin_Helper::get_instance(); |
| 125 | |
| 126 | $enabled_elements = \PremiumAddons\Admin\Includes\Admin_Helper::get_enabled_elements(); |
| 127 | |
| 128 | if ( $enabled_elements['premium-assets-generator'] ) { |
| 129 | \PremiumAddons\Includes\Assets_Manager::get_instance(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Load plugin translated strings using text domain |
| 135 | * |
| 136 | * @since 2.6.8 |
| 137 | * @access public |
| 138 | * |
| 139 | * @return void |
| 140 | */ |
| 141 | public function load_domain() { |
| 142 | |
| 143 | load_plugin_textdomain( 'premium-addons-for-elementor' ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Elementor Init |
| 148 | * |
| 149 | * Initialize plugin after Elementor is run. |
| 150 | * |
| 151 | * @since 2.6.8 |
| 152 | * @access public |
| 153 | * |
| 154 | * @return void |
| 155 | */ |
| 156 | public function elementor_init() { |
| 157 | |
| 158 | require_once PREMIUM_ADDONS_PATH . 'includes/class-premium-template-tags.php'; |
| 159 | |
| 160 | Compatibility\Premium_Addons_Wpml::get_instance(); |
| 161 | |
| 162 | Addons_Integration::get_instance(); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Register Widgets Category |
| 167 | * |
| 168 | * Register a new category for Premium Addons widgets |
| 169 | * |
| 170 | * @since 4.0.0 |
| 171 | * @access public |
| 172 | * |
| 173 | * @param object $elements_manager elements manager. |
| 174 | */ |
| 175 | public function register_widgets_category( $elements_manager ) { |
| 176 | |
| 177 | $elements_manager->add_category( |
| 178 | 'premium-elements', |
| 179 | array( |
| 180 | 'title' => Helper_Functions::get_category(), |
| 181 | ), |
| 182 | 1 |
| 183 | ); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Init |
| 188 | * |
| 189 | * @since 3.4.0 |
| 190 | * @access public |
| 191 | * |
| 192 | * @return void |
| 193 | */ |
| 194 | public function init() { |
| 195 | |
| 196 | if ( \PremiumAddons\Admin\Includes\Admin_Helper::check_premium_templates() ) { |
| 197 | require_once PREMIUM_ADDONS_PATH . 'includes/templates/templates.php'; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | |
| 202 | /** |
| 203 | * Creates and returns an instance of the class |
| 204 | * |
| 205 | * @since 2.6.8 |
| 206 | * @access public |
| 207 | * |
| 208 | * @return object |
| 209 | */ |
| 210 | public static function get_instance() { |
| 211 | |
| 212 | if ( ! isset( self::$instance ) ) { |
| 213 | |
| 214 | self::$instance = new self(); |
| 215 | |
| 216 | } |
| 217 | |
| 218 | return self::$instance; |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | if ( ! function_exists( 'pa_core' ) ) { |
| 224 | |
| 225 | /** |
| 226 | * Returns an instance of the plugin class. |
| 227 | * |
| 228 | * @since 1.0.0 |
| 229 | * @return object |
| 230 | */ |
| 231 | function pa_core() { |
| 232 | return PA_Core::get_instance(); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | pa_core(); |
| 237 |