WordPress custom page

Insert picture description here

<?php
// 不允许直接访问此文件。  
if (!defined('ABSPATH')) {
    
    
  exit;
}
add_action('admin_menu', 'create_weixin_menu');  // 加载小程序配置页面
function create_weixin_menu()
{
    
    
  // 创建新的顶级菜单 
  $page_title = "小程序配置"; // 页面title标签信息
  $menu_title = "小程序配置"; //菜单标题
  $capability = "administrator"; // 权限      Subscriber 订阅者 Contributor 投稿者 Author 作者 Editor 编辑 Administrator 管理员
  $menu_slug = "app_setting"; //别名自己命名
  $function = "weixin_settings_page"; // 执行函数  https://1.klyd.cn/02/wordpress/wp-admin/admin.php?page=app_setting
  $icon_url = plugins_url('me-config/includes/images/icon16.png'); // 菜单图标url地址
  $position = 66; // 此菜单项在菜单中的位置,警告:如果两个菜单项的位置属性相同,其中一个可能要被覆盖  2 Dashboard 仪表盘 5 Posts 文章 10 Media 媒体 15 Links 链接 20 Pages 页面 25 Comments 评论 60 Appearance 外观 65 Plugins 插件 70 Users 用户 75 Tools 工具 80 Settings 设置

  // 调用注册设置函数 
  add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
  // 刚加载时数据库没有字段,所以,当提交时,注册 weixin-group【settings_fields('weixin-group');】 这个组里的local_appid字段
  add_action('admin_init', 'register_weixinsettings');
}


function register_weixinsettings()
{
    
    
  // 注册weixin-group组里的内容,并将其 设置改字段的值
  register_setting('weixin-group', 'local_appid');
  register_setting('weixin-group', 'local_secret');
  register_setting('weixin-group', 'local_mchid');
  register_setting('weixin-group', 'local_paykey');
  register_setting('weixin-group', 'local_paybody');
  register_setting('weixin-group', 'local_swipe');
  register_setting('weixin-group', 'local_display_categories');
  register_setting('weixin-group', 'local_enable_comment_option');
  register_setting('weixin-group', 'local_enable_comment_check');
  register_setting('weixin-group', 'local_poster_imageurl');
  register_setting('weixin-group', 'local_praise_word');
  register_setting('weixin-group', 'local_enterprise_minapp');
  register_setting('weixin-group', 'local_list_ad');
  register_setting('weixin-group', 'local_list_ad_id');
  register_setting('weixin-group', 'local_list_ad_every');
  register_setting('weixin-group', 'local_detail_ad');
  register_setting('weixin-group', 'local_detail_ad_id ');
}


function loding_res()
{
    
    

  // css
  // wp_register_style('local_css',  ME_BASE_URL . "includes/js/tab/tabs.css");
  wp_enqueue_style('local_css',  ME_BASE_URL . "includes/js/tab/tabs.css");

  // js
  // wp_register_script();
  wp_enqueue_script('local_js', ME_BASE_URL . "includes/js/tab/tabs.min.js");
}


