| 1 |
<?php |
| 2 |
/** |
| 3 |
* Temporary compatibility shims for features present in Gutenberg, pending |
| 4 |
* upstream commit to the WordPress core source repository. Functions here |
| 5 |
* exist only as long as necessary for corresponding WordPress support, and |
| 6 |
* each should be associated with a Trac ticket. |
| 7 |
* |
| 8 |
* @package gutenberg |
| 9 |
*/ |
| 10 |
|
| 11 |
/** |
| 12 |
* Filters allowed CSS attributes to include `flex-basis`, included in saved |
| 13 |
* markup of the Column block. |
| 14 |
* |
| 15 |
* This can be removed when plugin support requires WordPress 5.3.0+. |
| 16 |
* |
| 17 |
* @see https://core.trac.wordpress.org/ticket/47281 |
| 18 |
* @see https://core.trac.wordpress.org/changeset/45363 |
| 19 |
* |
| 20 |
* @since 5.7.0 |
| 21 |
* |
| 22 |
* @param string[] $attr Array of allowed CSS attributes. |
| 23 |
* |
| 24 |
* @return string[] Filtered array of allowed CSS attributes. |
| 25 |
*/ |
| 26 |
function gutenberg_safe_style_css_column_flex_basis( $attr ) { |
| 27 |
$attr[] = 'flex-basis'; |
| 28 |
|
| 29 |
return $attr; |
| 30 |
} |
| 31 |
add_filter( 'safe_style_css', 'gutenberg_safe_style_css_column_flex_basis' ); |
| 32 |
|
| 33 |
/** |
| 34 |
* Sets the current post for usage in template blocks. |
| 35 |
* |
| 36 |
* @return WP_Post|null The post if any, or null otherwise. |
| 37 |
*/ |
| 38 |
function gutenberg_get_post_from_context() { |
| 39 |
// TODO: Without this temporary fix, an infinite loop can occur where |
| 40 |
// posts with post content blocks render themselves recursively. |
| 41 |
if ( is_admin() || defined( 'REST_REQUEST' ) ) { |
| 42 |
return null; |
| 43 |
} |
| 44 |
if ( ! in_the_loop() ) { |
| 45 |
rewind_posts(); |
| 46 |
the_post(); |
| 47 |
} |
| 48 |
return get_post(); |
| 49 |
} |
| 50 |
|