将屏幕字符串转换为屏幕对象

原型

convert_to_screen( string $hook_name )

参数

$hook_name (string) (Required) 钩子名称(也称为钩子后缀)用于确定屏幕。

返回值

(WP_Screen)  屏幕对象。

源文件

路径:wp-admin/includes/template.php

<?php
...
function convert_to_screen( $hook_name ) {
	if ( ! class_exists( 'WP_Screen' ) ) {
		_doing_it_wrong(
			'convert_to_screen(), add_meta_box()',
			sprintf(
				/* translators: 1: wp-admin/includes/template.php 2: add_meta_box() 3: add_meta_boxes */
				__( 'Likely direct inclusion of %1$s in order to use %2$s. This is very wrong. Hook the %2$s call into the %3$s action instead.' ),
				'<code>wp-admin/includes/template.php</code>',
				'<code>add_meta_box()</code>',
				'<code>add_meta_boxes</code>'
			),
			'3.3.0'
		);
		return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' );
	}
	return WP_Screen::get( $hook_name );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/convert_to_screen/