reset( $user->id ); // Add some css ?>

Users can reset the following preferences they have made in the admin area with the defaults: which columns are hidden in admin list tables, which meta boxes are hidden, and where meta boxes are positioned on edit pages.

id ); // Get the current url without extra params if ( $user_id = helpdocs_get( 'user_id' ) ) { $current_url = helpdocs_get_current_admin_url( false ).'?user_id='.absint( $user_id ); } else { $current_url = helpdocs_get_current_admin_url( false ); } // Admin list columns ?>
Reset Hidden Admin List Columns $value ) { // Get only these meta keys if ( str_starts_with( $key, 'manageedit-' ) && str_ends_with( $key, 'columnshidden' ) ) { // Strip the key to get the post type $manageedit_post_type = str_replace( [ 'manageedit-', 'columnshidden' ], '', $key ); // Fetch the post type object $post_type_obj = get_post_type_object( $manageedit_post_type ); // Check if post type still exists, and is on this site // Note: user may have additional post type options for different sites if on multisite if ( !is_null( $post_type_obj ) ) { // Get the values $values = unserialize( $value[0] ); // Skip empty values if ( empty( $values ) ) { continue; } // Get the post type name $post_type_name = $post_type_obj->labels->name; // Add a link to reset only this post type $manageedit_links[ $post_type_name ] = ''.esc_html( $post_type_name ).' Only — currently hiding: '.esc_html( implode( ', ', $values ) ).''; } } } // If none found if ( empty( $manageedit_links ) ) { ?>None found ALL POST TYPES
⤷
Reset Hidden Meta Boxes $value ) { // Get only these meta keys if ( str_starts_with( $key, 'metaboxhidden_' ) ) { // Strip the key to get the post type $metaboxhidden_area = str_replace( 'metaboxhidden_', '', $key ); // Fetch the post type object $post_type_obj = get_post_type_object( $metaboxhidden_area ); // Allowed exceptions $exceptions = [ 'dashboard' => 'Dashboard', 'dashboard-network' => 'Dashboard (Network)', 'nav-menus' => 'Navigation Menus' ]; // Check if post type still exists, and is on this site // Note: user may have additional post type options for different sites if on multisite if ( !is_null( $post_type_obj ) || array_key_exists( $metaboxhidden_area, $exceptions ) ) { // Get the values $values = unserialize( $value[0] ); // Skip empty values if ( empty( $values ) ) { continue; } // Get the post type name if ( !is_null( $post_type_obj ) ) { $name = $post_type_obj->labels->name; } else { $name = $exceptions[ $metaboxhidden_area ]; } // Add a link to reset only this post type $metaboxhidden_links[ $name ] = ''.esc_html( $name ).' Only — currently hiding: '.esc_html( implode( ', ', $values ) ).''; } } } // If none found if ( empty( $metaboxhidden_links ) ) { ?>None found ALL AREAS
⤷
Reset Meta Box Positions $value ) { // Get only these meta keys if ( str_starts_with( $key, 'meta-box-order_' ) ) { // Strip the key to get the post type $metaboxorder_area = str_replace( 'meta-box-order_', '', $key ); // Fetch the post type object $post_type_obj = get_post_type_object( $metaboxorder_area ); // Allowed exceptions $exceptions = [ 'dashboard' => 'Dashboard', 'dashboard-network' => 'Dashboard (Network)', 'nav-menus' => 'Navigation Menus' ]; // Check if post type still exists, and is on this site // Note: user may have additional post type options for different sites if on multisite if ( !is_null( $post_type_obj ) || array_key_exists( $metaboxorder_area, $exceptions ) ) { // Get the values $values = unserialize( $value[0] ); // Skip empty values if ( empty( $values ) ) { continue; } // Get the post type name if ( !is_null( $post_type_obj ) ) { $name = $post_type_obj->labels->name; } else { $name = $exceptions[ $metaboxorder_area ]; } // Add a link to reset only this post type $metaboxorder_links[ $name ] = ''.esc_html( $name ).' Only'; } } } // If none found if ( empty( $metaboxorder_links ) ) { ?>None found ALL AREAS
⤷
'manageedit-{value}columnshidden', 'metaboxhidden' => 'metaboxhidden_{value}', 'meta-box-order' => 'meta-box-order_{value}' ]; // Our meta key found $qs_param = false; $qs_value = false; // Iter the query strings foreach ( $_GET as $param => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended // Check if it's one of ours if ( array_key_exists( sanitize_text_field( $param ), $meta_keys ) ) { // Set the key/value $qs_param = sanitize_text_field( $param ); $qs_value = sanitize_text_field( $param ); // Stop at first instance break; } } // Stop if we didn't include one of our keys if ( !$qs_param && !$qs_value ) { return; } // If only a specified area if ( $value != 'all' ) { // Get the full meta key $meta_key_pattern = $meta_keys[ $qs_param ]; // Replace the value $meta_key = str_replace( '{value}', $qs_value, $meta_key_pattern ); // Delete the key delete_user_meta( $user_id, $meta_key ); // Otherwise we need to reset all of the user metakeys that match } else { // Get the user $user_meta = get_user_meta( $user_id ); // Split meta key regex $meta_key_pattern = $meta_keys[ $qs_param ]; $meta_key_parts = explode( '{value}', $meta_key_pattern ); // Iter to find what we are looking for foreach ( $user_meta as $key => $v ) { // Check for a meta key in the user meta if ( str_starts_with( $key, $meta_key_parts[0] ) && ( isset( $meta_key_parts[1] ) && str_ends_with( $key, $meta_key_parts[1] ) ) ) { // Delete the key delete_user_meta( $user_id, $key ); } } } // Remove the query string helpdocs_remove_qs_without_refresh( $qs_param ); } } // End reset() }