| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Add a duplicate post link. |
| 5 |
* |
| 6 |
* @since 2.27 |
| 7 |
*/ |
| 8 |
function mtphr_post_duplicator_action_row_link( $post ) { |
| 9 |
|
| 10 |
// Do not show on trash page |
| 11 |
$post_status = isset( $_GET['post_status'] ) ? sanitize_text_field( $_GET['post_status'] ) : false; |
| 12 |
if ( 'trash' == $post_status ) { |
| 13 |
return false; |
| 14 |
} |
| 15 |
|
| 16 |
$settings = get_mtphr_post_duplicator_settings(); |
| 17 |
if ( 'current_user' === $settings['post_duplication'] ) { |
| 18 |
if ( get_current_user_id() != $post->post_author ) { |
| 19 |
return false; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
// Get the post type object |
| 24 |
$post_type = get_post_type_object( $post->post_type ); |
| 25 |
|
| 26 |
// Set the button label |
| 27 |
$label = sprintf( __( 'Duplicate %s', 'post-duplicator' ), $post_type->labels->singular_name ); |
| 28 |
|
| 29 |
// Modify the label if duplicating to new post type |
| 30 |
if( $settings['type'] != 'same' ) { |
| 31 |
$new_post_type = get_post_type_object( $settings['type'] ); |
| 32 |
if( $post_type->name != $new_post_type->name ) { |
| 33 |
$label = sprintf( __( 'Duplicate %1$s to %2$s', 'post-duplicator' ), $post_type->labels->singular_name, $new_post_type->labels->singular_name ); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
// Create a nonce & add an action |
| 38 |
$nonce = wp_create_nonce( 'm4c_ajax_file_nonce' ); |
| 39 |
|
| 40 |
// Return the link |
| 41 |
return '<a class="m4c-duplicate-post" rel="'.esc_attr( $nonce ).'" href="#" data-postid="'.esc_attr( $post->ID ).'">'.wp_kses_post( $label ).'</a>'; |
| 42 |
} |
| 43 |
|
| 44 |
// Add the duplicate link to post actions |
| 45 |
function mtphr_post_duplicator_action_row( $actions, $post ){ |
| 46 |
if( function_exists('mtphr_post_duplicator_action_row_link') ) { |
| 47 |
if ( $link = mtphr_post_duplicator_action_row_link( $post ) ) { |
| 48 |
$actions['duplicate_post'] = $link; |
| 49 |
} |
| 50 |
} |
| 51 |
return $actions; |
| 52 |
} |
| 53 |
add_filter( 'post_row_actions', 'mtphr_post_duplicator_action_row', 10, 2 ); |
| 54 |
add_filter( 'page_row_actions', 'mtphr_post_duplicator_action_row', 10, 2 ); |
| 55 |
add_filter( 'cuar/core/admin/content-list-table/row-actions', 'mtphr_post_duplicator_action_row', 10, 2 ); |
| 56 |
|
| 57 |
|