royal-elementor-addons
Last commit date
admin
1 year ago
assets
1 year ago
base
1 year ago
classes
1 year ago
extensions
1 year ago
freemius
1 year ago
includes
1 year ago
languages
1 year ago
modules
1 year ago
plugin.php
1 year ago
readme.txt
1 year ago
wpml-config.xml
1 year ago
wpr-addons.php
1 year ago
wpr-addons.php
278 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Plugin Name: Royal Elementor Addons |
| 4 | * Description: The only plugin you need for Elementor page builder. |
| 5 | * Plugin URI: https://royal-elementor-addons.com/ |
| 6 | * Author: WP Royal |
| 7 | * Version: 1.3.984 |
| 8 | * License: GPLv3 |
| 9 | * Author URI: https://royal-elementor-addons.com/ |
| 10 | * Elementor tested up to: 5.0 |
| 11 | * Elementor Pro tested up to: 5.0 |
| 12 | * |
| 13 | * Text Domain: wpr-addons |
| 14 | */ |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; // Exit if accessed directly. |
| 18 | } |
| 19 | |
| 20 | define( 'WPR_ADDONS_VERSION', '1.3.984' ); |
| 21 | |
| 22 | define( 'WPR_ADDONS__FILE__', __FILE__ ); |
| 23 | define( 'WPR_ADDONS_PLUGIN_BASE', plugin_basename( WPR_ADDONS__FILE__ ) ); |
| 24 | define( 'WPR_ADDONS_PATH', plugin_dir_path( WPR_ADDONS__FILE__ ) ); |
| 25 | define( 'WPR_ADDONS_MODULES_PATH', WPR_ADDONS_PATH . 'modules/' ); |
| 26 | define( 'WPR_ADDONS_URL', plugins_url( '/', WPR_ADDONS__FILE__ ) ); |
| 27 | define( 'WPR_ADDONS_ASSETS_URL', WPR_ADDONS_URL . 'assets/' ); |
| 28 | define( 'WPR_ADDONS_MODULES_URL', WPR_ADDONS_URL . 'modules/' ); |
| 29 | |
| 30 | /** |
| 31 | * Feemius Integration |
| 32 | */ |
| 33 | if ( function_exists( 'wpr_fs' ) ) { |
| 34 | wpr_fs()->set_basename( false, __FILE__ ); |
| 35 | } else { |
| 36 | $register_freemius = true; |
| 37 | |
| 38 | if ( get_option('royal_elementor_addons_pro_activation_time') ) { |
| 39 | $register_freemius = false; |
| 40 | } |
| 41 | |
| 42 | if ( $register_freemius ) { |
| 43 | // Create a helper function for easy SDK access. |
| 44 | function wpr_fs() { |
| 45 | global $wpr_fs; |
| 46 | |
| 47 | if ( ! isset( $wpr_fs ) ) { |
| 48 | // Include Freemius SDK. |
| 49 | require_once dirname(__FILE__) . '/freemius/start.php'; |
| 50 | |
| 51 | $wpr_fs = fs_dynamic_init( array( |
| 52 | 'id' => '8416', |
| 53 | 'slug' => 'wpr-addons', |
| 54 | 'premium_slug' => 'wpr-addons-pro', |
| 55 | 'type' => 'plugin', |
| 56 | 'public_key' => 'pk_a0b21b234a7c9581a555b9ee9f28a', |
| 57 | 'is_premium' => false, |
| 58 | 'has_premium_version' => true, |
| 59 | 'has_paid_plans' => false, |
| 60 | 'has_addons' => false, |
| 61 | 'has_affiliation' => 'selected', |
| 62 | 'menu' => array( |
| 63 | 'slug' => 'wpr-addons', |
| 64 | 'first-path' => 'admin.php?page=wpr-templates-kit', |
| 65 | 'support' => false, |
| 66 | 'affiliation' => true, |
| 67 | 'pricing' => false, |
| 68 | ), |
| 69 | ) ); |
| 70 | } |
| 71 | |
| 72 | return $wpr_fs; |
| 73 | } |
| 74 | |
| 75 | // Init Freemius. |
| 76 | wpr_fs(); |
| 77 | // Signal that SDK was initiated. |
| 78 | do_action( 'wpr_fs_loaded' ); |
| 79 | |
| 80 | wpr_fs()->add_filter( 'show_deactivation_subscription_cancellation', '__return_false' ); |
| 81 | wpr_fs()->add_filter( 'deactivate_on_activation', '__return_false' ); |
| 82 | |
| 83 | function disable_contact_for_free_users( $is_visible, $menu_id ) { |
| 84 | |
| 85 | if ( 'contact' != $menu_id ) { |
| 86 | return $is_visible; |
| 87 | } |
| 88 | |
| 89 | return wpr_fs()->can_use_premium_code(); |
| 90 | } |
| 91 | |
| 92 | wpr_fs()->add_filter( 'is_submenu_visible', 'disable_contact_for_free_users', 10, 2 ); |
| 93 | |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Load gettext translate for our text domain. |
| 99 | * |
| 100 | * @since 1.0.0 |
| 101 | * |
| 102 | * @return void |
| 103 | */ |
| 104 | function wpr_addons_load_plugin() { |
| 105 | load_plugin_textdomain('wpr-addons', false, dirname(plugin_basename(__FILE__)) . '/languages/'); |
| 106 | |
| 107 | if ( ! did_action( 'elementor/loaded' ) ) { |
| 108 | add_action( 'admin_notices', 'wpr_addons_fail_load' ); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | $elementor_version_required = '2.0.0'; |
| 113 | if ( ! version_compare( ELEMENTOR_VERSION, $elementor_version_required, '>=' ) ) { |
| 114 | add_action( 'admin_notices', 'wpr_addons_fail_load_out_of_date' ); |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | require( WPR_ADDONS_PATH . 'plugin.php' ); |
| 119 | } |
| 120 | add_action( 'plugins_loaded', 'wpr_addons_load_plugin' ); |
| 121 | |
| 122 | /** |
| 123 | * Show in WP Dashboard notice about the plugin is not activated. |
| 124 | * |
| 125 | * @since 1.0.0 |
| 126 | * |
| 127 | * @return void |
| 128 | */ |
| 129 | function wpr_addons_fail_load() { |
| 130 | $screen = get_current_screen(); |
| 131 | if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) { |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | $plugin = 'elementor/elementor.php'; |
| 136 | |
| 137 | if ( _is_elementor_installed() ) { |
| 138 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | $activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin='. $plugin .'&plugin_status=all&paged=1&s', 'activate-plugin_'. $plugin ); |
| 143 | |
| 144 | $message = '<p>' . esc_html__( 'Royal Elementor Addons is not working because you need to activate the Elementor plugin.', 'wpr-addons' ) . '</p>'; |
| 145 | $message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $activation_url, esc_html__( 'Activate Elementor Now', 'wpr-addons' ) ) . '</p>'; |
| 146 | } else { |
| 147 | if ( ! current_user_can( 'install_plugins' ) ) { |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), 'install-plugin_elementor' ); |
| 152 | |
| 153 | $message = '<p>' . esc_html__( 'Royal Elementor Addons is not working because you need to install the Elemenor plugin', 'wpr-addons' ) . '</p>'; |
| 154 | $message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $install_url, esc_html__( 'Install Elementor Now', 'wpr-addons' ) ) . '</p>'; |
| 155 | } |
| 156 | |
| 157 | echo '<div class="error"><p>'. wp_kses_post($message) .'</p></div>'; |
| 158 | } |
| 159 | |
| 160 | function wpr_addons_fail_load_out_of_date() { |
| 161 | if ( ! current_user_can( 'update_plugins' ) ) { |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | $file_path = 'elementor/elementor.php'; |
| 166 | |
| 167 | $upgrade_link = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file_path, 'upgrade-plugin_'. $file_path ); |
| 168 | $message = '<p>' . esc_html__( 'Royal Elementor Addons is not working because you are using an old version of Elementor.', 'wpr-addons' ) . '</p>'; |
| 169 | $message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $upgrade_link, esc_html__( 'Update Elementor Now', 'wpr-addons' ) ) . '</p>'; |
| 170 | |
| 171 | echo '<div class="error">'. wp_kses_post($message) .'</div>'; |
| 172 | } |
| 173 | |
| 174 | if ( ! function_exists( '_is_elementor_installed' ) ) { |
| 175 | |
| 176 | function _is_elementor_installed() { |
| 177 | $file_path = 'elementor/elementor.php'; |
| 178 | $installed_plugins = get_plugins(); |
| 179 | |
| 180 | return isset( $installed_plugins[ $file_path ] ); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | |
| 185 | /** |
| 186 | * Redirect to Options Page |
| 187 | * |
| 188 | * @since 1.0.0 |
| 189 | * |
| 190 | */ |
| 191 | |
| 192 | function wpr_plugin_activate() { |
| 193 | set_transient('wpr_plugin_do_activation_redirect', true, 60); |
| 194 | } |
| 195 | |
| 196 | function wpr_plugin_redirect() { |
| 197 | if (get_transient('wpr_plugin_do_activation_redirect')) { |
| 198 | delete_transient('wpr_plugin_do_activation_redirect'); |
| 199 | |
| 200 | if ( !isset($_GET['activate-multi']) ) { |
| 201 | wp_redirect('admin.php?page=wpr-addons'); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | if ( did_action( 'elementor/loaded' ) ) { |
| 207 | |
| 208 | register_activation_hook(__FILE__, 'wpr_plugin_activate'); |
| 209 | add_action('admin_init', 'wpr_plugin_redirect'); |
| 210 | } |
| 211 | |
| 212 | // Set Plugin Activation Time |
| 213 | function royal_elementor_addons_activation_time() {//TODO: Try to locate this in rating-notice.php later if possible |
| 214 | if ( false === get_option( 'royal_elementor_addons_activation_time' ) ) { |
| 215 | add_option( 'royal_elementor_addons_activation_time', absint(intval(strtotime('now'))) ); |
| 216 | } |
| 217 | |
| 218 | if ( false === get_option( 'royal_elementor_addons_activation_time_for_sale' ) ) { |
| 219 | add_option( 'royal_elementor_addons_activation_time_for_sale', absint(intval(strtotime('now'))) ); |
| 220 | } |
| 221 | |
| 222 | if ( get_option('wpr_plugin_update_dismiss_notice_' . get_plugin_data(WPR_ADDONS__FILE__)['Version']) ) { |
| 223 | delete_option('wpr_plugin_update_dismiss_notice_' . get_plugin_data(WPR_ADDONS__FILE__)['Version']); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | register_activation_hook( __FILE__, 'royal_elementor_addons_activation_time' ); |
| 228 | |
| 229 | // Delete Plugin Update Notice |
| 230 | function royal_elementor_addons_deactivate() { |
| 231 | if ( get_option('wpr_plugin_update_dismiss_notice_' . get_plugin_data(WPR_ADDONS__FILE__)['Version']) ) { |
| 232 | delete_option('wpr_plugin_update_dismiss_notice_' . get_plugin_data(WPR_ADDONS__FILE__)['Version']); |
| 233 | } |
| 234 | |
| 235 | if ( get_option('wpr_pro_features_dismiss_notice_' . get_plugin_data(WPR_ADDONS__FILE__)['Version']) ) { |
| 236 | delete_option('wpr_pro_features_dismiss_notice_' . get_plugin_data(WPR_ADDONS__FILE__)['Version']); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // hook already exists with template kits notice |
| 241 | register_deactivation_hook( __FILE__, 'royal_elementor_addons_deactivate' ); |
| 242 | |
| 243 | function wpr_script_loader_tag( $tag, $handle ) { |
| 244 | if ( 'jquery-core' !== $handle && 'jquery-migrate' !== $handle && 'wpr-addons-js' !== $handle && 'wpr-isotope' !== $handle ) { |
| 245 | return $tag; |
| 246 | } |
| 247 | |
| 248 | |
| 249 | // Modern implementations may employ WP_HTML_Tag_Processor here. |
| 250 | // return str_replace( ' src=', ' defer src=', $tag ); |
| 251 | return str_replace( ' src', ' data-cfasync="false" src', $tag ); |
| 252 | } |
| 253 | |
| 254 | function exclude_wpr_scripts_from_wp_optimize( $excluded_handles ) { |
| 255 | // Replace 'my-script-handle' with the handle of the script you want to exclude. |
| 256 | $excluded_handles[] = 'wpr-addons-js'; |
| 257 | |
| 258 | return $excluded_handles; |
| 259 | } |
| 260 | |
| 261 | function exclude_wpr_styles_from_wp_optimize( $excluded_handles ) { |
| 262 | // Replace 'my-style-handle' with the handle of the style you want to exclude. |
| 263 | $excluded_handles[] = 'wpr-addons-css'; |
| 264 | |
| 265 | return $excluded_handles; |
| 266 | } |
| 267 | |
| 268 | if ( 'on' === get_option('wpr_ignore_wp_rocket_js', 'on') ) { |
| 269 | add_filter( 'script_loader_tag', 'wpr_script_loader_tag', 10, 2 ); |
| 270 | } |
| 271 | |
| 272 | if ( 'on' === get_option('wpr_ignore_wp_optimize_js', 'on') ) { |
| 273 | add_filter( 'wpo_minify_excluded_js_handles', 'exclude_wpr_scripts_from_wp_optimize' ); |
| 274 | } |
| 275 | |
| 276 | if ( 'on' === get_option('wpr_ignore_wp_optimize_css', 'on') ) { |
| 277 | add_filter( 'wpo_minify_excluded_css_handles', 'exclude_wpr_styles_from_wp_optimize' ); |
| 278 | } |