WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта
функция не описана

Yoast\WP\SEO\Integrations\Third_Party

Elementor::save_postdata() public Yoast 1.0

Saves the WP SEO metadata for posts.

Outputs JSON via wp_send_json then stops code execution.

{@internal $_POST parameters are validated via sanitize_post_meta().}}

{} Это метод класса: Elementor{}

Возвращает

null. Ничего.

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

$Elementor = new Elementor();
$Elementor->save_postdata();

Код Elementor::save_postdata() Yoast 16.8

<?php
public function save_postdata() {
	global $post;

	$post_id = \filter_input( \INPUT_POST, 'post_id', \FILTER_SANITIZE_NUMBER_INT );

	if ( ! \current_user_can( 'manage_options' ) ) {
		\wp_send_json_error( 'Unauthorized', 401 );
	}

	\check_ajax_referer( 'wpseo_elementor_save', '_wpseo_elementor_nonce' );

	// Bail if this is a multisite installation and the site has been switched.
	if ( \is_multisite() && \ms_is_switched() ) {
		\wp_send_json_error( 'Switched multisite', 409 );
	}

	\clean_post_cache( $post_id );
	// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- To setup the post we need to do this explicitly.
	$post = \get_post( $post_id );

	if ( ! \is_object( $post ) ) {
		// Non-existent post.
		\wp_send_json_error( 'Post not found', 400 );
	}

	\do_action( 'wpseo_save_compare_data', $post );

	// Initialize meta, amongst other things it registers sanitization.
	WPSEO_Meta::init();

	$social_fields = [];
	if ( $this->social_is_enabled ) {
		$social_fields = WPSEO_Meta::get_meta_field_defs( 'social', $post->post_type );
	}

	// The below methods use the global post so make sure it is setup.
	\setup_postdata( $post );
	$meta_boxes = \apply_filters( 'wpseo_save_metaboxes', [] );
	$meta_boxes = \array_merge(
		$meta_boxes,
		WPSEO_Meta::get_meta_field_defs( 'general', $post->post_type ),
		WPSEO_Meta::get_meta_field_defs( 'advanced', $post->post_type ),
		$social_fields,
		WPSEO_Meta::get_meta_field_defs( 'schema', $post->post_type )
	);

	foreach ( $meta_boxes as $key => $meta_box ) {
		// If analysis is disabled remove that analysis score value from the DB.
		if ( $this->is_meta_value_disabled( $key ) ) {
			WPSEO_Meta::delete( $key, $post_id );
			continue;
		}

		$data       = null;
		$field_name = WPSEO_Meta::$form_prefix . $key;

		if ( $meta_box['type'] === 'checkbox' ) {
			$data = isset( $_POST[ $field_name ] ) ? 'on' : 'off';
		}
		else {
			if ( isset( $_POST[ $field_name ] ) ) {
				// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: Sanitized through sanitize_post_meta.
				$data = \wp_unslash( $_POST[ $field_name ] );

				// For multi-select.
				if ( \is_array( $data ) ) {
					$data = \array_map( [ 'WPSEO_Utils', 'sanitize_text_field' ], $data );
				}

				if ( \is_string( $data ) ) {
					$data = ( $key !== 'canonical' ) ? WPSEO_Utils::sanitize_text_field( $data ) : WPSEO_Utils::sanitize_url( $data );
				}
			}

			// Reset options when no entry is present with multiselect - only applies to `meta-robots-adv` currently.
			if ( ! isset( $_POST[ $field_name ] ) && ( $meta_box['type'] === 'multiselect' ) ) {
				$data = [];
			}
		}

		if ( $data !== null ) {
			WPSEO_Meta::set_value( $key, $data, $post_id );
		}
	}

	// Saving the WP post to save the slug.
	$slug = \filter_input( \INPUT_POST, WPSEO_Meta::$form_prefix . 'slug', \FILTER_SANITIZE_STRING );
	if ( $post->post_name !== $slug ) {
		$post_array              = $post->to_array();
		$post_array['post_name'] = $slug;

		$save_successful = \wp_insert_post( $post_array );
		if ( \is_wp_error( $save_successful ) ) {
			\wp_send_json_error( 'Slug not saved', 400 );
		}

		// Update the post object to ensure we have the actual slug.
		// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Updating the post is needed to get the current slug.
		$post = \get_post( $post_id );
		if ( ! \is_object( $post ) ) {
			\wp_send_json_error( 'Updated slug not found', 400 );
		}
	}

	\do_action( 'wpseo_saved_postdata' );

	// Output the slug, because it is processed by WP and we need the actual slug again.
	\wp_send_json_success( [ 'slug' => $post->post_name ] );
}