0

How can I make a custom edit page for my plugins admin UI page, if the requested page has a query argument of $_GET['action'] == 'edit'?

My plugins entry url looks like

/admin.php?page=parser-top-level-handle

Than I have listed all my items per row in a table. On row hover appear "edit|delete"-links and other actions. If I'm then clicking on the edit-link, I get the following URl:

/edit.php?page=parser-top-level-handle&action=edit&record=55

At this point, I'd like to redirect the user to the edit form.

The code what I'm trying to use to be redirected to custom edit Page

 add_action( 'wp_loaded', array ( 'parserAdmin', 'init' ) );

     class parserAdmin {

            private $db;

            private $add_page;


            public static function init()
            {
                new self;
            }

            //the consructor for parser admin
            function __construct(){

                global $wpdb, $posts;
                $this->db = $wpdb;      
                add_action('admin_menu', array($this , 'parser_add_pages') );

                $this->get_targets();
                //Here I inspect if action exits or not             
                if($_GET['action']){            
                    switch ($_GET['action']){
                        case 'edit':
                               //than here should be a redirect to a custom page to edit the item passing the record query argument, do I need in this case hidden sup-page?!!!
                            break;
                        case 'delete':
                            var_dump('test');
                            $this->_delete_target($_GET['record'] , $_GET['post_id']);      
                            break;              
                    }           
                }
}
2
  • Is there an edit form already in place? You probably need to post your code.
    – s_ha_dum
    Dec 12, 2012 at 15:42
  • a bit a of help would be welcome I'm fighting with it for 2 days I have been taking a look on the workflow by posts first there is an url like wp-admin/edit.php than over there there is wp_redirect to wp-admin/post.php but at this point I'm lost
    – kakuki
    Dec 13, 2012 at 9:26

1 Answer 1

1

You may not have access to $_GET. I think you may need global $wpdb, $posts, $_GET;

Second, everything happens in the constructor, which is when the plugin loads, which is every time any page of the site loads. So, every time a page loads you are checking $_GET['action'] for either 'edit' or 'delete'. Those action values are pretty common. They are even used in WordPress Core. Look at the URL when you are editing a post. What you are doing here is going to cause no end of conflict.

You only want to process this on your plugin page, not globally for the site, so pull that code out of the constructor and put it into its own function. Then hook that function to a hook specific to your plugin page.

function parser_handler() {
  global $_GET;

  //Here I inspect if action exits or not             
  if($_GET['action']){            
    switch ($_GET['action']){
      case 'edit':
    //than here should be a redirect to a custom page to edit the item passing the record query argument, do I need in this case hidden sup-page?!!!
    break;
      case 'delete':
    var_dump('test');
    $this->_delete_target($_GET['record'] , $_GET['post_id']);      
    break;              
    }           
  }
}

In your constructor add...

add_action('load-parser-top-level-handle',array($this,'parser_handler'));

I am guessing at the load- hook. Consider that a placeholder. Here is how to find the right hook. Load your page. View source. Look for the Javascript near the top of the page. In that script should be a pagenow parameter. Take that value and put 'load-' in front of it. That hook runs immediately before your particular plugin page gets sent to the browser.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.