convert_to_screen

函式
convert_to_screen ( $hook_name )
引數
  • (string) $hook_name The hook name (also known as the hook suffix) used to determine the screen.
    Required:
返回值
  • (WP_Screen) Screen object.
定義位置
相關方法
convert_charsget_current_screenset_current_screenconvert_smilieswp_convert_hr_to_bytes
引入
3.0.0
棄用
-

WordPress中的convert_to_screen函式是一個實用函式,它可以將一個螢幕ID或WP_Screen類的例項轉換為WP_Screen物件。它主要是用來規範整個WordPress處理螢幕ID的方式,使開發者更容易管理和定製螢幕。

將一個螢幕字串轉換為一個螢幕物件。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >