/** * Updates the plugin to v2.2.1. * * @param int $version The current plugin version * @return void */ public function migrate_to_221($version) { // Continue if upgrading from a lower version if (version_compare($version, '2.2.1', '<')) { // Get the settings $settings = get_option('easingslider_settings'); // Bail if we have no settings or the setting we need if (!$settings or !isset($settings->image_resizing)) { return; } // Get all sliders $sliders = ES_Slider::all(); // Migrate the "Image Resizing" option foreach ($sliders as $slider) { $slider->dimensions->image_resizing = $settings->image_resizing; $slider->save(); } // Unset the settings option unset($settings->image_resizing); // Update the settings update_option('easingslider_settings', $settings); } }
/** * Widget settings form * * @param array $instance The widget instance */ public function form($instance) { // Get all of the sliders $sliders = ES_Slider::all(); // Print the settings ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', 'easingslider'); ?> </label> <input type="text" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " class="widefat" value="<?php if (isset($instance['title'])) { echo esc_attr($instance['title']); } ?> "> </p> <p> <label for="<?php echo $this->get_field_id('id'); ?> "><?php _e('Select Slider:', 'easingslider'); ?> </label> <select id="<?php echo $this->get_field_id('id'); ?> " name="<?php echo $this->get_field_name('id'); ?> " class="widefat"> <option value="-1"><?php _e('— Select —', 'easingslider'); ?> </option> <?php foreach ($sliders as $slider) { ?> <option value="<?php echo esc_attr($slider->ID); ?> " <?php if (isset($instance['id'])) { selected($instance['id'], $slider->ID); } ?> ><?php echo esc_html($slider->post_title) . sprintf(__(' (ID #%s)', 'easingslider'), $slider->ID); ?> </option> <?php } ?> </select> </p> <?php }
/** * Displays the view * * @return void */ public function display_view() { // Get the current page $page = sanitize_key($_GET['page']); // We need Easing Slider to be loaded by now, so continue if it has. if (class_exists('ES_Slider')) { // Get all sliders $sliders = ES_Slider::all(); // If we have no sliders, tell the user. if (empty($sliders)) { wp_die(__('You need to create some sliders to use the customizer.', 'easingslider')); exit; } // Get the specified slider, or pick the first one. if (isset($_GET['edit'])) { // Get and validate the ID, protecting against XSS attacks $id = sanitize_key($_GET['edit']); // Get the slider $slider = ES_Slider::find($id); } else { // Get the first slider $slider = array_shift(array_values($sliders)); } // Display the view require plugin_dir_path(dirname(__FILE__)) . 'partials/customizer.php'; } }
/** * Uninstall * * @return void */ public static function do_uninstall() { // Get the settings $settings = get_option('easingslider_settings'); // If enabled, remove the plugin data if ($settings->remove_data) { // Delete all of the sliders foreach (ES_Slider::all() as $slider) { ES_Slider::delete($slider->ID); } // Delete options delete_option('easingslider_version'); delete_option('easingslider_settings'); // Remove data hook do_action('easingslider_remove_data'); } // Trigger hooks do_action('easingslider_uninstall'); }
/** * Prints the "Add Slider" media thickbox * * @return void */ public function print_media_thickbox() { global $pagenow; // Bail if not in the post/page editor if (('post.php' or 'post-new.php') != $pagenow) { return; } // Get all sliders $sliders = ES_Slider::all(); // Display the thickbox ?> <style type="text/css"> .section { padding: 15px 15px 0 15px; } </style> <script type="text/javascript"> /** * Sends a shortcode to the post/page editor */ function insertSlider() { // Get the slider ID var id = jQuery('#slider').val(); // Display alert and bail if no slideshow was selected if ( '-1' === id ) { return alert("<?php _e('Please select a slider', 'easingslider'); ?> "); } // Send shortcode to editor send_to_editor('[easingslider id="'+ id +'"]'); // Close thickbox tb_remove(); } </script> <div id="select-slider" style="display: none;"> <div class="section"> <h2><?php _e('Add a slider', 'easingslider'); ?> </h2> <span><?php _e('Select a slider to insert from the box below.', 'easingslider'); ?> </span> </div> <div class="section"> <select name="slider" id="slider"> <option value="-1"><?php _e('Select a slider', 'easingslider'); ?> </option> <?php foreach ($sliders as $slider) { echo "<option value=\"{$slider->ID}\">{$slider->post_title} (ID #{$slider->ID})</option>"; } ?> </select> </div> <div class="section"> <button id="insert-slider" class="button-primary" onClick="insertSlider();"><?php _e('Insert Slider', 'easingslider'); ?> </button> <button id="close-slider-thickbox" class="button-secondary" style="margin-left: 5px;" onClick="tb_remove();"><?php _e('Close', 'easingslider'); ?> </a> </div> </div> <?php }