@@ -94,13 +94,15 @@ discard block |
||
94 | 94 | $new_instance = (array) $new_instance; |
95 | 95 | $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); |
96 | 96 | foreach ( $instance as $field => $val ) { |
97 | - if ( isset($new_instance[$field]) ) |
|
98 | - $instance[$field] = 1; |
|
97 | + if ( isset($new_instance[$field]) ) { |
|
98 | + $instance[$field] = 1; |
|
99 | + } |
|
99 | 100 | } |
100 | 101 | |
101 | 102 | $instance['orderby'] = 'name'; |
102 | - if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) |
|
103 | - $instance['orderby'] = $new_instance['orderby']; |
|
103 | + if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) { |
|
104 | + $instance['orderby'] = $new_instance['orderby']; |
|
105 | + } |
|
104 | 106 | |
105 | 107 | $instance['category'] = intval( $new_instance['category'] ); |
106 | 108 | $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1; |
@@ -121,8 +123,9 @@ discard block |
||
121 | 123 | //Defaults |
122 | 124 | $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) ); |
123 | 125 | $link_cats = get_terms( 'link_category' ); |
124 | - if ( ! $limit = intval( $instance['limit'] ) ) |
|
125 | - $limit = -1; |
|
126 | + if ( ! $limit = intval( $instance['limit'] ) ) { |
|
127 | + $limit = -1; |
|
128 | + } |
|
126 | 129 | ?> |
127 | 130 | <p> |
128 | 131 | <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label> |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | $widget_ops = array( |
27 | - 'description' => __( 'Your blogroll' ), |
|
27 | + 'description' => __('Your blogroll'), |
|
28 | 28 | 'customize_selective_refresh' => true, |
29 | 29 | ); |
30 | - parent::__construct( 'links', __( 'Links' ), $widget_ops ); |
|
30 | + parent::__construct('links', __('Links'), $widget_ops); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -40,17 +40,17 @@ discard block |
||
40 | 40 | * 'before_widget', and 'after_widget'. |
41 | 41 | * @param array $instance Settings for the current Links widget instance. |
42 | 42 | */ |
43 | - public function widget( $args, $instance ) { |
|
43 | + public function widget($args, $instance) { |
|
44 | 44 | $show_description = isset($instance['description']) ? $instance['description'] : false; |
45 | 45 | $show_name = isset($instance['name']) ? $instance['name'] : false; |
46 | 46 | $show_rating = isset($instance['rating']) ? $instance['rating'] : false; |
47 | 47 | $show_images = isset($instance['images']) ? $instance['images'] : true; |
48 | 48 | $category = isset($instance['category']) ? $instance['category'] : false; |
49 | - $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name'; |
|
49 | + $orderby = isset($instance['orderby']) ? $instance['orderby'] : 'name'; |
|
50 | 50 | $order = $orderby == 'rating' ? 'DESC' : 'ASC'; |
51 | - $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1; |
|
51 | + $limit = isset($instance['limit']) ? $instance['limit'] : -1; |
|
52 | 52 | |
53 | - $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] ); |
|
53 | + $before_widget = preg_replace('/id="[^"]*"/', 'id="%id"', $args['before_widget']); |
|
54 | 54 | |
55 | 55 | $widget_links_args = array( |
56 | 56 | 'title_before' => $args['before_title'], |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param array $widget_links_args An array of arguments to retrieve the links list. |
80 | 80 | * @param array $instance The settings for the particular instance of the widget. |
81 | 81 | */ |
82 | - wp_list_bookmarks( apply_filters( 'widget_links_args', $widget_links_args, $instance ) ); |
|
82 | + wp_list_bookmarks(apply_filters('widget_links_args', $widget_links_args, $instance)); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -93,20 +93,20 @@ discard block |
||
93 | 93 | * @param array $old_instance Old settings for this instance. |
94 | 94 | * @return array Updated settings to save. |
95 | 95 | */ |
96 | - public function update( $new_instance, $old_instance ) { |
|
96 | + public function update($new_instance, $old_instance) { |
|
97 | 97 | $new_instance = (array) $new_instance; |
98 | - $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); |
|
99 | - foreach ( $instance as $field => $val ) { |
|
100 | - if ( isset($new_instance[$field]) ) |
|
98 | + $instance = array('images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0); |
|
99 | + foreach ($instance as $field => $val) { |
|
100 | + if (isset($new_instance[$field])) |
|
101 | 101 | $instance[$field] = 1; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $instance['orderby'] = 'name'; |
105 | - if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) |
|
105 | + if (in_array($new_instance['orderby'], array('name', 'rating', 'id', 'rand'))) |
|
106 | 106 | $instance['orderby'] = $new_instance['orderby']; |
107 | 107 | |
108 | - $instance['category'] = intval( $new_instance['category'] ); |
|
109 | - $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1; |
|
108 | + $instance['category'] = intval($new_instance['category']); |
|
109 | + $instance['limit'] = ! empty($new_instance['limit']) ? intval($new_instance['limit']) : -1; |
|
110 | 110 | |
111 | 111 | return $instance; |
112 | 112 | } |
@@ -119,32 +119,32 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @param array $instance Current settings. |
121 | 121 | */ |
122 | - public function form( $instance ) { |
|
122 | + public function form($instance) { |
|
123 | 123 | |
124 | 124 | //Defaults |
125 | - $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) ); |
|
126 | - $link_cats = get_terms( 'link_category' ); |
|
127 | - if ( ! $limit = intval( $instance['limit'] ) ) |
|
125 | + $instance = wp_parse_args((array) $instance, array('images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1)); |
|
126 | + $link_cats = get_terms('link_category'); |
|
127 | + if ( ! $limit = intval($instance['limit'])) |
|
128 | 128 | $limit = -1; |
129 | 129 | ?> |
130 | 130 | <p> |
131 | - <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label> |
|
131 | + <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Select Link Category:'); ?></label> |
|
132 | 132 | <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>"> |
133 | 133 | <option value=""><?php _ex('All Links', 'links widget'); ?></option> |
134 | 134 | <?php |
135 | - foreach ( $link_cats as $link_cat ) { |
|
136 | - echo '<option value="' . intval( $link_cat->term_id ) . '"' |
|
137 | - . selected( $instance['category'], $link_cat->term_id, false ) |
|
138 | - . '>' . $link_cat->name . "</option>\n"; |
|
135 | + foreach ($link_cats as $link_cat) { |
|
136 | + echo '<option value="'.intval($link_cat->term_id).'"' |
|
137 | + . selected($instance['category'], $link_cat->term_id, false) |
|
138 | + . '>'.$link_cat->name."</option>\n"; |
|
139 | 139 | } |
140 | 140 | ?> |
141 | 141 | </select> |
142 | - <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label> |
|
142 | + <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e('Sort by:'); ?></label> |
|
143 | 143 | <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat"> |
144 | - <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option> |
|
145 | - <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option> |
|
146 | - <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option> |
|
147 | - <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option> |
|
144 | + <option value="name"<?php selected($instance['orderby'], 'name'); ?>><?php _e('Link title'); ?></option> |
|
145 | + <option value="rating"<?php selected($instance['orderby'], 'rating'); ?>><?php _e('Link rating'); ?></option> |
|
146 | + <option value="id"<?php selected($instance['orderby'], 'id'); ?>><?php _e('Link ID'); ?></option> |
|
147 | + <option value="rand"<?php selected($instance['orderby'], 'rand'); ?>><?php _ex('Random', 'Links widget'); ?></option> |
|
148 | 148 | </select> |
149 | 149 | </p> |
150 | 150 | <p> |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label> |
159 | 159 | </p> |
160 | 160 | <p> |
161 | - <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label> |
|
162 | - <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" /> |
|
161 | + <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e('Number of links to show:'); ?></label> |
|
162 | + <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval($limit); ?>" size="3" /> |
|
163 | 163 | </p> |
164 | 164 | <?php |
165 | 165 | } |
@@ -39,19 +39,23 @@ discard block |
||
39 | 39 | * @param array $instance Settings for the current RSS widget instance. |
40 | 40 | */ |
41 | 41 | public function widget( $args, $instance ) { |
42 | - if ( isset($instance['error']) && $instance['error'] ) |
|
43 | - return; |
|
42 | + if ( isset($instance['error']) && $instance['error'] ) { |
|
43 | + return; |
|
44 | + } |
|
44 | 45 | |
45 | 46 | $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; |
46 | - while ( stristr($url, 'http') != $url ) |
|
47 | - $url = substr($url, 1); |
|
47 | + while ( stristr($url, 'http') != $url ) { |
|
48 | + $url = substr($url, 1); |
|
49 | + } |
|
48 | 50 | |
49 | - if ( empty($url) ) |
|
50 | - return; |
|
51 | + if ( empty($url) ) { |
|
52 | + return; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | // self-url destruction sequence |
53 | - if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) |
|
54 | - return; |
|
56 | + if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) { |
|
57 | + return; |
|
58 | + } |
|
55 | 59 | |
56 | 60 | $rss = fetch_feed($url); |
57 | 61 | $title = $instance['title']; |
@@ -60,23 +64,27 @@ discard block |
||
60 | 64 | |
61 | 65 | if ( ! is_wp_error($rss) ) { |
62 | 66 | $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); |
63 | - if ( empty($title) ) |
|
64 | - $title = strip_tags( $rss->get_title() ); |
|
67 | + if ( empty($title) ) { |
|
68 | + $title = strip_tags( $rss->get_title() ); |
|
69 | + } |
|
65 | 70 | $link = strip_tags( $rss->get_permalink() ); |
66 | - while ( stristr($link, 'http') != $link ) |
|
67 | - $link = substr($link, 1); |
|
71 | + while ( stristr($link, 'http') != $link ) { |
|
72 | + $link = substr($link, 1); |
|
73 | + } |
|
68 | 74 | } |
69 | 75 | |
70 | - if ( empty($title) ) |
|
71 | - $title = empty($desc) ? __('Unknown Feed') : $desc; |
|
76 | + if ( empty($title) ) { |
|
77 | + $title = empty($desc) ? __('Unknown Feed') : $desc; |
|
78 | + } |
|
72 | 79 | |
73 | 80 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
74 | 81 | $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
75 | 82 | |
76 | 83 | $url = strip_tags( $url ); |
77 | 84 | $icon = includes_url( 'images/rss.png' ); |
78 | - if ( $title ) |
|
79 | - $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">'. esc_html( $title ) . '</a>'; |
|
85 | + if ( $title ) { |
|
86 | + $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">'. esc_html( $title ) . '</a>'; |
|
87 | + } |
|
80 | 88 | |
81 | 89 | echo $args['before_widget']; |
82 | 90 | if ( $title ) { |
@@ -85,8 +93,9 @@ discard block |
||
85 | 93 | wp_widget_rss_output( $rss, $instance ); |
86 | 94 | echo $args['after_widget']; |
87 | 95 | |
88 | - if ( ! is_wp_error($rss) ) |
|
89 | - $rss->__destruct(); |
|
96 | + if ( ! is_wp_error($rss) ) { |
|
97 | + $rss->__destruct(); |
|
98 | + } |
|
90 | 99 | unset($rss); |
91 | 100 | } |
92 | 101 |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | $widget_ops = array( |
27 | - 'description' => __( 'Entries from any RSS or Atom feed.' ), |
|
27 | + 'description' => __('Entries from any RSS or Atom feed.'), |
|
28 | 28 | 'customize_selective_refresh' => true, |
29 | 29 | ); |
30 | - $control_ops = array( 'width' => 400, 'height' => 200 ); |
|
31 | - parent::__construct( 'rss', __( 'RSS' ), $widget_ops, $control_ops ); |
|
30 | + $control_ops = array('width' => 400, 'height' => 200); |
|
31 | + parent::__construct('rss', __('RSS'), $widget_ops, $control_ops); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -41,19 +41,19 @@ discard block |
||
41 | 41 | * 'before_widget', and 'after_widget'. |
42 | 42 | * @param array $instance Settings for the current RSS widget instance. |
43 | 43 | */ |
44 | - public function widget( $args, $instance ) { |
|
45 | - if ( isset($instance['error']) && $instance['error'] ) |
|
44 | + public function widget($args, $instance) { |
|
45 | + if (isset($instance['error']) && $instance['error']) |
|
46 | 46 | return; |
47 | 47 | |
48 | - $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; |
|
49 | - while ( stristr($url, 'http') != $url ) |
|
48 | + $url = ! empty($instance['url']) ? $instance['url'] : ''; |
|
49 | + while (stristr($url, 'http') != $url) |
|
50 | 50 | $url = substr($url, 1); |
51 | 51 | |
52 | - if ( empty($url) ) |
|
52 | + if (empty($url)) |
|
53 | 53 | return; |
54 | 54 | |
55 | 55 | // self-url destruction sequence |
56 | - if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) |
|
56 | + if (in_array(untrailingslashit($url), array(site_url(), home_url()))) |
|
57 | 57 | return; |
58 | 58 | |
59 | 59 | $rss = fetch_feed($url); |
@@ -61,34 +61,34 @@ discard block |
||
61 | 61 | $desc = ''; |
62 | 62 | $link = ''; |
63 | 63 | |
64 | - if ( ! is_wp_error($rss) ) { |
|
64 | + if ( ! is_wp_error($rss)) { |
|
65 | 65 | $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); |
66 | - if ( empty($title) ) |
|
67 | - $title = strip_tags( $rss->get_title() ); |
|
68 | - $link = strip_tags( $rss->get_permalink() ); |
|
69 | - while ( stristr($link, 'http') != $link ) |
|
66 | + if (empty($title)) |
|
67 | + $title = strip_tags($rss->get_title()); |
|
68 | + $link = strip_tags($rss->get_permalink()); |
|
69 | + while (stristr($link, 'http') != $link) |
|
70 | 70 | $link = substr($link, 1); |
71 | 71 | } |
72 | 72 | |
73 | - if ( empty($title) ) |
|
73 | + if (empty($title)) |
|
74 | 74 | $title = empty($desc) ? __('Unknown Feed') : $desc; |
75 | 75 | |
76 | 76 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
77 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
77 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
78 | 78 | |
79 | - $url = strip_tags( $url ); |
|
80 | - $icon = includes_url( 'images/rss.png' ); |
|
81 | - if ( $title ) |
|
82 | - $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">'. esc_html( $title ) . '</a>'; |
|
79 | + $url = strip_tags($url); |
|
80 | + $icon = includes_url('images/rss.png'); |
|
81 | + if ($title) |
|
82 | + $title = '<a class="rsswidget" href="'.esc_url($url).'"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="'.esc_url($icon).'" alt="RSS" /></a> <a class="rsswidget" href="'.esc_url($link).'">'.esc_html($title).'</a>'; |
|
83 | 83 | |
84 | 84 | echo $args['before_widget']; |
85 | - if ( $title ) { |
|
86 | - echo $args['before_title'] . $title . $args['after_title']; |
|
85 | + if ($title) { |
|
86 | + echo $args['before_title'].$title.$args['after_title']; |
|
87 | 87 | } |
88 | - wp_widget_rss_output( $rss, $instance ); |
|
88 | + wp_widget_rss_output($rss, $instance); |
|
89 | 89 | echo $args['after_widget']; |
90 | 90 | |
91 | - if ( ! is_wp_error($rss) ) |
|
91 | + if ( ! is_wp_error($rss)) |
|
92 | 92 | $rss->__destruct(); |
93 | 93 | unset($rss); |
94 | 94 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @param array $old_instance Old settings for this instance. |
105 | 105 | * @return array Updated settings to save. |
106 | 106 | */ |
107 | - public function update( $new_instance, $old_instance ) { |
|
108 | - $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) ); |
|
109 | - return wp_widget_rss_process( $new_instance, $testurl ); |
|
107 | + public function update($new_instance, $old_instance) { |
|
108 | + $testurl = (isset($new_instance['url']) && ( ! isset($old_instance['url']) || ($new_instance['url'] != $old_instance['url']))); |
|
109 | + return wp_widget_rss_process($new_instance, $testurl); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @param array $instance Current settings. |
119 | 119 | */ |
120 | - public function form( $instance ) { |
|
121 | - if ( empty( $instance ) ) { |
|
122 | - $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 ); |
|
120 | + public function form($instance) { |
|
121 | + if (empty($instance)) { |
|
122 | + $instance = array('title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0); |
|
123 | 123 | } |
124 | 124 | $instance['number'] = $this->number; |
125 | 125 | |
126 | - wp_widget_rss_form( $instance ); |
|
126 | + wp_widget_rss_form($instance); |
|
127 | 127 | } |
128 | 128 | } |
@@ -49,8 +49,9 @@ |
||
49 | 49 | $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
50 | 50 | |
51 | 51 | $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; |
52 | - if ( ! $number ) |
|
53 | - $number = 5; |
|
52 | + if ( ! $number ) { |
|
53 | + $number = 5; |
|
54 | + } |
|
54 | 55 | $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; |
55 | 56 | |
56 | 57 | /** |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | public function __construct() { |
26 | 26 | $widget_ops = array( |
27 | 27 | 'classname' => 'widget_recent_entries', |
28 | - 'description' => __( 'Your site’s most recent Posts.' ), |
|
28 | + 'description' => __('Your site’s most recent Posts.'), |
|
29 | 29 | 'customize_selective_refresh' => true, |
30 | 30 | ); |
31 | - parent::__construct( 'recent-posts', __( 'Recent Posts' ), $widget_ops ); |
|
31 | + parent::__construct('recent-posts', __('Recent Posts'), $widget_ops); |
|
32 | 32 | $this->alt_option_name = 'widget_recent_entries'; |
33 | 33 | } |
34 | 34 | |
@@ -42,20 +42,20 @@ discard block |
||
42 | 42 | * 'before_widget', and 'after_widget'. |
43 | 43 | * @param array $instance Settings for the current Recent Posts widget instance. |
44 | 44 | */ |
45 | - public function widget( $args, $instance ) { |
|
46 | - if ( ! isset( $args['widget_id'] ) ) { |
|
45 | + public function widget($args, $instance) { |
|
46 | + if ( ! isset($args['widget_id'])) { |
|
47 | 47 | $args['widget_id'] = $this->id; |
48 | 48 | } |
49 | 49 | |
50 | - $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' ); |
|
50 | + $title = ( ! empty($instance['title'])) ? $instance['title'] : __('Recent Posts'); |
|
51 | 51 | |
52 | 52 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
53 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
53 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
54 | 54 | |
55 | - $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; |
|
56 | - if ( ! $number ) |
|
55 | + $number = ( ! empty($instance['number'])) ? absint($instance['number']) : 5; |
|
56 | + if ( ! $number) |
|
57 | 57 | $number = 5; |
58 | - $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; |
|
58 | + $show_date = isset($instance['show_date']) ? $instance['show_date'] : false; |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Filters the arguments for the Recent Posts widget. |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @param array $args An array of arguments used to retrieve the recent posts. |
68 | 68 | */ |
69 | - $r = new WP_Query( apply_filters( 'widget_posts_args', array( |
|
69 | + $r = new WP_Query(apply_filters('widget_posts_args', array( |
|
70 | 70 | 'posts_per_page' => $number, |
71 | 71 | 'no_found_rows' => true, |
72 | 72 | 'post_status' => 'publish', |
73 | 73 | 'ignore_sticky_posts' => true |
74 | - ) ) ); |
|
74 | + ))); |
|
75 | 75 | |
76 | 76 | if ($r->have_posts()) : |
77 | 77 | ?> |
78 | 78 | <?php echo $args['before_widget']; ?> |
79 | - <?php if ( $title ) { |
|
80 | - echo $args['before_title'] . $title . $args['after_title']; |
|
79 | + <?php if ($title) { |
|
80 | + echo $args['before_title'].$title.$args['after_title']; |
|
81 | 81 | } ?> |
82 | 82 | <ul> |
83 | - <?php while ( $r->have_posts() ) : $r->the_post(); ?> |
|
83 | + <?php while ($r->have_posts()) : $r->the_post(); ?> |
|
84 | 84 | <li> |
85 | 85 | <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a> |
86 | - <?php if ( $show_date ) : ?> |
|
86 | + <?php if ($show_date) : ?> |
|
87 | 87 | <span class="post-date"><?php echo get_the_date(); ?></span> |
88 | 88 | <?php endif; ?> |
89 | 89 | </li> |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | * @param array $old_instance Old settings for this instance. |
109 | 109 | * @return array Updated settings to save. |
110 | 110 | */ |
111 | - public function update( $new_instance, $old_instance ) { |
|
111 | + public function update($new_instance, $old_instance) { |
|
112 | 112 | $instance = $old_instance; |
113 | - $instance['title'] = sanitize_text_field( $new_instance['title'] ); |
|
113 | + $instance['title'] = sanitize_text_field($new_instance['title']); |
|
114 | 114 | $instance['number'] = (int) $new_instance['number']; |
115 | - $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false; |
|
115 | + $instance['show_date'] = isset($new_instance['show_date']) ? (bool) $new_instance['show_date'] : false; |
|
116 | 116 | return $instance; |
117 | 117 | } |
118 | 118 | |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @param array $instance Current settings. |
126 | 126 | */ |
127 | - public function form( $instance ) { |
|
128 | - $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
129 | - $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; |
|
130 | - $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false; |
|
127 | + public function form($instance) { |
|
128 | + $title = isset($instance['title']) ? esc_attr($instance['title']) : ''; |
|
129 | + $number = isset($instance['number']) ? absint($instance['number']) : 5; |
|
130 | + $show_date = isset($instance['show_date']) ? (bool) $instance['show_date'] : false; |
|
131 | 131 | ?> |
132 | - <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
|
133 | - <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p> |
|
132 | + <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
|
133 | + <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> |
|
134 | 134 | |
135 | - <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label> |
|
136 | - <input class="tiny-text" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" /></p> |
|
135 | + <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label> |
|
136 | + <input class="tiny-text" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" /></p> |
|
137 | 137 | |
138 | - <p><input class="checkbox" type="checkbox"<?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" /> |
|
139 | - <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p> |
|
138 | + <p><input class="checkbox" type="checkbox"<?php checked($show_date); ?> id="<?php echo $this->get_field_id('show_date'); ?>" name="<?php echo $this->get_field_name('show_date'); ?>" /> |
|
139 | + <label for="<?php echo $this->get_field_id('show_date'); ?>"><?php _e('Display post date?'); ?></label></p> |
|
140 | 140 | <?php |
141 | 141 | } |
142 | 142 | } |
@@ -173,8 +173,9 @@ |
||
173 | 173 | * @return string Name of the current taxonomy if set, otherwise 'post_tag'. |
174 | 174 | */ |
175 | 175 | public function _get_current_taxonomy($instance) { |
176 | - if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) ) |
|
177 | - return $instance['taxonomy']; |
|
176 | + if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) ) { |
|
177 | + return $instance['taxonomy']; |
|
178 | + } |
|
178 | 179 | |
179 | 180 | return 'post_tag'; |
180 | 181 | } |
@@ -144,39 +144,39 @@ |
||
144 | 144 | switch ( count( $taxonomies ) ) { |
145 | 145 | |
146 | 146 | // No tag cloud supporting taxonomies found, display error message |
147 | - case 0: |
|
148 | - echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>'; |
|
149 | - printf( $input, '' ); |
|
150 | - break; |
|
151 | - |
|
152 | - // Just a single tag cloud supporting taxonomy found, no need to display a select. |
|
153 | - case 1: |
|
154 | - $keys = array_keys( $taxonomies ); |
|
155 | - $taxonomy = reset( $keys ); |
|
156 | - printf( $input, esc_attr( $taxonomy ) ); |
|
157 | - echo $count_checkbox; |
|
158 | - break; |
|
159 | - |
|
160 | - // More than one tag cloud supporting taxonomy found, display a select. |
|
161 | - default: |
|
162 | - printf( |
|
163 | - '<p><label for="%1$s">%2$s</label>' . |
|
164 | - '<select class="widefat" id="%1$s" name="%3$s">', |
|
165 | - $id, |
|
166 | - __( 'Taxonomy:' ), |
|
167 | - $name |
|
168 | - ); |
|
169 | - |
|
170 | - foreach ( $taxonomies as $taxonomy => $tax ) { |
|
147 | + case 0: |
|
148 | + echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>'; |
|
149 | + printf( $input, '' ); |
|
150 | + break; |
|
151 | + |
|
152 | + // Just a single tag cloud supporting taxonomy found, no need to display a select. |
|
153 | + case 1: |
|
154 | + $keys = array_keys( $taxonomies ); |
|
155 | + $taxonomy = reset( $keys ); |
|
156 | + printf( $input, esc_attr( $taxonomy ) ); |
|
157 | + echo $count_checkbox; |
|
158 | + break; |
|
159 | + |
|
160 | + // More than one tag cloud supporting taxonomy found, display a select. |
|
161 | + default: |
|
171 | 162 | printf( |
172 | - '<option value="%s"%s>%s</option>', |
|
173 | - esc_attr( $taxonomy ), |
|
174 | - selected( $taxonomy, $current_taxonomy, false ), |
|
175 | - $tax->labels->name |
|
163 | + '<p><label for="%1$s">%2$s</label>' . |
|
164 | + '<select class="widefat" id="%1$s" name="%3$s">', |
|
165 | + $id, |
|
166 | + __( 'Taxonomy:' ), |
|
167 | + $name |
|
176 | 168 | ); |
177 | - } |
|
178 | 169 | |
179 | - echo '</select></p>' . $count_checkbox; |
|
170 | + foreach ( $taxonomies as $taxonomy => $tax ) { |
|
171 | + printf( |
|
172 | + '<option value="%s"%s>%s</option>', |
|
173 | + esc_attr( $taxonomy ), |
|
174 | + selected( $taxonomy, $current_taxonomy, false ), |
|
175 | + $tax->labels->name |
|
176 | + ); |
|
177 | + } |
|
178 | + |
|
179 | + echo '</select></p>' . $count_checkbox; |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | $widget_ops = array( |
27 | - 'description' => __( 'A cloud of your most used tags.' ), |
|
27 | + 'description' => __('A cloud of your most used tags.'), |
|
28 | 28 | 'customize_selective_refresh' => true, |
29 | 29 | ); |
30 | - parent::__construct( 'tag_cloud', __( 'Tag Cloud' ), $widget_ops ); |
|
30 | + parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | * 'before_widget', and 'after_widget'. |
41 | 41 | * @param array $instance Settings for the current Tag Cloud widget instance. |
42 | 42 | */ |
43 | - public function widget( $args, $instance ) { |
|
43 | + public function widget($args, $instance) { |
|
44 | 44 | $current_taxonomy = $this->_get_current_taxonomy($instance); |
45 | - if ( !empty($instance['title']) ) { |
|
45 | + if ( ! empty($instance['title'])) { |
|
46 | 46 | $title = $instance['title']; |
47 | 47 | } else { |
48 | - if ( 'post_tag' == $current_taxonomy ) { |
|
48 | + if ('post_tag' == $current_taxonomy) { |
|
49 | 49 | $title = __('Tags'); |
50 | 50 | } else { |
51 | 51 | $tax = get_taxonomy($current_taxonomy); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | - $show_count = ! empty( $instance['count'] ); |
|
56 | + $show_count = ! empty($instance['count']); |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Filters the taxonomy used in the Tag Cloud widget. |
@@ -65,22 +65,22 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param array $args Args used for the tag cloud widget. |
67 | 67 | */ |
68 | - $tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( |
|
68 | + $tag_cloud = wp_tag_cloud(apply_filters('widget_tag_cloud_args', array( |
|
69 | 69 | 'taxonomy' => $current_taxonomy, |
70 | 70 | 'echo' => false, |
71 | 71 | 'show_count' => $show_count, |
72 | - ) ) ); |
|
72 | + ))); |
|
73 | 73 | |
74 | - if ( empty( $tag_cloud ) ) { |
|
74 | + if (empty($tag_cloud)) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
79 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
79 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
80 | 80 | |
81 | 81 | echo $args['before_widget']; |
82 | - if ( $title ) { |
|
83 | - echo $args['before_title'] . $title . $args['after_title']; |
|
82 | + if ($title) { |
|
83 | + echo $args['before_title'].$title.$args['after_title']; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | echo '<div class="tagcloud">'; |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | * @param array $old_instance Old settings for this instance. |
103 | 103 | * @return array Settings to save or bool false to cancel saving. |
104 | 104 | */ |
105 | - public function update( $new_instance, $old_instance ) { |
|
105 | + public function update($new_instance, $old_instance) { |
|
106 | 106 | $instance = array(); |
107 | - $instance['title'] = sanitize_text_field( $new_instance['title'] ); |
|
108 | - $instance['count'] = ! empty( $new_instance['count'] ) ? 1 : 0; |
|
107 | + $instance['title'] = sanitize_text_field($new_instance['title']); |
|
108 | + $instance['count'] = ! empty($new_instance['count']) ? 1 : 0; |
|
109 | 109 | $instance['taxonomy'] = stripslashes($new_instance['taxonomy']); |
110 | 110 | return $instance; |
111 | 111 | } |
@@ -118,65 +118,65 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @param array $instance Current settings. |
120 | 120 | */ |
121 | - public function form( $instance ) { |
|
121 | + public function form($instance) { |
|
122 | 122 | $current_taxonomy = $this->_get_current_taxonomy($instance); |
123 | - $title_id = $this->get_field_id( 'title' ); |
|
124 | - $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false; |
|
125 | - $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
123 | + $title_id = $this->get_field_id('title'); |
|
124 | + $count = isset($instance['count']) ? (bool) $instance['count'] : false; |
|
125 | + $instance['title'] = ! empty($instance['title']) ? esc_attr($instance['title']) : ''; |
|
126 | 126 | |
127 | - echo '<p><label for="' . $title_id .'">' . __( 'Title:' ) . '</label> |
|
128 | - <input type="text" class="widefat" id="' . $title_id .'" name="' . $this->get_field_name( 'title' ) .'" value="' . $instance['title'] .'" /> |
|
127 | + echo '<p><label for="'.$title_id.'">'.__('Title:').'</label> |
|
128 | + <input type="text" class="widefat" id="' . $title_id.'" name="'.$this->get_field_name('title').'" value="'.$instance['title'].'" /> |
|
129 | 129 | </p>'; |
130 | 130 | |
131 | - $taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' ); |
|
132 | - $id = $this->get_field_id( 'taxonomy' ); |
|
133 | - $name = $this->get_field_name( 'taxonomy' ); |
|
134 | - $input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />'; |
|
131 | + $taxonomies = get_taxonomies(array('show_tagcloud' => true), 'object'); |
|
132 | + $id = $this->get_field_id('taxonomy'); |
|
133 | + $name = $this->get_field_name('taxonomy'); |
|
134 | + $input = '<input type="hidden" id="'.$id.'" name="'.$name.'" value="%s" />'; |
|
135 | 135 | |
136 | 136 | $count_checkbox = sprintf( |
137 | 137 | '<p><input type="checkbox" class="checkbox" id="%1$s" name="%2$s"%3$s /> <label for="%1$s">%4$s</label></p>', |
138 | - $this->get_field_id( 'count' ), |
|
139 | - $this->get_field_name( 'count' ), |
|
140 | - checked( $count, true, false ), |
|
141 | - __( 'Show tag counts' ) |
|
138 | + $this->get_field_id('count'), |
|
139 | + $this->get_field_name('count'), |
|
140 | + checked($count, true, false), |
|
141 | + __('Show tag counts') |
|
142 | 142 | ); |
143 | 143 | |
144 | - switch ( count( $taxonomies ) ) { |
|
144 | + switch (count($taxonomies)) { |
|
145 | 145 | |
146 | 146 | // No tag cloud supporting taxonomies found, display error message |
147 | 147 | case 0: |
148 | - echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>'; |
|
149 | - printf( $input, '' ); |
|
148 | + echo '<p>'.__('The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.').'</p>'; |
|
149 | + printf($input, ''); |
|
150 | 150 | break; |
151 | 151 | |
152 | 152 | // Just a single tag cloud supporting taxonomy found, no need to display a select. |
153 | 153 | case 1: |
154 | - $keys = array_keys( $taxonomies ); |
|
155 | - $taxonomy = reset( $keys ); |
|
156 | - printf( $input, esc_attr( $taxonomy ) ); |
|
154 | + $keys = array_keys($taxonomies); |
|
155 | + $taxonomy = reset($keys); |
|
156 | + printf($input, esc_attr($taxonomy)); |
|
157 | 157 | echo $count_checkbox; |
158 | 158 | break; |
159 | 159 | |
160 | 160 | // More than one tag cloud supporting taxonomy found, display a select. |
161 | 161 | default: |
162 | 162 | printf( |
163 | - '<p><label for="%1$s">%2$s</label>' . |
|
163 | + '<p><label for="%1$s">%2$s</label>'. |
|
164 | 164 | '<select class="widefat" id="%1$s" name="%3$s">', |
165 | 165 | $id, |
166 | - __( 'Taxonomy:' ), |
|
166 | + __('Taxonomy:'), |
|
167 | 167 | $name |
168 | 168 | ); |
169 | 169 | |
170 | - foreach ( $taxonomies as $taxonomy => $tax ) { |
|
170 | + foreach ($taxonomies as $taxonomy => $tax) { |
|
171 | 171 | printf( |
172 | 172 | '<option value="%s"%s>%s</option>', |
173 | - esc_attr( $taxonomy ), |
|
174 | - selected( $taxonomy, $current_taxonomy, false ), |
|
173 | + esc_attr($taxonomy), |
|
174 | + selected($taxonomy, $current_taxonomy, false), |
|
175 | 175 | $tax->labels->name |
176 | 176 | ); |
177 | 177 | } |
178 | 178 | |
179 | - echo '</select></p>' . $count_checkbox; |
|
179 | + echo '</select></p>'.$count_checkbox; |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @return string Name of the current taxonomy if set, otherwise 'post_tag'. |
191 | 191 | */ |
192 | 192 | public function _get_current_taxonomy($instance) { |
193 | - if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) ) |
|
193 | + if ( ! empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy'])) |
|
194 | 194 | return $instance['taxonomy']; |
195 | 195 | |
196 | 196 | return 'post_tag'; |
@@ -81,129 +81,129 @@ discard block |
||
81 | 81 | 'headers' => array(), 'body' => null, 'cookies' => array() |
82 | 82 | ); |
83 | 83 | |
84 | - $r = wp_parse_args( $args, $defaults ); |
|
84 | + $r = wp_parse_args($args, $defaults); |
|
85 | 85 | |
86 | - if ( isset( $r['headers']['User-Agent'] ) ) { |
|
86 | + if (isset($r['headers']['User-Agent'])) { |
|
87 | 87 | $r['user-agent'] = $r['headers']['User-Agent']; |
88 | - unset( $r['headers']['User-Agent'] ); |
|
89 | - } elseif ( isset( $r['headers']['user-agent'] ) ) { |
|
88 | + unset($r['headers']['User-Agent']); |
|
89 | + } elseif (isset($r['headers']['user-agent'])) { |
|
90 | 90 | $r['user-agent'] = $r['headers']['user-agent']; |
91 | - unset( $r['headers']['user-agent'] ); |
|
91 | + unset($r['headers']['user-agent']); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | // Construct Cookie: header if any cookies are set. |
95 | - WP_Http::buildCookieHeader( $r ); |
|
95 | + WP_Http::buildCookieHeader($r); |
|
96 | 96 | |
97 | 97 | $handle = curl_init(); |
98 | 98 | |
99 | 99 | // cURL offers really easy proxy support. |
100 | 100 | $proxy = new WP_HTTP_Proxy(); |
101 | 101 | |
102 | - if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { |
|
102 | + if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) { |
|
103 | 103 | |
104 | - curl_setopt( $handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP ); |
|
105 | - curl_setopt( $handle, CURLOPT_PROXY, $proxy->host() ); |
|
106 | - curl_setopt( $handle, CURLOPT_PROXYPORT, $proxy->port() ); |
|
104 | + curl_setopt($handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); |
|
105 | + curl_setopt($handle, CURLOPT_PROXY, $proxy->host()); |
|
106 | + curl_setopt($handle, CURLOPT_PROXYPORT, $proxy->port()); |
|
107 | 107 | |
108 | - if ( $proxy->use_authentication() ) { |
|
109 | - curl_setopt( $handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY ); |
|
110 | - curl_setopt( $handle, CURLOPT_PROXYUSERPWD, $proxy->authentication() ); |
|
108 | + if ($proxy->use_authentication()) { |
|
109 | + curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY); |
|
110 | + curl_setopt($handle, CURLOPT_PROXYUSERPWD, $proxy->authentication()); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | 114 | $is_local = isset($r['local']) && $r['local']; |
115 | 115 | $ssl_verify = isset($r['sslverify']) && $r['sslverify']; |
116 | - if ( $is_local ) { |
|
116 | + if ($is_local) { |
|
117 | 117 | /** This filter is documented in wp-includes/class-wp-http-streams.php */ |
118 | - $ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify ); |
|
119 | - } elseif ( ! $is_local ) { |
|
118 | + $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); |
|
119 | + } elseif ( ! $is_local) { |
|
120 | 120 | /** This filter is documented in wp-includes/class-wp-http-streams.php */ |
121 | - $ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify ); |
|
121 | + $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /* |
125 | 125 | * CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers. Have to use ceil since. |
126 | 126 | * a value of 0 will allow an unlimited timeout. |
127 | 127 | */ |
128 | - $timeout = (int) ceil( $r['timeout'] ); |
|
129 | - curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout ); |
|
130 | - curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout ); |
|
128 | + $timeout = (int) ceil($r['timeout']); |
|
129 | + curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, $timeout); |
|
130 | + curl_setopt($handle, CURLOPT_TIMEOUT, $timeout); |
|
131 | 131 | |
132 | - curl_setopt( $handle, CURLOPT_URL, $url); |
|
133 | - curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true ); |
|
134 | - curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, ( $ssl_verify === true ) ? 2 : false ); |
|
135 | - curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify ); |
|
132 | + curl_setopt($handle, CURLOPT_URL, $url); |
|
133 | + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); |
|
134 | + curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, ($ssl_verify === true) ? 2 : false); |
|
135 | + curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify); |
|
136 | 136 | |
137 | - if ( $ssl_verify ) { |
|
138 | - curl_setopt( $handle, CURLOPT_CAINFO, $r['sslcertificates'] ); |
|
137 | + if ($ssl_verify) { |
|
138 | + curl_setopt($handle, CURLOPT_CAINFO, $r['sslcertificates']); |
|
139 | 139 | } |
140 | 140 | |
141 | - curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] ); |
|
141 | + curl_setopt($handle, CURLOPT_USERAGENT, $r['user-agent']); |
|
142 | 142 | |
143 | 143 | /* |
144 | 144 | * The option doesn't work with safe mode or when open_basedir is set, and there's |
145 | 145 | * a bug #17490 with redirected POST requests, so handle redirections outside Curl. |
146 | 146 | */ |
147 | - curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false ); |
|
148 | - if ( defined( 'CURLOPT_PROTOCOLS' ) ) // PHP 5.2.10 / cURL 7.19.4 |
|
149 | - curl_setopt( $handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS ); |
|
147 | + curl_setopt($handle, CURLOPT_FOLLOWLOCATION, false); |
|
148 | + if (defined('CURLOPT_PROTOCOLS')) // PHP 5.2.10 / cURL 7.19.4 |
|
149 | + curl_setopt($handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
150 | 150 | |
151 | - switch ( $r['method'] ) { |
|
151 | + switch ($r['method']) { |
|
152 | 152 | case 'HEAD': |
153 | - curl_setopt( $handle, CURLOPT_NOBODY, true ); |
|
153 | + curl_setopt($handle, CURLOPT_NOBODY, true); |
|
154 | 154 | break; |
155 | 155 | case 'POST': |
156 | - curl_setopt( $handle, CURLOPT_POST, true ); |
|
157 | - curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
156 | + curl_setopt($handle, CURLOPT_POST, true); |
|
157 | + curl_setopt($handle, CURLOPT_POSTFIELDS, $r['body']); |
|
158 | 158 | break; |
159 | 159 | case 'PUT': |
160 | - curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, 'PUT' ); |
|
161 | - curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
160 | + curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
161 | + curl_setopt($handle, CURLOPT_POSTFIELDS, $r['body']); |
|
162 | 162 | break; |
163 | 163 | default: |
164 | - curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] ); |
|
165 | - if ( ! is_null( $r['body'] ) ) |
|
166 | - curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
164 | + curl_setopt($handle, CURLOPT_CUSTOMREQUEST, $r['method']); |
|
165 | + if ( ! is_null($r['body'])) |
|
166 | + curl_setopt($handle, CURLOPT_POSTFIELDS, $r['body']); |
|
167 | 167 | break; |
168 | 168 | } |
169 | 169 | |
170 | - if ( true === $r['blocking'] ) { |
|
171 | - curl_setopt( $handle, CURLOPT_HEADERFUNCTION, array( $this, 'stream_headers' ) ); |
|
172 | - curl_setopt( $handle, CURLOPT_WRITEFUNCTION, array( $this, 'stream_body' ) ); |
|
170 | + if (true === $r['blocking']) { |
|
171 | + curl_setopt($handle, CURLOPT_HEADERFUNCTION, array($this, 'stream_headers')); |
|
172 | + curl_setopt($handle, CURLOPT_WRITEFUNCTION, array($this, 'stream_body')); |
|
173 | 173 | } |
174 | 174 | |
175 | - curl_setopt( $handle, CURLOPT_HEADER, false ); |
|
175 | + curl_setopt($handle, CURLOPT_HEADER, false); |
|
176 | 176 | |
177 | - if ( isset( $r['limit_response_size'] ) ) |
|
178 | - $this->max_body_length = intval( $r['limit_response_size'] ); |
|
177 | + if (isset($r['limit_response_size'])) |
|
178 | + $this->max_body_length = intval($r['limit_response_size']); |
|
179 | 179 | else |
180 | 180 | $this->max_body_length = false; |
181 | 181 | |
182 | 182 | // If streaming to a file open a file handle, and setup our curl streaming handler. |
183 | - if ( $r['stream'] ) { |
|
184 | - if ( ! WP_DEBUG ) |
|
185 | - $this->stream_handle = @fopen( $r['filename'], 'w+' ); |
|
183 | + if ($r['stream']) { |
|
184 | + if ( ! WP_DEBUG) |
|
185 | + $this->stream_handle = @fopen($r['filename'], 'w+'); |
|
186 | 186 | else |
187 | - $this->stream_handle = fopen( $r['filename'], 'w+' ); |
|
188 | - if ( ! $this->stream_handle ) |
|
189 | - return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
187 | + $this->stream_handle = fopen($r['filename'], 'w+'); |
|
188 | + if ( ! $this->stream_handle) |
|
189 | + return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $r['filename'])); |
|
190 | 190 | } else { |
191 | 191 | $this->stream_handle = false; |
192 | 192 | } |
193 | 193 | |
194 | - if ( !empty( $r['headers'] ) ) { |
|
194 | + if ( ! empty($r['headers'])) { |
|
195 | 195 | // cURL expects full header strings in each element. |
196 | 196 | $headers = array(); |
197 | - foreach ( $r['headers'] as $name => $value ) { |
|
197 | + foreach ($r['headers'] as $name => $value) { |
|
198 | 198 | $headers[] = "{$name}: $value"; |
199 | 199 | } |
200 | - curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers ); |
|
200 | + curl_setopt($handle, CURLOPT_HTTPHEADER, $headers); |
|
201 | 201 | } |
202 | 202 | |
203 | - if ( $r['httpversion'] == '1.0' ) |
|
204 | - curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); |
|
203 | + if ($r['httpversion'] == '1.0') |
|
204 | + curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
|
205 | 205 | else |
206 | - curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); |
|
206 | + curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
207 | 207 | |
208 | 208 | /** |
209 | 209 | * Fires before the cURL request is executed. |
@@ -217,27 +217,27 @@ discard block |
||
217 | 217 | * @param array $r The HTTP request arguments. |
218 | 218 | * @param string $url The request URL. |
219 | 219 | */ |
220 | - do_action_ref_array( 'http_api_curl', array( &$handle, $r, $url ) ); |
|
220 | + do_action_ref_array('http_api_curl', array(&$handle, $r, $url)); |
|
221 | 221 | |
222 | 222 | // We don't need to return the body, so don't. Just execute request and return. |
223 | - if ( ! $r['blocking'] ) { |
|
224 | - curl_exec( $handle ); |
|
223 | + if ( ! $r['blocking']) { |
|
224 | + curl_exec($handle); |
|
225 | 225 | |
226 | - if ( $curl_error = curl_error( $handle ) ) { |
|
227 | - curl_close( $handle ); |
|
228 | - return new WP_Error( 'http_request_failed', $curl_error ); |
|
226 | + if ($curl_error = curl_error($handle)) { |
|
227 | + curl_close($handle); |
|
228 | + return new WP_Error('http_request_failed', $curl_error); |
|
229 | 229 | } |
230 | - if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) { |
|
231 | - curl_close( $handle ); |
|
232 | - return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); |
|
230 | + if (in_array(curl_getinfo($handle, CURLINFO_HTTP_CODE), array(301, 302))) { |
|
231 | + curl_close($handle); |
|
232 | + return new WP_Error('http_request_failed', __('Too many redirects.')); |
|
233 | 233 | } |
234 | 234 | |
235 | - curl_close( $handle ); |
|
236 | - return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); |
|
235 | + curl_close($handle); |
|
236 | + return array('headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array()); |
|
237 | 237 | } |
238 | 238 | |
239 | - curl_exec( $handle ); |
|
240 | - $theHeaders = WP_Http::processHeaders( $this->headers, $url ); |
|
239 | + curl_exec($handle); |
|
240 | + $theHeaders = WP_Http::processHeaders($this->headers, $url); |
|
241 | 241 | $theBody = $this->body; |
242 | 242 | $bytes_written_total = $this->bytes_written_total; |
243 | 243 | |
@@ -245,37 +245,37 @@ discard block |
||
245 | 245 | $this->body = ''; |
246 | 246 | $this->bytes_written_total = 0; |
247 | 247 | |
248 | - $curl_error = curl_errno( $handle ); |
|
248 | + $curl_error = curl_errno($handle); |
|
249 | 249 | |
250 | 250 | // If an error occurred, or, no response. |
251 | - if ( $curl_error || ( 0 == strlen( $theBody ) && empty( $theHeaders['headers'] ) ) ) { |
|
252 | - if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error ) { |
|
253 | - if ( ! $this->max_body_length || $this->max_body_length != $bytes_written_total ) { |
|
254 | - if ( $r['stream'] ) { |
|
255 | - curl_close( $handle ); |
|
256 | - fclose( $this->stream_handle ); |
|
257 | - return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) ); |
|
251 | + if ($curl_error || (0 == strlen($theBody) && empty($theHeaders['headers']))) { |
|
252 | + if (CURLE_WRITE_ERROR /* 23 */ == $curl_error) { |
|
253 | + if ( ! $this->max_body_length || $this->max_body_length != $bytes_written_total) { |
|
254 | + if ($r['stream']) { |
|
255 | + curl_close($handle); |
|
256 | + fclose($this->stream_handle); |
|
257 | + return new WP_Error('http_request_failed', __('Failed to write request to temporary file.')); |
|
258 | 258 | } else { |
259 | - curl_close( $handle ); |
|
260 | - return new WP_Error( 'http_request_failed', curl_error( $handle ) ); |
|
259 | + curl_close($handle); |
|
260 | + return new WP_Error('http_request_failed', curl_error($handle)); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | } else { |
264 | - if ( $curl_error = curl_error( $handle ) ) { |
|
265 | - curl_close( $handle ); |
|
266 | - return new WP_Error( 'http_request_failed', $curl_error ); |
|
264 | + if ($curl_error = curl_error($handle)) { |
|
265 | + curl_close($handle); |
|
266 | + return new WP_Error('http_request_failed', $curl_error); |
|
267 | 267 | } |
268 | 268 | } |
269 | - if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) { |
|
270 | - curl_close( $handle ); |
|
271 | - return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); |
|
269 | + if (in_array(curl_getinfo($handle, CURLINFO_HTTP_CODE), array(301, 302))) { |
|
270 | + curl_close($handle); |
|
271 | + return new WP_Error('http_request_failed', __('Too many redirects.')); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - curl_close( $handle ); |
|
275 | + curl_close($handle); |
|
276 | 276 | |
277 | - if ( $r['stream'] ) |
|
278 | - fclose( $this->stream_handle ); |
|
277 | + if ($r['stream']) |
|
278 | + fclose($this->stream_handle); |
|
279 | 279 | |
280 | 280 | $response = array( |
281 | 281 | 'headers' => $theHeaders['headers'], |
@@ -286,11 +286,11 @@ discard block |
||
286 | 286 | ); |
287 | 287 | |
288 | 288 | // Handle redirects. |
289 | - if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) |
|
289 | + if (false !== ($redirect_response = WP_HTTP::handle_redirects($url, $r, $response))) |
|
290 | 290 | return $redirect_response; |
291 | 291 | |
292 | - if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) |
|
293 | - $theBody = WP_Http_Encoding::decompress( $theBody ); |
|
292 | + if (true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers'])) |
|
293 | + $theBody = WP_Http_Encoding::decompress($theBody); |
|
294 | 294 | |
295 | 295 | $response['body'] = $theBody; |
296 | 296 | |
@@ -310,9 +310,9 @@ discard block |
||
310 | 310 | * @param string $headers cURL request headers. |
311 | 311 | * @return int Length of the request headers. |
312 | 312 | */ |
313 | - private function stream_headers( $handle, $headers ) { |
|
313 | + private function stream_headers($handle, $headers) { |
|
314 | 314 | $this->headers .= $headers; |
315 | - return strlen( $headers ); |
|
315 | + return strlen($headers); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -329,16 +329,16 @@ discard block |
||
329 | 329 | * @param string $data cURL request body. |
330 | 330 | * @return int Total bytes of data written. |
331 | 331 | */ |
332 | - private function stream_body( $handle, $data ) { |
|
333 | - $data_length = strlen( $data ); |
|
332 | + private function stream_body($handle, $data) { |
|
333 | + $data_length = strlen($data); |
|
334 | 334 | |
335 | - if ( $this->max_body_length && ( $this->bytes_written_total + $data_length ) > $this->max_body_length ) { |
|
336 | - $data_length = ( $this->max_body_length - $this->bytes_written_total ); |
|
337 | - $data = substr( $data, 0, $data_length ); |
|
335 | + if ($this->max_body_length && ($this->bytes_written_total + $data_length) > $this->max_body_length) { |
|
336 | + $data_length = ($this->max_body_length - $this->bytes_written_total); |
|
337 | + $data = substr($data, 0, $data_length); |
|
338 | 338 | } |
339 | 339 | |
340 | - if ( $this->stream_handle ) { |
|
341 | - $bytes_written = fwrite( $this->stream_handle, $data ); |
|
340 | + if ($this->stream_handle) { |
|
341 | + $bytes_written = fwrite($this->stream_handle, $data); |
|
342 | 342 | } else { |
343 | 343 | $this->body .= $data; |
344 | 344 | $bytes_written = $data_length; |
@@ -359,16 +359,16 @@ discard block |
||
359 | 359 | * @param array $args Optional. Array of request arguments. Default empty array. |
360 | 360 | * @return bool False means this class can not be used, true means it can. |
361 | 361 | */ |
362 | - public static function test( $args = array() ) { |
|
363 | - if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) |
|
362 | + public static function test($args = array()) { |
|
363 | + if ( ! function_exists('curl_init') || ! function_exists('curl_exec')) |
|
364 | 364 | return false; |
365 | 365 | |
366 | - $is_ssl = isset( $args['ssl'] ) && $args['ssl']; |
|
366 | + $is_ssl = isset($args['ssl']) && $args['ssl']; |
|
367 | 367 | |
368 | - if ( $is_ssl ) { |
|
368 | + if ($is_ssl) { |
|
369 | 369 | $curl_version = curl_version(); |
370 | 370 | // Check whether this cURL version support SSL requests. |
371 | - if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) |
|
371 | + if ( ! (CURL_VERSION_SSL & $curl_version['features'])) |
|
372 | 372 | return false; |
373 | 373 | } |
374 | 374 | |
@@ -380,6 +380,6 @@ discard block |
||
380 | 380 | * @param bool $use_class Whether the class can be used. Default true. |
381 | 381 | * @param array $args An array of request arguments. |
382 | 382 | */ |
383 | - return apply_filters( 'use_curl_transport', true, $args ); |
|
383 | + return apply_filters('use_curl_transport', true, $args); |
|
384 | 384 | } |
385 | 385 | } |
@@ -145,8 +145,10 @@ discard block |
||
145 | 145 | * a bug #17490 with redirected POST requests, so handle redirections outside Curl. |
146 | 146 | */ |
147 | 147 | curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false ); |
148 | - if ( defined( 'CURLOPT_PROTOCOLS' ) ) // PHP 5.2.10 / cURL 7.19.4 |
|
148 | + if ( defined( 'CURLOPT_PROTOCOLS' ) ) { |
|
149 | + // PHP 5.2.10 / cURL 7.19.4 |
|
149 | 150 | curl_setopt( $handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS ); |
151 | + } |
|
150 | 152 | |
151 | 153 | switch ( $r['method'] ) { |
152 | 154 | case 'HEAD': |
@@ -162,8 +164,9 @@ discard block |
||
162 | 164 | break; |
163 | 165 | default: |
164 | 166 | curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] ); |
165 | - if ( ! is_null( $r['body'] ) ) |
|
166 | - curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
167 | + if ( ! is_null( $r['body'] ) ) { |
|
168 | + curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
169 | + } |
|
167 | 170 | break; |
168 | 171 | } |
169 | 172 | |
@@ -174,19 +177,22 @@ discard block |
||
174 | 177 | |
175 | 178 | curl_setopt( $handle, CURLOPT_HEADER, false ); |
176 | 179 | |
177 | - if ( isset( $r['limit_response_size'] ) ) |
|
178 | - $this->max_body_length = intval( $r['limit_response_size'] ); |
|
179 | - else |
|
180 | - $this->max_body_length = false; |
|
180 | + if ( isset( $r['limit_response_size'] ) ) { |
|
181 | + $this->max_body_length = intval( $r['limit_response_size'] ); |
|
182 | + } else { |
|
183 | + $this->max_body_length = false; |
|
184 | + } |
|
181 | 185 | |
182 | 186 | // If streaming to a file open a file handle, and setup our curl streaming handler. |
183 | 187 | if ( $r['stream'] ) { |
184 | - if ( ! WP_DEBUG ) |
|
185 | - $this->stream_handle = @fopen( $r['filename'], 'w+' ); |
|
186 | - else |
|
187 | - $this->stream_handle = fopen( $r['filename'], 'w+' ); |
|
188 | - if ( ! $this->stream_handle ) |
|
189 | - return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
188 | + if ( ! WP_DEBUG ) { |
|
189 | + $this->stream_handle = @fopen( $r['filename'], 'w+' ); |
|
190 | + } else { |
|
191 | + $this->stream_handle = fopen( $r['filename'], 'w+' ); |
|
192 | + } |
|
193 | + if ( ! $this->stream_handle ) { |
|
194 | + return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
195 | + } |
|
190 | 196 | } else { |
191 | 197 | $this->stream_handle = false; |
192 | 198 | } |
@@ -200,10 +206,11 @@ discard block |
||
200 | 206 | curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers ); |
201 | 207 | } |
202 | 208 | |
203 | - if ( $r['httpversion'] == '1.0' ) |
|
204 | - curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); |
|
205 | - else |
|
206 | - curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); |
|
209 | + if ( $r['httpversion'] == '1.0' ) { |
|
210 | + curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); |
|
211 | + } else { |
|
212 | + curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); |
|
213 | + } |
|
207 | 214 | |
208 | 215 | /** |
209 | 216 | * Fires before the cURL request is executed. |
@@ -274,8 +281,9 @@ discard block |
||
274 | 281 | |
275 | 282 | curl_close( $handle ); |
276 | 283 | |
277 | - if ( $r['stream'] ) |
|
278 | - fclose( $this->stream_handle ); |
|
284 | + if ( $r['stream'] ) { |
|
285 | + fclose( $this->stream_handle ); |
|
286 | + } |
|
279 | 287 | |
280 | 288 | $response = array( |
281 | 289 | 'headers' => $theHeaders['headers'], |
@@ -286,11 +294,13 @@ discard block |
||
286 | 294 | ); |
287 | 295 | |
288 | 296 | // Handle redirects. |
289 | - if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) |
|
290 | - return $redirect_response; |
|
297 | + if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) { |
|
298 | + return $redirect_response; |
|
299 | + } |
|
291 | 300 | |
292 | - if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) |
|
293 | - $theBody = WP_Http_Encoding::decompress( $theBody ); |
|
301 | + if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) { |
|
302 | + $theBody = WP_Http_Encoding::decompress( $theBody ); |
|
303 | + } |
|
294 | 304 | |
295 | 305 | $response['body'] = $theBody; |
296 | 306 | |
@@ -360,16 +370,18 @@ discard block |
||
360 | 370 | * @return bool False means this class can not be used, true means it can. |
361 | 371 | */ |
362 | 372 | public static function test( $args = array() ) { |
363 | - if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) |
|
364 | - return false; |
|
373 | + if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) { |
|
374 | + return false; |
|
375 | + } |
|
365 | 376 | |
366 | 377 | $is_ssl = isset( $args['ssl'] ) && $args['ssl']; |
367 | 378 | |
368 | 379 | if ( $is_ssl ) { |
369 | 380 | $curl_version = curl_version(); |
370 | 381 | // Check whether this cURL version support SSL requests. |
371 | - if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) |
|
372 | - return false; |
|
382 | + if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) { |
|
383 | + return false; |
|
384 | + } |
|
373 | 385 | } |
374 | 386 | |
375 | 387 | /** |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * @param int $status Optional. HTTP status code. Default 200. |
52 | 52 | * @param array $headers Optional. HTTP header map. Default empty array. |
53 | 53 | */ |
54 | - public function __construct( $data = null, $status = 200, $headers = array() ) { |
|
54 | + public function __construct($data = null, $status = 200, $headers = array()) { |
|
55 | 55 | $this->data = $data; |
56 | - $this->set_status( $status ); |
|
57 | - $this->set_headers( $headers ); |
|
56 | + $this->set_status($status); |
|
57 | + $this->set_headers($headers); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @param array $headers Map of header name to header value. |
79 | 79 | */ |
80 | - public function set_headers( $headers ) { |
|
80 | + public function set_headers($headers) { |
|
81 | 81 | $this->headers = $headers; |
82 | 82 | } |
83 | 83 | |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | * @param bool $replace Optional. Whether to replace an existing header of the same name. |
93 | 93 | * Default true. |
94 | 94 | */ |
95 | - public function header( $key, $value, $replace = true ) { |
|
96 | - if ( $replace || ! isset( $this->headers[ $key ] ) ) { |
|
97 | - $this->headers[ $key ] = $value; |
|
95 | + public function header($key, $value, $replace = true) { |
|
96 | + if ($replace || ! isset($this->headers[$key])) { |
|
97 | + $this->headers[$key] = $value; |
|
98 | 98 | } else { |
99 | - $this->headers[ $key ] .= ', ' . $value; |
|
99 | + $this->headers[$key] .= ', '.$value; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @param int $code HTTP status. |
122 | 122 | */ |
123 | - public function set_status( $code ) { |
|
124 | - $this->status = absint( $code ); |
|
123 | + public function set_status($code) { |
|
124 | + $this->status = absint($code); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @param mixed $data Response data. |
146 | 146 | */ |
147 | - public function set_data( $data ) { |
|
147 | + public function set_data($data) { |
|
148 | 148 | $this->data = $data; |
149 | 149 | } |
150 | 150 |
@@ -58,8 +58,9 @@ |
||
58 | 58 | } |
59 | 59 | |
60 | 60 | $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\""; |
61 | - if ( $page->ID == $args['selected'] ) |
|
62 | - $output .= ' selected="selected"'; |
|
61 | + if ( $page->ID == $args['selected'] ) { |
|
62 | + $output .= ' selected="selected"'; |
|
63 | + } |
|
63 | 64 | $output .= '>'; |
64 | 65 | |
65 | 66 | $title = $page->post_title; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @see Walker::$db_fields |
38 | 38 | * @todo Decouple this |
39 | 39 | */ |
40 | - public $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); |
|
40 | + public $db_fields = array('parent' => 'post_parent', 'id' => 'ID'); |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Starts the element output. |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | * attribute. See wp_dropdown_pages(). Default empty array. |
57 | 57 | * @param int $id Optional. ID of the current page. Default 0 (unused). |
58 | 58 | */ |
59 | - public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) { |
|
59 | + public function start_el(&$output, $page, $depth = 0, $args = array(), $id = 0) { |
|
60 | 60 | $pad = str_repeat(' ', $depth * 3); |
61 | 61 | |
62 | - if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) { |
|
62 | + if ( ! isset($args['value_field']) || ! isset($page->{$args['value_field']} )) { |
|
63 | 63 | $args['value_field'] = 'ID'; |
64 | 64 | } |
65 | 65 | |
66 | - $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\""; |
|
67 | - if ( $page->ID == $args['selected'] ) |
|
66 | + $output .= "\t<option class=\"level-$depth\" value=\"".esc_attr($page->{$args['value_field']} )."\""; |
|
67 | + if ($page->ID == $args['selected']) |
|
68 | 68 | $output .= ' selected="selected"'; |
69 | 69 | $output .= '>'; |
70 | 70 | |
71 | 71 | $title = $page->post_title; |
72 | - if ( '' === $title ) { |
|
72 | + if ('' === $title) { |
|
73 | 73 | /* translators: %d: ID of a post */ |
74 | - $title = sprintf( __( '#%d (no title)' ), $page->ID ); |
|
74 | + $title = sprintf(__('#%d (no title)'), $page->ID); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param string $title Page title. |
83 | 83 | * @param object $page Page data object. |
84 | 84 | */ |
85 | - $title = apply_filters( 'list_pages', $title, $page ); |
|
85 | + $title = apply_filters('list_pages', $title, $page); |
|
86 | 86 | |
87 | - $output .= $pad . esc_html( $title ); |
|
87 | + $output .= $pad.esc_html($title); |
|
88 | 88 | $output .= "</option>\n"; |
89 | 89 | } |
90 | 90 | } |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | * @param string $href Target URI for the link. |
60 | 60 | * @param array $attributes Optional. Link parameters to send along with the URL. Default empty array. |
61 | 61 | */ |
62 | - public function add_link( $rel, $href, $attributes = array() ) { |
|
63 | - if ( empty( $this->links[ $rel ] ) ) { |
|
64 | - $this->links[ $rel ] = array(); |
|
62 | + public function add_link($rel, $href, $attributes = array()) { |
|
63 | + if (empty($this->links[$rel])) { |
|
64 | + $this->links[$rel] = array(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if ( isset( $attributes['href'] ) ) { |
|
67 | + if (isset($attributes['href'])) { |
|
68 | 68 | // Remove the href attribute, as it's used for the main URL. |
69 | - unset( $attributes['href'] ); |
|
69 | + unset($attributes['href']); |
|
70 | 70 | } |
71 | 71 | |
72 | - $this->links[ $rel ][] = array( |
|
72 | + $this->links[$rel][] = array( |
|
73 | 73 | 'href' => $href, |
74 | 74 | 'attributes' => $attributes, |
75 | 75 | ); |
@@ -85,19 +85,19 @@ discard block |
||
85 | 85 | * @param string $href Optional. Only remove links for the relation matching the given href. |
86 | 86 | * Default null. |
87 | 87 | */ |
88 | - public function remove_link( $rel, $href = null ) { |
|
89 | - if ( ! isset( $this->links[ $rel ] ) ) { |
|
88 | + public function remove_link($rel, $href = null) { |
|
89 | + if ( ! isset($this->links[$rel])) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | - if ( $href ) { |
|
94 | - $this->links[ $rel ] = wp_list_filter( $this->links[ $rel ], array( 'href' => $href ), 'NOT' ); |
|
93 | + if ($href) { |
|
94 | + $this->links[$rel] = wp_list_filter($this->links[$rel], array('href' => $href), 'NOT'); |
|
95 | 95 | } else { |
96 | - $this->links[ $rel ] = array(); |
|
96 | + $this->links[$rel] = array(); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( ! $this->links[ $rel ] ) { |
|
100 | - unset( $this->links[ $rel ] ); |
|
99 | + if ( ! $this->links[$rel]) { |
|
100 | + unset($this->links[$rel]); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @param array $links Map of link relation to list of links. |
116 | 116 | */ |
117 | - public function add_links( $links ) { |
|
118 | - foreach ( $links as $rel => $set ) { |
|
117 | + public function add_links($links) { |
|
118 | + foreach ($links as $rel => $set) { |
|
119 | 119 | // If it's a single link, wrap with an array for consistent handling. |
120 | - if ( isset( $set['href'] ) ) { |
|
121 | - $set = array( $set ); |
|
120 | + if (isset($set['href'])) { |
|
121 | + $set = array($set); |
|
122 | 122 | } |
123 | 123 | |
124 | - foreach ( $set as $attributes ) { |
|
125 | - $this->add_link( $rel, $attributes['href'], $attributes ); |
|
124 | + foreach ($set as $attributes) { |
|
125 | + $this->add_link($rel, $attributes['href'], $attributes); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | * @param array $other Optional. Other parameters to send, as an assocative array. |
156 | 156 | * Default empty array. |
157 | 157 | */ |
158 | - public function link_header( $rel, $link, $other = array() ) { |
|
159 | - $header = '<' . $link . '>; rel="' . $rel . '"'; |
|
158 | + public function link_header($rel, $link, $other = array()) { |
|
159 | + $header = '<'.$link.'>; rel="'.$rel.'"'; |
|
160 | 160 | |
161 | - foreach ( $other as $key => $value ) { |
|
162 | - if ( 'title' === $key ) { |
|
163 | - $value = '"' . $value . '"'; |
|
161 | + foreach ($other as $key => $value) { |
|
162 | + if ('title' === $key) { |
|
163 | + $value = '"'.$value.'"'; |
|
164 | 164 | } |
165 | - $header .= '; ' . $key . '=' . $value; |
|
165 | + $header .= '; '.$key.'='.$value; |
|
166 | 166 | } |
167 | - $this->header( 'Link', $header, false ); |
|
167 | + $this->header('Link', $header, false); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @param string $route Route name. |
189 | 189 | */ |
190 | - public function set_matched_route( $route ) { |
|
190 | + public function set_matched_route($route) { |
|
191 | 191 | $this->matched_route = $route; |
192 | 192 | } |
193 | 193 | |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * |
212 | 212 | * @param array $handler The matched handler. |
213 | 213 | */ |
214 | - public function set_matched_handler( $handler ) { |
|
214 | + public function set_matched_handler($handler) { |
|
215 | 215 | $this->matched_handler = $handler; |
216 | 216 | } |
217 | 217 | |
@@ -236,22 +236,22 @@ discard block |
||
236 | 236 | * @return WP_Error|null WP_Error or null on not an errored response. |
237 | 237 | */ |
238 | 238 | public function as_error() { |
239 | - if ( ! $this->is_error() ) { |
|
239 | + if ( ! $this->is_error()) { |
|
240 | 240 | return null; |
241 | 241 | } |
242 | 242 | |
243 | 243 | $error = new WP_Error; |
244 | 244 | |
245 | - if ( is_array( $this->get_data() ) ) { |
|
245 | + if (is_array($this->get_data())) { |
|
246 | 246 | $data = $this->get_data(); |
247 | - $error->add( $data['code'], $data['message'], $data['data'] ); |
|
248 | - if ( ! empty( $data['additional_errors'] ) ) { |
|
249 | - foreach( $data['additional_errors'] as $err ) { |
|
250 | - $error->add( $err['code'], $err['message'], $err['data'] ); |
|
247 | + $error->add($data['code'], $data['message'], $data['data']); |
|
248 | + if ( ! empty($data['additional_errors'])) { |
|
249 | + foreach ($data['additional_errors'] as $err) { |
|
250 | + $error->add($err['code'], $err['message'], $err['data']); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } else { |
254 | - $error->add( $this->get_status(), '', array( 'status' => $this->get_status() ) ); |
|
254 | + $error->add($this->get_status(), '', array('status' => $this->get_status())); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | return $error; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param array $additional Additional CURIEs to register with the API. |
301 | 301 | */ |
302 | - $additional = apply_filters( 'rest_response_link_curies', array() ); |
|
303 | - return array_merge( $curies, $additional ); |
|
302 | + $additional = apply_filters('rest_response_link_curies', array()); |
|
303 | + return array_merge($curies, $additional); |
|
304 | 304 | } |
305 | 305 | } |
@@ -151,32 +151,32 @@ discard block |
||
151 | 151 | * @type array|string $settings All settings IDs tied to the partial. If undefined, `$id` will be used. |
152 | 152 | * } |
153 | 153 | */ |
154 | - public function __construct( WP_Customize_Selective_Refresh $component, $id, $args = array() ) { |
|
155 | - $keys = array_keys( get_object_vars( $this ) ); |
|
156 | - foreach ( $keys as $key ) { |
|
157 | - if ( isset( $args[ $key ] ) ) { |
|
158 | - $this->$key = $args[ $key ]; |
|
154 | + public function __construct(WP_Customize_Selective_Refresh $component, $id, $args = array()) { |
|
155 | + $keys = array_keys(get_object_vars($this)); |
|
156 | + foreach ($keys as $key) { |
|
157 | + if (isset($args[$key])) { |
|
158 | + $this->$key = $args[$key]; |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | 162 | $this->component = $component; |
163 | 163 | $this->id = $id; |
164 | - $this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); |
|
165 | - $this->id_data['base'] = array_shift( $this->id_data['keys'] ); |
|
164 | + $this->id_data['keys'] = preg_split('/\[/', str_replace(']', '', $this->id)); |
|
165 | + $this->id_data['base'] = array_shift($this->id_data['keys']); |
|
166 | 166 | |
167 | - if ( empty( $this->render_callback ) ) { |
|
168 | - $this->render_callback = array( $this, 'render_callback' ); |
|
167 | + if (empty($this->render_callback)) { |
|
168 | + $this->render_callback = array($this, 'render_callback'); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Process settings. |
172 | - if ( ! isset( $this->settings ) ) { |
|
173 | - $this->settings = array( $id ); |
|
174 | - } else if ( is_string( $this->settings ) ) { |
|
175 | - $this->settings = array( $this->settings ); |
|
172 | + if ( ! isset($this->settings)) { |
|
173 | + $this->settings = array($id); |
|
174 | + } else if (is_string($this->settings)) { |
|
175 | + $this->settings = array($this->settings); |
|
176 | 176 | } |
177 | 177 | |
178 | - if ( empty( $this->primary_setting ) ) { |
|
179 | - $this->primary_setting = current( $this->settings ); |
|
178 | + if (empty($this->primary_setting)) { |
|
179 | + $this->primary_setting = current($this->settings); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
@@ -208,17 +208,17 @@ discard block |
||
208 | 208 | * @return string|array|false The rendered partial as a string, raw data array (for client-side JS template), |
209 | 209 | * or false if no render applied. |
210 | 210 | */ |
211 | - final public function render( $container_context = array() ) { |
|
211 | + final public function render($container_context = array()) { |
|
212 | 212 | $partial = $this; |
213 | 213 | $rendered = false; |
214 | 214 | |
215 | - if ( ! empty( $this->render_callback ) ) { |
|
215 | + if ( ! empty($this->render_callback)) { |
|
216 | 216 | ob_start(); |
217 | - $return_render = call_user_func( $this->render_callback, $this, $container_context ); |
|
217 | + $return_render = call_user_func($this->render_callback, $this, $container_context); |
|
218 | 218 | $ob_render = ob_get_clean(); |
219 | 219 | |
220 | - if ( null !== $return_render && '' !== $ob_render ) { |
|
221 | - _doing_it_wrong( __FUNCTION__, __( 'Partial render must echo the content or return the content string (or array), but not both.' ), '4.5.0' ); |
|
220 | + if (null !== $return_render && '' !== $ob_render) { |
|
221 | + _doing_it_wrong(__FUNCTION__, __('Partial render must echo the content or return the content string (or array), but not both.'), '4.5.0'); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /* |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param array $container_context Optional array of context data associated with |
239 | 239 | * the target container. |
240 | 240 | */ |
241 | - $rendered = apply_filters( 'customize_partial_render', $rendered, $partial, $container_context ); |
|
241 | + $rendered = apply_filters('customize_partial_render', $rendered, $partial, $container_context); |
|
242 | 242 | |
243 | 243 | /** |
244 | 244 | * Filters partial rendering for a specific partial. |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param array $container_context Optional array of context data associated with |
253 | 253 | * the target container. |
254 | 254 | */ |
255 | - $rendered = apply_filters( "customize_partial_render_{$partial->id}", $rendered, $partial, $container_context ); |
|
255 | + $rendered = apply_filters("customize_partial_render_{$partial->id}", $rendered, $partial, $container_context); |
|
256 | 256 | |
257 | 257 | return $rendered; |
258 | 258 | } |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | * @param array $context Context. |
277 | 277 | * @return string|array|false |
278 | 278 | */ |
279 | - public function render_callback( WP_Customize_Partial $partial, $context = array() ) { |
|
280 | - unset( $partial, $context ); |
|
279 | + public function render_callback(WP_Customize_Partial $partial, $context = array()) { |
|
280 | + unset($partial, $context); |
|
281 | 281 | return false; |
282 | 282 | } |
283 | 283 | |
@@ -314,12 +314,12 @@ discard block |
||
314 | 314 | * or if one of the associated settings does not exist. |
315 | 315 | */ |
316 | 316 | final public function check_capabilities() { |
317 | - if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) { |
|
317 | + if ( ! empty($this->capability) && ! current_user_can($this->capability)) { |
|
318 | 318 | return false; |
319 | 319 | } |
320 | - foreach ( $this->settings as $setting_id ) { |
|
321 | - $setting = $this->component->manager->get_setting( $setting_id ); |
|
322 | - if ( ! $setting || ! $setting->check_capabilities() ) { |
|
320 | + foreach ($this->settings as $setting_id) { |
|
321 | + $setting = $this->component->manager->get_setting($setting_id); |
|
322 | + if ( ! $setting || ! $setting->check_capabilities()) { |
|
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | } |