post_status ) { return new \WP_Error( 'searchsmith_trashed', __( 'The post is in the trash.', 'searchsmith' ), array( 'status' => 409 ) ); } $expected = self::parse_gmt( (string) $expected ); if ( null === $expected ) { return new \WP_Error( 'searchsmith_invalid_version', __( 'expected_modified_gmt is not a valid date.', 'searchsmith' ), array( 'status' => 400 ) ); } if ( ContentEditor::modified_mysql( $post ) !== $expected ) { return new \WP_Error( 'searchsmith_stale', __( 'The post changed since it was read.', 'searchsmith' ), array( 'status' => 409, 'modified_gmt' => ContentEditor::modified( $post ), ) ); } if ( ! function_exists( 'wp_check_post_lock' ) ) { require_once ABSPATH . 'wp-admin/includes/post.php'; } if ( wp_check_post_lock( $post->ID ) ) { return new \WP_Error( 'searchsmith_locked', __( 'Someone has the post open in the editor.', 'searchsmith' ), array( 'status' => 423 ) ); } return null; } /** * Refuses content changes to a page whose layout a page builder keeps. * * @param \WP_Post $post The post. * @return \WP_Error|null */ public static function builder_refusal( \WP_Post $post ) { $builder = Environment::builder_for_post( $post->ID ); if ( ! $builder ) { return null; } return new \WP_Error( 'searchsmith_builder_page', __( 'The post is built with a page builder, so its content cannot be edited here.', 'searchsmith' ), array( 'status' => 409, 'builder' => $builder, ) ); } /** * Runs a post save without core's HTML filtering of the content. * * For users without `unfiltered_html`, WordPress filters a post's whole * content through kses on save. That would rewrite blocks Blaze didn't * target, such as an embed an administrator added, breaking the promise * that they stay byte for byte the same. The content saved inside the * callback is the post's own stored content, or a revision of it, with * Blaze's changes made by the connector: new blocks already passed * through `wp_kses_post()` and replaced text escaped as plain text. * Titles and excerpts are still filtered as usual. * * @param callable $save The save. * @return mixed What the callback returns. */ public static function without_content_kses( callable $save ) { $removed = array(); foreach ( array( 'content_save_pre', 'content_filtered_save_pre' ) as $hook ) { $priority = has_filter( $hook, 'wp_filter_post_kses' ); if ( false !== $priority ) { remove_filter( $hook, 'wp_filter_post_kses', $priority ); $removed[ $hook ] = $priority; } } try { return $save(); } finally { foreach ( $removed as $hook => $priority ) { add_filter( $hook, 'wp_filter_post_kses', $priority ); } } } /** * Parses a date as UTC unless it names its own offset, and returns it in * the database's `Y-m-d H:i:s` format. * * @param string $value Date such as `2026-11-16T10:00:00`. * @return string|null */ public static function parse_gmt( $value ) { if ( '' === $value ) { return null; } try { $date = new \DateTimeImmutable( $value, new \DateTimeZone( 'UTC' ) ); } catch ( \Exception $e ) { return null; } return $date->setTimezone( new \DateTimeZone( 'UTC' ) )->format( 'Y-m-d H:i:s' ); } }