Visual Localize Script

Last Updated on January 8, 2019 by Neil Murray

A. Filter

Since Visual version 0.7.0 ed587e1, a filter cf7svisual_localize_script has been added to give addons ability to add their data into cf7svisual or modify it. Here are predefined properties added by Visual:

// Localize script filter since 0.7.0
$localize = apply_filters( 'cf7svisual_localize_script', array( 
    'ajaxurl'	=> admin_url('admin-ajax.php'),
    'versions'	=> $versions, // @since 0.7.0
    'nonce'		=> wp_create_nonce( $this->nonce ), // generate a nonce for security checking
    'update'	=> 'cf7skins_visual_update', // post action for saving
    'l10n'		=> array(
        'save'		=> __( 'Save', $this->textdomain ),
        'done'		=> __( 'Done', $this->textdomain ),
        'error'		=> __( 'Error', $this->textdomain ),
    ),
    'options'		=> $options, // @since 0.6.3
    'title'			=> $cf7 ? $cf7->title() : '',
    'items'			=> $items,
    'integration'	=> $integration,			
    'environment'	=> defined('CF7SKINSVISUAL_ENV') ? CF7SKINSVISUAL_ENV : null, // @since 0.7.0
) );

 

B. Versions

Issue #251/add-pro-tips is a good example to display a message about Multi addon if they not have it. Multi will need register the version by hooking to the filter.

add_filter( 'cf7svisual_localize_script', 'register_multi_version' );

function register_multi_version( $script ) {
    $script['versions']['multi'] = CF7SKINSMULTI_VERSION;	
    return $script;
}

The version is added to window object cf7svisual in versions property. Here is the result using console logging:

In example above we add ‘multi’ key with version value.

@Neil, please suggest the version key for each addon, it can be using the plugin/addon slug, but will fail if user change the folder name.


pro: 2.0.2, ready: 2.0.1, multi: 1.0.8, logic: 1.1.0 – that should give us all we need.

Neil