PluginProbe
Hotfix / 1.4
Hotfix v1.4
trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4
hotfix / hotfix.php

hotfix.php in Hotfix 1.4, at hotfix.php

292 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Hotfix
4 Description: Provides "hotfixes" for selected WordPress bugs, so you don't have to wait for the next WordPress core release. Keep the plugin updated!
5 Version: 1.4
6 Author: Mark Jaquith
7 Author URI: http://coveredwebservices.com/
8 */
9
10 // This bootstraps everything
11 WP_Hotfix_Controller::init();
12
13 class WP_Hotfix_Controller {
14 public static function init() {
15 add_action( 'init', 'wp_hotfix_init' );
16 register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
17 register_deactivation_hook( __FILE__, array( __CLASS__, 'deactivate' ) );
18 }
19 public static function activate() {
20 add_option( 'hotfix_version', '1' );
21 register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
22 }
23 public static function deactivate() {
24 delete_option( 'hotfix_version' );
25 }
26 public static function uninstall() {
27 self::deactivate(); // The same, for now
28 }
29 }
30
31 function wp_hotfix_init() {
32 global $wp_version;
33
34 $hotfixes = array();
35
36 switch ( $wp_version ) {
37 case '7.0' :
38 $hotfixes = array( '700_publishing_actions' ); // https://core.trac.wordpress.org/ticket/65286
39 break;
40 case '6.9' :
41 $hotfixes = array( '690_email_sender' ); // https://core.trac.wordpress.org/ticket/64368
42 break;
43 case '5.1' :
44 $hotfixes = array( '510_comment_reply_js' );
45 break;
46 case '3.5' :
47 $hotfixes = array( '350_twentytwelve', '350_iis_http_failure' );
48 break;
49 case '3.4.2' :
50 $hotfixes = array( '342_custom_fields' );
51 break;
52 case '3.3' :
53 $hotfixes = array( '330_no_wp_print_styles_in_admin', '330_no_json_encode_load_scripts' );
54 break;
55 case '3.1.3' :
56 $hotfixes = array( '313_post_status_query_string' );
57 break;
58 case '3.1' :
59 $hotfixes = array( '310_parsed_tax_query' );
60 break;
61 case '3.0.5' :
62 $hotfixes = array( '305_comment_text_kses' );
63 break;
64 }
65
66 $hotfixes = apply_filters( 'wp_hotfixes', $hotfixes );
67
68 foreach ( (array) $hotfixes as $hotfix ) {
69 call_user_func( 'wp_hotfix_' . $hotfix );
70 }
71 }
72
73 /* And now, the hotfixes */
74
75 function wp_hotfix_305_comment_text_kses() {
76 remove_filter( 'comment_text', 'wp_kses_data' );
77 if ( is_admin() )
78 add_filter( 'comment_text', 'wp_kses_post' );
79 }
80
81 function wp_hotfix_310_parsed_tax_query() {
82 add_filter( 'pre_get_posts', 'wp_hotfix_310_parsed_tax_query_pre_get_posts' );
83 }
84
85 function wp_hotfix_310_parsed_tax_query_pre_get_posts( $q ) {
86 @$q->parsed_tax_query = false; // Force it to be re-parsed.
87 return $q;
88 }
89
90 function wp_hotfix_313_post_status_query_string() {
91 add_filter( 'request', 'wp_hotfix_313_post_status_query_string_request' );
92 }
93
94 function wp_hotfix_313_post_status_query_string_request( $qvs ) {
95 if ( isset( $qvs['post_status'] ) && is_array( $qvs['post_status'] ) )
96 $qvs['post_status'] = implode( ',', $qvs['post_status'] );
97 return $qvs;
98 }
99
100 if ( ! function_exists( 'json_encode' ) ) {
101 function json_encode( $string ) {
102 global $wp_hotfix_json;
103
104 if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) {
105 require_once( dirname( __FILE__ ) . '/inc/class-json.php' );
106 $wp_hotfix_json = new Services_JSON();
107 }
108
109 return $wp_hotfix_json->encodeUnsafe( $string );
110 }
111 }
112
113 if ( ! function_exists( 'json_decode' ) && ! function_exists( '_json_decode_object_helper' ) ) {
114 function json_decode( $string, $assoc_array = false ) {
115 global $wp_hotfix_json;
116
117 if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) {
118 require_once( dirname( __FILE__ ) . '/inc/class-json.php' );
119 $wp_hotfix_json = new Services_JSON();
120 }
121
122 $res = $wp_hotfix_json->decode( $string );
123 if ( $assoc_array )
124 $res = _json_decode_object_helper( $res );
125 return $res;
126 }
127 function _json_decode_object_helper($data) {
128 if ( is_object($data) )
129 $data = get_object_vars($data);
130 return is_array($data) ? array_map(__FUNCTION__, $data) : $data;
131 }
132 }
133
134 function wp_hotfix_330_no_wp_print_styles_in_admin() {
135 add_action( 'admin_init', 'wp_hotfix_330_no_wp_print_styles_in_admin_remove', 999 );
136 }
137
138 function wp_hotfix_330_no_wp_print_styles_in_admin_remove() {
139 remove_all_actions( 'wp_print_styles' );
140 }
141
142 function wp_hotfix_330_no_json_encode_load_scripts() {
143 $functions = get_defined_functions();
144 if ( in_array( 'json_encode', $functions['internal'] ) )
145 return;
146
147 if ( ! defined( 'CONCATENATE_SCRIPTS' ) )
148 define( 'CONCATENATE_SCRIPTS', false );
149 }
150
151 function wp_hotfix_342_custom_fields() {
152 add_action( 'admin_footer-post.php', 'wp_hotfix_342_custom_fields_action' );
153 add_action( 'admin_footer-post-new.php', 'wp_hotfix_342_custom_fields_action' );
154 }
155
156 function wp_hotfix_342_custom_fields_action() {
157 ?><script>
158 jQuery(document).ready( function($) {
159 $('#postcustomstuff').on('hover focus', '#addmetasub, #updatemeta', function() {
160 $(this).attr('id', 'meta-add-submit');
161 });
162 });
163 </script>
164 <?php
165 }
166
167 function wp_hotfix_350_twentytwelve() {
168 add_action( 'pre_http_request', 'wp_hotfix_350_twentytwelve_pre_http_request', 10, 3 );
169 add_action( 'load-themes.php', 'wp_hotfix_350_twentytwelve_themes_php' );
170 add_action( 'load-update-core.php', 'wp_hotfix_350_twentytwelve_update_core_php', 9 );
171 }
172
173 function wp_hotfix_350_twentytwelve_update_core_php() {
174 if ( ! empty( $_GET['action'] ) )
175 return;
176
177 $theme = wp_get_theme('twentytwelve');
178 if ( ! $theme->exists() || ! $theme->errors() )
179 return;
180
181 delete_site_transient( 'update_themes' );
182 }
183
184 function wp_hotfix_350_twentytwelve_themes_php() {
185 $theme = wp_get_theme('twentytwelve');
186 if ( ! $theme->exists() || ! $theme->errors() )
187 return;
188
189 // Non-English installs weren't affected. Saves us the need to translate!
190 if ( 'en_US' != get_locale() )
191 return;
192
193 if ( current_user_can( 'update_themes' ) )
194 add_action( 'admin_notices', 'wp_hotfix_350_twentytwelve_notice' );
195 }
196
197 function wp_hotfix_350_twentytwelve_notice() {
198 printf( '<div class="error"><p><strong>Looking for Twenty Twelve?</strong> You will need to first update it at <a href="%s">Dashboard &rarr; Updates</a>.</p></div>',
199 self_admin_url( 'update-core.php' ) );
200 }
201
202 function wp_hotfix_350_twentytwelve_pre_http_request( $return, $args, $url ) {
203 if ( $url != 'http://api.wordpress.org/themes/update-check/1.0/' )
204 return $return;
205
206 if ( ! empty( $args['_twentytwelve_hijack'] ) )
207 return $return;
208
209 $theme = wp_get_theme('twentytwelve');
210 if ( ! $theme->exists() || ! $theme->errors() )
211 return $return;
212
213 $args['_twentytwelve_hijack'] = true;
214
215 $themes = unserialize( $args['body']['themes'] );
216 $themes['twentytwelve'] = array(
217 'Name' => 'Twenty Twelve',
218 'Title' => 'Twenty Twelve',
219 'Version' => '1.0',
220 'Author' => 'the WordPress team',
221 'Author URI' => 'http://wordpress.org/',
222 'Template' => 'twentytwelve',
223 'Stylesheet' => 'twentytwelve',
224 );
225 $args['body']['themes'] = serialize( $themes );
226 return wp_remote_post( $url, $args );
227 }
228
229 function wp_hotfix_350_iis_http_failure() {
230 add_filter( 'filesystem_method', 'wp_hotfix_350_iis_http_failure_define' );
231 }
232
233 function wp_hotfix_350_iis_http_failure_define( $filter ) {
234 if ( ! defined( 'WP_TEMP_DIR' ) )
235 define( 'WP_TEMP_DIR', wp_hotfix_350_iis_http_failure_get_temp_dir() );
236 remove_filter( 'filesystem_method', 'wp_hotfix_350_iis_http_failure_define' );
237 return $filter;
238 }
239
240 function wp_hotfix_350_iis_http_failure_get_temp_dir() {
241 $temp = ini_get('upload_tmp_dir');
242 if ( is_dir( $temp ) && @is_writable( $temp ) )
243 return trailingslashit( rtrim( $temp, '\\' ) );
244
245 $temp = WP_CONTENT_DIR . '/';
246 if ( is_dir( $temp ) && @is_writable( $temp ) )
247 return $temp;
248 return false;
249 }
250
251 function wp_hotfix_510_comment_reply_js() {
252 add_action( 'wp_enqueue_scripts', 'wp_hotfix_510_enqueue_comment_reply_js', 99 );
253 }
254
255 function wp_hotfix_510_enqueue_comment_reply_js() {
256 global $wp_scripts;
257
258 $suffix = SCRIPT_DEBUG ? '' : '.min';
259
260 $wp_scripts->registered['comment-reply']->src = plugins_url( "js/comment-reply$suffix.js", __FILE__ );
261 $wp_scripts->registered['comment-reply']->ver = 'wp46280';
262 }
263
264 function wp_hotfix_690_email_sender() {
265 add_action( 'phpmailer_init', 'wp_hotfix_690_email_sender_use_no_sender' );
266 }
267
268 function wp_hotfix_690_email_sender_use_no_sender( $phpmailer ) {
269 $phpmailer->Sender = "";
270 }
271
272 function wp_hotfix_700_publishing_actions() {
273 add_action( 'admin_print_styles', 'wp_hotfix_700_publishing_actions_css' );
274 }
275
276 function wp_hotfix_700_publishing_actions_css() {
277 global $hook_suffix;
278
279 if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) {
280 return;
281 }
282 ?>
283
284 <style>
285 #major-publishing-actions {
286 flex-wrap: wrap;
287 }
288 </style>
289
290 <?php
291 }
292