Open WordPress ‘Add New Post’ admin page with parameters set via $_GET

The problem is that $content is a reserved variable in WordPress, you have to use another name. Here, I have used $pre_content:

enter image description here

<?php
/**
 * Plugin Name: T5 Editor content by request
 * Description: Default text for post content from GET variable <code>pre_content</code>.
 * Author:      Fuxia Scholz
 * Version:     2012.06.30
 */

/*
 * See wp-admin/includes/post.php function get_default_post_to_edit()
 * There are also the filters 'default_title' and 'default_excerpt'
 */
add_filter( 'default_content', 't5_content_by_request', 10, 2 );

/**
 * Fills the default content for post type 'post' if it is not empty.
 *
 * @param string $content
 * @param object $post
 * @return string
 */
function t5_content_by_request( $content, $post )
{
    if ( ! empty ( $_GET['pre_content'] )
        and current_user_can( 'edit_post', $post->ID )
        and '' === $content
    )
    {
        return $_GET['pre_content'];
    }

    return $content;
}

Leave a Comment