| 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: 0.8 |
| 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 |
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 |
function activate() { |
| 20 |
add_option( 'hotfix_version', '1' ); |
| 21 |
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) ); |
| 22 |
} |
| 23 |
function deactivate() { |
| 24 |
delete_option( 'hotfix_version' ); |
| 25 |
} |
| 26 |
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 '3.3' : |
| 38 |
$hotfixes = array( '330_no_wp_print_styles_in_admin', '330_no_json_encode_load_scripts' ); |
| 39 |
break; |
| 40 |
case '3.1.3' : |
| 41 |
$hotfixes = array( '313_post_status_query_string' ); |
| 42 |
break; |
| 43 |
case '3.1' : |
| 44 |
$hotfixes = array( '310_parsed_tax_query' ); |
| 45 |
break; |
| 46 |
case '3.0.5' : |
| 47 |
$hotfixes = array( '305_comment_text_kses' ); |
| 48 |
break; |
| 49 |
} |
| 50 |
|
| 51 |
$hotfixes = apply_filters( 'wp_hotfixes', $hotfixes ); |
| 52 |
|
| 53 |
foreach ( (array) $hotfixes as $hotfix ) { |
| 54 |
call_user_func( 'wp_hotfix_' . $hotfix ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/* And now, the hotfixes */ |
| 59 |
|
| 60 |
function wp_hotfix_305_comment_text_kses() { |
| 61 |
remove_filter( 'comment_text', 'wp_kses_data' ); |
| 62 |
if ( is_admin() ) |
| 63 |
add_filter( 'comment_text', 'wp_kses_post' ); |
| 64 |
} |
| 65 |
|
| 66 |
function wp_hotfix_310_parsed_tax_query() { |
| 67 |
add_filter( 'pre_get_posts', 'wp_hotfix_310_parsed_tax_query_pre_get_posts' ); |
| 68 |
} |
| 69 |
|
| 70 |
function wp_hotfix_310_parsed_tax_query_pre_get_posts( $q ) { |
| 71 |
@$q->parsed_tax_query = false; // Force it to be re-parsed. |
| 72 |
return $q; |
| 73 |
} |
| 74 |
|
| 75 |
function wp_hotfix_313_post_status_query_string() { |
| 76 |
add_filter( 'request', 'wp_hotfix_313_post_status_query_string_request' ); |
| 77 |
} |
| 78 |
|
| 79 |
function wp_hotfix_313_post_status_query_string_request( $qvs ) { |
| 80 |
if ( isset( $qvs['post_status'] ) && is_array( $qvs['post_status'] ) ) |
| 81 |
$qvs['post_status'] = implode( ',', $qvs['post_status'] ); |
| 82 |
return $qvs; |
| 83 |
} |
| 84 |
|
| 85 |
if ( ! function_exists( 'json_encode' ) ) { |
| 86 |
function json_encode( $string ) { |
| 87 |
global $wp_hotfix_json; |
| 88 |
|
| 89 |
if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) { |
| 90 |
require_once( dirname( __FILE__ ) . '/inc/class-json.php' ); |
| 91 |
$wp_hotfix_json = new Services_JSON(); |
| 92 |
} |
| 93 |
|
| 94 |
return $wp_hotfix_json->encodeUnsafe( $string ); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
if ( ! function_exists( 'json_decode' ) && ! function_exists( '_json_decode_object_helper' ) ) { |
| 99 |
function json_decode( $string, $assoc_array = false ) { |
| 100 |
global $wp_hotfix_json; |
| 101 |
|
| 102 |
if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) { |
| 103 |
require_once( dirname( __FILE__ ) . '/inc/class-json.php' ); |
| 104 |
$wp_hotfix_json = new Services_JSON(); |
| 105 |
} |
| 106 |
|
| 107 |
$res = $wp_hotfix_json->decode( $string ); |
| 108 |
if ( $assoc_array ) |
| 109 |
$res = _json_decode_object_helper( $res ); |
| 110 |
return $res; |
| 111 |
} |
| 112 |
function _json_decode_object_helper($data) { |
| 113 |
if ( is_object($data) ) |
| 114 |
$data = get_object_vars($data); |
| 115 |
return is_array($data) ? array_map(__FUNCTION__, $data) : $data; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
function wp_hotfix_330_no_wp_print_styles_in_admin() { |
| 120 |
add_action( 'admin_init', 'wp_hotfix_330_no_wp_print_styles_in_admin_remove', 999 ); |
| 121 |
} |
| 122 |
|
| 123 |
function wp_hotfix_330_no_wp_print_styles_in_admin_remove() { |
| 124 |
remove_all_actions( 'wp_print_styles' ); |
| 125 |
} |
| 126 |
|
| 127 |
function wp_hotfix_330_no_json_encode_load_scripts() { |
| 128 |
$functions = get_defined_functions(); |
| 129 |
if ( in_array( 'json_encode', $functions['internal'] ) ) |
| 130 |
return; |
| 131 |
|
| 132 |
if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) |
| 133 |
define( 'CONCATENATE_SCRIPTS', false ); |
| 134 |
} |
| 135 |
|