$option ) { $menu .= '' . esc_html( $option['title'] ) . ''; } echo $menu; } } function options_container( $option_name, $options ) { $output = ''; if( !empty($options) ) { foreach ( $options as $key => $option ) { $output .= '
'. "\n" .'

'.$option["summary"].'

'. "\n"; $output .= form_table_container( $option_name, $option["fields"] ); $output .= '
'; } } else { $output = '
未定义设置选项
'; } echo $output; } function form_table_container( $option_name, $fields ) { $output = ''; $settings = get_option( $option_name ); if( $fields ) { $output .= ''; foreach ( $fields as $var => $field ) { switch ( $field['type'] ) { case 'password': $rows = isset($field["rows"])?$field["rows"]:4; $class = isset($field["class"])?'class="'.$field["class"].'"':''; $placeholder = isset($field["placeholder"])?'placeholder="'.$field["placeholder"].'"':''; $value = isset($settings[$var])?'value="'. esc_attr( $settings[$var] ).'"':'value=""'; $output .= ''; break; case 'textarea': $rows = isset($field["rows"])?$field["rows"]:4; $cols = isset($field["cols"])?$field["cols"]:20; $class = isset($field["class"])?'class="'.$field["class"].'"':''; $placeholder = isset($field["placeholder"])?'placeholder="'.$field["placeholder"].'"':''; $output .= ''; break; case 'select': $value = isset($settings[$var])?$settings[$var]:''; $output .= ''; break; case "radio": $value = isset($settings[$var])?$settings[$var]:''; $output .= ''; break; case "radio-i": $value = isset($settings[$var])?$settings[$var]:''; $output .= ''; break; case "checkbox": $class = isset($field["class"])?'class="'.$field["class"].'"':''; $value = isset($settings[$var])?$settings[$var]:''; $output .= ''; break; case "color": $value = isset($settings[$var])?'value="'. esc_attr( $settings[$var] ).'"':'value=""'; $output .= ''; break; case "upload": $class = isset($field["class"])?'class="'.$field["class"].'"':''; $placeholder = isset($field["placeholder"])?'placeholder="'.$field["placeholder"].'"':''; $value = isset($settings[$var])?'value="'. esc_attr( $settings[$var] ).'"':'value=""'; $output .= ''; break; case "editor": $output .= ''; break; case "info": $value = isset($settings[$var])?'value="'. esc_attr( $settings[$var] ).'"':'value=""'; $output .= ''; $output .= ''; break; case "mu-check": $multicheck = $settings[$var]; $output .= ''; break; case "mu-text": $multexts = isset($settings[$var])?$settings[$var]:''; $class = isset($field["class"])?'class="'.$field["class"].'"':''; $placeholder = isset($field["placeholder"])?'placeholder="'.$field["placeholder"].'"':''; $output .= ''; break; default: $class = isset($field["class"])?'class="'.$field["class"].'"':''; $placeholder = isset($field["placeholder"])?'placeholder="'.$field["placeholder"].'"':''; $value = isset($settings[$var])?'value="'. esc_attr( $settings[$var] ).'"':'value=""'; $output .= ''; break; } } $output .= '
'; if(!isset($field["class"]) && isset($field['description']) && !empty($field['description'])) { $output .= ''.$field['description'].''; } if(isset($field["class"]) && isset($field['description']) && !empty($field['description'])) { $output .= '

'.$field['description'].'

'; } $output .= '
'; if(isset($field['description']) && !empty($field['description'])) { $output .= '

'.$field['description'].'

'; } $output .= '
'; if(isset($field['description']) && !empty($field['description'])) { $output .= ''.$field['description'].''; } $output .= '
'; foreach ($field['options'] as $key => $option ) { $output .= ''; } if(isset($field['description']) && !empty($field['description'])) { $output .= '

'.$field['description'].'

'; } $output .= '
'; foreach ($field['options'] as $key => $option ) { $output .= ''; } if(isset($field['description']) && !empty($field['description'])) { $output .= '

'.$field['description'].'

'; } $output .= '
'; if(isset($field['description']) && !empty($field['description'])) { $output .= ''.$field['description'].''; } $output .= '
'; if(isset($field['description']) && !empty($field['description'])) { $output .= ''.$field['description'].''; } $output .= '
'; if(isset($field['description']) && !empty($field['description'])) { $output .= '

'.$field['description'].'

'; } $output .= '
'; echo $output; $textarea_name = esc_attr( $option_name . '[' . $var. ']' ); $default_editor_settings = array( 'textarea_name' => $textarea_name, 'media_buttons' => false, 'tinymce' => array( 'plugins' => 'wordpress,wplink' ) ); $editor_settings = array(); if ( isset( $field['rows'] ) ) { $editor_settings = array( 'wpautop' => true, // Default 'textarea_rows' => $field['rows'], 'tinymce' => array( 'plugins' => 'wordpress,wplink' ) ); } $editor_settings = array_merge( $default_editor_settings, $editor_settings ); wp_editor( $settings[$var], $var, $editor_settings ); $output = ''; $output .= '
'.$field['description'].'
'; foreach ($field['options'] as $key => $option) { $checked = ''; if( isset($multicheck[$key]) ) { $checked = checked($multicheck[$key], 1, false); } $output .= '' . esc_html( $option ) . ''; } if(isset($field['description']) && !empty($field['description'])) { $output .= '

'.$field['description'].'

'; } $output .= '
'; if($multexts) { foreach ($multexts as $option) { if($option) { $output .= ''; } } } $output .= ''; $output .= '
'; if(!isset($field["class"]) && isset($field['description']) && !empty($field['description'])) { $output .= ''.$field['description'].''; } if(isset($field["class"]) && isset($field['description']) && !empty($field['description'])) { $output .= '

'.$field['description'].'

'; } $output .= '
'; } return $output; } if( ! function_exists('validate_sanitize_setting_options') ) { function validate_sanitize_setting_options( $options, $input ) { $clean = array( ); if( ! empty($options) ) { foreach( $options as $key => $option ) { $fields = $option["fields"]; foreach( $fields as $var => $field ) { if( ! isset( $var ) ) { continue; } if( ! isset( $field['type'] ) ) { continue; } $id = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $var ) ); if( 'checkbox' == $field['type'] && ! isset( $input[$id] ) ) { $input[$id] = false; } if( 'mu-check' == $field['type'] && ! isset( $input[$id] ) ) { foreach ( $field['options'] as $key => $value ) { $input[$id][$key] = false; } } if( 'mu-text' == $field['type'] && ! isset( $input[$id] ) ) { $input[$id] = false; } if( has_filter( 'setting_sanitize_' . $field['type'] ) ) { $clean[$id] = apply_filters( 'setting_sanitize_' . $field['type'], $input[$id], $field ); } } } } return $clean; } } if( ! function_exists('validate_sanitize_defalut_options') ) { function validate_sanitize_defalut_options( $options ) { $clean = array( ); foreach( (array) $options as $key => $option ) { $fields = $option["fields"]; foreach( $fields as $var => $field ) { if( ! isset( $var ) ) { continue; } if( ! isset( $field['type'] ) ) { continue; } $id = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $var ) ); if( has_filter( 'setting_sanitize_' . $field['type'] ) ) { $clean[$id] = apply_filters( 'setting_sanitize_' . $field['type'], null, $field ); } } } do_action( 'update_validate_defalut_options', $clean ); return $clean; } } if( ! function_exists('validate_sanitize_multi_field') ) { function validate_sanitize_multi_field( $data ) { if( is_object( $data ) ) { $data = (array)$data; } if( is_array( $data ) ) { $output = array( ); $fields = array_filter( $data ); if( count($fields) == 0 ) { return $output; } if( count( $data ) == count( $data, COUNT_RECURSIVE ) ) { return array_filter(array_merge($data)); } foreach( $data as $id => $field ) { if( is_array($field) ) { $_fields = array_filter( $field ); if( count($_fields) == 0 ) { continue; } else { $output[$id] = validate_sanitize_multi_field( array_merge( $field ) ); } } else { $output[$id] = sanitize_text_field( $field ); } } return array_merge( $output ); } return sanitize_text_field( $data ); } } if( ! function_exists('wp_applets_activty_bulletin') ) { function wp_applets_activty_bulletin( ) { $bulletin = get_transient( 'wp_applets_bulletin_cache' ); if( $bulletin === false ) { $url = 'https://mp.weitimes.com/wp-json/wp/v2/miniprogram/bulletin'; $request = wp_remote_get( $url ); if( !is_wp_error( $request ) ) { $bulletin = json_decode( $request['body'], true ); set_transient( 'wp_applets_bulletin_cache', $bulletin, 24*HOUR_IN_SECONDS ); } } if( isset($bulletin["status"]) && $bulletin["status"] == 200 ) { echo '
'.$bulletin["content"].'
'; } } } add_action( 'admin_notices', function ( ) { $screen = get_current_screen( ); if( isset($_GET['page']) && isset($_REQUEST['settings-updated']) ) { if( $screen->id !== 'toplevel_page_'.trim($_GET['page']) ) return; if( 'true' === $_GET['settings-updated'] ) { $class = 'notice notice-success is-dismissible'; $message = __( '设置已更新保存!', 'imahui' ); } else { $class = 'notice notice-warning is-dismissible'; $message = __( '对不起,更新出错啦,请检查!', 'imahui' ); } printf( '

%2$s

', esc_attr( $class ), esc_html( $message ) ); } } );