PluginProbe
Hotfix / 0.7
Hotfix v0.7
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 0.7, at hotfix.php

114 lines 3.1 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: 0.7
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 }
81
82 if ( ! function_exists( 'json_encode' ) ) {
83 function json_encode( $string ) {
84 global $wp_hotfix_json;
85
86 if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) {
87 require_once( dirname( __FILE__ ) . '/inc/class-json.php' );
88 $wp_hotfix_json = new Services_JSON();
89 }
90
91 return $wp_hotfix_json->encodeUnsafe( $string );
92 }
93 }
94
95 if ( ! function_exists( 'json_decode' ) && ! function_exists( '_json_decode_object_helper' ) ) {
96 function json_decode( $string, $assoc_array = false ) {
97 global $wp_hotfix_json;
98
99 if ( ! is_a( $wp_hotfix_json, 'Services_JSON' ) ) {
100 require_once( dirname( __FILE__ ) . '/inc/class-json.php' );
101 $wp_hotfix_json = new Services_JSON();
102 }
103
104 $res = $wp_hotfix_json->decode( $string );
105 if ( $assoc_array )
106 $res = _json_decode_object_helper( $res );
107 return $res;
108 }
109 function _json_decode_object_helper($data) {
110 if ( is_object($data) )
111 $data = get_object_vars($data);
112 return is_array($data) ? array_map(__FUNCTION__, $data) : $data;
113 }
114 }