-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnamespace.php
348 lines (316 loc) · 9.44 KB
/
namespace.php
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
/**
* Aldine Actions
*
* @package Aldine
*/
namespace Aldine\Actions;
use PressbooksMix\Assets;
use Spatie\Color\Hex;
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function setup() {
$assets = new Assets( 'pressbooks-aldine', 'theme' );
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' );
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
*/
load_theme_textdomain( 'pressbooks-aldine', get_template_directory() . '/languages' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
[
'primary-menu' => __( 'Primary Menu', 'pressbooks-aldine' ),
'network-footer-menu' => __( 'Footer Menu', 'pressbooks-aldine' ),
]
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5', [
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
]
);
// Set up the WordPress core custom header feature.
add_theme_support(
'custom-header', [
'default-image' => get_template_directory_uri() . '/dist/images/header.jpg',
'width' => 1920,
'height' => 884,
'default-text-color' => '#000',
]
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo', [
'height' => 40,
'width' => 265,
'flex-width' => true,
'flex-height' => true,
]
);
// Add editor style.
add_editor_style( $assets->getPath( 'styles/editor.css' ) );
// Add shortcode buttons.
add_action( 'init', __NAMESPACE__ . '\register_shortcode_buttons' );
remove_theme_support( 'widgets-block-editor' );
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
// Disables the block editor from managing widgets.
add_filter( 'use_widgets_block_editor', '__return_false' );
}
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function widgets_init() {
$config = [
'before_widget' => '<div class="widget %1$s %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
];
register_sidebar(
[
'name' => __( 'Network Footer Block 1', 'pressbooks-aldine' ),
'description' => __(
'Add content for your network’s customizeable footer here.
Currently, only text and image widgets are supported.
Content in this widget area will appear in the first row (on mobile) or the first column (on desktops).',
'aldine'
),
'id' => 'network-footer-block-1',
] + $config
);
register_sidebar(
[
'name' => __( 'Network Footer Block 2', 'pressbooks-aldine' ),
'description' => __(
'Add content for your network’s customizeable footer here.
Currently, only text and image widgets are supported.
Content in this widget area will appear in the second row (on mobile) or the middle column (on desktop).',
'aldine'
),
'id' => 'network-footer-block-2',
] + $config
);
}
/**
* Enqueue scripts and styles.
*/
function enqueue_assets() {
$assets = new Assets( 'pressbooks-aldine', 'theme' );
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' );
wp_enqueue_style( 'aldine/style', $assets->getPath( 'styles/aldine.css' ), false, null );
wp_enqueue_style( 'aldine/webfonts', 'https://fonts.googleapis.com/css?family=Karla:400,400i,700|Spectral:400,400i,600', false, null );
wp_enqueue_script( 'aldine/script', $assets->getPath( 'scripts/aldine.js' ), [ 'jquery' ], null, true );
}
/**
* Add editor styles.
*/
function add_editor_styles() {
$assets = new Assets( 'pressbooks-aldine', 'theme' );
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' );
add_editor_style( $assets->getPath( 'styles/editor.css' ) );
}
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function content_width() {
$GLOBALS['content_width'] = apply_filters( 'pressbooks_aldine_content_width', 640 );
}
/**
* Output custom colors as CSS variables.
*
* @return void
*/
function output_custom_colors() {
if ( defined( 'PB_PLUGIN_VERSION' ) ) {
echo \Pressbooks\Admin\Branding\get_customizer_colors();
} else {
$colors = [
'primary',
'accent',
'primary_fg',
'accent_fg',
'primary_dark',
'accent_dark',
'primary_alpha',
'accent_alpha',
'header_text',
];
$values = [];
foreach ( $colors as $k ) {
$v = get_option( "pb_network_color_$k" );
if ( $v ) {
$values[ $k ] = $v;
}
}
$output = '';
if ( ! empty( $values ) ) {
$output .= '<style type="text/css">:root{';
foreach ( $values as $k => $v ) {
$k = str_replace( '_', '-', $k );
$output .= "--$k:$v;";
}
$output .= '}</style>';
}
echo $output;
}
}
/**
* Remove Admin Bar callback.
*/
function remove_admin_bar_callback() {
remove_action( 'wp_head', '_admin_bar_bump_cb' );
}
/**
* Hide content editor for Catalog page.
*/
function hide_catalog_content_editor() {
$post_id = $_GET['post'] ?? null;
if ( ! isset( $post_id ) ) {
return;
}
$template = get_page_template_slug( $post_id );
if ( $template === 'page-catalog.php' ) {
add_action(
'edit_form_after_title', function() {
printf( '<p>%s</p>', __( 'This page displays your network catalog, so there is no content to edit.', 'pressbooks-aldine' ) );
}
);
remove_post_type_support( 'page', 'editor' );
remove_post_type_support( 'page', 'thumbnail' );
}
}
/**
* Add dark and alpha variants for customizer colors on update.
*
* @param array $option Option
* @param string $old_value Unused parameter
* @param string $value Color value
* @since 1.0.0
*/
function add_color_variants( $option, $old_value, $value ) {
if ( ! in_array( $option, [ 'pb_network_color_primary', 'pb_network_color_accent' ], true ) ) {
return;
}
$color = Hex::fromString( $value );
$color = $color->toRgb();
$color_alpha = $color->toRgba( 0.25 );
$color_alpha = (string) $color_alpha;
update_option( $option . '_alpha', $color_alpha );
}
/**
* Register shortcode buttons.
*
* @since 1.1.0
*/
function register_shortcode_buttons() {
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
return;
}
if ( get_user_option( 'rich_editing' ) !== 'true' ) {
return;
}
add_filter( 'mce_external_plugins', '\Aldine\filters\add_buttons' );
add_filter( 'mce_buttons', '\Aldine\filters\register_buttons' );
}
/**
* Localize shortcode button strings.
*
* @since 1.1.0
*/
function tinymce_l18n() {
?>
<script type='text/javascript'>
const aldine = {
page_section: {
'title': '<?php _e( 'Page Section', 'pressbooks-aldine' ); ?>',
'title_label': '<?php _e( 'Title', 'pressbooks-aldine' ); ?>',
'standard': '<?php _e( 'Standard', 'pressbooks-aldine' ); ?>',
'accent': '<?php _e( 'Accent', 'pressbooks-aldine' ); ?>',
'bordered': '<?php _e( 'Bordered', 'pressbooks-aldine' ); ?>',
'borderless': '<?php _e( 'Borderless', 'pressbooks-aldine' ); ?>'
},
call_to_action: {
'title': '<?php _e( 'Call to Action', 'pressbooks-aldine' ); ?>',
'text': '<?php _e( 'Text', 'pressbooks-aldine' ); ?>',
'link': '<?php _e( 'Link', 'pressbooks-aldine' ); ?>'
}
};
</script>
<?php
}
/**
* Remove unwanted menu pages.
*
* @since 1.15.0
*/
function remove_menu_items() {
remove_menu_page( 'edit.php' );
remove_submenu_page( 'tools.php', 'import.php' );
remove_submenu_page( 'tools.php', 'export.php' );
remove_submenu_page( 'tools.php', 'tools.php' );
remove_submenu_page( 'options-general.php', 'options-writing.php' );
remove_submenu_page( 'options-general.php', 'options-reading.php' );
remove_submenu_page( 'options-general.php', 'options-permalink.php' );
}
/**
* Remove unwanted widgets.
*
* @since 1.15.0
*/
function remove_widgets() {
unregister_widget( 'WP_Widget_Pages' );
unregister_widget( 'WP_Widget_Calendar' );
unregister_widget( 'WP_Widget_Archives' );
unregister_widget( 'WP_Widget_Links' );
unregister_widget( 'WP_Widget_Meta' );
unregister_widget( 'WP_Widget_Search' );
unregister_widget( 'WP_Widget_Categories' );
unregister_widget( 'WP_Widget_Recent_Posts' );
unregister_widget( 'WP_Widget_Recent_Comments' );
unregister_widget( 'WP_Widget_RSS' );
unregister_widget( 'WP_Widget_Tag_Cloud' );
unregister_widget( 'WP_Widget_Media_Audio' );
unregister_widget( 'WP_Nav_Menu_Widget' );
unregister_widget( 'WP_Widget_Custom_HTML' );
unregister_widget( 'WP_Widget_Media_Video' );
unregister_widget( 'Akismet_Widget' );
}