convert_to_screen

The timeline below displays how wordpress function convert_to_screen has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Converts 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 (!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);
}

WordPress Version: 5.1

/**
 * 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 (!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);
}

WordPress Version: 4.9

/**
 * 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 (!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);
}

WordPress Version: 4.7

/**
 * 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 (!class_exists('WP_Screen')) {
        _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.0');
        return (object) array('id' => '_invalid', 'base' => '_are_belong_to_us');
    }
    return WP_Screen::get($hook_name);
}

WordPress Version: 4.6

/**
 * 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 (!class_exists('WP_Screen', false)) {
        _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.0');
        return (object) array('id' => '_invalid', 'base' => '_are_belong_to_us');
    }
    return WP_Screen::get($hook_name);
}

WordPress Version: 4.4

/**
 * 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 (!class_exists('WP_Screen', false)) {
        _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);
}

WordPress Version: 3.7

/**
 * 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 (!class_exists('WP_Screen')) {
        _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);
}