PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.6.3
Jetpack – WP Security, Backup, Speed, & Growth v12.6.3
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / sal / class.json-api-metadata.php

class.json-api-metadata.php in Jetpack – WP Security, Backup, Speed, & Growth 12.6.3, at sal/class.json-api-metadata.php

72 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * WPCOM_JSON_API_Metadata class - Utility classes that don't necessarily have a home yet.
4 *
5 * @package automattic/jetpack
6 */
7 /**
8 * Base class for WPCOM_JSON_API_Metadata
9 */
10 class WPCOM_JSON_API_Metadata {
11 /**
12 * Checks to see if a meta key is in the array of allowed public (and whitelisted) meta data.
13 *
14 * Additionally, if the key begins with 'geo_' or '_wpas_', true will also be returned.
15 *
16 * @param string $key A post metadata key value to check.
17 * @return bool True or false depending on whether the key meets the defined criteria.
18 **/
19 public static function is_public( $key ) {
20 if ( empty( $key ) ) {
21 return false;
22 }
23
24 // Default whitelisted meta keys.
25 $whitelisted_meta = array( '_thumbnail_id' );
26
27 // whitelist of metadata that can be accessed.
28 /** This filter is documented in json-endpoints/class.wpcom-json-api-post-endpoint.php */
29 if ( in_array( $key, apply_filters( 'rest_api_allowed_public_metadata', $whitelisted_meta ), true ) ) {
30 return true;
31 }
32
33 if ( 0 === strpos( $key, 'geo_' ) ) {
34 return true;
35 }
36
37 if ( 0 === strpos( $key, '_wpas_' ) ) {
38 return true;
39 }
40
41 return false;
42 }
43
44 /**
45 * Checks to see if a meta key should be used internally only.
46 *
47 * @param string $key A post metadata key value to check.
48 * @return bool True or false depending on whether the key meets the defined criteria.
49 **/
50 public static function is_internal_only( $key ) {
51 // We want to always return the `_jetpack_blogging_prompt_key` key in post responses if it is available.
52 if ( $key === '_jetpack_blogging_prompt_key' ) {
53 return false;
54 }
55
56 // We want to always return the `_jetpack_newsletter_access` key to display the correct newsletter access in Calypso.
57 if ( $key === '_jetpack_newsletter_access' ) {
58 return false;
59 }
60
61 if ( 0 === strpos( $key, '_jetpack_' ) ) {
62 return true;
63 }
64
65 if ( 0 === strpos( $key, '_elasticsearch_' ) ) {
66 return true;
67 }
68
69 return false;
70 }
71 }
72