/** * 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. Envira_Gallery_Common_Lite::get_instance()->flush_gallery_caches($id); // Return early if not an Envira gallery. if ('envira' !== $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); }
/** * Returns the singleton instance of the class. * * @since 1.0.0 * * @return object The Envira_Gallery_Common_Lite object. */ public static function get_instance() { if (!isset(self::$instance) && !self::$instance instanceof Envira_Gallery_Common_Lite) { self::$instance = new Envira_Gallery_Common_Lite(); } return self::$instance; }
/** * Saves the metadata for an image in a gallery. * * @since 1.0.0 */ function envira_gallery_lite_ajax_save_meta() { // Run a security check first. check_ajax_referer('envira-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('envira_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. Envira_Gallery_Common_Lite::get_instance()->flush_gallery_caches($post_id); echo json_encode(true); die; }
/** * Helper method for retrieving title displays. * * @since 1.2.7 * * @return array Array of title display data. */ public function get_title_displays() { $instance = Envira_Gallery_Common_Lite::get_instance(); return $instance->get_title_displays(); }
/** * 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 = Envira_Gallery_Common_Lite::get_instance(); return isset($data['config'][$key]) ? $data['config'][$key] : $instance->get_config_default($key); }