^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_default_post_to_edit()用法示例

get_default_post_to_edit( string $post_type = 'post',  bool $create_in_db = false )

Default post information to use when populating the “Write Post” form.


描述


参数

$post_type

(string)
(Optional)
A post type string.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

Default value: ‘post’

$create_in_db

(bool)
(Optional)
Whether to insert the post into database.

Default value: false


返回值

(WP_Post) Post object containing all the default post data as attributes


源代码

File: wp-admin/includes/post.php

function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
	$post_title = '';
	if ( !empty( $_REQUEST['post_title'] ) )
		$post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ));

	$post_content = '';
	if ( !empty( $_REQUEST['content'] ) )
		$post_content = esc_html( wp_unslash( $_REQUEST['content'] ));

	$post_excerpt = '';
	if ( !empty( $_REQUEST['excerpt'] ) )
		$post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ));

	if ( $create_in_db ) {
		$post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
		$post = get_post( $post_id );
		if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )
			set_post_format( $post, get_option( 'default_post_format' ) );
	} else {
		$post = new stdClass;
		$post->ID = 0;
		$post->post_author = '';
		$post->post_date = '';
		$post->post_date_gmt = '';
		$post->post_password = '';
		$post->post_name = '';
		$post->post_type = $post_type;
		$post->post_status = 'draft';
		$post->to_ping = '';
		$post->pinged = '';
		$post->comment_status = get_default_comment_status( $post_type );
		$post->ping_status = get_default_comment_status( $post_type, 'pingback' );
		$post->post_pingback = get_option( 'default_pingback_flag' );
		$post->post_category = get_option( 'default_category' );
		$post->page_template = 'default';
		$post->post_parent = 0;
		$post->menu_order = 0;
		$post = new WP_Post( $post );
	}

	/**
	 * Filters the default post content initially used in the "Write Post" form.
	 *
	 * @since 1.5.0
	 *
	 * @param string  $post_content Default post content.
	 * @param WP_Post $post         Post object.
	 */
	$post->post_content = apply_filters( 'default_content', $post_content, $post );

	/**
	 * Filters the default post title initially used in the "Write Post" form.
	 *
	 * @since 1.5.0
	 *
	 * @param string  $post_title Default post title.
	 * @param WP_Post $post       Post object.
	 */
	$post->post_title = apply_filters( 'default_title', $post_title, $post );

	/**
	 * Filters the default post excerpt initially used in the "Write Post" form.
	 *
	 * @since 1.5.0
	 *
	 * @param string  $post_excerpt Default post excerpt.
	 * @param WP_Post $post         Post object.
	 */
	$post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );

	return $post;
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

Uses

  • wp-includes/comment.php:
    get_default_comment_status()
  • wp-admin/includes/post.php:
    default_content
  • wp-admin/includes/post.php:
    default_title
  • wp-admin/includes/post.php:
    default_excerpt
  • wp-includes/theme.php:
    current_theme_supports()
  • wp-includes/l10n.php:
    __()
  • wp-includes/formatting.php:
    wp_unslash()
  • wp-includes/formatting.php:
    esc_html()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/option.php:
    get_option()
  • wp-includes/class-wp-post.php:
    WP_Post::__construct()
  • wp-includes/post.php:
    wp_insert_post()
  • wp-includes/post.php:
    post_type_supports()
  • wp-includes/post.php:
    get_post()
  • wp-includes/post-formats.php:
    set_post_format()
  • Show 10 more uses


Used By

  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::html()
  • wp-admin/includes/deprecated.php:
    get_default_page_to_edit()
  • wp-admin/includes/dashboard.php:
    wp_dashboard_quick_press()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::inline_edit()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::mw_newPost()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::_insert_post()
  • Show 1 more used by
    Hide more used by


让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