WordPress.org

Ready to get started?Download WordPress

Forums

function get_current_screen Can it use by themes/functions.php? (4 posts)

  1. nobita
    Member
    Posted 2 years ago #

    If this code is written, an error will occur. WordPress version 3.3 rc2 single

    $screen = get_current_screen();

    Above code create the error log below.

    [11-Dec-2011 09:32:08] PHP Fatal error: Call to undefined function get_current_screen() in /virtual/example/public_html/wp/wp-content/themes/twentyeleven/functions.php on line 596

    WordPress function get_current_screen was exists where wp-admin/includes/screen.php.

    But not included where functions.php

    check code:

    $included_files = get_included_files();
     var_dump($included_files);

    result
    theme/functions.php 134files included
    not exists wp-admin/includes/screen.php
    wp-admin/index.php 168files included
    exists wp-admin/includes/screen.php
    wp-admin/themes.php 167 files included
    exists wp-admin/includes/screen.php

    Please tell me How do I use this WordPress function?

    Thank you

  2. Big Bagel
    Member
    Posted 2 years ago #

    Unless I'm mistaken, get_current_screen is only intended for use when showing an administration screen. Its function is to return the current screen's hook suffix. If you want to explain what you're trying to do, I (or someone) might be able to provide a good alternative.

  3. nobita
    Member
    Posted 2 years ago #

    Hi Big Bagel

    I'm resolved

    My last test code works fine

    Thank you.

    add_action('admin_menu', 'my_theme_menu');
    function my_theme_menu() {
    	$theme_page= add_theme_page('My Theme Options','test','edit_theme_options','myslug','my_Theme_options');
    	if ( $theme_page ){	add_action( 'load-' . $theme_page, 'my_help_tabs_to_theme_page' );}
    }
    function my_theme_options() {
    	echo '<div class="wrap"><p>This is Theme Options page</p></div>';
    }
    function my_help_tabs_to_theme_page() {
    	$screen = get_current_screen();
    	$screen -> add_help_tab(array('id' => 'additional-plugin-help','title' => 'Special Instructions','content' => '<p>This is the content for the tab.</p>'));
    }
  4. Junior Grao
    Member
    Posted 2 years ago #

    Hi, nobita

    Enter in file functions.php and try to copy this:

    function get_current_screen() {
    global $current_screen;

    if ( ! isset( $current_screen ) )
    return null;

    return $current_screen;
    }

    Bests

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.