I'am workin in a sorter plugin for WordPress, which have Redux Framework installed to manage the options of every section. The plugin uses AJAX to get the ids of all the sections in the homepage of the website, then passes thos values to the plugin main file to process in a function that stores the values in the current user meta. That works well, no problem here. The function looks like this:
add_action( 'wp_ajax_save_sections_ids', 'save_sections_ids_sorting_sections' );
function save_sections_ids_sorting_sections() {
//stuff here...
$user_ide = get_current_user_id(); //it works because it is inside a hook
update_user_meta($user_ide, "set-sections", $sections_ids);
die();
}
Then I have to get the stored values in user_meta to pass them to the Redux Field, so I wrote other function in the main file of the plugin. The function is this:
function get_the_db_sections_ids() {
$user_ide = 1; //This should be get_current_user_id() or something similar, but nothing works, not even globalizing $current_user and using get_currentuserinfo();
$sections_ids = get_user_meta($user_ide, "set-sections", true);
$sorter_field = array(
"section_id" => "basic",
'id' => 'homepage-sections',
'type' => 'sorter',
'title' => 'Control de secciones',
'desc' => 'Arrastra y suelta los bloques con los nombres de las secciones, tanto para ordenarlas verticalmente como para desactivarlas o activarlas.',
'compiler' => 'true',
'options' => array(
'enabled' => array(
),
'disabled' => $sections_ids
),
);
return $sorter_field;
}
As you notice in the comment in the function above, I have tried several ways, also require_once("/../../../wp-load.php"), but nothing happens. I tried do_action and add_actions, to create a hook, but thos also use global variables, and for what I understand, the global variables do not work in functions with no hooks in plugins.
But I havent finished yet. The really tricky part is, I am calling an instance of Redux class inside the Redux config file (sample-config.php for the demo, I have a custom file, but it is the same).
The instance is Redux::setField($opt_name, get_the_db_sections_ids());
The problem this does not print anything if I call it form a function, or the function linked to the AJAX call.
As you can see, the second parameter of the instance is the function I wrote above that, and it works perfectly if I set $user_ide to 1, but I want the data stores in all admins user_meta, in case user 1 is erased, or whatever.
Is there a way to achive what I want, or to store the data somewhere else and get it from there. I was thinking in creating a custom table in db, and use wpdb to retrieve the data, but I think I can't use wpdb either, because it will be the same problem.
I get the feeling I'm missing something very basic, but I can't get it. Please help.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire