WC_Admin_Settings::get_option PHP Method

get_option() public static method

Get a setting from the settings API.
public static get_option ( mixed $option_name, $default = '' ) : string
$option_name mixed
return string
        public static function get_option($option_name, $default = '')
        {
            // Array value
            if (strstr($option_name, '[')) {
                parse_str($option_name, $option_array);
                // Option name is first key
                $option_name = current(array_keys($option_array));
                // Get value
                $option_values = get_option($option_name, '');
                $key = key($option_array[$option_name]);
                if (isset($option_values[$key])) {
                    $option_value = $option_values[$key];
                } else {
                    $option_value = null;
                }
                // Single value
            } else {
                $option_value = get_option($option_name, null);
            }
            if (is_array($option_value)) {
                $option_value = array_map('stripslashes', $option_value);
            } elseif (!is_null($option_value)) {
                $option_value = stripslashes($option_value);
            }
            return null === $option_value ? $default : $option_value;
        }

Usage Example

コード例 #1
0
ファイル: custom-textarea.php プロジェクト: yarwalker/ecobyt
    /**
     * Outputs a custom textarea template in plugin options panel
     *
     * @since   1.0.0
     * @return  void
     * @author  Alberto Ruggiero
     */
    public static function output($option)
    {
        $custom_attributes = array();
        if (!empty($option['custom_attributes']) && is_array($option['custom_attributes'])) {
            foreach ($option['custom_attributes'] as $attribute => $attribute_value) {
                $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($attribute_value) . '"';
            }
        }
        $option_value = WC_Admin_Settings::get_option($option['id'], $option['default']);
        ?>
        <tr valign="top">
            <th scope="row" class="titledesc">
                <label for="<?php 
        echo esc_attr($option['id']);
        ?>
"><?php 
        echo esc_html($option['title']);
        ?>
</label>
            </th>
            <td class="forminp forminp-<?php 
        echo sanitize_title($option['type']);
        ?>
">

                <textarea
                    name="<?php 
        echo esc_attr($option['id']);
        ?>
"
                    id="<?php 
        echo esc_attr($option['id']);
        ?>
"
                    style="<?php 
        echo esc_attr($option['css']);
        ?>
"
                    class="<?php 
        echo esc_attr($option['class']);
        ?>
"
                    <?php 
        echo implode(' ', $custom_attributes);
        ?>
                    ><?php 
        echo esc_textarea($option_value);
        ?>
</textarea><br /><br />
                <span class="description"><?php 
        echo $option['desc'];
        ?>
</span>
            </td>
        </tr>
    <?php 
    }
All Usage Examples Of WC_Admin_Settings::get_option