wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_get_media_library_mode › WordPress Function
Seit7.2.0
Veraltetn/v
› wp_get_media_library_mode ( Keine Parameter )
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Returns the current Media Library mode (grid or list).
Replicates the mode resolution in wp-admin/upload.php, which runs after theload-upload.php hook, without updating the saved user option.
upload.php falls back to grid mode for any falsey saved value and renders
grid mode only for the exact value 'grid'. A truthy saved value outside the
two known modes - one a plugin stored, say - therefore renders list mode
there and resolves to 'list' here, so callers do not isolate a page that
the Media Library renders in list mode.Quellcode
function wp_get_media_library_mode(): string {
$valid_modes = array( 'grid', 'list' );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $valid_modes, true ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
return $_GET['mode'];
}
$mode = get_user_option( 'media_library_mode', get_current_user_id() );
if ( in_array( $mode, $valid_modes, true ) ) {
return $mode;
}
// As in upload.php: nothing saved renders the grid, any other value the list.
return $mode ? 'list' : 'grid';
}