Plugin Directory

Changeset 2034188


Ignore:
Timestamp:
02/19/2019 01:41:23 PM (7 years ago)
Author:
nikolam
Message:

Fix multiple elements not showing or hiding + improve script

Location:
sermon-manager-for-wordpress/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • sermon-manager-for-wordpress/trunk/assets/js/admin/settings/conditionals.js

    r2030979 r2034188  
    55 */
    66
    7 var sm_conditionals = typeof sm_conditionals !== 'undefined' ? sm_conditionals : [];
    8 
    9 jQuery( document ).ready(
    10     function () {
    11         jQuery.each(
    12             sm_conditionals,
    13             function ( element_id, element_conditionals ) {
    14                 var element = jQuery( '#' + element_id ).closest( 'tr' );
    15 
    16                 jQuery.each(
    17                     element_conditionals,
    18                     function ( index, condition_data ) {
    19                         var conditional_element_id = condition_data.id;
    20                         var conditional_element    = jQuery( '#' + conditional_element_id );
    21                         var value                  = sm_isset( condition_data[ "value" ] ) ? condition_data[ "value" ] : condition_data[ "!value" ];
    22                         var not                    = sm_isset( condition_data[ "!value" ] );
    23 
    24                         conditional_element.off().on(
    25                             'change',
    26                             function () {
    27                                 var selected_category = this.value;
    28                                 hide_show_elements( not, value, selected_category, element );
    29                             }
    30                         );
    31 
    32                         hide_show_elements( not, value, conditional_element.val(), element );
    33                     }
    34                 );
    35             }
    36         );
    37     }
    38 );
    39 
    40 function hide_show_elements( not, value, current_value, element ) {
    41     element.find( 'select' ).find( 'option' ).each( function () {
    42         jQuery( this.remove() );
    43     } );
    44     element.find( 'select' ).append( jQuery( '<option/>' ).val( '' ).text( 'Loading...' ) );
    45 
    46     if ( not ) {
    47         if ( value !== current_value ) {
    48             element.removeClass( 'hidden' );
    49         } else {
    50             element.addClass( 'hidden' );
    51         }
    52     } else {
    53         if ( value === current_value ) {
    54             element.removeClass( 'hidden' );
    55         } else {
    56             element.addClass( 'hidden' );
    57         }
    58     }
    59 
    60     var data = {
    61         'action': 'sm_settings_get_select_data',
    62         'id': current_value,
    63     };
    64 
    65     // Request subcategory list.
    66     jQuery.post(
    67         ajaxurl,
    68         data,
    69         function ( response ) {
    70             if ( 'false' === response ) {
    71                 element.addClass( 'hidden' );
    72             } else {
    73                 response = JSON.parse( response );
    74                 element.find( 'select' ).find( 'option' ).each( function () {
    75                     jQuery( this.remove() );
    76                 } );
    77                 jQuery.each(
    78                     response,
    79                     function ( id, item ) {
    80                         element.find( 'select' ).append( jQuery( '<option/>' ).val( id ).text( item ) );
    81                     }
    82                 )
    83             }
     7if ( typeof sm_conditionals !== 'undefined' ) {
     8    // Bind to elements.
     9    jQuery(
     10        function () {
     11            jQuery.each(
     12                sm_conditionals,
     13                function ( element_id, element_conditionals ) {
     14                    /**
     15                     * The element that should be shown or hidden.
     16                     *
     17                     * @type object
     18                     */
     19                    let target_element = jQuery( '#' + element_id );
     20
     21                    /**
     22                     * The element's table row.
     23                     *
     24                     * @type object
     25                     */
     26                    let table_row = target_element.closest( 'tr' );
     27
     28                    // Go through each conditional.
     29                    jQuery.each(
     30                        element_conditionals,
     31                        function ( index, condition_data ) {
     32                            /**
     33                             * The element's HTML ID & database ID.
     34                             */
     35                            let conditional_element_id = condition_data.id;
     36
     37                            /**
     38                             * The element itself.
     39                             *
     40                             * @type object
     41                             */
     42                            let conditional_element = jQuery( '#' + conditional_element_id );
     43
     44                            /**
     45                             * The value that we are looking for in the element.
     46                             *
     47                             * @type string
     48                             */
     49                            let target_value = sm_isset( condition_data[ "value" ] ) ? condition_data[ "value" ] : condition_data[ "!value" ];
     50
     51                            /**
     52                             * If we should invert the value.
     53                             *
     54                             * @type boolean
     55                             */
     56                            let not = sm_isset( condition_data[ "!value" ] );
     57
     58                            // Hook into element's change event, so we can act on it.
     59                            conditional_element.on(
     60                                'change',
     61                                function () {
     62                                    /**
     63                                     * Currently selected value.
     64                                     *
     65                                     * @type string
     66                                     */
     67                                    let selected_value = this.value;
     68
     69                                    // Hide or show the elements.
     70                                    sm_hide_show_elements( target_value, selected_value, not, table_row );
     71                                }
     72                            );
     73
     74                            // Call the function first time.
     75                            sm_hide_show_elements( target_value, conditional_element.val(), not, table_row );
     76                        }
     77                    );
     78                }
     79            );
    8480        }
    8581    );
    8682}
    8783
     84/**
     85 * Hides or shows the element based on its value.
     86 *
     87 * @param {string} target_value Value that we are looking for.
     88 * @param {string} current_value The current value of the element.
     89 * @param {boolean} not If we should invert the value.
     90 * @param {object} table_row The table row to hide or show.
     91 */
     92function sm_hide_show_elements( target_value, current_value, not, table_row ) {
     93    let element = table_row.find( 'select' );
     94
     95    /**
     96     * If we should hide the row.
     97     *
     98     * @type {boolean}
     99     */
     100    let hide = target_value !== current_value;
     101
     102    /**
     103     * If the element should get data via Ajax.
     104     *
     105     * @type boolean
     106     */
     107    let is_ajax = element.data( 'ajax' ) ? element.data( 'ajax' ) : false;
     108
     109    // Invert if needed.
     110    hide = not ? ! hide : hide;
     111
     112    // Do hide.
     113    if ( ! is_ajax ) {
     114        if ( hide ) {
     115            table_row.addClass( 'hidden' );
     116        } else {
     117            table_row.removeClass( 'hidden' );
     118        }
     119    }
     120
     121    // If we should get options via Ajax.
     122    if ( is_ajax ) {
     123        let data = {
     124            'action': 'sm_settings_get_select_data',
     125            'id': current_value,
     126        };
     127
     128        // Request element data.
     129        jQuery.ajax(
     130            {
     131                method: 'POST',
     132                url: ajaxurl,
     133                data: data,
     134            }
     135        ).always(
     136            function () {
     137                // Reset element value.
     138                switch ( element.prop( 'tagName' ) ) {
     139                    case 'SELECT':
     140                        element.find( 'option' ).each(
     141                            function () {
     142                                jQuery( this.remove() );
     143                            }
     144                        );
     145                        if ( ! table_row.hasClass( 'hidden' ) ) {
     146                            element.append( jQuery( '<option/>' ).val( '' ).text( 'Loading...' ) );
     147                        }
     148                        break;
     149                }
     150            }
     151        ).done(
     152            function ( response ) {
     153                // Convert JSON to array/object.
     154                if ( 'false' === response ) {
     155                    response = false;
     156                } else {
     157                    try {
     158                        response = JSON.parse( response );
     159                    } catch ( err ) {
     160                        response = false;
     161                    }
     162                }
     163
     164                // Write received values to element.
     165                if ( typeof response === 'object' ) {
     166                    table_row.removeClass( 'hidden' );
     167
     168                    switch ( element.prop( 'tagName' ) ) {
     169                        case 'SELECT':
     170                            element.find( 'option' ).each(
     171                                function () {
     172                                    jQuery( this.remove() );
     173                                }
     174                            );
     175                            jQuery.each(
     176                                response,
     177                                function ( id, item ) {
     178                                    table_row.find( 'select' ).append( jQuery( '<option/>' ).val( id ).text( item ) );
     179                                }
     180                            );
     181                            break;
     182                    }
     183                }
     184
     185                if ( false === response ) {
     186                    table_row.addClass( 'hidden' );
     187                }
     188            }
     189        ).fail(
     190            function () {
     191                // Write error message if response is invalid.
     192                switch ( element.prop( 'tabName' ) ) {
     193                    case 'SELECT':
     194                        element.append( jQuery( '<option/>' ).val( '' ).text( 'Error.' ) );
     195                        break;
     196                }
     197            }
     198        );
     199    }
     200}
     201
    88202
    89203/**
    90204 * Checks to see if a value is set.
    91205 *
    92  * @param {Function} accessor Function that returns our value
     206 * @param {*} value The value to check.
    93207 */
    94 function sm_isset( accessor ) {
     208function sm_isset( value ) {
    95209    try {
    96         // Note we're seeing if the returned value of our function is not
    97         // undefined
    98         return typeof accessor !== 'undefined'
     210        return typeof value !== 'undefined'
    99211    } catch ( e ) {
    100         // And we're able to catch the Error it would normally throw for
    101         // referencing a property of undefined
    102212        return false
    103213    }
  • sermon-manager-for-wordpress/trunk/includes/admin/class-sm-admin-settings.php

    r2030979 r2034188  
    206206        $display_conditions = array();
    207207
    208         foreach ( $options as $value ) {
    209             if ( ! isset( $value['type'] ) ) {
     208        foreach ( $options as $option ) {
     209            if ( ! isset( $option['type'] ) ) {
    210210                continue;
    211211            }
    212212
    213213            // Fill out data that is not set.
    214             $value += array(
     214            $option += array(
    215215                'id'          => '',
    216                 'title'       => isset( $value['name'] ) ? $value['name'] : '',
     216                'title'       => isset( $option['name'] ) ? $option['name'] : '',
    217217                'class'       => '',
    218218                'css'         => '',
     
    224224                'disabled'    => false,
    225225                'display_if'  => array(),
     226                'ajax'        => false,
    226227            );
    227228
    228229            // Get conditional display.
    229             if ( ! empty( $value['display_if'] ) ) {
    230                 $display_conditions[ $value['id'] ]   = isset( $display_conditions[ $value['id'] ] ) ? $display_conditions[ $value['id'] ] : array();
    231                 $display_conditions[ $value['id'] ][] = $value['display_if'];
     230            if ( ! empty( $option['display_if'] ) ) {
     231                $display_conditions[ $option['id'] ]   = isset( $display_conditions[ $option['id'] ] ) ? $display_conditions[ $option['id'] ] : array();
     232                $display_conditions[ $option['id'] ][] = $option['display_if'];
    232233            }
    233234
     
    235236            $custom_attributes = array();
    236237
    237             if ( ! empty( $value['custom_attributes'] ) ) {
    238                 if ( is_array( $value['custom_attributes'] ) ) {
    239                     foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
     238            if ( ! empty( $option['custom_attributes'] ) ) {
     239                if ( is_array( $option['custom_attributes'] ) ) {
     240                    foreach ( $option['custom_attributes'] as $attribute => $attribute_value ) {
    240241                        $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
    241242                    }
    242                 } elseif ( is_string( $value['custom_attributes'] ) ) {
    243                     $custom_attributes[] = $value['custom_attributes'];
     243                } elseif ( is_string( $option['custom_attributes'] ) ) {
     244                    $custom_attributes[] = $option['custom_attributes'];
    244245                }
    245246            }
    246247
     248            if ( $option['ajax'] ) {
     249                $custom_attributes[] = 'data-ajax="true"';
     250            }
     251
    247252            // Get descriptions.
    248             $field_description = self::get_field_description( $value );
     253            $field_description = self::get_field_description( $option );
    249254            $description       = $field_description['description'];
    250255            $tooltip_html      = $field_description['tooltip_html'];
    251256
    252257            // Execute a function to get the options in (multi)select if it's specified.
    253             if ( isset( $value['options'] ) ) {
    254                 $value['options'] = self::_maybe_populate_options( $value['options'] );
     258            if ( isset( $option['options'] ) ) {
     259                $option['options'] = self::_maybe_populate_options( $option['options'] );
    255260            }
    256261
    257262            // Get the value.
    258263            if ( empty( $values ) ) {
    259                 $option_value = self::get_option( $value['id'], $value['default'] );
     264                $option_value = self::get_option( $option['id'], $option['default'] );
    260265            } else {
    261                 $option_value = empty( $values[ $value['id'] ] ) ? $value['default'] : $values[ $value['id'] ];
     266                $option_value = empty( $values[ $option['id'] ] ) ? $option['default'] : $values[ $option['id'] ];
    262267            }
    263268
    264269            // Output the field based on type.
    265             switch ( $value['type'] ) {
     270            switch ( $option['type'] ) {
    266271                // Section Titles.
    267272                case 'title':
    268                     if ( ! empty( $value['title'] ) ) {
    269                         echo '<h2 class="forminp-title">' . esc_html( $value['title'] ) . '</h2>';
    270                     }
    271                     if ( ! empty( $value['desc'] ) ) {
    272                         echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
     273                    if ( ! empty( $option['title'] ) ) {
     274                        echo '<h2 class="forminp-title">' . esc_html( $option['title'] ) . '</h2>';
     275                    }
     276                    if ( ! empty( $option['desc'] ) ) {
     277                        echo wpautop( wptexturize( wp_kses_post( $option['desc'] ) ) );
    273278                    }
    274279                    echo '<table class="form-table">' . "\n\n";
    275                     if ( ! empty( $value['id'] ) ) {
    276                         do_action( 'sm_settings_' . sanitize_title( $value['id'] ) );
     280                    if ( ! empty( $option['id'] ) ) {
     281                        do_action( 'sm_settings_' . sanitize_title( $option['id'] ) );
    277282                    }
    278283                    break;
     
    280285                // Section Ends.
    281286                case 'sectionend':
    282                     if ( ! empty( $value['id'] ) ) {
    283                         do_action( 'sm_settings_' . sanitize_title( $value['id'] ) . '_end' );
     287                    if ( ! empty( $option['id'] ) ) {
     288                        do_action( 'sm_settings_' . sanitize_title( $option['id'] ) . '_end' );
    284289                    }
    285290                    echo '</table>';
    286                     if ( ! empty( $value['id'] ) ) {
    287                         do_action( 'sm_settings_' . sanitize_title( $value['id'] ) . '_after' );
     291                    if ( ! empty( $option['id'] ) ) {
     292                        do_action( 'sm_settings_' . sanitize_title( $option['id'] ) . '_after' );
    288293                    }
    289294                    break;
     
    294299                case 'number':
    295300                case 'password':
    296                     if ( substr( $value['id'], 0, 2 ) === '__' && strlen( $value['id'] ) > 2 ) {
    297                         $option_value = $value['value'];
     301                    if ( substr( $option['id'], 0, 2 ) === '__' && strlen( $option['id'] ) > 2 ) {
     302                        $option_value = $option['value'];
    298303                    }
    299304
     
    301306                    <tr valign="top">
    302307                        <th scope="row" class="titledesc">
    303                             <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
     308                            <label for="<?php echo esc_attr( $option['id'] ); ?>"><?php echo esc_html( $option['title'] ); ?></label>
    304309                            <?php echo $tooltip_html; ?>
    305310                        </th>
    306                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>">
     311                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>">
    307312                            <input
    308                                     name="<?php echo esc_attr( $value['id'] ); ?>"
    309                                     id="<?php echo esc_attr( $value['id'] ); ?>"
    310                                     type="<?php echo esc_attr( $value['type'] ); ?>"
    311                                     style="<?php echo esc_attr( $value['css'] ); ?>"
     313                                    name="<?php echo esc_attr( $option['id'] ); ?>"
     314                                    id="<?php echo esc_attr( $option['id'] ); ?>"
     315                                    type="<?php echo esc_attr( $option['type'] ); ?>"
     316                                    style="<?php echo esc_attr( $option['css'] ); ?>"
    312317                                    value="<?php echo esc_attr( $option_value ); ?>"
    313                                     class="<?php echo esc_attr( $value['class'] ); ?>"
    314                                     placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
    315                                     size="<?php echo esc_attr( $value['size'] ); ?>"
    316                                 <?php if ( $value['disabled'] ) : ?>
     318                                    class="<?php echo esc_attr( $option['class'] ); ?>"
     319                                    placeholder="<?php echo esc_attr( $option['placeholder'] ); ?>"
     320                                    size="<?php echo esc_attr( $option['size'] ); ?>"
     321                                <?php if ( $option['disabled'] ) : ?>
    317322                                    disabled="disabled"
    318323                                <?php endif; ?>
     
    329334                    <tr valign="top">
    330335                        <th scope="row" class="titledesc">
    331                             <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
     336                            <label for="<?php echo esc_attr( $option['id'] ); ?>"><?php echo esc_html( $option['title'] ); ?></label>
    332337                            <?php echo $tooltip_html; ?>
    333338                        </th>
    334                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>">&lrm;
     339                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>">&lrm;
    335340                            <span class="colorpickpreview"
    336341                                    style="background: <?php echo esc_attr( $option_value ); ?>"></span>
    337342                            <input
    338                                     name="<?php echo esc_attr( $value['id'] ); ?>"
    339                                     id="<?php echo esc_attr( $value['id'] ); ?>"
     343                                    name="<?php echo esc_attr( $option['id'] ); ?>"
     344                                    id="<?php echo esc_attr( $option['id'] ); ?>"
    340345                                    type="text"
    341346                                    dir="ltr"
    342                                     style="<?php echo esc_attr( $value['css'] ); ?>"
     347                                    style="<?php echo esc_attr( $option['css'] ); ?>"
    343348                                    value="<?php echo esc_attr( $option_value ); ?>"
    344                                     class="<?php echo esc_attr( $value['class'] ); ?>colorpick"
    345                                     placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
    346                                 <?php if ( $value['disabled'] ) : ?>
     349                                    class="<?php echo esc_attr( $option['class'] ); ?>colorpick"
     350                                    placeholder="<?php echo esc_attr( $option['placeholder'] ); ?>"
     351                                <?php if ( $option['disabled'] ) : ?>
    347352                                    disabled="disabled"
    348353                                <?php endif; ?>
    349354                                <?php echo implode( ' ', $custom_attributes ); ?>
    350355                            />&lrm; <?php echo $description; ?>
    351                             <div id="colorPickerDiv_<?php echo esc_attr( $value['id'] ); ?>" class="colorpickdiv"
     356                            <div id="colorPickerDiv_<?php echo esc_attr( $option['id'] ); ?>" class="colorpickdiv"
    352357                                    style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>
    353358                        </td>
     
    361366                    <tr valign="top">
    362367                        <th scope="row" class="titledesc">
    363                             <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
     368                            <label for="<?php echo esc_attr( $option['id'] ); ?>"><?php echo esc_html( $option['title'] ); ?></label>
    364369                            <?php echo $tooltip_html; ?>
    365370                        </th>
    366                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>">
     371                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>">
    367372                            <?php echo $description; ?>
    368373
    369374                            <textarea
    370                                     name="<?php echo esc_attr( $value['id'] ); ?>"
    371                                     id="<?php echo esc_attr( $value['id'] ); ?>"
    372                                     style="<?php echo esc_attr( $value['css'] ); ?>"
    373                                     class="<?php echo esc_attr( $value['class'] ); ?>"
    374                                     placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
     375                                    name="<?php echo esc_attr( $option['id'] ); ?>"
     376                                    id="<?php echo esc_attr( $option['id'] ); ?>"
     377                                    style="<?php echo esc_attr( $option['css'] ); ?>"
     378                                    class="<?php echo esc_attr( $option['class'] ); ?>"
     379                                    placeholder="<?php echo esc_attr( $option['placeholder'] ); ?>"
    375380                                <?php echo implode( ' ', $custom_attributes ); ?>
    376                                 <?php if ( $value['disabled'] ) : ?>
     381                                <?php if ( $option['disabled'] ) : ?>
    377382                                    disabled="disabled"
    378383                                <?php endif; ?>
     
    389394                    <tr valign="top">
    390395                        <th scope="row" class="titledesc">
    391                             <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
     396                            <label for="<?php echo esc_attr( $option['id'] ); ?>"><?php echo esc_html( $option['title'] ); ?></label>
    392397                            <?php echo $tooltip_html; ?>
    393398                        </th>
    394                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>">
     399                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>">
    395400                            <select
    396                                     name="<?php echo esc_attr( $value['id'] ); ?><?php echo ( 'multiselect' === $value['type'] ) ? '[]' : ''; ?>"
    397                                     id="<?php echo esc_attr( $value['id'] ); ?>"
    398                                     style="<?php echo esc_attr( $value['css'] ); ?>"
    399                                     class="<?php echo esc_attr( $value['class'] ); ?>"
     401                                    name="<?php echo esc_attr( $option['id'] ); ?><?php echo ( 'multiselect' === $option['type'] ) ? '[]' : ''; ?>"
     402                                    id="<?php echo esc_attr( $option['id'] ); ?>"
     403                                    style="<?php echo esc_attr( $option['css'] ); ?>"
     404                                    class="<?php echo esc_attr( $option['class'] ); ?>"
    400405                                <?php echo implode( ' ', $custom_attributes ); ?>
    401                                 <?php echo ( 'multiselect' == $value['type'] ) ? 'multiple="multiple"' : ''; ?>
    402                                 <?php if ( $value['disabled'] ) : ?>
     406                                <?php echo ( 'multiselect' == $option['type'] ) ? 'multiple="multiple"' : ''; ?>
     407                                <?php if ( $option['disabled'] ) : ?>
    403408                                    disabled="disabled"
    404409                                <?php endif; ?>
    405410                            >
    406411                                <?php
    407                                 foreach ( $value['options'] as $key => $val ) {
     412                                foreach ( $option['options'] as $key => $val ) {
    408413                                    ?>
    409414                                    <option value="<?php echo esc_attr( $key ); ?>"
     
    432437                    <tr valign="top">
    433438                        <th scope="row" class="titledesc">
    434                             <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
     439                            <label for="<?php echo esc_attr( $option['id'] ); ?>"><?php echo esc_html( $option['title'] ); ?></label>
    435440                            <?php echo $tooltip_html; ?>
    436441                        </th>
    437                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>">
     442                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>">
    438443                            <fieldset
    439                                 <?php if ( $value['disabled'] ) : ?>
     444                                <?php if ( $option['disabled'] ) : ?>
    440445                                    disabled="disabled"
    441446                                <?php endif; ?>
     
    444449                                <ul>
    445450                                    <?php
    446                                     foreach ( $value['options'] as $key => $val ) {
     451                                    foreach ( $option['options'] as $key => $val ) {
    447452                                        ?>
    448453                                        <li>
    449454                                            <label>
    450455                                                <input
    451                                                         name="<?php echo esc_attr( $value['id'] ); ?>"
     456                                                        name="<?php echo esc_attr( $option['id'] ); ?>"
    452457                                                        value="<?php echo $key; ?>"
    453458                                                        type="radio"
    454                                                         style="<?php echo esc_attr( $value['css'] ); ?>"
    455                                                         class="<?php echo esc_attr( $value['class'] ); ?>"
     459                                                        style="<?php echo esc_attr( $option['css'] ); ?>"
     460                                                        class="<?php echo esc_attr( $option['class'] ); ?>"
    456461                                                    <?php echo implode( ' ', $custom_attributes ); ?>
    457462                                                    <?php checked( $key, $option_value ); ?>
     
    474479
    475480                    $visbility_class = array();
    476                     if ( ! isset( $value['hide_if_checked'] ) ) {
    477                         $value['hide_if_checked'] = false;
    478                     }
    479                     if ( ! isset( $value['show_if_checked'] ) ) {
    480                         $value['show_if_checked'] = false;
    481                     }
    482                     if ( 'yes' == $value['hide_if_checked'] || 'yes' == $value['show_if_checked'] ) {
     481                    if ( ! isset( $option['hide_if_checked'] ) ) {
     482                        $option['hide_if_checked'] = false;
     483                    }
     484                    if ( ! isset( $option['show_if_checked'] ) ) {
     485                        $option['show_if_checked'] = false;
     486                    }
     487                    if ( 'yes' == $option['hide_if_checked'] || 'yes' == $option['show_if_checked'] ) {
    483488                        $visbility_class[] = 'hidden_option';
    484489                    }
    485                     if ( 'option' == $value['hide_if_checked'] ) {
     490                    if ( 'option' == $option['hide_if_checked'] ) {
    486491                        $visbility_class[] = 'hide_options_if_checked';
    487492                    }
    488                     if ( 'option' == $value['show_if_checked'] ) {
     493                    if ( 'option' == $option['show_if_checked'] ) {
    489494                        $visbility_class[] = 'show_options_if_checked';
    490495                    }
     
    492497                    <tr valign="top" class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>">
    493498                        <!--suppress XmlDefaultAttributeValue -->
    494                         <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?></th>
     499                        <th scope="row" class="titledesc"><?php echo esc_html( $option['title'] ); ?></th>
    495500                        <td class="forminp forminp-checkbox">
    496501                            <fieldset
    497                                 <?php if ( $value['disabled'] ) : ?>
     502                                <?php if ( $option['disabled'] ) : ?>
    498503                                    disabled="disabled"
    499504                                <?php endif; ?>
     
    501506                                <?php
    502507
    503                                 if ( ! empty( $value['title'] ) ) {
     508                                if ( ! empty( $option['title'] ) ) {
    504509                                    ?>
    505510                                    <legend class="screen-reader-text">
    506                                         <span><?php echo esc_html( $value['title'] ); ?></span>
     511                                        <span><?php echo esc_html( $option['title'] ); ?></span>
    507512                                    </legend>
    508513                                    <?php
    509514                                }
    510515                                ?>
    511                                 <label for="<?php echo $value['id']; ?>">
     516                                <label for="<?php echo $option['id']; ?>">
    512517                                    <input
    513                                             name="<?php echo esc_attr( $value['id'] ); ?>"
    514                                             id="<?php echo esc_attr( $value['id'] ); ?>"
     518                                            name="<?php echo esc_attr( $option['id'] ); ?>"
     519                                            id="<?php echo esc_attr( $option['id'] ); ?>"
    515520                                            type="checkbox"
    516                                             class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
     521                                            class="<?php echo esc_attr( isset( $option['class'] ) ? $option['class'] : '' ); ?>"
    517522                                            value="1"
    518523                                        <?php checked( $option_value, 'yes' ); ?>
     
    532537                        <!--suppress XmlDefaultAttributeValue -->
    533538                        <th scope="row" class="titledesc">
    534                             <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
     539                            <label for="<?php echo esc_attr( $option['id'] ); ?>"><?php echo esc_html( $option['title'] ); ?></label>
    535540                            <?php echo $tooltip_html; ?>
    536541                        </th>
    537                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>">
     542                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>">
    538543                            <div class="image-picker-form-container">
    539544                                <input
    540                                         name="<?php echo esc_attr( $value['id'] ); ?>"
    541                                         id="<?php echo esc_attr( $value['id'] ); ?>"
     545                                        name="<?php echo esc_attr( $option['id'] ); ?>"
     546                                        id="<?php echo esc_attr( $option['id'] ); ?>"
    542547                                        type="text"
    543                                         style="<?php echo esc_attr( $value['css'] ); ?>"
     548                                        style="<?php echo esc_attr( $option['css'] ); ?>"
    544549                                        value="<?php echo esc_attr( $option_value ); ?>"
    545                                         class="<?php echo esc_attr( $value['class'] ); ?>"
    546                                         placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
    547                                     <?php if ( $value['disabled'] ) : ?>
     550                                        class="<?php echo esc_attr( $option['class'] ); ?>"
     551                                        placeholder="<?php echo esc_attr( $option['placeholder'] ); ?>"
     552                                    <?php if ( $option['disabled'] ) : ?>
    548553                                        disabled="disabled"
    549554                                    <?php endif; ?>
     
    551556                                />
    552557                                <a
    553                                         id="upload_<?php echo esc_attr( $value['id'] ); ?>"
     558                                        id="upload_<?php echo esc_attr( $option['id'] ); ?>"
    554559                                        href="#"
    555560                                        class="button upload-image"
     
    582587                    ?>
    583588                    <tr valign="top">
    584                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>" colspan="2">
    585                             <p><?php echo $value['desc']; ?></p>
     589                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>" colspan="2">
     590                            <p><?php echo $option['desc']; ?></p>
    586591                        </td>
    587592                    </tr>
     
    591596                    ?>
    592597                    <tr valign="top">
    593                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>" colspan="2">
     598                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>" colspan="2">
    594599                            <hr/>
    595600                        </td>
     
    600605                    ?>
    601606                    <tr valign="top">
    602                         <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ); ?>" colspan="2">
    603                             <h2><?php echo esc_html( $value['title'] ); ?></h2>
     607                        <td class="forminp forminp-<?php echo sanitize_title( $option['type'] ); ?>" colspan="2">
     608                            <h2><?php echo esc_html( $option['title'] ); ?></h2>
    604609                        </td>
    605610                    </tr>
     
    611616                     * Allows to add additional settings type.
    612617                     *
    613                      * @param array  $value             The option data.
     618                     * @param array  $option             The option data.
    614619                     * @param mixed  $option_value      The option value.
    615620                     * @param string $description       The option description HTML.
     
    620625                     * @since 2.15.6 - Added additional options, beside `$value`.
    621626                     */
    622                     do_action( 'sm_admin_field_' . $value['type'], $value, $option_value, $description, $tooltip_html, $custom_attributes );
     627                    do_action( 'sm_admin_field_' . $option['type'], $option, $option_value, $description, $tooltip_html, $custom_attributes );
    623628                    break;
    624629            }
     
    635640     * given form field
    636641     *
    637      * @param  array $value The form field value array.
     642     * @param  array $option The option array.
    638643     *
    639644     * @return array The description and tip as a 2 element array
    640645     */
    641     public static function get_field_description( $value ) {
     646    public static function get_field_description( $option ) {
    642647        $description  = '';
    643648        $tooltip_html = '';
    644649
    645         if ( true === $value['desc_tip'] ) {
    646             $tooltip_html = $value['desc'];
    647         } elseif ( ! empty( $value['desc_tip'] ) ) {
    648             $description  = $value['desc'];
    649             $tooltip_html = $value['desc_tip'];
    650         } elseif ( ! empty( $value['desc'] ) ) {
    651             $description = $value['desc'];
    652         }
    653 
    654         if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
     650        if ( true === $option['desc_tip'] ) {
     651            $tooltip_html = $option['desc'];
     652        } elseif ( ! empty( $option['desc_tip'] ) ) {
     653            $description  = $option['desc'];
     654            $tooltip_html = $option['desc_tip'];
     655        } elseif ( ! empty( $option['desc'] ) ) {
     656            $description = $option['desc'];
     657        }
     658
     659        if ( $description && in_array( $option['type'], array( 'textarea', 'radio' ) ) ) {
    655660            $description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
    656         } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
     661        } elseif ( $description && in_array( $option['type'], array( 'checkbox' ) ) ) {
    657662            $description = wp_kses_post( $description );
    658         } elseif ( $description && in_array( $value['type'], array( 'select', 'multiselect' ) ) ) {
     663        } elseif ( $description && in_array( $option['type'], array( 'select', 'multiselect' ) ) ) {
    659664            $description = '<p class="description">' . $description . '</p>';
    660665        } elseif ( $description ) {
     
    662667        }
    663668
    664         if ( $tooltip_html && in_array( $value['type'], array( 'checkbox' ) ) ) {
     669        if ( $tooltip_html && in_array( $option['type'], array( 'checkbox' ) ) ) {
    665670            $tooltip_html = '<p class="description">' . $tooltip_html . '</p>';
    666671        } elseif ( $tooltip_html ) {
Note: See TracChangeset for help on using the changeset viewer.