verification-tools-utils.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * Helper functions that are called from API even when module is inactive should be added here.
  4. * This file will be included in module-extras.php.
  5. */
  6. function jetpack_verification_validate( $verification_services_codes ) {
  7. foreach ( $verification_services_codes as $key => $code ) {
  8. // Parse html meta tag if it does not look like a valid code
  9. if ( ! preg_match( '/^[a-z0-9_-]+$/i', $code ) ) {
  10. $code = jetpack_verification_get_code($code);
  11. }
  12. $code = esc_attr( trim( $code ) );
  13. // limit length to 100 chars.
  14. $code = substr( $code, 0, 100 );
  15. /**
  16. * Fire after each Verification code was validated.
  17. *
  18. * @module verification-tools
  19. *
  20. * @since 3.0.0
  21. *
  22. * @param string $key Verification service name.
  23. * @param string $code Verification service code provided in field in the Tools menu.
  24. */
  25. do_action( 'jetpack_site_verification_validate', $key, $code );
  26. $verification_services_codes[ $key ] = $code;
  27. }
  28. return $verification_services_codes;
  29. }
  30. function jetpack_verification_get_code( $code ){
  31. $pattern = '/content=["\']?([^"\' ]*)["\' ]/is';
  32. preg_match( $pattern, $code, $match );
  33. if ( $match ){
  34. return urldecode( $match[1] );
  35. } else {
  36. return false;
  37. }
  38. }