Add custom action to the page listing screen


I’m creating functionality that will clone a published page and create a new draft page from the content. I placed an action link alongside the “Edit | Quick Edit | Trash | View” items that appear beneath each page title on the page listing page within the admin dash. My link has the post_id and the custom action name. The link points back to the edit.php page and a function is run if the action matches clone-post_{post_id}. I get the following error screen each time I click the link. However, the clone functionality does work. When I go back to the page listings page the draft page exists with the appropriate content.

add_filter('post_row_actions', 'update_page_listing_menu', 10, 2);
add_filter('page_row_actions', 'update_page_listing_menu', 10, 2);
function update_page_listing_menu($actions, WP_Post $post)
    $site_url = site_url();
    $base_url = $site_url .'/wp-admin/edit.php?post_type=page&post=' . $post->ID . '&action=clone-post_'. $post->ID;

    $actions['clone-post'] = '<a href="'. $complete_url . '">Copy to Draft</a>';
    return $actions;

// If copy to draft is true in the query vars then copy the post
function check_for_clone_action() {
    if ( strpos($_REQUEST['action'],'clone-post_' ) !== false )

function create_draft_post_from_published_post($id)

        $current_post = get_post( $id );

        $new_post_id = wp_insert_post( array(
            'post_title'   => $current_post->post_title,
            'post_content' => $current_post->post_content,
            'meta_input'   => array(
                'published_post_id' => $id
            'post_type'    => 'page'

        ), true );


FYI: I will add nonce verification once I get this working.

Below is the page that I see when clicking the link:
Page after clicking

, , TKEz 4 years 2019-11-06T10:24:16-05:00 0 Answers 68 views 0

Leave an answer