当前位置:首页WP美化B2美化7b2友链申请表页面

7b2友链申请表页面

js不是wordpress通用,js仅用于7b2pro主题,因使用7b2js函数,其他主题可以更改Ajax,传输token。

7b2友链申请表页面

提交页面HTML代码:

分类是自动获取网站的链接分类,可以改代码自定义设置。

  1. <?php
  2. get_header();
  3. $cats = get_terms('link_category');
  4. ?>
  5. <div id="vips">
  6. <div v-if="b2token" data-name="xutian" v-cloak>
  7. <div style="margin-top: 80px;margin-bottom:80px;display:flex;justify-content:center;" class="containers">
  8. <div class="content content-link-application">
  9. <div class="form-header">
  10. <h1>友链申请</h1>
  11. <br />
  12. <p>您可以通过提交下面的表单贵站相关信息。</p>
  13. </div>
  14. <div class="wb-form contact-form nice-validator n-default">
  15. <div class="mt20">
  16. <div class="form-group">
  17. <label>
  18. <font color="red">*</font>站点名称:
  19. </label>
  20. <input type="text" size="40" v-model.trim="link_name" class="form-control" placeholder="输入您的网站名称" autocomplete="off" />
  21. </div>
  22. <div class="form-group">
  23. <label>
  24. <font color="red">*</font>站点地址:
  25. </label>
  26. <input type="text" size="40" v-model.trim="link_url" class="form-control" placeholder="输入您的网站地址" autocomplete="off" />
  27. </div>
  28. <div class="form-group">
  29. <label>站点简介:</label>
  30. <input type="text" size="40" v-model.trim="link_description" class="form-control" placeholder="输入您的网站简介" autocomplete="off" />
  31. </div>
  32. <div class="form-group">
  33. <label>站点Logo:</label>
  34. <input type="text" size="40" v-model.trim="link_image" class="form-control" placeholder="请输入您的Logo链接地址" autocomplete="off" />
  35. </div>
  36. <div class="form-group">
  37. <label>其他备注:</label>
  38. <textarea class="check-textarea" style="min-height:200px;width:100%;padding:10px;" placeholder="输入备注" size="40" v-model.trim="link_notes"></textarea>
  39. </div>
  40. <div class="form-group">
  41. <label>
  42. <font color="red">*</font>站点分类:
  43. </label>
  44. <br />
  45. <select class="check-textarea" v-model.trim="link_category">
  46. <option value="">请选择链接分类</option>
  47. <?php
  48. foreach ($cats as $cat) {
  49. echo '<option value="' . $cat->term_id . '">' . $cat->name . '</option>';
  50. }
  51. ?>
  52. </select>
  53. </div>
  54. <div style="text-align:center">
  55. <input type="hidden" value="send" />
  56. <button class="btn-primary" @click="showWindow()" v-cloak>提交</button>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. <div v-else id="main" v-cloak>
  64. <div style="margin-top:80px;display:flex;justify-content:center;" class="containers">
  65. <div class="content content-link-application">
  66. <div class="form-header">
  67. <h1>友链申请</h1>
  68. <br />
  69. <p style="font-size:15px;">请登录后再试</p>
  70. <br />
  71. <div>
  72. <button @click="login()">立即登录</button>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <?php
  81. get_footer();

