WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a simple plugin to set a page as a homepage from the list pages (to appear next to edit, preview, trash actions etc), I was just wondering what that the most appropriate/secure place to submit this information to? By far the easiest way would be to just post back to the plugin file itself with a $_GET param, but that seems rather hacky and doesn't use a nonce or anything (my plugin does have current_user_can() in it.

Code is as simple as this:

function add_post_actions($actions, $post) {
    if($post->ID == get_option('page_on_front')) {
        $actions['homepage'] = '<span style="color: #999;">Your Homepage</span>';
    } else {
        $actions['homepage'] = '<a href="blah.php?post='.$post->ID.'">Set As Homepage</a>';

    return $actions;

function change_to_homepage($postId) {
    if ( ! current_user_can( 'manage_options' ) )
        wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );

    update_option('show_on_front', 'page');
    update_option('page_on_front', $postId);
share|improve this question
up vote 2 down vote accepted

To me it makes sense to send via GET to the page you are currently on.

That way you just hook into admin_init and check for your GET variables.

As for security you can pass nonces via URLS: http://codex.wordpress.org/Function_Reference/wp_nonce_url

share|improve this answer
Ok sounds easy, is there a WP function for getting/redirecting to the previous page? Also, would you check the $_GET then add the filter, or add the hook and check the $_GET in the function? Both require checking $_GET but only one adds a filter... – Dunhamzzz Sep 8 '11 at 9:25

Your Answer


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.