So basically, what I’m trying to do is to hook a static method of a class to another static method of that same class.

Code is here :

class LocatorMap {
    
    public static function init() {

        add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register_scripts' ) );

    }

    /* add_action( 'wp_enqueue_script', array( 'LocatorMap', 'register_scripts' ) ); */
    public function register_scripts() {

        global $post;

        /* http or https */
        $scheme = parse_url( get_bloginfo('url'), PHP_URL_SCHEME );

        /* register gmaps api and info box */
        wp_register_script( 'google-maps-api', $scheme . '://maps.googleapis.com/maps/api/js', array('jquery'), FALSE, true );
        wp_register_script( 'google-maps-info-box', $scheme . '://cdn.rawgit.com/googlemaps/v3-utility-library/infobox/1.1.13/src/infobox.js', array( 'jquery', 'google-maps-api' ), '1.1.13', true ); 

    }
}

Is this possible? I don’t know since I’m a bit new on this kind of a structure.

UPDATE
I am also calling this class on an external file.

define( DEALERSHIP_MAP_URL, untrailingslashit( plugin_dir_url( __FILE__ ) )  );
define( DEALERSHIP_MAP_DIR, untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( DEALERSHIP_MAP_TEMPLATE, DEALERSHIP_MAP_DIR . '/templates' );

require_once( 'core/class-locator-map.php' );

register_activation_hook( __FILE__, array( 'LocatorMap', 'init' ) );

3 Answers
3

register_activation_hook only runs once i.e. when the plugin is first activated – use the init hook instead to “boot up” your plugin:

add_action( 'init', 'LocatorMap::init' );

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *