| 1 |
<?php |
| 2 |
namespace Elementor\Modules\EditorOne\Classes; |
| 3 |
|
| 4 |
use Elementor\User; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
class Editor_One_Pointer { |
| 11 |
|
| 12 |
const CURRENT_POINTER_SLUG = 'e-editor-one-notice-pointer'; |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
add_action( 'admin_print_footer_scripts', [ $this, 'admin_print_script' ] ); |
| 16 |
} |
| 17 |
|
| 18 |
public function admin_print_script() { |
| 19 |
if ( ! $this->is_admin_user() || $this->is_dismissed() ) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
wp_enqueue_script( 'wp-pointer' ); |
| 24 |
wp_enqueue_style( 'wp-pointer' ); |
| 25 |
|
| 26 |
$learn_more_url = 'https://go.elementor.com/wp-dash-editor-one-learn-more/'; |
| 27 |
$pointer_content = '<h3>' . esc_html__( 'The Editor has a new home', 'elementor' ) . '</h3>'; |
| 28 |
$pointer_content .= sprintf( |
| 29 |
'<p>%s <a href="%s" target="_blank">%s</a></p>', |
| 30 |
esc_html__( 'Editor tools are now grouped together for quick access. Build and grow your site with everything you need in one place.', 'elementor' ), |
| 31 |
esc_url( $learn_more_url ), |
| 32 |
esc_html__( 'Learn more', 'elementor' ) |
| 33 |
); |
| 34 |
|
| 35 |
$got_it_url = Menu_Config::get_elementor_home_url(); |
| 36 |
$pointer_content .= sprintf( |
| 37 |
'<p><button class="button button-primary elementor-editor-one-pointer-got-it">%s</button></p>', |
| 38 |
esc_html__( 'Got it', 'elementor' ) |
| 39 |
); |
| 40 |
|
| 41 |
$pointer_element_selector = '#toplevel_page_' . Menu_Config::ELEMENTOR_HOME_MENU_SLUG; |
| 42 |
|
| 43 |
?> |
| 44 |
<script> |
| 45 |
jQuery( document ).ready( function( $ ) { |
| 46 |
setTimeout( function () { |
| 47 |
function markIntroductionAsViewed( redirectUrl ) { |
| 48 |
elementorCommon.ajax.addRequest( 'introduction_viewed', { |
| 49 |
data: { |
| 50 |
introductionKey: '<?php echo esc_attr( self::CURRENT_POINTER_SLUG ); ?>', |
| 51 |
}, |
| 52 |
success: function() { |
| 53 |
if ( redirectUrl ) { |
| 54 |
window.location.href = redirectUrl; |
| 55 |
} |
| 56 |
} |
| 57 |
} ); |
| 58 |
} |
| 59 |
|
| 60 |
$( '<?php echo esc_js( $pointer_element_selector ); ?>' ).pointer( { |
| 61 |
content: <?php echo wp_json_encode( $pointer_content ); ?>, |
| 62 |
position: { |
| 63 |
edge: 'top', |
| 64 |
align: 'left', |
| 65 |
at: 'left+20 bottom', |
| 66 |
my: 'left top' |
| 67 |
}, |
| 68 |
close: function() { |
| 69 |
markIntroductionAsViewed(); |
| 70 |
} |
| 71 |
} ).pointer( 'open' ); |
| 72 |
|
| 73 |
$( document ).on( 'click', '.elementor-editor-one-pointer-got-it', function( e ) { |
| 74 |
e.preventDefault(); |
| 75 |
markIntroductionAsViewed( '<?php echo esc_url( $got_it_url ); ?>' ); |
| 76 |
} ); |
| 77 |
}, 10 ); |
| 78 |
} ); |
| 79 |
</script> |
| 80 |
<?php |
| 81 |
} |
| 82 |
|
| 83 |
private function is_dismissed() { |
| 84 |
return User::get_introduction_meta( self::CURRENT_POINTER_SLUG ); |
| 85 |
} |
| 86 |
|
| 87 |
private function is_admin_user() { |
| 88 |
return current_user_can( 'manage_options' ); |
| 89 |
} |
| 90 |
} |
| 91 |
|