/** * Returns the singleton instance of the class. * * @since 1.0.0 * * @return object The Envira_Gallery_Metaboxes_Lite object. */ public static function get_instance() { if (!isset(self::$instance) && !self::$instance instanceof Envira_Gallery_Metaboxes_Lite) { self::$instance = new Envira_Gallery_Metaboxes_Lite(); } return self::$instance; }
/** * Refreshes the DOM view for a gallery. * * @since 1.0.0 */ function envira_gallery_lite_ajax_refresh() { // Run a security check first. check_ajax_referer('envira-gallery-refresh', 'nonce'); // Prepare variables. $post_id = absint($_POST['post_id']); $gallery = ''; // Grab all gallery data. $gallery_data = get_post_meta($post_id, '_eg_gallery_data', true); // If there are no gallery items, don't do anything. if (empty($gallery_data) || empty($gallery_data['gallery'])) { echo json_encode(array('error' => true)); die; } // Loop through the data and build out the gallery view. foreach ((array) $gallery_data['gallery'] as $id => $data) { $gallery .= Envira_Gallery_Metaboxes_Lite::get_instance()->get_gallery_item($id, $data, $post_id); } echo json_encode(array('success' => $gallery)); die; }