Support » Plugin: Gravity Forms Placeholder Add-On » Please use wp_localize_script

Viewing 4 replies - 1 through 4 (of 4 total)
  • Agreed, this would make for a much cleaner plugin. There’s not reason JavaScript and PHP can’t *work* together, they just shouldn’t *live* together.

    Plugin Author phpmypython

    (@phpmypython)

    Since the plugin takes the labels generated by Gravity forms and then uses those as the placeholder values there shouldn’t be a reason for me to have to localize the script for translation.

    @phpmypython – He didn’t mean for localization. He meant for actually defining the variables you need in javascript. That’s the other (purposed) reason of wp_localize_script.

    In other words, in gravityform-placeholder-addon.php:

    add_action('wp_enqueue_scripts', 'gf_placeholder_addon_script_enqueue');
    
    function gf_placeholder_addon_script_enqueue() {
    	$placeholder_js = plugins_url( basename(dirname(__FILE__)) ).'"/jquery.placeholder-1.0.1.js';
    	wp_enqueue_script('gf_placeholder_add_on', $plugin_url . '/gfplaceholderaddon.js', array('jquery'), '1.0' );
    	wp_localize_script('gf_placeholder_add_on', 'gf_placeholder_vars', array('jquery_placeholder_url' => $placeholder_js) );
    }

    In your gfplaceholderaddon.js:

    if ( support && gf_placeholder_vars.jquery_placeholder_url )
    		$.ajax({
    			cache: true,
    			dataType: 'script',
    			url: gf_placeholder_vars.jquery_placeholder_url,
    			success: function() {
    				$('input[placeholder], textarea[placeholder]').placeholder({
    					blankSubmit: true
    				});
    			},
    			type: 'get'
    		});

    I made a couple of edits after my initial post, so make sure you don’t rely on the initial notification of my post for accurate advice.

    Plugin Author phpmypython

    (@phpmypython)

    I’m working on incorporating this i assure you i haven’t forgot im just bogged down on other projects. i appreciate your suggestion and it will be implemented as soon as i can get to it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Please use wp_localize_script’ is closed to new replies.