Extending Admin Class Error

Community Forums Forums General Discussion Extending Admin Class Error

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  Gary Jones 1 year, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #28389

    somweb
    Participant
    Post count: 2

    I wrote a theme where I extended the Admin class successfully. Doing it now for a plugin, I am getting the following error on the first line of the new extended class:

    class UVASOMNAVBAR_Settings extends Genesis_Admin_Boxes {

    When in debug mode, here is the error I get on the line above:

    Fatal error: Class 'Genesis_Admin_Boxes' not found

    I am running Genesis 1.9 and am installing the plugin on the child theme where I also extended the class. On the child theme, the name of the new child class is different, so I know it’s not conflicting.

    So, my question is, do you use a different class or syntax if you are extending the admin class in a plugin rather than in a child theme?

    #35072

    Gary Jones
    Moderator
    Post count: 693

    Plugins get set up by WP before themes do, so at the moment your plugin runs and the class gets parsed, none of the Genesis_Admin_* classes exist.

    What you need to do is to put your class into a different file, then wrap a function around the require() call, which is hooked into genesis_admin_init. You’ll see that hook fires at the end of genesis/lib/classes/admin.php.

    [php]
    // my-plugin/class-uvasomnavbar.php

    class UVASOMNAVBAR_Settings extends Genesis_Admin_Boxes {

    }
    [/php]

    [php]
    // my-plugin/my-plugin.php

    add_action( ‘genesis_admin_init’, ‘myplugin_admin_init’ );
    /**
    * Include admin class, now Genesis admin classes exist, then instantiate it.
    */
    function myplugin_admin_init() {
    require( ‘path/to/class-uvasomnavbar.php’ );
    new UVASOMNAVBAR_Settings();
    }
    [/php]


    Changes in Genesis 2.1 – the ultimate guide to every single change in Genesis Framework 2.1, 2.1.1 and 2.1.2 (all 90 of them!) | @GaryJ

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.