提交页面CSS代码:

  1. .content-link-application{
  2. padding: 60px 40px;
  3. background-color: #fff;
  4. border-radius: 5px;
  5. width: 800px;
  6. -webkit-box-shadow: 0 7px 8px 0 rgba(0,0,0,.11);
  7. box-shadow: 0 7px 8px 0 rgba(0,0,0,.11)
  8. }
  9. .content-link-application .form-control
  10. {
  11. height: 38px;
  12. width: 100%
  13. }
  14. .content-link-application .captcha-img,.content-link-application .captcha-input
  15. {
  16. display: inline-block;
  17. vertical-align: middle
  18. }
  19. .content-link-application .form-header
  20. {
  21. max-width: 600px;
  22. margin-left: auto;
  23. margin-right: auto;
  24. padding-bottom: 40px
  25. }
  26. .content-link-application .form-header p
  27. {
  28. color: #999;
  29. font-size: 12px;
  30. margin: 0;
  31. }
  32. .content-link-application h1
  33. {
  34. font-size: 30px;
  35. line-height: 44px;
  36. font-weight: 700
  37. }
  38. .content-link-application .form-control{height:38px;width:100%}
  39. .content-link-application .captcha-img,.content-link-application .captcha-input{display:inline-block;vertical-align:middle}
  40. .content-link-application .contact-form{max-width:600px;margin-left:auto;margin-right:auto}
  41. .content-link-application .form-header{max-width:600px;margin-left:auto;margin-right:auto;padding-bottom:40px;text-align:center}
  42. .content-link-application .form-header p{color:#999;font-size: 12px;margin: 0;}
  43. .content-link-application h1{font-size:30px;line-height:44px;font-weight:700}
  44. .form-group
  45. {
  46. margin-bottom: 15px
  47. }
  48. .content-link-application .form-control
  49. {
  50. height: 38px;
  51. width: 100%
  52. }
  53. .btn.btn-default
  54. {
  55. color: #333;
  56. background-color: #fff;
  57. border-color: #ccc;
  58. outline: 0;
  59. -webkit-transition: all .1s ease-out 0s;
  60. -o-transition: all .1s ease-out 0s;
  61. transition: all .1s ease-out 0s
  62. }
  63. .container,.page-no-sidebar.member-lostpassword .member-lp-process
  64. {
  65. margin-right: auto;
  66. margin-left: auto;
  67. padding-left: 10px;
  68. padding-right: 10px
  69. }

提交页面JS代码:

  1. var xutianlinks = new Vue({
  2. el: '#vips',
  3. data: {
  4. link_name: '',
  5. link_url: '',
  6. link_description: '',
  7. link_category: '',
  8. link_image: '',
  9. link_notes: ''
  10. },
  11. methods: {
  12. login() {
  13. login.show = true
  14. },
  15. showWindow() {
  16. if (!b2token) {
  17. Qmsg['warning']('请登录后提交', { html: true });
  18. } else {
  19. if (this.link_name.length <= '0') {
  20. Qmsg['warning']('请输入您的网站名称', { html: true });
  21. } else if (this.link_url.length <= '0') {
  22. Qmsg['warning']('请输入您的网站地址', { html: true });
  23. } else if (this.link_category.length <= '0') {
  24. Qmsg['warning']('请选择站点分类', { html: true });
  25. } else {
  26. this.$https.post(b2_rest_url + 'xutian_api_link', 'link_name=' + this.link_name + '&link_url=' + this.link_url + '&link_description=' + this.link_description + '&link_category=' + this.link_category + '&link_image=' + this.link_image + '&link_notes=' + this.link_notes).then(res => {
  27. if (res.data.status == 200) {
  28. Qmsg['success'](res.data.msg, { html: true });
  29. location.reload();
  30. } else if (res.data.status == 401) {
  31. Qmsg['info'](res.data.msg, { html: true });
  32. }
  33. }).catch(err => {
  34. Qmsg['info'](err.response.data.message, { html: true });
  35. })
  36. }
  37. }
  38. }
  39. },
  40. })

后端处理PHP代码:

请将下方代码放入functions.php文件中

  1. <?php
  2. add_action('rest_api_init', function () {
  3. register_rest_route('b2/v1', '/xutian_api_link/', array(
  4. 'methods' => 'POST',
  5. 'callback' => function ($request) {
  6. $user_id = get_current_user_id();
  7. $xutian_api_link = get_user_meta($user_id, 'xutian_api_link', true);
  8. if (!$user_id) {
  9. return new \WP_Error('b2_login', __('请先登录', 'b2'), array('status' => 403));
  10. } else if ($xutian_api_link) {
  11. return new \WP_Error('xutian_api_link', __('您已提交,请勿重复提交', 'b2'), array('status' => 403));
  12. } else if ($request['link_name'] && $request['link_url'] && $request['link_category']) {
  13. return api_link($request, $user_id);
  14. } else {
  15. return new \WP_Error('user_error', __('请输入必填项', 'b2'), array('status' => 403));
  16. }
  17. },
  18. ));
  19. });
  20. function api_link($request, $user_id)
  21. {
  22. $link_url = isset($request['link_url']) ? trim(sanitize_text_field(htmlspecialchars($request['link_url'], ENT_QUOTES))) : '';
  23. $link_name = isset($request['link_name']) ? trim(sanitize_text_field(htmlspecialchars($request['link_name'], ENT_QUOTES))) : '';
  24. $link_image = isset($request['link_image']) ? esc_url($request['link_image']) : '';
  25. $link_category = isset($request['link_category']) ? trim(sanitize_text_field(htmlspecialchars($request['link_category'], ENT_QUOTES))) : '';
  26. $link_description = isset($request['link_description']) ? trim(sanitize_text_field(htmlspecialchars($request['link_description'], ENT_QUOTES))) : '';
  27. $link_notes = isset($request['link_notes']) ? trim(sanitize_text_field(htmlspecialchars($request['link_notes'], ENT_QUOTES))) : '';
  28. if ($user_id and $link_name and $link_url and $link_category and $link_description = $link_name) {
  29. $linkdata = array(
  30. 'link_name' => '【待审核】' . $link_name,
  31. 'link_url' => $link_url,
  32. 'link_image' => $link_image,
  33. 'link_category' => $link_category,
  34. 'link_notes' => $link_notes,
  35. 'link_description' => $link_description,
  36. 'link_target' => '_blank',
  37. 'link_visible' => 'N'
  38. );
  39. require_once(ABSPATH . 'wp-admin/includes/bookmark.php');
  40. $xutian = wp_insert_link($linkdata);
  41. update_user_meta($user_id, 'xutian_api_link', true);
  42. if ($xutian) {
  43. return array('status' => 200, 'msg' => '提交成功,待审核');
  44. } else {
  45. return new \WP_Error('user_error', __('提交失败,请联系管理员', 'b2'), array('status' => 403));
  46. }
  47. } else {
  48. return new \WP_Error('user_error', __('提交失败,请完善资料', 'b2'), array('status' => 403));
  49. }
  50. }

因防止恶意重复提交,代码中写入了update_user_meta($user_id, ‘xutian_api_link’, true);,get_user_meta($user_id, ‘xutian_api_link’, true);判断,所以用户只能提交一次,删除这个代码就可以无限提交了,或自己改判断提交次数等。

温馨提示:

文章标题:7b2友链申请表页面

文章链接:https://www.aqzyl.cn/664.html

更新时间:2022年03月08日

本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:779451579@qq.comm我们将第一时间处理!

资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。

所有资源仅限于参考和学习,版权归原作者所有,更多请阅读艾奇资源网络服务协议

本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:779451579@qq.comm我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读艾奇资源网络服务协议

给TA打赏
共{{data.count}}人
人已打赏
RIPRO美化wordpress模板WP美化免费资源精品模板

RiPlus子主题V1.3-Unreal[幻]主题|公益开源免费使用!

2021-11-26 14:43:38

B2美化WP美化

B2主题美化修改:菜单导航中加入图片广告

2022-3-21 21:41:56

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索