Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: class-wp-customize-widgets.php
* @see WP_Customize_Setting
[1000] Fix | Delete
*
[1001] Fix | Delete
* @param array $args Array of Customizer setting arguments.
[1002] Fix | Delete
* @param string $id Widget setting ID.
[1003] Fix | Delete
*/
[1004] Fix | Delete
return apply_filters( 'widget_customizer_setting_args', $args, $id );
[1005] Fix | Delete
}
[1006] Fix | Delete
[1007] Fix | Delete
/**
[1008] Fix | Delete
* Ensures sidebar widget arrays only ever contain widget IDS.
[1009] Fix | Delete
*
[1010] Fix | Delete
* Used as the 'sanitize_callback' for each $sidebars_widgets setting.
[1011] Fix | Delete
*
[1012] Fix | Delete
* @since 3.9.0
[1013] Fix | Delete
*
[1014] Fix | Delete
* @param string[] $widget_ids Array of widget IDs.
[1015] Fix | Delete
* @return string[] Array of sanitized widget IDs.
[1016] Fix | Delete
*/
[1017] Fix | Delete
public function sanitize_sidebar_widgets( $widget_ids ) {
[1018] Fix | Delete
$widget_ids = array_map( 'strval', (array) $widget_ids );
[1019] Fix | Delete
$sanitized_widget_ids = array();
[1020] Fix | Delete
foreach ( $widget_ids as $widget_id ) {
[1021] Fix | Delete
$sanitized_widget_ids[] = preg_replace( '/[^a-z0-9_\-]/', '', $widget_id );
[1022] Fix | Delete
}
[1023] Fix | Delete
return $sanitized_widget_ids;
[1024] Fix | Delete
}
[1025] Fix | Delete
[1026] Fix | Delete
/**
[1027] Fix | Delete
* Builds up an index of all available widgets for use in Backbone models.
[1028] Fix | Delete
*
[1029] Fix | Delete
* @since 3.9.0
[1030] Fix | Delete
*
[1031] Fix | Delete
* @global array $wp_registered_widgets
[1032] Fix | Delete
* @global array $wp_registered_widget_controls
[1033] Fix | Delete
*
[1034] Fix | Delete
* @see wp_list_widgets()
[1035] Fix | Delete
*
[1036] Fix | Delete
* @return array List of available widgets.
[1037] Fix | Delete
*/
[1038] Fix | Delete
public function get_available_widgets() {
[1039] Fix | Delete
static $available_widgets = array();
[1040] Fix | Delete
if ( ! empty( $available_widgets ) ) {
[1041] Fix | Delete
return $available_widgets;
[1042] Fix | Delete
}
[1043] Fix | Delete
[1044] Fix | Delete
global $wp_registered_widgets, $wp_registered_widget_controls;
[1045] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/widgets.php'; // For next_widget_id_number().
[1046] Fix | Delete
[1047] Fix | Delete
$sort = $wp_registered_widgets;
[1048] Fix | Delete
usort( $sort, array( $this, '_sort_name_callback' ) );
[1049] Fix | Delete
$done = array();
[1050] Fix | Delete
[1051] Fix | Delete
foreach ( $sort as $widget ) {
[1052] Fix | Delete
if ( in_array( $widget['callback'], $done, true ) ) { // We already showed this multi-widget.
[1053] Fix | Delete
continue;
[1054] Fix | Delete
}
[1055] Fix | Delete
[1056] Fix | Delete
$sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false );
[1057] Fix | Delete
$done[] = $widget['callback'];
[1058] Fix | Delete
[1059] Fix | Delete
if ( ! isset( $widget['params'][0] ) ) {
[1060] Fix | Delete
$widget['params'][0] = array();
[1061] Fix | Delete
}
[1062] Fix | Delete
[1063] Fix | Delete
$available_widget = $widget;
[1064] Fix | Delete
unset( $available_widget['callback'] ); // Not serializable to JSON.
[1065] Fix | Delete
[1066] Fix | Delete
$args = array(
[1067] Fix | Delete
'widget_id' => $widget['id'],
[1068] Fix | Delete
'widget_name' => $widget['name'],
[1069] Fix | Delete
'_display' => 'template',
[1070] Fix | Delete
);
[1071] Fix | Delete
[1072] Fix | Delete
$is_disabled = false;
[1073] Fix | Delete
$is_multi_widget = ( isset( $wp_registered_widget_controls[ $widget['id'] ]['id_base'] ) && isset( $widget['params'][0]['number'] ) );
[1074] Fix | Delete
if ( $is_multi_widget ) {
[1075] Fix | Delete
$id_base = $wp_registered_widget_controls[ $widget['id'] ]['id_base'];
[1076] Fix | Delete
$args['_temp_id'] = "$id_base-__i__";
[1077] Fix | Delete
$args['_multi_num'] = next_widget_id_number( $id_base );
[1078] Fix | Delete
$args['_add'] = 'multi';
[1079] Fix | Delete
} else {
[1080] Fix | Delete
$args['_add'] = 'single';
[1081] Fix | Delete
[1082] Fix | Delete
if ( $sidebar && 'wp_inactive_widgets' !== $sidebar ) {
[1083] Fix | Delete
$is_disabled = true;
[1084] Fix | Delete
}
[1085] Fix | Delete
$id_base = $widget['id'];
[1086] Fix | Delete
}
[1087] Fix | Delete
[1088] Fix | Delete
$list_widget_controls_args = wp_list_widget_controls_dynamic_sidebar(
[1089] Fix | Delete
array(
[1090] Fix | Delete
0 => $args,
[1091] Fix | Delete
1 => $widget['params'][0],
[1092] Fix | Delete
)
[1093] Fix | Delete
);
[1094] Fix | Delete
$control_tpl = $this->get_widget_control( $list_widget_controls_args );
[1095] Fix | Delete
[1096] Fix | Delete
// The properties here are mapped to the Backbone Widget model.
[1097] Fix | Delete
$available_widget = array_merge(
[1098] Fix | Delete
$available_widget,
[1099] Fix | Delete
array(
[1100] Fix | Delete
'temp_id' => isset( $args['_temp_id'] ) ? $args['_temp_id'] : null,
[1101] Fix | Delete
'is_multi' => $is_multi_widget,
[1102] Fix | Delete
'control_tpl' => $control_tpl,
[1103] Fix | Delete
'multi_number' => ( 'multi' === $args['_add'] ) ? $args['_multi_num'] : false,
[1104] Fix | Delete
'is_disabled' => $is_disabled,
[1105] Fix | Delete
'id_base' => $id_base,
[1106] Fix | Delete
'transport' => $this->is_widget_selective_refreshable( $id_base ) ? 'postMessage' : 'refresh',
[1107] Fix | Delete
'width' => $wp_registered_widget_controls[ $widget['id'] ]['width'],
[1108] Fix | Delete
'height' => $wp_registered_widget_controls[ $widget['id'] ]['height'],
[1109] Fix | Delete
'is_wide' => $this->is_wide_widget( $widget['id'] ),
[1110] Fix | Delete
)
[1111] Fix | Delete
);
[1112] Fix | Delete
[1113] Fix | Delete
$available_widgets[] = $available_widget;
[1114] Fix | Delete
}
[1115] Fix | Delete
[1116] Fix | Delete
return $available_widgets;
[1117] Fix | Delete
}
[1118] Fix | Delete
[1119] Fix | Delete
/**
[1120] Fix | Delete
* Naturally orders available widgets by name.
[1121] Fix | Delete
*
[1122] Fix | Delete
* @since 3.9.0
[1123] Fix | Delete
*
[1124] Fix | Delete
* @param array $widget_a The first widget to compare.
[1125] Fix | Delete
* @param array $widget_b The second widget to compare.
[1126] Fix | Delete
* @return int Reorder position for the current widget comparison.
[1127] Fix | Delete
*/
[1128] Fix | Delete
protected function _sort_name_callback( $widget_a, $widget_b ) {
[1129] Fix | Delete
return strnatcasecmp( $widget_a['name'], $widget_b['name'] );
[1130] Fix | Delete
}
[1131] Fix | Delete
[1132] Fix | Delete
/**
[1133] Fix | Delete
* Retrieves the widget control markup.
[1134] Fix | Delete
*
[1135] Fix | Delete
* @since 3.9.0
[1136] Fix | Delete
*
[1137] Fix | Delete
* @param array $args Widget control arguments.
[1138] Fix | Delete
* @return string Widget control form HTML markup.
[1139] Fix | Delete
*/
[1140] Fix | Delete
public function get_widget_control( $args ) {
[1141] Fix | Delete
$args[0]['before_form'] = '<div class="form">';
[1142] Fix | Delete
$args[0]['after_form'] = '</div><!-- .form -->';
[1143] Fix | Delete
$args[0]['before_widget_content'] = '<div class="widget-content">';
[1144] Fix | Delete
$args[0]['after_widget_content'] = '</div><!-- .widget-content -->';
[1145] Fix | Delete
ob_start();
[1146] Fix | Delete
wp_widget_control( ...$args );
[1147] Fix | Delete
$control_tpl = ob_get_clean();
[1148] Fix | Delete
return $control_tpl;
[1149] Fix | Delete
}
[1150] Fix | Delete
[1151] Fix | Delete
/**
[1152] Fix | Delete
* Retrieves the widget control markup parts.
[1153] Fix | Delete
*
[1154] Fix | Delete
* @since 4.4.0
[1155] Fix | Delete
*
[1156] Fix | Delete
* @param array $args Widget control arguments.
[1157] Fix | Delete
* @return array {
[1158] Fix | Delete
* @type string $control Markup for widget control wrapping form.
[1159] Fix | Delete
* @type string $content The contents of the widget form itself.
[1160] Fix | Delete
* }
[1161] Fix | Delete
*/
[1162] Fix | Delete
public function get_widget_control_parts( $args ) {
[1163] Fix | Delete
$args[0]['before_widget_content'] = '<div class="widget-content">';
[1164] Fix | Delete
$args[0]['after_widget_content'] = '</div><!-- .widget-content -->';
[1165] Fix | Delete
$control_markup = $this->get_widget_control( $args );
[1166] Fix | Delete
[1167] Fix | Delete
$content_start_pos = strpos( $control_markup, $args[0]['before_widget_content'] );
[1168] Fix | Delete
$content_end_pos = strrpos( $control_markup, $args[0]['after_widget_content'] );
[1169] Fix | Delete
[1170] Fix | Delete
$control = substr( $control_markup, 0, $content_start_pos + strlen( $args[0]['before_widget_content'] ) );
[1171] Fix | Delete
$control .= substr( $control_markup, $content_end_pos );
[1172] Fix | Delete
$content = trim(
[1173] Fix | Delete
substr(
[1174] Fix | Delete
$control_markup,
[1175] Fix | Delete
$content_start_pos + strlen( $args[0]['before_widget_content'] ),
[1176] Fix | Delete
$content_end_pos - $content_start_pos - strlen( $args[0]['before_widget_content'] )
[1177] Fix | Delete
)
[1178] Fix | Delete
);
[1179] Fix | Delete
[1180] Fix | Delete
return compact( 'control', 'content' );
[1181] Fix | Delete
}
[1182] Fix | Delete
[1183] Fix | Delete
/**
[1184] Fix | Delete
* Adds hooks for the Customizer preview.
[1185] Fix | Delete
*
[1186] Fix | Delete
* @since 3.9.0
[1187] Fix | Delete
*/
[1188] Fix | Delete
public function customize_preview_init() {
[1189] Fix | Delete
add_action( 'wp_enqueue_scripts', array( $this, 'customize_preview_enqueue' ) );
[1190] Fix | Delete
add_action( 'wp_print_styles', array( $this, 'print_preview_css' ), 1 );
[1191] Fix | Delete
add_action( 'wp_footer', array( $this, 'export_preview_data' ), 20 );
[1192] Fix | Delete
}
[1193] Fix | Delete
[1194] Fix | Delete
/**
[1195] Fix | Delete
* Refreshes the nonce for widget updates.
[1196] Fix | Delete
*
[1197] Fix | Delete
* @since 4.2.0
[1198] Fix | Delete
*
[1199] Fix | Delete
* @param array $nonces Array of nonces.
[1200] Fix | Delete
* @return array Array of nonces.
[1201] Fix | Delete
*/
[1202] Fix | Delete
public function refresh_nonces( $nonces ) {
[1203] Fix | Delete
$nonces['update-widget'] = wp_create_nonce( 'update-widget' );
[1204] Fix | Delete
return $nonces;
[1205] Fix | Delete
}
[1206] Fix | Delete
[1207] Fix | Delete
/**
[1208] Fix | Delete
* Tells the script loader to load the scripts and styles of custom blocks
[1209] Fix | Delete
* if the widgets block editor is enabled.
[1210] Fix | Delete
*
[1211] Fix | Delete
* @since 5.8.0
[1212] Fix | Delete
*
[1213] Fix | Delete
* @param bool $is_block_editor_screen Current decision about loading block assets.
[1214] Fix | Delete
* @return bool Filtered decision about loading block assets.
[1215] Fix | Delete
*/
[1216] Fix | Delete
public function should_load_block_editor_scripts_and_styles( $is_block_editor_screen ) {
[1217] Fix | Delete
if ( wp_use_widgets_block_editor() ) {
[1218] Fix | Delete
return true;
[1219] Fix | Delete
}
[1220] Fix | Delete
[1221] Fix | Delete
return $is_block_editor_screen;
[1222] Fix | Delete
}
[1223] Fix | Delete
[1224] Fix | Delete
/**
[1225] Fix | Delete
* When previewing, ensures the proper previewing widgets are used.
[1226] Fix | Delete
*
[1227] Fix | Delete
* Because wp_get_sidebars_widgets() gets called early at {@see 'init' } (via
[1228] Fix | Delete
* wp_convert_widget_settings()) and can set global variable `$_wp_sidebars_widgets`
[1229] Fix | Delete
* to the value of `get_option( 'sidebars_widgets' )` before the Customizer preview
[1230] Fix | Delete
* filter is added, it has to be reset after the filter has been added.
[1231] Fix | Delete
*
[1232] Fix | Delete
* @since 3.9.0
[1233] Fix | Delete
*
[1234] Fix | Delete
* @param array $sidebars_widgets List of widgets for the current sidebar.
[1235] Fix | Delete
* @return array
[1236] Fix | Delete
*/
[1237] Fix | Delete
public function preview_sidebars_widgets( $sidebars_widgets ) {
[1238] Fix | Delete
$sidebars_widgets = get_option( 'sidebars_widgets', array() );
[1239] Fix | Delete
[1240] Fix | Delete
unset( $sidebars_widgets['array_version'] );
[1241] Fix | Delete
return $sidebars_widgets;
[1242] Fix | Delete
}
[1243] Fix | Delete
[1244] Fix | Delete
/**
[1245] Fix | Delete
* Enqueues scripts for the Customizer preview.
[1246] Fix | Delete
*
[1247] Fix | Delete
* @since 3.9.0
[1248] Fix | Delete
*/
[1249] Fix | Delete
public function customize_preview_enqueue() {
[1250] Fix | Delete
wp_enqueue_script( 'customize-preview-widgets' );
[1251] Fix | Delete
}
[1252] Fix | Delete
[1253] Fix | Delete
/**
[1254] Fix | Delete
* Inserts default style for highlighted widget at early point so theme
[1255] Fix | Delete
* stylesheet can override.
[1256] Fix | Delete
*
[1257] Fix | Delete
* @since 3.9.0
[1258] Fix | Delete
*/
[1259] Fix | Delete
public function print_preview_css() {
[1260] Fix | Delete
?>
[1261] Fix | Delete
<style>
[1262] Fix | Delete
.widget-customizer-highlighted-widget {
[1263] Fix | Delete
outline: none;
[1264] Fix | Delete
-webkit-box-shadow: 0 0 2px rgba(30, 140, 190, 0.8);
[1265] Fix | Delete
box-shadow: 0 0 2px rgba(30, 140, 190, 0.8);
[1266] Fix | Delete
position: relative;
[1267] Fix | Delete
z-index: 1;
[1268] Fix | Delete
}
[1269] Fix | Delete
</style>
[1270] Fix | Delete
<?php
[1271] Fix | Delete
}
[1272] Fix | Delete
[1273] Fix | Delete
/**
[1274] Fix | Delete
* Communicates the sidebars that appeared on the page at the very end of the page,
[1275] Fix | Delete
* and at the very end of the wp_footer,
[1276] Fix | Delete
*
[1277] Fix | Delete
* @since 3.9.0
[1278] Fix | Delete
*
[1279] Fix | Delete
* @global array $wp_registered_sidebars
[1280] Fix | Delete
* @global array $wp_registered_widgets
[1281] Fix | Delete
*/
[1282] Fix | Delete
public function export_preview_data() {
[1283] Fix | Delete
global $wp_registered_sidebars, $wp_registered_widgets;
[1284] Fix | Delete
[1285] Fix | Delete
$switched_locale = switch_to_user_locale( get_current_user_id() );
[1286] Fix | Delete
[1287] Fix | Delete
$l10n = array(
[1288] Fix | Delete
'widgetTooltip' => __( 'Shift-click to edit this widget.' ),
[1289] Fix | Delete
);
[1290] Fix | Delete
[1291] Fix | Delete
if ( $switched_locale ) {
[1292] Fix | Delete
restore_previous_locale();
[1293] Fix | Delete
}
[1294] Fix | Delete
[1295] Fix | Delete
$rendered_sidebars = array_filter( $this->rendered_sidebars );
[1296] Fix | Delete
$rendered_widgets = array_filter( $this->rendered_widgets );
[1297] Fix | Delete
[1298] Fix | Delete
// Prepare Customizer settings to pass to JavaScript.
[1299] Fix | Delete
$settings = array(
[1300] Fix | Delete
'renderedSidebars' => array_fill_keys( array_keys( $rendered_sidebars ), true ),
[1301] Fix | Delete
'renderedWidgets' => array_fill_keys( array_keys( $rendered_widgets ), true ),
[1302] Fix | Delete
'registeredSidebars' => array_values( $wp_registered_sidebars ),
[1303] Fix | Delete
'registeredWidgets' => $wp_registered_widgets,
[1304] Fix | Delete
'l10n' => $l10n,
[1305] Fix | Delete
'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(),
[1306] Fix | Delete
);
[1307] Fix | Delete
[1308] Fix | Delete
foreach ( $settings['registeredWidgets'] as &$registered_widget ) {
[1309] Fix | Delete
unset( $registered_widget['callback'] ); // May not be JSON-serializable.
[1310] Fix | Delete
}
[1311] Fix | Delete
wp_print_inline_script_tag(
[1312] Fix | Delete
sprintf( 'var _wpWidgetCustomizerPreviewSettings = %s;', wp_json_encode( $settings ) )
[1313] Fix | Delete
);
[1314] Fix | Delete
}
[1315] Fix | Delete
[1316] Fix | Delete
/**
[1317] Fix | Delete
* Tracks the widgets that were rendered.
[1318] Fix | Delete
*
[1319] Fix | Delete
* @since 3.9.0
[1320] Fix | Delete
*
[1321] Fix | Delete
* @param array $widget Rendered widget to tally.
[1322] Fix | Delete
*/
[1323] Fix | Delete
public function tally_rendered_widgets( $widget ) {
[1324] Fix | Delete
$this->rendered_widgets[ $widget['id'] ] = true;
[1325] Fix | Delete
}
[1326] Fix | Delete
[1327] Fix | Delete
/**
[1328] Fix | Delete
* Determine if a widget is rendered on the page.
[1329] Fix | Delete
*
[1330] Fix | Delete
* @since 4.0.0
[1331] Fix | Delete
*
[1332] Fix | Delete
* @param string $widget_id Widget ID to check.
[1333] Fix | Delete
* @return bool Whether the widget is rendered.
[1334] Fix | Delete
*/
[1335] Fix | Delete
public function is_widget_rendered( $widget_id ) {
[1336] Fix | Delete
return ! empty( $this->rendered_widgets[ $widget_id ] );
[1337] Fix | Delete
}
[1338] Fix | Delete
[1339] Fix | Delete
/**
[1340] Fix | Delete
* Determines if a sidebar is rendered on the page.
[1341] Fix | Delete
*
[1342] Fix | Delete
* @since 4.0.0
[1343] Fix | Delete
*
[1344] Fix | Delete
* @param string $sidebar_id Sidebar ID to check.
[1345] Fix | Delete
* @return bool Whether the sidebar is rendered.
[1346] Fix | Delete
*/
[1347] Fix | Delete
public function is_sidebar_rendered( $sidebar_id ) {
[1348] Fix | Delete
return ! empty( $this->rendered_sidebars[ $sidebar_id ] );
[1349] Fix | Delete
}
[1350] Fix | Delete
[1351] Fix | Delete
/**
[1352] Fix | Delete
* Tallies the sidebars rendered via is_active_sidebar().
[1353] Fix | Delete
*
[1354] Fix | Delete
* Keep track of the times that is_active_sidebar() is called in the template,
[1355] Fix | Delete
* and assume that this means that the sidebar would be rendered on the template
[1356] Fix | Delete
* if there were widgets populating it.
[1357] Fix | Delete
*
[1358] Fix | Delete
* @since 3.9.0
[1359] Fix | Delete
*
[1360] Fix | Delete
* @param bool $is_active Whether the sidebar is active.
[1361] Fix | Delete
* @param string $sidebar_id Sidebar ID.
[1362] Fix | Delete
* @return bool Whether the sidebar is active.
[1363] Fix | Delete
*/
[1364] Fix | Delete
public function tally_sidebars_via_is_active_sidebar_calls( $is_active, $sidebar_id ) {
[1365] Fix | Delete
if ( is_registered_sidebar( $sidebar_id ) ) {
[1366] Fix | Delete
$this->rendered_sidebars[ $sidebar_id ] = true;
[1367] Fix | Delete
}
[1368] Fix | Delete
[1369] Fix | Delete
/*
[1370] Fix | Delete
* We may need to force this to true, and also force-true the value
[1371] Fix | Delete
* for 'dynamic_sidebar_has_widgets' if we want to ensure that there
[1372] Fix | Delete
* is an area to drop widgets into, if the sidebar is empty.
[1373] Fix | Delete
*/
[1374] Fix | Delete
return $is_active;
[1375] Fix | Delete
}
[1376] Fix | Delete
[1377] Fix | Delete
/**
[1378] Fix | Delete
* Tallies the sidebars rendered via dynamic_sidebar().
[1379] Fix | Delete
*
[1380] Fix | Delete
* Keep track of the times that dynamic_sidebar() is called in the template,
[1381] Fix | Delete
* and assume this means the sidebar would be rendered on the template if
[1382] Fix | Delete
* there were widgets populating it.
[1383] Fix | Delete
*
[1384] Fix | Delete
* @since 3.9.0
[1385] Fix | Delete
*
[1386] Fix | Delete
* @param bool $has_widgets Whether the current sidebar has widgets.
[1387] Fix | Delete
* @param string $sidebar_id Sidebar ID.
[1388] Fix | Delete
* @return bool Whether the current sidebar has widgets.
[1389] Fix | Delete
*/
[1390] Fix | Delete
public function tally_sidebars_via_dynamic_sidebar_calls( $has_widgets, $sidebar_id ) {
[1391] Fix | Delete
if ( is_registered_sidebar( $sidebar_id ) ) {
[1392] Fix | Delete
$this->rendered_sidebars[ $sidebar_id ] = true;
[1393] Fix | Delete
}
[1394] Fix | Delete
[1395] Fix | Delete
/*
[1396] Fix | Delete
* We may need to force this to true, and also force-true the value
[1397] Fix | Delete
* for 'is_active_sidebar' if we want to ensure there is an area to
[1398] Fix | Delete
* drop widgets into, if the sidebar is empty.
[1399] Fix | Delete
*/
[1400] Fix | Delete
return $has_widgets;
[1401] Fix | Delete
}
[1402] Fix | Delete
[1403] Fix | Delete
/**
[1404] Fix | Delete
* Retrieves MAC for a serialized widget instance string.
[1405] Fix | Delete
*
[1406] Fix | Delete
* Allows values posted back from JS to be rejected if any tampering of the
[1407] Fix | Delete
* data has occurred.
[1408] Fix | Delete
*
[1409] Fix | Delete
* @since 3.9.0
[1410] Fix | Delete
*
[1411] Fix | Delete
* @param string $serialized_instance Widget instance.
[1412] Fix | Delete
* @return string MAC for serialized widget instance.
[1413] Fix | Delete
*/
[1414] Fix | Delete
protected function get_instance_hash_key( $serialized_instance ) {
[1415] Fix | Delete
return wp_hash( $serialized_instance );
[1416] Fix | Delete
}
[1417] Fix | Delete
[1418] Fix | Delete
/**
[1419] Fix | Delete
* Sanitizes a widget instance.
[1420] Fix | Delete
*
[1421] Fix | Delete
* Unserialize the JS-instance for storing in the options. It's important that this filter
[1422] Fix | Delete
* only get applied to an instance *once*.
[1423] Fix | Delete
*
[1424] Fix | Delete
* @since 3.9.0
[1425] Fix | Delete
* @since 5.8.0 Added the `$id_base` parameter.
[1426] Fix | Delete
*
[1427] Fix | Delete
* @global WP_Widget_Factory $wp_widget_factory
[1428] Fix | Delete
*
[1429] Fix | Delete
* @param array $value Widget instance to sanitize.
[1430] Fix | Delete
* @param string $id_base Optional. Base of the ID of the widget being sanitized. Default null.
[1431] Fix | Delete
* @return array|void Sanitized widget instance.
[1432] Fix | Delete
*/
[1433] Fix | Delete
public function sanitize_widget_instance( $value, $id_base = null ) {
[1434] Fix | Delete
global $wp_widget_factory;
[1435] Fix | Delete
[1436] Fix | Delete
if ( array() === $value ) {
[1437] Fix | Delete
return $value;
[1438] Fix | Delete
}
[1439] Fix | Delete
[1440] Fix | Delete
if ( isset( $value['raw_instance'] ) && $id_base && wp_use_widgets_block_editor() ) {
[1441] Fix | Delete
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
[1442] Fix | Delete
if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) {
[1443] Fix | Delete
if ( 'block' === $id_base && ! current_user_can( 'unfiltered_html' ) ) {
[1444] Fix | Delete
/*
[1445] Fix | Delete
* The content of the 'block' widget is not filtered on the fly while editing.
[1446] Fix | Delete
* Filter the content here to prevent vulnerabilities.
[1447] Fix | Delete
*/
[1448] Fix | Delete
$value['raw_instance']['content'] = wp_kses_post( $value['raw_instance']['content'] );
[1449] Fix | Delete
}
[1450] Fix | Delete
[1451] Fix | Delete
return $value['raw_instance'];
[1452] Fix | Delete
}
[1453] Fix | Delete
}
[1454] Fix | Delete
[1455] Fix | Delete
if (
[1456] Fix | Delete
empty( $value['is_widget_customizer_js_value'] ) ||
[1457] Fix | Delete
empty( $value['instance_hash_key'] ) ||
[1458] Fix | Delete
empty( $value['encoded_serialized_instance'] )
[1459] Fix | Delete
) {
[1460] Fix | Delete
return;
[1461] Fix | Delete
}
[1462] Fix | Delete
[1463] Fix | Delete
$decoded = base64_decode( $value['encoded_serialized_instance'], true );
[1464] Fix | Delete
if ( false === $decoded ) {
[1465] Fix | Delete
return;
[1466] Fix | Delete
}
[1467] Fix | Delete
[1468] Fix | Delete
if ( ! hash_equals( $this->get_instance_hash_key( $decoded ), $value['instance_hash_key'] ) ) {
[1469] Fix | Delete
return;
[1470] Fix | Delete
}
[1471] Fix | Delete
[1472] Fix | Delete
$instance = unserialize( $decoded );
[1473] Fix | Delete
if ( false === $instance ) {
[1474] Fix | Delete
return;
[1475] Fix | Delete
}
[1476] Fix | Delete
[1477] Fix | Delete
return $instance;
[1478] Fix | Delete
}
[1479] Fix | Delete
[1480] Fix | Delete
/**
[1481] Fix | Delete
* Converts a widget instance into JSON-representable format.
[1482] Fix | Delete
*
[1483] Fix | Delete
* @since 3.9.0
[1484] Fix | Delete
* @since 5.8.0 Added the `$id_base` parameter.
[1485] Fix | Delete
*
[1486] Fix | Delete
* @global WP_Widget_Factory $wp_widget_factory
[1487] Fix | Delete
*
[1488] Fix | Delete
* @param array $value Widget instance to convert to JSON.
[1489] Fix | Delete
* @param string $id_base Optional. Base of the ID of the widget being sanitized. Default null.
[1490] Fix | Delete
* @return array JSON-converted widget instance.
[1491] Fix | Delete
*/
[1492] Fix | Delete
public function sanitize_widget_js_instance( $value, $id_base = null ) {
[1493] Fix | Delete
global $wp_widget_factory;
[1494] Fix | Delete
[1495] Fix | Delete
if ( empty( $value['is_widget_customizer_js_value'] ) ) {
[1496] Fix | Delete
$serialized = serialize( $value );
[1497] Fix | Delete
[1498] Fix | Delete
$js_value = array(
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function