class-wp-widget-meta.php 4.0 KB

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