true ) ) as $post_type ) { register_rest_field( $post_type, self::FIELD, array( 'get_callback' => array( __CLASS__, 'get_value' ), 'update_callback' => array( __CLASS__, 'update_value' ), 'schema' => array( 'description' => __( 'Are sharing buttons enabled?', 'jetpack-sharing-likes' ), 'type' => 'boolean', ), ) ); add_post_type_support( $post_type, self::POST_TYPE_SUPPORT ); } } /** * Whether sharing buttons may show on the post. * * @param array $post Post data as the REST API prepared it. */ public static function get_value( array $post ): bool { if ( ! isset( $post['id'] ) ) { return false; } return ! get_post_meta( $post['id'], self::META_KEY, true ); } /** * Clear the opt-out when enabling, set it when disabling. * * @param bool $enable Whether sharing buttons should show on the post. * @param \WP_Post $post_object The post being updated. * * @return int|bool What `update_post_meta()` or `delete_post_meta()` returned. */ public static function update_value( $enable, $post_object ) { if ( $enable ) { return delete_post_meta( $post_object->ID, self::META_KEY ); } return update_post_meta( $post_object->ID, self::META_KEY, true ); } }