PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 13.5
Jetpack – WP Security, Backup, Speed, & Growth v13.5
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 13.5, at sal/class.json-api-metadata.php

79 lines 2.1 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 /**
9 * Base class for WPCOM_JSON_API_Metadata
10 */
11 class WPCOM_JSON_API_Metadata {
12 /**
13 * Checks to see if a meta key is in the array of allowed public (and whitelisted) meta data.
14 *
15 * Additionally, if the key begins with 'geo_' or '_wpas_', true will also be returned.
16 *
17 * @param string $key A post metadata key value to check.
18 * @return bool True or false depending on whether the key meets the defined criteria.
19 **/
20 public static function is_public( $key ) {
21 if ( empty( $key ) ) {
22 return false;
23 }
24
25 // Default whitelisted meta keys.
26 $whitelisted_meta = array( '_thumbnail_id' );
27
28 // whitelist of metadata that can be accessed.
29 /** This filter is documented in json-endpoints/class.wpcom-json-api-post-endpoint.php */
30 if ( in_array( $key, apply_filters( 'rest_api_allowed_public_metadata', $whitelisted_meta ), true ) ) {
31 return true;
32 }
33
34 if ( str_starts_with( $key, 'geo_' ) ) {
35 return true;
36 }
37
38 if ( str_starts_with( $key, '_wpas_' ) ) {
39 return true;
40 }
41
42 return false;
43 }
44
45 /**
46 * Checks to see if a meta key should be used internally only.
47 *
48 * @param string $key A post metadata key value to check.
49 * @return bool True or false depending on whether the key meets the defined criteria.
50 **/
51 public static function is_internal_only( $key ) {
52 // We want to always return the `_jetpack_blogging_prompt_key` key in post responses if it is available.
53 if ( $key === '_jetpack_blogging_prompt_key' ) {
54 return false;
55 }
56
57 // We want to always return the `_jetpack_newsletter_access` key to
58 // display the correct newsletter access in Calypso.
59 $whitelist = array(
60 '_jetpack_newsletter_access',
61 '_jetpack_newsletter_tier_id',
62 );
63
64 if ( in_array( $key, $whitelist, true ) ) {
65 return false;
66 }
67
68 if ( str_starts_with( $key, '_jetpack_' ) ) {
69 return true;
70 }
71
72 if ( str_starts_with( $key, '_elasticsearch_' ) ) {
73 return true;
74 }
75
76 return false;
77 }
78 }
79