is_rtl() ? 'right' : 'left', 'align' => 'bottom', ]; if ( isset( $args['position'] ) ) { $args['position'] = wp_parse_args( (array) $args['position'], $default_position ); } $this->slug = $slug; $this->args = wp_parse_args( $args, [ 'selector' => '', 'description' => '', 'heading' => '', 'subheading' => '', 'position' => $default_position, 'class' => '', 'active_callback' => null, ] ); } /** * Gets the pointer slug. * * @since 1.2 * * @return string Unique pointer slug. */ public function get_slug() { return $this->slug; } /** * Checks whether the pointer is active. * * This method executes the active callback and looks at whether the pointer has been dismissed in order to * determine whether the pointer should be active or not. * * @since 1.2 * * @param string $hook_suffix The current admin screen hook suffix. * @return bool True if the pointer is active, false otherwise. */ public function is_active( $hook_suffix ) { if ( ! $this->args['selector'] || ! $this->args['description'] ) { return false; } if ( ! $this->args['active_callback'] ) { return true; } if ( ! call_user_func( $this->args['active_callback'], $hook_suffix ) ) { return false; } // Populate dismissed pointers list only once. if ( null === self::$dismissed_pointers ) { // Use array_flip() for more performant lookup. self::$dismissed_pointers = array_flip( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ); } return ! isset( self::$dismissed_pointers[ $this->slug ] ); } /** * Enqueues the script for the pointer. * * @since 1.2 */ public function enqueue() { wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); wp_enqueue_style( 'amp-validation-tooltips', amp_get_asset_url( 'css/amp-validation-tooltips.css' ), [ 'wp-pointer' ], AMP__VERSION ); wp_styles()->add_data( 'amp-validation-tooltips', 'rtl', 'replace' ); add_action( 'admin_print_footer_scripts', function() { $this->print_js(); } ); } /** * Prints the script for the pointer inline. * * Requires the 'wp-pointer' script to be loaded. * * @since 1.2 */ private function print_js() { $content = '

' . wp_kses( $this->args['description'], 'amp_admin_pointer' ) . '

'; if ( $this->args['subheading'] ) { $content = '

' . wp_kses( $this->args['subheading'], 'amp_admin_pointer' ) . '

' . $content; } if ( $this->args['heading'] ) { $content = '

' . wp_kses( $this->args['heading'], 'amp_admin_pointer' ) . '

' . $content; } $args = [ 'content' => $content, 'position' => $this->args['position'], 'pointerClass' => 'wp-pointer wp-amp-pointer' . ( ! empty( $this->args['class'] ) ? ' ' . $this->args['class'] : '' ), ]; ?>