get_id() ); $types = isset( $settings['post_types'] ) && is_array( $settings['post_types'] ) ? $settings['post_types'] : array( 'post', 'page' ); if ( ! in_array( $post->post_type, $types, true ) || ! current_user_can( 'edit_post', $post->ID ) || in_array( $post->post_status, array( 'trash', 'auto-draft' ), true ) ) { return $actions; } $url = wp_nonce_url( admin_url( 'admin.php?action=edminboost_duplicate_post&post=' . absint( $post->ID ) ), 'edminboost_duplicate_post_' . $post->ID ); $actions['edminboost_duplicate'] = sprintf( '%s', esc_url( $url ), esc_attr( sprintf( /* translators: %s: post title */ __( 'Duplicate "%s"', 'edminboost-admin-customization' ), wp_strip_all_tags( get_the_title( $post ) ) ) ), esc_html__( 'Duplicate', 'edminboost-admin-customization' ) ); return $actions; } /** * Handle duplicate action. * * @return void */ public function handle_duplicate() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Verified via check_admin_referer below. $post_id = isset( $_GET['post'] ) ? absint( wp_unslash( $_GET['post'] ) ) : 0; if ( ! $post_id || ! current_user_can( 'edit_post', $post_id ) ) { wp_die( esc_html__( 'You cannot duplicate this item.', 'edminboost-admin-customization' ) ); } check_admin_referer( 'edminboost_duplicate_post_' . $post_id ); $post = get_post( $post_id ); if ( ! $post ) { wp_die( esc_html__( 'Post not found.', 'edminboost-admin-customization' ) ); } $settings = EDMINBOOST_Settings::get_feature_settings( $this->get_id() ); $types = isset( $settings['post_types'] ) && is_array( $settings['post_types'] ) ? $settings['post_types'] : array( 'post', 'page' ); if ( ! in_array( $post->post_type, $types, true ) ) { wp_die( esc_html__( 'You cannot duplicate this item.', 'edminboost-admin-customization' ) ); } $new_id = wp_insert_post( array( 'post_title' => $post->post_title . ' ' . __( '(Copy)', 'edminboost-admin-customization' ), 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_status' => 'draft', 'post_type' => $post->post_type, 'post_author' => get_current_user_id(), ), true ); if ( is_wp_error( $new_id ) ) { wp_die( esc_html( $new_id->get_error_message() ) ); } wp_safe_redirect( admin_url( 'post.php?action=edit&post=' . $new_id ) ); exit; } }