AboutUs.class.php
3 years ago
BackwardsCompatibility.class.php
4 years ago
Blocks.class.php
4 years ago
CustomPostTypes.class.php
1 year ago
Dashboard.class.php
3 years ago
DeactivationSurvey.class.php
4 years ago
Helper.class.php
4 years ago
InstallationWalkthrough.class.php
4 years ago
Permissions.class.php
4 years ago
ReviewAsk.class.php
4 years ago
Settings.class.php
1 year ago
Widgets.class.php
4 years ago
WooCommerceIntegration.class.php
4 years ago
template-functions.php
1 year ago
InstallationWalkthrough.class.php
357 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class to handle everything related to the walk-through that runs on plugin activation |
| 5 | */ |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) |
| 8 | exit; |
| 9 | |
| 10 | class ewdusInstallationWalkthrough { |
| 11 | |
| 12 | public function __construct() { |
| 13 | add_action( 'admin_menu', array( $this, 'register_install_screen' ) ); |
| 14 | add_action( 'admin_head', array( $this, 'hide_install_screen_menu_item' ) ); |
| 15 | add_action( 'admin_init', array( $this, 'redirect' ), 9999 ); |
| 16 | |
| 17 | add_action( 'admin_head', array( $this, 'admin_enqueue' ) ); |
| 18 | |
| 19 | add_action( 'wp_ajax_us_welcome_add_slide', array( $this, 'create_slide' ) ); |
| 20 | add_action( 'wp_ajax_us_welcome_add_slider_page', array( $this, 'add_slider_page' ) ); |
| 21 | add_action( 'wp_ajax_us_welcome_set_options', array( $this, 'set_options' ) ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * On activation, redirect the user if they haven't used the plugin before |
| 26 | * @since 2.0.0 |
| 27 | */ |
| 28 | public function redirect() { |
| 29 | if ( ! get_transient( 'ewd-us-getting-started' ) ) |
| 30 | return; |
| 31 | |
| 32 | delete_transient( 'ewd-us-getting-started' ); |
| 33 | |
| 34 | if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) |
| 35 | return; |
| 36 | |
| 37 | if ( ! empty( get_posts( array( 'post_type' => EWD_US_SLIDER_POST_TYPE ) ) ) ) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | wp_safe_redirect( admin_url( 'index.php?page=ewd-us-getting-started' ) ); |
| 42 | exit; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Create the installation admin page |
| 47 | * @since 2.0.0 |
| 48 | */ |
| 49 | public function register_install_screen() { |
| 50 | |
| 51 | add_dashboard_page( |
| 52 | esc_html__( 'Ultimate Slider - Welcome!', 'ultimate-slider' ), |
| 53 | esc_html__( 'Ultimate Slider - Welcome!', 'ultimate-slider' ), |
| 54 | 'manage_options', |
| 55 | 'ewd-us-getting-started', |
| 56 | array( $this, 'display_install_screen' ) |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Hide the installation admin page from the WordPress sidebar menu |
| 62 | * @since 2.0.0 |
| 63 | */ |
| 64 | public function hide_install_screen_menu_item() { |
| 65 | |
| 66 | remove_submenu_page( 'index.php', 'ewd-us-getting-started' ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Create a new slide (image, title, description) |
| 71 | * @since 2.0.0 |
| 72 | */ |
| 73 | public function create_slide() { |
| 74 | |
| 75 | // Authenticate request |
| 76 | if ( ! check_ajax_referer( 'ewd-us-getting-started', 'nonce' ) ) { |
| 77 | |
| 78 | ewdusHelper::admin_nopriv_ajax(); |
| 79 | } |
| 80 | |
| 81 | $post_id = wp_insert_post( array( |
| 82 | 'post_title' => isset( $_POST['slide_title'] ) ? sanitize_text_field( $_POST['slide_title'] ) : '', |
| 83 | 'post_content' => isset( $_POST['slide_description'] ) ? '<!-- wp:paragraph --><p>' . sanitize_textarea_field( $_POST['slide_description'] ) . '</p><!-- /wp:paragraph -->' : '', |
| 84 | 'post_status' => 'publish', |
| 85 | 'post_type' => 'ultimate_slider' |
| 86 | ) ); |
| 87 | |
| 88 | if ( $post_id ) { |
| 89 | |
| 90 | update_post_meta( $post_id, "EWD_US_Slide_Order", 999 ); |
| 91 | |
| 92 | $attachment_id = isset( $_POST['slide_image'] ) ? attachment_url_to_postid( esc_url_raw( $_POST['slide_image'] ) ) : false; |
| 93 | if ( $attachment_id ) { |
| 94 | |
| 95 | set_post_thumbnail( $post_id, $attachment_id ); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | exit(); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Add in a page with the slider shortcode |
| 104 | * @since 2.0.0 |
| 105 | */ |
| 106 | public function add_slider_page() { |
| 107 | |
| 108 | // Authenticate request |
| 109 | if ( ! check_ajax_referer( 'ewd-us-getting-started', 'nonce' ) ) { |
| 110 | |
| 111 | ewdusHelper::admin_nopriv_ajax(); |
| 112 | } |
| 113 | |
| 114 | $slider_page = wp_insert_post( array( |
| 115 | 'post_title' => isset( $_POST['slider_page_title'] ) ? sanitize_text_field( $_POST['slider_page_title'] ) : '', |
| 116 | 'post_content' => '<!-- wp:paragraph --><p> [ultimate-slider] </p><!-- /wp:paragraph -->', |
| 117 | 'post_status' => 'publish', |
| 118 | 'post_type' => 'page' |
| 119 | ) ); |
| 120 | |
| 121 | exit(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Set a number of key options selected during the walk-through process |
| 126 | * @since 2.0.0 |
| 127 | */ |
| 128 | public function set_options() { |
| 129 | |
| 130 | // Authenticate request |
| 131 | if ( ! check_ajax_referer( 'ewd-us-getting-started', 'nonce' ) ) { |
| 132 | |
| 133 | ewdusHelper::admin_nopriv_ajax(); |
| 134 | } |
| 135 | |
| 136 | $ewd_us_options = get_option( 'ewd-us-settings' ); |
| 137 | |
| 138 | if ( isset( $_POST['autoplay_slideshow'] ) ) { $ewd_us_options['autoplay-slideshow'] = $_POST['autoplay_slideshow'] == 'true' ? 1 : 0; } |
| 139 | if ( isset( $_POST['aspect_ratio'] ) ) { $ewd_us_options['aspect-ratio'] = sanitize_text_field( $_POST['aspect_ratio'] ); } |
| 140 | if ( isset( $_POST['carousel'] ) ) { $ewd_us_options['carousel'] = $_POST['carousel'] == 'true' ? 1 : 0; } |
| 141 | if ( isset( $_POST['slide_indicators'] ) ) { $ewd_us_options['slide-indicators'] = sanitize_text_field( $_POST['slide_indicators'] ); } |
| 142 | if ( isset( $_POST['timer_bar'] ) ) { $ewd_us_options['timer-bar'] = sanitize_text_field( $_POST['timer_bar'] ); } |
| 143 | |
| 144 | update_option( 'ewd-us-settings', $ewd_us_options ); |
| 145 | |
| 146 | exit(); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Enqueue the admin assets necessary to run the walk-through and display it nicely |
| 151 | * @since 2.0.0 |
| 152 | */ |
| 153 | public function admin_enqueue() { |
| 154 | |
| 155 | if ( ! isset( $_GET['page'] ) or $_GET['page'] != 'ewd-us-getting-started' ) { return; } |
| 156 | |
| 157 | wp_enqueue_style( 'ewd-us-admin-css', EWD_US_PLUGIN_URL . '/assets/css/admin.css', array(), EWD_US_VERSION ); |
| 158 | wp_enqueue_style( 'ewd-us-sap-admin-css', EWD_US_PLUGIN_URL . '/lib/simple-admin-pages/css/admin.css', array(), EWD_US_VERSION ); |
| 159 | wp_enqueue_style( 'ewd-us-welcome-screen', EWD_US_PLUGIN_URL . '/assets/css/ewd-us-welcome-screen.css', array(), EWD_US_VERSION ); |
| 160 | wp_enqueue_style( 'ewd-us-admin-settings-css', EWD_US_PLUGIN_URL . '/lib/simple-admin-pages/css/admin-settings.css', array(), EWD_US_VERSION ); |
| 161 | |
| 162 | wp_enqueue_script( 'ewd-us-getting-started', EWD_US_PLUGIN_URL . '/assets/js/ewd-us-welcome-screen.js', array( 'jquery' ), EWD_US_VERSION ); |
| 163 | wp_enqueue_script( 'ewd-us-admin-settings-js', EWD_US_PLUGIN_URL . '/lib/simple-admin-pages/js/admin-settings.js', array( 'jquery' ), EWD_US_VERSION ); |
| 164 | wp_enqueue_script( 'ewd-us-admin-spectrum-js', EWD_US_PLUGIN_URL . '/lib/simple-admin-pages/js/spectrum.js', array( 'jquery' ), EWD_US_VERSION ); |
| 165 | |
| 166 | wp_localize_script( |
| 167 | 'ewd-us-getting-started', |
| 168 | 'ewd_us_getting_started', |
| 169 | array( |
| 170 | 'nonce' => wp_create_nonce( 'ewd-us-getting-started' ) |
| 171 | ) |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Output the HTML of the walk-through screen |
| 177 | * @since 2.0.0 |
| 178 | */ |
| 179 | public function display_install_screen() { ?> |
| 180 | |
| 181 | <div class='ewd-us-welcome-screen'> |
| 182 | |
| 183 | <div class='ewd-us-welcome-screen-header'> |
| 184 | <h1><?php _e( 'Welcome to the Ultimate Slider Plugin', 'ultimate-slider' ); ?></h1> |
| 185 | <p><?php _e( 'Thanks for choosing the Ultimate Slider! The following will help you get started with the plugin, by choosing which images the slider should be displayed for as well as the look of the slider.', 'ultimate-slider' ); ?></p> |
| 186 | </div> |
| 187 | |
| 188 | <div class='ewd-us-welcome-screen-box ewd-us-welcome-screen-add_slides ewd-us-welcome-screen-open' data-screen='add_slides'> |
| 189 | <h2><?php _e( '1. Add Slides', 'ultimate-slider' ); ?></h2> |
| 190 | <div class='ewd-us-welcome-screen-box-content'> |
| 191 | <table class='form-table ewd-us-welcome-screen-created-slides'> |
| 192 | <tr class='ewd-us-welcome-screen-add-slide-image ewd-us-welcome-screen-box-content-divs'> |
| 193 | <th scope='row'><?php _e( 'Slide Image', 'ultimate-slider' ); ?></th> |
| 194 | <td class='ewd-us-welcome-screen-option ewd-us-welcome-screen-image-preview-container'> |
| 195 | <div class='ewd-us-hidden ewd-us-welcome-screen-image-preview'> |
| 196 | <img> |
| 197 | </div> |
| 198 | <input type='hidden' name='slide_image_url'> |
| 199 | <input id="welcome_slide_image_button" class="button" type="button" value="Upload Image"> |
| 200 | </td> |
| 201 | </tr> |
| 202 | <tr class='ewd-us-welcome-screen-add-slide-title ewd-us-welcome-screen-box-content-divs'> |
| 203 | <th scope='row'><?php _e( 'Slide Title', 'ultimate-slider' ); ?></th> |
| 204 | <td class='ewd-us-welcome-screen-option'> |
| 205 | <input type='text'> |
| 206 | </td> |
| 207 | </tr> |
| 208 | <tr class='ewd-us-welcome-screen-add-slide-description ewd-us-welcome-screen-box-content-divs'> |
| 209 | <th scope='row'><?php _e( 'Description', 'ultimate-slider' ); ?></th> |
| 210 | <td class='ewd-us-welcome-screen-option'> |
| 211 | <textarea></textarea> |
| 212 | </td> |
| 213 | </tr> |
| 214 | <tr> |
| 215 | <th scope='row'></th> |
| 216 | <td> |
| 217 | <div class='ewd-us-welcome-screen-add-slide-button'><?php _e( 'Add Slide', 'ultimate-slider' ); ?></div> |
| 218 | </td> |
| 219 | </tr> |
| 220 | <tr></tr> |
| 221 | <tr> |
| 222 | <td colspan="2"> |
| 223 | <h3><?php _e( 'Created Slides', 'ultimate-slider' ); ?></h3> |
| 224 | <table class="ewd-us-welcome-screen-show-created-slides"> |
| 225 | <tr> |
| 226 | <th class="ewd-us-welcome-screen-show-created-slides-image"><?php _e( 'Image', 'ultimate-slider' ); ?></th> |
| 227 | <th class="ewd-us-welcome-screen-show-created-slides-title"><?php _e( 'Name', 'ultimate-slider' ); ?></th> |
| 228 | <th class="ewd-us-welcome-screen-show-created-slides-description"><?php _e( 'Description', 'ultimate-slider' ); ?></th> |
| 229 | </tr> |
| 230 | </table> |
| 231 | </td> |
| 232 | </tr> |
| 233 | </table> |
| 234 | |
| 235 | <div class="ewd-us-welcome-clear"></div> |
| 236 | <div class='ewd-us-welcome-screen-next-button' data-nextaction='slider_page'><?php _e( 'Next Step', 'ultimate-slider' ); ?></div> |
| 237 | <div class='clear'></div> |
| 238 | </div> |
| 239 | </div> |
| 240 | |
| 241 | <div class='ewd-us-welcome-screen-box ewd-us-welcome-screen-slider_page' data-screen='slider_page'> |
| 242 | <h2><?php _e( '2. Add a Slider Page', 'ultimate-slider' ); ?></h2> |
| 243 | <div class='ewd-us-welcome-screen-box-content'> |
| 244 | <p><?php _e( 'You can create a dedicated page for your slider below, or skip this step and add your slider to a page you\'ve already created manually.', 'ultimate-slider' ); ?></p> |
| 245 | <table class='form-table ewd-us-welcome-screen-menu-page'> |
| 246 | <tr class='ewd-us-welcome-screen-add-slider-page-name ewd-us-welcome-screen-box-content-divs'> |
| 247 | <th scope='row'><?php _e( 'Page Title', 'ultimate-slider' ); ?></th> |
| 248 | <td class='ewd-us-welcome-screen-option'> |
| 249 | <input type='text' value='Slider'> |
| 250 | </td> |
| 251 | </tr> |
| 252 | <tr> |
| 253 | <th scope='row'></th> |
| 254 | <td> |
| 255 | <div class='ewd-us-welcome-screen-add-slider-page-button' data-nextaction='options'><?php _e( 'Create Page', 'ultimate-slider' ); ?></div> |
| 256 | </td> |
| 257 | </tr> |
| 258 | </table> |
| 259 | |
| 260 | <div class="ewd-us-welcome-clear"></div> |
| 261 | <div class='ewd-us-welcome-screen-next-button' data-nextaction='options'><?php _e( 'Next Step', 'ultimate-slider' ); ?></div> |
| 262 | <div class='ewd-us-welcome-screen-previous-button' data-previousaction='add_slides'><?php _e( 'Previous Step', 'ultimate-slider' ); ?></div> |
| 263 | <div class='clear'></div> |
| 264 | </div> |
| 265 | </div> |
| 266 | |
| 267 | <div class='ewd-us-welcome-screen-box ewd-us-welcome-screen-options' data-screen='options'> |
| 268 | <h2><?php _e( '3. Key Options', 'ultimate-slider' ); ?></h2> |
| 269 | <div class='ewd-us-welcome-screen-box-content'> |
| 270 | <table class="form-table"> |
| 271 | <tr> |
| 272 | <th scope='row'><?php _e( 'Autoplay Slides', 'ultimate-slider' ); ?></th> |
| 273 | <td class='ewd-us-welcome-screen-option'> |
| 274 | <fieldset> |
| 275 | <div class="sap-admin-hide-radios"> |
| 276 | <input type='checkbox' name='autoplay_slideshow' value='1'> |
| 277 | </div> |
| 278 | <label class="sap-admin-switch"> |
| 279 | <input type="checkbox" class="sap-admin-option-toggle" data-inputname="autoplay_slideshow" checked="checked"> |
| 280 | <span class="sap-admin-switch-slider round"></span> |
| 281 | </label> |
| 282 | </fieldset> |
| 283 | </td> |
| 284 | </tr> |
| 285 | |
| 286 | <tr> |
| 287 | <th scope='row'><?php _e( 'Show Timer Bar', 'ultimate-slider' ); ?></th> |
| 288 | <td class='ewd-us-welcome-screen-option'> |
| 289 | <fieldset> |
| 290 | <label title='Top' class='sap-admin-input-container'><input type='radio' name='timer_bar' value='top'><span class='sap-admin-radio-button'></span> <span><?php _e( 'Top', 'ultimate-slider' )?></span></label><br> |
| 291 | <label title='Bottom' class='sap-admin-input-container'><input type='radio' name='timer_bar' value='bottom' checked><span class='sap-admin-radio-button'></span> <span><?php _e( 'Bottom', 'ultimate-slider' )?></span></label><br> |
| 292 | <label title='Off' class='sap-admin-input-container'><input type='radio' name='timer_bar' value='off'><span class='sap-admin-radio-button'></span> <span><?php _e( 'Off', 'ultimate-slider' )?></span></label><br> |
| 293 | </fieldset> |
| 294 | </td> |
| 295 | </tr> |
| 296 | |
| 297 | <tr> |
| 298 | <th scope='row'><?php _e( 'Carousel Mode', 'ultimate-slider' ); ?></th> |
| 299 | <td class='ewd-us-welcome-screen-option'> |
| 300 | <fieldset> |
| 301 | <div class="sap-admin-hide-radios"> |
| 302 | <input type='checkbox' name='carousel' value='1'> |
| 303 | </div> |
| 304 | <label class="sap-admin-switch"> |
| 305 | <input type="checkbox" class="sap-admin-option-toggle" data-inputname="carousel" checked="checked"> |
| 306 | <span class="sap-admin-switch-slider round"></span> |
| 307 | </label> |
| 308 | </fieldset> |
| 309 | </td> |
| 310 | </tr> |
| 311 | |
| 312 | <tr> |
| 313 | <th scope='row'><?php _e( 'Aspect Ratio', 'ultimate-slider' ); ?></th> |
| 314 | <td class='ewd-us-welcome-screen-option'> |
| 315 | <select name='aspect_ratio'> |
| 316 | <option value='3_1'>3:1</option> |
| 317 | <option value='16_7' selected>16:7</option> |
| 318 | <option value='2_1'>2:1</option> |
| 319 | <option value='16_9'>16:9</option> |
| 320 | <option value='3_2'>3:2</option> |
| 321 | <option value='4_3'>4:3</option> |
| 322 | <option value='1_1'>1:1</option> |
| 323 | </select> |
| 324 | </td> |
| 325 | </tr> |
| 326 | |
| 327 | <tr> |
| 328 | <th scope='row'><?php _e( 'Slide Indicators', 'ultimate-slider' ); ?></th> |
| 329 | <td class='ewd-us-welcome-screen-option'> |
| 330 | <fieldset> |
| 331 | <label title='None' class='sap-admin-input-container'><input type='radio' name='slide_indicators' value='none'><span class='sap-admin-radio-button'></span> <span><?php _e( 'None', 'ultimate-slider' )?></span></label><br> |
| 332 | <label title='Dots' class='sap-admin-input-container'><input type='radio' name='slide_indicators' value='dots' checked><span class='sap-admin-radio-button'></span> <span><?php _e( 'Dots', 'ultimate-slider' )?></span></label><br> |
| 333 | <label title='Thumbnails' class='sap-admin-input-container'><input type='radio' name='slide_indicators' value='thumbnails'><span class='sap-admin-radio-button'></span> <span><?php _e( 'Thumbnails', 'ultimate-slider' )?></span></label><br> |
| 334 | <label title='Side Thumbnails' class='sap-admin-input-container'><input type='radio' name='slide_indicators' value='sidethumbnails'><span class='sap-admin-radio-button'></span> <span><?php _e( 'Side Thumbnails', 'ultimate-slider' )?></span></label><br> |
| 335 | </fieldset> |
| 336 | </td> |
| 337 | </tr> |
| 338 | </table> |
| 339 | |
| 340 | <div class='ewd-us-welcome-screen-save-options-button'><?php _e( 'Save Options', 'ultimate-slider' ); ?></div> |
| 341 | <div class="ewd-us-welcome-clear"></div> |
| 342 | <div class='ewd-us-welcome-screen-previous-button' data-previousaction='add_slider'><?php _e( 'Previous Step', 'ultimate-slider' ); ?></div> |
| 343 | <div class='ewd-us-welcome-screen-finish-button'><a href='admin.php?page=ewd-us-settings'><?php _e('Finish', 'ultimate-slider'); ?></a></div> |
| 344 | <div class='clear'></div> |
| 345 | </div> |
| 346 | </div> |
| 347 | |
| 348 | <div class='ewd-us-welcome-screen-skip-container'> |
| 349 | <a href='admin.php?page=ewd-us-settings'><div class='ewd-us-welcome-screen-skip-button'><?php _e( 'Skip Setup', 'ultimate-slider' ); ?></div></a> |
| 350 | </div> |
| 351 | </div> |
| 352 | |
| 353 | <?php } |
| 354 | } |
| 355 | |
| 356 | |
| 357 | ?> |