| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WPB Elementor Addons |
| 4 |
* Plugin URI: https://wpbean.com/ |
| 5 |
* Description: Highly customizable addons for Elementor page builder. |
| 6 |
* Version: 1.2 |
| 7 |
* Author: wpbean |
| 8 |
* Author URI: https://wpbean.com |
| 9 |
* Text Domain: wpb-elementor-addons |
| 10 |
* Domain Path: /languages |
| 11 |
* |
| 12 |
* @package WPB Elementor Addons |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Plugin main class |
| 21 |
*/ |
| 22 |
class WPB_Elementor_Addons { |
| 23 |
|
| 24 |
/** |
| 25 |
* The plugin path |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
public $plugin_path; |
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* The theme directory path |
| 34 |
* |
| 35 |
* @var string |
| 36 |
*/ |
| 37 |
public $theme_dir_path; |
| 38 |
|
| 39 |
/** |
| 40 |
* Instance |
| 41 |
* |
| 42 |
* @access private |
| 43 |
* @static |
| 44 |
* |
| 45 |
* @var Plugin The single instance of the class. |
| 46 |
*/ |
| 47 |
private static $instance = null; |
| 48 |
|
| 49 |
/** |
| 50 |
* Instance |
| 51 |
* |
| 52 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 53 |
* |
| 54 |
* @access public |
| 55 |
* |
| 56 |
* @return Plugin An instance of the class. |
| 57 |
*/ |
| 58 |
public static function instance() { |
| 59 |
if ( is_null( self::$instance ) ) { |
| 60 |
self::$instance = new self(); |
| 61 |
} |
| 62 |
return self::$instance; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Class Constructor. |
| 67 |
*/ |
| 68 |
private function __construct() { |
| 69 |
$this->define_constants(); |
| 70 |
|
| 71 |
if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 72 |
add_action( 'plugins_loaded', array( $this, 'plugin_init' ) ); |
| 73 |
} else { |
| 74 |
add_action( 'admin_notices', array( $this, 'elementor_required_error' ) ); |
| 75 |
} |
| 76 |
|
| 77 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_actions_links' ) ); |
| 78 |
register_deactivation_hook( plugin_basename( __FILE__ ), array( $this, 'register_deactivation' ) ); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Define plugin Constants. |
| 83 |
*/ |
| 84 |
public function define_constants() { |
| 85 |
define( 'WPB_EA_VERSION', '1.0.9' ); |
| 86 |
define( 'WPB_EA_URL', plugins_url( '/', __FILE__ ) ); |
| 87 |
define( 'WPB_EA_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) ); |
| 88 |
define( 'WPB_EA_PREFIX', 'wpb_ea_' ); |
| 89 |
define( 'WPB_EA_THEME_DIR_PATH', 'wpb-elementor-addons/' ); |
| 90 |
define( 'WPB_EA_TEMPLATE_PATH', WPB_EA_PATH . 'templates/' ); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Initialize the plugin |
| 95 |
* |
| 96 |
* @return void |
| 97 |
*/ |
| 98 |
public function plugin_init() { |
| 99 |
$this->file_includes(); |
| 100 |
add_action( 'init', array( $this, 'localization_setup' ) ); |
| 101 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 102 |
add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 103 |
add_action( 'activated_plugin', array( $this, 'activation_redirect' ) ); |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Load the required files |
| 108 |
* |
| 109 |
* @return void |
| 110 |
*/ |
| 111 |
public function file_includes() { |
| 112 |
require_once __DIR__ . '/inc/helper.php'; |
| 113 |
require_once __DIR__ . '/inc/wpb_functions.php'; |
| 114 |
require_once __DIR__ . '/inc/wpb_scripts.php'; |
| 115 |
require_once __DIR__ . '/admin/admin-page.php'; |
| 116 |
require_once __DIR__ . '/admin/class.settings-api.php'; |
| 117 |
require_once __DIR__ . '/admin/plugin-settings.php'; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Plugin action links |
| 122 |
*/ |
| 123 |
public function plugin_actions_links( $links ) { |
| 124 |
if ( is_admin() ) { |
| 125 |
$links[] = '<a href="' . esc_url( admin_url( 'admin.php?page=wpb_ea_settings' ) ) . '">' . esc_html__( 'Settings', 'wpb-elementor-addons' ) . '</a>'; |
| 126 |
$links[] = '<a href="https://wpbean.com/support/" target="_blank">' . esc_html__( 'Support', 'wpb-elementor-addons' ) . '</a>'; |
| 127 |
$links[] = '<a href="http://docs.wpbean.com/docs/wpb-ea-elementor-addons/" target="_blank">' . esc_html__( 'Documentation', 'wpb-elementor-addons' ) . '</a>'; |
| 128 |
$links[] = '<a href="https://wpbean.com/elementor-addons/" target="_blank" class="elementor-plugins-gopro">' . esc_html__( 'Pro Addons', 'wpb-elementor-addons' ) . '</a>'; |
| 129 |
} |
| 130 |
return $links; |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Initialize plugin for localization |
| 135 |
* |
| 136 |
* @uses load_plugin_textdomain() |
| 137 |
*/ |
| 138 |
public function localization_setup() { |
| 139 |
load_plugin_textdomain( 'wpb-elementor-addons', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Activation redirect |
| 144 |
*/ |
| 145 |
public function activation_redirect( $plugin ) { |
| 146 |
if ( $plugin == plugin_basename( __FILE__ ) ) { |
| 147 |
wp_safe_redirect( esc_url( admin_url( 'admin.php?page=wpb-ea-about' ) ) ); |
| 148 |
exit; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Admin notices |
| 154 |
*/ |
| 155 |
public function admin_notices() { |
| 156 |
if ( ! is_plugin_active( 'elementor/elementor.php' ) ) { |
| 157 |
printf( '<div class="notice notice-warning is-dismissible"><p>%s</p></div>', esc_html__( 'This plugin required Elementor Page Builder installed to function.', 'wpb-elementor-addons' ) ); |
| 158 |
} |
| 159 |
|
| 160 |
$user_id = get_current_user_id(); |
| 161 |
$premium_addons = wpb_ea_premium_addons(); |
| 162 |
|
| 163 |
if ( ! empty( $premium_addons ) ) { |
| 164 |
foreach ( $premium_addons as $key => $premium_addon ) { |
| 165 |
if ( ! get_user_meta( $user_id, $key . '-discount-dismissed' ) ) { |
| 166 |
printf( |
| 167 |
'<div class="wpb-ea-discount-notice updated" style="padding: 30px 20px;border-left-color: #27ae60;border-left-width: 5px;margin-top: 20px;"><p style="font-size: 18px;line-height: 32px">%s <a target="_blank" href="%s">%s</a>! %s <b>%s</b></p><a href="%s">%s</a></div>', |
| 168 |
esc_html__( 'Get a 10% exclusive discount on the', 'wpb-elementor-addons' ), |
| 169 |
esc_url( 'https://wpbean.com/downloads/' . $key ), |
| 170 |
esc_html( $premium_addon ), |
| 171 |
esc_html__( 'Use discount code - ', 'wpb-elementor-addons' ), |
| 172 |
'10PERCENTOFF', |
| 173 |
esc_url( |
| 174 |
add_query_arg( |
| 175 |
array( |
| 176 |
$key . '-discount-dismissed' => 'true', |
| 177 |
'_wpnonce' => wp_create_nonce( 'wpb-ea-discount-dismissed-' . $key ), |
| 178 |
) |
| 179 |
) |
| 180 |
), |
| 181 |
esc_html__( 'Dismiss', 'wpb-elementor-addons' ) |
| 182 |
); |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* elementor_required_error |
| 190 |
*/ |
| 191 |
public function elementor_required_error() { |
| 192 |
$class = 'notice notice-warning'; |
| 193 |
$message = esc_html__( 'WPB Elementor Addons requires the Elementor plugin.', 'wpb-elementor-addons' ); |
| 194 |
|
| 195 |
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Admin Init |
| 200 |
*/ |
| 201 |
public function admin_init() { |
| 202 |
$user_id = get_current_user_id(); |
| 203 |
|
| 204 |
$premium_addons = wpb_ea_premium_addons(); |
| 205 |
|
| 206 |
if ( ! empty( $premium_addons ) ) { |
| 207 |
foreach ( $premium_addons as $key => $premium_addon ) { |
| 208 |
if ( isset( $_GET[ $key . '-discount-dismissed' ] ) ) { |
| 209 |
// run a quick security check. |
| 210 |
if ( ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'wpb-ea-discount-dismissed-' . $key ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 211 |
return; |
| 212 |
} |
| 213 |
add_user_meta( $user_id, $key . '-discount-dismissed', 'true', true ); |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
/** |
| 220 |
* Plugin Deactivation |
| 221 |
*/ |
| 222 |
public function register_deactivation() { |
| 223 |
$user_id = get_current_user_id(); |
| 224 |
|
| 225 |
$premium_addons = wpb_ea_premium_addons(); |
| 226 |
|
| 227 |
if ( ! empty( $premium_addons ) ) { |
| 228 |
foreach ( $premium_addons as $key => $premium_addon ) { |
| 229 |
if ( get_user_meta( $user_id, $key . '-discount-dismissed' ) ) { |
| 230 |
delete_user_meta( $user_id, $key . '-discount-dismissed' ); |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Initialize the main plugin. |
| 239 |
* |
| 240 |
* @return \WPB_Elementor_Addons |
| 241 |
*/ |
| 242 |
|
| 243 |
WPB_Elementor_Addons::instance(); |
| 244 |
|