Skip to content

Commit

Permalink
✨ 增加用户中心资料更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed Jan 27, 2023
1 parent 3640fb6 commit 0eb5202
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 33 deletions.
22 changes: 11 additions & 11 deletions 404.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
<a class="a-link" href="<?php echo home_url() ?>"><i class="fa fa-home"></i>&nbsp;<?php _e('返回首页', PUOCK) ?></a>
</div>
</div>
<!-- <script>-->
<!-- var timeCountDownS = 3;-->
<!-- var timeCountDownVal = 3;-->
<!-- timeCountDownVal = setInterval(function () {-->
<!-- $("#time-count-down").text(--timeCountDownS);-->
<!-- },1000);-->
<!-- setTimeout(function () {-->
<!-- window.clearInterval(timeCountDownVal);-->
<!-- window.location = '/';-->
<!-- },3000);-->
<!-- </script>-->
<script>
var timeCountDownS = 3;
var timeCountDownVal = 3;
timeCountDownVal = setInterval(function () {
$("#time-count-down").text(--timeCountDownS);
},1000);
setTimeout(function () {
window.clearInterval(timeCountDownVal);
window.location = '/';
},3000);
</script>
</div>


Expand Down
2 changes: 1 addition & 1 deletion assets/dist/js/puock.min.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions assets/dist/style/libs.min.css

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions assets/js/puock.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ class Puock {
this.stopLoading(loading)
if (res.code === 0) {
this.toast(res.msg || successTip, TYPE_SUCCESS)
form.trigger("reset")
if (form.data("no-reset") === undefined) {
form.trigger("reset")
}
if (res.data) {
const resData = res.data
if (resData.action) {
Expand Down Expand Up @@ -632,7 +634,7 @@ class Puock {

asyncCacheViews() {
if (this.data.params.async_view_id && this.data.params.async_view_generate_time) {
if (((new Date()).getTime()/1000) - this.data.params.async_view_generate_time > 10) {
if (((new Date()).getTime() / 1000) - this.data.params.async_view_generate_time > 10) {
$.post(this.data.params.home + "/wp-admin/admin-ajax.php?action=async_pk_views",
{id: this.data.params.async_view_id}, (res) => {
if (res.code !== 0) {
Expand Down
1 change: 1 addition & 0 deletions inc/ajax/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
require_once __DIR__ . '/dialog-post-share.php';
require_once __DIR__ . '/dialog-smiley.php';
require_once __DIR__ . '/dialog-reward.php';
require_once __DIR__ . '/user.php';
34 changes: 34 additions & 0 deletions inc/ajax/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php


class Puock_Ajax_User
{
public function __construct()
{
pk_ajax_register('pk_user_update_profile', array($this, 'update_profile'));
}

public function update_profile()
{
if (is_string($data = pk_get_req_data([
'nickname' => ['name' => __('昵称', PUOCK), 'required' => true, 'remove_html' => true],
'user_url' => ['name' => __('网站地址', PUOCK), 'remove_html' => true, 'empty' => true],
'description' => ['name' => __('个人说明', PUOCK), 'remove_html' => true, 'empty' => true],
])) === true) {
echo pk_ajax_resp_error($data);
wp_die();
}
$data['ID'] = get_current_user_id();
if (!empty($data['nickname'])) {
$data['display_name'] = $data['nickname'];
}
if (!wp_update_user($data)) {
echo pk_ajax_resp_error(__('保存失败', PUOCK));
wp_die();
}
echo pk_ajax_resp(null, __('保存成功', PUOCK));
wp_die();
}
}

new Puock_Ajax_User();
17 changes: 12 additions & 5 deletions inc/fun/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,13 @@ function pk_get_req_data(array $model)
if (isset($item['default'])) {
$data[$key] = $item['default'];
}
if ($item['empty'] ?? false) {
$data[$key] = '';
}
} else {
if ($item['remove_html'] ?? false) {
$val = sanitize_text_field($val);
}
$data[$key] = $val;
}
}
Expand Down Expand Up @@ -944,15 +950,15 @@ function pk_vd_gt_validate(array $args = null)

function pk_user_center_url(): string
{
if(pk_is_checked('user_center')){
return home_url().'/uc';
if (pk_is_checked('user_center')) {
return home_url() . '/uc';
}
return get_edit_profile_url();
}

function pk_rewrite_rule()
{
if(pk_is_checked('user_center')){
if (pk_is_checked('user_center')) {
add_rewrite_rule("^uc/?", 'index.php?pagename=user-center', "top");
}
}
Expand All @@ -967,7 +973,7 @@ function pk_template_redirect()
$template = '';
switch ($page_name) {
case 'user-center':
$template = PUOCK_ABS_DIR.'/inc/page/user-center.php';
$template = PUOCK_ABS_DIR . '/inc/page/user-center.php';
break;
default:
break;
Expand All @@ -981,7 +987,8 @@ function pk_template_redirect()

add_action('template_redirect', 'pk_template_redirect');

function pk_load_template($_template_file, $require_once = true, $args = array()){
function pk_load_template($_template_file, $require_once = true, $args = array())
{
status_header(200);
load_template($_template_file, $require_once, $args);
}
11 changes: 7 additions & 4 deletions inc/page/user-center.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</div>
</div>
<div class="col-lg-9 col-md-12 fs14">
<form action="">
<form action="<?php echo pk_ajax_url('pk_user_update_profile') ?>" class="ajax-form" data-no-reset>
<div class="mb-3 row">
<label class="col-sm-2 col-form-label">ID</label>
<div class="col-sm-10">
Expand All @@ -46,21 +46,24 @@
<div class="mb-3 row">
<label class="col-sm-2 col-form-label">昵称</label>
<div class="col-sm-10">
<input type="text" class="form-control" value="<?php echo $userinfo->nickname ?>">
<input name="nickname" type="text" class="form-control" value="<?php echo $userinfo->nickname ?>">
</div>
</div>
<div class="mb-3 row">
<label class="col-sm-2 col-form-label">网站地址</label>
<div class="col-sm-10">
<input type="url" class="form-control" value="<?php echo $userinfo->user_url ?>">
<input name="user_url" type="url" class="form-control" value="<?php echo $userinfo->user_url ?>">
</div>
</div>
<div class="mb-3 row">
<label class="col-sm-2 col-form-label">个人说明</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4"><?php echo $userinfo->description ?></textarea>
<textarea name="description" class="form-control" rows="4"><?php echo $userinfo->description ?></textarea>
</div>
</div>
<div class="mb-3 text-center">
<button class="btn btn-primary btn-sm" type="submit">提交保存</button>
</div>
</form>
</div>
</div>
Expand Down

0 comments on commit 0eb5202

Please sign in to comment.