/**
  * Set our transform hooks
  *
  */
 public function set_hooks()
 {
     $hook_prefix = photonfill_hook_prefix();
     // Override photon args
     add_filter($hook_prefix . '_photon_image_downsize_array', array($this, 'set_photon_args'), 5, 2);
     add_filter($hook_prefix . '_photon_image_downsize_string', array($this, 'set_photon_args'), 5, 2);
     // Transform our photon url
     add_filter($hook_prefix . '_photon_pre_args', array($this, 'transform_photon_url'), 5, 3);
 }
 /**
  * Set our transform hooks
  *
  */
 public function set_hooks()
 {
     $hook_prefix = photonfill_hook_prefix();
     // Override photon args
     add_filter($hook_prefix . '_photon_image_downsize_array', array($this, 'set_photon_args'), 5, 2);
     add_filter($hook_prefix . '_photon_image_downsize_string', array($this, 'set_photon_args'), 5, 2);
     // If we're using the photonfill_bypass_image_downsize, we skip downsize, and now need to
     // ensure the photon args are being set (but with a lower priority)
     if (apply_filters('photonfill_bypass_image_downsize', false)) {
         add_filter($hook_prefix . '_photon_pre_args', array($this, 'set_photon_args'), 4, 3);
     }
     // Transform our photon url
     add_filter($hook_prefix . '_photon_pre_args', array($this, 'transform_photon_url'), 5, 3);
 }
 /**
  * Manipulate our img src
  * @param int
  * @param array. This should always be an array of breakpoint width and height
  * @param boolean. Should this be the default srcset for the img element.
  */
 private function get_img_src($attachment_id, $size, $default = false)
 {
     if (!empty($attachment_id)) {
         if (empty($size)) {
             $attachment_meta = wp_get_attachment_metadata($attachment_id, true);
             $attachment_width = !empty($attachment_meta['width']) ? $attachment_meta['width'] : 0;
             $attachment_height = !empty($attachment_meta['height']) ? $attachment_meta['height'] : 0;
             $size = array($attachment_width, $attachment_height);
         }
         $width = $size[0];
         $height = $size[1];
         $img_src = array('width' => $width, 'height' => $height, 'default' => $default);
         // A hack for the fact that photon doesn't work with wp_ajax calls due to is_admin forcing image downsizing to return the original image
         if (is_admin()) {
             // Support jetpack photon and my_photon
             $photon_url_function = photonfill_hook_prefix() . '_photon_url';
             $attachment_src = wp_get_attachment_url($attachment_id);
             $img_src['url'] = $photon_url_function($attachment_src, array('attachment_id' => $attachment_id, 'width' => $img_src['width'], 'height' => $img_src['height']));
             $img_src['url2x'] = $photon_url_function($attachment_src, array('attachment_id' => $attachment_id, 'width' => absint($img_src['width'] * 2), 'height' => absint($img_src['height'] * 2)));
         } else {
             $attachment_src = wp_get_attachment_image_src($attachment_id, $size);
             $attachment_src_2x = wp_get_attachment_image_src($attachment_id, array(absint($width) * 2, absint($height) * 2));
             $img_src['url'] = $attachment_src[0];
             $img_src['url2x'] = $attachment_src_2x[0];
         }
         return $img_src;
     }
     return false;
 }