从gitee代码库中初始化项目。
This commit is contained in:
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Options_Framework
|
||||
* @author Devin Price <devin@wptheming.com>
|
||||
* @license GPL-2.0+
|
||||
* @link http://wptheming.com
|
||||
* @copyright 2010-2014 WP Theming
|
||||
*/
|
||||
|
||||
class Options_Framework_Admin {
|
||||
|
||||
/**
|
||||
* Page hook for the options screen
|
||||
*
|
||||
* @since 1.7.0
|
||||
* @type string
|
||||
*/
|
||||
protected $options_screen = null;
|
||||
|
||||
/**
|
||||
* Hook in the scripts and styles
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
// Gets options to load
|
||||
$options = & Options_Framework::_optionsframework_options();
|
||||
|
||||
// Checks if options are available
|
||||
if ( $options ) {
|
||||
|
||||
// Add the options page and menu item.
|
||||
add_action('admin_menu', array($this, 'add_top_options_page'));
|
||||
add_action('admin_menu', array($this, 'add_sub_options_page'));
|
||||
|
||||
// Add the required scripts and styles
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
|
||||
|
||||
// Settings need to be registered after admin_init
|
||||
add_action( 'admin_init', array( $this, 'settings_init' ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the settings
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
function settings_init() {
|
||||
|
||||
// Get the option name
|
||||
$options_framework = new Options_Framework;
|
||||
$name = $options_framework->get_option_name();
|
||||
|
||||
// Registers the settings fields and callback
|
||||
register_setting( 'optionsframework', $name, array ( $this, 'validate_options' ) );
|
||||
|
||||
// Displays notice after options save
|
||||
add_action( 'optionsframework_after_validate', array( $this, 'save_options_notice' ) );
|
||||
|
||||
add_action( 'optionsframework_after_sendmail', array( $this, 'send_mail_notice' ) );
|
||||
}
|
||||
|
||||
public function add_top_options_page()
|
||||
{
|
||||
add_menu_page(
|
||||
__('主题设置', 'kratos'),
|
||||
__('主题设置', 'kratos'),
|
||||
'manage_options',
|
||||
'kratos_options',
|
||||
'',
|
||||
'dashicons-admin-generic',
|
||||
99
|
||||
);
|
||||
}
|
||||
|
||||
public static function menu_settings()
|
||||
{
|
||||
$menu = array(
|
||||
'parent_slug' => 'kratos_options',
|
||||
'page_title' => __('主题设置', 'kratos'),
|
||||
'menu_title' => __('主题设置', 'kratos'),
|
||||
'capability' => 'manage_options',
|
||||
'menu_slug' => 'kratos_options',
|
||||
);
|
||||
|
||||
return $menu;
|
||||
}
|
||||
|
||||
public function add_sub_options_page()
|
||||
{
|
||||
$menu = $this->menu_settings();
|
||||
|
||||
$this->options_screen = add_submenu_page(
|
||||
$menu['parent_slug'],
|
||||
$menu['page_title'],
|
||||
$menu['menu_title'],
|
||||
$menu['capability'],
|
||||
$menu['menu_slug'],
|
||||
array($this, 'options_page')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the required stylesheets
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
|
||||
function enqueue_admin_styles( $hook ) {
|
||||
|
||||
if ( $this->options_screen != $hook )
|
||||
return;
|
||||
|
||||
wp_enqueue_style( 'optionsframework', get_stylesheet_directory_uri() . '/inc/options-framework/css/optionsframework.css', array(), Options_Framework::VERSION );
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the required javascript
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
function enqueue_admin_scripts( $hook ) {
|
||||
|
||||
if ( $this->options_screen != $hook )
|
||||
return;
|
||||
|
||||
// Enqueue custom option panel JS
|
||||
wp_enqueue_script(
|
||||
'options-custom',
|
||||
get_stylesheet_directory_uri() . '/inc/options-framework/js/options-custom.js',
|
||||
array( 'jquery','wp-color-picker' ),
|
||||
Options_Framework::VERSION
|
||||
);
|
||||
|
||||
// Inline scripts from options-interface.php
|
||||
add_action( 'admin_head', array( $this, 'of_admin_head' ) );
|
||||
}
|
||||
|
||||
function of_admin_head() {
|
||||
// Hook to add custom scripts
|
||||
do_action( 'optionsframework_custom_scripts' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds out the options panel.
|
||||
*
|
||||
* If we were using the Settings API as it was intended we would use
|
||||
* do_settings_sections here. But as we don't want the settings wrapped in a table,
|
||||
* we'll call our own custom optionsframework_fields. See options-interface.php
|
||||
* for specifics on how each individual field is generated.
|
||||
*
|
||||
* Nonces are provided using the settings_fields()
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
function options_page() { ?>
|
||||
|
||||
<div id="optionsframework-wrap" class="wrap">
|
||||
|
||||
<?php $menu = $this->menu_settings(); ?>
|
||||
<h2><?php echo esc_html( $menu['page_title'] ); ?></h2>
|
||||
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<?php echo Options_Framework_Interface::optionsframework_tabs(); ?>
|
||||
</h2>
|
||||
|
||||
<?php settings_errors( 'options-framework' ); ?>
|
||||
|
||||
<div id="optionsframework-metabox" class="metabox-holder">
|
||||
<div id="optionsframework" class="postbox">
|
||||
<form action="options.php" method="post">
|
||||
<?php settings_fields( 'optionsframework' ); ?>
|
||||
<?php Options_Framework_Interface::optionsframework_fields(); /* Settings */ ?>
|
||||
<div id="optionsframework-submit">
|
||||
<input type="submit" class="button-primary" name="update" value="<?php esc_attr_e( '保存配置', 'kratos' ); ?>" />
|
||||
<input type="submit" class="reset-button button-secondary" name="reset" value="<?php esc_attr_e( '恢复默认', 'kratos' ); ?>" onclick="return confirm( '<?php print esc_js( __( '单击「确定」进行恢复,但所有的配置都将丢失!', 'kratos' ) ); ?>' );" />
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</form>
|
||||
</div> <!-- / #container -->
|
||||
</div>
|
||||
<?php do_action( 'optionsframework_after' ); ?>
|
||||
</div> <!-- / .wrap -->
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Options.
|
||||
*
|
||||
* This runs after the submit/reset button has been clicked and
|
||||
* validates the inputs.
|
||||
*
|
||||
* @uses $_POST['reset'] to restore default options
|
||||
*/
|
||||
function validate_options( $input ) {
|
||||
|
||||
/*
|
||||
* Restore Defaults.
|
||||
*
|
||||
* In the event that the user clicked the "Restore Defaults"
|
||||
* button, the options defined in the theme's options.php
|
||||
* file will be added to the option for the active theme.
|
||||
*/
|
||||
|
||||
if ( isset( $_POST['reset'] ) ) {
|
||||
add_settings_error( 'options-framework', 'restore_defaults', __( '恢复完成', 'kratos' ), 'updated fade' );
|
||||
return $this->get_default_values();
|
||||
}
|
||||
|
||||
/*
|
||||
* Update Settings
|
||||
*
|
||||
* This used to check for $_POST['update'], but has been updated
|
||||
* to be compatible with the theme customizer introduced in WordPress 3.4
|
||||
*/
|
||||
|
||||
$clean = array();
|
||||
$options = & Options_Framework::_optionsframework_options();
|
||||
foreach ( $options as $option ) {
|
||||
|
||||
if ( ! isset( $option['id'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! isset( $option['type'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $option['id'] ) );
|
||||
|
||||
// Set checkbox to false if it wasn't sent in the $_POST
|
||||
if ( 'checkbox' == $option['type'] && ! isset( $input[$id] ) ) {
|
||||
$input[$id] = false;
|
||||
}
|
||||
|
||||
// Set each item in the multicheck to false if it wasn't sent in the $_POST
|
||||
if ( 'multicheck' == $option['type'] && ! isset( $input[$id] ) ) {
|
||||
foreach ( $option['options'] as $key => $value ) {
|
||||
$input[$id][$key] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// For a value to be submitted to database it must pass through a sanitization filter
|
||||
if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
|
||||
$clean[$id] = apply_filters( 'of_sanitize_' . $option['type'], $input[$id], $option );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $_POST['sendmail'] ) ) {
|
||||
wp_mail( get_bloginfo( 'admin_email' ) ,__('[测试]邮件服务配置成功', 'kratos'),__('恭喜您 SMTP 邮件服务配置成功!', 'kratos'));
|
||||
do_action( 'optionsframework_after_sendmail', $clean );
|
||||
return $clean;
|
||||
} else {
|
||||
do_action( 'optionsframework_after_validate', $clean );
|
||||
return $clean;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display message when options have been saved
|
||||
*/
|
||||
function save_options_notice() {
|
||||
add_settings_error( 'options-framework', 'save_options', __( '保存成功', 'kratos' ), 'updated fade' );
|
||||
}
|
||||
|
||||
function send_mail_notice() {
|
||||
add_settings_error( 'options-framework', 'send_mail', __( '发送完成,请留意邮箱:' . get_bloginfo( 'admin_email' ), 'kratos' ), 'updated fade' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default values for all the theme options
|
||||
*
|
||||
* Get an array of all default values as set in
|
||||
* options.php. The 'id','std' and 'type' keys need
|
||||
* to be defined in the configuration array. In the
|
||||
* event that these keys are not present the option
|
||||
* will not be included in this function's output.
|
||||
*
|
||||
* @return array Re-keyed options configuration array.
|
||||
*
|
||||
*/
|
||||
function get_default_values() {
|
||||
$output = array();
|
||||
$config = & Options_Framework::_optionsframework_options();
|
||||
foreach ( (array) $config as $option ) {
|
||||
if ( ! isset( $option['id'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $option['std'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $option['type'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
|
||||
$output[$option['id']] = apply_filters( 'of_sanitize_' . $option['type'], $option['std'], $option );
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Options_Framework
|
||||
* @author Devin Price <devin@wptheming.com>
|
||||
* @license GPL-2.0+
|
||||
* @link http://wptheming.com
|
||||
* @copyright 2010-2014 WP Theming
|
||||
*/
|
||||
|
||||
class Options_Framework {
|
||||
|
||||
/**
|
||||
* Plugin version, used for cache-busting of style and script file references.
|
||||
*
|
||||
* @since 1.7.0
|
||||
* @type string
|
||||
*/
|
||||
const VERSION = '1.9.1';
|
||||
|
||||
/**
|
||||
* Gets option name
|
||||
*
|
||||
* @since 1.9.0
|
||||
*/
|
||||
function get_option_name() {
|
||||
|
||||
$name = 'kratos';
|
||||
|
||||
return apply_filters( 'options_framework_option_name', $name );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for optionsframework_options()
|
||||
*
|
||||
* Allows for manipulating or setting options via 'of_options' filter
|
||||
* For example:
|
||||
*
|
||||
* <code>
|
||||
* add_filter( 'of_options', function( $options ) {
|
||||
* $options[] = array(
|
||||
* 'name' => 'Input Text Mini',
|
||||
* 'desc' => 'A mini text input field.',
|
||||
* 'id' => 'example_text_mini',
|
||||
* 'std' => 'Default',
|
||||
* 'class' => 'mini',
|
||||
* 'type' => 'text'
|
||||
* );
|
||||
*
|
||||
* return $options;
|
||||
* });
|
||||
* </code>
|
||||
*
|
||||
* Also allows for setting options via a return statement in the
|
||||
* options.php file. For example (in options.php):
|
||||
*
|
||||
* <code>
|
||||
* return array(...);
|
||||
* </code>
|
||||
*
|
||||
* @return array (by reference)
|
||||
*/
|
||||
static function &_optionsframework_options() {
|
||||
static $options = null;
|
||||
|
||||
if ( !$options ) {
|
||||
// Load options from options.php file (if it exists)
|
||||
$location = apply_filters( 'options_framework_location', array( 'theme-options.php' ) );
|
||||
$options = kratos_options();
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Options_Framework
|
||||
* @author Devin Price <devin@wptheming.com>
|
||||
* @license GPL-2.0+
|
||||
* @link http://wptheming.com
|
||||
* @copyright 2010-2014 WP Theming
|
||||
*/
|
||||
|
||||
class Options_Framework_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Generates the tabs that are used in the options menu
|
||||
*/
|
||||
public static function optionsframework_tabs()
|
||||
{
|
||||
$counter = 0;
|
||||
$options = &Options_Framework::_optionsframework_options();
|
||||
$menu = '';
|
||||
|
||||
foreach ($options as $value) {
|
||||
// Heading for Navigation
|
||||
if ($value['type'] == "heading") {
|
||||
$counter++;
|
||||
$class = '';
|
||||
$class = !empty($value['id']) ? $value['id'] : $value['name'];
|
||||
$class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class)) . '-tab';
|
||||
$menu .= '<a id="options-group-' . $counter . '-tab" class="nav-tab ' . $class . '" title="' . esc_attr($value['name']) . '" href="' . esc_attr('#options-group-' . $counter) . '">' . esc_html($value['name']) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
return $menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the options fields that are used in the form.
|
||||
*/
|
||||
public static function optionsframework_fields()
|
||||
{
|
||||
|
||||
global $allowedtags;
|
||||
|
||||
$options_framework = new Options_Framework;
|
||||
$option_name = $options_framework->get_option_name();
|
||||
$settings = get_option($option_name);
|
||||
$options = &Options_Framework::_optionsframework_options();
|
||||
|
||||
$counter = 0;
|
||||
$menu = '';
|
||||
|
||||
foreach ($options as $value) {
|
||||
|
||||
$val = '';
|
||||
$select_value = '';
|
||||
$output = '';
|
||||
|
||||
// Wrap all options
|
||||
if (($value['type'] != "heading") && ($value['type'] != "info") && ($value['type'] != "about")) {
|
||||
|
||||
// Keep all ids lowercase with no spaces
|
||||
$value['id'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['id']));
|
||||
|
||||
$id = 'section-' . $value['id'];
|
||||
|
||||
$class = 'section';
|
||||
if (isset($value['type'])) {
|
||||
$class .= ' section-' . $value['type'];
|
||||
}
|
||||
if (isset($value['class'])) {
|
||||
$class .= ' ' . $value['class'];
|
||||
}
|
||||
|
||||
$output .= '<div id="' . esc_attr($id) . '" class="' . esc_attr($class) . '">' . "\n";
|
||||
if (isset($value['name'])) {
|
||||
$output .= '<h4 class="heading">' . esc_html($value['name']) . '</h4>' . "\n";
|
||||
}
|
||||
if ($value['type'] != 'editor') {
|
||||
$output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
|
||||
} else {
|
||||
$output .= '<div class="option">' . "\n" . '<div>' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Set default value to $val
|
||||
if (isset($value['std'])) {
|
||||
$val = $value['std'];
|
||||
}
|
||||
|
||||
// If the option is already saved, override $val
|
||||
if (($value['type'] != 'heading') && ($value['type'] != 'info') && ($value['type'] != "about")) {
|
||||
if (isset($settings[($value['id'])])) {
|
||||
$val = $settings[($value['id'])];
|
||||
// Striping slashes of non-array options
|
||||
if (!is_array($val)) {
|
||||
$val = stripslashes($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is a description save it for labels
|
||||
$explain_value = '';
|
||||
if (isset($value['desc'])) {
|
||||
$explain_value = $value['desc'];
|
||||
}
|
||||
|
||||
// Set the placeholder if one exists
|
||||
$placeholder = '';
|
||||
if (isset($value['placeholder'])) {
|
||||
$placeholder = ' placeholder="' . esc_attr($value['placeholder']) . '"';
|
||||
}
|
||||
|
||||
if (has_filter('optionsframework_' . $value['type'])) {
|
||||
$output .= apply_filters('optionsframework_' . $value['type'], $option_name, $value, $val);
|
||||
}
|
||||
|
||||
switch ($value['type']) {
|
||||
|
||||
// Basic text input
|
||||
case 'text':
|
||||
$output .= '<input id="' . esc_attr($value['id']) . '" class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" type="text" value="' . esc_attr($val) . '"' . $placeholder . ' />';
|
||||
break;
|
||||
|
||||
// Password input
|
||||
case 'password':
|
||||
$output .= '<input id="' . esc_attr($value['id']) . '" class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" type="password" value="' . esc_attr($val) . '" />';
|
||||
break;
|
||||
|
||||
// Textarea
|
||||
case 'textarea':
|
||||
$rows = '8';
|
||||
|
||||
if (isset($value['settings']['rows'])) {
|
||||
$custom_rows = $value['settings']['rows'];
|
||||
if (is_numeric($custom_rows)) {
|
||||
$rows = $custom_rows;
|
||||
}
|
||||
}
|
||||
|
||||
$val = stripslashes($val);
|
||||
$output .= '<textarea id="' . esc_attr($value['id']) . '" class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" rows="' . $rows . '"' . $placeholder . '>' . esc_textarea($val) . '</textarea>';
|
||||
break;
|
||||
|
||||
// Select Box
|
||||
case 'select':
|
||||
$output .= '<select class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" id="' . esc_attr($value['id']) . '">';
|
||||
|
||||
foreach ($value['options'] as $key => $option) {
|
||||
$output .= '<option' . selected($val, $key, false) . ' value="' . esc_attr($key) . '">' . esc_html($option) . '</option>';
|
||||
}
|
||||
$output .= '</select>';
|
||||
break;
|
||||
|
||||
// Radio Box
|
||||
case "radio":
|
||||
$name = $option_name . '[' . $value['id'] . ']';
|
||||
foreach ($value['options'] as $key => $option) {
|
||||
$id = $option_name . '-' . $value['id'] . '-' . $key;
|
||||
$output .= '<input class="of-input of-radio" type="radio" name="' . esc_attr($name) . '" id="' . esc_attr($id) . '" value="' . esc_attr($key) . '" ' . checked($val, $key, false) . ' /><label for="' . esc_attr($id) . '">' . esc_html($option) . '</label>';
|
||||
}
|
||||
break;
|
||||
|
||||
// Image Selectors
|
||||
case "images":
|
||||
$name = $option_name . '[' . $value['id'] . ']';
|
||||
foreach ($value['options'] as $key => $option) {
|
||||
$selected = '';
|
||||
if ($val != '' && ($val == $key)) {
|
||||
$selected = ' of-radio-img-selected';
|
||||
}
|
||||
$output .= '<input type="radio" id="' . esc_attr($value['id'] . '_' . $key) . '" class="of-radio-img-radio" value="' . esc_attr($key) . '" name="' . esc_attr($name) . '" ' . checked($val, $key, false) . ' />';
|
||||
$output .= '<div class="of-radio-img-label">' . esc_html($key) . '</div>';
|
||||
$output .= '<img src="' . esc_url($option) . '" alt="' . $option . '" class="of-radio-img-img' . $selected . '" onclick="document.getElementById(\'' . esc_attr($value['id'] . '_' . $key) . '\').checked=true;" />';
|
||||
}
|
||||
break;
|
||||
|
||||
// Checkbox
|
||||
case "checkbox":
|
||||
$output .= '<input id="' . esc_attr($value['id']) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" ' . checked($val, 1, false) . ' />';
|
||||
$output .= '<label class="explain" for="' . esc_attr($value['id']) . '">' . wp_kses($explain_value, $allowedtags) . '</label>';
|
||||
break;
|
||||
|
||||
// Color picker
|
||||
case "color":
|
||||
$default_color = '';
|
||||
if (isset($value['std'])) {
|
||||
if ($val != $value['std']) {
|
||||
$default_color = ' data-default-color="' . $value['std'] . '" ';
|
||||
}
|
||||
|
||||
}
|
||||
$output .= '<input name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" id="' . esc_attr($value['id']) . '" class="of-color" type="text" value="' . esc_attr($val) . '"' . $default_color . ' />';
|
||||
|
||||
break;
|
||||
|
||||
// Uploader
|
||||
case "upload":
|
||||
$output .= Options_Framework_Media_Uploader::optionsframework_uploader($value['id'], $val, null);
|
||||
|
||||
break;
|
||||
|
||||
case "info":
|
||||
$id = '';
|
||||
$class = 'section';
|
||||
if (isset($value['id'])) {
|
||||
$id = 'id="' . esc_attr($value['id']) . '" ';
|
||||
}
|
||||
if (isset($value['type'])) {
|
||||
$class .= ' section-' . $value['type'];
|
||||
}
|
||||
if (isset($value['class'])) {
|
||||
$class .= ' ' . $value['class'];
|
||||
}
|
||||
|
||||
$output .= '<div ' . $id . 'class="' . esc_attr($class) . '">' . "\n";
|
||||
if (isset($value['name'])) {
|
||||
$output .= '<h4 class="heading">' . esc_html($value['name']) . '</h4>' . "\n";
|
||||
}
|
||||
if (isset($value['desc'])) {
|
||||
$output .= $value['desc'] . "\n";
|
||||
}
|
||||
$output .= '</div>' . "\n";
|
||||
break;
|
||||
case "sendmail":
|
||||
$output .= '<input type="submit" name="sendmail" class="button-secondary" value="' . __('测试邮件', 'kratos') . '">';
|
||||
break;
|
||||
|
||||
// Heading for Navigation
|
||||
case "heading":
|
||||
$counter++;
|
||||
if ($counter >= 2) {
|
||||
$output .= '</div>' . "\n";
|
||||
}
|
||||
$class = '';
|
||||
$class = !empty($value['id']) ? $value['id'] : $value['name'];
|
||||
$class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class));
|
||||
$output .= '<div id="options-group-' . $counter . '" class="group ' . $class . '">';
|
||||
$output .= '<h3>' . esc_html($value['name']) . '</h3>' . "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if (($value['type'] != "heading") && ($value['type'] != "info") && ($value['type'] != "about")) {
|
||||
$output .= '</div>';
|
||||
if (($value['type'] != "checkbox") && ($value['type'] != "editor")) {
|
||||
$output .= '<div class="explain">' . wp_kses($explain_value, $allowedtags) . '</div>' . "\n";
|
||||
}
|
||||
$output .= '</div></div>' . "\n";
|
||||
}
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
// Outputs closing div if there tabs
|
||||
if (Options_Framework_Interface::optionsframework_tabs() != '') {
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Options_Framework
|
||||
* @author Devin Price <devin@wptheming.com>
|
||||
* @license GPL-2.0+
|
||||
* @link http://wptheming.com
|
||||
* @copyright 2010-2014 WP Theming
|
||||
*/
|
||||
|
||||
class Options_Framework_Media_Uploader {
|
||||
|
||||
/**
|
||||
* Initialize the media uploader class
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public function init() {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'optionsframework_media_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Media Uploader Using the WordPress Media Library.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* string $_id - A token to identify this field (the name).
|
||||
* string $_value - The value of the field, if present.
|
||||
* string $_desc - An optional description of the field.
|
||||
*
|
||||
*/
|
||||
|
||||
static function optionsframework_uploader( $_id, $_value, $_desc = '', $_name = '' ) {
|
||||
|
||||
// Gets the unique option id
|
||||
$options_framework = new Options_Framework;
|
||||
$option_name = $options_framework->get_option_name();
|
||||
|
||||
$output = '';
|
||||
$id = '';
|
||||
$class = '';
|
||||
$int = '';
|
||||
$value = '';
|
||||
$name = '';
|
||||
|
||||
$id = strip_tags( strtolower( $_id ) );
|
||||
|
||||
// If a value is passed and we don't have a stored value, use the value that's passed through.
|
||||
if ( $_value != '' && $value == '' ) {
|
||||
$value = $_value;
|
||||
}
|
||||
|
||||
if ($_name != '') {
|
||||
$name = $_name;
|
||||
}
|
||||
else {
|
||||
$name = $option_name.'['.$id.']';
|
||||
}
|
||||
|
||||
if ( $value ) {
|
||||
$class = ' has-file';
|
||||
}
|
||||
$output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="'.$name.'" value="' . $value . '" placeholder="' . __('没有选择任何文件', 'kratos') .'" />' . "\n";
|
||||
if ( function_exists( 'wp_enqueue_media' ) ) {
|
||||
if ( ( $value == '' ) ) {
|
||||
$output .= '<input id="upload-' . $id . '" class="upload-button button" type="button" value="' . __( '上传', 'kratos' ) . '" />' . "\n";
|
||||
} else {
|
||||
$output .= '<input id="remove-' . $id . '" class="remove-file button" type="button" value="' . __( '删除', 'kratos' ) . '" />' . "\n";
|
||||
}
|
||||
} else {
|
||||
$output .= '<p><i>' . __( '升级 WordPress 版本获得完整的媒体支持', 'kratos' ) . '</i></p>';
|
||||
}
|
||||
|
||||
if ( $_desc != '' ) {
|
||||
$output .= '<span class="of-metabox-desc">' . $_desc . '</span>' . "\n";
|
||||
}
|
||||
|
||||
$output .= '<div class="screenshot" id="' . $id . '-image">' . "\n";
|
||||
|
||||
if ( $value != '' ) {
|
||||
$remove = '<a class="remove-image">删除</a>';
|
||||
$image = preg_match( '/(^.*\.jpg|jpeg|png|gif|svg|ico*)/i', $value );
|
||||
if ( $image ) {
|
||||
$output .= '<img src="' . $value . '" alt="" />' . $remove;
|
||||
} else {
|
||||
$parts = explode( "/", $value );
|
||||
for( $i = 0; $i < sizeof( $parts ); ++$i ) {
|
||||
$title = $parts[$i];
|
||||
}
|
||||
|
||||
// No output preview if it's not an image.
|
||||
$output .= '';
|
||||
|
||||
// Standard generic output if it's not an image.
|
||||
$title = __( '浏览文件', 'kratos' );
|
||||
$output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">'.$title.'</a></span></div>';
|
||||
}
|
||||
}
|
||||
$output .= '</div>' . "\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts for file uploader
|
||||
*/
|
||||
function optionsframework_media_scripts( $hook ) {
|
||||
|
||||
$menu = Options_Framework_Admin::menu_settings();
|
||||
|
||||
if ( substr( $hook, -strlen( $menu['menu_slug'] ) ) !== $menu['menu_slug'] )
|
||||
return;
|
||||
|
||||
if ( function_exists( 'wp_enqueue_media' ) )
|
||||
wp_enqueue_media();
|
||||
|
||||
wp_register_script( 'of-media-uploader', get_stylesheet_directory_uri() . '/inc/options-framework/js/media-uploader.js', array( 'jquery' ), Options_Framework::VERSION );
|
||||
wp_enqueue_script( 'of-media-uploader' );
|
||||
wp_localize_script( 'of-media-uploader', 'optionsframework_l10n', array(
|
||||
'upload' => __( '上传', 'kratos' ),
|
||||
'remove' => __( '删除', 'kratos' )
|
||||
) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Options_Framework
|
||||
* @author Devin Price <devin@wptheming.com>
|
||||
* @license GPL-2.0+
|
||||
* @link http://wptheming.com
|
||||
* @copyright 2010-2014 WP Theming
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sanitization for text input
|
||||
*
|
||||
* @link http://developer.wordpress.org/reference/functions/sanitize_text_field/
|
||||
*/
|
||||
add_filter( 'of_sanitize_text', 'sanitize_text_field' );
|
||||
|
||||
/**
|
||||
* Sanitization for password input
|
||||
*
|
||||
* @link http://developer.wordpress.org/reference/functions/sanitize_text_field/
|
||||
*/
|
||||
add_filter( 'of_sanitize_password', 'sanitize_text_field' );
|
||||
|
||||
/**
|
||||
* Sanitization for select input
|
||||
*
|
||||
* Validates that the selected option is a valid option.
|
||||
*/
|
||||
add_filter( 'of_sanitize_select', 'of_sanitize_enum', 10, 2 );
|
||||
|
||||
/**
|
||||
* Sanitization for radio input
|
||||
*
|
||||
* Validates that the selected option is a valid option.
|
||||
*/
|
||||
add_filter( 'of_sanitize_radio', 'of_sanitize_enum', 10, 2 );
|
||||
|
||||
/**
|
||||
* Sanitization for image selector
|
||||
*
|
||||
* Validates that the selected option is a valid option.
|
||||
*/
|
||||
add_filter( 'of_sanitize_images', 'of_sanitize_enum', 10, 2 );
|
||||
|
||||
/**
|
||||
* Sanitization for textarea field
|
||||
*
|
||||
* @param $input string
|
||||
* @return $output sanitized string
|
||||
*/
|
||||
function of_sanitize_textarea( $input ) {
|
||||
global $allowedposttags;
|
||||
$output = wp_kses( $input, $allowedposttags );
|
||||
return $output;
|
||||
}
|
||||
add_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
|
||||
|
||||
/**
|
||||
* Sanitization for checkbox input
|
||||
*
|
||||
* @param $input string (1 or empty) checkbox state
|
||||
* @return $output '1' or false
|
||||
*/
|
||||
function of_sanitize_checkbox( $input ) {
|
||||
if ( $input ) {
|
||||
$output = '1';
|
||||
} else {
|
||||
$output = false;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
add_filter( 'of_sanitize_checkbox', 'of_sanitize_checkbox' );
|
||||
|
||||
/**
|
||||
* File upload sanitization.
|
||||
*
|
||||
* Returns a sanitized filepath if it has a valid extension.
|
||||
*
|
||||
* @param string $input filepath
|
||||
* @returns string $output filepath
|
||||
*/
|
||||
function of_sanitize_upload( $input ) {
|
||||
$output = '';
|
||||
$filetype = wp_check_filetype( $input );
|
||||
if ( $filetype["ext"] ) {
|
||||
$output = esc_url( $input );
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
add_filter( 'of_sanitize_upload', 'of_sanitize_upload' );
|
||||
|
||||
/**
|
||||
* Sanitization of input with allowed tags and wpautotop.
|
||||
*
|
||||
* Allows allowed tags in html input and ensures tags close properly.
|
||||
*
|
||||
* @param string $input
|
||||
* @returns string $output
|
||||
*/
|
||||
function of_sanitize_allowedtags( $input ) {
|
||||
global $allowedtags;
|
||||
$output = wpautop( wp_kses( $input, $allowedtags ) );
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitization of input with allowed post tags and wpautotop.
|
||||
*
|
||||
* Allows allowed post tags in html input and ensures tags close properly.
|
||||
*
|
||||
* @param string $input
|
||||
* @returns string $output
|
||||
*/
|
||||
function of_sanitize_allowedposttags( $input ) {
|
||||
global $allowedposttags;
|
||||
$output = wpautop( wp_kses( $input, $allowedposttags) );
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the $input is one of the avilable choices
|
||||
* for that specific option.
|
||||
*
|
||||
* @param string $input
|
||||
* @returns string $output
|
||||
*/
|
||||
function of_sanitize_enum( $input, $option ) {
|
||||
$output = '';
|
||||
if ( array_key_exists( $input, $option['options'] ) ) {
|
||||
$output = $input;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitization for background option.
|
||||
*
|
||||
* @returns array $output
|
||||
*/
|
||||
function of_sanitize_background( $input ) {
|
||||
|
||||
$output = wp_parse_args( $input, array(
|
||||
'color' => '',
|
||||
'image' => '',
|
||||
'repeat' => 'repeat',
|
||||
'position' => 'top center',
|
||||
'attachment' => 'scroll'
|
||||
) );
|
||||
|
||||
$output['color'] = apply_filters( 'of_sanitize_hex', $input['color'] );
|
||||
$output['image'] = apply_filters( 'of_sanitize_upload', $input['image'] );
|
||||
|
||||
return $output;
|
||||
}
|
||||
add_filter( 'of_sanitize_background', 'of_sanitize_background' );
|
||||
|
||||
/**
|
||||
* Sanitize a color represented in hexidecimal notation.
|
||||
*
|
||||
* @param string Color in hexidecimal notation. "#" may or may not be prepended to the string.
|
||||
* @param string The value that this function should return if it cannot be recognized as a color.
|
||||
* @return string
|
||||
*/
|
||||
|
||||
function of_sanitize_hex( $hex, $default = '' ) {
|
||||
if ( of_validate_hex( $hex ) ) {
|
||||
return $hex;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
add_filter( 'of_sanitize_color', 'of_sanitize_hex' );
|
||||
|
||||
/**
|
||||
* Is a given string a color formatted in hexidecimal notation?
|
||||
*
|
||||
* @param string Color in hexidecimal notation. "#" may or may not be prepended to the string.
|
||||
* @return bool
|
||||
*/
|
||||
function of_validate_hex( $hex ) {
|
||||
$hex = trim( $hex );
|
||||
/* Strip recognized prefixes. */
|
||||
if ( 0 === strpos( $hex, '#' ) ) {
|
||||
$hex = substr( $hex, 1 );
|
||||
}
|
||||
elseif ( 0 === strpos( $hex, '%23' ) ) {
|
||||
$hex = substr( $hex, 3 );
|
||||
}
|
||||
/* Regex match. */
|
||||
if ( 0 === preg_match( '/^[0-9a-fA-F]{6}$/', $hex ) ) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user