[ 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          );
  32          parent::__construct( 'meta', __( 'Meta' ), $widget_ops );
  33      }
  34  
  35      /**
  36       * Outputs the content for the current Meta widget instance.
  37       *
  38       * @since 2.8.0
  39       *
  40       * @param array $args     Display arguments including 'before_title', 'after_title',
  41       *                        'before_widget', and 'after_widget'.
  42       * @param array $instance Settings for the current Meta widget instance.
  43       */
  44  	public function widget( $args, $instance ) {
  45          $default_title = __( 'Meta' );
  46          $title         = ! empty( $instance['title'] ) ? $instance['title'] : $default_title;
  47  
  48          /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
  49          $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  50  
  51          echo $args['before_widget'];
  52  
  53          if ( $title ) {
  54              echo $args['before_title'] . $title . $args['after_title'];
  55          }
  56  
  57          $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
  58  
  59          /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */
  60          $format = apply_filters( 'navigation_widgets_format', $format );
  61  
  62          if ( 'html5' === $format ) {
  63              // The title may be filtered: Strip out HTML and make sure the aria-label is never empty.
  64              $title      = trim( strip_tags( $title ) );
  65              $aria_label = $title ? $title : $default_title;
  66              echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
  67          }
  68          ?>
  69  
  70          <ul>
  71              <?php wp_register(); ?>
  72              <li><?php wp_loginout(); ?></li>
  73              <li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e( 'Entries feed' ); ?></a></li>
  74              <li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e( 'Comments feed' ); ?></a></li>
  75  
  76              <?php
  77              /**
  78               * Filters the "WordPress.org" list item HTML in the Meta widget.
  79               *
  80               * @since 3.6.0
  81               * @since 4.9.0 Added the `$instance` parameter.
  82               *
  83               * @param string $html     Default HTML for the WordPress.org list item.
  84               * @param array  $instance Array of settings for the current widget.
  85               */
  86              echo apply_filters(
  87                  'widget_meta_poweredby',
  88                  sprintf(
  89                      '<li><a href="%1$s">%2$s</a></li>',
  90                      esc_url( __( 'https://wordpress.org/' ) ),
  91                      __( 'WordPress.org' )
  92                  ),
  93                  $instance
  94              );
  95  
  96              wp_meta();
  97              ?>
  98  
  99          </ul>
 100  
 101          <?php
 102          if ( 'html5' === $format ) {
 103              echo '</nav>';
 104          }
 105  
 106          echo $args['after_widget'];
 107      }
 108  
 109      /**
 110       * Handles updating settings for the current Meta widget instance.
 111       *
 112       * @since 2.8.0
 113       *
 114       * @param array $new_instance New settings for this instance as input by the user via
 115       *                            WP_Widget::form().
 116       * @param array $old_instance Old settings for this instance.
 117       * @return array Updated settings to save.
 118       */
 119  	public function update( $new_instance, $old_instance ) {
 120          $instance          = $old_instance;
 121          $instance['title'] = sanitize_text_field( $new_instance['title'] );
 122  
 123          return $instance;
 124      }
 125  
 126      /**
 127       * Outputs the settings form for the Meta widget.
 128       *
 129       * @since 2.8.0
 130       *
 131       * @param array $instance Current settings.
 132       */
 133  	public function form( $instance ) {
 134          $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
 135          ?>
 136          <p>
 137              <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
 138              <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'] ); ?>" />
 139          </p>
 140          <?php
 141      }
 142  }


Generated: Tue Dec 1 01:00:04 2020 Cross-referenced by PHPXref 0.7.1