| 1 |
<?php |
| 2 |
/** |
| 3 |
* PHP and WordPress configuration compatibility functions for the Gutenberg |
| 4 |
* editor plugin changes related to REST API. |
| 5 |
* |
| 6 |
* @package gutenberg |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
die( 'Silence is golden.' ); |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Registers the REST API routes needed by the Gutenberg editor. |
| 15 |
* |
| 16 |
* @since 2.8.0 |
| 17 |
* @deprecated 5.0.0 |
| 18 |
*/ |
| 19 |
function gutenberg_register_rest_routes() { |
| 20 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Handle a failing oEmbed proxy request to try embedding as a shortcode. |
| 25 |
* |
| 26 |
* @see https://core.trac.wordpress.org/ticket/45447 |
| 27 |
* |
| 28 |
* @since 2.3.0 |
| 29 |
* |
| 30 |
* @param WP_HTTP_Response|WP_Error $response The REST Request response. |
| 31 |
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server). |
| 32 |
* @param WP_REST_Request $request Request used to generate the response. |
| 33 |
* @return WP_HTTP_Response|object|WP_Error The REST Request response. |
| 34 |
*/ |
| 35 |
function gutenberg_filter_oembed_result( $response, $handler, $request ) { |
| 36 |
if ( ! is_wp_error( $response ) || 'oembed_invalid_url' !== $response->get_error_code() || |
| 37 |
'/oembed/1.0/proxy' !== $request->get_route() ) { |
| 38 |
return $response; |
| 39 |
} |
| 40 |
|
| 41 |
// Try using a classic embed instead. |
| 42 |
global $wp_embed; |
| 43 |
$html = $wp_embed->shortcode( array(), $_GET['url'] ); |
| 44 |
if ( ! $html ) { |
| 45 |
return $response; |
| 46 |
} |
| 47 |
|
| 48 |
global $wp_scripts; |
| 49 |
|
| 50 |
// Check if any scripts were enqueued by the shortcode, and include them in |
| 51 |
// the response. |
| 52 |
$enqueued_scripts = array(); |
| 53 |
foreach ( $wp_scripts->queue as $script ) { |
| 54 |
$enqueued_scripts[] = $wp_scripts->registered[ $script ]->src; |
| 55 |
} |
| 56 |
|
| 57 |
return array( |
| 58 |
'provider_name' => __( 'Embed Handler', 'gutenberg' ), |
| 59 |
'html' => $html, |
| 60 |
'scripts' => $enqueued_scripts, |
| 61 |
); |
| 62 |
} |
| 63 |
add_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result', 10, 3 ); |
| 64 |
|
| 65 |
/** |
| 66 |
* Add additional 'visibility' rest api field to taxonomies. |
| 67 |
* |
| 68 |
* Used so private taxonomies are not displayed in the UI. |
| 69 |
* |
| 70 |
* @see https://core.trac.wordpress.org/ticket/42707 |
| 71 |
* @deprecated 5.0.0 |
| 72 |
*/ |
| 73 |
function gutenberg_add_taxonomy_visibility_field() { |
| 74 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Gets taxonomy visibility property data. |
| 79 |
* |
| 80 |
* @see https://core.trac.wordpress.org/ticket/42707 |
| 81 |
* @deprecated 5.0.0 |
| 82 |
* |
| 83 |
* @param array $object Taxonomy data from REST API. |
| 84 |
* @return array Array of taxonomy visibility data. |
| 85 |
*/ |
| 86 |
function gutenberg_get_taxonomy_visibility_data( $object ) { |
| 87 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 88 |
|
| 89 |
return isset( $object['visibility'] ) ? $object['visibility'] : array(); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Add a permalink template to posts in the post REST API response. |
| 94 |
* |
| 95 |
* @see https://core.trac.wordpress.org/ticket/45017 |
| 96 |
* @deprecated 5.0.0 |
| 97 |
* |
| 98 |
* @param WP_REST_Response $response WP REST API response of a post. |
| 99 |
* @return WP_REST_Response Response containing the permalink_template. |
| 100 |
*/ |
| 101 |
function gutenberg_add_permalink_template_to_posts( $response ) { |
| 102 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 103 |
|
| 104 |
return $response; |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Add the block format version to post content in the post REST API response. |
| 109 |
* |
| 110 |
* @see https://core.trac.wordpress.org/ticket/43887 |
| 111 |
* @deprecated 5.0.0 |
| 112 |
* |
| 113 |
* @param WP_REST_Response $response WP REST API response of a post. |
| 114 |
* @return WP_REST_Response Response containing the block_format. |
| 115 |
*/ |
| 116 |
function gutenberg_add_block_format_to_post_content( $response ) { |
| 117 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 118 |
|
| 119 |
return $response; |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Include target schema attributes to links, based on whether the user can. |
| 124 |
* |
| 125 |
* @see https://core.trac.wordpress.org/ticket/45014 |
| 126 |
* @deprecated 5.0.0 |
| 127 |
* |
| 128 |
* @param WP_REST_Response $response WP REST API response of a post. |
| 129 |
* @return WP_REST_Response Response containing the new links. |
| 130 |
*/ |
| 131 |
function gutenberg_add_target_schema_to_links( $response ) { |
| 132 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 133 |
|
| 134 |
return $response; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Whenever a post type is registered, ensure we're hooked into it's WP REST API response. |
| 139 |
* |
| 140 |
* @deprecated 5.0.0 |
| 141 |
* |
| 142 |
* @param string $post_type The newly registered post type. |
| 143 |
* @return string That same post type. |
| 144 |
*/ |
| 145 |
function gutenberg_register_post_prepare_functions( $post_type ) { |
| 146 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 147 |
|
| 148 |
return $post_type; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Silence PHP Warnings and Errors in JSON requests |
| 153 |
* |
| 154 |
* @see https://core.trac.wordpress.org/ticket/44534 |
| 155 |
* @deprecated 5.0.0 |
| 156 |
*/ |
| 157 |
function gutenberg_silence_rest_errors() { |
| 158 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Include additional labels for registered post types |
| 163 |
* |
| 164 |
* @see https://core.trac.wordpress.org/ticket/45101 |
| 165 |
* @deprecated 5.0.0 |
| 166 |
* |
| 167 |
* @param array $args Arguments supplied to register_post_type(). |
| 168 |
* @return array Arguments supplied to register_post_type() |
| 169 |
*/ |
| 170 |
function gutenberg_filter_post_type_labels( $args ) { |
| 171 |
_deprecated_function( __FUNCTION__, '5.0.0' ); |
| 172 |
|
| 173 |
return $args; |
| 174 |
} |
| 175 |
|