I have following code in my plugin of WordPress:
wp_localize_script('ffd_js_script', 'myAjax', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'idinfo' => $myoptionValue[idinfo],
'index1' => $myoptionValue[id1],
'index2' => $myoptionValue[id2]
)
);
I want to replace
'index1' => $myoptionValue[id1],
'index2' => $myoptionValue[id2]
with
for($i=1; $i<= $myoptionValue[fieldcount]; $i++)
{
$arguments .= ',"index"'.$i.'=>'.$myoptionValue[id.$i];
}
So that I have
wp_localize_script('ffd_js_script', 'myAjax', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'idinfo' => $myoptionValue[idinfo]
$arguments
)
);
Apparently I’m thinking it might be as simple as this, but it isn’t, where is my mistake?
EDIT:
full code:
require( plugin_dir_path( __FILE__ ) . 'menu.php');
require_once( plugin_dir_path( __FILE__ ) . 'getuser.php');
add_action( 'wp_enqueue_scripts', 'ffd_load_scripts' );
function ffd_load_scripts()
{
$myoption = get_option( 'fixformdata_options' );
$myoptionValue = maybe_unserialize( $myoption );
$arguments = array();
for($i=1; $i<= $myoptionValue[fieldcount]; $i++)
{
$arguments['index'.$i] = $myoptionValue['id'.$i];
}
wp_register_script('ffd_js_script', WP_PLUGIN_URL.'/FixFormData/js/ffd_js_script.js', array('jquery'));
wp_localize_script('ffd_js_script', 'myAjax', merge_array(array(
'ajaxurl' => admin_url('admin-ajax.php'),
'idinfo' => $myoptionValue['idinfo']),$arguments)
);
wp_enqueue_script('jquery');
wp_enqueue_script('ffd_js_script', plugin_dir_url(__FILE__) . 'js/ffd_js_script.js');
}