WP_Customize_Nav_Menus::insert_auto_draft_post()
Adds a new auto-draft post.
Метод класса: WP_Customize_Nav_Menus{}
Хуков нет.
Возвращает
WP_Post|WP_Error
. Inserted auto-draft post object or error.
Использование
$WP_Customize_Nav_Menus = new WP_Customize_Nav_Menus(); $WP_Customize_Nav_Menus->insert_auto_draft_post( $postarr );
- $postarr(массив) (обязательный)
Post array. Note that post_status is overridden to be auto-draft.
-
post_title(строка)
Post title. Required. -
post_type(строка)
Post type. Required. -
post_name(строка)
Post name. - post_content(строка)
Post content.
-
Список изменений
С версии 4.7.0 | Введена. |
Код WP_Customize_Nav_Menus::insert_auto_draft_post() WP Customize Nav Menus::insert auto draft post WP 6.6.2
public function insert_auto_draft_post( $postarr ) { if ( ! isset( $postarr['post_type'] ) ) { return new WP_Error( 'unknown_post_type', __( 'Invalid post type.' ) ); } if ( empty( $postarr['post_title'] ) ) { return new WP_Error( 'empty_title', __( 'Empty title.' ) ); } if ( ! empty( $postarr['post_status'] ) ) { return new WP_Error( 'status_forbidden', __( 'Status is forbidden.' ) ); } /* * If the changeset is a draft, this will change to draft the next time the changeset * is updated; otherwise, auto-draft will persist in autosave revisions, until save. */ $postarr['post_status'] = 'auto-draft'; // Auto-drafts are allowed to have empty post_names, so it has to be explicitly set. if ( empty( $postarr['post_name'] ) ) { $postarr['post_name'] = sanitize_title( $postarr['post_title'] ); } if ( ! isset( $postarr['meta_input'] ) ) { $postarr['meta_input'] = array(); } $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name']; $postarr['meta_input']['_customize_changeset_uuid'] = $this->manager->changeset_uuid(); unset( $postarr['post_name'] ); add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 ); $r = wp_insert_post( wp_slash( $postarr ), true ); remove_filter( 'wp_insert_post_empty_content', '__return_false', 1000 ); if ( is_wp_error( $r ) ) { return $r; } else { return get_post( $r ); } }