EasyDigitalDownloads
3 years ago
Elementor
2 years ago
Integrations
3 years ago
MemberPress
2 years ago
Plugins
2 years ago
Promos
3 years ago
Rules
2 years ago
Shortcodes
2 years ago
WPForms
1 year ago
WooCommerce
1 year ago
Actions.php
1 year ago
Ajax.php
4 years ago
Api.php
1 year ago
ApiAuth.php
4 years ago
ApiKey.php
1 year ago
AssetLoader.php
5 years ago
BaseRestApi.php
3 years ago
Blocks.php
1 year ago
ClassicEditor.php
3 years ago
ConstantContact.php
1 year ago
Debug.php
1 year ago
EasyDigitalDownloads.php
1 year ago
Elementor.php
3 years ago
Inserter.php
3 years ago
InstallSkin.php
5 years ago
InstallSkinCompat.php
5 years ago
MailPoet.php
1 year ago
MemberPress.php
2 years ago
Menu.php
1 year ago
Notifications.php
1 year ago
OmuApi.php
4 years ago
Output.php
1 year ago
Pages.php
1 year ago
Partners.php
1 year ago
Plugins.php
2 years ago
Promos.php
3 years ago
Refresh.php
1 year ago
RestApi.php
1 year ago
RevenueAttribution.php
4 years ago
Review.php
4 years ago
Rules.php
1 year ago
Save.php
2 years ago
Shortcode.php
4 years ago
Sites.php
1 year ago
Support.php
1 year ago
Type.php
3 years ago
Urls.php
1 year ago
Utils.php
1 year ago
Validate.php
2 years ago
WPForms.php
2 years ago
Welcome.php
4 years ago
Widget.php
4 years ago
WooCommerce.php
1 year ago
Wordfence.php
3 years ago
WpErrorException.php
5 years ago
Elementor.php
242 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Elementor class. |
| 4 | * |
| 5 | * @since 2.2.0 |
| 6 | * |
| 7 | * @package OMAPI |
| 8 | * @author Justin Sternberg |
| 9 | */ |
| 10 | |
| 11 | // Exit if accessed directly. |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * The Elementor class. |
| 18 | * |
| 19 | * @since 2.2.0 |
| 20 | */ |
| 21 | class OMAPI_Elementor { |
| 22 | |
| 23 | /** |
| 24 | * Holds the class object. |
| 25 | * |
| 26 | * @since 1.7.0 |
| 27 | * |
| 28 | * @var object |
| 29 | */ |
| 30 | public static $instance; |
| 31 | |
| 32 | /** |
| 33 | * Path to the file. |
| 34 | * |
| 35 | * @since 1.7.0 |
| 36 | * |
| 37 | * @var string |
| 38 | */ |
| 39 | public $file = __FILE__; |
| 40 | |
| 41 | /** |
| 42 | * Holds the base class object. |
| 43 | * |
| 44 | * @since 1.7.0 |
| 45 | * |
| 46 | * @var object |
| 47 | */ |
| 48 | public $base; |
| 49 | |
| 50 | /** |
| 51 | * The minimum Elementor version required. |
| 52 | * |
| 53 | * @since 2.11.2 |
| 54 | * |
| 55 | * @var string |
| 56 | */ |
| 57 | const MINIMUM_VERSION = '3.1.0'; |
| 58 | |
| 59 | /** |
| 60 | * Primary class constructor. |
| 61 | * |
| 62 | * @since 1.7.0 |
| 63 | */ |
| 64 | public function __construct() { |
| 65 | |
| 66 | // Set our object. |
| 67 | $this->set(); |
| 68 | |
| 69 | // Skip if Elementor is not available. |
| 70 | if ( ! class_exists( '\Elementor\Plugin' ) ) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | // Check if Elementor is the minimum version. |
| 75 | if ( ! self::is_minimum_version() ) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'editor_assets' ) ); |
| 80 | add_action( 'elementor/widgets/widgets_registered', array( $this, 'register_widget' ), 999 ); |
| 81 | add_action( 'optin_monster_should_set_campaigns_as_preview', array( $this, 'maybe_set_campaigns_as_preview' ) ); |
| 82 | add_action( 'optin_monster_display_media_button', array( $this, 'maybe_show_campaign_button' ), 10, 2 ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Sets our object instance and base class instance. |
| 87 | * |
| 88 | * @since 1.7.0 |
| 89 | */ |
| 90 | public function set() { |
| 91 | self::$instance = $this; |
| 92 | $this->base = OMAPI::get_instance(); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Load an integration css in the elementor document. |
| 97 | * |
| 98 | * @since 2.2.0 |
| 99 | */ |
| 100 | public function editor_assets() { |
| 101 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 102 | if ( empty( $_GET['action'] ) || 'elementor' !== $_GET['action'] ) { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | $css_handle = $this->base->plugin_slug . '-elementor-admin'; |
| 107 | wp_enqueue_style( |
| 108 | $css_handle, |
| 109 | $this->base->url . 'assets/dist/css/elementor-admin.min.css', |
| 110 | array(), |
| 111 | $this->base->asset_version() |
| 112 | ); |
| 113 | |
| 114 | $this->maybe_enqueue_dark_mode( $css_handle ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Handle enqueueing the dark-mode css. Will be conditionally displayed based on the UI setting. |
| 119 | * |
| 120 | * We have to do this until Elementor has better handling for dark-mode via a body class |
| 121 | * |
| 122 | * @see https://github.com/elementor/elementor/issues/13419 |
| 123 | * |
| 124 | * @since 2.2.0 |
| 125 | * |
| 126 | * @param string $css_handle Non-dark mode handle. |
| 127 | * |
| 128 | * @return bool|string |
| 129 | */ |
| 130 | protected function maybe_enqueue_dark_mode( $css_handle ) { |
| 131 | |
| 132 | $ui_theme = \Elementor\Core\Settings\Manager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); |
| 133 | |
| 134 | if ( 'light' === $ui_theme ) { |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | $ui_theme_media_queries = 'auto' === $ui_theme |
| 139 | ? '(prefers-color-scheme: dark)' |
| 140 | : 'all'; |
| 141 | |
| 142 | wp_enqueue_style( |
| 143 | $css_handle . '-dark-mode', |
| 144 | $this->base->url . 'assets/dist/css/elementor-admin-dark.min.css', |
| 145 | array( $css_handle ), |
| 146 | $this->base->asset_version(), |
| 147 | $ui_theme_media_queries |
| 148 | ); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Return the Elementor versions string. |
| 153 | * |
| 154 | * @since 2.11.2 |
| 155 | * |
| 156 | * @return string |
| 157 | */ |
| 158 | public static function version() { |
| 159 | return defined( 'ELEMENTOR_VERSION' ) ? ELEMENTOR_VERSION : '0.0.0'; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Determines if the passed version string passes the operator compare |
| 164 | * against the currently installed version of Elementor. |
| 165 | * |
| 166 | * Defaults to checking if the current Elementor version is greater than |
| 167 | * the passed version. |
| 168 | * |
| 169 | * @since 2.11.2 |
| 170 | * |
| 171 | * @param string $version The version to check. |
| 172 | * @param string $operator The operator to use for comparison. |
| 173 | * |
| 174 | * @return string |
| 175 | */ |
| 176 | public static function version_compare( $version = '', $operator = '>=' ) { |
| 177 | return version_compare( self::version(), $version, $operator ); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Determines if the current Elementor version meets the minimum version |
| 182 | * requirement. |
| 183 | * |
| 184 | * @since 2.11.2 |
| 185 | * |
| 186 | * @return boolean |
| 187 | */ |
| 188 | public static function is_minimum_version() { |
| 189 | return self::version_compare( self::MINIMUM_VERSION ); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Register WPForms Widget. |
| 194 | * |
| 195 | * @since 2.2.0 |
| 196 | * |
| 197 | * @param \Elementor\Widgets_Manager $widget_manager Elementor widget manager object. |
| 198 | */ |
| 199 | public function register_widget( $widget_manager ) { |
| 200 | $widget_manager->register_widget_type( new OMAPI_Elementor_Widget() ); |
| 201 | |
| 202 | // We need to override the button widget with our extended version. |
| 203 | $widget_manager->register_widget_type( new OMAPI_Elementor_ButtonWidget() ); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Set the preview flag if in the elementor preview mode. |
| 208 | * |
| 209 | * @since 2.2.0 |
| 210 | * |
| 211 | * @param bool $is_preview Whether we're currently in preview mode. |
| 212 | * |
| 213 | * @return bool Whether we're in preview mode. |
| 214 | */ |
| 215 | public function maybe_set_campaigns_as_preview( $is_preview ) { |
| 216 | if ( ! $is_preview ) { |
| 217 | $is_preview = \Elementor\Plugin::instance()->preview->is_preview_mode(); |
| 218 | } |
| 219 | |
| 220 | return $is_preview; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Show the editor campaign media button if in the elementor editor. |
| 225 | * |
| 226 | * @since 2.3.0 |
| 227 | * |
| 228 | * @param bool $show Whether button will show. |
| 229 | * |
| 230 | * @return bool Whether button will show. |
| 231 | */ |
| 232 | public function maybe_show_campaign_button( $show, $editor_id ) { |
| 233 | $edit_mode = \Elementor\Plugin::instance()->editor->is_edit_mode(); |
| 234 | if ( $edit_mode ) { |
| 235 | $show = true; |
| 236 | add_action( 'elementor/editor/footer', array( $this->base->classicEditor, 'shortcode_modal' ) ); |
| 237 | } |
| 238 | |
| 239 | return $show; |
| 240 | } |
| 241 | } |
| 242 |