From 16c72e9e47598acaabb2c32ea69d9583b83e7277 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 23 Nov 2011 21:29:33 +0000 Subject: [PATCH] Move convert_to_screen() back to template.php to avoid fatal errors with plugins and themes that direct include template.php into the front end. Flag this bad behavior with _doing_it_wrong(). Props nacin. fixes #19342 git-svn-id: https://develop.svn.wordpress.org/trunk@19428 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/screen.php | 12 ------------ wp-admin/includes/template.php | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/wp-admin/includes/screen.php b/wp-admin/includes/screen.php index 2a6173edcf..fd6afb2d99 100644 --- a/wp-admin/includes/screen.php +++ b/wp-admin/includes/screen.php @@ -107,18 +107,6 @@ function get_hidden_meta_boxes( $screen ) { return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults ); } -/** - * Convert a screen string to a screen object - * - * @since 3.0.0 - * - * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. - * @return WP_Screen Screen object. - */ -function convert_to_screen( $hook_name ) { - return WP_Screen::get( $hook_name ); -} - /** * Add contextual help text for a page. * diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 7705509b1c..06da772d6d 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -1795,4 +1795,21 @@ final class WP_Internal_Pointers { } } -add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); \ No newline at end of file +add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); + +/** + * Convert a screen string to a screen object + * + * @since 3.0.0 + * + * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. + * @return WP_Screen Screen object. + */ +function convert_to_screen( $hook_name ) { + if ( ! is_admin() ) { + _doing_it_wrong( 'convert_to_screen(), add_meta_box()', __( "Likely direct inclusion of wp-admin/includes/template.php in order to use add_meta_box(). This is very wrong. Hook the add_meta_box() call into the add_meta_boxes action instead." ), '3.3' ); + return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' ); + } + + return WP_Screen::get( $hook_name ); +} \ No newline at end of file