0

I have already created a custom post plugin.

I need to add predefined text/values, when creating new custom post within this plugin.

Is it possible to handle these predefined text/values in my plugin .php file, and make them active?

<?php
/*
Plugin Name: Grand Prix Autíčka
Plugin URI: http://www/
Description: Přidávání autíček
Version: 1.0
Author: Thomas Dobo
Author URI: http://www/
License: GPLv2
*/

add_action( 'init', 'create_movie_review' );


function create_movie_review() {
register_post_type( 'movie_reviews',
array(
'labels' => array(
'name' => 'Grand Prix Autíčka',
'singular_name' => 'Movie Review',
'add_new' => 'Přidat Nový',
'add_new_item' => 'Add New Movie Review',
'edit' => 'Upravit',
'edit_item' => 'Edit Movie Review',
'new_item' => 'New Movie Review',
'view' => 'View',
'view_item' => 'View Movie Review',
'search_items' => 'Search Movie Reviews',
'not_found' => 'No Movie Reviews found',
'not_found_in_trash' =>
'No Movie Reviews found in Trash',
'parent' => 'Parent Movie Review'
),
'public' => true,
'menu_position' => 15,
'supports' =>
array( 'title', 'editor', 'comments',
'thumbnail',  ),
'taxonomies' => array( '' ),
'menu_icon' =>
plugins_url( 'images/image.png', __FILE__ ),
'has_archive' => true
)
);
}

add_action( 'admin_init', 'my_admin' );

i add this code, but it shows in all new posts/pages i need default content only for plugins new post

add_filter( 'default_content', 'my_editor_content' );

function my_editor_content( $content ) {

    $content = "This is some custom content I'm adding to the post editor because I hate re-typing it.";

    return $content;
}

please advise ,thank you

1
  • It could be useful to add some php code, updating your question… Commented Apr 11, 2016 at 8:53

1 Answer 1

0

You need to add a condition:

function my_editor_content( $content ) {
$content = "";    
if ( 'movie_reviews' == get_post_type() ) {
        $content = "This is some custom content I'm adding to the post editor because I hate re-typing it."; }

        return $content;
2
  • plugin works, but not add default $content to editor
    – Thomas.D
    Commented Apr 11, 2016 at 19:08
  • post-new.php?post_type=movie_reviews
    – Thomas.D
    Commented Apr 11, 2016 at 19:09

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.