compatibility
4 years ago
controls
4 years ago
pa-display-conditions
4 years ago
templates
4 years ago
acf-helper.php
4 years ago
addons-cross-cp.php
4 years ago
addons-integration.php
4 years ago
class-pa-core.php
4 years ago
class-premium-template-tags.php
4 years ago
helper-functions.php
4 years ago
lang-locale.php
4 years ago
module-base.php
4 years ago
class-pa-core.php
249 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 | /** |
| 50 | * AutoLoad |
| 51 | * |
| 52 | * @since 3.20.9 |
| 53 | * @param string $class class. |
| 54 | */ |
| 55 | public function autoload( $class ) { |
| 56 | |
| 57 | if ( 0 !== strpos( $class, 'PremiumAddons' ) ) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | $class_to_load = $class; |
| 62 | |
| 63 | if ( ! class_exists( $class_to_load ) ) { |
| 64 | $filename = strtolower( |
| 65 | preg_replace( |
| 66 | array( '/^PremiumAddons\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ), |
| 67 | array( '', '$1-$2', '-', DIRECTORY_SEPARATOR ), |
| 68 | $class_to_load |
| 69 | ) |
| 70 | ); |
| 71 | |
| 72 | $filename = PREMIUM_ADDONS_PATH . $filename . '.php'; |
| 73 | |
| 74 | if ( is_readable( $filename ) ) { |
| 75 | include $filename; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Installs translation text domain and checks if Elementor is installed |
| 82 | * |
| 83 | * @since 1.0.0 |
| 84 | * @access public |
| 85 | * |
| 86 | * @return void |
| 87 | */ |
| 88 | public function premium_addons_elementor_setup() { |
| 89 | |
| 90 | // Load plugin textdomain. |
| 91 | $this->load_domain(); |
| 92 | |
| 93 | // load plugin necessary files. |
| 94 | $this->load_files(); |
| 95 | |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Set transient for admin review notice |
| 100 | * |
| 101 | * @since 3.1.7 |
| 102 | * @access public |
| 103 | * |
| 104 | * @return void |
| 105 | */ |
| 106 | public function set_transient() { |
| 107 | |
| 108 | $cache_key = 'premium_notice_' . PREMIUM_ADDONS_VERSION; |
| 109 | |
| 110 | $expiration = 3600 * 72; |
| 111 | |
| 112 | set_transient( $cache_key, true, $expiration ); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | /** |
| 117 | * Require initial necessary files |
| 118 | * |
| 119 | * @since 2.6.8 |
| 120 | * @access public |
| 121 | * |
| 122 | * @return void |
| 123 | */ |
| 124 | public function load_files() { |
| 125 | |
| 126 | \PremiumAddons\Admin\Includes\Admin_Helper::get_instance(); |
| 127 | |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Load plugin translated strings using text domain |
| 132 | * |
| 133 | * @since 2.6.8 |
| 134 | * @access public |
| 135 | * |
| 136 | * @return void |
| 137 | */ |
| 138 | public function load_domain() { |
| 139 | |
| 140 | load_plugin_textdomain( 'premium-addons-for-elementor' ); |
| 141 | |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Elementor Init |
| 146 | * |
| 147 | * Initialize plugin after Elementor is run. |
| 148 | * |
| 149 | * @since 2.6.8 |
| 150 | * @access public |
| 151 | * |
| 152 | * @return void |
| 153 | */ |
| 154 | public function elementor_init() { |
| 155 | |
| 156 | require_once PREMIUM_ADDONS_PATH . 'includes/class-premium-template-tags.php'; |
| 157 | |
| 158 | Compatibility\Premium_Addons_Wpml::get_instance(); |
| 159 | |
| 160 | Addons_Integration::get_instance(); |
| 161 | |
| 162 | if ( version_compare( ELEMENTOR_VERSION, '2.0.0' ) < 0 ) { |
| 163 | |
| 164 | \Elementor\Plugin::instance()->elements_manager->add_category( |
| 165 | 'premium-elements', |
| 166 | array( |
| 167 | 'title' => Helper_Functions::get_category(), |
| 168 | ), |
| 169 | 1 |
| 170 | ); |
| 171 | } |
| 172 | |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Register Widgets Category |
| 177 | * |
| 178 | * Register a new category for Premium Addons widgets |
| 179 | * |
| 180 | * @since 4.0.0 |
| 181 | * @access public |
| 182 | * |
| 183 | * @param object $elements_manager elements manager. |
| 184 | */ |
| 185 | public function register_widgets_category( $elements_manager ) { |
| 186 | |
| 187 | $elements_manager->add_category( |
| 188 | 'premium-elements', |
| 189 | array( |
| 190 | 'title' => Helper_Functions::get_category(), |
| 191 | ), |
| 192 | 1 |
| 193 | ); |
| 194 | |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Init |
| 199 | * |
| 200 | * @since 3.4.0 |
| 201 | * @access public |
| 202 | * |
| 203 | * @return void |
| 204 | */ |
| 205 | public function init() { |
| 206 | |
| 207 | if ( \PremiumAddons\Admin\Includes\Admin_Helper::check_premium_templates() ) { |
| 208 | require_once PREMIUM_ADDONS_PATH . 'includes/templates/templates.php'; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /** |
| 214 | * Creates and returns an instance of the class |
| 215 | * |
| 216 | * @since 2.6.8 |
| 217 | * @access public |
| 218 | * |
| 219 | * @return object |
| 220 | */ |
| 221 | public static function get_instance() { |
| 222 | |
| 223 | if ( ! isset( self::$instance ) ) { |
| 224 | |
| 225 | self::$instance = new self(); |
| 226 | |
| 227 | } |
| 228 | |
| 229 | return self::$instance; |
| 230 | } |
| 231 | |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | if ( ! function_exists( 'pa_core' ) ) { |
| 236 | |
| 237 | /** |
| 238 | * Returns an instance of the plugin class. |
| 239 | * |
| 240 | * @since 1.0.0 |
| 241 | * @return object |
| 242 | */ |
| 243 | function pa_core() { |
| 244 | return PA_Core::get_instance(); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | pa_core(); |
| 249 |