index.php
2 years ago
metaboxes.php
2 years ago
post-type.php
2 years ago
settings.php
2 years ago
shortcode.php
2 years ago
settings.php
397 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Author : DeipGroup |
| 5 | * Date: 8/11/2016 |
| 6 | * Time: 4:15 PM |
| 7 | * |
| 8 | * @package dflip |
| 9 | * |
| 10 | * @since dflip 1.2 |
| 11 | */ |
| 12 | class DFlip_Settings { |
| 13 | |
| 14 | /** |
| 15 | * Holds the singleton class object. |
| 16 | * |
| 17 | * @since 1.2.0 |
| 18 | * |
| 19 | * @var object |
| 20 | */ |
| 21 | public static $instance; |
| 22 | |
| 23 | public $hook; |
| 24 | |
| 25 | /** |
| 26 | * Holds the base DFlip class object. |
| 27 | * |
| 28 | * @since 1.2.0 |
| 29 | * |
| 30 | * @var object |
| 31 | */ |
| 32 | public $base; |
| 33 | |
| 34 | /** |
| 35 | * Holds the base DFlip class fields. |
| 36 | * |
| 37 | * @since 1.2.0 |
| 38 | * |
| 39 | * @var object |
| 40 | */ |
| 41 | public $fields; |
| 42 | |
| 43 | /** |
| 44 | * Primary class constructor. |
| 45 | * |
| 46 | * @since 1.2.0 |
| 47 | */ |
| 48 | public function __construct() { |
| 49 | |
| 50 | // Load the base class object. |
| 51 | $this->base = DFlip::get_instance(); |
| 52 | |
| 53 | add_action( 'admin_menu', array( $this, 'settings_menu' ) ); |
| 54 | |
| 55 | $this->fields = array_merge( array(), $this->base->defaults ); |
| 56 | |
| 57 | foreach ( $this->fields as $key => $value ) { |
| 58 | |
| 59 | if ( isset( $value['choices'] ) && is_array( $value['choices'] ) && isset( $value['choices']['global'] ) ) { |
| 60 | unset( $this->fields[ $key ]['choices']['global'] ); |
| 61 | } |
| 62 | |
| 63 | } |
| 64 | |
| 65 | // Load the metabox hooks and filters. |
| 66 | // add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 100); |
| 67 | |
| 68 | // Add action to save metabox config options. |
| 69 | // add_action('save_post', array($this, 'save_meta_boxes'), 10, 2); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Creates menu for the settings page |
| 74 | * |
| 75 | * @since 1.2 |
| 76 | */ |
| 77 | public function settings_menu() { |
| 78 | |
| 79 | $this->hook = add_submenu_page( 'edit.php?post_type=dflip', __( 'dFlip Global Settings', '3d-flipbook-dflip-lite' ), __( 'Global Settings', '3d-flipbook-dflip-lite' ), 'manage_options', $this->base->plugin_slug . '-settings', |
| 80 | array( $this, 'settings_page' ) ); |
| 81 | |
| 82 | //The resulting page's hook_suffix, or false if the user does not have the capability required. |
| 83 | if ( $this->hook ) { |
| 84 | add_action( 'load-' . $this->hook, array( $this, 'update_settings' ) ); |
| 85 | // Load metabox assets. |
| 86 | add_action( 'load-' . $this->hook, array( $this, 'hook_page_assets' ) ); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Callback to create the settings page |
| 92 | * |
| 93 | * @since 1.2 |
| 94 | */ |
| 95 | public function settings_page() { |
| 96 | |
| 97 | $tabs = array( |
| 98 | |
| 99 | 'advanced' => __( 'Advanced', '3d-flipbook-dflip-lite' ) |
| 100 | |
| 101 | ); |
| 102 | |
| 103 | //create tabs and content |
| 104 | ?> |
| 105 | |
| 106 | <h2><?php echo esc_html( get_admin_page_title() ); ?></h2> |
| 107 | <form id="dflip-settings" method="post" class="dflip-settings postbox"> |
| 108 | |
| 109 | <?php |
| 110 | wp_nonce_field( 'dflip_settings_nonce', 'dflip_settings_nonce' ); |
| 111 | submit_button( __( 'Update Settings', '3d-flipbook-dflip-lite' ), 'primary', 'dflip_settings_submit', false ); |
| 112 | ?> |
| 113 | |
| 114 | <div class="dflip-tabs"> |
| 115 | <ul class="dflip-tabs-list"> |
| 116 | <?php |
| 117 | //create tabs |
| 118 | $active_set = false; |
| 119 | foreach ( (array) $tabs as $id => $title ) { |
| 120 | ?> |
| 121 | <li class="dflip-update-hash dflip-tab <?php echo( $active_set == false ? 'dflip-active' : '' ) ?>"> |
| 122 | <a href="#dflip-tab-content-<?php echo $id ?>"><?php echo $title ?></a></li> |
| 123 | <?php $active_set = true; |
| 124 | } |
| 125 | ?> |
| 126 | </ul> |
| 127 | <?php |
| 128 | |
| 129 | $active_set = false; |
| 130 | foreach ( (array) $tabs as $id => $title ) { |
| 131 | ?> |
| 132 | <div id="dflip-tab-content-<?php echo $id ?>" |
| 133 | class="dflip-tab-content <?php echo( $active_set == false ? "dflip-active" : "" ) ?>"> |
| 134 | |
| 135 | <?php |
| 136 | $active_set = true; |
| 137 | |
| 138 | //create content for tab |
| 139 | $function = $id . "_tab"; |
| 140 | if ( method_exists( $this, $function ) ) { |
| 141 | call_user_func( array( $this, $function ) ); |
| 142 | }; |
| 143 | |
| 144 | ?> |
| 145 | </div> |
| 146 | <?php } ?> |
| 147 | </div> |
| 148 | </form> |
| 149 | <?php |
| 150 | |
| 151 | } |
| 152 | |
| 153 | public function hook_page_assets() { |
| 154 | add_action( 'admin_enqueue_scripts', array( $this, 'meta_box_styles_scripts' ) ); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Loads styles and scripts for our metaboxes. |
| 159 | * |
| 160 | * @return null Bail out if not on the proper screen. |
| 161 | * @since 1.0.0 |
| 162 | * |
| 163 | */ |
| 164 | public function meta_box_styles_scripts() { |
| 165 | |
| 166 | |
| 167 | // Load necessary metabox styles. |
| 168 | wp_register_style( $this->base->plugin_slug . '-setting-metabox-style', plugins_url( '../assets/css/metaboxes.css', __FILE__ ), array(), $this->base->version ); |
| 169 | wp_enqueue_style( $this->base->plugin_slug . '-setting-metabox-style' ); |
| 170 | wp_enqueue_style( 'wp-color-picker' ); |
| 171 | |
| 172 | // Load necessary metabox scripts. |
| 173 | wp_register_script( $this->base->plugin_slug . '-setting-metabox-script', plugins_url( '../assets/js/metaboxes.js', __FILE__ ), array( 'jquery', 'jquery-ui-tabs', 'wp-color-picker' ), |
| 174 | $this->base->version ); |
| 175 | wp_enqueue_script( $this->base->plugin_slug . '-setting-metabox-script' ); |
| 176 | |
| 177 | wp_enqueue_media(); |
| 178 | |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Creates the UI for General tab |
| 183 | * |
| 184 | * @since 1.0.0 |
| 185 | * |
| 186 | */ |
| 187 | public function general_tab() { |
| 188 | |
| 189 | |
| 190 | ?> |
| 191 | |
| 192 | <!--Clear-fix--> |
| 193 | <div class="dflip-box"></div> |
| 194 | |
| 195 | <?php |
| 196 | } |
| 197 | |
| 198 | public function layout_tab() { |
| 199 | |
| 200 | |
| 201 | ?> |
| 202 | |
| 203 | <!--Clear-fix--> |
| 204 | <div class="dflip-box"></div> |
| 205 | |
| 206 | <?php |
| 207 | } |
| 208 | |
| 209 | public function post_tab() { |
| 210 | |
| 211 | ?> |
| 212 | |
| 213 | <!--Clear-fix--> |
| 214 | <div class="dflip-box"></div> |
| 215 | |
| 216 | <?php |
| 217 | } |
| 218 | |
| 219 | |
| 220 | public function flipbook_tab() { |
| 221 | |
| 222 | |
| 223 | ?> |
| 224 | |
| 225 | <!--Clear-fix--> |
| 226 | <div class="dflip-box"></div> |
| 227 | |
| 228 | <?php |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /** |
| 233 | * Creates the UI for Popup tab |
| 234 | * |
| 235 | * @since 2.1.23 |
| 236 | * |
| 237 | */ |
| 238 | public function popup_tab() { |
| 239 | |
| 240 | |
| 241 | ?> |
| 242 | |
| 243 | <!--Clear-fix--> |
| 244 | <div class="dflip-box"></div> |
| 245 | |
| 246 | <?php |
| 247 | } |
| 248 | |
| 249 | |
| 250 | /** |
| 251 | * Creates the UI for Controls tab |
| 252 | * |
| 253 | * @since 2.1.40 |
| 254 | * |
| 255 | */ |
| 256 | public function controls_tab() { |
| 257 | |
| 258 | |
| 259 | ?> |
| 260 | |
| 261 | <!--Clear-fix--> |
| 262 | <div class="dflip-box"></div> |
| 263 | |
| 264 | <?php |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Creates the UI for Advanced tab |
| 269 | * |
| 270 | * @since 2.1.23 |
| 271 | * |
| 272 | */ |
| 273 | public function advanced_tab() { |
| 274 | |
| 275 | $this->base->create_setting( 'selectiveScriptLoading' ); |
| 276 | |
| 277 | |
| 278 | ?> |
| 279 | |
| 280 | <!--Clear-fix--> |
| 281 | <div class="dflip-box"></div> |
| 282 | |
| 283 | <?php |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Creates the UI for PDF tab |
| 288 | * |
| 289 | * @since 2.1.23 |
| 290 | * |
| 291 | */ |
| 292 | public function pdf_tab() { |
| 293 | |
| 294 | |
| 295 | ?> |
| 296 | |
| 297 | <!--Clear-fix--> |
| 298 | <div class="dflip-box"></div> |
| 299 | |
| 300 | <?php |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Creates the UI for Translate tab |
| 305 | * |
| 306 | * @since 1.0.0 |
| 307 | * |
| 308 | */ |
| 309 | public function translate_tab() { |
| 310 | |
| 311 | |
| 312 | ?> |
| 313 | |
| 314 | <!--Clear-fix--> |
| 315 | <div class="dflip-box"></div> |
| 316 | <?php |
| 317 | |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Update settings |
| 322 | * |
| 323 | * @return null Invalid nonce / no need to save |
| 324 | * @since 1.2.0.1 |
| 325 | * |
| 326 | */ |
| 327 | public function update_settings() { |
| 328 | |
| 329 | // Check form was submitted |
| 330 | if ( !isset( $_POST['dflip_settings_submit'] ) ) { |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | // Check nonce is valid |
| 335 | if ( !wp_verify_nonce( $_POST['dflip_settings_nonce'], 'dflip_settings_nonce' ) ) { |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | // Sanitize all user inputs. |
| 340 | |
| 341 | $sanitized_data = array(); |
| 342 | $sanitized_data['selectiveScriptLoading'] = sanitize_text_field( $_POST['_dflip']['selectiveScriptLoading'] ); |
| 343 | |
| 344 | $settings = is_multisite() ? get_blog_option( null, '_dflip_settings', true ) : get_option( '_dflip_settings', true ); |
| 345 | if ( empty( $settings ) ) { |
| 346 | $settings = array(); |
| 347 | } |
| 348 | $settings = array_merge( $settings, $sanitized_data ); |
| 349 | |
| 350 | if ( is_multisite() ) { |
| 351 | // Update options |
| 352 | update_blog_option( null, '_dflip_settings', $settings ); |
| 353 | } else { |
| 354 | // Update options |
| 355 | update_option( '_dflip_settings', $settings ); |
| 356 | } |
| 357 | // Show confirmation |
| 358 | add_action( 'admin_notices', array( $this, 'updated_settings' ) ); |
| 359 | |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * display a saved notice |
| 364 | * |
| 365 | * @since 1.2.0.1 |
| 366 | */ |
| 367 | public function updated_settings() { |
| 368 | ?> |
| 369 | <div class="updated"> |
| 370 | <p><?php _e( 'Settings updated.', '3d-flipbook-dflip-lite' ); ?></p> |
| 371 | </div> |
| 372 | <?php |
| 373 | |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Returns the singleton instance of the class. |
| 378 | * |
| 379 | * @return object DFlip_Settings object. |
| 380 | * @since 1.2.0 |
| 381 | * |
| 382 | */ |
| 383 | public static function get_instance() { |
| 384 | |
| 385 | if ( !isset( self::$instance ) |
| 386 | && !( self::$instance instanceof DFlip_Settings ) ) { |
| 387 | self::$instance = new DFlip_Settings(); |
| 388 | } |
| 389 | |
| 390 | return self::$instance; |
| 391 | |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // Load the DFlip_Settings class. |
| 396 | $dflip_settings = DFlip_Settings::get_instance(); |
| 397 |