PluginProbe
Hotfix / 1.2
Hotfix v1.2
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.2, at hotfix.php

257 lines 7.4 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.2
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 '5.1' :
38 $hotfixes = array( '510_comment_reply_js' );
39 break;
40 case '3.5' :
41 $hotfixes = array( '350_twentytwelve', '350_iis_http_failure' );
42 break;
43 case '3.4.2' :
44 $hotfixes = array( '342_custom_fields' );
45 break;
46 case '3.3' :
47 $hotfixes = array( '330_no_wp_print_styles_in_admin', '330_no_json_encode_load_scripts' );
48 break;
49 case '3.1.3' :
50 $hotfixes = array( '313_post_status_query_string' );
51 break;
52 case '3.1' :
53 $hotfixes = array( '310_parsed_tax_query' );
54 break;
55 case '3.0.5' :
56 $hotfixes = array( '305_comment_text_kses' );
57 break;
58 }
59
60 $hotfixes = apply_filters( 'wp_hotfixes', $hotfixes );
61
62 foreach ( (array) $hotfixes as $hotfix ) {
63 call_user_func( 'wp_hotfix_' . $hotfix );
64 }
65 }
66
67 /* And now, the hotfixes */
68
69 function wp_hotfix_305_comment_text_kses() {
70 remove_filter( 'comment_text', 'wp_kses_data' );
71 if ( is_admin() )
72 add_filter( 'comment_text', 'wp_kses_post' );
73 }
74
75 function wp_hotfix_310_parsed_tax_query() {
76 add_filter( 'pre_get_posts', 'wp_hotfix_310_parsed_tax_query_pre_get_posts' );
77 }
78
79 function wp_hotfix_310_parsed_tax_query_pre_get_posts( $q ) {
80 @$q->parsed_tax_query = false; // Force it to be re-parsed.
81 return $q;
82 }
83
84 function wp_hotfix_313_post_status_query_string() {
85 add_filter( 'request', 'wp_hotfix_313_post_status_query_string_request' );
86 }
87
88 function wp_hotfix_313_post_status_query_string_request( $qvs ) {
89 if ( isset( $qvs['post_status'] ) && is_array( $qvs['post_status'] ) )
90 $qvs['post_status'] = implode( ',', $qvs['post_status'] );
91 return $qvs;
92 }
93
94 if ( ! function_exists( 'json_encode' ) ) {
95 function json_encode( $string ) {
96 global $wp_hotfix_json;
97
98 if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) {
99 require_once( dirname( __FILE__ ) . '/inc/class-json.php' );
100 $wp_hotfix_json = new Services_JSON();
101 }
102
103 return $wp_hotfix_json->encodeUnsafe( $string );
104 }
105 }
106
107 if ( ! function_exists( 'json_decode' ) && ! function_exists( '_json_decode_object_helper' ) ) {
108 function json_decode( $string, $assoc_array = false ) {
109 global $wp_hotfix_json;
110
111 if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) {
112 require_once( dirname( __FILE__ ) . '/inc/class-json.php' );
113 $wp_hotfix_json = new Services_JSON();
114 }
115
116 $res = $wp_hotfix_json->decode( $string );
117 if ( $assoc_array )
118 $res = _json_decode_object_helper( $res );
119 return $res;
120 }
121 function _json_decode_object_helper($data) {
122 if ( is_object($data) )
123 $data = get_object_vars($data);
124 return is_array($data) ? array_map(__FUNCTION__, $data) : $data;
125 }
126 }
127
128 function wp_hotfix_330_no_wp_print_styles_in_admin() {
129 add_action( 'admin_init', 'wp_hotfix_330_no_wp_print_styles_in_admin_remove', 999 );
130 }
131
132 function wp_hotfix_330_no_wp_print_styles_in_admin_remove() {
133 remove_all_actions( 'wp_print_styles' );
134 }
135
136 function wp_hotfix_330_no_json_encode_load_scripts() {
137 $functions = get_defined_functions();
138 if ( in_array( 'json_encode', $functions['internal'] ) )
139 return;
140
141 if ( ! defined( 'CONCATENATE_SCRIPTS' ) )
142 define( 'CONCATENATE_SCRIPTS', false );
143 }
144
145 function wp_hotfix_342_custom_fields() {
146 add_action( 'admin_footer-post.php', 'wp_hotfix_342_custom_fields_action' );
147 add_action( 'admin_footer-post-new.php', 'wp_hotfix_342_custom_fields_action' );
148 }
149
150 function wp_hotfix_342_custom_fields_action() {
151 ?><script>
152 jQuery(document).ready( function($) {
153 $('#postcustomstuff').on('hover focus', '#addmetasub, #updatemeta', function() {
154 $(this).attr('id', 'meta-add-submit');
155 });
156 });
157 </script>
158 <?php
159 }
160
161 function wp_hotfix_350_twentytwelve() {
162 add_action( 'pre_http_request', 'wp_hotfix_350_twentytwelve_pre_http_request', 10, 3 );
163 add_action( 'load-themes.php', 'wp_hotfix_350_twentytwelve_themes_php' );
164 add_action( 'load-update-core.php', 'wp_hotfix_350_twentytwelve_update_core_php', 9 );
165 }
166
167 function wp_hotfix_350_twentytwelve_update_core_php() {
168 if ( ! empty( $_GET['action'] ) )
169 return;
170
171 $theme = wp_get_theme('twentytwelve');
172 if ( ! $theme->exists() || ! $theme->errors() )
173 return;
174
175 delete_site_transient( 'update_themes' );
176 }
177
178 function wp_hotfix_350_twentytwelve_themes_php() {
179 $theme = wp_get_theme('twentytwelve');
180 if ( ! $theme->exists() || ! $theme->errors() )
181 return;
182
183 // Non-English installs weren't affected. Saves us the need to translate!
184 if ( 'en_US' != get_locale() )
185 return;
186
187 if ( current_user_can( 'update_themes' ) )
188 add_action( 'admin_notices', 'wp_hotfix_350_twentytwelve_notice' );
189 }
190
191 function wp_hotfix_350_twentytwelve_notice() {
192 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>',
193 self_admin_url( 'update-core.php' ) );
194 }
195
196 function wp_hotfix_350_twentytwelve_pre_http_request( $return, $args, $url ) {
197 if ( $url != 'http://api.wordpress.org/themes/update-check/1.0/' )
198 return $return;
199
200 if ( ! empty( $args['_twentytwelve_hijack'] ) )
201 return $return;
202
203 $theme = wp_get_theme('twentytwelve');
204 if ( ! $theme->exists() || ! $theme->errors() )
205 return $return;
206
207 $args['_twentytwelve_hijack'] = true;
208
209 $themes = unserialize( $args['body']['themes'] );
210 $themes['twentytwelve'] = array(
211 'Name' => 'Twenty Twelve',
212 'Title' => 'Twenty Twelve',
213 'Version' => '1.0',
214 'Author' => 'the WordPress team',
215 'Author URI' => 'http://wordpress.org/',
216 'Template' => 'twentytwelve',
217 'Stylesheet' => 'twentytwelve',
218 );
219 $args['body']['themes'] = serialize( $themes );
220 return wp_remote_post( $url, $args );
221 }
222
223 function wp_hotfix_350_iis_http_failure() {
224 add_filter( 'filesystem_method', 'wp_hotfix_350_iis_http_failure_define' );
225 }
226
227 function wp_hotfix_350_iis_http_failure_define( $filter ) {
228 if ( ! defined( 'WP_TEMP_DIR' ) )
229 define( 'WP_TEMP_DIR', wp_hotfix_350_iis_http_failure_get_temp_dir() );
230 remove_filter( 'filesystem_method', 'wp_hotfix_350_iis_http_failure_define' );
231 return $filter;
232 }
233
234 function wp_hotfix_350_iis_http_failure_get_temp_dir() {
235 $temp = ini_get('upload_tmp_dir');
236 if ( is_dir( $temp ) && @is_writable( $temp ) )
237 return trailingslashit( rtrim( $temp, '\\' ) );
238
239 $temp = WP_CONTENT_DIR . '/';
240 if ( is_dir( $temp ) && @is_writable( $temp ) )
241 return $temp;
242 return false;
243 }
244
245 function wp_hotfix_510_comment_reply_js() {
246 add_action( 'wp_enqueue_scripts', 'wp_hotfix_510_enqueue_comment_reply_js', 99 );
247 }
248
249 function wp_hotfix_510_enqueue_comment_reply_js() {
250 global $wp_scripts;
251
252 $suffix = SCRIPT_DEBUG ? '' : '.min';
253
254 $wp_scripts->registered['comment-reply']->src = plugins_url( "js/comment-reply$suffix.js", __FILE__ );
255 $wp_scripts->registered['comment-reply']->ver = 'wp46280';
256 }
257