can I do something like that? to pass arguments to my function? I already studied add_action doc but did not figure out how to do it. What the exact syntax to pass two argum
I have made a code to send parameters and process.
function recibe_data_post() {
$post_data = $_POST;
if (isset($post_data)) {
if (isset($post_data['lista_negra'])) {
$args = array (
'btn' => 'lista_negra',
'estado'=> $post_data['lista_negra'],
);
add_action('template_redirect',
function() use ( $args ) {
recibe_parametros_btn( $args ); });
}
if (isset($post_data['seleccionado'])) {
$args = array (
'btn' => 'seleccionado',
'estado'=> $post_data['seleccionado'],
);
add_action('template_redirect',
function() use ( $args ) {
recibe_parametros_btn( $args ); });
}
}
}
add_action( 'init', 'recibe_data_post' );
function recibe_parametros_btn( $args ) {
$data_enc = json_encode($args);
$data_dec = json_decode($data_enc);
$btn = $data_dec->btn;
$estado = $data_dec->estado;
fdav_procesa_botones($btn, $estado);
}
function fdav_procesa_botones($btn, int $estado) {
$post_id = get_the_ID();
$data = get_post($post_id);
if ( $estado == 1 ) {
update_field($btn, 0, $post_id);
} elseif ( $estado == 0 ) {
update_field($btn, 1, $post_id);
}
}