| 1 |
<?php |
| 2 |
namespace Elementor\Core\Admin; |
| 3 |
|
| 4 |
use Elementor\Api; |
| 5 |
use Elementor\Beta_Testers; |
| 6 |
use Elementor\Core\Base\App; |
| 7 |
use Elementor\Plugin; |
| 8 |
use Elementor\Settings; |
| 9 |
use Elementor\User; |
| 10 |
use Elementor\Utils; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
class Admin extends App { |
| 17 |
|
| 18 |
/** |
| 19 |
* Get module name. |
| 20 |
* |
| 21 |
* Retrieve the module name. |
| 22 |
* |
| 23 |
* @since 2.3.0 |
| 24 |
* @access public |
| 25 |
* |
| 26 |
* @return string Module name. |
| 27 |
*/ |
| 28 |
public function get_name() { |
| 29 |
return 'admin'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @since 2.2.0 |
| 34 |
* @access public |
| 35 |
*/ |
| 36 |
public function maybe_redirect_to_getting_started() { |
| 37 |
if ( ! get_transient( 'elementor_activation_redirect' ) ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
if ( wp_doing_ajax() ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
delete_transient( 'elementor_activation_redirect' ); |
| 46 |
|
| 47 |
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
global $wpdb; |
| 52 |
|
| 53 |
$has_elementor_page = ! ! $wpdb->get_var( "SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_elementor_edit_mode' LIMIT 1;" ); |
| 54 |
|
| 55 |
if ( $has_elementor_page ) { |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
wp_safe_redirect( admin_url( 'admin.php?page=elementor-getting-started' ) ); |
| 60 |
|
| 61 |
exit; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Enqueue admin scripts. |
| 66 |
* |
| 67 |
* Registers all the admin scripts and enqueues them. |
| 68 |
* |
| 69 |
* Fired by `admin_enqueue_scripts` action. |
| 70 |
* |
| 71 |
* @since 1.0.0 |
| 72 |
* @access public |
| 73 |
*/ |
| 74 |
public function enqueue_scripts() { |
| 75 |
wp_register_script( |
| 76 |
'elementor-admin', |
| 77 |
$this->get_js_assets_url( 'admin' ), |
| 78 |
[ |
| 79 |
'elementor-common', |
| 80 |
], |
| 81 |
ELEMENTOR_VERSION, |
| 82 |
true |
| 83 |
); |
| 84 |
|
| 85 |
wp_enqueue_script( 'elementor-admin' ); |
| 86 |
|
| 87 |
$this->print_config(); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Enqueue admin styles. |
| 92 |
* |
| 93 |
* Registers all the admin styles and enqueues them. |
| 94 |
* |
| 95 |
* Fired by `admin_enqueue_scripts` action. |
| 96 |
* |
| 97 |
* @since 1.0.0 |
| 98 |
* @access public |
| 99 |
*/ |
| 100 |
public function enqueue_styles() { |
| 101 |
$direction_suffix = is_rtl() ? '-rtl' : ''; |
| 102 |
|
| 103 |
wp_register_style( |
| 104 |
'elementor-admin', |
| 105 |
$this->get_css_assets_url( 'admin' . $direction_suffix ), |
| 106 |
[ |
| 107 |
'elementor-common', |
| 108 |
], |
| 109 |
ELEMENTOR_VERSION |
| 110 |
); |
| 111 |
|
| 112 |
wp_enqueue_style( 'elementor-admin' ); |
| 113 |
|
| 114 |
// It's for upgrade notice. |
| 115 |
// TODO: enqueue this just if needed. |
| 116 |
add_thickbox(); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Print switch mode button. |
| 121 |
* |
| 122 |
* Adds a switch button in post edit screen (which has cpt support). To allow |
| 123 |
* the user to switch from the native WordPress editor to Elementor builder. |
| 124 |
* |
| 125 |
* Fired by `edit_form_after_title` action. |
| 126 |
* |
| 127 |
* @since 1.0.0 |
| 128 |
* @access public |
| 129 |
* |
| 130 |
* @param \WP_Post $post The current post object. |
| 131 |
*/ |
| 132 |
public function print_switch_mode_button( $post ) { |
| 133 |
// Exit if Gutenberg are active. |
| 134 |
if ( did_action( 'enqueue_block_editor_assets' ) ) { |
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
$document = Plugin::$instance->documents->get( $post->ID ); |
| 139 |
|
| 140 |
if ( ! $document || ! $document->is_editable_by_current_user() ) { |
| 141 |
return; |
| 142 |
} |
| 143 |
|
| 144 |
wp_nonce_field( basename( __FILE__ ), '_elementor_edit_mode_nonce' ); |
| 145 |
?> |
| 146 |
<div id="elementor-switch-mode"> |
| 147 |
<input id="elementor-switch-mode-input" type="hidden" name="_elementor_post_mode" value="<?php echo $document->is_built_with_elementor(); ?>" /> |
| 148 |
<button id="elementor-switch-mode-button" type="button" class="button button-primary button-hero"> |
| 149 |
<span class="elementor-switch-mode-on"> |
| 150 |
<i class="eicon-arrow-<?php echo ( is_rtl() ) ? 'right' : 'left'; ?>" aria-hidden="true"></i> |
| 151 |
<?php echo __( 'Back to WordPress Editor', 'elementor' ); ?> |
| 152 |
</span> |
| 153 |
<span class="elementor-switch-mode-off"> |
| 154 |
<i class="eicon-elementor-square" aria-hidden="true"></i> |
| 155 |
<?php echo __( 'Edit with Elementor', 'elementor' ); ?> |
| 156 |
</span> |
| 157 |
</button> |
| 158 |
</div> |
| 159 |
<div id="elementor-editor"> |
| 160 |
<a id="elementor-go-to-edit-page-link" href="<?php echo $document->get_edit_url(); ?>"> |
| 161 |
<div id="elementor-editor-button" class="button button-primary button-hero"> |
| 162 |
<i class="eicon-elementor-square" aria-hidden="true"></i> |
| 163 |
<?php echo __( 'Edit with Elementor', 'elementor' ); ?> |
| 164 |
</div> |
| 165 |
<div class="elementor-loader-wrapper"> |
| 166 |
<div class="elementor-loader"> |
| 167 |
<div class="elementor-loader-boxes"> |
| 168 |
<div class="elementor-loader-box"></div> |
| 169 |
<div class="elementor-loader-box"></div> |
| 170 |
<div class="elementor-loader-box"></div> |
| 171 |
<div class="elementor-loader-box"></div> |
| 172 |
</div> |
| 173 |
</div> |
| 174 |
<div class="elementor-loading-title"><?php echo __( 'Loading', 'elementor' ); ?></div> |
| 175 |
</div> |
| 176 |
</a> |
| 177 |
</div> |
| 178 |
<?php |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Save post. |
| 183 |
* |
| 184 |
* Flag the post mode when the post is saved. |
| 185 |
* |
| 186 |
* Fired by `save_post` action. |
| 187 |
* |
| 188 |
* @since 1.0.0 |
| 189 |
* @access public |
| 190 |
* |
| 191 |
* @param int $post_id Post ID. |
| 192 |
*/ |
| 193 |
public function save_post( $post_id ) { |
| 194 |
if ( ! isset( $_POST['_elementor_edit_mode_nonce'] ) || ! wp_verify_nonce( $_POST['_elementor_edit_mode_nonce'], basename( __FILE__ ) ) ) { |
| 195 |
return; |
| 196 |
} |
| 197 |
|
| 198 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 199 |
return; |
| 200 |
} |
| 201 |
|
| 202 |
Plugin::$instance->documents->get( $post_id )->set_is_built_with_elementor( ! empty( $_POST['_elementor_post_mode'] ) ); |
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Add Elementor post state. |
| 207 |
* |
| 208 |
* Adds a new "Elementor" post state to the post table. |
| 209 |
* |
| 210 |
* Fired by `display_post_states` filter. |
| 211 |
* |
| 212 |
* @since 1.8.0 |
| 213 |
* @access public |
| 214 |
* |
| 215 |
* @param array $post_states An array of post display states. |
| 216 |
* @param \WP_Post $post The current post object. |
| 217 |
* |
| 218 |
* @return array A filtered array of post display states. |
| 219 |
*/ |
| 220 |
public function add_elementor_post_state( $post_states, $post ) { |
| 221 |
if ( User::is_current_user_can_edit( $post->ID ) && Plugin::$instance->db->is_built_with_elementor( $post->ID ) ) { |
| 222 |
$post_states['elementor'] = __( 'Elementor', 'elementor' ); |
| 223 |
} |
| 224 |
|
| 225 |
return $post_states; |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Body status classes. |
| 230 |
* |
| 231 |
* Adds CSS classes to the admin body tag. |
| 232 |
* |
| 233 |
* Fired by `admin_body_class` filter. |
| 234 |
* |
| 235 |
* @since 1.0.0 |
| 236 |
* @access public |
| 237 |
* |
| 238 |
* @param string $classes Space-separated list of CSS classes. |
| 239 |
* |
| 240 |
* @return string Space-separated list of CSS classes. |
| 241 |
*/ |
| 242 |
public function body_status_classes( $classes ) { |
| 243 |
global $pagenow; |
| 244 |
|
| 245 |
if ( in_array( $pagenow, [ 'post.php', 'post-new.php' ], true ) && Utils::is_post_support() ) { |
| 246 |
$post = get_post(); |
| 247 |
|
| 248 |
$mode_class = Plugin::$instance->db->is_built_with_elementor( $post->ID ) ? 'elementor-editor-active' : 'elementor-editor-inactive'; |
| 249 |
|
| 250 |
$classes .= ' ' . $mode_class; |
| 251 |
} |
| 252 |
|
| 253 |
return $classes; |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Plugin action links. |
| 258 |
* |
| 259 |
* Adds action links to the plugin list table |
| 260 |
* |
| 261 |
* Fired by `plugin_action_links` filter. |
| 262 |
* |
| 263 |
* @since 1.0.0 |
| 264 |
* @access public |
| 265 |
* |
| 266 |
* @param array $links An array of plugin action links. |
| 267 |
* |
| 268 |
* @return array An array of plugin action links. |
| 269 |
*/ |
| 270 |
public function plugin_action_links( $links ) { |
| 271 |
$settings_link = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=' . Settings::PAGE_ID ), __( 'Settings', 'elementor' ) ); |
| 272 |
|
| 273 |
array_unshift( $links, $settings_link ); |
| 274 |
|
| 275 |
$links['go_pro'] = sprintf( '<a href="%1$s" target="_blank" class="elementor-plugins-gopro">%2$s</a>', Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=wp-plugins&utm_campaign=gopro&utm_medium=wp-dash' ), __( 'Go Pro', 'elementor' ) ); |
| 276 |
|
| 277 |
return $links; |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Plugin row meta. |
| 282 |
* |
| 283 |
* Adds row meta links to the plugin list table |
| 284 |
* |
| 285 |
* Fired by `plugin_row_meta` filter. |
| 286 |
* |
| 287 |
* @since 1.1.4 |
| 288 |
* @access public |
| 289 |
* |
| 290 |
* @param array $plugin_meta An array of the plugin's metadata, including |
| 291 |
* the version, author, author URI, and plugin URI. |
| 292 |
* @param string $plugin_file Path to the plugin file, relative to the plugins |
| 293 |
* directory. |
| 294 |
* |
| 295 |
* @return array An array of plugin row meta links. |
| 296 |
*/ |
| 297 |
public function plugin_row_meta( $plugin_meta, $plugin_file ) { |
| 298 |
if ( ELEMENTOR_PLUGIN_BASE === $plugin_file ) { |
| 299 |
$row_meta = [ |
| 300 |
'docs' => '<a href="https://go.elementor.com/docs-admin-plugins/" aria-label="' . esc_attr( __( 'View Elementor Documentation', 'elementor' ) ) . '" target="_blank">' . __( 'Docs & FAQs', 'elementor' ) . '</a>', |
| 301 |
'ideo' => '<a href="https://go.elementor.com/yt-admin-plugins/" aria-label="' . esc_attr( __( 'View Elementor Video Tutorials', 'elementor' ) ) . '" target="_blank">' . __( 'Video Tutorials', 'elementor' ) . '</a>', |
| 302 |
]; |
| 303 |
|
| 304 |
$plugin_meta = array_merge( $plugin_meta, $row_meta ); |
| 305 |
} |
| 306 |
|
| 307 |
return $plugin_meta; |
| 308 |
} |
| 309 |
|
| 310 |
/** |
| 311 |
* Admin footer text. |
| 312 |
* |
| 313 |
* Modifies the "Thank you" text displayed in the admin footer. |
| 314 |
* |
| 315 |
* Fired by `admin_footer_text` filter. |
| 316 |
* |
| 317 |
* @since 1.0.0 |
| 318 |
* @access public |
| 319 |
* |
| 320 |
* @param string $footer_text The content that will be printed. |
| 321 |
* |
| 322 |
* @return string The content that will be printed. |
| 323 |
*/ |
| 324 |
public function admin_footer_text( $footer_text ) { |
| 325 |
$current_screen = get_current_screen(); |
| 326 |
$is_elementor_screen = ( $current_screen && false !== strpos( $current_screen->id, 'elementor' ) ); |
| 327 |
|
| 328 |
if ( $is_elementor_screen ) { |
| 329 |
$footer_text = sprintf( |
| 330 |
/* translators: 1: Elementor, 2: Link to plugin review */ |
| 331 |
__( 'Enjoyed %1$s? Please leave us a %2$s rating. We really appreciate your support!', 'elementor' ), |
| 332 |
'<strong>' . __( 'Elementor', 'elementor' ) . '</strong>', |
| 333 |
'<a href="https://go.elementor.com/admin-review/" target="_blank">★★★★★</a>' |
| 334 |
); |
| 335 |
} |
| 336 |
|
| 337 |
return $footer_text; |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* Register dashboard widgets. |
| 342 |
* |
| 343 |
* Adds a new Elementor widgets to WordPress dashboard. |
| 344 |
* |
| 345 |
* Fired by `wp_dashboard_setup` action. |
| 346 |
* |
| 347 |
* @since 1.9.0 |
| 348 |
* @access public |
| 349 |
*/ |
| 350 |
public function register_dashboard_widgets() { |
| 351 |
wp_add_dashboard_widget( 'e-dashboard-overview', __( 'Elementor Overview', 'elementor' ), [ $this, 'elementor_dashboard_overview_widget' ] ); |
| 352 |
|
| 353 |
// Move our widget to top. |
| 354 |
global $wp_meta_boxes; |
| 355 |
|
| 356 |
$dashboard = $wp_meta_boxes['dashboard']['normal']['core']; |
| 357 |
$ours = [ |
| 358 |
'e-dashboard-overview' => $dashboard['e-dashboard-overview'], |
| 359 |
]; |
| 360 |
|
| 361 |
$wp_meta_boxes['dashboard']['normal']['core'] = array_merge( $ours, $dashboard ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 362 |
} |
| 363 |
|
| 364 |
/** |
| 365 |
* Elementor dashboard widget. |
| 366 |
* |
| 367 |
* Displays the Elementor dashboard widget. |
| 368 |
* |
| 369 |
* Fired by `wp_add_dashboard_widget` function. |
| 370 |
* |
| 371 |
* @since 1.9.0 |
| 372 |
* @access public |
| 373 |
*/ |
| 374 |
public function elementor_dashboard_overview_widget() { |
| 375 |
$elementor_feed = Api::get_feed_data(); |
| 376 |
|
| 377 |
$recently_edited_query_args = [ |
| 378 |
'post_type' => 'any', |
| 379 |
'post_status' => [ 'publish', 'draft' ], |
| 380 |
'posts_per_page' => '3', |
| 381 |
'meta_key' => '_elementor_edit_mode', |
| 382 |
'meta_value' => 'builder', |
| 383 |
'orderby' => 'modified', |
| 384 |
]; |
| 385 |
|
| 386 |
$recently_edited_query = new \WP_Query( $recently_edited_query_args ); |
| 387 |
|
| 388 |
if ( User::is_current_user_can_edit_post_type( 'page' ) ) { |
| 389 |
$create_new_label = __( 'Create New Page', 'elementor' ); |
| 390 |
$create_new_post_type = 'page'; |
| 391 |
} elseif ( User::is_current_user_can_edit_post_type( 'post' ) ) { |
| 392 |
$create_new_label = __( 'Create New Post', 'elementor' ); |
| 393 |
$create_new_post_type = 'post'; |
| 394 |
} |
| 395 |
?> |
| 396 |
<div class="e-dashboard-widget"> |
| 397 |
<div class="e-overview__header"> |
| 398 |
<div class="e-overview__logo"><div class="e-logo-wrapper"><i class="eicon-elementor"></i></div></div> |
| 399 |
<div class="e-overview__versions"> |
| 400 |
<span class="e-overview__version"><?php echo __( 'Elementor', 'elementor' ); ?> v<?php echo ELEMENTOR_VERSION; ?></span> |
| 401 |
<?php |
| 402 |
/** |
| 403 |
* Elementor dashboard widget after the version. |
| 404 |
* |
| 405 |
* Fires after Elementor version display in the dashboard widget. |
| 406 |
* |
| 407 |
* @since 1.9.0 |
| 408 |
*/ |
| 409 |
do_action( 'elementor/admin/dashboard_overview_widget/after_version' ); |
| 410 |
?> |
| 411 |
</div> |
| 412 |
<?php if ( ! empty( $create_new_post_type ) ) : ?> |
| 413 |
<div class="e-overview__create"> |
| 414 |
<a href="<?php echo esc_url( Utils::get_create_new_post_url( $create_new_post_type ) ); ?>" class="button"><span aria-hidden="true" class="dashicons dashicons-plus"></span> <?php echo esc_html( $create_new_label ); ?></a> |
| 415 |
</div> |
| 416 |
<?php endif; ?> |
| 417 |
</div> |
| 418 |
<?php if ( $recently_edited_query->have_posts() ) : ?> |
| 419 |
<div class="e-overview__recently-edited"> |
| 420 |
<h3 class="e-heading e-divider_bottom"><?php echo __( 'Recently Edited', 'elementor' ); ?></h3> |
| 421 |
<ul class="e-overview__posts"> |
| 422 |
<?php |
| 423 |
while ( $recently_edited_query->have_posts() ) : |
| 424 |
$recently_edited_query->the_post(); |
| 425 |
$document = Plugin::$instance->documents->get( get_the_ID() ); |
| 426 |
|
| 427 |
$date = date_i18n( _x( 'M jS', 'Dashboard Overview Widget Recently Date', 'elementor' ), get_the_modified_time( 'U' ) ); |
| 428 |
?> |
| 429 |
<li class="e-overview__post"> |
| 430 |
<a href="<?php echo esc_attr( $document->get_edit_url() ); ?>" class="e-overview__post-link"><?php echo esc_html( get_the_title() ); ?> <span class="dashicons dashicons-edit"></span></a> <span><?php echo $date; ?>, <?php the_time(); ?></span> |
| 431 |
</li> |
| 432 |
<?php endwhile; ?> |
| 433 |
</ul> |
| 434 |
</div> |
| 435 |
<?php endif; ?> |
| 436 |
<?php if ( ! empty( $elementor_feed ) ) : ?> |
| 437 |
<div class="e-overview__feed"> |
| 438 |
<h3 class="e-heading e-divider_bottom"><?php echo __( 'News & Updates', 'elementor' ); ?></h3> |
| 439 |
<ul class="e-overview__posts"> |
| 440 |
<?php foreach ( $elementor_feed as $feed_item ) : ?> |
| 441 |
<li class="e-overview__post"> |
| 442 |
<a href="<?php echo esc_url( $feed_item['url'] ); ?>" class="e-overview__post-link" target="_blank"> |
| 443 |
<?php if ( ! empty( $feed_item['badge'] ) ) : ?> |
| 444 |
<span class="e-overview__badge"><?php echo esc_html( $feed_item['badge'] ); ?></span> |
| 445 |
<?php endif; ?> |
| 446 |
<?php echo esc_html( $feed_item['title'] ); ?> |
| 447 |
</a> |
| 448 |
<p class="e-overview__post-description"><?php echo esc_html( $feed_item['excerpt'] ); ?></p> |
| 449 |
</li> |
| 450 |
<?php endforeach; ?> |
| 451 |
</ul> |
| 452 |
</div> |
| 453 |
<?php endif; ?> |
| 454 |
<div class="e-overview__footer e-divider_top"> |
| 455 |
<ul> |
| 456 |
<?php foreach ( $this->get_dashboard_overview_widget_footer_actions() as $action_id => $action ) : ?> |
| 457 |
<li class="e-overview__<?php echo esc_attr( $action_id ); ?>"><a href="<?php echo esc_attr( $action['link'] ); ?>" target="_blank"><?php echo esc_html( $action['title'] ); ?> <span class="screen-reader-text"><?php echo __( '(opens in a new window)', 'elementor' ); ?></span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></li> |
| 458 |
<?php endforeach; ?> |
| 459 |
</ul> |
| 460 |
</div> |
| 461 |
</div> |
| 462 |
<?php |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Get elementor dashboard overview widget footer actions. |
| 467 |
* |
| 468 |
* Retrieves the footer action links displayed in elementor dashboard widget. |
| 469 |
* |
| 470 |
* @since 1.9.0 |
| 471 |
* @access private |
| 472 |
*/ |
| 473 |
private function get_dashboard_overview_widget_footer_actions() { |
| 474 |
$base_actions = [ |
| 475 |
'blog' => [ |
| 476 |
'title' => __( 'Blog', 'elementor' ), |
| 477 |
'link' => 'https://go.elementor.com/overview-widget-blog/', |
| 478 |
], |
| 479 |
'help' => [ |
| 480 |
'title' => __( 'Help', 'elementor' ), |
| 481 |
'link' => 'https://go.elementor.com/overview-widget-docs/', |
| 482 |
], |
| 483 |
]; |
| 484 |
|
| 485 |
$additions_actions = [ |
| 486 |
'go-pro' => [ |
| 487 |
'title' => __( 'Go Pro', 'elementor' ), |
| 488 |
'link' => Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=wp-overview-widget&utm_campaign=gopro&utm_medium=wp-dash' ), |
| 489 |
], |
| 490 |
]; |
| 491 |
|
| 492 |
// Visible to all core users when Elementor Pro is not installed. |
| 493 |
$additions_actions['find_an_expert'] = [ |
| 494 |
'title' => __( 'Find an Expert', 'elementor' ), |
| 495 |
'link' => 'https://go.elementor.com/go-pro-find-an-expert', |
| 496 |
]; |
| 497 |
|
| 498 |
/** |
| 499 |
* Dashboard widget footer actions. |
| 500 |
* |
| 501 |
* Filters the additions actions displayed in Elementor dashboard widget. |
| 502 |
* |
| 503 |
* Developers can add new action links to Elementor dashboard widget |
| 504 |
* footer using this filter. |
| 505 |
* |
| 506 |
* @since 1.9.0 |
| 507 |
* |
| 508 |
* @param array $additions_actions Elementor dashboard widget footer actions. |
| 509 |
*/ |
| 510 |
$additions_actions = apply_filters( 'elementor/admin/dashboard_overview_widget/footer_actions', $additions_actions ); |
| 511 |
|
| 512 |
$actions = $base_actions + $additions_actions; |
| 513 |
|
| 514 |
return $actions; |
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Admin action new post. |
| 519 |
* |
| 520 |
* When a new post action is fired the title is set to 'Elementor' and the post ID. |
| 521 |
* |
| 522 |
* Fired by `admin_action_elementor_new_post` action. |
| 523 |
* |
| 524 |
* @since 1.9.0 |
| 525 |
* @access public |
| 526 |
*/ |
| 527 |
public function admin_action_new_post() { |
| 528 |
check_admin_referer( 'elementor_action_new_post' ); |
| 529 |
|
| 530 |
if ( empty( $_GET['post_type'] ) ) { |
| 531 |
$post_type = 'post'; |
| 532 |
} else { |
| 533 |
$post_type = $_GET['post_type']; |
| 534 |
} |
| 535 |
|
| 536 |
if ( ! User::is_current_user_can_edit_post_type( $post_type ) ) { |
| 537 |
return; |
| 538 |
} |
| 539 |
|
| 540 |
if ( empty( $_GET['template_type'] ) ) { |
| 541 |
$type = 'post'; |
| 542 |
} else { |
| 543 |
$type = sanitize_text_field( $_GET['template_type'] ); |
| 544 |
} |
| 545 |
|
| 546 |
$post_data = isset( $_GET['post_data'] ) ? $_GET['post_data'] : []; |
| 547 |
|
| 548 |
$meta = []; |
| 549 |
|
| 550 |
/** |
| 551 |
* Create new post meta data. |
| 552 |
* |
| 553 |
* Filters the meta data of any new post created. |
| 554 |
* |
| 555 |
* @since 2.0.0 |
| 556 |
* |
| 557 |
* @param array $meta Post meta data. |
| 558 |
*/ |
| 559 |
$meta = apply_filters( 'elementor/admin/create_new_post/meta', $meta ); |
| 560 |
|
| 561 |
$post_data['post_type'] = $post_type; |
| 562 |
|
| 563 |
$document = Plugin::$instance->documents->create( $type, $post_data, $meta ); |
| 564 |
|
| 565 |
if ( is_wp_error( $document ) ) { |
| 566 |
wp_die( $document ); |
| 567 |
} |
| 568 |
|
| 569 |
wp_redirect( $document->get_edit_url() ); |
| 570 |
|
| 571 |
die; |
| 572 |
} |
| 573 |
|
| 574 |
/** |
| 575 |
* @since 2.3.0 |
| 576 |
* @access public |
| 577 |
*/ |
| 578 |
public function add_new_template_template() { |
| 579 |
Plugin::$instance->common->add_template( ELEMENTOR_PATH . 'includes/admin-templates/new-template.php' ); |
| 580 |
} |
| 581 |
|
| 582 |
/** |
| 583 |
* @access public |
| 584 |
*/ |
| 585 |
public function enqueue_new_template_scripts() { |
| 586 |
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 587 |
|
| 588 |
wp_enqueue_script( |
| 589 |
'elementor-new-template', |
| 590 |
ELEMENTOR_ASSETS_URL . 'js/new-template' . $suffix . '.js', |
| 591 |
[], |
| 592 |
ELEMENTOR_VERSION, |
| 593 |
true |
| 594 |
); |
| 595 |
} |
| 596 |
|
| 597 |
/** |
| 598 |
* @since 2.6.0 |
| 599 |
* @access public |
| 600 |
*/ |
| 601 |
public function add_beta_tester_template() { |
| 602 |
Plugin::$instance->common->add_template( ELEMENTOR_PATH . 'includes/admin-templates/beta-tester.php' ); |
| 603 |
} |
| 604 |
|
| 605 |
/** |
| 606 |
* @access public |
| 607 |
*/ |
| 608 |
public function enqueue_beta_tester_scripts() { |
| 609 |
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 610 |
|
| 611 |
wp_enqueue_script( |
| 612 |
'elementor-beta-tester', |
| 613 |
ELEMENTOR_ASSETS_URL . 'js/beta-tester' . $suffix . '.js', |
| 614 |
[], |
| 615 |
ELEMENTOR_VERSION, |
| 616 |
true |
| 617 |
); |
| 618 |
} |
| 619 |
|
| 620 |
/** |
| 621 |
* @access public |
| 622 |
*/ |
| 623 |
public function init_new_template() { |
| 624 |
if ( 'edit-elementor_library' !== get_current_screen()->id ) { |
| 625 |
return; |
| 626 |
} |
| 627 |
|
| 628 |
// Allow plugins to add their templates on admin_head. |
| 629 |
add_action( 'admin_head', [ $this, 'add_new_template_template' ] ); |
| 630 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_new_template_scripts' ] ); |
| 631 |
} |
| 632 |
|
| 633 |
public function version_update_warning( $current_version, $new_version ) { |
| 634 |
$current_version_minor_part = explode( '.', $current_version )[1]; |
| 635 |
$new_version_minor_part = explode( '.', $new_version )[1]; |
| 636 |
|
| 637 |
if ( $current_version_minor_part === $new_version_minor_part ) { |
| 638 |
return; |
| 639 |
} |
| 640 |
?> |
| 641 |
<hr class="e-major-update-warning__separator" /> |
| 642 |
<div class="e-major-update-warning"> |
| 643 |
<div class="e-major-update-warning__icon"> |
| 644 |
<i class="eicon-info-circle"></i> |
| 645 |
</div> |
| 646 |
<div> |
| 647 |
<div class="e-major-update-warning__title"> |
| 648 |
<?php echo __( 'Heads up, Please backup before upgrade!', 'elementor' ); ?> |
| 649 |
</div> |
| 650 |
<div class="e-major-update-warning__message"><?php echo sprintf( __( 'The latest update includes some substantial changes across different areas of the plugin. We highly recommend you <a href="%s">backup your site before upgrading</a>, and make sure you first update in a staging environment', 'elementor' ), 'https://go.elementor.com/wp-dash-update-backup' ); ?></div> |
| 651 |
</div> |
| 652 |
</div> |
| 653 |
<?php |
| 654 |
} |
| 655 |
|
| 656 |
/** |
| 657 |
* @access public |
| 658 |
*/ |
| 659 |
public function init_beta_tester( $current_screen ) { |
| 660 |
if ( ( 'toplevel_page_elementor' === $current_screen->base ) || 'elementor_page_elementor-tools' === $current_screen->id ) { |
| 661 |
add_action( 'admin_head', [ $this, 'add_beta_tester_template' ] ); |
| 662 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_beta_tester_scripts' ] ); |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
/** |
| 667 |
* Admin constructor. |
| 668 |
* |
| 669 |
* Initializing Elementor in WordPress admin. |
| 670 |
* |
| 671 |
* @since 1.0.0 |
| 672 |
* @access public |
| 673 |
*/ |
| 674 |
public function __construct() { |
| 675 |
Plugin::$instance->init_common(); |
| 676 |
|
| 677 |
$this->add_component( 'feedback', new Feedback() ); |
| 678 |
$this->add_component( 'canary-deployment', new Canary_Deployment() ); |
| 679 |
$this->add_component( 'admin-notices', new Admin_Notices() ); |
| 680 |
|
| 681 |
add_action( 'admin_init', [ $this, 'maybe_redirect_to_getting_started' ] ); |
| 682 |
|
| 683 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 684 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] ); |
| 685 |
|
| 686 |
add_action( 'edit_form_after_title', [ $this, 'print_switch_mode_button' ] ); |
| 687 |
add_action( 'save_post', [ $this, 'save_post' ] ); |
| 688 |
|
| 689 |
add_filter( 'display_post_states', [ $this, 'add_elementor_post_state' ], 10, 2 ); |
| 690 |
|
| 691 |
add_filter( 'plugin_action_links_' . ELEMENTOR_PLUGIN_BASE, [ $this, 'plugin_action_links' ] ); |
| 692 |
add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 ); |
| 693 |
|
| 694 |
add_filter( 'admin_body_class', [ $this, 'body_status_classes' ] ); |
| 695 |
add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] ); |
| 696 |
|
| 697 |
// Register Dashboard Widgets. |
| 698 |
add_action( 'wp_dashboard_setup', [ $this, 'register_dashboard_widgets' ] ); |
| 699 |
|
| 700 |
// Admin Actions |
| 701 |
add_action( 'admin_action_elementor_new_post', [ $this, 'admin_action_new_post' ] ); |
| 702 |
|
| 703 |
add_action( 'current_screen', [ $this, 'init_new_template' ] ); |
| 704 |
add_action( 'current_screen', [ $this, 'init_beta_tester' ] ); |
| 705 |
|
| 706 |
add_action( 'in_plugin_update_message-' . ELEMENTOR_PLUGIN_BASE, function( $plugin_data ) { |
| 707 |
$this->version_update_warning( ELEMENTOR_VERSION, $plugin_data['new_version'] ); |
| 708 |
} ); |
| 709 |
} |
| 710 |
|
| 711 |
/** |
| 712 |
* @since 2.3.0 |
| 713 |
* @access protected |
| 714 |
*/ |
| 715 |
protected function get_init_settings() { |
| 716 |
$beta_tester_email = get_user_meta( get_current_user_id(), User::BETA_TESTER_META_KEY, true ); |
| 717 |
$elementor_beta = get_option( 'elementor_beta', 'no' ); |
| 718 |
$all_introductions = User::get_introduction_meta(); |
| 719 |
$beta_tester_signup_dismissed = array_key_exists( Beta_Testers::BETA_TESTER_SIGNUP, $all_introductions ); |
| 720 |
|
| 721 |
$settings = [ |
| 722 |
'home_url' => home_url(), |
| 723 |
'settings_url' => Settings::get_url(), |
| 724 |
'user' => [ |
| 725 |
'introduction' => User::get_introduction_meta(), |
| 726 |
], |
| 727 |
'beta_tester' => [ |
| 728 |
'beta_tester_signup' => Beta_Testers::BETA_TESTER_SIGNUP, |
| 729 |
'has_email' => $beta_tester_email, |
| 730 |
'option_enabled' => 'no' !== $elementor_beta, |
| 731 |
'signup_dismissed' => $beta_tester_signup_dismissed, |
| 732 |
], |
| 733 |
]; |
| 734 |
|
| 735 |
return apply_filters( 'elementor/admin/localize_settings', $settings ); |
| 736 |
} |
| 737 |
} |
| 738 |
|