Estoy tratando de crear un botón en el back-end para llamar a una función php en functions.php. Agregué el botón así:
add_action( 'edit_form_after_title', 'update_my_data');
function update_my_data( $post ) {
if( 'item' == $post->post_type )
echo '<a href="#" class="button-primary">Update PDF</a>';
}
y la función que necesito ejecutar al hacer clic es esta:
function mysave($id, $post)
{
if ($post->post_type != 'item'){
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return;
}
if ( (defined( 'REST_REQUEST' ) && REST_REQUEST ) ){
return;
}
if (wp_is_post_revision($id)) {
return;
}
if (wp_is_post_autosave($id)) {
return;
}
if ( 'trash' === $post->post_status ) {
return;
}
if ( 'draft' === $post->post_status ) {
return;
}
$dig = get_post_meta($id, 'wpcf-digitisation-project-no')[0];
#$hmml = get_post_meta($id, 'wpcf-hmml-project-no')[0];
$inv = get_post_meta($id, 'wpcf-inventory-no')[0];
if($dig!=""){
$command = escapeshellcmd('python3 '. dirname(__file__). '/create_pdf.py digital '.$inv);
}else{
$command = escapeshellcmd('python3 '. dirname(__file__). '/create_pdf.py hl'.$inv);
}
exec( $command, $output, $ret_code);
}
En este momento, esta función está asociada con el gancho save_post pero quiero que la función de update_post_meta y esta función estén separadas, es decir: el botón de actualización original actualizará los metadatos como se pretendía originalmente, y creará un nuevo botón Actualizar PDF que llamará a mysave función
.