mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Coding Standards: Use strict type check for in_array()
and array_search()
.
This addresses all the remaining `WordPress.PHP.StrictInArray.MissingTrueStrict` issues in core. Includes minor code layout fixes for better readability. Follow-up to [47550]. See #49542. Built from https://develop.svn.wordpress.org/trunk@47557 git-svn-id: http://core.svn.wordpress.org/trunk@47332 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7097f6cef0
commit
856e1a27b8
@ -83,7 +83,7 @@ class Walker_Category_Checklist extends Walker {
|
||||
|
||||
$args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
|
||||
|
||||
$class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
|
||||
$class = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';
|
||||
|
||||
$args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
|
||||
|
||||
@ -91,7 +91,7 @@ class Walker_Category_Checklist extends Walker {
|
||||
$aria_checked = 'false';
|
||||
$inner_class = 'category';
|
||||
|
||||
if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
|
||||
if ( in_array( $category->term_id, $args['selected_cats'], true ) ) {
|
||||
$inner_class .= ' selected';
|
||||
$aria_checked = 'true';
|
||||
}
|
||||
@ -102,10 +102,13 @@ class Walker_Category_Checklist extends Walker {
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
|
||||
} else {
|
||||
$is_selected = in_array( $category->term_id, $args['selected_cats'], true );
|
||||
$is_disabled = ! empty( $args['disabled'] );
|
||||
|
||||
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
|
||||
'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
|
||||
checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
|
||||
disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
|
||||
checked( $is_selected, true, false ) .
|
||||
disabled( $is_disabled, true, false ) . ' /> ' .
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>';
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ class WP_Filesystem_Base {
|
||||
$attarray = preg_split( '//', $mode );
|
||||
|
||||
for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
|
||||
$key = array_search( $attarray[ $i ], $legal );
|
||||
$key = array_search( $attarray[ $i ], $legal, true );
|
||||
if ( $key ) {
|
||||
$realmode .= $legal[ $key ];
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ class WP_MS_Users_List_Table extends WP_List_Table {
|
||||
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
|
||||
}
|
||||
|
||||
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
|
||||
if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins, true ) ) {
|
||||
$actions['delete'] = '<a href="' . esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ class WP_Terms_List_Table extends WP_List_Table {
|
||||
$my_parent = get_term( $p, $taxonomy );
|
||||
$my_parents[] = $my_parent;
|
||||
$p = $my_parent->parent;
|
||||
if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops.
|
||||
if ( in_array( $p, $parent_ids, true ) ) { // Prevent parent loops.
|
||||
break;
|
||||
}
|
||||
$parent_ids[] = $p;
|
||||
|
@ -519,7 +519,7 @@ function wp_dashboard_quick_press( $error_msg = false ) {
|
||||
$post = get_default_post_to_edit( 'post', true );
|
||||
$user_id = get_current_user_id();
|
||||
// Don't create an option if this is a super admin who does not belong to this site.
|
||||
if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) {
|
||||
if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
|
||||
update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
|
||||
}
|
||||
}
|
||||
|
@ -922,19 +922,23 @@ function confirm_delete_users( $users ) {
|
||||
'fields' => array( 'ID', 'user_login' ),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
|
||||
$user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
|
||||
$user_dropdown = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
|
||||
$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
|
||||
$user_list = '';
|
||||
|
||||
foreach ( $blog_users as $user ) {
|
||||
if ( ! in_array( $user->ID, $allusers ) ) {
|
||||
if ( ! in_array( (int) $user->ID, $allusers, true ) ) {
|
||||
$user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
|
||||
}
|
||||
}
|
||||
|
||||
if ( '' == $user_list ) {
|
||||
$user_list = $admin_out;
|
||||
}
|
||||
|
||||
$user_dropdown .= $user_list;
|
||||
$user_dropdown .= "</select>\n";
|
||||
?>
|
||||
|
@ -1149,8 +1149,10 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte
|
||||
'post_status' => 'draft,publish',
|
||||
)
|
||||
);
|
||||
|
||||
$messages = array();
|
||||
$menu_items = array();
|
||||
|
||||
// Index menu items by DB ID.
|
||||
foreach ( $unsorted_menu_items as $_item ) {
|
||||
$menu_items[ $_item->db_id ] = $_item;
|
||||
@ -1173,6 +1175,7 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte
|
||||
);
|
||||
|
||||
wp_defer_term_counting( true );
|
||||
|
||||
// Loop through all the menu items' POST variables.
|
||||
if ( ! empty( $_POST['menu-item-db-id'] ) ) {
|
||||
foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
|
||||
@ -1209,19 +1212,22 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte
|
||||
// Store 'auto-add' pages.
|
||||
$auto_add = ! empty( $_POST['auto-add-pages'] );
|
||||
$nav_menu_option = (array) get_option( 'nav_menu_options' );
|
||||
|
||||
if ( ! isset( $nav_menu_option['auto_add'] ) ) {
|
||||
$nav_menu_option['auto_add'] = array();
|
||||
}
|
||||
|
||||
if ( $auto_add ) {
|
||||
if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) {
|
||||
if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ) ) {
|
||||
$nav_menu_option['auto_add'][] = $nav_menu_selected_id;
|
||||
}
|
||||
} else {
|
||||
$key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] );
|
||||
$key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'], true );
|
||||
if ( false !== $key ) {
|
||||
unset( $nav_menu_option['auto_add'][ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Remove non-existent/deleted menus.
|
||||
$nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
|
||||
update_option( 'nav_menu_options', $nav_menu_option );
|
||||
|
@ -2170,7 +2170,7 @@ function add_option_whitelist( $new_options, $options = '' ) {
|
||||
$whitelist_options[ $page ] = array();
|
||||
$whitelist_options[ $page ][] = $key;
|
||||
} else {
|
||||
$pos = array_search( $key, $whitelist_options[ $page ] );
|
||||
$pos = array_search( $key, $whitelist_options[ $page ], true );
|
||||
if ( false === $pos ) {
|
||||
$whitelist_options[ $page ][] = $key;
|
||||
}
|
||||
@ -2202,7 +2202,7 @@ function remove_option_whitelist( $del_options, $options = '' ) {
|
||||
foreach ( $del_options as $page => $keys ) {
|
||||
foreach ( $keys as $key ) {
|
||||
if ( isset( $whitelist_options[ $page ] ) && is_array( $whitelist_options[ $page ] ) ) {
|
||||
$pos = array_search( $key, $whitelist_options[ $page ] );
|
||||
$pos = array_search( $key, $whitelist_options[ $page ], true );
|
||||
if ( false !== $pos ) {
|
||||
unset( $whitelist_options[ $page ][ $pos ] );
|
||||
}
|
||||
|
@ -548,8 +548,8 @@ function bulk_edit_posts( $post_data = null ) {
|
||||
$children[] = $parent;
|
||||
|
||||
foreach ( $pages as $page ) {
|
||||
if ( $page->ID == $parent ) {
|
||||
$parent = $page->post_parent;
|
||||
if ( (int) $page->ID === $parent ) {
|
||||
$parent = (int) $page->post_parent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -568,7 +568,7 @@ function bulk_edit_posts( $post_data = null ) {
|
||||
$post_type_object = get_post_type_object( get_post_type( $post_ID ) );
|
||||
|
||||
if ( ! isset( $post_type_object )
|
||||
|| ( isset( $children ) && in_array( $post_ID, $children ) )
|
||||
|| ( isset( $children ) && in_array( $post_ID, $children, true ) )
|
||||
|| ! current_user_can( 'edit_post', $post_ID )
|
||||
) {
|
||||
$skipped[] = $post_ID;
|
||||
|
@ -314,7 +314,7 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
|
||||
// Now, grab the initial diff.
|
||||
$compare_two_mode = is_numeric( $from );
|
||||
if ( ! $compare_two_mode ) {
|
||||
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
|
||||
$found = array_search( $selected_revision_id, array_keys( $revisions ), true );
|
||||
if ( $found ) {
|
||||
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
|
||||
$from = reset( $from );
|
||||
|
@ -128,10 +128,12 @@ function meta_box_prefs( $screen ) {
|
||||
$widget_title = $box['args']['__widget_basename'];
|
||||
}
|
||||
|
||||
$is_hidden = in_array( $box['id'], $hidden, true );
|
||||
|
||||
printf(
|
||||
'<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>',
|
||||
esc_attr( $box['id'] ),
|
||||
checked( in_array( $box['id'], $hidden, true ), false, false ),
|
||||
checked( $is_hidden, false, false ),
|
||||
$widget_title
|
||||
);
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ function wp_terms_checklist( $post_id = 0, $args = array() ) {
|
||||
$keys = array_keys( $categories );
|
||||
|
||||
foreach ( $keys as $k ) {
|
||||
if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'] ) ) {
|
||||
if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) {
|
||||
$checked_categories[] = $categories[ $k ];
|
||||
unset( $categories[ $k ] );
|
||||
}
|
||||
@ -228,13 +228,14 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
|
||||
$tax = get_taxonomy( $taxonomy );
|
||||
|
||||
$popular_ids = array();
|
||||
|
||||
foreach ( (array) $terms as $term ) {
|
||||
$popular_ids[] = $term->term_id;
|
||||
if ( ! $echo ) { // Hack for Ajax use.
|
||||
continue;
|
||||
}
|
||||
$id = "popular-$taxonomy-$term->term_id";
|
||||
$checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
|
||||
$checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : '';
|
||||
?>
|
||||
|
||||
<li id="<?php echo $id; ?>" class="popular-category">
|
||||
@ -291,7 +292,7 @@ function wp_link_category_checklist( $link_id = 0 ) {
|
||||
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
$name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) );
|
||||
$checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
|
||||
$checked = in_array( $cat_id, $checked_categories, true ) ? ' checked="checked"' : '';
|
||||
echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, '</label></li>';
|
||||
}
|
||||
}
|
||||
@ -339,6 +340,7 @@ function get_inline_data( $post ) {
|
||||
}
|
||||
|
||||
$taxonomy_names = get_object_taxonomies( $post->post_type );
|
||||
|
||||
foreach ( $taxonomy_names as $taxonomy_name ) {
|
||||
$taxonomy = get_taxonomy( $taxonomy_name );
|
||||
|
||||
@ -721,7 +723,6 @@ function meta_form( $post = null ) {
|
||||
<select id="metakeyselect" name="metakeyselect">
|
||||
<option value="#NONE#"><?php _e( '— Select —' ); ?></option>
|
||||
<?php
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) ) {
|
||||
continue;
|
||||
@ -834,6 +835,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
|
||||
}
|
||||
|
||||
echo "\n\n";
|
||||
|
||||
$map = array(
|
||||
'mm' => array( $mm, $cur_mm ),
|
||||
'jj' => array( $jj, $cur_jj ),
|
||||
@ -841,6 +843,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
|
||||
'hh' => array( $hh, $cur_hh ),
|
||||
'mn' => array( $mn, $cur_mn ),
|
||||
);
|
||||
|
||||
foreach ( $map as $timeunit => $value ) {
|
||||
list( $unit, $curr ) = $value;
|
||||
|
||||
@ -868,7 +871,9 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
|
||||
*/
|
||||
function page_template_dropdown( $default = '', $post_type = 'page' ) {
|
||||
$templates = get_page_templates( null, $post_type );
|
||||
|
||||
ksort( $templates );
|
||||
|
||||
foreach ( array_keys( $templates ) as $template ) {
|
||||
$selected = selected( $default, $templates[ $template ], false );
|
||||
echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>';
|
||||
@ -1195,11 +1200,13 @@ function _get_plugin_from_callback( $callback ) {
|
||||
// Only show errors if the meta box was registered by a plugin.
|
||||
$filename = wp_normalize_path( $reflection->getFileName() );
|
||||
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
|
||||
|
||||
if ( strpos( $filename, $plugin_dir ) === 0 ) {
|
||||
$filename = str_replace( $plugin_dir, '', $filename );
|
||||
$filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename );
|
||||
|
||||
$plugins = get_plugins();
|
||||
|
||||
foreach ( $plugins as $name => $plugin ) {
|
||||
if ( strpos( $name, $filename ) === 0 ) {
|
||||
return $plugin;
|
||||
@ -1249,6 +1256,7 @@ function do_meta_boxes( $screen, $context, $object ) {
|
||||
// Grab the ones the user has manually sorted.
|
||||
// Pull them out of their previous context/priority and into the one the user chose.
|
||||
$sorted = get_user_option( "meta-box-order_$page" );
|
||||
|
||||
if ( ! $already_sorted && $sorted ) {
|
||||
foreach ( $sorted as $box_context => $ids ) {
|
||||
foreach ( explode( ',', $ids ) as $id ) {
|
||||
@ -1780,11 +1788,13 @@ function get_settings_errors( $setting = '', $sanitize = false ) {
|
||||
// Filter the results to those of a specific setting if one was set.
|
||||
if ( $setting ) {
|
||||
$setting_errors = array();
|
||||
|
||||
foreach ( (array) $wp_settings_errors as $key => $details ) {
|
||||
if ( $setting == $details['setting'] ) {
|
||||
$setting_errors[] = $wp_settings_errors[ $key ];
|
||||
}
|
||||
}
|
||||
|
||||
return $setting_errors;
|
||||
}
|
||||
|
||||
@ -1833,6 +1843,7 @@ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = fa
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
foreach ( $settings_errors as $key => $details ) {
|
||||
if ( 'updated' === $details['type'] ) {
|
||||
$details['type'] = 'success';
|
||||
@ -1855,6 +1866,7 @@ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = fa
|
||||
$output .= "<p><strong>{$details['message']}</strong></p>";
|
||||
$output .= "</div> \n";
|
||||
}
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
@ -2084,6 +2096,7 @@ function _post_states( $post, $echo = true ) {
|
||||
$i = 0;
|
||||
|
||||
$post_states_string .= ' — ';
|
||||
|
||||
foreach ( $post_states as $state ) {
|
||||
++$i;
|
||||
( $i == $state_count ) ? $sep = '' : $sep = ', ';
|
||||
@ -2188,7 +2201,7 @@ function _media_states( $post ) {
|
||||
if ( is_random_header_image() ) {
|
||||
$header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
|
||||
|
||||
if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) {
|
||||
if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images, true ) ) {
|
||||
$media_states[] = __( 'Header Image' );
|
||||
}
|
||||
} else {
|
||||
@ -2242,7 +2255,9 @@ function _media_states( $post ) {
|
||||
if ( ! empty( $media_states ) ) {
|
||||
$state_count = count( $media_states );
|
||||
$i = 0;
|
||||
|
||||
echo ' — ';
|
||||
|
||||
foreach ( $media_states as $state ) {
|
||||
++$i;
|
||||
( $i == $state_count ) ? $sep = '' : $sep = ', ';
|
||||
@ -2369,12 +2384,15 @@ function get_submit_button( $text = '', $type = 'primary large', $name = 'submit
|
||||
|
||||
$button_shorthand = array( 'primary', 'small', 'large' );
|
||||
$classes = array( 'button' );
|
||||
|
||||
foreach ( $type as $t ) {
|
||||
if ( 'secondary' === $t || 'button-secondary' === $t ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes[] = in_array( $t, $button_shorthand, true ) ? 'button-' . $t : $t;
|
||||
}
|
||||
|
||||
// Remove empty items, remove duplicate items, and finally build a string.
|
||||
$class = implode( ' ', array_unique( array_filter( $classes ) ) );
|
||||
|
||||
|
@ -104,8 +104,11 @@ switch ( $action ) {
|
||||
$next_item_data['menu_item_parent'] != $menu_item_data['menu_item_parent']
|
||||
)
|
||||
) {
|
||||
|
||||
$parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
|
||||
if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
|
||||
$parent_db_id = (int) $menu_item_data['menu_item_parent'];
|
||||
} else {
|
||||
$parent_db_id = 0;
|
||||
}
|
||||
|
||||
$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
|
||||
|
||||
@ -131,7 +134,7 @@ switch ( $action ) {
|
||||
// The item is last but still has a parent, so bubble up.
|
||||
} elseif (
|
||||
! empty( $menu_item_data['menu_item_parent'] ) &&
|
||||
in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids )
|
||||
in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true )
|
||||
) {
|
||||
$menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true );
|
||||
update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
|
||||
@ -168,11 +171,16 @@ switch ( $action ) {
|
||||
// If this menu item is a child of the previous.
|
||||
if (
|
||||
! empty( $menu_item_data['menu_item_parent'] ) &&
|
||||
in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) &&
|
||||
in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true ) &&
|
||||
isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) &&
|
||||
( $menu_item_data['menu_item_parent'] == $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
|
||||
) {
|
||||
$parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
|
||||
if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
|
||||
$parent_db_id = (int) $menu_item_data['menu_item_parent'];
|
||||
} else {
|
||||
$parent_db_id = 0;
|
||||
}
|
||||
|
||||
$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
|
||||
|
||||
if ( ! is_wp_error( $parent_object ) ) {
|
||||
@ -198,7 +206,7 @@ switch ( $action ) {
|
||||
! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] )
|
||||
) {
|
||||
$_possible_parent_id = (int) get_post_meta( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ], '_menu_item_menu_item_parent', true );
|
||||
if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) ) {
|
||||
if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ), true ) ) {
|
||||
$menu_item_data['menu_item_parent'] = $_possible_parent_id;
|
||||
} else {
|
||||
$menu_item_data['menu_item_parent'] = 0;
|
||||
@ -225,7 +233,7 @@ switch ( $action ) {
|
||||
} elseif (
|
||||
empty( $menu_item_data['menu_order'] ) ||
|
||||
empty( $menu_item_data['menu_item_parent'] ) ||
|
||||
! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) ||
|
||||
! in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true ) ||
|
||||
empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) ||
|
||||
$orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] != $menu_item_data['menu_item_parent']
|
||||
) {
|
||||
@ -800,9 +808,10 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
|
||||
<?php
|
||||
echo esc_html( $_nav_menu->truncated_name );
|
||||
|
||||
if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
|
||||
if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations, true ) ) {
|
||||
$locations_assigned_to_this_menu = array();
|
||||
foreach ( array_keys( $menu_locations, $_nav_menu->term_id ) as $menu_location_key ) {
|
||||
|
||||
foreach ( array_keys( $menu_locations, $_nav_menu->term_id, true ) as $menu_location_key ) {
|
||||
if ( isset( $locations[ $menu_location_key ] ) ) {
|
||||
$locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
|
||||
}
|
||||
@ -815,7 +824,9 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
|
||||
*
|
||||
* @param int $locations Number of menu locations to list. Default 3.
|
||||
*/
|
||||
$assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) );
|
||||
$locations_listed_per_menu = absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) );
|
||||
|
||||
$assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, $locations_listed_per_menu );
|
||||
|
||||
// Adds ellipses following the number of locations defined in $assigned_locations.
|
||||
if ( ! empty( $assigned_locations ) ) {
|
||||
@ -956,9 +967,10 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
|
||||
<?php
|
||||
if ( ! isset( $auto_add ) ) {
|
||||
$auto_add = get_option( 'nav_menu_options' );
|
||||
|
||||
if ( ! isset( $auto_add['auto_add'] ) ) {
|
||||
$auto_add = false;
|
||||
} elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) ) {
|
||||
} elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'], true ) ) {
|
||||
$auto_add = true;
|
||||
} else {
|
||||
$auto_add = false;
|
||||
|
@ -72,8 +72,9 @@ if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
|
||||
|
||||
$existing_details = get_site( $id );
|
||||
$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
|
||||
|
||||
foreach ( $blog_data_checkboxes as $c ) {
|
||||
if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) {
|
||||
if ( ! in_array( (int) $existing_details->$c, array( 0, 1 ), true ) ) {
|
||||
$blog_data[ $c ] = $existing_details->$c;
|
||||
} else {
|
||||
$blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0;
|
||||
@ -194,7 +195,7 @@ if ( ! empty( $messages ) ) {
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php _e( 'Set site attributes' ); ?></legend>
|
||||
<?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
|
||||
<label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( $details->$field_key, array( 0, 1 ) ) ); ?> />
|
||||
<label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( (int) $details->$field_key, array( 0, 1 ), true ) ); ?> />
|
||||
<?php echo $field_label; ?></label><br/>
|
||||
<?php endforeach; ?>
|
||||
<fieldset>
|
||||
|
@ -237,7 +237,7 @@ switch ( $wp_list_table->current_action() ) {
|
||||
|
||||
$all_userids = $userids;
|
||||
|
||||
if ( in_array( $current_user->ID, $userids ) ) {
|
||||
if ( in_array( $current_user->ID, $userids, true ) ) {
|
||||
$userids = array_diff( $userids, array( $current_user->ID ) );
|
||||
}
|
||||
|
||||
|
@ -1041,7 +1041,7 @@ class WP_Http {
|
||||
|
||||
// POST requests should not POST to a redirected location.
|
||||
if ( 'POST' == $args['method'] ) {
|
||||
if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) {
|
||||
if ( in_array( $response['response']['code'], array( 302, 303 ), true ) ) {
|
||||
$args['method'] = 'GET';
|
||||
}
|
||||
}
|
||||
|
@ -122,12 +122,14 @@ class Walker_Page extends Walker {
|
||||
|
||||
if ( ! empty( $current_page ) ) {
|
||||
$_current_page = get_post( $current_page );
|
||||
if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
|
||||
|
||||
if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
|
||||
$css_class[] = 'current_page_ancestor';
|
||||
}
|
||||
|
||||
if ( $page->ID == $current_page ) {
|
||||
$css_class[] = 'current_page_item';
|
||||
} elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
|
||||
} elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
|
||||
$css_class[] = 'current_page_parent';
|
||||
}
|
||||
} elseif ( get_option( 'page_for_posts' ) == $page->ID ) {
|
||||
|
@ -192,7 +192,7 @@ class WP_Http_Cookie {
|
||||
}
|
||||
|
||||
// Port - supports "port-lists" in the format: "80,8000,8080".
|
||||
if ( ! empty( $port ) && ! in_array( $url['port'], explode( ',', $port ) ) ) {
|
||||
if ( ! empty( $port ) && ! in_array( $url['port'], array_map( 'intval', explode( ',', $port ) ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ class WP_Http_Curl {
|
||||
curl_close( $handle );
|
||||
return new WP_Error( 'http_request_failed', $curl_error );
|
||||
}
|
||||
if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) {
|
||||
if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ), true ) ) {
|
||||
curl_close( $handle );
|
||||
return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) );
|
||||
}
|
||||
@ -286,7 +286,7 @@ class WP_Http_Curl {
|
||||
return new WP_Error( 'http_request_failed', $curl_error );
|
||||
}
|
||||
}
|
||||
if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) {
|
||||
if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ), true ) ) {
|
||||
curl_close( $handle );
|
||||
return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) );
|
||||
}
|
||||
|
@ -3137,7 +3137,7 @@ class WP_Query {
|
||||
$sticky_offset = 0;
|
||||
// Loop over posts and relocate stickies to the front.
|
||||
for ( $i = 0; $i < $num_posts; $i++ ) {
|
||||
if ( in_array( $this->posts[ $i ]->ID, $sticky_posts ) ) {
|
||||
if ( in_array( $this->posts[ $i ]->ID, $sticky_posts, true ) ) {
|
||||
$sticky_post = $this->posts[ $i ];
|
||||
// Remove sticky from current position.
|
||||
array_splice( $this->posts, $i, 1 );
|
||||
@ -3146,7 +3146,7 @@ class WP_Query {
|
||||
// Increment the sticky offset. The next sticky will be placed at this offset.
|
||||
$sticky_offset++;
|
||||
// Remove post from sticky posts array.
|
||||
$offset = array_search( $sticky_post->ID, $sticky_posts );
|
||||
$offset = array_search( $sticky_post->ID, $sticky_posts, true );
|
||||
unset( $sticky_posts[ $offset ] );
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ final class WP_Theme implements ArrayAccess {
|
||||
$this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' );
|
||||
// Default themes always trump their pretenders.
|
||||
// Properly identify default themes that are inside a directory within wp-content/themes.
|
||||
$default_theme_slug = array_search( $this->headers['Name'], self::$default_themes );
|
||||
$default_theme_slug = array_search( $this->headers['Name'], self::$default_themes, true );
|
||||
if ( $default_theme_slug ) {
|
||||
if ( basename( $this->stylesheet ) != $default_theme_slug ) {
|
||||
$this->headers['Name'] .= '/' . $this->stylesheet;
|
||||
|
@ -179,7 +179,7 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
|
||||
$value['auto_add'] = false;
|
||||
|
||||
if ( isset( $nav_menu_options['auto_add'] ) && is_array( $nav_menu_options['auto_add'] ) ) {
|
||||
$value['auto_add'] = in_array( $term->term_id, $nav_menu_options['auto_add'] );
|
||||
$value['auto_add'] = in_array( $term->term_id, $nav_menu_options['auto_add'], true );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,6 +188,7 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
|
||||
$value = $this->default;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -602,7 +603,8 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
|
||||
$nav_menu_options['auto_add'] = array();
|
||||
}
|
||||
|
||||
$i = array_search( $menu_id, $nav_menu_options['auto_add'] );
|
||||
$i = array_search( $menu_id, $nav_menu_options['auto_add'], true );
|
||||
|
||||
if ( $auto_add && false === $i ) {
|
||||
array_push( $nav_menu_options['auto_add'], $this->term_id );
|
||||
} elseif ( ! $auto_add && false !== $i ) {
|
||||
|
@ -2180,9 +2180,10 @@ function get_calendar( $initial = true, $echo = true ) {
|
||||
AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'",
|
||||
ARRAY_N
|
||||
);
|
||||
|
||||
if ( $dayswithposts ) {
|
||||
foreach ( (array) $dayswithposts as $daywith ) {
|
||||
$daywithpost[] = $daywith[0];
|
||||
$daywithpost[] = (int) $daywith[0];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2209,7 +2210,7 @@ function get_calendar( $initial = true, $echo = true ) {
|
||||
$calendar_output .= '<td>';
|
||||
}
|
||||
|
||||
if ( in_array( $day, $daywithpost ) ) {
|
||||
if ( in_array( $day, $daywithpost, true ) ) {
|
||||
// Any posts today?
|
||||
$date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
|
||||
/* translators: Post calendar label. %s: Date. */
|
||||
@ -2223,6 +2224,7 @@ function get_calendar( $initial = true, $echo = true ) {
|
||||
} else {
|
||||
$calendar_output .= $day;
|
||||
}
|
||||
|
||||
$calendar_output .= '</td>';
|
||||
|
||||
if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
|
||||
@ -2234,6 +2236,7 @@ function get_calendar( $initial = true, $echo = true ) {
|
||||
if ( 0 != $pad && 7 != $pad ) {
|
||||
$calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '"> </td>';
|
||||
}
|
||||
|
||||
$calendar_output .= "\n\t</tr>\n\t</tbody>";
|
||||
|
||||
$calendar_output .= "\n\t</table>";
|
||||
|
@ -3687,13 +3687,15 @@ function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
|
||||
$user_id = $user_id ? (int) $user_id : get_current_user_id();
|
||||
|
||||
$blogs = get_blogs_of_user( $user_id );
|
||||
|
||||
if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) {
|
||||
$url = user_admin_url( $path, $scheme );
|
||||
} elseif ( ! is_multisite() ) {
|
||||
$url = admin_url( $path, $scheme );
|
||||
} else {
|
||||
$current_blog = get_current_blog_id();
|
||||
if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
|
||||
|
||||
if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ), true ) ) ) {
|
||||
$url = admin_url( $path, $scheme );
|
||||
} else {
|
||||
$active = get_active_blog_for_user( $user_id );
|
||||
|
@ -392,7 +392,9 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
|
||||
}
|
||||
|
||||
// If the menu item corresponds to a taxonomy term for the currently queried non-hierarchical post object.
|
||||
if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) {
|
||||
if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type
|
||||
&& in_array( (int) $menu_item->object_id, $possible_object_parents, true )
|
||||
) {
|
||||
$active_parent_object_ids[] = (int) $menu_item->object_id;
|
||||
$active_parent_item_ids[] = (int) $menu_item->db_id;
|
||||
$active_object = $queried_object->post_type;
|
||||
@ -404,7 +406,8 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
|
||||
( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id )
|
||||
|| ( 'post_type' == $menu_item->type && $wp_query->is_singular )
|
||||
|| ( 'taxonomy' == $menu_item->type
|
||||
&& ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object )
|
||||
&& ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )
|
||||
&& $queried_object->taxonomy == $menu_item->object )
|
||||
)
|
||||
) {
|
||||
$classes[] = 'current-menu-item';
|
||||
@ -525,7 +528,7 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
|
||||
'post_type' == $parent_item->type
|
||||
&& ! empty( $queried_object->post_type )
|
||||
&& is_post_type_hierarchical( $queried_object->post_type )
|
||||
&& in_array( $parent_item->object_id, $queried_object->ancestors )
|
||||
&& in_array( (int) $parent_item->object_id, $queried_object->ancestors, true )
|
||||
&& $parent_item->object != $queried_object->ID
|
||||
) ||
|
||||
|
||||
@ -533,7 +536,7 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
|
||||
(
|
||||
'taxonomy' == $parent_item->type
|
||||
&& isset( $possible_taxonomy_ancestors[ $parent_item->object ] )
|
||||
&& in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] )
|
||||
&& in_array( (int) $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ], true )
|
||||
&& (
|
||||
! isset( $queried_object->term_id ) ||
|
||||
$parent_item->object_id != $queried_object->term_id
|
||||
|
@ -2284,7 +2284,12 @@ function is_sticky( $post_id = 0 ) {
|
||||
|
||||
$stickies = get_option( 'sticky_posts' );
|
||||
|
||||
$is_sticky = is_array( $stickies ) && in_array( $post_id, $stickies );
|
||||
if ( is_array( $stickies ) ) {
|
||||
$stickies = array_map( 'intval', $stickies );
|
||||
$is_sticky = in_array( $post_id, $stickies, true );
|
||||
} else {
|
||||
$is_sticky = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters whether a post is sticky.
|
||||
@ -2511,13 +2516,16 @@ function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) {
|
||||
* @param int $post_id Post ID.
|
||||
*/
|
||||
function stick_post( $post_id ) {
|
||||
$post_id = (int) $post_id;
|
||||
$stickies = get_option( 'sticky_posts' );
|
||||
|
||||
if ( ! is_array( $stickies ) ) {
|
||||
$stickies = array( $post_id );
|
||||
$stickies = array();
|
||||
}
|
||||
|
||||
if ( ! in_array( $post_id, $stickies ) ) {
|
||||
$stickies = array_map( 'intval', $stickies );
|
||||
|
||||
if ( ! in_array( $post_id, $stickies, true ) ) {
|
||||
$stickies[] = $post_id;
|
||||
}
|
||||
|
||||
@ -2545,17 +2553,20 @@ function stick_post( $post_id ) {
|
||||
* @param int $post_id Post ID.
|
||||
*/
|
||||
function unstick_post( $post_id ) {
|
||||
$post_id = (int) $post_id;
|
||||
$stickies = get_option( 'sticky_posts' );
|
||||
|
||||
if ( ! is_array( $stickies ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! in_array( $post_id, $stickies ) ) {
|
||||
$stickies = array_map( 'intval', $stickies );
|
||||
|
||||
if ( ! in_array( $post_id, $stickies, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$offset = array_search( $post_id, $stickies );
|
||||
$offset = array_search( $post_id, $stickies, true );
|
||||
if ( false === $offset ) {
|
||||
return;
|
||||
}
|
||||
@ -2842,7 +2853,9 @@ function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) {
|
||||
$mimes = array_map( 'trim', explode( ',', $type ) );
|
||||
foreach ( $mimes as $mime ) {
|
||||
$regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
|
||||
|
||||
$patternses[][ $type ] = "^$regex$";
|
||||
|
||||
if ( false === strpos( $mime, '/' ) ) {
|
||||
$patternses[][ $type ] = "^$regex/";
|
||||
$patternses[][ $type ] = $regex;
|
||||
@ -2854,12 +2867,15 @@ function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) {
|
||||
foreach ( $patternses as $patterns ) {
|
||||
foreach ( $patterns as $type => $pattern ) {
|
||||
foreach ( (array) $real_mime_types as $real ) {
|
||||
if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ] ) ) ) {
|
||||
if ( preg_match( "#$pattern#", $real )
|
||||
&& ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ], true ) )
|
||||
) {
|
||||
$matches[ $type ][] = $real;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $matches;
|
||||
}
|
||||
|
||||
@ -2914,9 +2930,11 @@ function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) {
|
||||
$wheres[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'";
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $wheres ) ) {
|
||||
$where = ' AND (' . join( ' OR ', $wheres ) . ') ';
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
@ -4436,15 +4454,16 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p
|
||||
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
|
||||
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
|
||||
|
||||
// Prevent new post slugs that could result in URLs that conflict with date archives.
|
||||
$post = get_post( $post_ID );
|
||||
|
||||
// Prevent new post slugs that could result in URLs that conflict with date archives.
|
||||
$conflicts_with_date_archive = false;
|
||||
if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) ) {
|
||||
$slug_num = intval( $slug );
|
||||
|
||||
if ( $slug_num ) {
|
||||
$permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
|
||||
$postname_index = array_search( '%postname%', $permastructs );
|
||||
$postname_index = array_search( '%postname%', $permastructs, true );
|
||||
|
||||
/*
|
||||
* Potential date clashes are as follows:
|
||||
@ -5500,7 +5519,7 @@ function get_pages( $args = array() ) {
|
||||
|
||||
$num_pages = count( $pages );
|
||||
for ( $i = 0; $i < $num_pages; $i++ ) {
|
||||
if ( in_array( $pages[ $i ]->ID, $exclude ) ) {
|
||||
if ( in_array( $pages[ $i ]->ID, $exclude, true ) ) {
|
||||
unset( $pages[ $i ] );
|
||||
}
|
||||
}
|
||||
@ -5811,6 +5830,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
|
||||
*/
|
||||
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
|
||||
$attachment_id = (int) $attachment_id;
|
||||
|
||||
$post = get_post( $attachment_id );
|
||||
if ( ! $post ) {
|
||||
return false;
|
||||
@ -5845,6 +5865,7 @@ function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
|
||||
*/
|
||||
function wp_update_attachment_metadata( $attachment_id, $data ) {
|
||||
$attachment_id = (int) $attachment_id;
|
||||
|
||||
$post = get_post( $attachment_id );
|
||||
if ( ! $post ) {
|
||||
return false;
|
||||
@ -5878,6 +5899,7 @@ function wp_update_attachment_metadata( $attachment_id, $data ) {
|
||||
*/
|
||||
function wp_get_attachment_url( $attachment_id = 0 ) {
|
||||
$attachment_id = (int) $attachment_id;
|
||||
|
||||
$post = get_post( $attachment_id );
|
||||
if ( ! $post ) {
|
||||
return false;
|
||||
|
@ -596,7 +596,7 @@ function url_to_postid( $url ) {
|
||||
parse_str( $query, $query_vars );
|
||||
$query = array();
|
||||
foreach ( (array) $query_vars as $key => $value ) {
|
||||
if ( in_array( $key, $wp->public_query_vars, true ) ) {
|
||||
if ( in_array( (string) $key, $wp->public_query_vars, true ) ) {
|
||||
$query[ $key ] = $value;
|
||||
if ( isset( $post_type_query_vars[ $key ] ) ) {
|
||||
$query['post_type'] = $post_type_query_vars[ $key ];
|
||||
|
@ -2468,16 +2468,20 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
|
||||
}
|
||||
|
||||
$term_info = term_exists( $term, $taxonomy );
|
||||
|
||||
if ( ! $term_info ) {
|
||||
// Skip if a non-existent term ID is passed.
|
||||
if ( is_int( $term ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$term_info = wp_insert_term( $term, $taxonomy );
|
||||
}
|
||||
|
||||
if ( is_wp_error( $term_info ) ) {
|
||||
return $term_info;
|
||||
}
|
||||
|
||||
$term_ids[] = $term_info['term_id'];
|
||||
$tt_id = $term_info['term_taxonomy_id'];
|
||||
$tt_ids[] = $tt_id;
|
||||
@ -2497,6 +2501,7 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
|
||||
* @param string $taxonomy Taxonomy slug.
|
||||
*/
|
||||
do_action( 'add_term_relationship', $object_id, $tt_id, $taxonomy );
|
||||
|
||||
$wpdb->insert(
|
||||
$wpdb->term_relationships,
|
||||
array(
|
||||
@ -2516,6 +2521,7 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
|
||||
* @param string $taxonomy Taxonomy slug.
|
||||
*/
|
||||
do_action( 'added_term_relationship', $object_id, $tt_id, $taxonomy );
|
||||
|
||||
$new_tt_ids[] = $tt_id;
|
||||
}
|
||||
|
||||
@ -2539,9 +2545,11 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
|
||||
}
|
||||
|
||||
$t = get_taxonomy( $taxonomy );
|
||||
|
||||
if ( ! $append && isset( $t->sort ) && $t->sort ) {
|
||||
$values = array();
|
||||
$term_order = 0;
|
||||
|
||||
$final_tt_ids = wp_get_object_terms(
|
||||
$object_id,
|
||||
$taxonomy,
|
||||
@ -2550,11 +2558,13 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
|
||||
'update_term_meta_cache' => false,
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $tt_ids as $tt_id ) {
|
||||
if ( in_array( $tt_id, $final_tt_ids ) ) {
|
||||
if ( in_array( (int) $tt_id, $final_tt_ids, true ) ) {
|
||||
$values[] = $wpdb->prepare( '(%d, %d, %d)', $object_id, $tt_id, ++$term_order );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $values ) {
|
||||
if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . ' ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)' ) ) {
|
||||
return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database.' ), $wpdb->last_error );
|
||||
@ -2578,6 +2588,7 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
|
||||
* @param array $old_tt_ids Old array of term taxonomy IDs.
|
||||
*/
|
||||
do_action( 'set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids );
|
||||
|
||||
return $tt_ids;
|
||||
}
|
||||
|
||||
@ -3616,8 +3627,10 @@ function _pad_term_counts( &$terms, $taxonomy ) {
|
||||
$tax_obj = get_taxonomy( $taxonomy );
|
||||
$object_types = esc_sql( $tax_obj->object_type );
|
||||
$results = $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode( ',', array_keys( $term_ids ) ) . ") AND post_type IN ('" . implode( "', '", $object_types ) . "') AND post_status = 'publish'" );
|
||||
|
||||
foreach ( $results as $row ) {
|
||||
$id = $term_ids[ $row->term_taxonomy_id ];
|
||||
|
||||
$term_items[ $id ][ $row->object_id ] = isset( $term_items[ $id ][ $row->object_id ] ) ? ++$term_items[ $id ][ $row->object_id ] : 1;
|
||||
}
|
||||
|
||||
@ -3627,14 +3640,16 @@ function _pad_term_counts( &$terms, $taxonomy ) {
|
||||
$ancestors = array();
|
||||
while ( ! empty( $terms_by_id[ $child ] ) && $parent = $terms_by_id[ $child ]->parent ) {
|
||||
$ancestors[] = $child;
|
||||
|
||||
if ( ! empty( $term_items[ $term_id ] ) ) {
|
||||
foreach ( $term_items[ $term_id ] as $item_id => $touches ) {
|
||||
$term_items[ $parent ][ $item_id ] = isset( $term_items[ $parent ][ $item_id ] ) ? ++$term_items[ $parent ][ $item_id ] : 1;
|
||||
}
|
||||
}
|
||||
|
||||
$child = $parent;
|
||||
|
||||
if ( in_array( $parent, $ancestors ) ) {
|
||||
if ( in_array( $parent, $ancestors, true ) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -4522,7 +4537,7 @@ function get_ancestors( $object_id = 0, $object_type = '', $resource_type = '' )
|
||||
|
||||
if ( 'taxonomy' === $resource_type ) {
|
||||
$term = get_term( $object_id, $object_type );
|
||||
while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
|
||||
while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors, true ) ) {
|
||||
$ancestors[] = (int) $term->parent;
|
||||
$term = get_term( $term->parent, $object_type );
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-alpha-47556';
|
||||
$wp_version = '5.5-alpha-47557';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user