WPCF7_ContactForm::save()publicCF7 1.0

Stores this contact form properties to the database.

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

Возвращает

int. The post ID on success. The value 0 on failure.

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

$WPCF7_ContactForm = new WPCF7_ContactForm();
$WPCF7_ContactForm->save();

Код WPCF7_ContactForm::save() CF7 5.9.3

public function save() {
	$title = wp_slash( $this->title );
	$props = wp_slash( $this->get_properties() );

	$post_content = implode( "\n", wpcf7_array_flatten( $props ) );

	if ( $this->initial() ) {
		$post_id = wp_insert_post( array(
			'post_type' => self::post_type,
			'post_status' => 'publish',
			'post_title' => $title,
			'post_content' => trim( $post_content ),
		) );
	} else {
		$post_id = wp_update_post( array(
			'ID' => (int) $this->id,
			'post_status' => 'publish',
			'post_title' => $title,
			'post_content' => trim( $post_content ),
		) );
	}

	if ( $post_id ) {
		foreach ( $props as $prop => $value ) {
			update_post_meta( $post_id, '_' . $prop,
				wpcf7_normalize_newline_deep( $value )
			);
		}

		if ( wpcf7_is_valid_locale( $this->locale ) ) {
			update_post_meta( $post_id, '_locale', $this->locale );
		}

		add_post_meta( $post_id, '_hash',
			wpcf7_generate_contact_form_hash( $post_id ),
			true // Unique
		);

		if ( $this->initial() ) {
			$this->id = $post_id;
			do_action( 'wpcf7_after_create', $this );
		} else {
			do_action( 'wpcf7_after_update', $this );
		}

		do_action( 'wpcf7_after_save', $this );
	}

	return $post_id;
}