-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-freeze.php
266 lines (237 loc) · 8.88 KB
/
code-freeze.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
<?php
/*
Plugin Name: Code Freeze
Plugin URI: https://github.com/rvola/code-freeze
Description: Temporarily puts your WordPress into a "read only" state. When activated, comments and trackbacks are temporarily disabled as well as changes in the dashboard. Deactivate to restore full functionality.
Author: studio RVOLA
Author URI: http://www.rvola.com
Author original: Kevin Davis - http://www.davistribe.org
Text Domain: codefreeze
Domain Path: /languages/
Version: rvola-1.3.0
License: GPLv2
*/
/**
* LICENSE
* This file is part of Code Freeze.
*
* Code Freeze is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @package code-freeze
* @author Kevin Davis <[email protected]>
* @copyright Copyright 2012 Kevin Davis
* @license http://www.gnu.org/licenses/gpl.txt GPL 2.0
* @link http://www.davistribe.org/codefreeze/
*/
if ( ! function_exists( 'cf_custom_login_message' ) ) {
add_filter( 'login_message' , 'cf_custom_login_message' );
load_plugin_textdomain( 'codefreeze', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
/**
* Insert text onto login page
*
* @return string Text to insert onto login page
*/
function cf_custom_login_message() {
$message = '<p class="message" style="padding:10px;border: 2px solid red; margin-bottom: 10px;"><span style="color:red;font-weight:bold; text-align:center;display:block">'.__('CODE FREEZE NOTICE', 'codefreeze' ).':</span><br/>'.__('This site is currently being migrated to a new location. Changes made here will not be reflected in the migrated site. To avoid lost work, please do not make any changes to the site until this message is removed.', 'codefreeze' ).'</p>';
return $message;
}
}
if ( ! function_exists( 'cf_effective_notice' ) ) {
add_action( 'admin_notices', 'cf_effective_notice' );
/**
* Show notice on site pages when site disabled
*
* @return void
*/
function cf_effective_notice() {
echo '<div class="error"><p><strong>'.__('Warning: Code Freeze is in effect.', 'codefreeze').'</strong> '.__('All changes made during this period will be lost.', 'codefreeze' ).'</p></div>';
}
}
if ( ! function_exists( 'cf_admin_init' ) ) {
add_action( 'admin_init', 'cf_admin_init' );
add_action( 'admin_print_scripts', 'cf_load_admin_head' );
add_action( 'plugins_loaded', 'cf_close_comments' );
add_action( 'admin_head' , 'cf_remove_media_buttons' );
add_filter( 'tiny_mce_before_init', 'cf_visedit_readonly',10 ,1 );
add_filter( 'post_row_actions', 'cf_remove_row_actions', 10, 1 );
add_filter( 'page_row_actions', 'cf_remove_row_actions', 10, 1 );
add_filter( 'user_row_actions', 'cf_remove_row_actions', 10, 1 );
add_filter( 'tag_row_actions', 'cf_remove_row_actions', 10, 1 );
add_filter( 'media_row_actions', 'cf_remove_row_actions', 10, 1 );
add_filter( 'plugin_install_action_links', 'cf_remove_row_actions', 10, 1 );
add_filter( 'theme_install_action_links', 'cf_remove_row_actions', 10, 1 );
add_filter('plugin_action_links', 'cf_plugin_action_links', 10, 2);
/*Prevent Automatic Background Updates */
add_filter( 'auto_update_core', '__return_false' );
add_filter( 'auto_update_plugin', '__return_false' );
add_filter( 'auto_update_translation', '__return_false' );
add_filter( 'auto_update_theme', '__return_false' );
/**
* Register javascript, disable quickpress widget, remove add/edit menu items
*
* @return void
*/
function cf_admin_init() {
// register js
wp_register_script( 'codefreeze-js', plugins_url('/js/func.js', __FILE__), false, '1.3.0', true );
// make localizable
load_plugin_textdomain( 'codefreeze', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
// remove QuickPress widget
remove_meta_box('dashboard_quick_press', 'dashboard', 'normal');
// remove menu items - doesn't work for all of them in admin_menu
cf_modify_menu();
}
/**
* Load javascript on all admin pages
*
* @return void
*/
function cf_load_admin_head() {
wp_enqueue_script( 'codefreeze-js' );
wp_localize_script( 'codefreeze-js', 'cf', array(
'wp_version' => get_bloginfo( 'version' )
) );
}
/**
* Close comments and trackbacks while activated
*
* @return void
*/
function cf_close_comments() {
add_filter( 'the_posts', 'cf_set_comment_status' );
add_filter( 'comments_open', 'cf_close_the_comments', 10, 2 );
add_filter( 'pings_open', 'cf_close_the_comments', 10, 2 );
/**
* Close comments and trackbacks while activated
*
* @return array Array of posts with comments closed
*/
function cf_set_comment_status ( $posts ) {
if ( ! empty( $posts ) && is_singular() ) {
$posts[0]->comment_status = 'closed';
$posts[0]->post_status = 'closed';
}
return $posts;
}
/**
* Close comments and trackbacks while activated
*
* @return $open
*/
function cf_close_the_comments ( $open, $post_id ) {
// if not open, than back
if ( ! $open )
return $open;
$post = get_post( $post_id );
if ( $post -> post_type ) // all post types
return FALSE;
return $open;
}
}
/**
* Remove media upload button(s)
*
* @return void
*/
function cf_remove_media_buttons() {
remove_action( 'media_buttons', 'media_buttons' );
}
/**
* Set visual editor as "read only"
*
* @return array Array of arguments to send to editor
*/
function cf_visedit_readonly( $args ) {
// suppress php warning in core when editor is read only
$args['readonly'] = 1;
return $args;
}
/**
* Remove invalid action links
*
* @return array Modified array of action links
*/
function cf_remove_row_actions($actions) {
unset( $actions['trash'] );
unset( $actions['delete'] );
// no normal filter action for this (install plugin row)
foreach ($actions as $k => $v) {
if (strpos($v, 'class="install-now') ) {
unset ($actions[$k]);
}
}
return $actions;
}
/**
* Remove add/edit menu items
*
* @return void
*/
function cf_modify_menu() {
global $submenu;
unset($submenu['edit.php?post_type=page'][10]); // Page > Add New
remove_submenu_page('edit.php', 'post-new.php');
remove_submenu_page('sites.php', 'site-new.php');
remove_submenu_page('upload.php', 'media-new.php');
remove_submenu_page('link-manager.php', 'link-add.php');
remove_submenu_page('themes.php', 'theme-editor.php');
remove_submenu_page('themes.php', 'customize.php');
remove_submenu_page('themes.php', 'theme-install.php');
remove_submenu_page('plugins.php', 'plugin-editor.php');
remove_submenu_page('plugins.php', 'plugin-install.php');
remove_submenu_page('users.php', 'user-new.php');
remove_submenu_page('tools.php', 'import.php');
remove_submenu_page('update-core.php', 'upgrade.php');
}
/**
* Remove Activation/Deactivation/Edit links for all plugins but this one
*
* @return array Modified array of action links for plugins
*/
function cf_plugin_action_links($links, $file) {
$this_plugin = plugin_basename(__FILE__);
unset($links['edit']);
if ($file !== $this_plugin) {
return array(); // prevents PHP warning from any plugins that have modified the action links
}
return $links;
}
/**
* Remove topic replies and new topics from bbPress
*
* @note props to theZedt
* @return void
*/
if ( class_exists( 'bbPress' ) ) {
add_filter( 'bbp_current_user_can_access_create_reply_form', cf_close_bbp_comments );
add_filter( 'bbp_current_user_can_access_create_topic_form', cf_close_bbp_comments );
function cf_close_bbp_comments() {
return false;
}
}
}
/*--------------------------------------------------------- */
/* !Activation/Deactivation */
/*--------------------------------------------------------- */
register_activation_hook( __FILE__, 'cf_activation_action');
function cf_activation_action() {
add_option( 'cf-backup-users_can_register', get_option( 'users_can_register'), false, true );
update_option( 'users_can_register', 0 );
}
register_deactivation_hook( __FILE__, 'cf_desactivation_action');
function cf_desactivation_action() {
update_option( 'users_can_register', get_option( 'cf-backup-users_can_register') );
delete_option( 'cf-backup-users_can_register' );
}