mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -110,7 +110,7 @@ class WP_Widget {
|
||||
* @param array $instance The settings for the particular instance of the widget.
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
die('function WP_Widget::widget() must be over-ridden in a sub-class.');
|
||||
die( 'function WP_Widget::widget() must be over-ridden in a sub-class.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +140,7 @@ class WP_Widget {
|
||||
* @return string Default return is 'noform'.
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
|
||||
echo '<p class="no-options-widget">' . __( 'There are no options for this widget.' ) . '</p>';
|
||||
return 'noform';
|
||||
}
|
||||
|
||||
@@ -160,10 +160,15 @@ class WP_Widget {
|
||||
* information on accepted arguments. Default empty array.
|
||||
*/
|
||||
public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
|
||||
$this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base);
|
||||
$this->name = $name;
|
||||
$this->option_name = 'widget_' . $this->id_base;
|
||||
$this->widget_options = wp_parse_args( $widget_options, array( 'classname' => $this->option_name, 'customize_selective_refresh' => false ) );
|
||||
$this->id_base = empty( $id_base ) ? preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) ) : strtolower( $id_base );
|
||||
$this->name = $name;
|
||||
$this->option_name = 'widget_' . $this->id_base;
|
||||
$this->widget_options = wp_parse_args(
|
||||
$widget_options, array(
|
||||
'classname' => $this->option_name,
|
||||
'customize_selective_refresh' => false,
|
||||
)
|
||||
);
|
||||
$this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
|
||||
}
|
||||
|
||||
@@ -199,7 +204,7 @@ class WP_Widget {
|
||||
* @param string $field_name Field name
|
||||
* @return string Name attribute for $field_name
|
||||
*/
|
||||
public function get_field_name($field_name) {
|
||||
public function get_field_name( $field_name ) {
|
||||
if ( false === $pos = strpos( $field_name, '[' ) ) {
|
||||
return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
|
||||
} else {
|
||||
@@ -230,7 +235,7 @@ class WP_Widget {
|
||||
*/
|
||||
public function _register() {
|
||||
$settings = $this->get_settings();
|
||||
$empty = true;
|
||||
$empty = true;
|
||||
|
||||
// When $settings is an array-like object, get an intrinsic array for use with array_keys().
|
||||
if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) {
|
||||
@@ -262,9 +267,9 @@ class WP_Widget {
|
||||
* @param int $number The unique order number of this widget instance compared to other
|
||||
* instances of the same class.
|
||||
*/
|
||||
public function _set($number) {
|
||||
public function _set( $number ) {
|
||||
$this->number = $number;
|
||||
$this->id = $this->id_base . '-' . $number;
|
||||
$this->id = $this->id_base . '-' . $number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,7 +280,7 @@ class WP_Widget {
|
||||
* @return callable Display callback.
|
||||
*/
|
||||
public function _get_display_callback() {
|
||||
return array($this, 'display_callback');
|
||||
return array( $this, 'display_callback' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,7 +291,7 @@ class WP_Widget {
|
||||
* @return callable Update callback.
|
||||
*/
|
||||
public function _get_update_callback() {
|
||||
return array($this, 'update_callback');
|
||||
return array( $this, 'update_callback' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,7 +302,7 @@ class WP_Widget {
|
||||
* @return callable Form callback.
|
||||
*/
|
||||
public function _get_form_callback() {
|
||||
return array($this, 'form_callback');
|
||||
return array( $this, 'form_callback' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +321,7 @@ class WP_Widget {
|
||||
*/
|
||||
public function is_preview() {
|
||||
global $wp_customize;
|
||||
return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ;
|
||||
return ( isset( $wp_customize ) && $wp_customize->is_preview() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,37 +397,40 @@ class WP_Widget {
|
||||
$all_instances = $this->get_settings();
|
||||
|
||||
// We need to update the data
|
||||
if ( $this->updated )
|
||||
if ( $this->updated ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
||||
if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) {
|
||||
// Delete the settings for this instance of the widget
|
||||
if ( isset($_POST['the-widget-id']) )
|
||||
if ( isset( $_POST['the-widget-id'] ) ) {
|
||||
$del_id = $_POST['the-widget-id'];
|
||||
else
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
|
||||
$number = $wp_registered_widgets[$del_id]['params'][0]['number'];
|
||||
if ( isset( $wp_registered_widgets[ $del_id ]['params'][0]['number'] ) ) {
|
||||
$number = $wp_registered_widgets[ $del_id ]['params'][0]['number'];
|
||||
|
||||
if ( $this->id_base . '-' . $number == $del_id )
|
||||
unset($all_instances[$number]);
|
||||
if ( $this->id_base . '-' . $number == $del_id ) {
|
||||
unset( $all_instances[ $number ] );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {
|
||||
$settings = $_POST['widget-' . $this->id_base];
|
||||
} elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) {
|
||||
$num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
|
||||
if ( isset( $_POST[ 'widget-' . $this->id_base ] ) && is_array( $_POST[ 'widget-' . $this->id_base ] ) ) {
|
||||
$settings = $_POST[ 'widget-' . $this->id_base ];
|
||||
} elseif ( isset( $_POST['id_base'] ) && $_POST['id_base'] == $this->id_base ) {
|
||||
$num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
|
||||
$settings = array( $num => array() );
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $settings as $number => $new_instance ) {
|
||||
$new_instance = stripslashes_deep($new_instance);
|
||||
$this->_set($number);
|
||||
$new_instance = stripslashes_deep( $new_instance );
|
||||
$this->_set( $number );
|
||||
|
||||
$old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
|
||||
$old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
|
||||
|
||||
$was_cache_addition_suspended = wp_suspend_cache_addition();
|
||||
if ( $this->is_preview() && ! $was_cache_addition_suspended ) {
|
||||
@@ -450,14 +458,14 @@ class WP_Widget {
|
||||
*/
|
||||
$instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this );
|
||||
if ( false !== $instance ) {
|
||||
$all_instances[$number] = $instance;
|
||||
$all_instances[ $number ] = $instance;
|
||||
}
|
||||
|
||||
break; // run only once
|
||||
}
|
||||
}
|
||||
|
||||
$this->save_settings($all_instances);
|
||||
$this->save_settings( $all_instances );
|
||||
$this->updated = true;
|
||||
}
|
||||
|
||||
@@ -475,18 +483,19 @@ class WP_Widget {
|
||||
* @return string|null
|
||||
*/
|
||||
public function form_callback( $widget_args = 1 ) {
|
||||
if ( is_numeric($widget_args) )
|
||||
if ( is_numeric( $widget_args ) ) {
|
||||
$widget_args = array( 'number' => $widget_args );
|
||||
}
|
||||
|
||||
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
|
||||
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
|
||||
$all_instances = $this->get_settings();
|
||||
|
||||
if ( -1 == $widget_args['number'] ) {
|
||||
// We echo out a form where 'number' can be set later
|
||||
$this->_set('__i__');
|
||||
$this->_set( '__i__' );
|
||||
$instance = array();
|
||||
} else {
|
||||
$this->_set($widget_args['number']);
|
||||
$this->_set( $widget_args['number'] );
|
||||
$instance = $all_instances[ $widget_args['number'] ];
|
||||
}
|
||||
|
||||
@@ -504,7 +513,7 @@ class WP_Widget {
|
||||
|
||||
$return = null;
|
||||
if ( false !== $instance ) {
|
||||
$return = $this->form($instance);
|
||||
$return = $this->form( $instance );
|
||||
|
||||
/**
|
||||
* Fires at the end of the widget control form.
|
||||
@@ -536,9 +545,9 @@ class WP_Widget {
|
||||
* compared to other instances of the same class. Default -1.
|
||||
*/
|
||||
public function _register_one( $number = -1 ) {
|
||||
wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
|
||||
wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
|
||||
_register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) );
|
||||
_register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );
|
||||
_register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user