Changeset 9084
- Timestamp:
- 07/29/2019 07:00:42 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/import-block-editor.php
r8803 r9084 12 12 ); 13 13 14 add_filter( 'template_redirect', array( $this, 'redirects' ), 1 ); 14 15 add_filter( 'handbook_label', array( $this, 'change_handbook_label' ), 10, 2 ); 15 16 add_filter( 'handbook_display_toc', array( $this, 'disable_toc' ) ); … … 29 30 remove_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allow_extra_tags' ), 10, 1 ); 30 31 } ); 32 } 33 34 /** 35 * Handles redirects for renamed/removed handbook pages. 36 */ 37 public function redirects() { 38 if ( 0 !== strpos( $_SERVER['REQUEST_URI'], '/block-editor/' ) ) { 39 return; 40 } 41 42 $handbook_path = explode( '/', trailingslashit( $_SERVER['REQUEST_URI'] ), 3 ); 43 $handbook_path = $handbook_path[2] ?? null; 44 45 if ( is_null( $handbook_path ) ) { 46 return; 47 } 48 49 // Any handbook pages where the slug changes should be listed here. 50 $redirects = [ 51 'tutorials/block-tutorial/block-controls-toolbars-and-inspector' => 'tutorials/block-tutorial/block-controls-toolbar-and-sidebar/', 52 ]; 53 54 // General path redirects. (More specific path first.) 55 $path_redirects = [ 56 // 'some-path/' => 'new-path/', 57 ]; 58 59 $new_handbook_path = ''; 60 if ( ! empty( $redirects[ untrailingslashit( $handbook_path ) ] ) ) { 61 $new_handbook_path = $redirects[ untrailingslashit( $handbook_path ) ]; 62 } else { 63 foreach ( $path_redirects as $old_path => $new_path ) { 64 if ( 0 === strpos( $handbook_path, $old_path ) ) { 65 $new_handbook_path = str_replace( $old_path, $new_path, $handbook_path ); 66 break; 67 } 68 } 69 } 70 71 if ( $new_handbook_path ) { 72 $redirect_to = get_post_type_archive_link( $this->get_post_type() ) . $new_handbook_path; 73 74 wp_safe_redirect( $redirect_to, 301 ); 75 exit; 76 } 31 77 } 32 78
Note: See TracChangeset
for help on using the changeset viewer.