Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Currently I'm developing(well at least trying to;) plugin which will handle custom gallery of images. I stumbled upon one problem though. I'll try to picture it.

I've created custom menu page on which I can edit gallery options as well as I can add/delete/edit elements of gallery. I did add link to every gallery item so after choosing 'edit' I could be able to modify element.

function column_rls_name($item) {
  $actions = array(
            'edit'      => sprintf('<a href="?page=%s&action=%s&rls_element=%s">Edit</a>',$_REQUEST['page'],'edit',$item['rls_name']),
        );
  return sprintf('%1$s %2$s', $item['rls_name'], $this->row_actions($actions) );
}

Problem begins when 'edit' on element is clicked. It should redirect to settings page.

Here I have a question. What is the best way to do this. Are there any helper functions/hooks/etc out there which would help in creating such page (and detect redirection).

Of course I could do it in function responsible for displaying main gallery options like:

if($_GET['action']=='edit')
    //then do sth
else
    //display main gallery options

but I don't think it's the best way.

I would like to know which functions I could use, from creating custom link, creating custom page and registering them.

What method should be used when action=edit is triggered. How to spot it was requested on the actual page. How to show then page related to the content.

wp-admin/options-general.php?page=rls_logotypes&action=edit&rls_element=element1
share|improve this question
    
Problem begins when 'edit' on element is clicked. It should redirect to settings page. Where is the problem? Where redirect it now? What is the best way to do what? Create a redirection? Or create a propper link to an admin page? Please clearify your question. What does $this->row_actions($actions) do? –  Ralf912 Dec 8 '12 at 13:49
    
It does redirect (changes link from options-general.php?page=rls_logotypes to options-general.php?page=rls_logotypes&action=edit&book=element1) but my question here is which helper functions(if they exist) should I use to detect this redirection and show another page. My question is should i detect it manually or could I use some functions/hooks. row_actions is just a function from WP_List_Tables which inserts a div in to the table row with links. –  dfens Dec 8 '12 at 13:56
    
You do not want to show another page and you do not want to do a redirection. You are on page rls_logotype which is a subpage of options-general.php What you want to do is to detect an action. A redirect is if you go from site A to site B (e.g. from dashboard.php to options.php). You can only use $_REQUEST (or $_GET / $_POST) to detect an action in your url-parameters. –  Ralf912 Dec 8 '12 at 14:22
    
Multi-post: stackoverflow.com/q/13774231/1287812 –  brasofilo Dec 8 '12 at 15:40
add comment

1 Answer

Get the url of a specific admin page (e.g. the settings page (options-general.php)):

admin_url( 'options-general.php' )

Codex admin_url()

Adding query arguments to an url:

$params = array(
    'page'          => $_REQUEST['page'],
    'action'        => 'edit',
    'rls_element'   => $item['rls_name']
);

$url = add_query_arg( $params, $org_url );

Codex add_query_arg()

Put a and b together:

$params = array(
    'page'          => $_REQUEST['page'],
    'action'        => 'edit',
    'rls_element'   => $item['rls_name']
);

$url = add_query_arg( $params, admin_url( 'options-general.php' ) );

Now we can create links:

public function column_rls_name( $item ){

    $actions = array(
    'edit'  => $this->create_admin_link(
                        array(
                            'text'      => 'Edit',
                            'action'    => 'edit',
                            'item'      => $item['rls_name']
                        )
                )
    );

    return sprintf( '%1$s %2$s', $item['rls_name'], $this->row_actions( $actions ) );

}

public function create_admin_link( $args = array() ){

    $params = array(
        'page'          => $_REQUEST['page'],
        'action'        => $args['action'],
        'rls_element'   => $args['item']
    );

    $url = add_query_arg( $params, admin_url( 'options-general.php' ) );

    return sprintf( '<a href="%s">%s</a>', $url, $args['text'] );

}
share|improve this answer
    
Thanks! So one element of puzzle is solved.Thx for explaining thing with redirection. So as far as I understand 'edit' should be detected in a function responsible for displaying main rls_logotypes page. –  dfens Dec 8 '12 at 14:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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