public function save_post()

in admin/AmazonAI-PollyService.php [36:80]


	public function save_post( $post_id, $post, $updated ) {
		$common = $this->common;
		$logger = new AmazonAI_Logger();
		$logger->log(sprintf('%s Saving post ( id=%s )', __METHOD__, $post_id));

		// Check if this isn't an auto save.
		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
			return;
		}

		// Check to make sure this is not a new post creation.
		if ( ! $updated ) {
			return;
		}

		// Validate if this post which is being saved is one of supported types. If not, return.
		$post_types_supported = $common->get_posttypes_array();
		$post_type = get_post_type($post_id);
		if ( !in_array($post_type, $post_types_supported) ) {
			return;
		}

		// If nonce is valid then update post meta
		// If it's not valid then this is probably a quick or bulk edit request in which case we won't update the polly post meta
		if ( isset($_POST[self::NONCE_NAME]) && wp_verify_nonce($_POST[self::NONCE_NAME], 'amazon-polly') ) {
			update_post_meta( $post_id, 'amazon_polly_enable', (int) isset($_POST['amazon_polly_enable']));

			// If disabling post translation
			if ( isset($_POST['amazon_ai_deactive_translation']) ) {
				$common->deactive_translation_for_post($post_id);
			}

			// Update post voice ID
			if ( isset( $_POST['amazon_polly_voice_id']) ) {
				$voice_id = sanitize_text_field(wp_unslash($_POST['amazon_polly_voice_id']));
				update_post_meta( $post_id, 'amazon_polly_voice_id', $voice_id);
			}
		}

		if( ! ( wp_is_post_revision( $post_id) || wp_is_post_autosave( $post_id ) ) ) {
			$logger->log(sprintf('%s Starting background task process ( id=%s )', __METHOD__, $post_id));
	    $background_task = new AmazonAI_BackgroundTask();
	    $background_task->trigger(self::GENERATE_POST_AUDIO_TASK, [ $post_id ]);
		}
	}