true ) ); wp_set_script_translations( $handle, 'schedulereed', SCHEDULEREED_DIR . 'languages' ); foreach ( array( "build/style-{$entry}.css", "build/{$entry}.css" ) as $css ) { if ( file_exists( SCHEDULEREED_DIR . $css ) ) { wp_register_style( $handle, plugins_url( $css, SCHEDULEREED_FILE ), array(), $asset['version'] ); break; } } return true; } /** * What every ScheduleReed script needs: where the API is and a nonce, so * signed-in users are recognised. * * @return array */ public static function globals(): array { return array( 'api' => esc_url_raw( rest_url( 'schedulereed/v1/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'edition' => Edition::for_script(), ); } /** * Print the globals before a script once. * * @param string $handle Script handle. */ public static function localize( string $handle ): void { static $done = array(); if ( isset( $done[ $handle ] ) ) { return; } $done[ $handle ] = true; wp_add_inline_script( $handle, 'window.schedulereed = Object.assign( window.schedulereed || {}, ' . wp_json_encode( self::globals() ) . ' );', 'before' ); } }