From af60320611c6f05978d0247930795e69f497cf3a Mon Sep 17 00:00:00 2001 From: Zach Owen Date: Thu, 26 Apr 2018 16:06:03 -0400 Subject: [PATCH] #8 - Allows filtering yoast_meta --- plugin.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugin.php b/plugin.php index ecefb7e..49818ec 100755 --- a/plugin.php +++ b/plugin.php @@ -7,7 +7,7 @@ * Description: Adds Yoast fields to page and post metadata to WP REST API responses * Author: Niels Garve, Pablo Postigo, Tedy Warsitha, Charlie Francis * Author URI: https://github.com/niels-garve - * Version: 1.4.1 + * Version: 1.4.2 * Plugin URI: https://github.com/niels-garve/yoast-to-rest-api */ class Yoast_To_REST_API { @@ -132,6 +132,17 @@ function wp_api_encode_yoast( $p, $field_name, $request ) { 'yoast_wpseo_canonical' => $wpseo_frontend->canonical( false ), ); + /** + * Filter the returned yoast meta. + * + * @since 1.4.2 + * @param array $yoast_meta Array of metadata to return from Yoast. + * @param \WP_Post $p The current post object. + * @param \WP_REST_Request $request The REST request. + * @return array $yoast_meta Filtered meta array. + */ + $yoast_meta = apply_filters( 'wpseo_to_api_yoast_meta', $yoast_meta, $p, $request ); + wp_reset_query(); return (array) $yoast_meta; @@ -146,6 +157,15 @@ private function wp_api_encode_taxonomy() { 'yoast_wpseo_metadesc' => $wpseo_frontend->metadesc( false ), ); + /** + * Filter the returned yoast meta for a taxonomy. + * + * @since 1.4.2 + * @param array $yoast_meta Array of metadata to return from Yoast. + * @return array $yoast_meta Filtered meta array. + */ + $yoast_meta = apply_filters( 'wpseo_to_api_yoast_taxonomy_meta', $yoast_meta ); + return (array) $yoast_meta; }