[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/widgets/ -> class-wp-widget-meta.php (source)

   1  <?php
   2  /**
   3   * Widget API: WP_Widget_Meta class
   4   *
   5   * @package WordPress
   6   * @subpackage Widgets
   7   * @since 4.4.0
   8   */
   9  
  10  /**
  11   * Core class used to implement a Meta widget.
  12   *
  13   * Displays log in/out, RSS feed links, etc.
  14   *
  15   * @since 2.8.0
  16   *
  17   * @see WP_Widget
  18   */
  19  class WP_Widget_Meta extends WP_Widget {
  20  
  21      /**
  22       * Sets up a new Meta widget instance.
  23       *
  24       * @since 2.8.0
  25       */
  26  	public function __construct() {
  27          $widget_ops = array(
  28              'classname'                   => 'widget_meta',
  29              'description'                 => __( 'Login, RSS, &amp; WordPress.org links.' ),
  30              'customize_selective_refresh' => true,
  31              'show_instance_in_rest'       => true,
  32          );
  33          parent::__construct( 'meta', __( 'Meta' ), $widget_ops );
  34      }
  35  
  36      /**
  37       * Outputs the content for the current Meta widget instance.
  38       *
  39       * @since 2.8.0
  40       *
  41       * @param array $args     Display arguments including 'before_title', 'after_title',
  42       *                        'before_widget', and 'after_widget'.
  43       * @param array $instance Settings for the current Meta widget instance.
  44       */
  45  	public function widget( $args, $instance ) {
  46          $default_title = __( 'Meta' );
  47          $title         = ! empty( $instance['title'] ) ? $instance['title'] : $default_title;
  48  
  49          /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
  50          $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  51  
  52          echo $args['before_widget'];
  53  
  54          if ( $title ) {
  55              echo $args['before_title'] . $title . $args['after_title'];
  56          }
  57  
  58          $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
  59  
  60          /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */
  61          $format = apply_filters( 'navigation_widgets_format', $format );
  62  
  63          if ( 'html5' === $format ) {
  64              // The title may be filtered: Strip out HTML and make sure the aria-label is never empty.
  65              $title      = trim( strip_tags( $title ) );
  66              $aria_label = $title ? $title : $default_title;
  67              echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
  68          }
  69          ?>
  70  
  71          <ul>
  72              <?php wp_register(); ?>
  73              <li><?php wp_loginout(); ?></li>
  74              <li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e( 'Entries feed' ); ?></a></li>
  75              <li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e( 'Comments feed' ); ?></a></li>
  76  
  77              <?php
  78              /**
  79               * Filters the "WordPress.org" list item HTML in the Meta widget.
  80               *
  81               * @since 3.6.0
  82               * @since 4.9.0 Added the `$instance` parameter.
  83               *
  84               * @param string $html     Default HTML for the WordPress.org list item.
  85               * @param array  $instance Array of settings for the current widget.
  86               */
  87              echo apply_filters(
  88                  'widget_meta_poweredby',
  89                  sprintf(
  90                      '<li><a href="%1$s">%2$s</a></li>',
  91                      esc_url( __( 'https://wordpress.org/' ) ),
  92                      __( 'WordPress.org' )
  93                  ),
  94                  $instance
  95              );
  96  
  97              wp_meta();
  98              ?>
  99  
 100          </ul>
 101  
 102          <?php
 103          if ( 'html5' === $format ) {
 104              echo '</nav>';
 105          }
 106  
 107          echo $args['after_widget'];
 108      }
 109  
 110      /**
 111       * Handles updating settings for the current Meta widget instance.
 112       *
 113       * @since 2.8.0
 114       *
 115       * @param array $new_instance New settings for this instance as input by the user via
 116       *                            WP_Widget::form().
 117       * @param array $old_instance Old settings for this instance.
 118       * @return array Updated settings to save.
 119       */
 120  	public function update( $new_instance, $old_instance ) {
 121          $instance          = $old_instance;
 122          $instance['title'] = sanitize_text_field( $new_instance['title'] );
 123  
 124          return $instance;
 125      }
 126  
 127      /**
 128       * Outputs the settings form for the Meta widget.
 129       *
 130       * @since 2.8.0
 131       *
 132       * @param array $instance Current settings.
 133       */
 134  	public function form( $instance ) {
 135          $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
 136          ?>
 137          <p>
 138              <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
 139              <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
 140          </p>
 141          <?php
 142      }
 143  }


Generated: Mon Oct 25 01:00:03 2021 Cross-referenced by PHPXref 0.7.1