WC_Admin_Meta_Boxes::save_meta_boxes()publicWC 1.0

Check if we're saving, the trigger an action based on the post type.

Метод класса: WC_Admin_Meta_Boxes{}

Возвращает

null. Ничего (null).

Использование

$WC_Admin_Meta_Boxes = new WC_Admin_Meta_Boxes();
$WC_Admin_Meta_Boxes->save_meta_boxes( $post_id, $post );
$post_id(int) (обязательный)
Post ID.
$post(объект) (обязательный)
Post object.

Код WC_Admin_Meta_Boxes::save_meta_boxes() WC 9.4.2

public function save_meta_boxes( $post_id, $post ) {
	$post_id = absint( $post_id );

	// $post_id and $post are required
	if ( empty( $post_id ) || empty( $post ) || ! is_a( $post, 'WP_Post' ) || self::$saved_meta_boxes ) {
		return;
	}

	// Dont' save meta boxes for revisions or autosaves.
	if ( Constants::is_true( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
		return;
	}

	// Check the nonce.
	if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['woocommerce_meta_nonce'] ), 'woocommerce_save_data' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
		return;
	}

	// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
	if ( empty( $_POST['post_ID'] ) || absint( $_POST['post_ID'] ) !== $post_id ) {
		return;
	}

	// Check user has permission to edit.
	if ( ! current_user_can( 'edit_post', $post_id ) ) {
		return;
	}

	// We need this save event to run once to avoid potential endless loops. This would have been perfect:
	// remove_action( current_filter(), __METHOD__ );
	// But cannot be used due to https://github.com/woocommerce/woocommerce/issues/6485
	// When that is patched in core we can use the above.
	self::$saved_meta_boxes = true;

	// Check the post type.
	if ( in_array( $post->post_type, wc_get_order_types( 'order-meta-boxes' ), true ) ) {
		if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
			return;
		}

		/**
		 * Save meta for shop order.
		 *
		 * @param int $post_id Post ID.
		 * @param object $post Post object.
		 *
		 * @since 2.1.0
		 */
		do_action( 'woocommerce_process_shop_order_meta', $post_id, $post );
	} elseif ( in_array( $post->post_type, array( 'product', 'shop_coupon' ), true ) ) {
		/**
		 * Save meta for product.
		 *
		 * @param int $post_id Post ID.
		 * @param object $post Post object.
		 *
		 * @since 2.1.0
		 */
		do_action( 'woocommerce_process_' . $post->post_type . '_meta', $post_id, $post );
	}
}