| 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.9 |
| 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.4.2' : |
| 38 |
$hotfixes = array( '342_custom_fields' ); |
| 39 |
break; |
| 40 |
case '3.3' : |
| 41 |
$hotfixes = array( '330_no_wp_print_styles_in_admin', '330_no_json_encode_load_scripts' ); |
| 42 |
break; |
| 43 |
case '3.1.3' : |
| 44 |
$hotfixes = array( '313_post_status_query_string' ); |
| 45 |
break; |
| 46 |
case '3.1' : |
| 47 |
$hotfixes = array( '310_parsed_tax_query' ); |
| 48 |
break; |
| 49 |
case '3.0.5' : |
| 50 |
$hotfixes = array( '305_comment_text_kses' ); |
| 51 |
break; |
| 52 |
} |
| 53 |
|
| 54 |
$hotfixes = apply_filters( 'wp_hotfixes', $hotfixes ); |
| 55 |
|
| 56 |
foreach ( (array) $hotfixes as $hotfix ) { |
| 57 |
call_user_func( 'wp_hotfix_' . $hotfix ); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/* And now, the hotfixes */ |
| 62 |
|
| 63 |
function wp_hotfix_305_comment_text_kses() { |
| 64 |
remove_filter( 'comment_text', 'wp_kses_data' ); |
| 65 |
if ( is_admin() ) |
| 66 |
add_filter( 'comment_text', 'wp_kses_post' ); |
| 67 |
} |
| 68 |
|
| 69 |
function wp_hotfix_310_parsed_tax_query() { |
| 70 |
add_filter( 'pre_get_posts', 'wp_hotfix_310_parsed_tax_query_pre_get_posts' ); |
| 71 |
} |
| 72 |
|
| 73 |
function wp_hotfix_310_parsed_tax_query_pre_get_posts( $q ) { |
| 74 |
@$q->parsed_tax_query = false; // Force it to be re-parsed. |
| 75 |
return $q; |
| 76 |
} |
| 77 |
|
| 78 |
function wp_hotfix_313_post_status_query_string() { |
| 79 |
add_filter( 'request', 'wp_hotfix_313_post_status_query_string_request' ); |
| 80 |
} |
| 81 |
|
| 82 |
function wp_hotfix_313_post_status_query_string_request( $qvs ) { |
| 83 |
if ( isset( $qvs['post_status'] ) && is_array( $qvs['post_status'] ) ) |
| 84 |
$qvs['post_status'] = implode( ',', $qvs['post_status'] ); |
| 85 |
return $qvs; |
| 86 |
} |
| 87 |
|
| 88 |
if ( ! function_exists( 'json_encode' ) ) { |
| 89 |
function json_encode( $string ) { |
| 90 |
global $wp_hotfix_json; |
| 91 |
|
| 92 |
if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) { |
| 93 |
require_once( dirname( __FILE__ ) . '/inc/class-json.php' ); |
| 94 |
$wp_hotfix_json = new Services_JSON(); |
| 95 |
} |
| 96 |
|
| 97 |
return $wp_hotfix_json->encodeUnsafe( $string ); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
if ( ! function_exists( 'json_decode' ) && ! function_exists( '_json_decode_object_helper' ) ) { |
| 102 |
function json_decode( $string, $assoc_array = false ) { |
| 103 |
global $wp_hotfix_json; |
| 104 |
|
| 105 |
if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) { |
| 106 |
require_once( dirname( __FILE__ ) . '/inc/class-json.php' ); |
| 107 |
$wp_hotfix_json = new Services_JSON(); |
| 108 |
} |
| 109 |
|
| 110 |
$res = $wp_hotfix_json->decode( $string ); |
| 111 |
if ( $assoc_array ) |
| 112 |
$res = _json_decode_object_helper( $res ); |
| 113 |
return $res; |
| 114 |
} |
| 115 |
function _json_decode_object_helper($data) { |
| 116 |
if ( is_object($data) ) |
| 117 |
$data = get_object_vars($data); |
| 118 |
return is_array($data) ? array_map(__FUNCTION__, $data) : $data; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
function wp_hotfix_330_no_wp_print_styles_in_admin() { |
| 123 |
add_action( 'admin_init', 'wp_hotfix_330_no_wp_print_styles_in_admin_remove', 999 ); |
| 124 |
} |
| 125 |
|
| 126 |
function wp_hotfix_330_no_wp_print_styles_in_admin_remove() { |
| 127 |
remove_all_actions( 'wp_print_styles' ); |
| 128 |
} |
| 129 |
|
| 130 |
function wp_hotfix_330_no_json_encode_load_scripts() { |
| 131 |
$functions = get_defined_functions(); |
| 132 |
if ( in_array( 'json_encode', $functions['internal'] ) ) |
| 133 |
return; |
| 134 |
|
| 135 |
if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) |
| 136 |
define( 'CONCATENATE_SCRIPTS', false ); |
| 137 |
} |
| 138 |
|
| 139 |
function wp_hotfix_342_custom_fields() { |
| 140 |
add_action( 'admin_footer-post.php', 'wp_hotfix_342_custom_fields_action' ); |
| 141 |
add_action( 'admin_footer-post-new.php', 'wp_hotfix_342_custom_fields_action' ); |
| 142 |
} |
| 143 |
|
| 144 |
function wp_hotfix_342_custom_fields_action() { |
| 145 |
?><script> |
| 146 |
jQuery(document).ready( function($) { |
| 147 |
$('#postcustomstuff').on('hover focus', '#addmetasub, #updatemeta', function() { |
| 148 |
$(this).attr('id', 'meta-add-submit'); |
| 149 |
}); |
| 150 |
}); |
| 151 |
</script> |
| 152 |
<?php |
| 153 |
} |
| 154 |
|