这里有一个简单的插件,可以修改按下此帖子类型:
<?php
/**
* Plugin Name: Press-This Custom Post Type
* Plugin URI: http://wordpress.stackexchange.com/a/192065/26350
*/
add_filter( \'wp_insert_post_data\', function( $data )
{
$old_cpt = \'post\';
$new_cpt = \'page\'; // <-- Edit this cpt to your needs!
$obj = get_post_type_object( $new_cpt );
// Change the post type
if(
doing_action( \'wp_ajax_press-this-save-post\' ) // Check the context
&& isset( $data[\'post_type\'] )
&& $old_cpt === $data[\'post_type\'] // Check the old post type
&& isset( $obj->cap->create_posts )
&& current_user_can( $obj->cap->create_posts ) // Check for capability
)
$data[\'post_type\'] = $new_cpt;
return $data;
}, PHP_INT_MAX );
您必须根据需要修改帖子类型。
在这里,我们通过检查以下内容来确保我们处于ajax上下文中:
doing_action( \'wp_ajax_press-this-save-post\' )
我们还确保当前用户有能力创建新的自定义帖子。
下面是一个示例,我们可以使用它修改帖子类型并将其分配给自定义分类术语:
/**
* Plugin Name: Press-This Custom Post Type And Taxonomy Term
* Plugin URI: http://wordpress.stackexchange.com/a/192065/26350
*/
add_filter( \'press_this_save_post\', function( $data )
{
//---------------------------------------------------------------
// Edit to your needs:
//
$new_cpt = \'movie\'; // new post type
$taxonomy = \'actor\'; // existing taxonomy
$term = \'john-wayne\'; // existing term
//---------------------------------------------------------------
$post_object = get_post_type_object( $new_cpt );
$tax_object = get_taxonomy( $taxonomy );
// Change the post type if current user can
if(
isset( $post_object->cap->create_posts )
&& current_user_can( $post_object->cap->create_posts )
)
$data[\'post_type\'] = $new_cpt;
// Change taxonomy + term if current user can
if (
isset( $tax_object->cap->assign_terms )
&& current_user_can( $tax_object->cap->assign_terms )
)
$data[\'tax_input\'][$taxonomy] = $term;
return $data;
}, 999 );