forked from pressbooks/pressbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks-admin.php
169 lines (137 loc) · 7.96 KB
/
hooks-admin.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
<?php
/**
* @author PressBooks <[email protected]>
* @license GPLv2 (or any later version)
*/
if ( ! defined( 'ABSPATH' ) )
exit;
// -------------------------------------------------------------------------------------------------------------------
// Includes
// -------------------------------------------------------------------------------------------------------------------
require( PB_PLUGIN_DIR . 'admin/pb-admin-dashboard.php' );
require( PB_PLUGIN_DIR . 'admin/pb-admin-laf.php' );
require( PB_PLUGIN_DIR . 'admin/pb-admin-metaboxes.php' );
require( PB_PLUGIN_DIR . 'admin/pb-admin-customcss.php' );
// -------------------------------------------------------------------------------------------------------------------
// Look & feel of admin interface and Dashboard
// -------------------------------------------------------------------------------------------------------------------
// PressBook-ify the admin bar
add_action( 'admin_bar_menu', '\PressBooks\Admin\Laf\replace_menu_bar_branding', 11 );
add_action( 'admin_bar_menu', '\PressBooks\Admin\Laf\replace_menu_bar_my_sites', 21 );
add_action( 'admin_bar_menu', '\PressBooks\Admin\Laf\remove_menu_bar_update', 41 );
add_action( 'admin_bar_menu', '\PressBooks\Admin\Laf\remove_menu_bar_new_content', 71 );
// Add contact Info
add_action( 'admin_head', '\PressBooks\Admin\Laf\add_feedback_dialogue' );
add_filter( 'admin_footer_text', '\PressBooks\Admin\Laf\add_footer_link' );
if ( \PressBooks\Book::isBook() ) {
// Aggressively replace default interface
add_action( 'admin_init', '\PressBooks\Admin\Laf\redirect_away_from_bad_urls' );
add_action( 'admin_menu', '\PressBooks\Admin\Laf\replace_book_admin_menu', 1 );
add_action( 'wp_dashboard_setup', '\PressBooks\Admin\Dashboard\replace_dashboard_widgets' );
remove_action( 'welcome_panel', 'wp_welcome_panel' );
add_action( 'customize_register', '\PressBooks\Admin\Laf\customize_register', 1000 );
} else {
// Fix extraneous menus
add_action( 'admin_menu', '\PressBooks\Admin\Laf\fix_root_admin_menu', 1 );
}
if ( true == is_main_site() ) {
add_action( 'wp_dashboard_setup', '\PressBooks\Admin\Dashboard\replace_root_dashboard_widgets' );
}
// Javascript, Css
add_action( 'admin_init', '\PressBooks\Admin\Laf\init_css_js' );
// Hacks
add_action( 'edit_form_advanced', '\PressBooks\Admin\Laf\edit_form_hacks' );
// Privacy, Ecommerce, and Advanced settings
add_action( 'admin_init', '\PressBooks\Admin\Laf\privacy_settings_init' );
add_action( 'admin_init', '\PressBooks\Admin\Laf\ecomm_settings_init' );
add_action( 'admin_init', '\PressBooks\Admin\Laf\advanced_settings_init' );
// Replaces 'WordPress' with 'PressBooks' in titles of admin pages.
add_filter( 'admin_title', '\PressBooks\Admin\Laf\admin_title' );
// Echo our notices, if any
add_action( 'admin_notices', '\PressBooks\Admin\Laf\admin_notices' );
// -------------------------------------------------------------------------------------------------------------------
// Posts, Meta Boxes
// -------------------------------------------------------------------------------------------------------------------
add_action( 'admin_menu', function () {
remove_meta_box( 'pageparentdiv', 'chapter', 'normal' );
remove_meta_box( 'submitdiv', 'metadata', 'normal' );
remove_meta_box( 'submitdiv', 'author', 'normal' );
remove_meta_box( 'submitdiv', 'part', 'normal' );
} );
add_action( 'admin_init', '\PressBooks\Admin\Metaboxes\add_meta_boxes' );
if ( \PressBooks\Book::isBook() ) {
add_action( 'admin_enqueue_scripts', '\PressBooks\Admin\Metaboxes\add_metadata_styles' );
add_action( 'save_post', '\PressBooks\Book::consolidatePost', 10, 2 );
add_action( 'save_post', '\PressBooks\Admin\Metaboxes\upload_cover_image', 10, 2 );
add_action( 'save_post', '\PressBooks\Admin\Metaboxes\title_update', 20, 2 );
add_action( 'save_post', '\PressBooks\Admin\Metaboxes\add_required_data', 30, 2 );
add_action( 'save_post', '\PressBooks\Book::deleteBookObjectCache', 1000 );
add_action( 'wp_trash_post', '\PressBooks\Book::deletePost' );
add_action( 'wp_trash_post', '\PressBooks\Book::deleteBookObjectCache', 1000 );
add_filter( 'tiny_mce_before_init', '\PressBooks\Editor::mceBeforeInitInsertFormats' );
add_filter( 'mce_buttons_2', '\PressBooks\Editor::mceButtons');
add_action( 'init', '\PressBooks\Editor::addEditorStyle' );
}
// -------------------------------------------------------------------------------------------------------------------
// Custom user profile
// -------------------------------------------------------------------------------------------------------------------
add_action( 'admin_init', '\PressBooks\Admin\Metaboxes\add_user_meta' );
// -------------------------------------------------------------------------------------------------------------------
// Ajax
// -------------------------------------------------------------------------------------------------------------------
// Book Organize Page
add_action( 'wp_ajax_pb_update_chapter', '\PressBooks\Book::updateChapter' );
add_action( 'wp_ajax_pb_update_front_matter', '\PressBooks\Book::updateFrontMatter' );
add_action( 'wp_ajax_pb_update_back_matter', '\PressBooks\Book::updateBackMatter' );
add_action( 'wp_ajax_pb_update_export_options', '\PressBooks\Book::updateExportOptions' );
add_action( 'wp_ajax_pb_update_privacy_options', '\PressBooks\Book::updatePrivacyOptions' );
add_action( 'wp_ajax_pb_update_global_privacy_options', '\PressBooks\Book::updateGlobalPrivacyOptions' );
// Book Information Page
add_action( 'wp_ajax_pb_delete_cover_image', '\PressBooks\Admin\Metaboxes\delete_cover_image' );
// Convert MS Word Footnotes
add_action( 'wp_ajax_pb_ftnref_convert', '\PressBooks\Shortcodes\Footnotes\Footnotes::convertWordFootnotes' );
// Load CSS into Custom CSS textarea
add_action( 'wp_ajax_pb_load_css_from', '\PressBooks\Admin\CustomCss\load_css_from' );
// User Catalog Page
add_action( 'wp_ajax_pb_delete_catalog_logo', '\PressBooks\Catalog::deleteLogo' );
// -------------------------------------------------------------------------------------------------------------------
// Custom Css
// -------------------------------------------------------------------------------------------------------------------
add_action( 'admin_menu', '\PressBooks\Admin\CustomCss\add_menu' );
add_action( 'load-post.php', '\PressBooks\Admin\CustomCss\redirect_css_editor' );
// -------------------------------------------------------------------------------------------------------------------
// "Catch-all" routines, must come after taxonomies and friends
// -------------------------------------------------------------------------------------------------------------------
add_action( 'init', '\PressBooks\Export\Export::formSubmit', 50 );
add_action( 'init', '\PressBooks\Import\Import::formSubmit', 50 );
add_action( 'init', '\PressBooks\CustomCss::formSubmit', 50 );
add_action( 'init', '\PressBooks\Catalog::formSubmit', 50 );
// -------------------------------------------------------------------------------------------------------------------
// Leftovers
// -------------------------------------------------------------------------------------------------------------------
if ( \PressBooks\Book::isBook() ) {
add_action( 'post_edit_form_tag', function () {
echo ' enctype="multipart/form-data"';
} );
// Disable all pointers (i.e. tooltips) all the time, see \WP_Internal_Pointers()
add_action( 'admin_init', function () {
remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
} );
// Fix for "are you sure you want to leave page" message when editing a part
add_action( 'admin_enqueue_scripts', function () {
if ( 'part' == get_post_type() )
wp_dequeue_script( 'autosave' );
} );
// Hide welcome screen
add_action( 'load-index.php', function () {
$user_id = get_current_user_id();
if ( get_user_meta( $user_id, 'show_welcome_panel', true ) ) {
update_user_meta( $user_id, 'show_welcome_panel', 0 );
}
} );
// Disable live preview
add_filter( 'theme_action_links', function ( $actions ) {
unset ( $actions['preview'] );
return $actions;
} );
}