self::HEADER ) ); $parts = preg_split( '/[\s,]+/', (string) ( $data['contracts'] ?? '' ) ); foreach ( is_array( $parts ) ? $parts : array() as $one ) { if ( 1 === preg_match( '/^C\d+@\d+$/', $one ) ) { $found[] = $one; } } } $filtered = apply_filters( 'rooster_lms_theme_contracts', array_values( array_unique( $found ) ) ); self::$contracts = is_array( $filtered ) ? array_values( array_filter( array_map( 'strval', $filtered ) ) ) : array(); } return self::$contracts; } public static function version( string $contract ): int { $max = 0; foreach ( self::contracts() as $one ) { if ( str_starts_with( $one, $contract . '@' ) ) { $max = max( $max, (int) substr( $one, strlen( $contract ) + 1 ) ); } } return $max; } public static function authority(): string { $authority = function_exists( 'rooster_design_authority' ) ? (string) rooster_design_authority() : 'plugins'; $authority = apply_filters( 'rooster_lms_design_authority', $authority ); return 'theme' === $authority ? 'theme' : 'plugins'; } public static function editor_flag(): void { wp_add_inline_script( 'wp-blocks', 'window.roosterLmsDesign=' . wp_json_encode( array( 'themed' => self::designs() ) ) . ';', 'before' ); } public static function designs(): bool { return 'theme' === self::authority() && self::declares( 'C2' ); } public static function declares( string $contract ): bool { foreach ( self::contracts() as $one ) { if ( $one === $contract || ( ! str_contains( $contract, '@' ) && str_starts_with( $one, $contract . '@' ) ) ) { return true; } } return false; } public static function academy_page( $academy, $queried = null ): bool { if ( $academy || '' !== (string) get_query_var( CertificateRoute::VAR ) ) { return true; } if ( ! $queried instanceof \WP_Post ) { return false; } if ( PersonsModule::POST_TYPE === $queried->post_type ) { return true; } if ( 'page' !== $queried->post_type ) { return false; } foreach ( array( 'account_page_id', 'portal_page_id', 'certificate_verify_page_id', 'registration_page_id' ) as $setting ) { $page = (int) Settings::get( $setting ); if ( $page > 0 && ( $page === (int) $queried->ID || in_array( (int) $queried->ID, array_map( 'intval', Providers::current()->post_translations( $page ) ), true ) ) ) { return true; } } return false; } public static function reset(): void { self::$contracts = null; } }