I am trying to create a button on the back end to call a php function in functions.php. I added the button as so:
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>';
}
and the function I need to execute on click is this:
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);
}
Right now this function is associated with the hook save_post but I want the function of update_post_meta and this function to be seperate ie: the original update button will update the meta data as originally intended, and create a new button Update PDF which will call the mysave function