true, 'classname' => 'widget_text primer-widgets primer-hero-text-widget', 'description' => sprintf( /* translators: theme name */ esc_html__( "A %s theme widget designed for the Hero area on your site's front page.", 'primer' ), esc_html( $this->get_current_theme_name() ) ), ); parent::__construct( 'primer-hero-text', /* translators: the widget title */ esc_html__( 'Hero Text', 'primer' ), $widget_options ); add_action( 'admin_init', array( $this, 'register_scripts' ) ); } /** * Display the widget on the front-end. * * @since 1.6.0 * * @param array $args Display arguments including `before_title`, `after_title`, `before_widget`, and `after_widget`. * @param array $instance The settings for the particular instance of the widget. */ public function widget( $args, $instance ) { /** * Filter the widget title. * * @link https://developer.wordpress.org/reference/hooks/widget_title/ * @since 1.6.0 * * @param array $instance An array of the widget's settings. * @param string $id_base The widget ID. * * @var string */ $title = ! empty( $instance['title'] ) ? (string) apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) : null; /** * Filter the widget text. * * @link https://developer.wordpress.org/reference/hooks/widget_text/ * @since 1.6.0 * * @param array $instance Array of settings for the current widget. * @param Primer_Hero_Text_Widget $this Current Hero Text widget instance. * * @var string */ $text = ! empty( $instance['text'] ) ? (string) apply_filters( 'widget_text', $instance['text'], $instance, $this ) : null; $button_text = ! empty( $instance['button_text'] ) ? $instance['button_text'] : null; $button_link = ! empty( $instance['button_link'] ) ? $instance['button_link'] : null; // The `button_link` can be empty. if ( ! $title && ! $text && ! $button_text ) { return; } echo $args['before_widget']; // xss ok. ?>
wp_create_nonce( 'internal-linking' ), ) ); } /** * Print widget admin scripts. * * @action admin_print_footer_scripts * @action customize_controls_print_footer_scripts * @since 1.6.0 */ public function print_scripts() { wp_print_scripts( 'primer-admin-hero-text-widget' ); } /** * Return the current theme name. * * Looks for the `current_theme` option first, and if not * present will fetch it using `wp_get_theme()`. * * @since 1.6.0 * * @return string */ protected function get_current_theme_name() { if ( $current_theme = get_option( 'current_theme' ) ) { return $current_theme; } $theme = wp_get_theme(); return $theme->get( 'Name' ); } }