Changeset 12252
- Timestamp:
- 11/18/2022 01:48:31 AM (2 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/.wp-env.json
r11559 r12252 1 1 { 2 "core": "WordPress/WordPress#master",3 2 "themes": [ 4 3 ".", -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/README.md
r11559 r12252 9 9 0. Install all the prerequisites. 10 10 11 1. **Required:** Node.js 14. 12 2. **Required:** Composer. 13 3. **Recommended:** Docker (to use the automatic setup) 11 1. **Required:** Node.js 14 12 2. **Required:** Composer 13 3. **Required:** Subversion 14 4. **Recommended:** Docker (to use the automatic setup) 14 15 15 16 1. Build the parent theme WordPress.org theme. … … 19 20 2. Install all the required `npm` packages. 20 21 ```bash 22 $ npm install 23 ``` 24 If you face issues installing Sass, try the following command, and 25 `npm install` again. 26 ```bash 27 $ npm install node-sass@npm:sass 21 28 $ npm install 22 29 ``` … … 77 84 `wporg-openverse` (child) themes installed. For detailed instructions, 78 85 please read [the wp-env docs](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/). 86 4. Edit the `.htaccess` file to prevent Apache 404 errors. 87 ```bash 88 $ wp-env run cli bash 89 bash-5.1$ printf "RewriteEngine on\nFallbackResource /index.php\n" > .htaccess 90 bash-5.1$ exit 91 ``` 79 92 80 93 **Manual:** … … 97 110 6. Activate and customize the theme. 98 111 99 1. Log into `/wp-admin`. 112 1. Log into `/wp-admin`. If you used `@wordpress/env`, your username will 113 be 'admin' and password will be 'password'. 100 114 2. Under Appearance > Themes, activate the theme 'WordPress.org Openverse'. 101 115 3. To change the embed URL, open the customizer at Appearance > Customize … … 108 122 2. Visit the site and interactively test the messages. 109 123 124 8. Test redirects. 125 126 1. Visit some test URLs. 127 1. https://ru.wordpress.org/openverse → ... 128 2. https://wordpress.org/openverse/search/?q=dog → ... 129 2. See the target redirect URL as a comment inside the dev tools. 130 1. ... → https://openverse.wordpress.net/ru/ 131 2. ... → https://openverse.wordpress.net/search/?q=dog 132 3. Change the language in Settings > General to see how the locale factors 133 into the redirect path. 134 110 135 ## Related links 111 136 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/functions.php
r11592 r12252 18 18 * This is subdirectory on WordPress.org which loads the Openverse site. This is 19 19 * prefixed in front of all path changes sent by the embedded `iframe`. 20 * 21 * When used with the standalone redirect, it is removed from the path forwarded 22 * to the standalone site. 20 23 */ 21 24 if ( !defined( 'OPENVERSE_SUBPATH' ) ) { … … 83 86 84 87 /** 88 * Get the slug of the given WP locale. This function returns a blank string if 89 * the locale is `en_US` because that is considered the default and is not 90 * prefixed in the URL paths. It also returns a blank string if `$wp_locale` is 91 * not found in the locales list. 92 */ 93 function get_locale_slug( $curr_locale ) { 94 if ( $curr_locale === 'en_US' ) { 95 return ''; 96 } 97 98 return get_locales()[ $curr_locale ]->slug ?? ''; 99 } 100 101 /** 85 102 * Enqueue styles & scripts. 86 103 * … … 106 123 107 124 $use_path_based_locale_forwarding = get_theme_mod( 'ov_path_based_i18n', false ); 108 $wp_locale = get_locale(); 109 $locale = get_locales()[ $wp_locale ]; 110 $locale_slug = $use_path_based_locale_forwarding && $wp_locale !== 'en_US' ? $locale->slug : ''; 125 $curr_locale = get_locale(); 126 $locale_slug = ''; 127 if ( $use_path_based_locale_forwarding ) { 128 $locale_slug = get_locale_slug( $curr_locale ); 129 } 111 130 112 131 wp_add_inline_script( … … 114 133 /* JS */ 'const openverseUrl = ' . wp_json_encode( get_theme_mod( 'ov_src_url', OPENVERSE_URL ) ) . ";\n" . 115 134 /* JS */ 'const openverseSubpath = ' . wp_json_encode( OPENVERSE_SUBPATH ) . ";\n" . 116 /* JS */ 'const currentLocale = ' . wp_json_encode( $ wp_locale ) . ";\n" . /* Used for legacy cookie based locale forwarding */135 /* JS */ 'const currentLocale = ' . wp_json_encode( $curr_locale ) . ";\n" . /* Used for legacy cookie based locale forwarding */ 117 136 /* JS */ 'const localeSlug = ' . wp_json_encode( $locale_slug ) . ";\n", 118 137 /* position */ 'before' … … 151 170 } 152 171 add_filter( 'document_title_parts', __NAMESPACE__ . '\title_no_title' ); 172 173 /* 174 TODO: Delete this and everything related to it 175 ====================== 176 Openverse iframe embed 177 ====================== 178 */ 153 179 154 180 /** … … 204 230 } 205 231 add_action( 'customize_register', __NAMESPACE__ . '\wporg_ov_customizer' ); 232 233 /* 234 ===================================== 235 Openverse standalone site redirection 236 ===================================== 237 */ 238 239 /** 240 * This is the URL at which the standalone Openverse site is hosted. When 241 * redirect is enabled (see setting `ov_is_redirect_enabled`), the theme 242 * redirects all incoming requests to the right URL on this domain. 243 * 244 * Note: Do not put a trailing slash '/' in this URL. Paths start with a leading 245 * slash so a trailing slash here will lead to two slashes in the final URL. 246 */ 247 if ( !defined( 'OPENVERSE_STANDALONE_URL' ) ) { 248 define( 'OPENVERSE_STANDALONE_URL', 'https://openverse.wordpress.net' ); 249 } 250 251 /** 252 * Determine the target URL of the redirect based on the Openverse standalone 253 * URL, the requested path and the current locale. 254 * 255 * Examples: 256 * - https://ru.wordpress.org/openverse → {ov_redirect_url}/ru/ 257 * - https://wordpress.org/openverse/search/?q=dog → {ov_redirect_url}/search/?q=dog 258 */ 259 function get_target_url() { 260 $target_url = get_theme_mod( 'ov_redirect_url', OPENVERSE_STANDALONE_URL ); 261 262 $curr_locale = get_locale(); 263 $locale = get_locale_slug( $curr_locale ); 264 if ( $locale !== '' ) { 265 $target_url .= '/' . $locale; 266 } 267 268 $path = $_SERVER['REQUEST_URI']; 269 if ( $path ) { 270 $count = 1; // Only replace the leading Openverse subpath. 271 $target_url .= str_replace( OPENVERSE_SUBPATH, '', $path, $count ); 272 } 273 274 return $target_url; 275 } 276 277 /** 278 * Provide configuration for the theme to redirect to the given standalone 279 * Openverse site. The destination URL can be configured and the behaviour can 280 * be dormant unless enabled. 281 * 282 * @param \WP_Customize_Manager $wp_customize Theme Customizer object. 283 */ 284 function wporg_ov_redir_customizer( $wp_customize ) { 285 $wp_customize->add_section( 'ov_redir', array( 286 'priority' => 10, 287 'capability' => 'edit_theme_options', 288 'title' => 'Openverse Redirect', 289 'description' => 'Configure the redirection to the standalone Openverse site.' 290 ) ); 291 292 $wp_customize->add_setting( 'ov_redirect_url', array( 293 'type' => 'theme_mod', 294 'capability' => 'edit_theme_options', 295 'default' => OPENVERSE_STANDALONE_URL, 296 'sanitize_callback' => function( $val, $setting ) { 297 if ( substr( $val, -1 ) == '/' ) { // If the last character is a slash '/',... 298 $val = substr( $val, 0, -1 ); // ...remove it. 299 } 300 if ( empty( $val ) ) { 301 return $setting->default; 302 } 303 return $val; 304 } 305 ) ); 306 307 $wp_customize->add_control( 'ov_redirect_url', array( 308 'section' => 'ov_redir', 309 'type' => 'url', 310 'id' => 'ov_redirect_url', 311 'label' => 'Redirect URL', 312 'description' => '<b>Note</b>: ' 313 . 'Do not put a trailing slash \'/\' in this URL.<br/>' 314 . '<b>Default</b>: ' 315 . esc_html( OPENVERSE_STANDALONE_URL ), 316 'priority' => 10, 317 'input_attrs' => array( 318 'placeholder' => 'URL' 319 ) 320 ) ); 321 322 $wp_customize->add_setting( 'ov_is_redirect_enabled', array( 323 'type' => 'theme_mod', 324 'capability' => 'edit_theme_options', 325 'default' => false 326 ) ); 327 328 $wp_customize->add_control( 'ov_is_redirect_enabled', array( 329 'section' => 'ov_redir', 330 'type' => 'checkbox', 331 'id' => 'ov_is_redirect_enabled', 332 'label' => 'Redirect to the standalone Openverse site.', 333 'priority' => 10 334 ) ); 335 } 336 add_action( 'customize_register', __NAMESPACE__ . '\wporg_ov_redir_customizer' ); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/index.php
r11217 r12252 15 15 namespace WordPressdotorg\Openverse\Theme; 16 16 17 /* 18 If the theme mod `ov_is_redirect_enabled` is set to `true`, redirect to the 19 standalone site and exit immediately. If not, print what would have been the 20 redirect URL to the HTML as a comment. 21 */ 22 23 $is_redirect_enabled = get_theme_mod( 'ov_is_redirect_enabled' ); 24 $target_url = get_target_url(); 25 26 if ( $is_redirect_enabled ) { 27 wp_redirect( $target_url ); 28 exit; 29 } else { 30 echo "<!-- " . $target_url . " -->"; 31 } 32 17 33 get_header(); 18 34 ?>
Note: See TracChangeset
for help on using the changeset viewer.