GC_Customize_Nav_Menus::save_nav_menus_created_posts()

最后更新于:2021-11-27 04:41:11

GC_Customize_Nav_Menus::save_nav_menus_created_posts( GC_Customize_Setting$setting)

Publish the auto-draft posts that were created for nav menu items.

参数

$setting

(GC_Customize_Setting) (Required) Customizer setting object.

源文件

文件: gc-includes/class-gc-customize-nav-menus.php

	public function save_nav_menus_created_posts( $setting ) {
		$post_ids = $setting->post_value();
		if ( ! empty( $post_ids ) ) {
			foreach ( $post_ids as $post_id ) {

				// Prevent overriding the status that a user may have prematurely updated the post to.
				$current_status = get_post_status( $post_id );
				if ( 'auto-draft' !== $current_status && 'draft' !== $current_status ) {
					continue;
				}

				$target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish';
				$args          = array(
					'ID'          => $post_id,
					'post_status' => $target_status,
				);
				$post_name     = get_post_meta( $post_id, '_customize_draft_post_name', true );
				if ( $post_name ) {
					$args['post_name'] = $post_name;
				}

				// Note that gc_publish_post() cannot be used because unique slugs need to be assigned.
				gc_update_post( gc_slash( $args ) );

				delete_post_meta( $post_id, '_customize_draft_post_name' );
			}
		}
	}