wpseek.com
WordPress开发者和主题制作者的搜索引擎
wp_get_media_library_mode › WordPress Function
Since7.2.0
已弃用n/a
› wp_get_media_library_mode ( 没有参数 )
| 返回: |
|
| 定义在: |
|
| 文档: |
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.源码
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';
}