Update WP and plugins

This commit is contained in:
Oliver Davies 2019-04-16 20:56:22 +01:00
parent 10a4713229
commit 1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions

View file

@ -23,10 +23,10 @@ class WP_Nav_Menu_Widget extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'description' => __( 'Add a navigation menu to your sidebar.' ),
'description' => __( 'Add a navigation menu to your sidebar.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'nav_menu', __('Navigation Menu'), $widget_ops );
parent::__construct( 'nav_menu', __( 'Navigation Menu' ), $widget_ops );
}
/**
@ -59,7 +59,7 @@ class WP_Nav_Menu_Widget extends WP_Widget {
$nav_menu_args = array(
'fallback_cb' => '',
'menu' => $nav_menu
'menu' => $nav_menu,
);
/**
@ -114,15 +114,27 @@ class WP_Nav_Menu_Widget extends WP_Widget {
*/
public function form( $instance ) {
global $wp_customize;
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
// Get menus
$menus = wp_get_nav_menus();
$empty_menus_style = $not_empty_menus_style = '';
if ( empty( $menus ) ) {
$empty_menus_style = ' style="display:none" ';
} else {
$not_empty_menus_style = ' style="display:none" ';
}
$nav_menu_style = '';
if ( ! $nav_menu ) {
$nav_menu_style = 'display: none;';
}
// If no menus exists, direct the user to go and create some.
?>
<p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>>
<p class="nav-menu-widget-no-menus-message" <?php echo $not_empty_menus_style; ?>>
<?php
if ( $wp_customize instanceof WP_Customize_Manager ) {
$url = 'javascript: wp.customize.panel( "nav_menus" ).focus();';
@ -132,9 +144,9 @@ class WP_Nav_Menu_Widget extends WP_Widget {
?>
<?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?>
</p>
<div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>>
<div class="nav-menu-widget-form-controls" <?php echo $empty_menus_style; ?>>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>"/>
</p>
<p>
@ -149,8 +161,8 @@ class WP_Nav_Menu_Widget extends WP_Widget {
</select>
</p>
<?php if ( $wp_customize instanceof WP_Customize_Manager ) : ?>
<p class="edit-selected-nav-menu" style="<?php if ( ! $nav_menu ) { echo 'display: none;'; } ?>">
<button type="button" class="button"><?php _e( 'Edit Menu' ) ?></button>
<p class="edit-selected-nav-menu" style="<?php echo $nav_menu_style; ?>">
<button type="button" class="button"><?php _e( 'Edit Menu' ); ?></button>
</p>
<?php endif; ?>
</div>

View file

@ -23,11 +23,11 @@ class WP_Widget_Archives extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_archive',
'description' => __( 'A monthly archive of your site&#8217;s Posts.' ),
'classname' => 'widget_archive',
'description' => __( 'A monthly archive of your site&#8217;s Posts.' ),
'customize_selective_refresh' => true,
);
parent::__construct('archives', __('Archives'), $widget_ops);
parent::__construct( 'archives', __( 'Archives' ), $widget_ops );
}
/**
@ -71,11 +71,15 @@ class WP_Widget_Archives extends WP_Widget {
* @param array $args An array of Archives widget drop-down arguments.
* @param array $instance Settings for the current Archives widget instance.
*/
$dropdown_args = apply_filters( 'widget_archives_dropdown_args', array(
'type' => 'monthly',
'format' => 'option',
'show_post_count' => $c
), $instance );
$dropdown_args = apply_filters(
'widget_archives_dropdown_args',
array(
'type' => 'monthly',
'format' => 'option',
'show_post_count' => $c,
),
$instance
);
switch ( $dropdown_args['type'] ) {
case 'yearly':
@ -102,25 +106,31 @@ class WP_Widget_Archives extends WP_Widget {
</select>
<?php } else { ?>
<ul>
<?php
/**
* Filters the arguments for the Archives widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
*/
wp_get_archives( apply_filters( 'widget_archives_args', array(
'type' => 'monthly',
'show_post_count' => $c
), $instance ) );
?>
<?php
/**
* Filters the arguments for the Archives widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
*/
wp_get_archives(
apply_filters(
'widget_archives_args',
array(
'type' => 'monthly',
'show_post_count' => $c,
),
$instance
)
);
?>
</ul>
<?php
<?php
}
echo $args['after_widget'];
@ -137,10 +147,17 @@ class WP_Widget_Archives extends WP_Widget {
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['count'] = $new_instance['count'] ? 1 : 0;
$instance = $old_instance;
$new_instance = wp_parse_args(
(array) $new_instance,
array(
'title' => '',
'count' => 0,
'dropdown' => '',
)
);
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['count'] = $new_instance['count'] ? 1 : 0;
$instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
return $instance;
@ -154,14 +171,20 @@ class WP_Widget_Archives extends WP_Widget {
* @param array $instance Current settings.
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
$title = sanitize_text_field( $instance['title'] );
$instance = wp_parse_args(
(array) $instance,
array(
'title' => '',
'count' => 0,
'dropdown' => '',
)
);
?>
<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($title); ?>" /></p>
<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>
<p>
<input class="checkbox" type="checkbox"<?php checked( $instance['dropdown'] ); ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label>
<input class="checkbox" type="checkbox"<?php checked( $instance['dropdown'] ); ?> id="<?php echo $this->get_field_id( 'dropdown' ); ?>" name="<?php echo $this->get_field_name( 'dropdown' ); ?>" /> <label for="<?php echo $this->get_field_id( 'dropdown' ); ?>"><?php _e( 'Display as dropdown' ); ?></label>
<br/>
<input class="checkbox" type="checkbox"<?php checked( $instance['count'] ); ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label>
<input class="checkbox" type="checkbox"<?php checked( $instance['count'] ); ?> id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" /> <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show post counts' ); ?></label>
</p>
<?php
}

View file

@ -19,8 +19,6 @@ class WP_Widget_Calendar extends WP_Widget {
* Ensure that the ID attribute only appears in the markup once
*
* @since 4.4.0
*
* @static
* @var int
*/
private static $instance = 0;
@ -32,8 +30,8 @@ class WP_Widget_Calendar extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_calendar',
'description' => __( 'A calendar of your site&#8217;s Posts.' ),
'classname' => 'widget_calendar',
'description' => __( 'A calendar of your site&#8217;s Posts.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'calendar', __( 'Calendar' ), $widget_ops );
@ -81,7 +79,7 @@ class WP_Widget_Calendar extends WP_Widget {
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
return $instance;
@ -96,10 +94,9 @@ class WP_Widget_Calendar extends WP_Widget {
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = sanitize_text_field( $instance['title'] );
?>
<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($title); ?>" /></p>
<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>
<?php
}
}

View file

@ -23,8 +23,8 @@ class WP_Widget_Categories extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_categories',
'description' => __( 'A list or dropdown of categories.' ),
'classname' => 'widget_categories',
'description' => __( 'A list or dropdown of categories.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'categories', __( 'Categories' ), $widget_ops );
@ -67,13 +67,13 @@ class WP_Widget_Categories extends WP_Widget {
if ( $d ) {
echo sprintf( '<form action="%s" method="get">', esc_url( home_url() ) );
$dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
$dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
$first_dropdown = false;
echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';
$cat_args['show_option_none'] = __( 'Select Category' );
$cat_args['id'] = $dropdown_id;
$cat_args['id'] = $dropdown_id;
/**
* Filters the arguments for the Categories widget drop-down.
@ -105,26 +105,26 @@ class WP_Widget_Categories extends WP_Widget {
/* ]]> */
</script>
<?php
<?php
} else {
?>
?>
<ul>
<?php
$cat_args['title_li'] = '';
<?php
$cat_args['title_li'] = '';
/**
* Filters the arguments for the Categories widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @param array $cat_args An array of Categories widget options.
* @param array $instance Array of settings for the current widget.
*/
wp_list_categories( apply_filters( 'widget_categories_args', $cat_args, $instance ) );
?>
/**
* Filters the arguments for the Categories widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @param array $cat_args An array of Categories widget options.
* @param array $instance Array of settings for the current widget.
*/
wp_list_categories( apply_filters( 'widget_categories_args', $cat_args, $instance ) );
?>
</ul>
<?php
<?php
}
echo $args['after_widget'];
@ -141,11 +141,11 @@ class WP_Widget_Categories extends WP_Widget {
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['count'] = !empty($new_instance['count']) ? 1 : 0;
$instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
$instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['count'] = ! empty( $new_instance['count'] ) ? 1 : 0;
$instance['hierarchical'] = ! empty( $new_instance['hierarchical'] ) ? 1 : 0;
$instance['dropdown'] = ! empty( $new_instance['dropdown'] ) ? 1 : 0;
return $instance;
}
@ -159,23 +159,22 @@ class WP_Widget_Categories extends WP_Widget {
*/
public function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
$title = sanitize_text_field( $instance['title'] );
$count = isset($instance['count']) ? (bool) $instance['count'] :false;
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$count = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
$hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
$dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
$dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
?>
<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( $title ); ?>" /></p>
<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>
<p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
<label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
<p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'dropdown' ); ?>" name="<?php echo $this->get_field_name( 'dropdown' ); ?>"<?php checked( $dropdown ); ?> />
<label for="<?php echo $this->get_field_id( 'dropdown' ); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
<label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>"<?php checked( $count ); ?> />
<label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show post counts' ); ?></label><br />
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
<label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'hierarchical' ); ?>" name="<?php echo $this->get_field_name( 'hierarchical' ); ?>"<?php checked( $hierarchical ); ?> />
<label for="<?php echo $this->get_field_id( 'hierarchical' ); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
<?php
}

View file

@ -31,7 +31,7 @@ class WP_Widget_Custom_HTML extends WP_Widget {
* @var array
*/
protected $default_instance = array(
'title' => '',
'title' => '',
'content' => '',
);
@ -41,13 +41,13 @@ class WP_Widget_Custom_HTML extends WP_Widget {
* @since 4.8.1
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_custom_html',
'description' => __( 'Arbitrary HTML code.' ),
$widget_ops = array(
'classname' => 'widget_custom_html',
'description' => __( 'Arbitrary HTML code.' ),
'customize_selective_refresh' => true,
);
$control_ops = array(
'width' => 400,
'width' => 400,
'height' => 350,
);
parent::__construct( 'custom_html', __( 'Custom HTML' ), $widget_ops, $control_ops );
@ -130,11 +130,14 @@ class WP_Widget_Custom_HTML extends WP_Widget {
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
// Prepare instance data that looks like a normal Text widget.
$simulated_text_widget_instance = array_merge( $instance, array(
'text' => isset( $instance['content'] ) ? $instance['content'] : '',
'filter' => false, // Because wpautop is not applied.
'visual' => false, // Because it wasn't created in TinyMCE.
) );
$simulated_text_widget_instance = array_merge(
$instance,
array(
'text' => isset( $instance['content'] ) ? $instance['content'] : '',
'filter' => false, // Because wpautop is not applied.
'visual' => false, // Because it wasn't created in TinyMCE.
)
);
unset( $simulated_text_widget_instance['content'] ); // Was moved to 'text' prop.
/** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
@ -179,7 +182,7 @@ class WP_Widget_Custom_HTML extends WP_Widget {
* @return array Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance ) {
$instance = array_merge( $this->default_instance, $old_instance );
$instance = array_merge( $this->default_instance, $old_instance );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
if ( current_user_can( 'unfiltered_html' ) ) {
$instance['content'] = $new_instance['content'];
@ -195,13 +198,15 @@ class WP_Widget_Custom_HTML extends WP_Widget {
* @since 4.9.0
*/
public function enqueue_admin_scripts() {
$settings = wp_enqueue_code_editor( array(
'type' => 'text/html',
'codemirror' => array(
'indentUnit' => 2,
'tabSize' => 2,
),
) );
$settings = wp_enqueue_code_editor(
array(
'type' => 'text/html',
'codemirror' => array(
'indentUnit' => 2,
'tabSize' => 2,
),
)
);
wp_enqueue_script( 'custom-html-widgets' );
if ( empty( $settings ) ) {
@ -216,7 +221,7 @@ class WP_Widget_Custom_HTML extends WP_Widget {
/* translators: %d: error count */
'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ),
/* translators: %d: error count */
'plural' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
'plural' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
),
);
wp_add_inline_script( 'custom-html-widgets', sprintf( 'jQuery.extend( wp.customHtmlWidgets.l10n, %s );', wp_json_encode( $l10n ) ), 'after' );
@ -262,8 +267,8 @@ class WP_Widget_Custom_HTML extends WP_Widget {
<?php if ( ! current_user_can( 'unfiltered_html' ) ) : ?>
<?php
$probably_unsafe_html = array( 'script', 'iframe', 'form', 'input', 'style' );
$allowed_html = wp_kses_allowed_html( 'post' );
$disallowed_html = array_diff( $probably_unsafe_html, array_keys( $allowed_html ) );
$allowed_html = wp_kses_allowed_html( 'post' );
$disallowed_html = array_diff( $probably_unsafe_html, array_keys( $allowed_html ) );
?>
<?php if ( ! empty( $disallowed_html ) ) : ?>
<# if ( data.codeEditorDisabled ) { #>
@ -288,7 +293,7 @@ class WP_Widget_Custom_HTML extends WP_Widget {
public static function add_help_text() {
$screen = get_current_screen();
$content = '<p>';
$content = '<p>';
$content .= __( 'Use the Custom HTML widget to add arbitrary HTML code to your widget areas.' );
$content .= '</p>';
@ -299,9 +304,10 @@ class WP_Widget_Custom_HTML extends WP_Widget {
__( 'The edit field automatically highlights code syntax. You can disable this in your <a href="%1$s" %2$s>user profile%3$s</a> to work in plain text mode.' ),
esc_url( get_edit_profile_url() ),
'class="external-link" target="_blank"',
sprintf( '<span class="screen-reader-text"> %s</span>',
sprintf(
'<span class="screen-reader-text"> %s</span>',
/* translators: accessibility text */
__( '(opens in a new window)' )
__( '(opens in a new tab)' )
)
);
$content .= '</p>';
@ -314,10 +320,12 @@ class WP_Widget_Custom_HTML extends WP_Widget {
$content .= '</ul>';
}
$screen->add_help_tab( array(
'id' => 'custom_html_widget',
'title' => __( 'Custom HTML Widget' ),
'content' => $content,
) );
$screen->add_help_tab(
array(
'id' => 'custom_html_widget',
'title' => __( 'Custom HTML Widget' ),
'content' => $content,
)
);
}
}

View file

@ -23,7 +23,7 @@ class WP_Widget_Links extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'description' => __( 'Your blogroll' ),
'description' => __( 'Your blogroll' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'links', __( 'Links' ), $widget_ops );
@ -39,14 +39,14 @@ class WP_Widget_Links extends WP_Widget {
* @param array $instance Settings for the current Links widget instance.
*/
public function widget( $args, $instance ) {
$show_description = isset($instance['description']) ? $instance['description'] : false;
$show_name = isset($instance['name']) ? $instance['name'] : false;
$show_rating = isset($instance['rating']) ? $instance['rating'] : false;
$show_images = isset($instance['images']) ? $instance['images'] : true;
$category = isset($instance['category']) ? $instance['category'] : false;
$orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
$order = $orderby == 'rating' ? 'DESC' : 'ASC';
$limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
$show_description = isset( $instance['description'] ) ? $instance['description'] : false;
$show_name = isset( $instance['name'] ) ? $instance['name'] : false;
$show_rating = isset( $instance['rating'] ) ? $instance['rating'] : false;
$show_images = isset( $instance['images'] ) ? $instance['images'] : true;
$category = isset( $instance['category'] ) ? $instance['category'] : false;
$orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
$order = $orderby == 'rating' ? 'DESC' : 'ASC';
$limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
$before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] );
@ -92,18 +92,25 @@ class WP_Widget_Links extends WP_Widget {
*/
public function update( $new_instance, $old_instance ) {
$new_instance = (array) $new_instance;
$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
$instance = array(
'images' => 0,
'name' => 0,
'description' => 0,
'rating' => 0,
);
foreach ( $instance as $field => $val ) {
if ( isset($new_instance[$field]) )
$instance[$field] = 1;
if ( isset( $new_instance[ $field ] ) ) {
$instance[ $field ] = 1;
}
}
$instance['orderby'] = 'name';
if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) {
$instance['orderby'] = $new_instance['orderby'];
}
$instance['category'] = intval( $new_instance['category'] );
$instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
$instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
return $instance;
}
@ -118,15 +125,27 @@ class WP_Widget_Links extends WP_Widget {
public function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
$instance = wp_parse_args(
(array) $instance,
array(
'images' => true,
'name' => true,
'description' => false,
'rating' => false,
'category' => false,
'orderby' => 'name',
'limit' => -1,
)
);
$link_cats = get_terms( 'link_category' );
if ( ! $limit = intval( $instance['limit'] ) )
if ( ! $limit = intval( $instance['limit'] ) ) {
$limit = -1;
?>
}
?>
<p>
<label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
<option value=""><?php _ex('All Links', 'links widget'); ?></option>
<label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Select Link Category:' ); ?></label>
<select class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>">
<option value=""><?php _ex( 'All Links', 'links widget' ); ?></option>
<?php
foreach ( $link_cats as $link_cat ) {
echo '<option value="' . intval( $link_cat->term_id ) . '"'
@ -135,8 +154,8 @@ class WP_Widget_Links extends WP_Widget {
}
?>
</select>
<label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
<select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
<label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Sort by:' ); ?></label>
<select name="<?php echo $this->get_field_name( 'orderby' ); ?>" id="<?php echo $this->get_field_id( 'orderby' ); ?>" class="widefat">
<option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
<option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
<option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
@ -144,18 +163,18 @@ class WP_Widget_Links extends WP_Widget {
</select>
</p>
<p>
<input class="checkbox" type="checkbox"<?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" />
<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
<input class="checkbox" type="checkbox"<?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" />
<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
<input class="checkbox" type="checkbox"<?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" />
<label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
<input class="checkbox" type="checkbox"<?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
<label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
<input class="checkbox" type="checkbox"<?php checked( $instance['images'], true ); ?> id="<?php echo $this->get_field_id( 'images' ); ?>" name="<?php echo $this->get_field_name( 'images' ); ?>" />
<label for="<?php echo $this->get_field_id( 'images' ); ?>"><?php _e( 'Show Link Image' ); ?></label><br />
<input class="checkbox" type="checkbox"<?php checked( $instance['name'], true ); ?> id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" />
<label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e( 'Show Link Name' ); ?></label><br />
<input class="checkbox" type="checkbox"<?php checked( $instance['description'], true ); ?> id="<?php echo $this->get_field_id( 'description' ); ?>" name="<?php echo $this->get_field_name( 'description' ); ?>" />
<label for="<?php echo $this->get_field_id( 'description' ); ?>"><?php _e( 'Show Link Description' ); ?></label><br />
<input class="checkbox" type="checkbox"<?php checked( $instance['rating'], true ); ?> id="<?php echo $this->get_field_id( 'rating' ); ?>" name="<?php echo $this->get_field_name( 'rating' ); ?>" />
<label for="<?php echo $this->get_field_id( 'rating' ); ?>"><?php _e( 'Show Link Rating' ); ?></label>
</p>
<p>
<label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
<input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" />
<label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Number of links to show:' ); ?></label>
<input id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" />
</p>
<?php
}

View file

@ -22,26 +22,33 @@ class WP_Widget_Media_Audio extends WP_Widget_Media {
* @since 4.8.0
*/
public function __construct() {
parent::__construct( 'media_audio', __( 'Audio' ), array(
'description' => __( 'Displays an audio player.' ),
'mime_type' => 'audio',
) );
parent::__construct(
'media_audio',
__( 'Audio' ),
array(
'description' => __( 'Displays an audio player.' ),
'mime_type' => 'audio',
)
);
$this->l10n = array_merge( $this->l10n, array(
'no_media_selected' => __( 'No audio selected' ),
'add_media' => _x( 'Add Audio', 'label for button in the audio widget' ),
'replace_media' => _x( 'Replace Audio', 'label for button in the audio widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Audio', 'label for button in the audio widget; should preferably not be longer than ~13 characters long' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library */
__( 'We can&#8217;t find that audio file. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: widget count */
'media_library_state_multi' => _n_noop( 'Audio Widget (%d)', 'Audio Widget (%d)' ),
'media_library_state_single' => __( 'Audio Widget' ),
'unsupported_file_type' => __( 'Looks like this isn&#8217;t the correct kind of file. Please link to an audio file instead.' ),
) );
$this->l10n = array_merge(
$this->l10n,
array(
'no_media_selected' => __( 'No audio selected' ),
'add_media' => _x( 'Add Audio', 'label for button in the audio widget' ),
'replace_media' => _x( 'Replace Audio', 'label for button in the audio widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Audio', 'label for button in the audio widget; should preferably not be longer than ~13 characters long' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library */
__( 'We can&#8217;t find that audio file. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: widget count */
'media_library_state_multi' => _n_noop( 'Audio Widget (%d)', 'Audio Widget (%d)' ),
'media_library_state_single' => __( 'Audio Widget' ),
'unsupported_file_type' => __( 'Looks like this isn&#8217;t the correct kind of file. Please link to an audio file instead.' ),
)
);
}
/**
@ -59,14 +66,14 @@ class WP_Widget_Media_Audio extends WP_Widget_Media {
parent::get_instance_schema(),
array(
'preload' => array(
'type' => 'string',
'enum' => array( 'none', 'auto', 'metadata' ),
'default' => 'none',
'type' => 'string',
'enum' => array( 'none', 'auto', 'metadata' ),
'default' => 'none',
'description' => __( 'Preload' ),
),
'loop' => array(
'type' => 'boolean',
'default' => false,
'loop' => array(
'type' => 'boolean',
'default' => false,
'description' => __( 'Loop' ),
),
)
@ -74,9 +81,9 @@ class WP_Widget_Media_Audio extends WP_Widget_Media {
foreach ( wp_get_audio_extensions() as $audio_extension ) {
$schema[ $audio_extension ] = array(
'type' => 'string',
'default' => '',
'format' => 'uri',
'type' => 'string',
'default' => '',
'format' => 'uri',
/* translators: %s: audio extension */
'description' => sprintf( __( 'URL to the %s audio source file' ), $audio_extension ),
);
@ -94,7 +101,7 @@ class WP_Widget_Media_Audio extends WP_Widget_Media {
* @return void
*/
public function render_media( $instance ) {
$instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
$instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
$attachment = null;
if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) {
@ -192,7 +199,7 @@ class WP_Widget_Media_Audio extends WP_Widget_Media {
<p><?php _e( 'Unable to preview media due to an unknown error.' ); ?></p>
</div>
<# } else if ( data.model && data.model.src ) { #>
<?php wp_underscore_audio_template() ?>
<?php wp_underscore_audio_template(); ?>
<# } #>
</script>
<?php

View file

@ -22,17 +22,24 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
* @since 4.9.0
*/
public function __construct() {
parent::__construct( 'media_gallery', __( 'Gallery' ), array(
'description' => __( 'Displays an image gallery.' ),
'mime_type' => 'image',
) );
parent::__construct(
'media_gallery',
__( 'Gallery' ),
array(
'description' => __( 'Displays an image gallery.' ),
'mime_type' => 'image',
)
);
$this->l10n = array_merge( $this->l10n, array(
'no_media_selected' => __( 'No images selected' ),
'add_media' => _x( 'Add Images', 'label for button in the gallery widget; should not be longer than ~13 characters long' ),
'replace_media' => '',
'edit_media' => _x( 'Edit Gallery', 'label for button in the gallery widget; should not be longer than ~13 characters long' ),
) );
$this->l10n = array_merge(
$this->l10n,
array(
'no_media_selected' => __( 'No images selected' ),
'add_media' => _x( 'Add Images', 'label for button in the gallery widget; should not be longer than ~13 characters long' ),
'replace_media' => '',
'edit_media' => _x( 'Edit Gallery', 'label for button in the gallery widget; should not be longer than ~13 characters long' ),
)
);
}
/**
@ -47,37 +54,37 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
*/
public function get_instance_schema() {
$schema = array(
'title' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'description' => __( 'Title for the widget' ),
'title' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'description' => __( 'Title for the widget' ),
'should_preview_update' => false,
),
'ids' => array(
'type' => 'array',
'items' => array(
'ids' => array(
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
),
'columns' => array(
'type' => 'integer',
'columns' => array(
'type' => 'integer',
'default' => 3,
'minimum' => 1,
'maximum' => 9,
),
'size' => array(
'type' => 'string',
'enum' => array_merge( get_intermediate_image_sizes(), array( 'full', 'custom' ) ),
'size' => array(
'type' => 'string',
'enum' => array_merge( get_intermediate_image_sizes(), array( 'full', 'custom' ) ),
'default' => 'thumbnail',
),
'link_type' => array(
'type' => 'string',
'enum' => array( 'post', 'file', 'none' ),
'default' => 'post',
'media_prop' => 'link',
'link_type' => array(
'type' => 'string',
'enum' => array( 'post', 'file', 'none' ),
'default' => 'post',
'media_prop' => 'link',
'should_preview_update' => false,
),
'orderby_random' => array(
@ -169,15 +176,15 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
?>
<script type="text/html" id="tmpl-wp-media-widget-gallery-preview">
<# var describedById = 'describedBy-' + String( Math.random() ); #>
<# if ( data.ids.length ) { #>
<#
var ids = _.filter( data.ids, function( id ) {
return ( id in data.attachments );
} );
#>
<# if ( ids.length ) { #>
<div class="gallery media-widget-gallery-preview">
<# _.each( data.ids, function( id, index ) { #>
<#
var attachment = data.attachments[ id ];
if ( ! attachment ) {
return;
}
#>
<# _.each( ids, function( id, index ) { #>
<# var attachment = data.attachments[ id ]; #>
<# if ( index < 6 ) { #>
<dl class="gallery-item">
<dt class="gallery-icon">
@ -186,9 +193,9 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
<# } else { #>
<img src="{{ attachment.url }}" alt="" />
<# } #>
<# if ( index === 5 && data.ids.length > 6 ) { #>
<# if ( index === 5 && ids.length > 6 ) { #>
<div class="gallery-icon-placeholder">
<p class="gallery-icon-placeholder-text">+{{ data.ids.length - 5 }}</p>
<p class="gallery-icon-placeholder-text">+{{ ids.length - 5 }}</p>
</div>
<# } #>
</dt>

View file

@ -22,25 +22,32 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
* @since 4.8.0
*/
public function __construct() {
parent::__construct( 'media_image', __( 'Image' ), array(
'description' => __( 'Displays an image.' ),
'mime_type' => 'image',
) );
parent::__construct(
'media_image',
__( 'Image' ),
array(
'description' => __( 'Displays an image.' ),
'mime_type' => 'image',
)
);
$this->l10n = array_merge( $this->l10n, array(
'no_media_selected' => __( 'No image selected' ),
'add_media' => _x( 'Add Image', 'label for button in the image widget' ),
'replace_media' => _x( 'Replace Image', 'label for button in the image widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Image', 'label for button in the image widget; should preferably not be longer than ~13 characters long' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library */
__( 'We can&#8217;t find that image. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: widget count */
'media_library_state_multi' => _n_noop( 'Image Widget (%d)', 'Image Widget (%d)' ),
'media_library_state_single' => __( 'Image Widget' ),
) );
$this->l10n = array_merge(
$this->l10n,
array(
'no_media_selected' => __( 'No image selected' ),
'add_media' => _x( 'Add Image', 'label for button in the image widget' ),
'replace_media' => _x( 'Replace Image', 'label for button in the image widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Image', 'label for button in the image widget; should preferably not be longer than ~13 characters long' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library */
__( 'We can&#8217;t find that image. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: widget count */
'media_library_state_multi' => _n_noop( 'Image Widget (%d)', 'Image Widget (%d)' ),
'media_library_state_single' => __( 'Image Widget' ),
)
);
}
/**
@ -57,91 +64,91 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
return array_merge(
parent::get_instance_schema(),
array(
'size' => array(
'type' => 'string',
'enum' => array_merge( get_intermediate_image_sizes(), array( 'full', 'custom' ) ),
'default' => 'medium',
'size' => array(
'type' => 'string',
'enum' => array_merge( get_intermediate_image_sizes(), array( 'full', 'custom' ) ),
'default' => 'medium',
'description' => __( 'Size' ),
),
'width' => array( // Via 'customWidth', only when size=custom; otherwise via 'width'.
'type' => 'integer',
'minimum' => 0,
'default' => 0,
'width' => array( // Via 'customWidth', only when size=custom; otherwise via 'width'.
'type' => 'integer',
'minimum' => 0,
'default' => 0,
'description' => __( 'Width' ),
),
'height' => array( // Via 'customHeight', only when size=custom; otherwise via 'height'.
'type' => 'integer',
'minimum' => 0,
'default' => 0,
'height' => array( // Via 'customHeight', only when size=custom; otherwise via 'height'.
'type' => 'integer',
'minimum' => 0,
'default' => 0,
'description' => __( 'Height' ),
),
'caption' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'wp_kses_post',
'description' => __( 'Caption' ),
'caption' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'wp_kses_post',
'description' => __( 'Caption' ),
'should_preview_update' => false,
),
'alt' => array(
'type' => 'string',
'default' => '',
'alt' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'description' => __( 'Alternative Text' ),
'description' => __( 'Alternative Text' ),
),
'link_type' => array(
'type' => 'string',
'enum' => array( 'none', 'file', 'post', 'custom' ),
'default' => 'custom',
'media_prop' => 'link',
'description' => __( 'Link To' ),
'link_type' => array(
'type' => 'string',
'enum' => array( 'none', 'file', 'post', 'custom' ),
'default' => 'custom',
'media_prop' => 'link',
'description' => __( 'Link To' ),
'should_preview_update' => true,
),
'link_url' => array(
'type' => 'string',
'default' => '',
'format' => 'uri',
'media_prop' => 'linkUrl',
'description' => __( 'URL' ),
'link_url' => array(
'type' => 'string',
'default' => '',
'format' => 'uri',
'media_prop' => 'linkUrl',
'description' => __( 'URL' ),
'should_preview_update' => true,
),
'image_classes' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
'media_prop' => 'extraClasses',
'description' => __( 'Image CSS Class' ),
'image_classes' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
'media_prop' => 'extraClasses',
'description' => __( 'Image CSS Class' ),
'should_preview_update' => false,
),
'link_classes' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
'media_prop' => 'linkClassName',
'link_classes' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
'media_prop' => 'linkClassName',
'should_preview_update' => false,
'description' => __( 'Link CSS Class' ),
'description' => __( 'Link CSS Class' ),
),
'link_rel' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
'media_prop' => 'linkRel',
'description' => __( 'Link Rel' ),
'link_rel' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => array( $this, 'sanitize_token_list' ),
'media_prop' => 'linkRel',
'description' => __( 'Link Rel' ),
'should_preview_update' => false,
),
'link_target_blank' => array(
'type' => 'boolean',
'default' => false,
'media_prop' => 'linkTargetBlank',
'description' => __( 'Open link in a new tab' ),
'type' => 'boolean',
'default' => false,
'media_prop' => 'linkTargetBlank',
'description' => __( 'Open link in a new tab' ),
'should_preview_update' => false,
),
'image_title' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'media_prop' => 'title',
'description' => __( 'Image Title Attribute' ),
'image_title' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'media_prop' => 'title',
'description' => __( 'Image Title Attribute' ),
'should_preview_update' => false,
),
@ -168,9 +175,12 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
*/
public function render_media( $instance ) {
$instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
$instance = wp_parse_args( $instance, array(
'size' => 'thumbnail',
) );
$instance = wp_parse_args(
$instance,
array(
'size' => 'thumbnail',
)
);
$attachment = null;
if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) {
@ -205,7 +215,7 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
$image = wp_get_attachment_image( $attachment->ID, $size, false, $image_attributes );
$caption_size = _wp_get_image_size_from_meta( $instance['size'], wp_get_attachment_metadata( $attachment->ID ) );
$width = empty( $caption_size[0] ) ? 0 : $caption_size[0];
$width = empty( $caption_size[0] ) ? 0 : $caption_size[0];
} else {
if ( empty( $instance['url'] ) ) {
@ -213,9 +223,9 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
}
$instance['size'] = 'custom';
$caption = $instance['caption'];
$width = $instance['width'];
$classes = 'image ' . $instance['image_classes'];
$caption = $instance['caption'];
$width = $instance['width'];
$classes = 'image ' . $instance['image_classes'];
if ( 0 === $instance['width'] ) {
$instance['width'] = '';
}
@ -223,7 +233,8 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
$instance['height'] = '';
}
$image = sprintf( '<img class="%1$s" src="%2$s" alt="%3$s" width="%4$s" height="%5$s" />',
$image = sprintf(
'<img class="%1$s" src="%2$s" alt="%3$s" width="%4$s" height="%5$s" />',
esc_attr( $classes ),
esc_url( $instance['url'] ),
esc_attr( $instance['alt'] ),
@ -259,10 +270,13 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
}
if ( $caption ) {
$image = img_caption_shortcode( array(
'width' => $width,
'caption' => $caption,
), $image );
$image = img_caption_shortcode(
array(
'width' => $width,
'caption' => $caption,
),
$image
);
}
echo $image;
@ -337,10 +351,12 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
<# } else if ( data.url ) { #>
<img class="attachment-thumb" src="{{ data.url }}" draggable="false" alt="{{ data.alt }}" <# if ( ! data.alt && data.currentFilename ) { #> aria-describedby="{{ describedById }}" <# } #> />
<# if ( ! data.alt && data.currentFilename ) { #>
<p class="hidden" id="{{ describedById }}"><?php
/* translators: placeholder is image filename */
<p class="hidden" id="{{ describedById }}">
<?php
/* translators: %s: image filename */
echo sprintf( __( 'Current image: %s' ), '{{ data.currentFilename }}' );
?></p>
?>
</p>
<# } #>
<# } #>
</script>

View file

@ -22,27 +22,34 @@ class WP_Widget_Media_Video extends WP_Widget_Media {
* @since 4.8.0
*/
public function __construct() {
parent::__construct( 'media_video', __( 'Video' ), array(
'description' => __( 'Displays a video from the media library or from YouTube, Vimeo, or another provider.' ),
'mime_type' => 'video',
) );
parent::__construct(
'media_video',
__( 'Video' ),
array(
'description' => __( 'Displays a video from the media library or from YouTube, Vimeo, or another provider.' ),
'mime_type' => 'video',
)
);
$this->l10n = array_merge( $this->l10n, array(
'no_media_selected' => __( 'No video selected' ),
'add_media' => _x( 'Add Video', 'label for button in the video widget' ),
'replace_media' => _x( 'Replace Video', 'label for button in the video widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Video', 'label for button in the video widget; should preferably not be longer than ~13 characters long' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library */
__( 'We can&#8217;t find that video. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: widget count */
'media_library_state_multi' => _n_noop( 'Video Widget (%d)', 'Video Widget (%d)' ),
'media_library_state_single' => __( 'Video Widget' ),
/* translators: %s: a list of valid video file extensions */
'unsupported_file_type' => sprintf( __( 'Sorry, we can&#8217;t load the video at the supplied URL. Please check that the URL is for a supported video file (%s) or stream (e.g. YouTube and Vimeo).' ), '<code>.' . implode( '</code>, <code>.', wp_get_video_extensions() ) . '</code>' ),
) );
$this->l10n = array_merge(
$this->l10n,
array(
'no_media_selected' => __( 'No video selected' ),
'add_media' => _x( 'Add Video', 'label for button in the video widget' ),
'replace_media' => _x( 'Replace Video', 'label for button in the video widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Video', 'label for button in the video widget; should preferably not be longer than ~13 characters long' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library */
__( 'We can&#8217;t find that video. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: widget count */
'media_library_state_multi' => _n_noop( 'Video Widget (%d)', 'Video Widget (%d)' ),
'media_library_state_single' => __( 'Video Widget' ),
/* translators: %s: a list of valid video file extensions */
'unsupported_file_type' => sprintf( __( 'Sorry, we can&#8217;t load the video at the supplied URL. Please check that the URL is for a supported video file (%s) or stream (e.g. YouTube and Vimeo).' ), '<code>.' . implode( '</code>, <code>.', wp_get_video_extensions() ) . '</code>' ),
)
);
}
/**
@ -60,23 +67,23 @@ class WP_Widget_Media_Video extends WP_Widget_Media {
parent::get_instance_schema(),
array(
'preload' => array(
'type' => 'string',
'enum' => array( 'none', 'auto', 'metadata' ),
'default' => 'metadata',
'description' => __( 'Preload' ),
'type' => 'string',
'enum' => array( 'none', 'auto', 'metadata' ),
'default' => 'metadata',
'description' => __( 'Preload' ),
'should_preview_update' => false,
),
'loop' => array(
'type' => 'boolean',
'default' => false,
'description' => __( 'Loop' ),
'loop' => array(
'type' => 'boolean',
'default' => false,
'description' => __( 'Loop' ),
'should_preview_update' => false,
),
'content' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'wp_kses_post',
'description' => __( 'Tracks (subtitles, captions, descriptions, chapters, or metadata)' ),
'type' => 'string',
'default' => '',
'sanitize_callback' => 'wp_kses_post',
'description' => __( 'Tracks (subtitles, captions, descriptions, chapters, or metadata)' ),
'should_preview_update' => false,
),
)
@ -84,9 +91,9 @@ class WP_Widget_Media_Video extends WP_Widget_Media {
foreach ( wp_get_video_extensions() as $video_extension ) {
$schema[ $video_extension ] = array(
'type' => 'string',
'default' => '',
'format' => 'uri',
'type' => 'string',
'default' => '',
'format' => 'uri',
/* translators: %s: video extension */
'description' => sprintf( __( 'URL to the %s video source file' ), $video_extension ),
);
@ -105,7 +112,7 @@ class WP_Widget_Media_Video extends WP_Widget_Media {
* @return void
*/
public function render_media( $instance ) {
$instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
$instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance );
$attachment = null;
if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) {
@ -243,7 +250,7 @@ class WP_Widget_Media_Video extends WP_Widget_Media {
<span class="dashicons dashicons-format-video"></span>
</a>
<# } else if ( data.model.src ) { #>
<?php wp_underscore_video_template() ?>
<?php wp_underscore_video_template(); ?>
<# } #>
</script>
<?php

View file

@ -23,14 +23,14 @@ abstract class WP_Widget_Media extends WP_Widget {
* @var array
*/
public $l10n = array(
'add_to_widget' => '',
'replace_media' => '',
'edit_media' => '',
'media_library_state_multi' => '',
'add_to_widget' => '',
'replace_media' => '',
'edit_media' => '',
'media_library_state_multi' => '',
'media_library_state_single' => '',
'missing_attachment' => '',
'no_media_selected' => '',
'add_media' => '',
'missing_attachment' => '',
'no_media_selected' => '',
'add_media' => '',
);
/**
@ -54,31 +54,34 @@ abstract class WP_Widget_Media extends WP_Widget {
* for information on accepted arguments. Default empty array.
*/
public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
$widget_opts = wp_parse_args( $widget_options, array(
'description' => __( 'A media item.' ),
'customize_selective_refresh' => true,
'mime_type' => '',
) );
$widget_opts = wp_parse_args(
$widget_options,
array(
'description' => __( 'A media item.' ),
'customize_selective_refresh' => true,
'mime_type' => '',
)
);
$control_opts = wp_parse_args( $control_options, array() );
$l10n_defaults = array(
'no_media_selected' => __( 'No media selected' ),
'add_media' => _x( 'Add Media', 'label for button in the media widget' ),
'replace_media' => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
'add_to_widget' => __( 'Add to Widget' ),
'missing_attachment' => sprintf(
'no_media_selected' => __( 'No media selected' ),
'add_media' => _x( 'Add Media', 'label for button in the media widget' ),
'replace_media' => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
'edit_media' => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
'add_to_widget' => __( 'Add to Widget' ),
'missing_attachment' => sprintf(
/* translators: %s: URL to media library */
__( 'We can&#8217;t find that file. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
esc_url( admin_url( 'upload.php' ) )
),
/* translators: %d: widget count */
'media_library_state_multi' => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
'media_library_state_multi' => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
'media_library_state_single' => __( 'Media Widget' ),
'unsupported_file_type' => __( 'Looks like this isn&#8217;t the correct kind of file. Please link to an appropriate file instead.' ),
'unsupported_file_type' => __( 'Looks like this isn&#8217;t the correct kind of file. Please link to an appropriate file instead.' ),
);
$this->l10n = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
$this->l10n = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
parent::__construct(
$id_base,
@ -129,23 +132,23 @@ abstract class WP_Widget_Media extends WP_Widget {
public function get_instance_schema() {
$schema = array(
'attachment_id' => array(
'type' => 'integer',
'default' => 0,
'minimum' => 0,
'type' => 'integer',
'default' => 0,
'minimum' => 0,
'description' => __( 'Attachment post ID' ),
'media_prop' => 'id',
'media_prop' => 'id',
),
'url' => array(
'type' => 'string',
'default' => '',
'format' => 'uri',
'url' => array(
'type' => 'string',
'default' => '',
'format' => 'uri',
'description' => __( 'URL to the media file' ),
),
'title' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'description' => __( 'Title for the widget' ),
'title' => array(
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'description' => __( 'Title for the widget' ),
'should_preview_update' => false,
),
);
@ -322,7 +325,7 @@ abstract class WP_Widget_Media extends WP_Widget {
*/
final public function form( $instance ) {
$instance_schema = $this->get_instance_schema();
$instance = wp_array_slice_assoc(
$instance = wp_array_slice_assoc(
wp_parse_args( (array) $instance, wp_list_pluck( $instance_schema, 'default' ) ),
array_keys( $instance_schema )
);
@ -336,7 +339,7 @@ abstract class WP_Widget_Media extends WP_Widget {
id="<?php echo esc_attr( $this->get_field_id( $name ) ); // Needed specifically by wpWidgets.appendTitle(). ?>"
value="<?php echo esc_attr( is_array( $value ) ? join( ',', $value ) : strval( $value ) ); ?>"
/>
<?php
<?php
endforeach;
}

View file

@ -25,8 +25,8 @@ class WP_Widget_Meta extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_meta',
'description' => __( 'Login, RSS, &amp; WordPress.org links.' ),
'classname' => 'widget_meta',
'description' => __( 'Login, RSS, &amp; WordPress.org links.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'meta', __( 'Meta' ), $widget_ops );
@ -52,12 +52,12 @@ class WP_Widget_Meta extends WP_Widget {
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
?>
?>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
<li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
<li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e( 'Entries <abbr title="Really Simple Syndication">RSS</abbr>' ); ?></a></li>
<li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e( 'Comments <abbr title="Really Simple Syndication">RSS</abbr>' ); ?></a></li>
<?php
/**
* Filters the "Powered by WordPress" text in the Meta widget.
@ -68,18 +68,23 @@ class WP_Widget_Meta extends WP_Widget {
* @param string $title_text Default title text for the WordPress.org link.
* @param array $instance Array of settings for the current widget.
*/
echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>',
esc_url( __( 'https://wordpress.org/' ) ),
esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
_x( 'WordPress.org', 'meta widget link text' )
), $instance );
echo apply_filters(
'widget_meta_poweredby',
sprintf(
'<li><a href="%s" title="%s">%s</a></li>',
esc_url( __( 'https://wordpress.org/' ) ),
esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
_x( 'WordPress.org', 'meta widget link text' )
),
$instance
);
wp_meta();
?>
</ul>
<?php
echo $args['after_widget'];
echo $args['after_widget'];
}
/**
@ -93,7 +98,7 @@ class WP_Widget_Meta extends WP_Widget {
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
return $instance;
@ -108,9 +113,8 @@ class WP_Widget_Meta extends WP_Widget {
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = sanitize_text_field( $instance['title'] );
?>
<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($title); ?>" /></p>
<?php
?>
<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>
<?php
}
}

View file

@ -23,8 +23,8 @@ class WP_Widget_Pages extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_pages',
'description' => __( 'A list of your site&#8217;s Pages.' ),
'classname' => 'widget_pages',
'description' => __( 'A list of your site&#8217;s Pages.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'pages', __( 'Pages' ), $widget_ops );
@ -53,11 +53,12 @@ class WP_Widget_Pages extends WP_Widget {
*/
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
if ( $sortby == 'menu_order' )
if ( $sortby == 'menu_order' ) {
$sortby = 'menu_order, post_title';
}
/**
* Filters the arguments for the Pages widget.
@ -70,23 +71,29 @@ class WP_Widget_Pages extends WP_Widget {
* @param array $args An array of arguments to retrieve the pages list.
* @param array $instance Array of settings for the current widget.
*/
$out = wp_list_pages( apply_filters( 'widget_pages_args', array(
'title_li' => '',
'echo' => 0,
'sort_column' => $sortby,
'exclude' => $exclude
), $instance ) );
$out = wp_list_pages(
apply_filters(
'widget_pages_args',
array(
'title_li' => '',
'echo' => 0,
'sort_column' => $sortby,
'exclude' => $exclude,
),
$instance
)
);
if ( ! empty( $out ) ) {
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
?>
?>
<ul>
<?php echo $out; ?>
</ul>
<?php
<?php
echo $args['after_widget'];
}
}
@ -102,7 +109,7 @@ class WP_Widget_Pages extends WP_Widget {
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
$instance['sortby'] = $new_instance['sortby'];
@ -124,17 +131,24 @@ class WP_Widget_Pages extends WP_Widget {
*/
public function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
$instance = wp_parse_args(
(array) $instance,
array(
'sortby' => 'post_title',
'title' => '',
'exclude' => '',
)
);
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label>
<select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat">
<option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
<option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
<option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e( 'Page title' ); ?></option>
<option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e( 'Page order' ); ?></option>
<option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
</select>
</p>

View file

@ -23,8 +23,8 @@ class WP_Widget_Recent_Comments extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_recent_comments',
'description' => __( 'Your site&#8217;s most recent comments.' ),
'classname' => 'widget_recent_comments',
'description' => __( 'Your site&#8217;s most recent comments.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'recent-comments', __( 'Recent Comments' ), $widget_ops );
@ -35,7 +35,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
}
}
/**
/**
* Outputs the default styles for the Recent Comments widget.
*
* @since 2.8.0
@ -50,8 +50,9 @@ class WP_Widget_Recent_Comments extends WP_Widget {
* @param string $id_base The widget ID.
*/
if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
|| ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
|| ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) ) {
return;
}
?>
<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
<?php
@ -67,8 +68,9 @@ class WP_Widget_Recent_Comments extends WP_Widget {
* @param array $instance Settings for the current Recent Comments widget instance.
*/
public function widget( $args, $instance ) {
if ( ! isset( $args['widget_id'] ) )
if ( ! isset( $args['widget_id'] ) ) {
$args['widget_id'] = $this->id;
}
$output = '';
@ -78,8 +80,9 @@ class WP_Widget_Recent_Comments extends WP_Widget {
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
if ( ! $number )
if ( ! $number ) {
$number = 5;
}
/**
* Filters the arguments for the Recent Comments widget.
@ -92,11 +95,17 @@ class WP_Widget_Recent_Comments extends WP_Widget {
* @param array $comment_args An array of arguments used to retrieve the recent comments.
* @param array $instance Array of settings for the current widget.
*/
$comments = get_comments( apply_filters( 'widget_comments_args', array(
'number' => $number,
'status' => 'approve',
'post_status' => 'publish'
), $instance ) );
$comments = get_comments(
apply_filters(
'widget_comments_args',
array(
'number' => $number,
'status' => 'approve',
'post_status' => 'publish',
),
$instance
)
);
$output .= $args['before_widget'];
if ( $title ) {
@ -112,7 +121,8 @@ class WP_Widget_Recent_Comments extends WP_Widget {
foreach ( (array) $comments as $comment ) {
$output .= '<li class="recentcomments">';
/* translators: comments widget: 1: comment author, 2: post link */
$output .= sprintf( _x( '%1$s on %2$s', 'widgets' ),
$output .= sprintf(
_x( '%1$s on %2$s', 'widgets' ),
'<span class="comment-author-link">' . get_comment_author_link( $comment ) . '</span>',
'<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>'
);
@ -136,8 +146,8 @@ class WP_Widget_Recent_Comments extends WP_Widget {
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['number'] = absint( $new_instance['number'] );
return $instance;
}
@ -150,7 +160,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
* @param array $instance Current settings.
*/
public function form( $instance ) {
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
?>
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>

View file

@ -23,8 +23,8 @@ class WP_Widget_Recent_Posts extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_recent_entries',
'description' => __( 'Your site&#8217;s most recent Posts.' ),
'classname' => 'widget_recent_entries',
'description' => __( 'Your site&#8217;s most recent Posts.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'recent-posts', __( 'Recent Posts' ), $widget_ops );
@ -67,12 +67,18 @@ class WP_Widget_Recent_Posts extends WP_Widget {
* @param array $args An array of arguments used to retrieve the recent posts.
* @param array $instance Array of settings for the current widget.
*/
$r = new WP_Query( apply_filters( 'widget_posts_args', array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
), $instance ) );
$r = new WP_Query(
apply_filters(
'widget_posts_args',
array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
),
$instance
)
);
if ( ! $r->have_posts() ) {
return;
@ -91,7 +97,7 @@ class WP_Widget_Recent_Posts extends WP_Widget {
$title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
?>
<li>
<a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title ; ?></a>
<a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title; ?></a>
<?php if ( $show_date ) : ?>
<span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
<?php endif; ?>
@ -113,9 +119,9 @@ class WP_Widget_Recent_Posts extends WP_Widget {
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['number'] = (int) $new_instance['number'];
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['number'] = (int) $new_instance['number'];
$instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
return $instance;
}
@ -131,7 +137,7 @@ class WP_Widget_Recent_Posts extends WP_Widget {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
?>
?>
<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 $title; ?>" /></p>
@ -140,6 +146,6 @@ class WP_Widget_Recent_Posts extends WP_Widget {
<p><input class="checkbox" type="checkbox"<?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
<label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
<?php
<?php
}
}

View file

@ -22,11 +22,14 @@ class WP_Widget_RSS extends WP_Widget {
* @since 2.8.0
*/
public function __construct() {
$widget_ops = array(
'description' => __( 'Entries from any RSS or Atom feed.' ),
$widget_ops = array(
'description' => __( 'Entries from any RSS or Atom feed.' ),
'customize_selective_refresh' => true,
);
$control_ops = array( 'width' => 400, 'height' => 200 );
$control_ops = array(
'width' => 400,
'height' => 200,
);
parent::__construct( 'rss', __( 'RSS' ), $widget_ops, $control_ops );
}
@ -40,32 +43,38 @@ class WP_Widget_RSS extends WP_Widget {
* @param array $instance Settings for the current RSS widget instance.
*/
public function widget( $args, $instance ) {
if ( isset($instance['error']) && $instance['error'] )
if ( isset( $instance['error'] ) && $instance['error'] ) {
return;
}
$url = ! empty( $instance['url'] ) ? $instance['url'] : '';
while ( stristr($url, 'http') != $url )
$url = substr($url, 1);
while ( stristr( $url, 'http' ) != $url ) {
$url = substr( $url, 1 );
}
if ( empty($url) )
if ( empty( $url ) ) {
return;
}
// self-url destruction sequence
if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) {
return;
}
$rss = fetch_feed($url);
$rss = fetch_feed( $url );
$title = $instance['title'];
$desc = '';
$link = '';
$desc = '';
$link = '';
if ( ! is_wp_error($rss) ) {
$desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
if ( empty($title) )
if ( ! is_wp_error( $rss ) ) {
$desc = esc_attr( strip_tags( @html_entity_decode( $rss->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
if ( empty( $title ) ) {
$title = strip_tags( $rss->get_title() );
}
$link = strip_tags( $rss->get_permalink() );
while ( stristr($link, 'http') != $link )
$link = substr($link, 1);
while ( stristr( $link, 'http' ) != $link ) {
$link = substr( $link, 1 );
}
}
if ( empty( $title ) ) {
@ -75,10 +84,11 @@ class WP_Widget_RSS extends WP_Widget {
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$url = strip_tags( $url );
$url = strip_tags( $url );
$icon = includes_url( 'images/rss.png' );
if ( $title )
$title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">'. esc_html( $title ) . '</a>';
if ( $title ) {
$title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>';
}
echo $args['before_widget'];
if ( $title ) {
@ -87,9 +97,10 @@ class WP_Widget_RSS extends WP_Widget {
wp_widget_rss_output( $rss, $instance );
echo $args['after_widget'];
if ( ! is_wp_error($rss) )
if ( ! is_wp_error( $rss ) ) {
$rss->__destruct();
unset($rss);
}
unset( $rss );
}
/**
@ -103,7 +114,7 @@ class WP_Widget_RSS extends WP_Widget {
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
$testurl = ( isset( $new_instance['url'] ) && ( ! isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
return wp_widget_rss_process( $new_instance, $testurl );
}
@ -116,7 +127,15 @@ class WP_Widget_RSS extends WP_Widget {
*/
public function form( $instance ) {
if ( empty( $instance ) ) {
$instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
$instance = array(
'title' => '',
'url' => '',
'items' => 10,
'error' => false,
'show_summary' => 0,
'show_author' => 0,
'show_date' => 0,
);
}
$instance['number'] = $this->number;

View file

@ -23,8 +23,8 @@ class WP_Widget_Search extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_search',
'description' => __( 'A search form for your site.' ),
'classname' => 'widget_search',
'description' => __( 'A search form for your site.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
@ -64,10 +64,10 @@ class WP_Widget_Search extends WP_Widget {
* @param array $instance Current settings.
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
$title = $instance['title'];
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = $instance['title'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <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($title); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?> <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( $title ); ?>" /></label></p>
<?php
}
@ -82,8 +82,8 @@ class WP_Widget_Search extends WP_Widget {
* @return array Updated settings.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '' ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
return $instance;
}

View file

@ -23,7 +23,7 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
*/
public function __construct() {
$widget_ops = array(
'description' => __( 'A cloud of your most used tags.' ),
'description' => __( 'A cloud of your most used tags.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'tag_cloud', __( 'Tag Cloud' ), $widget_ops );
@ -47,7 +47,7 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
if ( 'post_tag' === $current_taxonomy ) {
$title = __( 'Tags' );
} else {
$tax = get_taxonomy( $current_taxonomy );
$tax = get_taxonomy( $current_taxonomy );
$title = $tax->labels->name;
}
}
@ -66,11 +66,17 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
* @param array $args Args used for the tag cloud widget.
* @param array $instance Array of settings for the current widget.
*/
$tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
'taxonomy' => $current_taxonomy,
'echo' => false,
'show_count' => $show_count,
), $instance ) );
$tag_cloud = wp_tag_cloud(
apply_filters(
'widget_tag_cloud_args',
array(
'taxonomy' => $current_taxonomy,
'echo' => false,
'show_count' => $show_count,
),
$instance
)
);
if ( empty( $tag_cloud ) ) {
return;
@ -103,10 +109,10 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
* @return array Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['count'] = ! empty( $new_instance['count'] ) ? 1 : 0;
$instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
$instance = array();
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['count'] = ! empty( $new_instance['count'] ) ? 1 : 0;
$instance['taxonomy'] = stripslashes( $new_instance['taxonomy'] );
return $instance;
}
@ -118,19 +124,19 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
* @param array $instance Current settings.
*/
public function form( $instance ) {
$current_taxonomy = $this->_get_current_taxonomy($instance);
$title_id = $this->get_field_id( 'title' );
$count = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
$current_taxonomy = $this->_get_current_taxonomy( $instance );
$title_id = $this->get_field_id( 'title' );
$count = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
$instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
echo '<p><label for="' . $title_id .'">' . __( 'Title:' ) . '</label>
<input type="text" class="widefat" id="' . $title_id .'" name="' . $this->get_field_name( 'title' ) .'" value="' . $instance['title'] .'" />
echo '<p><label for="' . $title_id . '">' . __( 'Title:' ) . '</label>
<input type="text" class="widefat" id="' . $title_id . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $instance['title'] . '" />
</p>';
$taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' );
$id = $this->get_field_id( 'taxonomy' );
$name = $this->get_field_name( 'taxonomy' );
$input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';
$id = $this->get_field_id( 'taxonomy' );
$name = $this->get_field_name( 'taxonomy' );
$input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';
$count_checkbox = sprintf(
'<p><input type="checkbox" class="checkbox" id="%1$s" name="%2$s"%3$s /> <label for="%1$s">%4$s</label></p>',
@ -142,40 +148,40 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
switch ( count( $taxonomies ) ) {
// No tag cloud supporting taxonomies found, display error message
case 0:
echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>';
printf( $input, '' );
break;
// No tag cloud supporting taxonomies found, display error message
case 0:
echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>';
printf( $input, '' );
break;
// Just a single tag cloud supporting taxonomy found, no need to display a select.
case 1:
$keys = array_keys( $taxonomies );
$taxonomy = reset( $keys );
printf( $input, esc_attr( $taxonomy ) );
echo $count_checkbox;
break;
// Just a single tag cloud supporting taxonomy found, no need to display a select.
case 1:
$keys = array_keys( $taxonomies );
$taxonomy = reset( $keys );
printf( $input, esc_attr( $taxonomy ) );
echo $count_checkbox;
break;
// More than one tag cloud supporting taxonomy found, display a select.
default:
printf(
'<p><label for="%1$s">%2$s</label>' .
'<select class="widefat" id="%1$s" name="%3$s">',
$id,
__( 'Taxonomy:' ),
$name
);
foreach ( $taxonomies as $taxonomy => $tax ) {
// More than one tag cloud supporting taxonomy found, display a select.
default:
printf(
'<option value="%s"%s>%s</option>',
esc_attr( $taxonomy ),
selected( $taxonomy, $current_taxonomy, false ),
$tax->labels->name
'<p><label for="%1$s">%2$s</label>' .
'<select class="widefat" id="%1$s" name="%3$s">',
$id,
__( 'Taxonomy:' ),
$name
);
}
echo '</select></p>' . $count_checkbox;
foreach ( $taxonomies as $taxonomy => $tax ) {
printf(
'<option value="%s"%s>%s</option>',
esc_attr( $taxonomy ),
selected( $taxonomy, $current_taxonomy, false ),
$tax->labels->name
);
}
echo '</select></p>' . $count_checkbox;
}
}
@ -187,9 +193,10 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
* @param array $instance Current settings.
* @return string Name of the current taxonomy if set, otherwise 'post_tag'.
*/
public function _get_current_taxonomy($instance) {
if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
public function _get_current_taxonomy( $instance ) {
if ( ! empty( $instance['taxonomy'] ) && taxonomy_exists( $instance['taxonomy'] ) ) {
return $instance['taxonomy'];
}
return 'post_tag';
}

View file

@ -30,13 +30,13 @@ class WP_Widget_Text extends WP_Widget {
* @since 2.8.0
*/
public function __construct() {
$widget_ops = array(
'classname' => 'widget_text',
'description' => __( 'Arbitrary text.' ),
$widget_ops = array(
'classname' => 'widget_text',
'description' => __( 'Arbitrary text.' ),
'customize_selective_refresh' => true,
);
$control_ops = array(
'width' => 400,
'width' => 400,
'height' => 350,
);
parent::__construct( 'text', __( 'Text' ), $widget_ops, $control_ops );
@ -99,7 +99,7 @@ class WP_Widget_Text extends WP_Widget {
return false;
}
$wpautop = ! empty( $instance['filter'] );
$wpautop = ! empty( $instance['filter'] );
$has_line_breaks = ( false !== strpos( trim( $instance['text'] ), "\n" ) );
// If auto-paragraphs are not enabled and there are line breaks, then ensure legacy mode.
@ -120,38 +120,45 @@ class WP_Widget_Text extends WP_Widget {
}
$doc = new DOMDocument();
@$doc->loadHTML( sprintf(
'<!DOCTYPE html><html><head><meta charset="%s"></head><body>%s</body></html>',
esc_attr( get_bloginfo( 'charset' ) ),
$instance['text']
) );
// Suppress warnings generated by loadHTML
$errors = libxml_use_internal_errors( true );
@$doc->loadHTML(
sprintf(
'<!DOCTYPE html><html><head><meta charset="%s"></head><body>%s</body></html>',
esc_attr( get_bloginfo( 'charset' ) ),
$instance['text']
)
);
libxml_use_internal_errors( $errors );
$body = $doc->getElementsByTagName( 'body' )->item( 0 );
// See $allowedposttags.
$safe_elements_attributes = array(
'strong' => array(),
'em' => array(),
'b' => array(),
'i' => array(),
'u' => array(),
's' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'hr' => array(),
'abbr' => array(),
'strong' => array(),
'em' => array(),
'b' => array(),
'i' => array(),
'u' => array(),
's' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'hr' => array(),
'abbr' => array(),
'acronym' => array(),
'code' => array(),
'dfn' => array(),
'a' => array(
'code' => array(),
'dfn' => array(),
'a' => array(
'href' => true,
),
'img' => array(
'img' => array(
'src' => true,
'alt' => true,
),
);
$safe_empty_elements = array( 'img', 'hr', 'iframe' );
$safe_empty_elements = array( 'img', 'hr', 'iframe' );
foreach ( $body->getElementsByTagName( '*' ) as $element ) {
/** @var DOMElement $element */
@ -219,7 +226,7 @@ class WP_Widget_Text extends WP_Widget {
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$text = ! empty( $instance['text'] ) ? $instance['text'] : '';
$text = ! empty( $instance['text'] ) ? $instance['text'] : '';
$is_visual_text_widget = ( ! empty( $instance['visual'] ) && ! empty( $instance['filter'] ) );
// In 4.8.0 only, visual Text widgets get filter=content, without visual prop; upgrade instance props just-in-time.
@ -237,7 +244,7 @@ class WP_Widget_Text extends WP_Widget {
* and it applies after wpautop() to prevent corrupting HTML output added by the shortcode. When do_shortcode() is
* added to 'widget_text_content' then do_shortcode() will be manually called when in legacy mode as well.
*/
$widget_text_do_shortcode_priority = has_filter( 'widget_text', 'do_shortcode' );
$widget_text_do_shortcode_priority = has_filter( 'widget_text', 'do_shortcode' );
$should_suspend_legacy_shortcode_support = ( $is_visual_text_widget && false !== $widget_text_do_shortcode_priority );
if ( $should_suspend_legacy_shortcode_support ) {
remove_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority );
@ -355,12 +362,15 @@ class WP_Widget_Text extends WP_Widget {
* @return array Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance ) {
$new_instance = wp_parse_args( $new_instance, array(
'title' => '',
'text' => '',
'filter' => false, // For back-compat.
'visual' => null, // Must be explicitly defined.
) );
$new_instance = wp_parse_args(
$new_instance,
array(
'title' => '',
'text' => '',
'filter' => false, // For back-compat.
'visual' => null, // Must be explicitly defined.
)
);
$instance = $old_instance;
@ -427,7 +437,7 @@ class WP_Widget_Text extends WP_Widget {
* @since 2.8.0
* @since 4.8.0 Form only contains hidden inputs which are synced with JS template.
* @since 4.8.1 Restored original form to be displayed when in legacy mode.
* @see WP_Widget_Visual_Text::render_control_template_scripts()
* @see WP_Widget_Text::render_control_template_scripts()
* @see _WP_Editors::editor()
*
* @param array $instance Current settings.
@ -438,7 +448,7 @@ class WP_Widget_Text extends WP_Widget {
(array) $instance,
array(
'title' => '',
'text' => '',
'text' => '',
)
);
?>
@ -488,7 +498,7 @@ class WP_Widget_Text extends WP_Widget {
<p>
<input id="<?php echo $this->get_field_id( 'filter' ); ?>" name="<?php echo $this->get_field_name( 'filter' ); ?>" type="checkbox"<?php checked( ! empty( $instance['filter'] ) ); ?> />&nbsp;<label for="<?php echo $this->get_field_id( 'filter' ); ?>"><?php _e( 'Automatically add paragraphs' ); ?></label>
</p>
<?php
<?php
endif;
}