| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Oauth\Components; |
| 4 |
|
| 5 |
use ImageOptimization\Modules\Core\Components\Pointers; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class Connect_Pointer { |
| 12 |
const CURRENT_POINTER_SLUG = 'image-optimization-auth-connect'; |
| 13 |
|
| 14 |
public function admin_print_script() { |
| 15 |
if ( Connect::is_connected() ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
wp_enqueue_script( 'wp-pointer' ); |
| 20 |
wp_enqueue_style( 'wp-pointer' ); |
| 21 |
|
| 22 |
$pointer_content = '<h3>' . esc_html__( 'Start by connecting your license', 'image-optimization' ) . '</h3>'; |
| 23 |
$pointer_content .= '<p>' . esc_html__( 'You’re one click away from improving your site’s performance dramatically!', 'image-optimization' ) . '</p>'; |
| 24 |
?> |
| 25 |
<script> |
| 26 |
jQuery( document ).ready( function( $ ) { |
| 27 |
console.log( $( '.image-optimization-stats-connect-button' ) ); |
| 28 |
|
| 29 |
const intervalId = setInterval( () => { |
| 30 |
if ( ! $( '.image-optimization-stats-connect-button' ).length ) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
clearInterval(intervalId); |
| 35 |
|
| 36 |
$( '.image-optimization-stats-connect-button' ).first().pointer( { |
| 37 |
content: '<?php echo $pointer_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>', |
| 38 |
pointerClass: 'image-optimization-auth-connect-pointer', |
| 39 |
position: { |
| 40 |
edge: 'top', |
| 41 |
align: <?php echo is_rtl() ? "'left'" : "'right'"; ?>, |
| 42 |
}, |
| 43 |
} ).pointer( 'open' ); |
| 44 |
}, 100 ); |
| 45 |
} ); |
| 46 |
</script> |
| 47 |
|
| 48 |
<style> |
| 49 |
.image-optimization-auth-connect-pointer .wp-pointer-arrow { |
| 50 |
inset-block-start: 4px; |
| 51 |
inset-inline-start: 78%; |
| 52 |
} |
| 53 |
|
| 54 |
.image-optimization-auth-connect-pointer .wp-pointer-arrow-inner { |
| 55 |
inset-block-start: 10px; |
| 56 |
} |
| 57 |
</style> |
| 58 |
<?php |
| 59 |
} |
| 60 |
|
| 61 |
public function __construct() { |
| 62 |
add_action( 'in_admin_header', [ $this, 'admin_print_script' ] ); |
| 63 |
} |
| 64 |
} |
| 65 |
|