I'll be brief and hope I can explain my scenario correctly. Here's my scenario. The jQuery slider plugin has an anonymous callback method. I would like to give the Admin the ability to create a function for that callback method. So from the plugin's add/edit pages the admin has a textarea to input the jQuery code. Now the textarea input gets save to the database and when it's passed using the wp_localize_script() it gets pass as a string that does not get recognize as a Javascript/jQuery code. So far, I have only being able to make it work using eval() in order for it to be recognize and to run as a Javascript/jQuery function.
On the Admin page:
<textarea id="callback" name="callback" rows="10" ><?php echo $callback; ?></textarea>
On the wp_localize_script() array:
wp_localize_script( 'init_file', 'slider_option', $config_array );
$config_array = array(
...
'onSliderEnd' => $callback,
...
);
On the initialize jQuery file:
$('body').slider({
...
'onSliderEnd': function(){ eval( slider_option.onSliderEnd; ); },
...
});
Is this a safe way to use eval()? Any other suggestions? Or should I just not allow such an option?
Thanks in advance for all your replies.