Skip to content
This repository has been archived by the owner on Aug 8, 2022. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bmqy committed Aug 30, 2018
1 parent 90df57a commit 567ee90
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 63 deletions.
50 changes: 44 additions & 6 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,16 +1081,54 @@ function bmqynext_show_udpate_success(){

/*
* 后台显示表单项
* 表单名
* 字段名
* 表单名称
* 字段信息
* */
if(!function_exists('bmqynext_generate_form')){
function bmqynext_show_form_item($formName, $item=[]){
echo '<form action="" method="post" name="form1" novalidate="novalidate">'
function bmqynext_generate_form($formName='', $items=[], $action=''){

if(empty($formName) || !is_array($items)){
return false;
}

$formName = wp_get_theme()->get('TextDomain').'_'. $formName;
$html = '<form action="'. $action .'" method="post" name="'. $formName .'" novalidate="novalidate">'
.'<table class="form-table">';

echo '</table>'
.submit_button( __(\"Save Changes\"), \"primary\", $formName ))
foreach($items as $item=>$val){
if (is_array($items[$item])){
$itemArr = $items[$item];
$filed = $formName .'_'. $item;
$type = $itemArr['type'];
$name = __($itemArr['name'], 'bmqynext');
$placeholder = !empty($itemArr['placeholder']) ? $itemArr['placeholder'] : '' ;
$tips = !empty($itemArr['tips']) ? $itemArr['tips'] : '' ;
switch ($type){
case 'checkbox':
$html .= '<tr>
<th scope="row"><label for="'. $filed .'">'. $name .'</label></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span>'. $name .'</span></legend>
<label for="'. $filed .'"><input name="'. $filed .'" type="checkbox" id="'. $filed .'" value="1" '. checked(get_option($filed), true, false) .'>'. $tips .'</label>
</fieldset>
</td>
</tr>';
break;
case 'input':
$html .= '<tr>
<th scope="row"><label for="'. $filed .'">'. $name .'</label></th>
<td><input name="'. $filed .'" type="text" id="'. $filed .'" placeholder="'. $placeholder .'" value="" class="regular-text ltr"><p class="description" id="tagline-description">'. $tips .'</p></td>
</tr>';
break;
}
}
}

$html .= '</table>'
.get_submit_button( __("Save Changes"), "primary", $formName )
.'</form>';

echo $html;
}
}
2 changes: 1 addition & 1 deletion options/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function bmqynext_settings() {
<a href="<?php echo esc_url( add_query_arg( array( 'options' => 'ad' ), admin_url( 'themes.php?page=bmqynext_settings' ) ) ); ?>" class="nav-tab <?php if($options === 'ad') echo " nav-tab-active"?>"><?php esc_html_e('AD Settings', 'bmqynext') ?></a>
<a href="<?php echo esc_url( add_query_arg( array( 'options' => 'other' ), admin_url( 'themes.php?page=bmqynext_settings' ) ) ); ?>" class="nav-tab <?php if($options === 'other') echo " nav-tab-active"?>"><?php esc_html_e('Other Settings', 'bmqynext') ?></a>
</h2>
<div id="bmqynextOptionsFormBase">
<div id="bmqynextOptionsForm">
<?php
switch ($options){
case 'base':
Expand Down
127 changes: 71 additions & 56 deletions options/menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,72 @@
* Date: 2018-08-15
* Time: 13:20
*/
?>

<?php
$navMenu = array(
'icon' => array(
'type' => 'checkbox',
'name' => 'Nav Icon',
),
'home' => array(
'type' => 'input',
'name' => 'Home',
'placeholder' => '请输入图标',
'tips' => '设置显示的图标',
),
'category' => array(
'type' => 'input',
'name' => 'Category',
),
'about' => array(
'type' => 'input',
'name' => 'About',
),
'archives' => array(
'type' => 'input',
'name' => 'Archives',
),
'tag' => array(
'type' => 'input',
'name' => 'Tag',
),
'sitemap' => array(
'type' => 'input',
'name' => 'Sitemap',
)
);
$socialMenu = array(
'icon' => array(
'type' => 'checkbox',
'name' => 'Social Icon',
),
'weibo' => array(
'type' => 'input',
'name' => 'Weibo',
),
'zhihu' => array(
'type' => 'input',
'name' => 'Zhihu',
),
'github' => array(
'type' => 'input',
'name' => 'Github',
),
'google' => array(
'type' => 'input',
'name' => 'Google',
),
'twitter' => array(
'type' => 'input',
'name' => 'Twitter',
),
'facebook' => array(
'type' => 'input',
'name' => 'Facebook',
)
);


$bmqynext_options_menu = 'bmqynext_options_menu';
$bmqynext_opt_show_nav_icon_name = 'bmqynext_opt_show_nav_icon';
Expand Down Expand Up @@ -52,59 +118,8 @@

bmqynext_show_udpate_success();
}
?>
<form action="" method="post" name="form1" novalidate="novalidate">
<table class="form-table">
<tr>
<th scope="row"><label for="<?php echo $bmqynext_opt_show_nav_icon_name; ?>"><?php esc_html_e('Nav Icon', 'bmqynext') ?></label></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php esc_html_e('Nav Icon', 'bmqynext') ?></span></legend>
<label for="<?php echo $bmqynext_opt_show_nav_icon_name; ?>"><input name="<?php echo $bmqynext_opt_show_nav_icon_name; ?>" type="checkbox" id="<?php echo $bmqynext_opt_show_nav_icon_name; ?>" value="1" <?php checked( $bmqynext_opt_show_nav_icon_val ); ?> /></label>
</fieldset>
</td>
</tr>
<tr>
<th scope="row"><label for="topRecommendTitle"><?php esc_html_e('Home', 'bmqynext') ?></label></th>
<td><input name="<?php echo $bmqynext_opt_nav_home_name; ?>" type="text" id="<?php echo $bmqynext_opt_nav_home_name; ?>" value="<?php echo $bmqynext_opt_nav_home_val; ?>" class="regular-text ltr"/></td>
</tr>
<tr>
<th scope="row"><label for="topRecommendTitle"><?php esc_html_e('Category', 'bmqynext') ?></label></th>
<td><input name="<?php echo $bmqynext_opt_nav_category_name; ?>" type="text" id="<?php echo $bmqynext_opt_nav_category_name; ?>" value="<?php echo $bmqynext_opt_nav_category_val; ?>" class="regular-text ltr"/></td>
</tr>
<tr>
<th scope="row"><label for="topRecommendTitle"><?php esc_html_e('About', 'bmqynext') ?></label></th>
<td><input name="<?php echo $bmqynext_opt_nav_about_name; ?>" type="text" id="<?php echo $bmqynext_opt_nav_about_name; ?>" value="<?php echo $bmqynext_opt_nav_about_val; ?>" class="regular-text ltr"/></td>
</tr>
<tr>
<th scope="row"><label for="topRecommendTitle"><?php esc_html_e('Archives', 'bmqynext') ?></label></th>
<td><input name="<?php echo $bmqynext_opt_nav_archives_name; ?>" type="text" id="<?php echo $bmqynext_opt_nav_archives_name; ?>" value="<?php echo $bmqynext_opt_nav_archives_val; ?>" class="regular-text ltr"/></td>
</tr>
<tr>
<th scope="row"><label for="topRecommendTitle"><?php esc_html_e('Tag', 'bmqynext') ?></label></th>
<td><input name="<?php echo $bmqynext_opt_nav_tag_name; ?>" type="text" id="<?php echo $bmqynext_opt_nav_tag_name; ?>" value="<?php echo $bmqynext_opt_nav_tag_val; ?>" class="regular-text ltr"/></td>
</tr>
<tr>
<th scope="row"><label for="topRecommendTitle"><?php esc_html_e('Sitemap', 'bmqynext') ?></label></th>
<td><input name="<?php echo $bmqynext_opt_nav_sitemap_name; ?>" type="text" id="<?php echo $bmqynext_opt_nav_sitemap_name; ?>" value="<?php echo $bmqynext_opt_nav_sitemap_val; ?>" class="regular-text ltr"/></td>
</tr>
<tr>
<th scope="row"><label for="topRecommendTitle"><?php esc_html_e('Search', 'bmqynext') ?></label></th>
<td><input name="<?php echo $bmqynext_opt_nav_search_name; ?>" type="text" id="<?php echo $bmqynext_opt_nav_search_name; ?>" value="<?php echo $bmqynext_opt_nav_search_val; ?>" class="regular-text ltr"/></td>
</tr>
<tr>
<th scope="row"><label for="<?php echo $bmqynext_opt_show_social_icon_name; ?>"><?php esc_html_e('Social Icon', 'bmqynext') ?></label></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php esc_html_e('Social Icon', 'bmqynext') ?></span></legend>
<label for="<?php echo $bmqynext_opt_show_social_icon_name; ?>"><input name="<?php echo $bmqynext_opt_show_social_icon_name; ?>" type="checkbox" id="<?php echo $bmqynext_opt_show_social_icon_name; ?>" value="1" <?php checked( $bmqynext_opt_show_social_icon_val ); ?> /></label>
</fieldset>
</td>
</tr>
<tr>
<th scope="row"><label for="topRecommendTitle"><?php esc_html_e('Weibo', 'bmqynext') ?></label></th>
<td><input name="keyword" type="text" id="keyword" value="<?php echo $bmqynext_opt_keyword_val; ?>" class="regular-text ltr"/></td>
</tr>
</table>
<?php submit_button( __('Save Changes'), 'primary', $bmqynext_options_menu ); ?>
</form>

bmqynext_generate_form('options_nav', $navMenu);

bmqynext_generate_form('options_social', $socialMenu);
?>

0 comments on commit 567ee90

Please sign in to comment.