function weixin_settings_page()
{
    
    
?>
  <div class="wrap">
    <h2>小程序设置</h2>
    <?php
    if (!empty($_REQUEST['settings-updated'])) {
    
    
      echo '<div id="message" class="updated fade"><p><strong>设置已保存</strong></p></div>';
    }
    // php最低版本要求版本
    if (version_compare(PHP_VERSION, '5.6.0', '<=')) {
    
    
      echo '<div class="notice notice-error is-dismissible"> <p><font color="red">提示:php版本小于5.6.0, 插件程序将无法正常使用,当前系统的php版本是:' . PHP_VERSION . '</font></p> </div>';
    }
    ?>
    <form method="post" action="options.php">
      <div class="responsive-tabs">
        <!--wordpressf常用函数 
        settings_ fields和do_ settings fields 是一对,输出随机数、动作、设置表单,
        需要注意的是该函数必须在设置页面的 form标签中调用。 

        -->

        <!--           添加组          -->
        <?php settings_fields('weixin-group'); ?>
        <?php do_settings_sections('weixin-group'); ?>
        <div class="responsive-tabs">
          <h2> 常规设置</h2>
          <div class="section">
            <table class="form-table">
              <tr valign="top"> <th scope="row">AppID</th> <!--  esc_attr 返回过滤后的字符串,即字面意思转义属性.此外还有esc_js() esc_url() esc_html() esc_sql() --> <td><input type="text" name="local_appid" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_appid')); ?>" />* </td> </tr>
              <tr valign="top"> <th scope="row">AppSecret</th> <td><input type="text" name="local_secret" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_secret')); ?>" />* </td> </tr>
              <tr valign="top"> <th scope="row">商户号MCHID</th> <td><input type="text" name="local_mchid" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_mchid')); ?>" /> <p style="color: #959595; display:inline">微信支付商户后台获取</p> </td> </tr>
              <tr valign="top"> <th scope="row">商户支付密钥key</th> <td><input type="text" name="local_paykey" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_paykey')); ?>" /> <p style="color: #959595; display:inline">微信支付商户后台获取</p> </td> </tr>
              <tr valign="top"> <th scope="row">支付描述</th> <td><input type="text" name="local_paybody" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_paybody')); ?>" />*              </td> </tr>


              <tr valign="top">
                <th scope="row">小程序首页滑动文章ID</th>
                <td><input type="text" name="local_swipe" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_swipe')); ?>" />
                  <p style="color: #959595; display:inline">* 请用英文半角逗号分隔</p>
                </td>
              </tr>

              <tr valign="top">
                <th scope="row">在小程序里显示的文章分类id</th>
                <td><input type="text" name="local_display_categories" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_display_categories')); ?>" />
                  <br />
                  <p style="color: #959595 ; display:inline">* 文章分类id,只支持一级分类,请用英文半角逗号分隔,留空则显示所有分类</p>
                </td>
              </tr>



              <tr valign="top">
                <th scope="row">开启小程序的评论</th>
                <td>

                  <?php

                  $local_enable_comment_option = get_option('local_enable_comment_option');
                  $checkbox = empty($local_enable_comment_option) ? '' : 'checked';
                  echo '<input name="local_enable_comment_option"  type="checkbox"  value="1" ' . $checkbox . ' />';


                  ?>
                  &emsp;&emsp;&emsp;&emsp;开启评论审核

                  <?php
                  $local_enable_comment_check = get_option('local_enable_comment_check');
                  $checkbox1 = empty($local_enable_comment_check) ? '' : 'checked';
                  echo '<input name="local_enable_comment_check"  type="checkbox"  value="1" ' . $checkbox1 . ' />';

                  ?>
                </td>
              </tr>

              <tr valign="top">
                <th scope="row">海报图片默认地址</th>
                <td><input type="text" name="local_poster_imageurl" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_poster_imageurl')); ?>" /><br />
                  <p style="color: #959595; display:inline">* 请输完整的图片地址,例如:https://www.watch-life.net/images/poster.jpg</p>
                </td>
              </tr>

              <tr valign="top">
                <th scope="row">"赞赏"文字调整为</th>
                <td><input type="text" name="local_praise_word" placeholder="喜欢" style="width:400px; height:40px" value="<?php echo esc_attr(get_option('local_praise_word')); ?>" /><br />
                  <p style="color: #959595; display:inline">* 例如:<code>鼓励</code>,<code>喜欢</code><code>稀罕</code>,不要超过两个汉字</p>
                </td>
              </tr>
 

            </table>
          </div>
          <h2>广告设置</h2>
          <div class="section">
            <table class="form-table">
              <tr valign="top">
                <th scope="row">开启文章列表广告</th>
                <td>
                  <?php
                  $local_list_ad = get_option('local_list_ad');
                  $checkbox = empty($local_list_ad) ? '' : 'checked';
                  echo '<input name="local_list_ad"  type="checkbox"  value="1" ' . $checkbox . ' />';
                  ?>
                  &emsp;&emsp;&emsp;广告id:&emsp;<input type="text" name="local_list_ad_id" style="width:300px; height:40px" value="<?php echo esc_attr(get_option('local_list_ad_id')); ?>" />
                  <br />&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<input type="number" name="local_list_ad_every" style="width:40px; height:40px" value="<?php echo esc_attr(get_option('local_list_ad_every')); ?>" />条列表展示一条广告<br />
                  <p style="color: #959595; display:inline">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;请输入整数,否则无法正常展示广告</p>
                </td>
                </td>
              </tr>

              <tr valign="top">
                <th scope="row">开启内容详情页广告</th>
                <td>

                  <?php
                  $local_detail_ad = get_option('local_detail_ad');
                  $checkbox = empty($local_detail_ad) ? '' : 'checked';
                  echo '<input name="local_detail_ad"  type="checkbox"  value="1" ' . $checkbox . ' />';
                  ?>
                  &emsp;&emsp;&emsp;广告id:&emsp;<input type="text" name="local_detail_ad_id" style="width:300px; height:40px" value="<?php echo esc_attr(get_option('local_detail_ad_id')); ?>" />
                </td>
              </tr>

              <tr valign="top">
                <th scope="row">激励视频广告id</th>
                <td>
                  <input type="text" name="local_excitation_ad_id" style="width:300px; height:40px" value="<?php echo esc_attr(get_option('local_excitation_ad_id')); ?>" />
                </td>
              </tr>
            </table>
          </div>
        </div>


        <?php submit_button(); ?>
        <!-- 显示一个提交按钮 -->
    </form>

    <!-- 引入css,js -->
    <?php loding_res() ?>
    <script>
      jQuery(document).ready(function($) {
    
    
        RESPONSIVEUI.responsiveTabs();
      });
    </script>
  </div>
<?php
}

Guess you like

Origin blog.csdn.net/weixin_44797182/article/details/113340418