/** * Validates that the parameter is a custom sharing service ID like 'custom-1461976264'. * * @since 4.3.0 * * @param string $value Value to check. * @param WP_REST_Request $request * @param string $param Name of the parameter passed to endpoint holding $value. * * @return bool */ public static function validate_custom_service_id($value = '', $request, $param) { if (!empty($value) && (!is_string($value) || !preg_match('/custom\\-[0-1]+/i', $value))) { return new WP_Error('invalid_param', sprintf(esc_html__("%s must be a string prefixed with 'custom-' and followed by a numeric ID.", 'jetpack'), $param)); } if (!class_exists('Sharing_Service') && !@(include JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php')) { return new WP_Error('invalid_param', esc_html__('Failed loading required dependency Sharing_Service.', 'jetpack')); } $sharer = new Sharing_Service(); $services = array_keys($sharer->get_all_services()); if (!empty($value) && !in_array($value, $services)) { return new WP_Error('invalid_param', sprintf(esc_html__('%s is not a registered custom sharing service.', 'jetpack'), $param)); } return true; }