self::FIELD_ID ) ); add_settings_field( 'rooster_lms_' . self::FOLD, __( 'Admin menu in the Designer', 'rooster-lms' ), array( self::class, 'fold_field' ), $page, self::SECTION, array( 'label_for' => self::FOLD_ID ) ); self::place( $page ); } public static function choices(): array { return array( EditorPreference::DESIGNER => __( 'Rooster LMS Designer', 'rooster-lms' ), EditorPreference::BLOCK => __( 'Block editor', 'rooster-lms' ), ); } public static function field(): void { $value = EditorPreference::site(); printf( ''; echo '
' . esc_html__( 'The title and "Edit" in the lists of courses, lessons and quizzes, the admin bar\'s edit link and the row actions open this editor; the other one stays one click away beside it. Each person can choose otherwise with the "Designer" switch in the menu bar.', 'rooster-lms' ) . '
'; if ( ! EditorSwitch::available() ) { echo '' . esc_html__( 'The Designer is not built on this site, so everything opens in the block editor for now.', 'rooster-lms' ) . '
'; } } public static function fold_field(): void { $kit = \RoosterLMS\UI\Ui::kit_toggle( Settings::OPTION . '[' . self::FOLD . ']', true === Settings::get( self::FOLD ), array( 'id' => self::FOLD_ID, 'help' => true, 'label' => __( 'Fold the admin menu to its icons while the Designer is open', 'rooster-lms' ) ) ); if ( null !== $kit ) { echo wp_kses( $kit, \RoosterLMS\UI\Kses::admin() ); } else { printf( '', esc_attr( Settings::OPTION ), esc_attr( self::FOLD ), esc_attr( self::FOLD_ID ), checked( true === Settings::get( self::FOLD ), true, false ), esc_html__( 'Fold the admin menu to its icons while the Designer is open', 'rooster-lms' ) ); } echo '' . esc_html__( 'More room for the curriculum and the editor. On every other screen the menu stays as each person keeps it.', 'rooster-lms' ) . '
'; } private static function place( string $page ): void { global $wp_settings_sections; $sections = (array) ( $wp_settings_sections[ $page ] ?? array() ); if ( ! isset( $sections[ self::SECTION ] ) ) { return; } $ours = $sections[ self::SECTION ]; unset( $sections[ self::SECTION ] ); $out = array(); foreach ( $sections as $id => $section ) { $out[ $id ] = $section; if ( \RoosterLMS\Admin\SettingsPage::SECTION === $id ) { $out[ self::SECTION ] = $ours; } } if ( ! isset( $out[ self::SECTION ] ) ) { $out[ self::SECTION ] = $ours; } $wp_settings_sections[ $page ] = $out; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- the order of our own sections. } }