sql - How to handle my row actions on a custom list table in the admin section

admin2025-01-07  6

I have set up a plugin that because of the amount of data being used I set up a custom table and have extended the WP_List_Table class. I know that is not recommended, but Custom Post Types just won't offer what I need. I plan on including a copy of the WP_List_Table class when releasing this project to prevent any unwanted bugs...

Anyhow, I have the following code and have went through a lot of tutorials on extending the WP_List_Table class, but have hit a wall.

function column_name( $item ) {
  $title = '<strong>' . $item['projectName'] . '</strong>';

  $actions = [
    'edit'    => sprintf( '<a href="?page=%s&action=%s&project=%s">Edit</a>',
      $_REQUEST['page'], 'edit', $item['projectID'] ),
    'delete'  => sprintf( '<a href="?page=%s&action=%s&project=%s">Delete</a>',
      $_REQUEST['page'], 'delete', $item['projectID'] )
  ];

  return $title . $this->row_actions( $actions );
}

When I click edit, all that happens is a url change. I am not sure how to actually generate a form/admin page to edit/update a project when the edit button is clicked. I am also getting a redirection error when "delete" is clicked, which I plan on getting to later. I assume for delete I just need to make sure I have the proper SQL statement to remove the project from the database.

Thank you in advance for your help.

I have set up a plugin that because of the amount of data being used I set up a custom table and have extended the WP_List_Table class. I know that is not recommended, but Custom Post Types just won't offer what I need. I plan on including a copy of the WP_List_Table class when releasing this project to prevent any unwanted bugs...

Anyhow, I have the following code and have went through a lot of tutorials on extending the WP_List_Table class, but have hit a wall.

function column_name( $item ) {
  $title = '<strong>' . $item['projectName'] . '</strong>';

  $actions = [
    'edit'    => sprintf( '<a href="?page=%s&action=%s&project=%s">Edit</a>',
      $_REQUEST['page'], 'edit', $item['projectID'] ),
    'delete'  => sprintf( '<a href="?page=%s&action=%s&project=%s">Delete</a>',
      $_REQUEST['page'], 'delete', $item['projectID'] )
  ];

  return $title . $this->row_actions( $actions );
}

When I click edit, all that happens is a url change. I am not sure how to actually generate a form/admin page to edit/update a project when the edit button is clicked. I am also getting a redirection error when "delete" is clicked, which I plan on getting to later. I assume for delete I just need to make sure I have the proper SQL statement to remove the project from the database.

Thank you in advance for your help.

Share Improve this question asked Aug 4, 2017 at 21:19 Dylan WagnerDylan Wagner 331 silver badge6 bronze badges 2
  • You'll need to register an admin page and implement the forms etc from scratch. Also some context as to why you needed custom tables would be helpful. It's very possible somebody has thought of something you haven't and you can sidestep all of this entirely – Tom J Nowell Commented Aug 4, 2017 at 21:59
  • Sorry for the late reply! It's a project management system. There are plenty out there, but it's for a project my grad team is stuck on. So we would make an admin page and then have that form on there, and could we use AJAX to pull the clicked on project's information into the form for editing? – Dylan Wagner Commented Aug 7, 2017 at 17:47
Add a comment  | 

1 Answer 1

Reset to default 0

Apparently the right way to do this is to get the suffix returned by your custom page that normally displays the table and use it to hook into the page load before any admin content is rendered.

add_action('admin_menu', function() {
    $page_hook_suffix = add_submenu_page( # or related function
        …
        function() {
            # content of table page
        }
    );
    if ($page_hook_suffix) {
        add_action("load-$page_hook_suffix", function() {
           # verify nonces, handle actions, redirect, etc.
        });
    }
});
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736255187a262.html

最新回复(0)