BrilliantPlugins / geometa-acf

A GeoMeta custom field type for ACF
GNU General Public License v2.0
9 stars 3 forks source link

Where to add click handler #13

Open rimager opened 3 months ago

rimager commented 3 months ago

Hi there! I understand this Plugin likely isn't maintained, but could you give me any guidance where to add the jQuery click handler when I'm using geocod.io?

jQuery(document).on('geometa-acf/byo-geocode',function(e, origEvent, callback){

nciske commented 3 months ago

https://www.wpastronaut.com/blog/loading-javascript-files-in-wordpress/

rimager commented 3 months ago

Thank you! This worked for me. Much appreciated!!

function enqueue_admin_geo_script($hook)
{
    // Load only on ?page=mypluginname
    if ($hook != 'post.php' && $hook != 'post-new.php') {
        return;
    }

    wp_register_script('geo-api-script', TEMPLATE_URL . '/assets/js/geocode.js', array('jquery'));

    $api_key = 'XYZ';

    // Localize the script with the API key
    wp_localize_script('geo-api-script', 'geoVars', array(
        'apiKey' => $api_key,
    ));

    // Enqueue the script with localized data
    wp_enqueue_script('geo-api-script');
}