Changeset 8701
- Timestamp:
- 04/29/2019 07:09:55 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
r8689 r8701 13 13 14 14 add_filter( 'handbook_label', array( $this, 'change_handbook_label' ), 10, 2 ); 15 add_filter( 'get_post_metadata', array( $this, 'fix_markdown_source_meta' ), 10, 4 ); 15 16 add_filter( 'wporg_markdown_before_transform', array( $this, 'wporg_markdown_before_transform' ), 10, 2 ); 16 17 add_filter( 'wporg_markdown_after_transform', array( $this, 'wporg_markdown_after_transform' ), 10, 2 ); … … 42 43 43 44 return $label; 45 } 46 47 /** 48 * Fixes fetched value of markdown_source meta field to not be the 49 * raw.githubcontent.com domain that is currently incorrectly used 50 * in the block editor manifest. 51 * 52 * @param mixed $null A value for the meta if its data retrieval is 53 * overridden, else null. 54 * @param int $object_id Object ID. 55 * @param string $meta_key Meta key. 56 * @param bool $single Whether to return only the first value of the specified $meta_key. 57 * @return mixed 58 */ 59 public function fix_markdown_source_meta( $null, $object_id, $meta_key, $single ) { 60 if ( 61 // Not the markdown source meta key. 62 $meta_key !== $this->meta_key 63 || 64 // Not the block editor handbook. 65 $this->get_post_type() !== get_post_type( $object_id ) 66 ) { 67 return $null; 68 } 69 70 $post = get_post( $object_id ); 71 72 $meta_type = 'post'; 73 74 /* Most of the rest of this is taken from get_metadata() */ 75 76 $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); 77 78 if ( ! $meta_cache ) { 79 $meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); 80 $meta_cache = $meta_cache[ $object_id ]; 81 } 82 83 if ( ! $meta_key ) { 84 return $null; 85 } 86 87 if ( isset( $meta_cache[ $meta_key ] ) ) { 88 if ( $single ) { 89 $value = maybe_unserialize( $meta_cache[ $meta_key ][0] ); 90 $value = str_replace( 'https://raw.githubusercontent.com/WordPress/gutenberg/', 'https://github.com/WordPress/gutenberg/edit/', $value ); 91 } else { 92 $value = array_map( 'maybe_unserialize', $meta_cache[ $meta_key ] ); 93 $value = array_map( 94 function( $x ) { 95 return str_replace( 'https://raw.githubusercontent.com/WordPress/gutenberg/', 'https://github.com/WordPress/gutenberg/edit/', $x ); 96 }, 97 $value 98 ); 99 } 100 return $value; 101 } 102 103 return $null; 44 104 } 45 105
Note: See TracChangeset
for help on using the changeset viewer.