| 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.5 |
| 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.1.3' : |
| 38 |
$hotfixes = array( '313_post_status_query_string' ); |
| 39 |
break; |
| 40 |
case '3.1' : |
| 41 |
$hotfixes = array( '310_parsed_tax_query' ); |
| 42 |
break; |
| 43 |
case '3.0.5' : |
| 44 |
$hotfixes = array( '305_comment_text_kses' ); |
| 45 |
break; |
| 46 |
} |
| 47 |
|
| 48 |
$hotfixes = apply_filters( 'wp_hotfixes', $hotfixes ); |
| 49 |
|
| 50 |
foreach ( (array) $hotfixes as $hotfix ) { |
| 51 |
call_user_func( 'wp_hotfix_' . $hotfix ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
/* And now, the hotfixes */ |
| 56 |
|
| 57 |
function wp_hotfix_305_comment_text_kses() { |
| 58 |
remove_filter( 'comment_text', 'wp_kses_data' ); |
| 59 |
if ( is_admin() ) |
| 60 |
add_filter( 'comment_text', 'wp_kses_post' ); |
| 61 |
} |
| 62 |
|
| 63 |
function wp_hotfix_310_parsed_tax_query() { |
| 64 |
add_filter( 'pre_get_posts', 'wp_hotfix_310_parsed_tax_query_pre_get_posts' ); |
| 65 |
} |
| 66 |
|
| 67 |
function wp_hotfix_310_parsed_tax_query_pre_get_posts( $q ) { |
| 68 |
@$q->parsed_tax_query = false; // Force it to be re-parsed. |
| 69 |
return $q; |
| 70 |
} |
| 71 |
|
| 72 |
function wp_hotfix_313_post_status_query_string() { |
| 73 |
add_filter( 'request', 'wp_hotfix_313_post_status_query_string_request' ); |
| 74 |
} |
| 75 |
|
| 76 |
function wp_hotfix_313_post_status_query_string_request( $qvs ) { |
| 77 |
if ( isset( $qvs['post_status'] ) && is_array( $qvs['post_status'] ) ) |
| 78 |
$qvs['post_status'] = implode( ',', $qvs['post_status'] ); |
| 79 |
return $qvs; |
| 80 |
} |