-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-mbb-admin.php
More file actions
219 lines (187 loc) · 5.68 KB
/
Copy pathclass-mbb-admin.php
File metadata and controls
219 lines (187 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
if ( ! class_exists( 'MBB_Admin' ) ) :
/**
* Class for admin item customizations
*/
class MBB_Admin {
/**
* Instance of the class.
*
* @var MBB_Admin instance of the class.
*/
private static $instance;
/**
* Title for content displayed after default
* WP title input.
*
* @var string content after post title.
*/
private $content_after_title = '';
/**
* Placeholder text for the default WP title input
*
* @var string customized text for the post title placeholder.
*/
private $enter_title_here_text;
/**
* MBB_Admin constructor.
*/
private function __construct() {
/* Don't do anything, needs to be initialized via instance() method */
}
/**
* Create one instance of the class
*
* @return MBB_Admin instance of the class
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new MBB_Admin;
self::$instance->setup();
}
return self::$instance;
}
/**
* Setup actions, filters, enqueue scripts/styles, etc.
*/
public function setup() {
// Add content under title.
add_action( 'edit_form_after_title', [ $this, 'add_content_after_title' ] );
// Load admin scripts/styles.
add_action( 'admin_enqueue_scripts', [ $this, 'load_admin_scripts_styles' ] );
// Load front-end scripts/styles.
add_action( 'wp_enqueue_scripts', [ $this, 'load_scripts_styles' ] );
// Remove theme supports.
add_action( 'init', [ $this, 'theme_supports' ] );
// Change 'title here' text.
add_filter( 'enter_title_here', [ $this, 'change_title_here_text' ], 11, 2 );
// Register navigation menus & add theme supports. Already loaded on 'after_setup_theme' here.
$this->register_nav_menus();
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
add_theme_support( 'post-thumbnails' );
}
// Register/Unregister widgets.
add_action( 'widgets_init', [ $this, 'register_widgets' ] );
add_action( 'widgets_init', [ $this, 'unregister_widgets' ] );
// Add feeds for custom post types.
add_filter( 'wp_head', [ $this, 'add_custom_post_type_rss' ] );
}
/**
* Set the content to be displayed on the edit screen after the title.
*
* @param mixed $content the content to display.
*/
public function set_content_after_title( $content ) {
$this->content_after_title = $content;
}
/**
* Callback for adding content after the edit post screen title.
*/
public function add_content_after_title() {
echo wp_kses_post( $this->content_after_title );
}
/**
* Set the 'enter title text' here.
*
* @param string $content the text to display.
*/
public function set_enter_title_here_text( $content ) {
$this->enter_title_here_text = $content;
}
/**
* Change the title here text based on the post type.
*
* @param string $title the title copy.
* @param WP_Post $post the post object.
*
* @return string $title
*/
public function change_title_here_text( $title, $post ) {
if ( function_exists( 'get_current_screen' ) ) {
$screen = get_current_screen();
if ( ! empty( $screen->post_type ) && post_type_exists( $screen->post_type ) && $post->post_type === $screen->post_type ) {
$title = $this->enter_title_here_text;
} else {
$title = 'Enter the title here';
}
}
return $title;
}
/**
* Only administrators can edit categories.
*/
public static function remove_manage_categories_capability() {
$editor = get_role( 'editor' );
$editor->remove_cap( 'manage_categories' );
}
/**
* Enqueue admin scripts and styles.
*/
public function load_admin_scripts_styles() {
wp_enqueue_style( 'mbb-admin-styles', MBB_PLUGIN_DIR_URL . 'assets/css/mbb-admin.css', [], '1.0.0', 'screen' );
wp_enqueue_script( 'mbb-admin-script', MBB_PLUGIN_DIR_URL . 'assets/js/mbb_admin.min.js', false, true );
}
/**
* Enqueue frontend scripts and styles.
*/
public function load_scripts_styles() {
wp_enqueue_script( 'mbb-notifications', MBB_PLUGIN_DIR_URL . 'assets/js/mbb_notifications.min.js', [ 'jquery' ], '1.0.0', false );
}
/**
* Add and remove theme supports.
*/
public function theme_supports() {
foreach ( MBB_Helpers()->get_remove_theme_support_items() as $item ) {
if ( current_theme_supports( $item ) ) {
remove_theme_support( $item );
}
}
foreach ( MBB_Helpers()->get_add_theme_support_items() as $item ) {
if ( ! current_theme_supports( $item ) ) {
add_theme_support( $item );
}
}
}
/**
* Register navigation menus.
*/
public function register_nav_menus() {
foreach ( MBB_Helpers()->get_nav_menus() as $location => $desc ) {
register_nav_menu( $location, $desc );
}
}
/**
* Register widget areas.
*/
public function register_widgets() {
foreach ( MBB_Helpers()->get_registered_widgets() as $widget ) {
register_widget( $widget );
}
}
/**
* Unregister widgets.
*/
public function unregister_widgets() {
foreach ( MBB_Helpers()->get_unregistered_widgets() as $widget ) {
unregister_widget( $widget );
}
}
/**
* Add custom post type rss.
*/
public function add_custom_post_type_rss() {
$post_types = [ 'events' ];
foreach ( $post_types as $post_type ) {
$feed = get_post_type_archive_feed_link( $post_type );
if ( '' === $feed || ! is_string( $feed ) ) {
$feed = get_bloginfo( 'rss2_url' ) . "?post_type=$post_type";
}
echo wp_kses_post( sprintf( '<link rel="%1$s" type="%2$s" href="%3$s" />', 'alternate', 'application/rss+xml', $feed ) );
}
}
}
function MBB_Admin() {
return MBB_Admin::instance();
}
register_activation_hook( __FILE__, [ 'MBB_Admin', 'remove_manage_categories_capability' ] );
endif;