Nessuna descrizione

verification-tools-utils.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. if ( ! function_exists( 'jetpack_verification_validate' ) ) {
  7. function jetpack_verification_validate( $verification_services_codes ) {
  8. foreach ( $verification_services_codes as $key => $code ) {
  9. // Parse html meta tag if it does not look like a valid code
  10. if ( ! preg_match( '/^[a-z0-9_-]+$/i', $code ) ) {
  11. $code = jetpack_verification_get_code( $code );
  12. }
  13. $code = esc_attr( trim( $code ) );
  14. // limit length to 100 chars.
  15. $code = substr( $code, 0, 100 );
  16. /**
  17. * Fire after each Verification code was validated.
  18. *
  19. * @module verification-tools
  20. *
  21. * @since 3.0.0
  22. *
  23. * @param string $key Verification service name.
  24. * @param string $code Verification service code provided in field in the Tools menu.
  25. */
  26. do_action( 'jetpack_site_verification_validate', $key, $code );
  27. $verification_services_codes[ $key ] = $code;
  28. }
  29. return $verification_services_codes;
  30. }
  31. }
  32. if ( ! function_exists( 'jetpack_verification_get_code' ) ) {
  33. function jetpack_verification_get_code( $code ) {
  34. $pattern = '/content=["\']?([^"\' ]*)["\' ]/is';
  35. preg_match( $pattern, $code, $match );
  36. if ( $match ) {
  37. return urldecode( $match[1] );
  38. } else {
  39. return false;
  40. }
  41. }
  42. }