jetpack_photon_parse_wpcom_query_args

The Jetpack by WordPress.com jetpack photon parse wpcom query args function.

Description

jetpack_photon_parse_wpcom_query_args( $args, $image_url ); 

Parameters (2)

0. $args
The args.
1. $image_url
The image url.

Usage

  1. if ( !function_exists( 'jetpack_photon_parse_wpcom_query_args' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/functions.photon.php'; 
  3.  
  4. // The args. 
  5. $args = null; 
  6.  
  7. // The image url. 
  8. $image_url = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = jetpack_photon_parse_wpcom_query_args($args, $image_url); 
  12.  

Defined (1)

The function is defined in the following location(s).

/functions.photon.php  
  1. function jetpack_photon_parse_wpcom_query_args( $args, $image_url ) { 
  2. $parsed_url = @parse_url( $image_url ); 
  3.  
  4. if ( ! $parsed_url ) 
  5. return $args; 
  6.  
  7. $image_url_parts = wp_parse_args( $parsed_url, array( 
  8. 'host' => '',  
  9. 'query' => '' 
  10. ) ); 
  11.  
  12. if ( '.files.wordpress.com' != substr( $image_url_parts['host'], -20 ) ) 
  13. return $args; 
  14.  
  15. if ( empty( $image_url_parts['query'] ) ) 
  16. return $args; 
  17.  
  18. $wpcom_args = wp_parse_args( $image_url_parts['query'] ); 
  19.  
  20. if ( empty( $wpcom_args['w'] ) || empty( $wpcom_args['h'] ) ) 
  21. return $args; 
  22.  
  23. // Keep the crop by using "resize" 
  24. if ( ! empty( $wpcom_args['crop'] ) ) { 
  25. if ( is_array( $args ) ) { 
  26. $args = array_merge( array( 'resize' => array( $wpcom_args['w'], $wpcom_args['h'] ) ), $args ); 
  27. } else { 
  28. $args = 'resize=' . rawurlencode( absint( $wpcom_args['w'] ) . ', ' . absint( $wpcom_args['h'] ) ) . '&' . $args; 
  29. } else { 
  30. if ( is_array( $args ) ) { 
  31. $args = array_merge( array( 'fit' => array( $wpcom_args['w'], $wpcom_args['h'] ) ), $args ); 
  32. } else { 
  33. $args = 'fit=' . rawurlencode( absint( $wpcom_args['w'] ) . ', ' . absint( $wpcom_args['h'] ) ) . '&' . $args; 
  34.  
  35. return $args;