forked from pressbooks/pressbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.php
138 lines (110 loc) · 6.74 KB
/
hooks.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
<?php
/**
* @author PressBooks <[email protected]>
* @license GPLv2 (or any later version)
*/
if ( ! defined( 'ABSPATH' ) )
exit;
// -------------------------------------------------------------------------------------------------------------------
// Includes
// -------------------------------------------------------------------------------------------------------------------
require( PB_PLUGIN_DIR . 'includes/pb-utility.php' );
require( PB_PLUGIN_DIR . 'includes/pb-image.php' );
require( PB_PLUGIN_DIR . 'includes/pb-l10n.php' );
require( PB_PLUGIN_DIR . 'includes/pb-postype.php' );
require( PB_PLUGIN_DIR . 'includes/pb-redirect.php' );
require( PB_PLUGIN_DIR . 'includes/pb-sanitize.php' );
require( PB_PLUGIN_DIR . 'includes/pb-taxonomy.php' );
// -------------------------------------------------------------------------------------------------------------------
// Custom Metadata plugin
// -------------------------------------------------------------------------------------------------------------------
add_filter( 'custom_metadata_manager_default_editor_args', '\PressBooks\Editor::metadataManagerDefaultEditorArgs' );
require( PB_PLUGIN_DIR . 'symbionts/custom-metadata/custom_metadata.php' );
// -------------------------------------------------------------------------------------------------------------------
// Languages
// -------------------------------------------------------------------------------------------------------------------
add_action( 'init', '\PressBooks\L10n\load_plugin_textdomain' );
add_filter( 'gettext', '\PressBooks\L10n\override_core_strings', 10, 3 );
if ( \PressBooks\Book::isBook() && \PressBooks\l10n\use_book_locale() ) {
add_filter( 'locale', '\PressBooks\Export\Export::setLocale' );
} else {
add_filter( 'locale', '\PressBooks\L10n\set_locale' );
}
// -------------------------------------------------------------------------------------------------------------------
// Images
// -------------------------------------------------------------------------------------------------------------------
add_action( 'init', '\PressBooks\Image\fix_intermediate_image_size_options' );
add_filter( 'intermediate_image_sizes', '\PressBooks\Image\intermediate_image_sizes' );
add_filter( 'intermediate_image_sizes_advanced', '\PressBooks\Image\intermediate_image_sizes_advanced' );
add_action( 'delete_attachment', '\PressBooks\Image\delete_attachment' );
add_filter( 'wp_update_attachment_metadata', '\PressBooks\Image\save_attachment', 10, 2 );
// -------------------------------------------------------------------------------------------------------------------
// Custom Post Types and Taxonomies
// -------------------------------------------------------------------------------------------------------------------
add_action( 'init', '\PressBooks\PostType\register_post_types' );
add_action( 'init', '\PressBooks\Taxonomy\register_taxonomies' );
// -------------------------------------------------------------------------------------------------------------------
// Remove the "admin bar" from any public facing theme
// -------------------------------------------------------------------------------------------------------------------
if ( is_admin() === false ) {
add_action( 'init', function () {
wp_deregister_script( 'admin-bar' );
wp_deregister_style( 'admin-bar' );
remove_action( 'init', '_wp_admin_bar_init' );
remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
}, 0 );
}
// -------------------------------------------------------------------------------------------------------------------
// The following is used when a REGISTERED USER creates a NEW BLOG
// -------------------------------------------------------------------------------------------------------------------
add_action( 'wpmu_new_blog', function ( $b, $u ) {
$activate = new \PressBooks\Activation();
$activate->wpmuNewBlog( $b, $u );
}, 9, 2 );
// -------------------------------------------------------------------------------------------------------------------
// Redirects
// -------------------------------------------------------------------------------------------------------------------
add_filter( 'init', '\PressBooks\Redirect\rewrite_rules_for_format', 1 );
add_filter( 'init', '\PressBooks\Redirect\rewrite_rules_for_catalog', 1 );
add_filter( 'login_redirect', '\PressBooks\Redirect\login', 10, 3 );
// -------------------------------------------------------------------------------------------------------------------
// Sitemap
// -------------------------------------------------------------------------------------------------------------------
add_filter( 'init', '\PressBooks\Redirect\rewrite_rules_for_sitemap' );
add_action( 'do_robotstxt', '\PressBooks\Utility\add_sitemap_to_robots_txt' );
// -------------------------------------------------------------------------------------------------------------------
// Shortcodes
// -------------------------------------------------------------------------------------------------------------------
$_ = new \PressBooks\Shortcodes\Footnotes\Footnotes();
$_ = new \PressBooks\Shortcodes\WikiPublisher\Glyphs();
// -------------------------------------------------------------------------------------------------------------------
// Upgrade Book Metadata
// -------------------------------------------------------------------------------------------------------------------
if ( \PressBooks\Book::isBook() ) {
add_action( 'init', function () {
$meta_version = get_option( 'pressbooks_metadata_version', 0 );
if ( $meta_version < \PressBooks\Metadata::$currentVersion ) {
$metadata = new \PressBooks\Metadata();
$metadata->upgrade( $meta_version );
update_option( 'pressbooks_metadata_version', \PressBooks\Metadata::$currentVersion );
}
}, 1000 );
}
// -------------------------------------------------------------------------------------------------------------------
// Upgrade Catalog
// -------------------------------------------------------------------------------------------------------------------
add_action( 'init', function () {
$catalog_version = get_site_option( 'pressbooks_catalog_version', 0 );
if ( $catalog_version < \PressBooks\Catalog::$currentVersion ) {
$metadata = new \PressBooks\Catalog();
$metadata->upgrade( $catalog_version );
update_site_option( 'pressbooks_catalog_version', \PressBooks\Catalog::$currentVersion );
}
}, 1000 );
// -------------------------------------------------------------------------------------------------------------------
// Turn off XML-RPC
// -------------------------------------------------------------------------------------------------------------------
add_filter( 'xmlrpc_enabled', '__return_false' );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );