/home/techb158/public_html/wp-content/plugins/wpforms-lite/src/Admin/Education/Pointers
Edit: /home/techb158/public_html/wp-content/plugins/wpforms-lite/src/Admin/Education/Pointers/Pointer.php (10399B)
allow_display() || ! $this->allow_load() ) {
return;
}
// Set initial arguments.
$this->set_initial_args();
// Register hooks.
$this->hooks();
}
/**
* Check if the pointer is already dismissed or interacted with.
*
* @since 1.8.8
*
* @return bool
*/
private function allow_display(): bool {
// If the pointer ID is empty, return.
// Check if announcements are allowed to be displayed.
if ( empty( $this->pointer_id ) || wpforms_setting( 'hide-announcements' ) ) {
return false;
}
// Get pointers.
$pointers = (array) get_option( self::OPTION_NAME, [] );
// Check if the pointer ID exists in the engagement list.
if ( isset( $pointers['engagement'] ) && in_array( $this->pointer_id, (array) $pointers['engagement'], true ) ) {
return false;
}
// Check if the pointer ID exists in the dismissed list.
if ( isset( $pointers['dismiss'] ) && in_array( $this->pointer_id, (array) $pointers['dismiss'], true ) ) {
return false;
}
return true;
}
/**
* Register hooks for the pointer.
*
* @since 1.8.8
*/
private function hooks(): void {
// Enqueue assets.
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
// Print the pointer script.
add_action( 'admin_print_footer_scripts', [ $this, 'print_script' ] );
// Add Ajax callback for the engagement.
add_action( 'wp_ajax_wpforms_education_pointers_engagement', [ $this, 'engagement_callback' ] );
// Add Ajax callback for dismissing the pointer.
add_action( 'wp_ajax_wpforms_education_pointers_dismiss', [ $this, 'dismiss_callback' ] );
}
/**
* Enqueue assets for the pointer.
*
* @since 1.8.8
*/
public function enqueue_assets() {
// Enqueue the pointer CSS.
wp_enqueue_style( 'wp-pointer' );
// Enqueue the pointer script.
wp_enqueue_script( 'wp-pointer' );
}
/**
* Print the pointer script.
*
* @since 1.8.8
*/
public function print_script(): void {
// Encode the $args array into JSON format.
$encoded_args = $this->get_prepared_args();
if ( empty( $encoded_args ) ) {
return;
}
// Sanitize pointer ID and selector.
$pointer_id = sanitize_text_field( $this->pointer_id );
$selector = sanitize_text_field( $this->get_selector() );
// Get the admin-ajax URL.
$ajaxurl = esc_url_raw( admin_url( 'admin-ajax.php' ) );
// Create nonce for the pointer.
$nonce = sanitize_text_field( $this->get_nonce_token() );
// Menu flyout selector.
$menu_flyout = "{$this->top_level_menu}:not(.wp-menu-open)";
// Inline CSS style id.
$inline_css_id = "wpforms-{$pointer_id}-inline-css";
// The type of echo being used in this PHP code is a HEREDOC syntax.
// HEREDOC allows you to create strings that span multiple lines without
// needing to concatenate them with dots (.) as you would with double quotes.
// phpcs:disable
echo <<
( function( $ ) {
let options = $encoded_args, setup;
if ( ! options ) {
return;
}
options = $.extend( options, {
show: function() {
if ( ! $( '#$inline_css_id' ).length && $( '$menu_flyout' ).length ) {
$( '