-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
172 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Puock\Theme\classes; | ||
|
||
class PuockClassLoad | ||
{ | ||
|
||
private static array $classes = []; | ||
|
||
public function __construct() | ||
{ | ||
if (pk_is_checked('user_center')) { | ||
self::$classes[] = PuockUserCenter::class; | ||
} | ||
add_action('init', array($this, '__wp_init')); | ||
} | ||
|
||
public function __wp_init() | ||
{ | ||
$this->load_class(); | ||
} | ||
|
||
public static function add_class(IPuockClassLoad $class) | ||
{ | ||
self::$classes[] = $class; | ||
} | ||
|
||
private static function load_class() | ||
{ | ||
foreach (self::$classes as $class) { | ||
$class::load(); | ||
} | ||
} | ||
} | ||
|
||
interface IPuockClassLoad | ||
{ | ||
public static function load(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace Puock\Theme\classes; | ||
|
||
class PuockUserCenter implements IPuockClassLoad | ||
{ | ||
|
||
private static array $menus = []; | ||
|
||
public static function load() | ||
{ | ||
pk_ajax_register('pk_user_update_profile', array(__CLASS__, 'update_profile')); | ||
self::register_basic_menus(); | ||
} | ||
|
||
private static function register_basic_menus() | ||
{ | ||
self::$menus['profile'] = [ | ||
'title' => __('个人资料', PUOCK), | ||
'subtitle' => __('您的基本个人资料', PUOCK), | ||
'call' => array(__CLASS__, 'page_profile'), | ||
]; | ||
} | ||
|
||
public static function get_menus() | ||
{ | ||
return apply_filters('pk_user_center_menus', self::$menus); | ||
} | ||
|
||
public static function register_menu($id, $title, $call, $subtitle = '', $args = array()) | ||
{ | ||
self::$menus[$id] = [ | ||
'title' => $title, | ||
'subtitle' => $subtitle, | ||
'call' => $call, | ||
]; | ||
} | ||
|
||
public static 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(); | ||
} | ||
|
||
public static function page_profile() | ||
{ | ||
$userinfo = get_userdata(get_current_user_id()); | ||
?> | ||
<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"> | ||
<input type="text" readonly class="form-control" value="<?php echo $userinfo->ID ?>"> | ||
</div> | ||
</div> | ||
<div class="mb-3 row"> | ||
<label class="col-sm-2 col-form-label">用户名</label> | ||
<div class="col-sm-10"> | ||
<input type="text" readonly class="form-control" value="<?php echo $userinfo->user_nicename ?>"> | ||
<small class="c-sub">用户名不可更改</small> | ||
</div> | ||
</div> | ||
<div class="mb-3 row"> | ||
<label class="col-sm-2 col-form-label">昵称</label> | ||
<div class="col-sm-10"> | ||
<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 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 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> | ||
<?php | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters