I am creating a set of plugins that all use AJAX. Now localizing the admin.php in all the plugins seems to be a bit of an overkill. Is there a way to localize the script only once.\
Now I do not know which plugin would be initialized at first, so I have to place the localize function in all the plugins.
The way I do it now is by the following code.
if( ! defined( 'AJAX_LOCALIZED' ) ){
define( 'AJAX_LOCALIZED', 1 );
wp_localize_script(
'my-ajax-script',
'ajax-object',
array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) )
);
}
This works ok, but maybe there is a build in method to do this, maybe more general that compliments with other plugins.