WordPress.org

Ready to get started?Download WordPress

Forums

function convert_to_screen() no longer exists in template.php? (9 posts)

  1. artichokelucy
    Member
    Posted 1 year ago #

    I am making a widget that utilizes the wp_list_tables class. Everything works great in the plugin admin section.

    However, as soon as I simply instantiate my GB_List_Tables class, which extends WP_List_Tables, the widget throws a fatal error: undefined function convert_to_screen (url: http://heartwoodfarms.org/greenbox/ if you're curious, nothing much to see though)

    Here's my widget() function:

    //Display the widget
     function widget( $args, $instance ){
        	extract( $args );
            $title = empty($instance['title']) ? ' ' : apply_filters('my title', $instance['title']);
    	echo $before_widget;
    	// Display the widget title
    	if ( $title )
        	echo $before_title . $title . $after_title;
    
    	$list_table = new GB_List_Table();
        	echo $after_widget;
    }

    After much futile debuggery, I finally checked in template.php, and, sure enough, there is no function convert_to_screen() , even though that is where the function is supposed to reside.

    Is this something that was deprecated with a new version of wordpress? I have the latest: 3.5

    I have tried to copy and paste the convert_to_screen function into template.php, but I find myself in a seemingly endless stream of things that are required but are missing in order for convert_to_screen() to work.

    I'm stuck. Help would be greatly appreciated.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the function is still in /wp-admin/includes/template.php line 1860+

    possibly re-upload a new /wp-admin folder or template.php

  3. artichokelucy
    Member
    Posted 1 year ago #

    I have reuploaded all folders, as well as installed wordpress on my localhost to see if reinstalling the entire site would help. Nothing changed.

    When I copy the function code into wp-includes/template.php within 'if( ! function_exists('convert_to_screen') ) {} ' , it registers that the function exists, however it moves onto the error: class WP_Screen does not exist. I can keep hacking all these errors, but I feel like the issue is probably an easy fix, I just need to find the simple solution.

  4. artichokelucy
    Member
    Posted 1 year ago #

    Somehow, /wp-admin/includes/template.php is not being properly connected to the wp_list_table class. I tried loading the widget after the rest of the theme had loaded, thinking it was maybe that the files were being uploading in the improper order, but that didn't change anything.

    Also, the wp_list_tables class works great in my plugin's admin section. It's only when I try to instantiate the class in either a widget or a shortcode.

  5. artichokelucy
    Member
    Posted 1 year ago #

    If I put 'require_once(ABSPATH . 'wp-admin/includes/template.php' );' in class-wp-list-table.php , then it appears to recognize the function convert_to_screen, but instead throws the error: Notice: Undefined index: hook_suffix in /wordpress/wp-admin/includes/screen.php on line 401

  6. artichokelucy
    Member
    Posted 1 year ago #

    I also have to include
    'if( ! class_exists('WP_Screen') ) {
    require_once( ABSPATH . 'wp-admin/includes/screen.php' );
    }'
    in order for that to happen. Otherwise I just get:

    Notice: convert_to_screen(), add_meta_box() was called incorrectly. 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. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /Users/artichokes/Desktop/wordpress/wp-includes/functions.php on line 2944

  7. artichokelucy
    Member
    Posted 1 year ago #

    Well, hmmm. I appear to have fixed it. I put

    require_once(ABSPATH . 'wp-admin/includes/template.php' );
    
    if( ! class_exists('WP_Screen') ) {
    require_once( ABSPATH . 'wp-admin/includes/screen.php' );
    }

    into wp-list-table.php and then

    global $hook_suffix;

    in screen.php's get() function

    Is this something that should maybe be fixed on WordPress' end?

  8. shawn@eggplantstudios.ca
    Member
    Posted 1 year ago #

    Also have the exact same problem. Is there anyway to fix this without modifying the core?

  9. shawn@eggplantstudios.ca
    Member
    Posted 1 year ago #

    I solved it by adding

    require_once(ABSPATH . 'wp-admin/includes/template.php' );

    to my plugin file which creates the class; Then in my class constructor:

    parent::__construct( array(
                'singular'  => 'interval',     //singular name of the listed records
                'plural'    => 'intervals',    //plural name of the listed records
                'ajax'      => false,        //does this table support ajax?
                'screen'      => 'interval-list'        //hook suffix
            ) );

    Adding the 'screen' => 'interval-list' fixed the Hook Suffix error.

Topic Closed

This topic has been closed to new replies.

About this Topic