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);

1 Answer 1


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

  • 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, 2011 at 9:25

Your Answer

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

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