Making WordPress.org


Ignore:
Timestamp:
07/17/2024 11:19:52 AM (23 months ago)
Author:
psrpinto
Message:

Translate: Sync "Translation Events" from GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/route.php

    r13739 r13906  
    55use GP_Route;
    66use Wporg\TranslationEvents\Templates;
     7use Wporg\TranslationEvents\Theme_Loader;
    78
    89abstract class Route extends GP_Route {
     10    private Theme_Loader $theme_loader;
     11    private bool $use_theme = false;
     12
     13    public function __construct() {
     14        parent::__construct();
     15        $this->theme_loader = new Theme_Loader( 'wporg-translate-events-2024' );
     16    }
     17
    918    public function tmpl( $template, $args = array(), $honor_api = true ) {
    1019        $this->set_notices_and_errors();
    1120        $this->header( 'Content-Type: text/html; charset=utf-8' );
    1221
    13         Templates::render( $template, $args );
     22        if ( ! $this->use_theme ) {
     23            $this->enqueue_legacy_styles();
     24            Templates::render( $template, $args );
     25            return;
     26        }
     27
     28        $json = wp_json_encode( $args );
     29        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
     30        echo do_blocks( "<!-- wp:wporg-translate-events-2024/page-events-$template $json /-->" );
     31    }
     32
     33    protected function use_theme( bool $also_in_production = false ): void {
     34        if ( $also_in_production ) {
     35            $this->use_theme = true;
     36        } else {
     37            // Only enable if new design has been explicitly enabled.
     38            $this->use_theme = defined( 'TRANSLATION_EVENTS_NEW_DESIGN' ) && TRANSLATION_EVENTS_NEW_DESIGN;
     39        }
     40
     41        if ( ! $this->use_theme ) {
     42            return;
     43        }
     44
     45        $this->theme_loader->load();
     46    }
     47
     48    private function enqueue_legacy_styles(): void {
     49        wp_register_style(
     50            'translation-events-css',
     51            plugins_url( '/assets/css/translation-events.css', realpath( __DIR__ . '/../' ) ),
     52            array( 'dashicons' ),
     53            filemtime( __DIR__ . '/../../assets/css/translation-events.css' )
     54        );
     55        wp_enqueue_style( 'translation-events-css' );
    1456    }
    1557}
Note: See TracChangeset for help on using the changeset viewer.