Ok, I have figured out how to resolve this issue. I have made some updates to my plugin but to get it fully functioning @vprat will need to update his files as well.
The actual tasks are their own post type attached to the task list as a child post. So, to get the tasks duplicated each task post also needs to be duplicated and then modified to attach the duplicated task list is it’s parent post.
I realized as I was working on this that I cannot support customizing my file for special situations like this (it could get out of hand). But, I have now added a custom action into my plugin (after the duplication process). I have also separated out the post duplication function from the ajax call used when clicking a Duplicate button. This allows posts to be duplicated by other means based on the situation (like the code below).
I will update my plugin soon, to version 2.20. I have worked the necessary code to be used in the Task extension to successfully duplicate tasks with the task list. @vprat will need to add the following into the extension (feel free to modify if you wish):
function my_post_duplicator_created( $original_id, $duplicate_id ) {
if( get_post_type($original_id) != 'cuar_tasklist' || get_post_type($duplicate_id) != 'cuar_tasklist' ) return;
// Get & loop through the original tasks
$tasks = get_posts(array(
'post_type' => 'cuar_task',
'post_parent' => $original_id
));
if( is_array($tasks) && count($tasks) > 0 ) {
foreach( $tasks as $i=>$task ) {
// Duplicate the task
$duplicate_task_id = mtphr_duplicate_post( $task->ID );
// Update the post parent of the task
wp_update_post(
array(
'ID' => $duplicate_task_id,
'post_parent' => $duplicate_id
)
);
}
}
}
add_action( 'mtphr_post_duplicator_created', 'my_post_duplicator_created', 10, 2 );
I have not looked into the Invoices duplication, but I’m assuming it’s a similar situation that can be worked out in a similar fashion (using the mtphr_post_duplicator_created hook).
@vprat I will leave the custom post/page row actions (for the duplicate button) that I had previously built into the plugin. But, I have also modified the button output into a separate function to be easily used in other custom situations like this. Here is how I would add it to your plugin (if I didn’t already have it included in my plugin):
function mtphr_post_duplicator_action_row( $actions, $post ){
if( function_exists('mtphr_post_duplicator_action_row_link') ) {
$actions['duplicate_post'] = mtphr_post_duplicator_action_row_link( $post );
}
return $actions;
}
add_filter( 'cuar/core/admin/content-list-table/row-actions', 'my_post_duplicator_action_row', 10, 2 );