예제 #1
0
 /**
  * Untrash a gallery when the gallery post type is untrashed.
  *
  * @since 1.0.0
  *
  * @param $id   The post ID being untrashed.
  * @return null Return early if no gallery is found.
  */
 public function untrash_gallery($id)
 {
     $gallery = get_post($id);
     // Flush necessary gallery caches to ensure untrashed galleries are showing.
     HW_Gallery_Common_Lite::get_instance()->flush_gallery_caches($id);
     // Return early if not an Envira gallery.
     if ('hw-gallery' !== $gallery->post_type) {
         return;
     }
     // Set the gallery status to inactive.
     $gallery_data = get_post_meta($id, '_eg_gallery_data', true);
     if (empty($gallery_data)) {
         return;
     }
     if (isset($gallery_data['status'])) {
         unset($gallery_data['status']);
     }
     update_post_meta($id, '_eg_gallery_data', $gallery_data);
 }
예제 #2
0
 /**
  * Returns the singleton instance of the class.
  *
  * @since 1.0.0
  *
  * @return object The HW_Gallery_Common_Lite object.
  */
 public static function get_instance()
 {
     if (!isset(self::$instance) && !self::$instance instanceof HW_Gallery_Common_Lite) {
         self::$instance = new HW_Gallery_Common_Lite();
     }
     return self::$instance;
 }
예제 #3
0
 /**
  * Helper method for retrieving title displays.
  *
  * @since 1.2.7
  *
  * @return array Array of title display data.
  */
 public function get_title_displays()
 {
     $instance = HW_Gallery_Common_Lite::get_instance();
     return $instance->get_title_displays();
 }
 /**
  * Helper method to retrieve the proper image src attribute based on gallery settings.
  *
  * @since 1.0.0
  *
  * @param int $id      The image attachment ID to use.
  * @param array $item  Gallery item data.
  * @param array $data  The gallery data to use for retrieval.
  * @param bool $mobile Whether or not to retrieve the mobile image.
  * @return string      The proper image src attribute for the image.
  */
 public function get_image_src($id, $item, $data, $mobile = false)
 {
     // Get the full image src. If it does not return the data we need, return the image link instead.
     $src = wp_get_attachment_image_src($id, 'full');
     $image = !empty($src[0]) ? $src[0] : false;
     if (!$image) {
         $image = !empty($item['src']) ? $item['src'] : false;
         if (!$image) {
             return apply_filters('hw_gallery_no_image_src', $item['link'], $id, $item, $data);
         }
     }
     // Generate the cropped image if necessary.
     $type = $mobile ? 'mobile' : 'crop';
     if (isset($data['config'][$type]) && $data['config'][$type]) {
         $common = HW_Gallery_Common_Lite::get_instance();
         $args = apply_filters('hw_gallery_crop_image_args', array('position' => 'c', 'width' => $this->get_config($type . '_width', $data), 'height' => $this->get_config($type . '_height', $data), 'quality' => 100, 'retina' => false));
         $cropped_image = $common->resize_image($image, $args['width'], $args['height'], true, $args['position'], $args['quality'], $args['retina']);
         // If there is an error, possibly output error message and return the default image src.
         if (is_wp_error($cropped_image)) {
             // If WP_DEBUG is enabled, and we're logged in, output an error to the user
             if (defined('WP_DEBUG') && WP_DEBUG && is_user_logged_in()) {
                 echo '<pre>Envira: Error occured resizing image (these messages are only displayed to logged in WordPress users):<br />';
                 echo 'Error: ' . $cropped_image->get_error_message() . '<br />';
                 echo 'Image: ' . $image . '<br />';
                 echo 'Args: ' . var_export($args, true) . '</pre>';
             }
             // Return the non-cropped image as a fallback.
             return apply_filters('hw_gallery_image_src', $src, $id, $item, $data);
         } else {
             return apply_filters('hw_gallery_image_src', array($cropped_image, $args['width'], $args['height']), $id, $item, $data);
         }
     } else {
         return apply_filters('hw_gallery_image_src', $src, $id, $item, $data);
     }
 }
예제 #5
0
/**
 * Saves the metadata for an image in a gallery.
 *
 * @since 1.0.0
 */
function hw_gallery_lite_ajax_save_meta()
{
    // Run a security check first.
    check_ajax_referer('hw-gallery-save-meta', 'nonce');
    // Prepare variables.
    $post_id = absint($_POST['post_id']);
    $attach_id = absint($_POST['attach_id']);
    $meta = $_POST['meta'];
    $gallery_data = get_post_meta($post_id, '_eg_gallery_data', true);
    if (isset($meta['title'])) {
        $gallery_data['gallery'][$attach_id]['title'] = trim($meta['title']);
    }
    if (isset($meta['alt'])) {
        $gallery_data['gallery'][$attach_id]['alt'] = trim(esc_html($meta['alt']));
    }
    if (isset($meta['link'])) {
        $gallery_data['gallery'][$attach_id]['link'] = esc_url($meta['link']);
    }
    // Allow filtering of meta before saving.
    $gallery_data = apply_filters('hw_gallery_ajax_save_meta', $gallery_data, $meta, $attach_id, $post_id);
    // Update the gallery data.
    update_post_meta($post_id, '_eg_gallery_data', $gallery_data);
    // Flush the gallery cache.
    HW_Gallery_Common_Lite::get_instance()->flush_gallery_caches($post_id);
    echo json_encode(true);
    die;
}
예제 #6
0
 /**
  * Helper method for retrieving config values.
  *
  * @since 1.0.0
  *
  * @param string $key The config key to retrieve.
  * @param array $data The gallery data to use for retrieval.
  * @return string     Key value on success, default if not set.
  */
 public function get_config($key, $data)
 {
     $instance = HW_Gallery_Common_Lite::get_instance();
     return isset($data['config'][$key]) ? $data['config'][$key] : $instance->get_config_default($key);
 }