class-wp-widget-meta.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. );
  30. parent::__construct( 'meta', __( 'Meta' ), $widget_ops );
  31. }
  32. /**
  33. * Outputs the content for the current Meta widget instance.
  34. *
  35. * @since 2.8.0
  36. *
  37. * @param array $args Display arguments including 'before_title', 'after_title',
  38. * 'before_widget', and 'after_widget'.
  39. * @param array $instance Settings for the current Meta widget instance.
  40. */
  41. public function widget( $args, $instance ) {
  42. $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Meta' );
  43. /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
  44. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  45. echo $args['before_widget'];
  46. if ( $title ) {
  47. echo $args['before_title'] . $title . $args['after_title'];
  48. }
  49. ?>
  50. <ul>
  51. <?php wp_register(); ?>
  52. <li><?php wp_loginout(); ?></li>
  53. <li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e( 'Entries feed' ); ?></a></li>
  54. <li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e( 'Comments feed' ); ?></a></li>
  55. <?php
  56. /**
  57. * Filters the "WordPress.org" list item HTML in the Meta widget.
  58. *
  59. * @since 3.6.0
  60. * @since 4.9.0 Added the `$instance` parameter.
  61. *
  62. * @param string $html Default HTML for the WordPress.org list item.
  63. * @param array $instance Array of settings for the current widget.
  64. */
  65. echo apply_filters(
  66. 'widget_meta_poweredby',
  67. sprintf(
  68. '<li><a href="%1$s">%2$s</a></li>',
  69. esc_url( __( 'https://wordpress.org/' ) ),
  70. __( 'WordPress.org' )
  71. ),
  72. $instance
  73. );
  74. wp_meta();
  75. ?>
  76. </ul>
  77. <?php
  78. echo $args['after_widget'];
  79. }
  80. /**
  81. * Handles updating settings for the current Meta widget instance.
  82. *
  83. * @since 2.8.0
  84. *
  85. * @param array $new_instance New settings for this instance as input by the user via
  86. * WP_Widget::form().
  87. * @param array $old_instance Old settings for this instance.
  88. * @return array Updated settings to save.
  89. */
  90. public function update( $new_instance, $old_instance ) {
  91. $instance = $old_instance;
  92. $instance['title'] = sanitize_text_field( $new_instance['title'] );
  93. return $instance;
  94. }
  95. /**
  96. * Outputs the settings form for the Meta widget.
  97. *
  98. * @since 2.8.0
  99. *
  100. * @param array $instance Current settings.
  101. */
  102. public function form( $instance ) {
  103. $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  104. ?>
  105. <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> <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'] ); ?>" /></p>
  106. <?php
  107. }
  108. }