0 ? get_post( $post_id ) : null; return $user_id > 0 && $post instanceof \WP_Post && in_array( $post->post_type, ContentInfo::TYPES, true ) && user_can( $user_id, 'edit_post', $post_id ); } public static function active_post(): int { return self::$post_id; } public static function reset(): void { self::$post_id = 0; remove_filter( 'admin_body_class', array( self::class, 'body_class' ) ); remove_filter( 'filter_block_editor_meta_boxes', array( self::class, 'block_editor_meta_boxes' ), PHP_INT_MAX ); remove_action( 'add_meta_boxes', array( self::class, 'remove_meta_boxes' ), PHP_INT_MAX ); remove_action( 'enqueue_block_editor_assets', array( self::class, 'enqueue' ), 100 ); remove_filter( 'redirect_post_location', array( self::class, 'keep_flag' ) ); } public static function body_class( $classes ): string { $post = get_post( self::$post_id ); $extra = ' ' . self::BODY_CLASS; $extra .= null !== $post && 'publish' !== $post->post_status ? ' ' . self::BODY_CLASS . '--draft' : ''; return (string) $classes . $extra; } public static function block_editor_meta_boxes( $boxes ) { $post = get_post( self::$post_id ); if ( is_array( $boxes ) && null !== $post ) { unset( $boxes[ $post->post_type ] ); } return $boxes; } public static function remove_meta_boxes( $post_type = '' ): void { global $wp_meta_boxes; $post_type = is_string( $post_type ) ? $post_type : ''; if ( '' === $post_type || ! isset( $wp_meta_boxes[ $post_type ] ) || ! is_array( $wp_meta_boxes[ $post_type ] ) ) { return; } foreach ( $wp_meta_boxes[ $post_type ] as $context => $priorities ) { foreach ( (array) $priorities as $boxes ) { foreach ( array_keys( (array) $boxes ) as $id ) { if ( 'submitdiv' !== $id ) { remove_meta_box( (string) $id, $post_type, (string) $context ); } } } } } public static function keep_flag( $location ): string { return add_query_arg( self::FLAG, '1', (string) $location ); } public static function panels( string $post_type ): array { $out = self::PANELS; foreach ( get_object_taxonomies( $post_type ) as $taxonomy ) { $out[] = 'taxonomy-panel-' . $taxonomy; } return $out; } public static function enqueue(): void { $post = get_post( self::$post_id ); if ( null === $post ) { return; } wp_enqueue_style( self::HANDLE, plugins_url( 'assets/admin/content-frame.css', ROOSTER_LMS_FILE ), array(), ROOSTER_LMS_VERSION ); wp_enqueue_script( self::HANDLE, plugins_url( 'assets/admin/content-frame.js', ROOSTER_LMS_FILE ), array( 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-plugins', 'wp-preferences', 'wp-edit-post' ), ROOSTER_LMS_VERSION, array( 'in_footer' => true ) ); wp_add_inline_script( self::HANDLE, 'window.roosterLmsContentFrame = ' . wp_json_encode( array( 'postId' => $post->ID, 'source' => self::MESSAGE_SOURCE, 'panels' => self::panels( $post->post_type ), 'plugins' => array( 'rooster-lms-builder-switch' ), ), JSON_HEX_TAG | JSON_HEX_AMP ) . ';', 'before' ); } }