Advertisement
HarunRRayhan

WeDevs Settings API

Jul 25th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.30 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * weDevs Settings API wrapper class
  5.  *
  6.  */
  7. if ( !class_exists( 'WeDevs_Settings_API' ) ):
  8. class WeDevs_Settings_API {
  9.  
  10.     /**
  11.      * settings sections array
  12.      *
  13.      * @var array
  14.      */
  15.     protected $settings_sections = array();
  16.  
  17.     /**
  18.      * Settings fields array
  19.      *
  20.      * @var array
  21.      */
  22.     protected $settings_fields = array();
  23.  
  24.     public function __construct() {
  25.         add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
  26.     }
  27.  
  28.     /**
  29.      * Enqueue scripts and styles
  30.      */
  31.     function admin_enqueue_scripts() {
  32.         wp_enqueue_style( 'wp-color-picker' );
  33.  
  34.         wp_enqueue_media();
  35.         wp_enqueue_script( 'wp-color-picker' );
  36.         wp_enqueue_script( 'jquery' );
  37.     }
  38.  
  39.     /**
  40.      * Set settings sections
  41.      *
  42.      * @param array   $sections setting sections array
  43.      */
  44.     function set_sections( $sections ) {
  45.         $this->settings_sections = $sections;
  46.  
  47.         return $this;
  48.     }
  49.  
  50.     /**
  51.      * Add a single section
  52.      *
  53.      * @param array   $section
  54.      */
  55.     function add_section( $section ) {
  56.         $this->settings_sections[] = $section;
  57.  
  58.         return $this;
  59.     }
  60.  
  61.     /**
  62.      * Set settings fields
  63.      *
  64.      * @param array   $fields settings fields array
  65.      */
  66.     function set_fields( $fields ) {
  67.         $this->settings_fields = $fields;
  68.  
  69.         return $this;
  70.     }
  71.  
  72.     function add_field( $section, $field ) {
  73.         $defaults = array(
  74.             'name'  => '',
  75.             'label' => '',
  76.             'desc'  => '',
  77.             'type'  => 'text'
  78.         );
  79.  
  80.         $arg = wp_parse_args( $field, $defaults );
  81.         $this->settings_fields[$section][] = $arg;
  82.  
  83.         return $this;
  84.     }
  85.  
  86.     /**
  87.      * Initialize and registers the settings sections and fileds to WordPress
  88.      *
  89.      * Usually this should be called at `admin_init` hook.
  90.      *
  91.      * This function gets the initiated settings sections and fields. Then
  92.      * registers them to WordPress and ready for use.
  93.      */
  94.     function admin_init() {
  95.         //register settings sections
  96.         foreach ( $this->settings_sections as $section ) {
  97.             if ( false == get_option( $section['id'] ) ) {
  98.                 add_option( $section['id'] );
  99.             }
  100.  
  101.             if ( isset($section['desc']) && !empty($section['desc']) ) {
  102.                 $section['desc'] = '<div class="inside">' . $section['desc'] . '</div>';
  103.                 $callback = create_function('', 'echo "' . str_replace( '"', '\"', $section['desc'] ) . '";');
  104.             } else if ( isset( $section['callback'] ) ) {
  105.                 $callback = $section['callback'];
  106.             } else {
  107.                 $callback = null;
  108.             }
  109.  
  110.             add_settings_section( $section['id'], $section['title'], $callback, $section['id'] );
  111.         }
  112.  
  113.         //register settings fields
  114.         foreach ( $this->settings_fields as $section => $field ) {
  115.             foreach ( $field as $option ) {
  116.  
  117.                 $name = $option['name'];
  118.                 $type = isset( $option['type'] ) ? $option['type'] : 'text';
  119.                 $label = isset( $option['label'] ) ? $option['label'] : '';
  120.                 $callback = isset( $option['callback'] ) ? $option['callback'] : array( $this, 'callback_' . $type );
  121.  
  122.                 $args = array(
  123.                     'id'                => $name,
  124.                     'class'             => isset( $option['class'] ) ? $option['class'] : $name,
  125.                     'label_for'         => "{$section}[{$name}]",
  126.                     'desc'              => isset( $option['desc'] ) ? $option['desc'] : '',
  127.                     'name'              => $label,
  128.                     'section'           => $section,
  129.                     'size'              => isset( $option['size'] ) ? $option['size'] : null,
  130.                     'options'           => isset( $option['options'] ) ? $option['options'] : '',
  131.                     'std'               => isset( $option['default'] ) ? $option['default'] : '',
  132.                     'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
  133.                     'type'              => $type,
  134.                     'placeholder'       => isset( $option['placeholder'] ) ? $option['placeholder'] : '',
  135.                     'min'               => isset( $option['min'] ) ? $option['min'] : '',
  136.                     'max'               => isset( $option['max'] ) ? $option['max'] : '',
  137.                     'step'              => isset( $option['step'] ) ? $option['step'] : '',
  138.                 );
  139.  
  140.                 add_settings_field( "{$section}[{$name}]", $label, $callback, $section, $section, $args );
  141.             }
  142.         }
  143.  
  144.         // creates our settings in the options table
  145.         foreach ( $this->settings_sections as $section ) {
  146.             register_setting( $section['id'], $section['id'], array( $this, 'sanitize_options' ) );
  147.         }
  148.     }
  149.  
  150.     /**
  151.      * Get field description for display
  152.      *
  153.      * @param array   $args settings field args
  154.      */
  155.     public function get_field_description( $args ) {
  156.         if ( ! empty( $args['desc'] ) ) {
  157.             $desc = sprintf( '<p class="description">%s</p>', $args['desc'] );
  158.         } else {
  159.             $desc = '';
  160.         }
  161.  
  162.         return $desc;
  163.     }
  164.  
  165.     /**
  166.      * Displays a text field for a settings field
  167.      *
  168.      * @param array   $args settings field args
  169.      */
  170.     function callback_text( $args ) {
  171.  
  172.         $value       = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
  173.         $size        = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
  174.         $type        = isset( $args['type'] ) ? $args['type'] : 'text';
  175.         $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
  176.  
  177.         $html        = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );
  178.         $html       .= $this->get_field_description( $args );
  179.  
  180.         echo $html;
  181.     }
  182.  
  183.     /**
  184.      * Displays a url field for a settings field
  185.      *
  186.      * @param array   $args settings field args
  187.      */
  188.     function callback_url( $args ) {
  189.         $this->callback_text( $args );
  190.     }
  191.  
  192.     /**
  193.      * Displays a number field for a settings field
  194.      *
  195.      * @param array   $args settings field args
  196.      */
  197.     function callback_number( $args ) {
  198.         $value       = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
  199.         $size        = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
  200.         $type        = isset( $args['type'] ) ? $args['type'] : 'number';
  201.         $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
  202.         $min         = empty( $args['min'] ) ? '' : ' min="' . $args['min'] . '"';
  203.         $max         = empty( $args['max'] ) ? '' : ' max="' . $args['max'] . '"';
  204.         $step        = empty( $args['max'] ) ? '' : ' step="' . $args['step'] . '"';
  205.  
  206.         $html        = sprintf( '<input type="%1$s" class="%2$s-number" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );
  207.         $html       .= $this->get_field_description( $args );
  208.  
  209.         echo $html;
  210.     }
  211.  
  212.     /**
  213.      * Displays a checkbox for a settings field
  214.      *
  215.      * @param array   $args settings field args
  216.      */
  217.     function callback_checkbox( $args ) {
  218.  
  219.         $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
  220.  
  221.         $html  = '<fieldset>';
  222.         $html  .= sprintf( '<label for="wpuf-%1$s[%2$s]">', $args['section'], $args['id'] );
  223.         $html  .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id'] );
  224.         $html  .= sprintf( '<input type="checkbox" class="checkbox" id="wpuf-%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked( $value, 'on', false ) );
  225.         $html  .= sprintf( '%1$s</label>', $args['desc'] );
  226.         $html  .= '</fieldset>';
  227.  
  228.         echo $html;
  229.     }
  230.  
  231.     /**
  232.      * Displays a multicheckbox for a settings field
  233.      *
  234.      * @param array   $args settings field args
  235.      */
  236.     function callback_multicheck( $args ) {
  237.  
  238.         $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
  239.         $html  = '<fieldset>';
  240.         $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="" />', $args['section'], $args['id'] );
  241.         foreach ( $args['options'] as $key => $label ) {
  242.             $checked = isset( $value[$key] ) ? $value[$key] : '0';
  243.             $html    .= sprintf( '<label for="wpuf-%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
  244.             $html    .= sprintf( '<input type="checkbox" class="checkbox" id="wpuf-%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $checked, $key, false ) );
  245.             $html    .= sprintf( '%1$s</label><br>',  $label );
  246.         }
  247.  
  248.         $html .= $this->get_field_description( $args );
  249.         $html .= '</fieldset>';
  250.  
  251.         echo $html;
  252.     }
  253.  
  254.     /**
  255.      * Displays a radio button for a settings field
  256.      *
  257.      * @param array   $args settings field args
  258.      */
  259.     function callback_radio( $args ) {
  260.  
  261.         $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
  262.         $html  = '<fieldset>';
  263.  
  264.         foreach ( $args['options'] as $key => $label ) {
  265.             $html .= sprintf( '<label for="wpuf-%1$s[%2$s][%3$s]">',  $args['section'], $args['id'], $key );
  266.             $html .= sprintf( '<input type="radio" class="radio" id="wpuf-%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $value, $key, false ) );
  267.             $html .= sprintf( '%1$s</label><br>', $label );
  268.         }
  269.  
  270.         $html .= $this->get_field_description( $args );
  271.         $html .= '</fieldset>';
  272.  
  273.         echo $html;
  274.     }
  275.  
  276.     /**
  277.      * Displays a selectbox for a settings field
  278.      *
  279.      * @param array   $args settings field args
  280.      */
  281.     function callback_select( $args ) {
  282.  
  283.         $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
  284.         $size  = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
  285.         $html  = sprintf( '<select class="%1$s" name="%2$s[%3$s]" id="%2$s[%3$s]">', $size, $args['section'], $args['id'] );
  286.  
  287.         foreach ( $args['options'] as $key => $label ) {
  288.             $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $value, $key, false ), $label );
  289.         }
  290.  
  291.         $html .= sprintf( '</select>' );
  292.         $html .= $this->get_field_description( $args );
  293.  
  294.         echo $html;
  295.     }
  296.  
  297.     /**
  298.      * Displays a textarea for a settings field
  299.      *
  300.      * @param array   $args settings field args
  301.      */
  302.     function callback_textarea( $args ) {
  303.  
  304.         $value       = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
  305.         $size        = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
  306.         $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
  307.  
  308.         $html        = sprintf( '<textarea rows="5" cols="55" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );
  309.         $html        .= $this->get_field_description( $args );
  310.  
  311.         echo $html;
  312.     }
  313.  
  314.     /**
  315.      * Displays the html for a settings field
  316.      *
  317.      * @param array   $args settings field args
  318.      * @return string
  319.      */
  320.     function callback_html( $args ) {
  321.         echo $this->get_field_description( $args );
  322.     }
  323.  
  324.     /**
  325.      * Displays a rich text textarea for a settings field
  326.      *
  327.      * @param array   $args settings field args
  328.      */
  329.     function callback_wysiwyg( $args ) {
  330.  
  331.         $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
  332.         $size  = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : '500px';
  333.  
  334.         echo '<div style="max-width: ' . $size . ';">';
  335.  
  336.         $editor_settings = array(
  337.             'teeny'         => true,
  338.             'textarea_name' => $args['section'] . '[' . $args['id'] . ']',
  339.             'textarea_rows' => 10
  340.         );
  341.  
  342.         if ( isset( $args['options'] ) && is_array( $args['options'] ) ) {
  343.             $editor_settings = array_merge( $editor_settings, $args['options'] );
  344.         }
  345.  
  346.         wp_editor( $value, $args['section'] . '-' . $args['id'], $editor_settings );
  347.  
  348.         echo '</div>';
  349.  
  350.         echo $this->get_field_description( $args );
  351.     }
  352.  
  353.     /**
  354.      * Displays a file upload field for a settings field
  355.      *
  356.      * @param array   $args settings field args
  357.      */
  358.     function callback_file( $args ) {
  359.  
  360.         $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
  361.         $size  = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
  362.         $id    = $args['section']  . '[' . $args['id'] . ']';
  363.         $label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : __( 'Choose File' );
  364.  
  365.         $html  = sprintf( '<input type="text" class="%1$s-text wpsa-url" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
  366.         $html  .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
  367.         $html  .= $this->get_field_description( $args );
  368.  
  369.         echo $html;
  370.     }
  371.  
  372.     /**
  373.      * Displays a password field for a settings field
  374.      *
  375.      * @param array   $args settings field args
  376.      */
  377.     function callback_password( $args ) {
  378.  
  379.         $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
  380.         $size  = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
  381.  
  382.         $html  = sprintf( '<input type="password" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
  383.         $html  .= $this->get_field_description( $args );
  384.  
  385.         echo $html;
  386.     }
  387.  
  388.     /**
  389.      * Displays a color picker field for a settings field
  390.      *
  391.      * @param array   $args settings field args
  392.      */
  393.     function callback_color( $args ) {
  394.  
  395.         $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
  396.         $size  = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
  397.  
  398.         $html  = sprintf( '<input type="text" class="%1$s-text wp-color-picker-field" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s" data-default-color="%5$s" />', $size, $args['section'], $args['id'], $value, $args['std'] );
  399.         $html  .= $this->get_field_description( $args );
  400.  
  401.         echo $html;
  402.     }
  403.  
  404.  
  405.     /**
  406.      * Displays a select box for creating the pages select box
  407.      *
  408.      * @param array   $args settings field args
  409.      */
  410.     function callback_pages( $args ) {
  411.  
  412.         $dropdown_args = array(
  413.             'selected' => esc_attr($this->get_option($args['id'], $args['section'], $args['std'] ) ),
  414.             'name'     => $args['section'] . '[' . $args['id'] . ']',
  415.             'id'       => $args['section'] . '[' . $args['id'] . ']',
  416.             'echo'     => 0
  417.         );
  418.         $html = wp_dropdown_pages( $dropdown_args );
  419.         echo $html;
  420.     }
  421.  
  422.     /**
  423.      * Sanitize callback for Settings API
  424.      *
  425.      * @return mixed
  426.      */
  427.     function sanitize_options( $options ) {
  428.  
  429.         if ( !$options ) {
  430.             return $options;
  431.         }
  432.  
  433.         foreach( $options as $option_slug => $option_value ) {
  434.             $sanitize_callback = $this->get_sanitize_callback( $option_slug );
  435.  
  436.             // If callback is set, call it
  437.             if ( $sanitize_callback ) {
  438.                 $options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
  439.                 continue;
  440.             }
  441.         }
  442.  
  443.         return $options;
  444.     }
  445.  
  446.     /**
  447.      * Get sanitization callback for given option slug
  448.      *
  449.      * @param string $slug option slug
  450.      *
  451.      * @return mixed string or bool false
  452.      */
  453.     function get_sanitize_callback( $slug = '' ) {
  454.         if ( empty( $slug ) ) {
  455.             return false;
  456.         }
  457.  
  458.         // Iterate over registered fields and see if we can find proper callback
  459.         foreach( $this->settings_fields as $section => $options ) {
  460.             foreach ( $options as $option ) {
  461.                 if ( $option['name'] != $slug ) {
  462.                     continue;
  463.                 }
  464.  
  465.                 // Return the callback name
  466.                 return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
  467.             }
  468.         }
  469.  
  470.         return false;
  471.     }
  472.  
  473.     /**
  474.      * Get the value of a settings field
  475.      *
  476.      * @param string  $option  settings field name
  477.      * @param string  $section the section name this field belongs to
  478.      * @param string  $default default text if it's not found
  479.      * @return string
  480.      */
  481.     function get_option( $option, $section, $default = '' ) {
  482.  
  483.         $options = get_option( $section );
  484.  
  485.         if ( isset( $options[$option] ) ) {
  486.             return $options[$option];
  487.         }
  488.  
  489.         return $default;
  490.     }
  491.  
  492.     /**
  493.      * Show navigations as tab
  494.      *
  495.      * Shows all the settings section labels as tab
  496.      */
  497.     function show_navigation() {
  498.         $html = '<h2 class="nav-tab-wrapper">';
  499.  
  500.         $count = count( $this->settings_sections );
  501.  
  502.         // don't show the navigation if only one section exists
  503.         if ( $count === 1 ) {
  504.             return;
  505.         }
  506.  
  507.         foreach ( $this->settings_sections as $tab ) {
  508.             $html .= sprintf( '<a href="#%1$s" class="nav-tab" id="%1$s-tab">%2$s</a>', $tab['id'], $tab['title'] );
  509.         }
  510.  
  511.         $html .= '</h2>';
  512.  
  513.         echo $html;
  514.     }
  515.  
  516.     /**
  517.      * Show the section settings forms
  518.      *
  519.      * This function displays every sections in a different form
  520.      */
  521.     function show_forms() {
  522.         ?>
  523.         <div class="metabox-holder">
  524.             <?php foreach ( $this->settings_sections as $form ) { ?>
  525.                 <div id="<?php echo $form['id']; ?>" class="group" style="display: none;">
  526.                     <form method="post" action="options.php">
  527.                         <?php
  528.                         do_action( 'wsa_form_top_' . $form['id'], $form );
  529.                         settings_fields( $form['id'] );
  530.                         do_settings_sections( $form['id'] );
  531.                         do_action( 'wsa_form_bottom_' . $form['id'], $form );
  532.                         if ( isset( $this->settings_fields[ $form['id'] ] ) ):
  533.                         ?>
  534.                         <div style="padding-left: 10px">
  535.                             <?php submit_button(); ?>
  536.                         </div>
  537.                         <?php endif; ?>
  538.                     </form>
  539.                 </div>
  540.             <?php } ?>
  541.         </div>
  542.         <?php
  543.         $this->script();
  544.     }
  545.  
  546.     /**
  547.      * Tabbable JavaScript codes & Initiate Color Picker
  548.      *
  549.      * This code uses localstorage for displaying active tabs
  550.      */
  551.     function script() {
  552.         ?>
  553.         <script>
  554.             jQuery(document).ready(function($) {
  555.                 //Initiate Color Picker
  556.                 $('.wp-color-picker-field').wpColorPicker();
  557.  
  558.                 // Switches option sections
  559.                 $('.group').hide();
  560.                 var activetab = '';
  561.                 if (typeof(localStorage) != 'undefined' ) {
  562.                     activetab = localStorage.getItem("activetab");
  563.                 }
  564.                
  565.                 //if url has section id as hash then set it as active or override the current local storage value
  566.                 if(window.location.hash){
  567.                     activetab = window.location.hash;
  568.                     if (typeof(localStorage) != 'undefined' ) {
  569.                         localStorage.setItem("activetab", activetab);
  570.                     }                
  571.                 }
  572.                
  573.                 if (activetab != '' && $(activetab).length ) {
  574.                     $(activetab).fadeIn();
  575.                 } else {
  576.                     $('.group:first').fadeIn();
  577.                 }
  578.                 $('.group .collapsed').each(function(){
  579.                     $(this).find('input:checked').parent().parent().parent().nextAll().each(
  580.                     function(){
  581.                         if ($(this).hasClass('last')) {
  582.                             $(this).removeClass('hidden');
  583.                             return false;
  584.                         }
  585.                         $(this).filter('.hidden').removeClass('hidden');
  586.                     });
  587.                 });
  588.  
  589.                 if (activetab != '' && $(activetab + '-tab').length ) {
  590.                     $(activetab + '-tab').addClass('nav-tab-active');
  591.                 }
  592.                 else {
  593.                     $('.nav-tab-wrapper a:first').addClass('nav-tab-active');
  594.                 }
  595.                 $('.nav-tab-wrapper a').click(function(evt) {
  596.                     $('.nav-tab-wrapper a').removeClass('nav-tab-active');
  597.                     $(this).addClass('nav-tab-active').blur();
  598.                     var clicked_group = $(this).attr('href');
  599.                     if (typeof(localStorage) != 'undefined' ) {
  600.                         localStorage.setItem("activetab", $(this).attr('href'));
  601.                     }
  602.                     $('.group').hide();
  603.                     $(clicked_group).fadeIn();
  604.                     evt.preventDefault();
  605.                 });
  606.  
  607.                 $('.wpsa-browse').on('click', function (event) {
  608.                     event.preventDefault();
  609.  
  610.                     var self = $(this);
  611.  
  612.                     // Create the media frame.
  613.                     var file_frame = wp.media.frames.file_frame = wp.media({
  614.                         title: self.data('uploader_title'),
  615.                         button: {
  616.                             text: self.data('uploader_button_text'),
  617.                         },
  618.                         multiple: false
  619.                     });
  620.  
  621.                     file_frame.on('select', function () {
  622.                         attachment = file_frame.state().get('selection').first().toJSON();
  623.                         self.prev('.wpsa-url').val(attachment.url).change();
  624.                     });
  625.  
  626.                     // Finally, open the modal
  627.                     file_frame.open();
  628.                 });
  629.         });
  630.         </script>
  631.         <?php
  632.         $this->_style_fix();
  633.     }
  634.  
  635.     function _style_fix() {
  636.         global $wp_version;
  637.  
  638.         if (version_compare($wp_version, '3.8', '<=')):
  639.         ?>
  640.         <style type="text/css">
  641.             /** WordPress 3.8 Fix **/
  642.             .form-table th { padding: 20px 10px; }
  643.             #wpbody-content .metabox-holder { padding-top: 5px; }
  644.         </style>
  645.         <?php
  646.         endif;
  647.     }
  648.  
  649. }
  650.  
  651. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement