class-opengraph-validator.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Indexables
  6. */
  7. /**
  8. * Class WPSEO_OpenGraph_Validator.
  9. */
  10. class WPSEO_OpenGraph_Validator implements WPSEO_Endpoint_Validator {
  11. /**
  12. * Validates the OpenGraph-related data.
  13. *
  14. * @param array $request_data The request data to validate.
  15. *
  16. * @return void
  17. *
  18. * @throws WPSEO_Invalid_Argument_Exception Thrown if one of the OpenGraph properties is of an invalid value type.
  19. */
  20. public function validate( $request_data ) {
  21. if ( WPSEO_Validator::key_exists( $request_data, 'og_title' ) && ! WPSEO_Validator::is_string( $request_data['og_title'] ) ) {
  22. throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['og_title'], 'og_title' );
  23. }
  24. if ( WPSEO_Validator::key_exists( $request_data, 'og_description' ) && ! WPSEO_Validator::is_string( $request_data['og_description'] ) ) {
  25. throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['og_description'], 'og_description' );
  26. }
  27. if ( WPSEO_Validator::key_exists( $request_data, 'og_image' ) && ! WPSEO_Validator::is_string( $request_data['og_image'] ) ) {
  28. throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['og_image'], 'og_image' );
  29. }
  30. }
  31. }