Skip to content

Commit 77f9a7c

Browse files
author
Tom Hanoldt
committed
add Dashboard and User classes
1 parent 0d8d656 commit 77f9a7c

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

User.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace cw\wp;
4+
5+
6+
class User{
7+
public function __construct(){
8+
}
9+
10+
public function name(){
11+
$current_user = wp_get_current_user();
12+
13+
if(!empty($current_user->user_firstname))
14+
return $current_user->user_firstname ;
15+
16+
if(!empty($current_user->display_name))
17+
return $current_user->display_name;
18+
19+
return $current_user->user_login;
20+
}
21+
}

admin/Dashboard.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace cw\wp\admin;
4+
5+
class Dashboard{
6+
public function addMainWidget($id, $name, $callback, $priotirty='core'){
7+
return $this->addWidget($id, $name, $callback, 'normal', $priotirty);
8+
}
9+
10+
public function addSideWidget($id, $name, $callback, $priotirty='core'){
11+
return $this->addWidget($id, $name, $callback, 'side', $priotirty);
12+
}
13+
14+
public function addWidget($id, $name, $callback, $where='normal', $priotirty='core'){
15+
add_action('wp_dashboard_setup', function() use($id, $name, $callback, $where, $priotirty){
16+
add_meta_box($id, $name, $callback, 'dashboard', $where, $priotirty);
17+
}, 1000);
18+
return $this;
19+
}
20+
21+
public function removeWidgets(){
22+
add_action('wp_dashboard_setup', function(){
23+
global $wp_meta_boxes;
24+
$wp_meta_boxes['dashboard']['side'] = ['core' => []];
25+
$wp_meta_boxes['dashboard']['normal'] = ['core' => []];
26+
}, 1000);
27+
return $this;
28+
}
29+
30+
public function replaceWelcomePanel($input){
31+
add_action( 'admin_footer', function() use($input){
32+
if(is_callable($input))
33+
$input = $input();
34+
35+
$input = str_replace(array("\r", "\n"), '', $input);
36+
$input = addcslashes($input, '"');
37+
38+
echo '<script>(function($){$("#welcome-panel").html("'.$input.'");})(jQuery);</script>';
39+
}, 1000);
40+
return $this;
41+
}
42+
43+
public function appendToWelcomePanel($input){
44+
add_action( 'admin_footer', function() use($input){
45+
if(is_callable($input))
46+
$input = $input();
47+
48+
$input = str_replace(array("\r", "\n"), '', $input);
49+
$input = addcslashes($input, '"');
50+
51+
echo '<script>(function($){$("#welcome-panel").append("'.$input.'");})(jQuery);</script>';
52+
}, 1000);
53+
return $this;
54+
}
55+
56+
public function hideWidgetArea(){
57+
add_action( 'admin_footer', function(){
58+
echo '<script>(function($){$("#dashboard-widgets-wrap").html("");})(jQuery);</script>';
59+
}, 101 );
60+
return $this;
61+
}
62+
}

0 commit comments

Comments
 (0)