'Elementor Document Saved' ); } public static function register( ?bool $active = null ): void { if ( ! ( $active ?? self::is_active() ) ) { return; } add_action( 'elementor/document/before_save', array( __CLASS__, 'before_save' ) ); add_action( 'elementor/document/after_save', array( __CLASS__, 'after_save' ) ); } public static function post_types(): array { return array(); } public static function internal_post_types(): array { return array(); } /** * @param mixed $document The Elementor document. */ public static function before_save( $document ): void { $id = self::post_id( $document ); if ( $id > 0 && ! self::is_autosave( $document, $id ) ) { PostChanges::claim( $id ); } } /** * @param mixed $document The Elementor document. */ public static function after_save( $document ): void { $id = self::post_id( $document ); if ( $id <= 0 || self::is_autosave( $document, $id ) ) { return; } $diff = PostChanges::release( $id ) ?? array(); $type = is_object( $document ) && method_exists( $document, 'get_name' ) ? sanitize_key( (string) $document->get_name() ) : ''; $post = get_post( $id ); $summary = 'kit' === $type ? 'Elementor site settings saved' : sprintf( 'Elementor %1$s "%2$s" saved', $post ? (string) $post->post_type : 'document', $post ? EventLogger::bounded( (string) $post->post_title, 200 ) : '#' . $id ); EventLogger::log( self::SAVED, $summary, $post ? (string) $post->post_type : 'post', $id, array( 'plugin' => self::PLUGIN, 'document_type' => $type, ) + $diff ); } /** * Whether the save is the editor's autosave: the document's own post is * a revision of the main one, not the main one. Autosaves run every * minute while the editor is open and change nothing published; they are * not logged. * * @param mixed $document The Elementor document. * @param int $main_id Its main post id. */ public static function is_autosave( $document, int $main_id ): bool { if ( ! is_object( $document ) || ! method_exists( $document, 'get_post' ) ) { return false; } $post = $document->get_post(); return is_object( $post ) && isset( $post->ID ) && (int) $post->ID !== $main_id; } /** * The post a document saves to: its main id (a revision or autosave * resolves to the post it belongs to). * * @param mixed $document The Elementor document. */ public static function post_id( $document ): int { if ( ! is_object( $document ) || ! method_exists( $document, 'get_main_id' ) ) { return 0; } $id = $document->get_main_id(); return is_numeric( $id ) ? (int) $id : 0; } }