Edit File by line
/home/barbar84/public_h.../wp-admin/includes
File: widgets.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Widgets Administration API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Display list of the available widgets.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.5.0
[11] Fix | Delete
*
[12] Fix | Delete
* @global array $wp_registered_widgets
[13] Fix | Delete
* @global array $wp_registered_widget_controls
[14] Fix | Delete
*/
[15] Fix | Delete
function wp_list_widgets() {
[16] Fix | Delete
global $wp_registered_widgets, $wp_registered_widget_controls;
[17] Fix | Delete
[18] Fix | Delete
$sort = $wp_registered_widgets;
[19] Fix | Delete
usort( $sort, '_sort_name_callback' );
[20] Fix | Delete
$done = array();
[21] Fix | Delete
[22] Fix | Delete
foreach ( $sort as $widget ) {
[23] Fix | Delete
if ( in_array( $widget['callback'], $done, true ) ) { // We already showed this multi-widget.
[24] Fix | Delete
continue;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
$sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false );
[28] Fix | Delete
$done[] = $widget['callback'];
[29] Fix | Delete
[30] Fix | Delete
if ( ! isset( $widget['params'][0] ) ) {
[31] Fix | Delete
$widget['params'][0] = array();
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
$args = array(
[35] Fix | Delete
'widget_id' => $widget['id'],
[36] Fix | Delete
'widget_name' => $widget['name'],
[37] Fix | Delete
'_display' => 'template',
[38] Fix | Delete
);
[39] Fix | Delete
[40] Fix | Delete
if ( isset( $wp_registered_widget_controls[ $widget['id'] ]['id_base'] ) && isset( $widget['params'][0]['number'] ) ) {
[41] Fix | Delete
$id_base = $wp_registered_widget_controls[ $widget['id'] ]['id_base'];
[42] Fix | Delete
$args['_temp_id'] = "$id_base-__i__";
[43] Fix | Delete
$args['_multi_num'] = next_widget_id_number( $id_base );
[44] Fix | Delete
$args['_add'] = 'multi';
[45] Fix | Delete
} else {
[46] Fix | Delete
$args['_add'] = 'single';
[47] Fix | Delete
if ( $sidebar ) {
[48] Fix | Delete
$args['_hide'] = '1';
[49] Fix | Delete
}
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
$control_args = array(
[53] Fix | Delete
0 => $args,
[54] Fix | Delete
1 => $widget['params'][0],
[55] Fix | Delete
);
[56] Fix | Delete
$sidebar_args = wp_list_widget_controls_dynamic_sidebar( $control_args );
[57] Fix | Delete
[58] Fix | Delete
wp_widget_control( ...$sidebar_args );
[59] Fix | Delete
}
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Callback to sort array by a 'name' key.
[64] Fix | Delete
*
[65] Fix | Delete
* @since 3.1.0
[66] Fix | Delete
* @access private
[67] Fix | Delete
*
[68] Fix | Delete
* @return int
[69] Fix | Delete
*/
[70] Fix | Delete
function _sort_name_callback( $a, $b ) {
[71] Fix | Delete
return strnatcasecmp( $a['name'], $b['name'] );
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Show the widgets and their settings for a sidebar.
[76] Fix | Delete
* Used in the admin widget config screen.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 2.5.0
[79] Fix | Delete
*
[80] Fix | Delete
* @param string $sidebar Sidebar ID.
[81] Fix | Delete
* @param string $sidebar_name Optional. Sidebar name. Default empty.
[82] Fix | Delete
*/
[83] Fix | Delete
function wp_list_widget_controls( $sidebar, $sidebar_name = '' ) {
[84] Fix | Delete
add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' );
[85] Fix | Delete
[86] Fix | Delete
$description = wp_sidebar_description( $sidebar );
[87] Fix | Delete
[88] Fix | Delete
echo '<div id="' . esc_attr( $sidebar ) . '" class="widgets-sortables">';
[89] Fix | Delete
[90] Fix | Delete
if ( $sidebar_name ) {
[91] Fix | Delete
$add_to = sprintf(
[92] Fix | Delete
/* translators: %s: Widgets sidebar name. */
[93] Fix | Delete
__( 'Add to: %s' ),
[94] Fix | Delete
$sidebar_name
[95] Fix | Delete
);
[96] Fix | Delete
?>
[97] Fix | Delete
<div class="sidebar-name" data-add-to="<?php echo esc_attr( $add_to ); ?>">
[98] Fix | Delete
<button type="button" class="handlediv hide-if-no-js" aria-expanded="true">
[99] Fix | Delete
<span class="screen-reader-text"><?php echo esc_html( $sidebar_name ); ?></span>
[100] Fix | Delete
<span class="toggle-indicator" aria-hidden="true"></span>
[101] Fix | Delete
</button>
[102] Fix | Delete
<h2><?php echo esc_html( $sidebar_name ); ?> <span class="spinner"></span></h2>
[103] Fix | Delete
</div>
[104] Fix | Delete
<?php
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
if ( ! empty( $description ) ) {
[108] Fix | Delete
?>
[109] Fix | Delete
<div class="sidebar-description">
[110] Fix | Delete
<p class="description"><?php echo $description; ?></p>
[111] Fix | Delete
</div>
[112] Fix | Delete
<?php
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
dynamic_sidebar( $sidebar );
[116] Fix | Delete
[117] Fix | Delete
echo '</div>';
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Retrieves the widget control arguments.
[122] Fix | Delete
*
[123] Fix | Delete
* @since 2.5.0
[124] Fix | Delete
*
[125] Fix | Delete
* @global array $wp_registered_widgets
[126] Fix | Delete
*
[127] Fix | Delete
* @param array $params
[128] Fix | Delete
* @return array
[129] Fix | Delete
*/
[130] Fix | Delete
function wp_list_widget_controls_dynamic_sidebar( $params ) {
[131] Fix | Delete
global $wp_registered_widgets;
[132] Fix | Delete
static $i = 0;
[133] Fix | Delete
$i++;
[134] Fix | Delete
[135] Fix | Delete
$widget_id = $params[0]['widget_id'];
[136] Fix | Delete
$id = isset( $params[0]['_temp_id'] ) ? $params[0]['_temp_id'] : $widget_id;
[137] Fix | Delete
$hidden = isset( $params[0]['_hide'] ) ? ' style="display:none;"' : '';
[138] Fix | Delete
[139] Fix | Delete
$params[0]['before_widget'] = "<div id='widget-{$i}_{$id}' class='widget'$hidden>";
[140] Fix | Delete
$params[0]['after_widget'] = '</div>';
[141] Fix | Delete
$params[0]['before_title'] = '%BEG_OF_TITLE%'; // Deprecated.
[142] Fix | Delete
$params[0]['after_title'] = '%END_OF_TITLE%'; // Deprecated.
[143] Fix | Delete
[144] Fix | Delete
if ( is_callable( $wp_registered_widgets[ $widget_id ]['callback'] ) ) {
[145] Fix | Delete
$wp_registered_widgets[ $widget_id ]['_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
[146] Fix | Delete
$wp_registered_widgets[ $widget_id ]['callback'] = 'wp_widget_control';
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
return $params;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* @global array $wp_registered_widgets
[154] Fix | Delete
*
[155] Fix | Delete
* @param string $id_base
[156] Fix | Delete
* @return int
[157] Fix | Delete
*/
[158] Fix | Delete
function next_widget_id_number( $id_base ) {
[159] Fix | Delete
global $wp_registered_widgets;
[160] Fix | Delete
$number = 1;
[161] Fix | Delete
[162] Fix | Delete
foreach ( $wp_registered_widgets as $widget_id => $widget ) {
[163] Fix | Delete
if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) ) {
[164] Fix | Delete
$number = max( $number, $matches[1] );
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
$number++;
[168] Fix | Delete
[169] Fix | Delete
return $number;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Meta widget used to display the control form for a widget.
[174] Fix | Delete
*
[175] Fix | Delete
* Called from dynamic_sidebar().
[176] Fix | Delete
*
[177] Fix | Delete
* @since 2.5.0
[178] Fix | Delete
*
[179] Fix | Delete
* @global array $wp_registered_widgets
[180] Fix | Delete
* @global array $wp_registered_widget_controls
[181] Fix | Delete
* @global array $sidebars_widgets
[182] Fix | Delete
*
[183] Fix | Delete
* @param array $sidebar_args
[184] Fix | Delete
* @return array
[185] Fix | Delete
*/
[186] Fix | Delete
function wp_widget_control( $sidebar_args ) {
[187] Fix | Delete
global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets;
[188] Fix | Delete
[189] Fix | Delete
$widget_id = $sidebar_args['widget_id'];
[190] Fix | Delete
$sidebar_id = isset( $sidebar_args['id'] ) ? $sidebar_args['id'] : false;
[191] Fix | Delete
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[ $sidebar_id ], true ) : '-1'; // Position of widget in sidebar.
[192] Fix | Delete
$control = isset( $wp_registered_widget_controls[ $widget_id ] ) ? $wp_registered_widget_controls[ $widget_id ] : array();
[193] Fix | Delete
$widget = $wp_registered_widgets[ $widget_id ];
[194] Fix | Delete
[195] Fix | Delete
$id_format = $widget['id'];
[196] Fix | Delete
$widget_number = isset( $control['params'][0]['number'] ) ? $control['params'][0]['number'] : '';
[197] Fix | Delete
$id_base = isset( $control['id_base'] ) ? $control['id_base'] : $widget_id;
[198] Fix | Delete
$width = isset( $control['width'] ) ? $control['width'] : '';
[199] Fix | Delete
$height = isset( $control['height'] ) ? $control['height'] : '';
[200] Fix | Delete
$multi_number = isset( $sidebar_args['_multi_num'] ) ? $sidebar_args['_multi_num'] : '';
[201] Fix | Delete
$add_new = isset( $sidebar_args['_add'] ) ? $sidebar_args['_add'] : '';
[202] Fix | Delete
[203] Fix | Delete
$before_form = isset( $sidebar_args['before_form'] ) ? $sidebar_args['before_form'] : '<form method="post">';
[204] Fix | Delete
$after_form = isset( $sidebar_args['after_form'] ) ? $sidebar_args['after_form'] : '</form>';
[205] Fix | Delete
$before_widget_content = isset( $sidebar_args['before_widget_content'] ) ? $sidebar_args['before_widget_content'] : '<div class="widget-content">';
[206] Fix | Delete
$after_widget_content = isset( $sidebar_args['after_widget_content'] ) ? $sidebar_args['after_widget_content'] : '</div>';
[207] Fix | Delete
[208] Fix | Delete
$query_arg = array( 'editwidget' => $widget['id'] );
[209] Fix | Delete
if ( $add_new ) {
[210] Fix | Delete
$query_arg['addnew'] = 1;
[211] Fix | Delete
if ( $multi_number ) {
[212] Fix | Delete
$query_arg['num'] = $multi_number;
[213] Fix | Delete
$query_arg['base'] = $id_base;
[214] Fix | Delete
}
[215] Fix | Delete
} else {
[216] Fix | Delete
$query_arg['sidebar'] = $sidebar_id;
[217] Fix | Delete
$query_arg['key'] = $key;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
/*
[221] Fix | Delete
* We aren't showing a widget control, we're outputting a template
[222] Fix | Delete
* for a multi-widget control.
[223] Fix | Delete
*/
[224] Fix | Delete
if ( isset( $sidebar_args['_display'] ) && 'template' === $sidebar_args['_display'] && $widget_number ) {
[225] Fix | Delete
// number == -1 implies a template where id numbers are replaced by a generic '__i__'.
[226] Fix | Delete
$control['params'][0]['number'] = -1;
[227] Fix | Delete
// With id_base widget id's are constructed like {$id_base}-{$id_number}.
[228] Fix | Delete
if ( isset( $control['id_base'] ) ) {
[229] Fix | Delete
$id_format = $control['id_base'] . '-__i__';
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
$wp_registered_widgets[ $widget_id ]['callback'] = $wp_registered_widgets[ $widget_id ]['_callback'];
[234] Fix | Delete
unset( $wp_registered_widgets[ $widget_id ]['_callback'] );
[235] Fix | Delete
[236] Fix | Delete
$widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) );
[237] Fix | Delete
$has_form = 'noform';
[238] Fix | Delete
[239] Fix | Delete
echo $sidebar_args['before_widget'];
[240] Fix | Delete
?>
[241] Fix | Delete
<div class="widget-top">
[242] Fix | Delete
<div class="widget-title-action">
[243] Fix | Delete
<button type="button" class="widget-action hide-if-no-js" aria-expanded="false">
[244] Fix | Delete
<span class="screen-reader-text edit">
[245] Fix | Delete
<?php
[246] Fix | Delete
/* translators: %s: Widget title. */
[247] Fix | Delete
printf( __( 'Edit widget: %s' ), $widget_title );
[248] Fix | Delete
?>
[249] Fix | Delete
</span>
[250] Fix | Delete
<span class="screen-reader-text add">
[251] Fix | Delete
<?php
[252] Fix | Delete
/* translators: %s: Widget title. */
[253] Fix | Delete
printf( __( 'Add widget: %s' ), $widget_title );
[254] Fix | Delete
?>
[255] Fix | Delete
</span>
[256] Fix | Delete
<span class="toggle-indicator" aria-hidden="true"></span>
[257] Fix | Delete
</button>
[258] Fix | Delete
<a class="widget-control-edit hide-if-js" href="<?php echo esc_url( add_query_arg( $query_arg ) ); ?>">
[259] Fix | Delete
<span class="edit"><?php _ex( 'Edit', 'widget' ); ?></span>
[260] Fix | Delete
<span class="add"><?php _ex( 'Add', 'widget' ); ?></span>
[261] Fix | Delete
<span class="screen-reader-text"><?php echo $widget_title; ?></span>
[262] Fix | Delete
</a>
[263] Fix | Delete
</div>
[264] Fix | Delete
<div class="widget-title"><h3><?php echo $widget_title; ?><span class="in-widget-title"></span></h3></div>
[265] Fix | Delete
</div>
[266] Fix | Delete
[267] Fix | Delete
<div class="widget-inside">
[268] Fix | Delete
<?php echo $before_form; ?>
[269] Fix | Delete
<?php echo $before_widget_content; ?>
[270] Fix | Delete
<?php
[271] Fix | Delete
if ( isset( $control['callback'] ) ) {
[272] Fix | Delete
$has_form = call_user_func_array( $control['callback'], $control['params'] );
[273] Fix | Delete
} else {
[274] Fix | Delete
echo "\t\t<p>" . __( 'There are no options for this widget.' ) . "</p>\n";
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
$noform_class = '';
[278] Fix | Delete
if ( 'noform' === $has_form ) {
[279] Fix | Delete
$noform_class = ' widget-control-noform';
[280] Fix | Delete
}
[281] Fix | Delete
?>
[282] Fix | Delete
<?php echo $after_widget_content; ?>
[283] Fix | Delete
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr( $id_format ); ?>" />
[284] Fix | Delete
<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr( $id_base ); ?>" />
[285] Fix | Delete
<input type="hidden" name="widget-width" class="widget-width" value="<?php echo esc_attr( $width ); ?>" />
[286] Fix | Delete
<input type="hidden" name="widget-height" class="widget-height" value="<?php echo esc_attr( $height ); ?>" />
[287] Fix | Delete
<input type="hidden" name="widget_number" class="widget_number" value="<?php echo esc_attr( $widget_number ); ?>" />
[288] Fix | Delete
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr( $multi_number ); ?>" />
[289] Fix | Delete
<input type="hidden" name="add_new" class="add_new" value="<?php echo esc_attr( $add_new ); ?>" />
[290] Fix | Delete
[291] Fix | Delete
<div class="widget-control-actions">
[292] Fix | Delete
<div class="alignleft">
[293] Fix | Delete
<button type="button" class="button-link button-link-delete widget-control-remove"><?php _e( 'Delete' ); ?></button>
[294] Fix | Delete
<span class="widget-control-close-wrapper">
[295] Fix | Delete
| <button type="button" class="button-link widget-control-close"><?php _e( 'Done' ); ?></button>
[296] Fix | Delete
</span>
[297] Fix | Delete
</div>
[298] Fix | Delete
<div class="alignright<?php echo $noform_class; ?>">
[299] Fix | Delete
<?php submit_button( __( 'Save' ), 'primary widget-control-save right', 'savewidget', false, array( 'id' => 'widget-' . esc_attr( $id_format ) . '-savewidget' ) ); ?>
[300] Fix | Delete
<span class="spinner"></span>
[301] Fix | Delete
</div>
[302] Fix | Delete
<br class="clear" />
[303] Fix | Delete
</div>
[304] Fix | Delete
<?php echo $after_form; ?>
[305] Fix | Delete
</div>
[306] Fix | Delete
[307] Fix | Delete
<div class="widget-description">
[308] Fix | Delete
<?php
[309] Fix | Delete
$widget_description = wp_widget_description( $widget_id );
[310] Fix | Delete
echo ( $widget_description ) ? "$widget_description\n" : "$widget_title\n";
[311] Fix | Delete
?>
[312] Fix | Delete
</div>
[313] Fix | Delete
<?php
[314] Fix | Delete
echo $sidebar_args['after_widget'];
[315] Fix | Delete
[316] Fix | Delete
return $sidebar_args;
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
/**
[320] Fix | Delete
* @param string $classes
[321] Fix | Delete
* @return string
[322] Fix | Delete
*/
[323] Fix | Delete
function wp_widgets_access_body_class( $classes ) {
[324] Fix | Delete
return "$classes widgets_access ";
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function