Static function not registering in another file

I have a file that registers a class, Skizzar_Admin_Theme_Options, in that class are the following 3 functions (among others):

static function get_saved_option( $option_slug = '', $user_role = '', $include_user_meta = true, $network = false ) {

    $option_info = self::get_option_info( $option_slug );

    // Incompatible arguments
    if ( ! $option_slug || is_null( $option_info ) ) {
        return null;
    }

    // Prepare saved options
    $options = self::get_saved_options( $include_user_meta, $network );

    // Return role-based value
    if ( $option_info['role-based'] ) {

        // Get user role
        if ( ! $user_role ) {
            $user_role = Skizzar_Admin_Theme_User::get_user_role();
            $user_role = is_null( $user_role ) ? '' : $user_role;
        }

        // Return role-based value if it exists, or the default for new roles
        return isset( $options[ $option_slug ][ $user_role ] ) ? $options[ $option_slug ][ $user_role ] : $options[ $option_slug ]['sat-default'];

    }

    // Return
    return $options[ $option_slug ];

}

// Shortcut to get a network option
static function get_saved_network_option( $option_slug = '' ) {
    return self::get_saved_option( $option_slug, '', true, true );
}

// Return global values if single site dettings are disabled 
static function get_skizzar_admin_option() {
    $is_network_only = ( is_multisite() && Skizzar_Admin_Theme_Options::get_saved_network_option( 'enable-global-settings' ) ) ? 'get_saved_network_option' : 'get_saved_option';
    return $is_network_only;
}

They are, get_saved_option() which returns plugin options saved from a single wordpress site, get_network_saved_option() which returns plugin options from the network admin if a multisite install. And also get_skizzar_admin_option(), which checks if the site is a multisite, and the user has chosen to use global settings instead of single site settings and then returns either ‘get_saved_option’ or ‘get_network_saved_option’ depending on the outcome.

Read More

To call the class in other files in my plugin I use:

Skizzar_Admin_Theme_Options::get_skizzar_admin_option( [option-slug] )

for example, I can use this to get rid of a certain menu item in the toolbar:

if ( Skizzar_Admin_Theme_Options::get_skizzar_admin_option( 'hide-toolbar-updates' ) ) {
    $wp_toolbar->remove_node( 'updates' );
}

This uses ‘get_skizzar_admin_option’ to check whether we should be looking at network saved options, or single site options.

My method is working, from what I can see, across all files except for one. The strange thing is, in this file, I can use:

Skizzar_Admin_Theme_Options::get_saved_option()

or

Skizzar_Admin_Theme_Options::get_network_saved_option

and it works fine, but when I use

Skizzar_Admin_Theme_Options::get_skizzar_admin_option

I get the error:

get_saved_network_option is not defined

Is there an obvious reason I’m missing why my function wouldn’t load in just one file?

Related posts

1 comment

  1. Kindly modify your get_skizzar_admin_option function as per follows and try.

    static function get_skizzar_admin_option() {
        $is_network_only = ( is_multisite() && self::get_saved_network_option( 'enable-global-settings' ) ) ? 'get_saved_network_option' : 'get_saved_option';
        return $is_network_only;
    }
    

Comments are closed.