@@ -13,36 +13,36 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email { |
14 | 14 | |
15 | 15 | /** |
16 | - * Contains the type of this notification email. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Contains the type of this notification email. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id; |
21 | 21 | |
22 | 22 | /** |
23 | - * Contains any object to use in filters. |
|
24 | - * |
|
25 | - * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
26 | - */ |
|
23 | + * Contains any object to use in filters. |
|
24 | + * |
|
25 | + * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
26 | + */ |
|
27 | 27 | public $object; |
28 | 28 | |
29 | 29 | /** |
30 | - * Class constructor. |
|
31 | - * |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | 32 | * @param string $id Email Type. |
33 | 33 | * @param mixed $object Optional. Associated object. |
34 | - */ |
|
35 | - public function __construct( $id, $object = false ) { |
|
34 | + */ |
|
35 | + public function __construct( $id, $object = false ) { |
|
36 | 36 | $this->id = $id; |
37 | 37 | $this->object = $object; |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | - * Retrieves an option |
|
42 | - * |
|
41 | + * Retrieves an option |
|
42 | + * |
|
43 | 43 | * @return mixed |
44 | - */ |
|
45 | - public function get_option( $key ) { |
|
44 | + */ |
|
45 | + public function get_option( $key ) { |
|
46 | 46 | |
47 | 47 | $key = "email_{$this->id}_$key"; |
48 | 48 | $value = wpinv_get_option( $key, null ); |
@@ -60,80 +60,80 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Retrieves the email body. |
|
64 | - * |
|
63 | + * Retrieves the email body. |
|
64 | + * |
|
65 | 65 | * @return string |
66 | - */ |
|
67 | - public function get_body() { |
|
66 | + */ |
|
67 | + public function get_body() { |
|
68 | 68 | $body = $this->get_option( 'body' ); |
69 | 69 | return apply_filters( 'getpaid_get_email_body', $body, $this->id, $this->object ); |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | - * Retrieves the email subject. |
|
74 | - * |
|
73 | + * Retrieves the email subject. |
|
74 | + * |
|
75 | 75 | * @return string |
76 | - */ |
|
77 | - public function get_subject() { |
|
76 | + */ |
|
77 | + public function get_subject() { |
|
78 | 78 | $subject = $this->get_option( 'subject' ); |
79 | 79 | return apply_filters( 'getpaid_get_email_subject', $subject, $this->id, $this->object ); |
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | - * Retrieves the email heading. |
|
84 | - * |
|
83 | + * Retrieves the email heading. |
|
84 | + * |
|
85 | 85 | * @return string |
86 | - */ |
|
87 | - public function get_heading() { |
|
86 | + */ |
|
87 | + public function get_heading() { |
|
88 | 88 | $heading = $this->get_option( 'heading' ); |
89 | 89 | return apply_filters( 'getpaid_get_email_heading', $heading, $this->id, $this->object ); |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | - * Checks if an email is active. |
|
94 | - * |
|
93 | + * Checks if an email is active. |
|
94 | + * |
|
95 | 95 | * @return bool |
96 | - */ |
|
97 | - public function is_active() { |
|
96 | + */ |
|
97 | + public function is_active() { |
|
98 | 98 | $is_active = ! empty( $this->get_option( 'active' ) ); |
99 | 99 | return apply_filters( 'getpaid_email_type_is_active', $is_active, $this->id, $this->object ); |
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * Checks if the site's admin should receive email notifications. |
|
104 | - * |
|
103 | + * Checks if the site's admin should receive email notifications. |
|
104 | + * |
|
105 | 105 | * @return bool |
106 | - */ |
|
107 | - public function include_admin_bcc() { |
|
106 | + */ |
|
107 | + public function include_admin_bcc() { |
|
108 | 108 | $include_admin_bcc = ! empty( $this->get_option( 'admin_bcc' ) ); |
109 | 109 | return apply_filters( 'getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object ); |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Checks whether this email should be sent to the customer or admin. |
|
114 | - * |
|
113 | + * Checks whether this email should be sent to the customer or admin. |
|
114 | + * |
|
115 | 115 | * @return bool |
116 | - */ |
|
117 | - public function is_admin_email() { |
|
116 | + */ |
|
117 | + public function is_admin_email() { |
|
118 | 118 | $is_admin_email = in_array( $this->id, array( 'new_invoice', 'failed_invoice' ) ); |
119 | 119 | return apply_filters( 'getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object ); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | - * Returns email attachments. |
|
124 | - * |
|
123 | + * Returns email attachments. |
|
124 | + * |
|
125 | 125 | * @return array |
126 | - */ |
|
127 | - public function get_attachments() { |
|
126 | + */ |
|
127 | + public function get_attachments() { |
|
128 | 128 | return apply_filters( 'getpaid_get_email_attachments', array(), $this->id, $this->object ); |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * Returns an array of merge tags. |
|
133 | - * |
|
132 | + * Returns an array of merge tags. |
|
133 | + * |
|
134 | 134 | * @return array |
135 | - */ |
|
136 | - public function get_merge_tags() { |
|
135 | + */ |
|
136 | + public function get_merge_tags() { |
|
137 | 137 | |
138 | 138 | $merge_tags = array( |
139 | 139 | '{site_title}' => wpinv_get_blogname(), |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Adds merge tags to a text. |
|
148 | - * |
|
147 | + * Adds merge tags to a text. |
|
148 | + * |
|
149 | 149 | * @param string string $text |
150 | 150 | * @param array $merge_tags |
151 | 151 | * @return string |
152 | - */ |
|
153 | - public function add_merge_tags( $text, $merge_tags = array() ) { |
|
152 | + */ |
|
153 | + public function add_merge_tags( $text, $merge_tags = array() ) { |
|
154 | 154 | |
155 | 155 | foreach ( $merge_tags as $key => $value ) { |
156 | 156 | $text = str_replace( $key, $value, $text ); |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | - * Returns the email content |
|
164 | - * |
|
163 | + * Returns the email content |
|
164 | + * |
|
165 | 165 | * @param array $merge_tags |
166 | 166 | * @param array $extra_args Extra template args |
167 | 167 | * @return string |
168 | - */ |
|
169 | - public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
168 | + */ |
|
169 | + public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
170 | 170 | |
171 | 171 | $content = wpinv_get_template_html( |
172 | 172 | "emails/wpinv-email-{$this->id}.php", |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Represents a single email type. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param string $id Email Type. |
33 | 33 | * @param mixed $object Optional. Associated object. |
34 | 34 | */ |
35 | - public function __construct( $id, $object = false ) { |
|
35 | + public function __construct($id, $object = false) { |
|
36 | 36 | $this->id = $id; |
37 | 37 | $this->object = $object; |
38 | 38 | } |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return mixed |
44 | 44 | */ |
45 | - public function get_option( $key ) { |
|
45 | + public function get_option($key) { |
|
46 | 46 | |
47 | 47 | $key = "email_{$this->id}_$key"; |
48 | - $value = wpinv_get_option( $key, null ); |
|
49 | - if ( is_null( $value ) ) { |
|
48 | + $value = wpinv_get_option($key, null); |
|
49 | + if (is_null($value)) { |
|
50 | 50 | $options = wpinv_get_emails(); |
51 | 51 | |
52 | - if ( ! isset( $options[ $this->id ] ) || ! isset( $options[ $this->id ][ $key ] ) ) { |
|
52 | + if (!isset($options[$this->id]) || !isset($options[$this->id][$key])) { |
|
53 | 53 | return ''; |
54 | 54 | } |
55 | 55 | |
56 | - $value = isset( $options[ $this->id ][ $key ]['std'] ) ? $options[ $this->id ][ $key ]['std'] : ''; |
|
56 | + $value = isset($options[$this->id][$key]['std']) ? $options[$this->id][$key]['std'] : ''; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | return $value; |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @return string |
66 | 66 | */ |
67 | 67 | public function get_body() { |
68 | - $body = $this->get_option( 'body' ); |
|
69 | - return apply_filters( 'getpaid_get_email_body', $body, $this->id, $this->object ); |
|
68 | + $body = $this->get_option('body'); |
|
69 | + return apply_filters('getpaid_get_email_body', $body, $this->id, $this->object); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * @return string |
76 | 76 | */ |
77 | 77 | public function get_subject() { |
78 | - $subject = $this->get_option( 'subject' ); |
|
79 | - return apply_filters( 'getpaid_get_email_subject', $subject, $this->id, $this->object ); |
|
78 | + $subject = $this->get_option('subject'); |
|
79 | + return apply_filters('getpaid_get_email_subject', $subject, $this->id, $this->object); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * @return string |
86 | 86 | */ |
87 | 87 | public function get_heading() { |
88 | - $heading = $this->get_option( 'heading' ); |
|
89 | - return apply_filters( 'getpaid_get_email_heading', $heading, $this->id, $this->object ); |
|
88 | + $heading = $this->get_option('heading'); |
|
89 | + return apply_filters('getpaid_get_email_heading', $heading, $this->id, $this->object); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | * @return bool |
96 | 96 | */ |
97 | 97 | public function is_active() { |
98 | - $is_active = ! empty( $this->get_option( 'active' ) ); |
|
99 | - return apply_filters( 'getpaid_email_type_is_active', $is_active, $this->id, $this->object ); |
|
98 | + $is_active = !empty($this->get_option('active')); |
|
99 | + return apply_filters('getpaid_email_type_is_active', $is_active, $this->id, $this->object); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * @return bool |
106 | 106 | */ |
107 | 107 | public function include_admin_bcc() { |
108 | - $include_admin_bcc = ! empty( $this->get_option( 'admin_bcc' ) ); |
|
109 | - return apply_filters( 'getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object ); |
|
108 | + $include_admin_bcc = !empty($this->get_option('admin_bcc')); |
|
109 | + return apply_filters('getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * @return bool |
116 | 116 | */ |
117 | 117 | public function is_admin_email() { |
118 | - $is_admin_email = in_array( $this->id, array( 'new_invoice', 'failed_invoice' ) ); |
|
119 | - return apply_filters( 'getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object ); |
|
118 | + $is_admin_email = in_array($this->id, array('new_invoice', 'failed_invoice')); |
|
119 | + return apply_filters('getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return array |
126 | 126 | */ |
127 | 127 | public function get_attachments() { |
128 | - return apply_filters( 'getpaid_get_email_attachments', array(), $this->id, $this->object ); |
|
128 | + return apply_filters('getpaid_get_email_attachments', array(), $this->id, $this->object); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | |
138 | 138 | $merge_tags = array( |
139 | 139 | '{site_title}' => wpinv_get_blogname(), |
140 | - '{date}' => getpaid_format_date_value( current_time( 'mysql' ) ), |
|
140 | + '{date}' => getpaid_format_date_value(current_time('mysql')), |
|
141 | 141 | ); |
142 | 142 | |
143 | - return apply_filters( 'getpaid_get_email_merge_tags', $merge_tags, $this->object, $this->id ); |
|
143 | + return apply_filters('getpaid_get_email_merge_tags', $merge_tags, $this->object, $this->id); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -150,13 +150,13 @@ discard block |
||
150 | 150 | * @param array $merge_tags |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function add_merge_tags( $text, $merge_tags = array() ) { |
|
153 | + public function add_merge_tags($text, $merge_tags = array()) { |
|
154 | 154 | |
155 | - foreach ( $merge_tags as $key => $value ) { |
|
156 | - $text = str_replace( $key, $value, $text ); |
|
155 | + foreach ($merge_tags as $key => $value) { |
|
156 | + $text = str_replace($key, $value, $text); |
|
157 | 157 | } |
158 | 158 | |
159 | - return wptexturize( $text ); |
|
159 | + return wptexturize($text); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param array $extra_args Extra template args |
167 | 167 | * @return string |
168 | 168 | */ |
169 | - public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
169 | + public function get_content($merge_tags = array(), $extra_args = array()) { |
|
170 | 170 | |
171 | 171 | $content = wpinv_get_template_html( |
172 | 172 | "emails/wpinv-email-{$this->id}.php", |
@@ -176,15 +176,15 @@ discard block |
||
176 | 176 | 'invoice' => $this->object, // Backwards compat. |
177 | 177 | 'object' => $this->object, |
178 | 178 | 'email_type' => $this->id, |
179 | - 'email_heading' => $this->add_merge_tags( $this->get_heading(), $merge_tags ), |
|
179 | + 'email_heading' => $this->add_merge_tags($this->get_heading(), $merge_tags), |
|
180 | 180 | 'sent_to_admin' => $this->is_admin_email(), |
181 | 181 | 'plain_text' => false, |
182 | - 'message_body' => wpautop( $this->add_merge_tags( $this->get_body(), $merge_tags ) ), |
|
182 | + 'message_body' => wpautop($this->add_merge_tags($this->get_body(), $merge_tags)), |
|
183 | 183 | ) |
184 | 184 | ) |
185 | 185 | ); |
186 | 186 | |
187 | - return wpinv_email_style_body( $content ); |
|
187 | + return wpinv_email_style_body($content); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | } |
@@ -12,294 +12,294 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Helper { |
14 | 14 | |
15 | - /** |
|
16 | - * Get report totals such as invoice totals and discount amounts. |
|
17 | - * |
|
18 | - * Data example: |
|
19 | - * |
|
20 | - * 'subtotal' => array( |
|
21 | - * 'type' => 'invoice_data', |
|
22 | - * 'function' => 'SUM', |
|
23 | - * 'name' => 'subtotal' |
|
24 | - * ) |
|
25 | - * |
|
26 | - * @param array $args |
|
27 | - * @return mixed depending on query_type |
|
28 | - */ |
|
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $default_args = array( |
|
33 | - 'data' => array(), // The data to retrieve. |
|
34 | - 'where' => array(), // An array of where queries. |
|
35 | - 'query_type' => 'get_row', // wpdb query to run. |
|
36 | - 'group_by' => '', // What to group results by. |
|
37 | - 'order_by' => '', // What to order by. |
|
38 | - 'limit' => '', // Results limit. |
|
39 | - 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | - 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | - ); |
|
44 | - |
|
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
47 | - |
|
48 | - extract( $args ); |
|
49 | - |
|
50 | - if ( empty( $data ) ) { |
|
51 | - return ''; |
|
52 | - } |
|
53 | - |
|
54 | - $query = array(); |
|
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | - $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | - |
|
59 | - $query['where'] = " |
|
15 | + /** |
|
16 | + * Get report totals such as invoice totals and discount amounts. |
|
17 | + * |
|
18 | + * Data example: |
|
19 | + * |
|
20 | + * 'subtotal' => array( |
|
21 | + * 'type' => 'invoice_data', |
|
22 | + * 'function' => 'SUM', |
|
23 | + * 'name' => 'subtotal' |
|
24 | + * ) |
|
25 | + * |
|
26 | + * @param array $args |
|
27 | + * @return mixed depending on query_type |
|
28 | + */ |
|
29 | + public static function get_invoice_report_data( $args = array() ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $default_args = array( |
|
33 | + 'data' => array(), // The data to retrieve. |
|
34 | + 'where' => array(), // An array of where queries. |
|
35 | + 'query_type' => 'get_row', // wpdb query to run. |
|
36 | + 'group_by' => '', // What to group results by. |
|
37 | + 'order_by' => '', // What to order by. |
|
38 | + 'limit' => '', // Results limit. |
|
39 | + 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | + 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | + 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | + ); |
|
44 | + |
|
45 | + $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | + $args = wp_parse_args( $args, $default_args ); |
|
47 | + |
|
48 | + extract( $args ); |
|
49 | + |
|
50 | + if ( empty( $data ) ) { |
|
51 | + return ''; |
|
52 | + } |
|
53 | + |
|
54 | + $query = array(); |
|
55 | + $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | + $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | + $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | + |
|
59 | + $query['where'] = " |
|
60 | 60 | WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
64 | - $query['where'] .= " |
|
63 | + if ( ! empty( $invoice_status ) ) { |
|
64 | + $query['where'] .= " |
|
65 | 65 | AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
66 | 66 | "; |
67 | - } |
|
68 | - |
|
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | - } else { |
|
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
78 | - $query['where'] .= " |
|
67 | + } |
|
68 | + |
|
69 | + if ( ! empty( $parent_invoice_status ) ) { |
|
70 | + if ( ! empty( $invoice_status ) ) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | + } else { |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + if ( ! empty( $filter_range['before'] ) ) { |
|
78 | + $query['where'] .= " |
|
79 | 79 | AND posts.post_date < '" . date( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
80 | 80 | "; |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
84 | - $query['where'] .= " |
|
83 | + if ( ! empty( $filter_range['after'] ) ) { |
|
84 | + $query['where'] .= " |
|
85 | 85 | AND posts.post_date > '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['after'] ) ) . "' |
86 | 86 | "; |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if ( ! empty( $where ) ) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ( $where as $value ) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) { |
|
94 | - |
|
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
97 | - } |
|
98 | - |
|
99 | - if ( ! empty( $value['value'] ) ) { |
|
100 | - $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | - } |
|
102 | - } else { |
|
103 | - $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! empty( $where_value ) ) { |
|
107 | - $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - if ( $group_by ) { |
|
113 | - $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | - } |
|
115 | - |
|
116 | - if ( $order_by ) { |
|
117 | - $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | - } |
|
119 | - |
|
120 | - if ( $limit ) { |
|
121 | - $query['limit'] = "LIMIT {$limit}"; |
|
122 | - } |
|
123 | - |
|
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
126 | - |
|
127 | - return self::execute( $query_type, $query ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Prepares the data to select. |
|
133 | - * |
|
134 | - * |
|
135 | - * @param array $data |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public static function prepare_invoice_data( $data ) { |
|
139 | - |
|
140 | - $prepared = array(); |
|
141 | - |
|
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
144 | - $distinct = ''; |
|
145 | - |
|
146 | - if ( isset( $value['distinct'] ) ) { |
|
147 | - $distinct = 'DISTINCT'; |
|
148 | - } |
|
149 | - |
|
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | - |
|
152 | - if ( false === $get_key ) { |
|
153 | - // Skip to the next foreach iteration else the query will be invalid. |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if ( ! empty( $value['function'] ) ) { |
|
158 | - $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | - } else { |
|
160 | - $get = "{$distinct} {$get_key}"; |
|
161 | - } |
|
162 | - |
|
163 | - $prepared[] = "{$get} as {$value['name']}"; |
|
164 | - } |
|
165 | - |
|
166 | - return $prepared; |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Prepares the joins to use. |
|
172 | - * |
|
173 | - * |
|
174 | - * @param array $data |
|
175 | - * @param bool $with_parent |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | - global $wpdb; |
|
180 | - |
|
181 | - $prepared = array(); |
|
182 | - |
|
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
187 | - |
|
188 | - switch ( $type ) { |
|
189 | - case 'meta': |
|
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | - break; |
|
192 | - case 'parent_meta': |
|
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | - break; |
|
195 | - case 'invoice_data': |
|
196 | - $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | - break; |
|
198 | - case 'invoice_item': |
|
199 | - $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | - break; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - if ( $with_parent ) { |
|
205 | - $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | - } |
|
207 | - |
|
208 | - return $prepared; |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Retrieves the appropriate table key to use. |
|
214 | - * |
|
215 | - * |
|
216 | - * @param string $key |
|
217 | - * @param string $table |
|
218 | - * @return string|false |
|
219 | - */ |
|
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
221 | - |
|
222 | - $keys = array( |
|
223 | - 'meta' => "meta_{$key}.meta_value", |
|
224 | - 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | - 'post_data' => "posts.{$key}", |
|
226 | - 'invoice_data' => "invoices.{$key}", |
|
227 | - 'invoice_item' => "invoice_items.{$key}", |
|
228 | - ); |
|
229 | - |
|
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | - |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Executes a query and caches the result for a minute. |
|
236 | - * |
|
237 | - * |
|
238 | - * @param string $query_type |
|
239 | - * @param string $query |
|
240 | - * @return mixed depending on query_type |
|
241 | - */ |
|
242 | - public static function execute( $query_type, $query ) { |
|
243 | - global $wpdb; |
|
244 | - |
|
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
248 | - self::enable_big_selects(); |
|
249 | - |
|
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
252 | - } |
|
253 | - |
|
254 | - return $result; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Enables big mysql selects for reports, just once for this session. |
|
260 | - */ |
|
261 | - protected static function enable_big_selects() { |
|
262 | - static $big_selects = false; |
|
263 | - |
|
264 | - global $wpdb; |
|
265 | - |
|
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | - $big_selects = true; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Get the cached query result or null if it's not in the cache. |
|
274 | - * |
|
275 | - * @param string $query_hash The query hash. |
|
276 | - * |
|
277 | - * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | - */ |
|
279 | - protected static function get_cached_query( $query_hash ) { |
|
280 | - |
|
281 | - return wp_cache_get( |
|
282 | - $query_hash, |
|
283 | - strtolower( __CLASS__ ) |
|
284 | - ); |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Set the cached query result. |
|
290 | - * |
|
291 | - * @param string $query_hash The query hash. |
|
292 | - * @param mixed $data The data to cache. |
|
293 | - */ |
|
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
295 | - |
|
296 | - wp_cache_set( |
|
297 | - $query_hash, |
|
298 | - $data, |
|
299 | - strtolower( __CLASS__ ), |
|
300 | - MINUTE_IN_SECONDS |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
93 | + if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) { |
|
94 | + |
|
95 | + if ( is_array( $value['value'] ) ) { |
|
96 | + $value['value'] = implode( "','", $value['value'] ); |
|
97 | + } |
|
98 | + |
|
99 | + if ( ! empty( $value['value'] ) ) { |
|
100 | + $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | + } |
|
102 | + } else { |
|
103 | + $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! empty( $where_value ) ) { |
|
107 | + $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + if ( $group_by ) { |
|
113 | + $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | + } |
|
115 | + |
|
116 | + if ( $order_by ) { |
|
117 | + $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | + } |
|
119 | + |
|
120 | + if ( $limit ) { |
|
121 | + $query['limit'] = "LIMIT {$limit}"; |
|
122 | + } |
|
123 | + |
|
124 | + $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | + $query = implode( ' ', $query ); |
|
126 | + |
|
127 | + return self::execute( $query_type, $query ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Prepares the data to select. |
|
133 | + * |
|
134 | + * |
|
135 | + * @param array $data |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public static function prepare_invoice_data( $data ) { |
|
139 | + |
|
140 | + $prepared = array(); |
|
141 | + |
|
142 | + foreach ( $data as $raw_key => $value ) { |
|
143 | + $key = sanitize_key( $raw_key ); |
|
144 | + $distinct = ''; |
|
145 | + |
|
146 | + if ( isset( $value['distinct'] ) ) { |
|
147 | + $distinct = 'DISTINCT'; |
|
148 | + } |
|
149 | + |
|
150 | + $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | + |
|
152 | + if ( false === $get_key ) { |
|
153 | + // Skip to the next foreach iteration else the query will be invalid. |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if ( ! empty( $value['function'] ) ) { |
|
158 | + $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | + } else { |
|
160 | + $get = "{$distinct} {$get_key}"; |
|
161 | + } |
|
162 | + |
|
163 | + $prepared[] = "{$get} as {$value['name']}"; |
|
164 | + } |
|
165 | + |
|
166 | + return $prepared; |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Prepares the joins to use. |
|
172 | + * |
|
173 | + * |
|
174 | + * @param array $data |
|
175 | + * @param bool $with_parent |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | + global $wpdb; |
|
180 | + |
|
181 | + $prepared = array(); |
|
182 | + |
|
183 | + foreach ( $data as $raw_key => $value ) { |
|
184 | + $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | + $key = sanitize_key( $raw_key ); |
|
187 | + |
|
188 | + switch ( $type ) { |
|
189 | + case 'meta': |
|
190 | + $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | + break; |
|
192 | + case 'parent_meta': |
|
193 | + $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | + break; |
|
195 | + case 'invoice_data': |
|
196 | + $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | + break; |
|
198 | + case 'invoice_item': |
|
199 | + $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | + break; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + if ( $with_parent ) { |
|
205 | + $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | + } |
|
207 | + |
|
208 | + return $prepared; |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Retrieves the appropriate table key to use. |
|
214 | + * |
|
215 | + * |
|
216 | + * @param string $key |
|
217 | + * @param string $table |
|
218 | + * @return string|false |
|
219 | + */ |
|
220 | + public static function get_invoice_table_key( $key, $table ) { |
|
221 | + |
|
222 | + $keys = array( |
|
223 | + 'meta' => "meta_{$key}.meta_value", |
|
224 | + 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | + 'post_data' => "posts.{$key}", |
|
226 | + 'invoice_data' => "invoices.{$key}", |
|
227 | + 'invoice_item' => "invoice_items.{$key}", |
|
228 | + ); |
|
229 | + |
|
230 | + return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | + |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Executes a query and caches the result for a minute. |
|
236 | + * |
|
237 | + * |
|
238 | + * @param string $query_type |
|
239 | + * @param string $query |
|
240 | + * @return mixed depending on query_type |
|
241 | + */ |
|
242 | + public static function execute( $query_type, $query ) { |
|
243 | + global $wpdb; |
|
244 | + |
|
245 | + $query_hash = md5( $query_type . $query ); |
|
246 | + $result = self::get_cached_query( $query_hash ); |
|
247 | + if ( $result === false ) { |
|
248 | + self::enable_big_selects(); |
|
249 | + |
|
250 | + $result = $wpdb->$query_type( $query ); |
|
251 | + self::set_cached_query( $query_hash, $result ); |
|
252 | + } |
|
253 | + |
|
254 | + return $result; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Enables big mysql selects for reports, just once for this session. |
|
260 | + */ |
|
261 | + protected static function enable_big_selects() { |
|
262 | + static $big_selects = false; |
|
263 | + |
|
264 | + global $wpdb; |
|
265 | + |
|
266 | + if ( ! $big_selects ) { |
|
267 | + $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | + $big_selects = true; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Get the cached query result or null if it's not in the cache. |
|
274 | + * |
|
275 | + * @param string $query_hash The query hash. |
|
276 | + * |
|
277 | + * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | + */ |
|
279 | + protected static function get_cached_query( $query_hash ) { |
|
280 | + |
|
281 | + return wp_cache_get( |
|
282 | + $query_hash, |
|
283 | + strtolower( __CLASS__ ) |
|
284 | + ); |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Set the cached query result. |
|
290 | + * |
|
291 | + * @param string $query_hash The query hash. |
|
292 | + * @param mixed $data The data to cache. |
|
293 | + */ |
|
294 | + protected static function set_cached_query( $query_hash, $data ) { |
|
295 | + |
|
296 | + wp_cache_set( |
|
297 | + $query_hash, |
|
298 | + $data, |
|
299 | + strtolower( __CLASS__ ), |
|
300 | + MINUTE_IN_SECONDS |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Helper Class. |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param array $args |
27 | 27 | * @return mixed depending on query_type |
28 | 28 | */ |
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
29 | + public static function get_invoice_report_data($args = array()) { |
|
30 | 30 | global $wpdb; |
31 | 31 | |
32 | 32 | $default_args = array( |
@@ -37,94 +37,94 @@ discard block |
||
37 | 37 | 'order_by' => '', // What to order by. |
38 | 38 | 'limit' => '', // Results limit. |
39 | 39 | 'filter_range' => array(), // An array of before and after dates to limit results by. |
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
40 | + 'invoice_types' => array('wpi_invoice'), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold'), |
|
42 | 42 | 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
43 | 43 | ); |
44 | 44 | |
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
45 | + $args = apply_filters('getpaid_reports_get_invoice_report_data_args', $args); |
|
46 | + $args = wp_parse_args($args, $default_args); |
|
47 | 47 | |
48 | - extract( $args ); |
|
48 | + extract($args); |
|
49 | 49 | |
50 | - if ( empty( $data ) ) { |
|
50 | + if (empty($data)) { |
|
51 | 51 | return ''; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $query = array(); |
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
55 | + $query['select'] = 'SELECT ' . implode(',', self::prepare_invoice_data($data)); |
|
56 | 56 | $query['from'] = "FROM {$wpdb->posts} AS posts"; |
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
57 | + $query['join'] = implode(' ', self::prepare_invoice_joins($data + $where, !empty($parent_invoice_status))); |
|
58 | 58 | |
59 | 59 | $query['where'] = " |
60 | - WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
|
60 | + WHERE posts.post_type IN ( '" . implode("','", $invoice_types) . "' ) |
|
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
63 | + if (!empty($invoice_status)) { |
|
64 | 64 | $query['where'] .= " |
65 | - AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
|
65 | + AND posts.post_status IN ( '" . implode("','", $invoice_status) . "' ) |
|
66 | 66 | "; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
69 | + if (!empty($parent_invoice_status)) { |
|
70 | + if (!empty($invoice_status)) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) OR parent.ID IS NULL ) "; |
|
72 | 72 | } else { |
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) "; |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
77 | + if (!empty($filter_range['before'])) { |
|
78 | 78 | $query['where'] .= " |
79 | - AND posts.post_date < '" . date( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
|
79 | + AND posts.post_date < '" . date('Y-m-d 23:59:59', strtotime($filter_range['before'])) . "' |
|
80 | 80 | "; |
81 | 81 | } |
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
83 | + if (!empty($filter_range['after'])) { |
|
84 | 84 | $query['where'] .= " |
85 | - AND posts.post_date > '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['after'] ) ) . "' |
|
85 | + AND posts.post_date > '" . date('Y-m-d H:i:s', strtotime($filter_range['after'])) . "' |
|
86 | 86 | "; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if (!empty($where)) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ($where as $value) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) { |
|
93 | + if (strtolower($value['operator']) == 'in' || strtolower($value['operator']) == 'not in') { |
|
94 | 94 | |
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
95 | + if (is_array($value['value'])) { |
|
96 | + $value['value'] = implode("','", $value['value']); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( ! empty( $value['value'] ) ) { |
|
99 | + if (!empty($value['value'])) { |
|
100 | 100 | $where_value = "{$value['operator']} ('{$value['value']}')"; |
101 | 101 | } |
102 | 102 | } else { |
103 | 103 | $where_value = "{$value['operator']} '{$value['value']}'"; |
104 | 104 | } |
105 | 105 | |
106 | - if ( ! empty( $where_value ) ) { |
|
106 | + if (!empty($where_value)) { |
|
107 | 107 | $query['where'] .= " AND {$value['key']} {$where_value}"; |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( $group_by ) { |
|
112 | + if ($group_by) { |
|
113 | 113 | $query['group_by'] = "GROUP BY {$group_by}"; |
114 | 114 | } |
115 | 115 | |
116 | - if ( $order_by ) { |
|
116 | + if ($order_by) { |
|
117 | 117 | $query['order_by'] = "ORDER BY {$order_by}"; |
118 | 118 | } |
119 | 119 | |
120 | - if ( $limit ) { |
|
120 | + if ($limit) { |
|
121 | 121 | $query['limit'] = "LIMIT {$limit}"; |
122 | 122 | } |
123 | 123 | |
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
124 | + $query = apply_filters('getpaid_reports_get_invoice_report_query', $query, $data); |
|
125 | + $query = implode(' ', $query); |
|
126 | 126 | |
127 | - return self::execute( $query_type, $query ); |
|
127 | + return self::execute($query_type, $query); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
@@ -135,26 +135,26 @@ discard block |
||
135 | 135 | * @param array $data |
136 | 136 | * @return array |
137 | 137 | */ |
138 | - public static function prepare_invoice_data( $data ) { |
|
138 | + public static function prepare_invoice_data($data) { |
|
139 | 139 | |
140 | 140 | $prepared = array(); |
141 | 141 | |
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
142 | + foreach ($data as $raw_key => $value) { |
|
143 | + $key = sanitize_key($raw_key); |
|
144 | 144 | $distinct = ''; |
145 | 145 | |
146 | - if ( isset( $value['distinct'] ) ) { |
|
146 | + if (isset($value['distinct'])) { |
|
147 | 147 | $distinct = 'DISTINCT'; |
148 | 148 | } |
149 | 149 | |
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
150 | + $get_key = self::get_invoice_table_key($key, $value['type']); |
|
151 | 151 | |
152 | - if ( false === $get_key ) { |
|
152 | + if (false === $get_key) { |
|
153 | 153 | // Skip to the next foreach iteration else the query will be invalid. |
154 | 154 | continue; |
155 | 155 | } |
156 | 156 | |
157 | - if ( ! empty( $value['function'] ) ) { |
|
157 | + if (!empty($value['function'])) { |
|
158 | 158 | $get = "{$value['function']}({$distinct} {$get_key})"; |
159 | 159 | } else { |
160 | 160 | $get = "{$distinct} {$get_key}"; |
@@ -175,22 +175,22 @@ discard block |
||
175 | 175 | * @param bool $with_parent |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
178 | + public static function prepare_invoice_joins($data, $with_parent) { |
|
179 | 179 | global $wpdb; |
180 | 180 | |
181 | 181 | $prepared = array(); |
182 | 182 | |
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
183 | + foreach ($data as $raw_key => $value) { |
|
184 | + $join_type = isset($value['join_type']) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset($value['type']) ? $value['type'] : false; |
|
186 | + $key = sanitize_key($raw_key); |
|
187 | 187 | |
188 | - switch ( $type ) { |
|
188 | + switch ($type) { |
|
189 | 189 | case 'meta': |
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
190 | + $prepared["meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | 191 | break; |
192 | 192 | case 'parent_meta': |
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
193 | + $prepared["parent_meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | 194 | break; |
195 | 195 | case 'invoice_data': |
196 | 196 | $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( $with_parent ) { |
|
204 | + if ($with_parent) { |
|
205 | 205 | $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
206 | 206 | } |
207 | 207 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param string $table |
218 | 218 | * @return string|false |
219 | 219 | */ |
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
220 | + public static function get_invoice_table_key($key, $table) { |
|
221 | 221 | |
222 | 222 | $keys = array( |
223 | 223 | 'meta' => "meta_{$key}.meta_value", |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | 'invoice_item' => "invoice_items.{$key}", |
228 | 228 | ); |
229 | 229 | |
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
230 | + return isset($keys[$table]) ? $keys[$table] : false; |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | |
@@ -239,16 +239,16 @@ discard block |
||
239 | 239 | * @param string $query |
240 | 240 | * @return mixed depending on query_type |
241 | 241 | */ |
242 | - public static function execute( $query_type, $query ) { |
|
242 | + public static function execute($query_type, $query) { |
|
243 | 243 | global $wpdb; |
244 | 244 | |
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
245 | + $query_hash = md5($query_type . $query); |
|
246 | + $result = self::get_cached_query($query_hash); |
|
247 | + if ($result === false) { |
|
248 | 248 | self::enable_big_selects(); |
249 | 249 | |
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
250 | + $result = $wpdb->$query_type($query); |
|
251 | + self::set_cached_query($query_hash, $result); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | return $result; |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | |
264 | 264 | global $wpdb; |
265 | 265 | |
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
266 | + if (!$big_selects) { |
|
267 | + $wpdb->query('SET SESSION SQL_BIG_SELECTS=1'); |
|
268 | 268 | $big_selects = true; |
269 | 269 | } |
270 | 270 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
278 | 278 | */ |
279 | - protected static function get_cached_query( $query_hash ) { |
|
279 | + protected static function get_cached_query($query_hash) { |
|
280 | 280 | |
281 | 281 | return wp_cache_get( |
282 | 282 | $query_hash, |
283 | - strtolower( __CLASS__ ) |
|
283 | + strtolower(__CLASS__) |
|
284 | 284 | ); |
285 | 285 | |
286 | 286 | } |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | * @param string $query_hash The query hash. |
292 | 292 | * @param mixed $data The data to cache. |
293 | 293 | */ |
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
294 | + protected static function set_cached_query($query_hash, $data) { |
|
295 | 295 | |
296 | 296 | wp_cache_set( |
297 | 297 | $query_hash, |
298 | 298 | $data, |
299 | - strtolower( __CLASS__ ), |
|
299 | + strtolower(__CLASS__), |
|
300 | 300 | MINUTE_IN_SECONDS |
301 | 301 | ); |
302 | 302 |
@@ -7,20 +7,20 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Fetch the invoice. |
13 | -if ( empty( $invoice ) ) { |
|
14 | - $invoice = new WPInv_Invoice( $GLOBALS['post'] ); |
|
13 | +if (empty($invoice)) { |
|
14 | + $invoice = new WPInv_Invoice($GLOBALS['post']); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | // Abort if it does not exist. |
18 | -if ( $invoice->get_id() == 0 ) { |
|
18 | +if ($invoice->get_id() == 0) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | 22 | // Fires before printing an invoice. |
23 | -do_action( 'wpinv_invoice_print_before_display', $invoice ); |
|
23 | +do_action('wpinv_invoice_print_before_display', $invoice); |
|
24 | 24 | |
25 | 25 | ?><!DOCTYPE html> |
26 | 26 | |
@@ -29,16 +29,16 @@ discard block |
||
29 | 29 | |
30 | 30 | <head> |
31 | 31 | |
32 | - <meta charset="<?php bloginfo( 'charset' ); ?>"> |
|
32 | + <meta charset="<?php bloginfo('charset'); ?>"> |
|
33 | 33 | <meta name="viewport" content="width=device-width, initial-scale=1.0" > |
34 | 34 | |
35 | 35 | <meta name="robots" content="noindex,nofollow"> |
36 | 36 | |
37 | 37 | <link rel="profile" href="https://gmpg.org/xfn/11"> |
38 | 38 | |
39 | - <title>#<?php echo esc_html( $invoice->get_number() ); ?></title> |
|
39 | + <title>#<?php echo esc_html($invoice->get_number()); ?></title> |
|
40 | 40 | |
41 | - <?php do_action( 'wpinv_invoice_print_head', $invoice ); ?> |
|
41 | + <?php do_action('wpinv_invoice_print_head', $invoice); ?> |
|
42 | 42 | |
43 | 43 | <style type="text/css"> |
44 | 44 | .body{ |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | <body class="body wpinv wpinv-print" style="font-weight: 400;"> |
71 | 71 | |
72 | 72 | <div id="wpinv-print-inner"> |
73 | - <?php do_action( 'getpaid_invoice', $invoice ); ?> |
|
74 | - <?php do_action( 'wpinv_invoice_print_body_end', $invoice ); ?> |
|
73 | + <?php do_action('getpaid_invoice', $invoice); ?> |
|
74 | + <?php do_action('wpinv_invoice_print_body_end', $invoice); ?> |
|
75 | 75 | </div> |
76 | 76 | </body> |
77 | 77 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,470 +11,470 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Helper { |
13 | 13 | |
14 | - /** |
|
15 | - * A component helper for generating a input name. |
|
16 | - * |
|
17 | - * @param $text |
|
18 | - * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public static function name( $text, $multiple = false ) { |
|
23 | - $output = ''; |
|
24 | - |
|
25 | - if ( $text ) { |
|
26 | - $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | - $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
28 | - } |
|
29 | - |
|
30 | - return $output; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * A component helper for generating a item id. |
|
35 | - * |
|
36 | - * @param $text string The text to be used as the value. |
|
37 | - * |
|
38 | - * @return string The sanitized item. |
|
39 | - */ |
|
40 | - public static function id( $text ) { |
|
41 | - $output = ''; |
|
42 | - |
|
43 | - if ( $text ) { |
|
44 | - $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
45 | - } |
|
46 | - |
|
47 | - return $output; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * A component helper for generating a item title. |
|
52 | - * |
|
53 | - * @param $text string The text to be used as the value. |
|
54 | - * |
|
55 | - * @return string The sanitized item. |
|
56 | - */ |
|
57 | - public static function title( $text ) { |
|
58 | - $output = ''; |
|
59 | - |
|
60 | - if ( $text ) { |
|
61 | - $output = ' title="' . esc_attr( $text ) . '" '; |
|
62 | - } |
|
63 | - |
|
64 | - return $output; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * A component helper for generating a item value. |
|
69 | - * |
|
70 | - * @param $text string The text to be used as the value. |
|
71 | - * |
|
72 | - * @return string The sanitized item. |
|
73 | - */ |
|
74 | - public static function value( $text ) { |
|
75 | - $output = ''; |
|
76 | - |
|
77 | - if ( $text !== null && $text !== false ) { |
|
78 | - $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | - } |
|
80 | - |
|
81 | - return $output; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * A component helper for generating a item class attribute. |
|
86 | - * |
|
87 | - * @param $text string The text to be used as the value. |
|
88 | - * |
|
89 | - * @return string The sanitized item. |
|
90 | - */ |
|
91 | - public static function class_attr( $text ) { |
|
92 | - $output = ''; |
|
93 | - |
|
94 | - if ( $text ) { |
|
95 | - $classes = self::esc_classes( $text ); |
|
96 | - if ( ! empty( $classes ) ) { |
|
97 | - $output = ' class="' . $classes . '" '; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - return $output; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Escape a string of classes. |
|
106 | - * |
|
107 | - * @param $text |
|
108 | - * |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public static function esc_classes( $text ) { |
|
112 | - $output = ''; |
|
113 | - |
|
114 | - if ( $text ) { |
|
115 | - $classes = explode( " ", $text ); |
|
116 | - $classes = array_map( "trim", $classes ); |
|
117 | - $classes = array_map( "sanitize_html_class", $classes ); |
|
118 | - if ( ! empty( $classes ) ) { |
|
119 | - $output = implode( " ", $classes ); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - return $output; |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param $args |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public static function data_attributes( $args ) { |
|
133 | - $output = ''; |
|
134 | - |
|
135 | - if ( ! empty( $args ) ) { |
|
136 | - |
|
137 | - foreach ( $args as $key => $val ) { |
|
138 | - if ( substr( $key, 0, 5 ) === "data-" ) { |
|
139 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - return $output; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param $args |
|
149 | - * |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public static function aria_attributes( $args ) { |
|
153 | - $output = ''; |
|
154 | - |
|
155 | - if ( ! empty( $args ) ) { |
|
156 | - |
|
157 | - foreach ( $args as $key => $val ) { |
|
158 | - if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
159 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $output; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Build a font awesome icon from a class. |
|
169 | - * |
|
170 | - * @param $class |
|
171 | - * @param bool $space_after |
|
172 | - * @param array $extra_attributes An array of extra attributes. |
|
173 | - * |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
177 | - $output = ''; |
|
178 | - |
|
179 | - if ( $class ) { |
|
180 | - $classes = self::esc_classes( $class ); |
|
181 | - if ( ! empty( $classes ) ) { |
|
182 | - $output = '<i class="' . $classes . '" '; |
|
183 | - // extra attributes |
|
184 | - if ( ! empty( $extra_attributes ) ) { |
|
185 | - $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
186 | - } |
|
187 | - $output .= '></i>'; |
|
188 | - if ( $space_after ) { |
|
189 | - $output .= " "; |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return $output; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $args |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function extra_attributes( $args ) { |
|
203 | - $output = ''; |
|
204 | - |
|
205 | - if ( ! empty( $args ) ) { |
|
206 | - |
|
207 | - if ( is_array( $args ) ) { |
|
208 | - foreach ( $args as $key => $val ) { |
|
209 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
210 | - } |
|
211 | - } else { |
|
212 | - $output .= ' ' . $args . ' '; |
|
213 | - } |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - return $output; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param $args |
|
222 | - * |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function help_text( $text ) { |
|
226 | - $output = ''; |
|
227 | - |
|
228 | - if ( $text ) { |
|
229 | - $output .= '<small class="form-text text-muted">' . wp_kses_post( $text ) . '</small>'; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - return $output; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Replace element require context with JS. |
|
238 | - * |
|
239 | - * @param $input |
|
240 | - * |
|
241 | - * @return string|void |
|
242 | - */ |
|
243 | - public static function element_require( $input ) { |
|
244 | - |
|
245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
246 | - |
|
247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
248 | - "jQuery(form).find('[data-argument=\"", |
|
249 | - "\"]').find('input,select,textarea').val()", |
|
250 | - "\"]').find('input:checked').val()", |
|
251 | - ), $input ) ); |
|
252 | - |
|
253 | - if ( $output ) { |
|
254 | - $output = ' data-element-require="' . $output . '" '; |
|
255 | - } |
|
256 | - |
|
257 | - return $output; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
262 | - * |
|
263 | - * @since 0.1.41 |
|
264 | - * |
|
265 | - * @param mixed $value The value to be stripped. |
|
266 | - * @param array $input Input Field. |
|
267 | - * |
|
268 | - * @return mixed Stripped value. |
|
269 | - */ |
|
270 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
271 | - $original = $value; |
|
272 | - |
|
273 | - if ( is_array( $value ) ) { |
|
274 | - foreach ( $value as $index => $item ) { |
|
275 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
276 | - } |
|
277 | - } elseif ( is_object( $value ) ) { |
|
278 | - $object_vars = get_object_vars( $value ); |
|
279 | - |
|
280 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
281 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
282 | - } |
|
283 | - } else { |
|
284 | - $value = self::_sanitize_html_field( $value, $input ); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Filters content and keeps only allowable HTML elements. |
|
289 | - * |
|
290 | - * @since 0.1.41 |
|
291 | - * |
|
292 | - * @param string|array $value Content to filter through kses. |
|
293 | - * @param string|array $value Original content without filter. |
|
294 | - * @param array $input Input Field. |
|
295 | - */ |
|
296 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Filters content and keeps only allowable HTML elements. |
|
301 | - * |
|
302 | - * This function makes sure that only the allowed HTML element names, attribute |
|
303 | - * names and attribute values plus only sane HTML entities will occur in |
|
304 | - * $string. You have to remove any slashes from PHP's magic quotes before you |
|
305 | - * call this function. |
|
306 | - * |
|
307 | - * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
308 | - * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
309 | - * covers all common link protocols, except for 'javascript' which should not |
|
310 | - * be allowed for untrusted users. |
|
311 | - * |
|
312 | - * @since 0.1.41 |
|
313 | - * |
|
314 | - * @param string|array $value Content to filter through kses. |
|
315 | - * @param array $input Input Field. |
|
316 | - * |
|
317 | - * @return string Filtered content with only allowed HTML elements. |
|
318 | - */ |
|
319 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | - if ( $value === '' ) { |
|
321 | - return $value; |
|
322 | - } |
|
323 | - |
|
324 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
325 | - |
|
326 | - if ( ! is_array( $allowed_html ) ) { |
|
327 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
328 | - } |
|
329 | - |
|
330 | - $filtered = trim( wp_unslash( $value ) ); |
|
331 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
332 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
333 | - |
|
334 | - return $filtered; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Returns an array of allowed HTML tags and attributes for a given context. |
|
339 | - * |
|
340 | - * @since 0.1.41 |
|
341 | - * |
|
342 | - * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
343 | - * 'strip', 'data', 'entities', or the name of a field filter such as |
|
344 | - * 'pre_user_description'. |
|
345 | - * @param array $input Input. |
|
346 | - * |
|
347 | - * @return array Array of allowed HTML tags and their allowed attributes. |
|
348 | - */ |
|
349 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
350 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
351 | - |
|
352 | - if ( is_array( $allowed_html ) ) { |
|
353 | - // <iframe> |
|
354 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
355 | - $allowed_html['iframe'] = array( |
|
356 | - 'class' => true, |
|
357 | - 'id' => true, |
|
358 | - 'src' => true, |
|
359 | - 'width' => true, |
|
360 | - 'height' => true, |
|
361 | - 'frameborder' => true, |
|
362 | - 'marginwidth' => true, |
|
363 | - 'marginheight' => true, |
|
364 | - 'scrolling' => true, |
|
365 | - 'style' => true, |
|
366 | - 'title' => true, |
|
367 | - 'allow' => true, |
|
368 | - 'allowfullscreen' => true, |
|
369 | - 'data-*' => true, |
|
370 | - ); |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Filters the allowed html tags. |
|
376 | - * |
|
377 | - * @since 0.1.41 |
|
378 | - * |
|
379 | - * @param array[]|string $allowed_html Allowed html tags. |
|
380 | - * @param @param string|array $context The context for which to retrieve tags. |
|
381 | - * @param array $input Input field. |
|
382 | - */ |
|
383 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
384 | - } |
|
385 | - |
|
386 | - public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
387 | - |
|
388 | - $class = ''; |
|
389 | - |
|
390 | - // set default if empty |
|
391 | - if( $label_number === '' ){ |
|
392 | - $label_number = 2; |
|
393 | - } |
|
394 | - |
|
395 | - if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
396 | - if ( $type == 'label' ) { |
|
397 | - $class = 'col-sm-' . absint( $label_number ); |
|
398 | - } elseif ( $type == 'input' ) { |
|
399 | - $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - return $class; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Sanitizes a multiline string from user input or from the database. |
|
408 | - * |
|
409 | - * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way. |
|
410 | - * |
|
411 | - * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original |
|
412 | - * |
|
413 | - * @since 0.1.66 |
|
414 | - * |
|
415 | - * @param string $str String to sanitize. |
|
416 | - * @return string Sanitized string. |
|
417 | - */ |
|
418 | - public static function sanitize_textarea_field( $str ) { |
|
419 | - $filtered = self::_sanitize_text_fields( $str, true ); |
|
420 | - |
|
421 | - /** |
|
422 | - * Filters a sanitized textarea field string. |
|
423 | - * |
|
424 | - * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php |
|
425 | - * |
|
426 | - * @param string $filtered The sanitized string. |
|
427 | - * @param string $str The string prior to being sanitized. |
|
428 | - */ |
|
429 | - return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Internal helper function to sanitize a string from user input or from the db. |
|
434 | - * |
|
435 | - * @since 0.1.66 |
|
436 | - * @access private |
|
437 | - * |
|
438 | - * @param string $str String to sanitize. |
|
439 | - * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false. |
|
440 | - * @return string Sanitized string. |
|
441 | - */ |
|
442 | - public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
443 | - if ( is_object( $str ) || is_array( $str ) ) { |
|
444 | - return ''; |
|
445 | - } |
|
446 | - |
|
447 | - $str = (string) $str; |
|
448 | - |
|
449 | - $filtered = wp_check_invalid_utf8( $str ); |
|
450 | - |
|
451 | - if ( strpos( $filtered, '<' ) !== false ) { |
|
452 | - $filtered = wp_pre_kses_less_than( $filtered ); |
|
453 | - // This will strip extra whitespace for us. |
|
454 | - $filtered = wp_strip_all_tags( $filtered, false ); |
|
455 | - |
|
456 | - // Use HTML entities in a special case to make sure no later |
|
457 | - // newline stripping stage could lead to a functional tag. |
|
458 | - $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
459 | - } |
|
460 | - |
|
461 | - if ( ! $keep_newlines ) { |
|
462 | - $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
463 | - } |
|
464 | - $filtered = trim( $filtered ); |
|
465 | - |
|
466 | - $found = false; |
|
467 | - while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
468 | - $filtered = str_replace( $match[1], '', $filtered ); |
|
469 | - $found = true; |
|
470 | - } |
|
471 | - unset( $match ); |
|
472 | - |
|
473 | - if ( $found ) { |
|
474 | - // Strip out the whitespace that may now exist after removing the octets. |
|
475 | - $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
476 | - } |
|
477 | - |
|
478 | - return $filtered; |
|
479 | - } |
|
14 | + /** |
|
15 | + * A component helper for generating a input name. |
|
16 | + * |
|
17 | + * @param $text |
|
18 | + * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public static function name( $text, $multiple = false ) { |
|
23 | + $output = ''; |
|
24 | + |
|
25 | + if ( $text ) { |
|
26 | + $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | + $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
28 | + } |
|
29 | + |
|
30 | + return $output; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * A component helper for generating a item id. |
|
35 | + * |
|
36 | + * @param $text string The text to be used as the value. |
|
37 | + * |
|
38 | + * @return string The sanitized item. |
|
39 | + */ |
|
40 | + public static function id( $text ) { |
|
41 | + $output = ''; |
|
42 | + |
|
43 | + if ( $text ) { |
|
44 | + $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
45 | + } |
|
46 | + |
|
47 | + return $output; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * A component helper for generating a item title. |
|
52 | + * |
|
53 | + * @param $text string The text to be used as the value. |
|
54 | + * |
|
55 | + * @return string The sanitized item. |
|
56 | + */ |
|
57 | + public static function title( $text ) { |
|
58 | + $output = ''; |
|
59 | + |
|
60 | + if ( $text ) { |
|
61 | + $output = ' title="' . esc_attr( $text ) . '" '; |
|
62 | + } |
|
63 | + |
|
64 | + return $output; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * A component helper for generating a item value. |
|
69 | + * |
|
70 | + * @param $text string The text to be used as the value. |
|
71 | + * |
|
72 | + * @return string The sanitized item. |
|
73 | + */ |
|
74 | + public static function value( $text ) { |
|
75 | + $output = ''; |
|
76 | + |
|
77 | + if ( $text !== null && $text !== false ) { |
|
78 | + $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | + } |
|
80 | + |
|
81 | + return $output; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * A component helper for generating a item class attribute. |
|
86 | + * |
|
87 | + * @param $text string The text to be used as the value. |
|
88 | + * |
|
89 | + * @return string The sanitized item. |
|
90 | + */ |
|
91 | + public static function class_attr( $text ) { |
|
92 | + $output = ''; |
|
93 | + |
|
94 | + if ( $text ) { |
|
95 | + $classes = self::esc_classes( $text ); |
|
96 | + if ( ! empty( $classes ) ) { |
|
97 | + $output = ' class="' . $classes . '" '; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + return $output; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Escape a string of classes. |
|
106 | + * |
|
107 | + * @param $text |
|
108 | + * |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public static function esc_classes( $text ) { |
|
112 | + $output = ''; |
|
113 | + |
|
114 | + if ( $text ) { |
|
115 | + $classes = explode( " ", $text ); |
|
116 | + $classes = array_map( "trim", $classes ); |
|
117 | + $classes = array_map( "sanitize_html_class", $classes ); |
|
118 | + if ( ! empty( $classes ) ) { |
|
119 | + $output = implode( " ", $classes ); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + return $output; |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param $args |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public static function data_attributes( $args ) { |
|
133 | + $output = ''; |
|
134 | + |
|
135 | + if ( ! empty( $args ) ) { |
|
136 | + |
|
137 | + foreach ( $args as $key => $val ) { |
|
138 | + if ( substr( $key, 0, 5 ) === "data-" ) { |
|
139 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + return $output; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param $args |
|
149 | + * |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public static function aria_attributes( $args ) { |
|
153 | + $output = ''; |
|
154 | + |
|
155 | + if ( ! empty( $args ) ) { |
|
156 | + |
|
157 | + foreach ( $args as $key => $val ) { |
|
158 | + if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
159 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $output; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Build a font awesome icon from a class. |
|
169 | + * |
|
170 | + * @param $class |
|
171 | + * @param bool $space_after |
|
172 | + * @param array $extra_attributes An array of extra attributes. |
|
173 | + * |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
177 | + $output = ''; |
|
178 | + |
|
179 | + if ( $class ) { |
|
180 | + $classes = self::esc_classes( $class ); |
|
181 | + if ( ! empty( $classes ) ) { |
|
182 | + $output = '<i class="' . $classes . '" '; |
|
183 | + // extra attributes |
|
184 | + if ( ! empty( $extra_attributes ) ) { |
|
185 | + $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
186 | + } |
|
187 | + $output .= '></i>'; |
|
188 | + if ( $space_after ) { |
|
189 | + $output .= " "; |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return $output; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $args |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function extra_attributes( $args ) { |
|
203 | + $output = ''; |
|
204 | + |
|
205 | + if ( ! empty( $args ) ) { |
|
206 | + |
|
207 | + if ( is_array( $args ) ) { |
|
208 | + foreach ( $args as $key => $val ) { |
|
209 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
210 | + } |
|
211 | + } else { |
|
212 | + $output .= ' ' . $args . ' '; |
|
213 | + } |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + return $output; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param $args |
|
222 | + * |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function help_text( $text ) { |
|
226 | + $output = ''; |
|
227 | + |
|
228 | + if ( $text ) { |
|
229 | + $output .= '<small class="form-text text-muted">' . wp_kses_post( $text ) . '</small>'; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + return $output; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Replace element require context with JS. |
|
238 | + * |
|
239 | + * @param $input |
|
240 | + * |
|
241 | + * @return string|void |
|
242 | + */ |
|
243 | + public static function element_require( $input ) { |
|
244 | + |
|
245 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
246 | + |
|
247 | + $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
248 | + "jQuery(form).find('[data-argument=\"", |
|
249 | + "\"]').find('input,select,textarea').val()", |
|
250 | + "\"]').find('input:checked').val()", |
|
251 | + ), $input ) ); |
|
252 | + |
|
253 | + if ( $output ) { |
|
254 | + $output = ' data-element-require="' . $output . '" '; |
|
255 | + } |
|
256 | + |
|
257 | + return $output; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
262 | + * |
|
263 | + * @since 0.1.41 |
|
264 | + * |
|
265 | + * @param mixed $value The value to be stripped. |
|
266 | + * @param array $input Input Field. |
|
267 | + * |
|
268 | + * @return mixed Stripped value. |
|
269 | + */ |
|
270 | + public static function sanitize_html_field( $value, $input = array() ) { |
|
271 | + $original = $value; |
|
272 | + |
|
273 | + if ( is_array( $value ) ) { |
|
274 | + foreach ( $value as $index => $item ) { |
|
275 | + $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
276 | + } |
|
277 | + } elseif ( is_object( $value ) ) { |
|
278 | + $object_vars = get_object_vars( $value ); |
|
279 | + |
|
280 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
281 | + $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
282 | + } |
|
283 | + } else { |
|
284 | + $value = self::_sanitize_html_field( $value, $input ); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Filters content and keeps only allowable HTML elements. |
|
289 | + * |
|
290 | + * @since 0.1.41 |
|
291 | + * |
|
292 | + * @param string|array $value Content to filter through kses. |
|
293 | + * @param string|array $value Original content without filter. |
|
294 | + * @param array $input Input Field. |
|
295 | + */ |
|
296 | + return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Filters content and keeps only allowable HTML elements. |
|
301 | + * |
|
302 | + * This function makes sure that only the allowed HTML element names, attribute |
|
303 | + * names and attribute values plus only sane HTML entities will occur in |
|
304 | + * $string. You have to remove any slashes from PHP's magic quotes before you |
|
305 | + * call this function. |
|
306 | + * |
|
307 | + * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
308 | + * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
309 | + * covers all common link protocols, except for 'javascript' which should not |
|
310 | + * be allowed for untrusted users. |
|
311 | + * |
|
312 | + * @since 0.1.41 |
|
313 | + * |
|
314 | + * @param string|array $value Content to filter through kses. |
|
315 | + * @param array $input Input Field. |
|
316 | + * |
|
317 | + * @return string Filtered content with only allowed HTML elements. |
|
318 | + */ |
|
319 | + public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | + if ( $value === '' ) { |
|
321 | + return $value; |
|
322 | + } |
|
323 | + |
|
324 | + $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
325 | + |
|
326 | + if ( ! is_array( $allowed_html ) ) { |
|
327 | + $allowed_html = wp_kses_allowed_html( 'post' ); |
|
328 | + } |
|
329 | + |
|
330 | + $filtered = trim( wp_unslash( $value ) ); |
|
331 | + $filtered = wp_kses( $filtered, $allowed_html ); |
|
332 | + $filtered = balanceTags( $filtered ); // Balances tags |
|
333 | + |
|
334 | + return $filtered; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Returns an array of allowed HTML tags and attributes for a given context. |
|
339 | + * |
|
340 | + * @since 0.1.41 |
|
341 | + * |
|
342 | + * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
343 | + * 'strip', 'data', 'entities', or the name of a field filter such as |
|
344 | + * 'pre_user_description'. |
|
345 | + * @param array $input Input. |
|
346 | + * |
|
347 | + * @return array Array of allowed HTML tags and their allowed attributes. |
|
348 | + */ |
|
349 | + public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
350 | + $allowed_html = wp_kses_allowed_html( $context ); |
|
351 | + |
|
352 | + if ( is_array( $allowed_html ) ) { |
|
353 | + // <iframe> |
|
354 | + if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
355 | + $allowed_html['iframe'] = array( |
|
356 | + 'class' => true, |
|
357 | + 'id' => true, |
|
358 | + 'src' => true, |
|
359 | + 'width' => true, |
|
360 | + 'height' => true, |
|
361 | + 'frameborder' => true, |
|
362 | + 'marginwidth' => true, |
|
363 | + 'marginheight' => true, |
|
364 | + 'scrolling' => true, |
|
365 | + 'style' => true, |
|
366 | + 'title' => true, |
|
367 | + 'allow' => true, |
|
368 | + 'allowfullscreen' => true, |
|
369 | + 'data-*' => true, |
|
370 | + ); |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Filters the allowed html tags. |
|
376 | + * |
|
377 | + * @since 0.1.41 |
|
378 | + * |
|
379 | + * @param array[]|string $allowed_html Allowed html tags. |
|
380 | + * @param @param string|array $context The context for which to retrieve tags. |
|
381 | + * @param array $input Input field. |
|
382 | + */ |
|
383 | + return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
384 | + } |
|
385 | + |
|
386 | + public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
387 | + |
|
388 | + $class = ''; |
|
389 | + |
|
390 | + // set default if empty |
|
391 | + if( $label_number === '' ){ |
|
392 | + $label_number = 2; |
|
393 | + } |
|
394 | + |
|
395 | + if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
396 | + if ( $type == 'label' ) { |
|
397 | + $class = 'col-sm-' . absint( $label_number ); |
|
398 | + } elseif ( $type == 'input' ) { |
|
399 | + $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + return $class; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Sanitizes a multiline string from user input or from the database. |
|
408 | + * |
|
409 | + * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way. |
|
410 | + * |
|
411 | + * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original |
|
412 | + * |
|
413 | + * @since 0.1.66 |
|
414 | + * |
|
415 | + * @param string $str String to sanitize. |
|
416 | + * @return string Sanitized string. |
|
417 | + */ |
|
418 | + public static function sanitize_textarea_field( $str ) { |
|
419 | + $filtered = self::_sanitize_text_fields( $str, true ); |
|
420 | + |
|
421 | + /** |
|
422 | + * Filters a sanitized textarea field string. |
|
423 | + * |
|
424 | + * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php |
|
425 | + * |
|
426 | + * @param string $filtered The sanitized string. |
|
427 | + * @param string $str The string prior to being sanitized. |
|
428 | + */ |
|
429 | + return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Internal helper function to sanitize a string from user input or from the db. |
|
434 | + * |
|
435 | + * @since 0.1.66 |
|
436 | + * @access private |
|
437 | + * |
|
438 | + * @param string $str String to sanitize. |
|
439 | + * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false. |
|
440 | + * @return string Sanitized string. |
|
441 | + */ |
|
442 | + public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
443 | + if ( is_object( $str ) || is_array( $str ) ) { |
|
444 | + return ''; |
|
445 | + } |
|
446 | + |
|
447 | + $str = (string) $str; |
|
448 | + |
|
449 | + $filtered = wp_check_invalid_utf8( $str ); |
|
450 | + |
|
451 | + if ( strpos( $filtered, '<' ) !== false ) { |
|
452 | + $filtered = wp_pre_kses_less_than( $filtered ); |
|
453 | + // This will strip extra whitespace for us. |
|
454 | + $filtered = wp_strip_all_tags( $filtered, false ); |
|
455 | + |
|
456 | + // Use HTML entities in a special case to make sure no later |
|
457 | + // newline stripping stage could lead to a functional tag. |
|
458 | + $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
459 | + } |
|
460 | + |
|
461 | + if ( ! $keep_newlines ) { |
|
462 | + $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
463 | + } |
|
464 | + $filtered = trim( $filtered ); |
|
465 | + |
|
466 | + $found = false; |
|
467 | + while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
468 | + $filtered = str_replace( $match[1], '', $filtered ); |
|
469 | + $found = true; |
|
470 | + } |
|
471 | + unset( $match ); |
|
472 | + |
|
473 | + if ( $found ) { |
|
474 | + // Strip out the whitespace that may now exist after removing the octets. |
|
475 | + $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
476 | + } |
|
477 | + |
|
478 | + return $filtered; |
|
479 | + } |
|
480 | 480 | } |
481 | 481 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return string |
21 | 21 | */ |
22 | - public static function name( $text, $multiple = false ) { |
|
22 | + public static function name($text, $multiple = false) { |
|
23 | 23 | $output = ''; |
24 | 24 | |
25 | - if ( $text ) { |
|
26 | - $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | - $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
25 | + if ($text) { |
|
26 | + $is_multiple = strpos($text, '[') === false && $multiple ? '[]' : ''; |
|
27 | + $output = ' name="' . esc_attr($text) . $is_multiple . '" '; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | return $output; |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return string The sanitized item. |
39 | 39 | */ |
40 | - public static function id( $text ) { |
|
40 | + public static function id($text) { |
|
41 | 41 | $output = ''; |
42 | 42 | |
43 | - if ( $text ) { |
|
44 | - $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
43 | + if ($text) { |
|
44 | + $output = ' id="' . sanitize_html_class($text) . '" '; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | return $output; |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return string The sanitized item. |
56 | 56 | */ |
57 | - public static function title( $text ) { |
|
57 | + public static function title($text) { |
|
58 | 58 | $output = ''; |
59 | 59 | |
60 | - if ( $text ) { |
|
61 | - $output = ' title="' . esc_attr( $text ) . '" '; |
|
60 | + if ($text) { |
|
61 | + $output = ' title="' . esc_attr($text) . '" '; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return $output; |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string The sanitized item. |
73 | 73 | */ |
74 | - public static function value( $text ) { |
|
74 | + public static function value($text) { |
|
75 | 75 | $output = ''; |
76 | 76 | |
77 | - if ( $text !== null && $text !== false ) { |
|
78 | - $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
77 | + if ($text !== null && $text !== false) { |
|
78 | + $output = ' value="' . esc_attr(wp_unslash($text)) . '" '; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return $output; |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string The sanitized item. |
90 | 90 | */ |
91 | - public static function class_attr( $text ) { |
|
91 | + public static function class_attr($text) { |
|
92 | 92 | $output = ''; |
93 | 93 | |
94 | - if ( $text ) { |
|
95 | - $classes = self::esc_classes( $text ); |
|
96 | - if ( ! empty( $classes ) ) { |
|
94 | + if ($text) { |
|
95 | + $classes = self::esc_classes($text); |
|
96 | + if (!empty($classes)) { |
|
97 | 97 | $output = ' class="' . $classes . '" '; |
98 | 98 | } |
99 | 99 | } |
@@ -108,15 +108,15 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - public static function esc_classes( $text ) { |
|
111 | + public static function esc_classes($text) { |
|
112 | 112 | $output = ''; |
113 | 113 | |
114 | - if ( $text ) { |
|
115 | - $classes = explode( " ", $text ); |
|
116 | - $classes = array_map( "trim", $classes ); |
|
117 | - $classes = array_map( "sanitize_html_class", $classes ); |
|
118 | - if ( ! empty( $classes ) ) { |
|
119 | - $output = implode( " ", $classes ); |
|
114 | + if ($text) { |
|
115 | + $classes = explode(" ", $text); |
|
116 | + $classes = array_map("trim", $classes); |
|
117 | + $classes = array_map("sanitize_html_class", $classes); |
|
118 | + if (!empty($classes)) { |
|
119 | + $output = implode(" ", $classes); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function data_attributes( $args ) { |
|
132 | + public static function data_attributes($args) { |
|
133 | 133 | $output = ''; |
134 | 134 | |
135 | - if ( ! empty( $args ) ) { |
|
135 | + if (!empty($args)) { |
|
136 | 136 | |
137 | - foreach ( $args as $key => $val ) { |
|
138 | - if ( substr( $key, 0, 5 ) === "data-" ) { |
|
139 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
137 | + foreach ($args as $key => $val) { |
|
138 | + if (substr($key, 0, 5) === "data-") { |
|
139 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | } |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return string |
151 | 151 | */ |
152 | - public static function aria_attributes( $args ) { |
|
152 | + public static function aria_attributes($args) { |
|
153 | 153 | $output = ''; |
154 | 154 | |
155 | - if ( ! empty( $args ) ) { |
|
155 | + if (!empty($args)) { |
|
156 | 156 | |
157 | - foreach ( $args as $key => $val ) { |
|
158 | - if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
159 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
157 | + foreach ($args as $key => $val) { |
|
158 | + if (substr($key, 0, 5) === "aria-") { |
|
159 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -173,19 +173,19 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return string |
175 | 175 | */ |
176 | - public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
176 | + public static function icon($class, $space_after = false, $extra_attributes = array()) { |
|
177 | 177 | $output = ''; |
178 | 178 | |
179 | - if ( $class ) { |
|
180 | - $classes = self::esc_classes( $class ); |
|
181 | - if ( ! empty( $classes ) ) { |
|
179 | + if ($class) { |
|
180 | + $classes = self::esc_classes($class); |
|
181 | + if (!empty($classes)) { |
|
182 | 182 | $output = '<i class="' . $classes . '" '; |
183 | 183 | // extra attributes |
184 | - if ( ! empty( $extra_attributes ) ) { |
|
185 | - $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
184 | + if (!empty($extra_attributes)) { |
|
185 | + $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
186 | 186 | } |
187 | 187 | $output .= '></i>'; |
188 | - if ( $space_after ) { |
|
188 | + if ($space_after) { |
|
189 | 189 | $output .= " "; |
190 | 190 | } |
191 | 191 | } |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public static function extra_attributes( $args ) { |
|
202 | + public static function extra_attributes($args) { |
|
203 | 203 | $output = ''; |
204 | 204 | |
205 | - if ( ! empty( $args ) ) { |
|
205 | + if (!empty($args)) { |
|
206 | 206 | |
207 | - if ( is_array( $args ) ) { |
|
208 | - foreach ( $args as $key => $val ) { |
|
209 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
207 | + if (is_array($args)) { |
|
208 | + foreach ($args as $key => $val) { |
|
209 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
210 | 210 | } |
211 | 211 | } else { |
212 | 212 | $output .= ' ' . $args . ' '; |
@@ -222,11 +222,11 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return string |
224 | 224 | */ |
225 | - public static function help_text( $text ) { |
|
225 | + public static function help_text($text) { |
|
226 | 226 | $output = ''; |
227 | 227 | |
228 | - if ( $text ) { |
|
229 | - $output .= '<small class="form-text text-muted">' . wp_kses_post( $text ) . '</small>'; |
|
228 | + if ($text) { |
|
229 | + $output .= '<small class="form-text text-muted">' . wp_kses_post($text) . '</small>'; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | |
@@ -240,17 +240,17 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @return string|void |
242 | 242 | */ |
243 | - public static function element_require( $input ) { |
|
243 | + public static function element_require($input) { |
|
244 | 244 | |
245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
245 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
246 | 246 | |
247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
247 | + $output = esc_attr(str_replace(array("[%", "%]", "%:checked]"), array( |
|
248 | 248 | "jQuery(form).find('[data-argument=\"", |
249 | 249 | "\"]').find('input,select,textarea').val()", |
250 | 250 | "\"]').find('input:checked').val()", |
251 | - ), $input ) ); |
|
251 | + ), $input)); |
|
252 | 252 | |
253 | - if ( $output ) { |
|
253 | + if ($output) { |
|
254 | 254 | $output = ' data-element-require="' . $output . '" '; |
255 | 255 | } |
256 | 256 | |
@@ -267,21 +267,21 @@ discard block |
||
267 | 267 | * |
268 | 268 | * @return mixed Stripped value. |
269 | 269 | */ |
270 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
270 | + public static function sanitize_html_field($value, $input = array()) { |
|
271 | 271 | $original = $value; |
272 | 272 | |
273 | - if ( is_array( $value ) ) { |
|
274 | - foreach ( $value as $index => $item ) { |
|
275 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
273 | + if (is_array($value)) { |
|
274 | + foreach ($value as $index => $item) { |
|
275 | + $value[$index] = self::_sanitize_html_field($value, $input); |
|
276 | 276 | } |
277 | - } elseif ( is_object( $value ) ) { |
|
278 | - $object_vars = get_object_vars( $value ); |
|
277 | + } elseif (is_object($value)) { |
|
278 | + $object_vars = get_object_vars($value); |
|
279 | 279 | |
280 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
281 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
280 | + foreach ($object_vars as $property_name => $property_value) { |
|
281 | + $value->$property_name = self::_sanitize_html_field($property_value, $input); |
|
282 | 282 | } |
283 | 283 | } else { |
284 | - $value = self::_sanitize_html_field( $value, $input ); |
|
284 | + $value = self::_sanitize_html_field($value, $input); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @param string|array $value Original content without filter. |
294 | 294 | * @param array $input Input Field. |
295 | 295 | */ |
296 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
296 | + return apply_filters('ayecode_ui_sanitize_html_field', $value, $original, $input); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -316,20 +316,20 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @return string Filtered content with only allowed HTML elements. |
318 | 318 | */ |
319 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | - if ( $value === '' ) { |
|
319 | + public static function _sanitize_html_field($value, $input = array()) { |
|
320 | + if ($value === '') { |
|
321 | 321 | return $value; |
322 | 322 | } |
323 | 323 | |
324 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
324 | + $allowed_html = self::kses_allowed_html('post', $input); |
|
325 | 325 | |
326 | - if ( ! is_array( $allowed_html ) ) { |
|
327 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
326 | + if (!is_array($allowed_html)) { |
|
327 | + $allowed_html = wp_kses_allowed_html('post'); |
|
328 | 328 | } |
329 | 329 | |
330 | - $filtered = trim( wp_unslash( $value ) ); |
|
331 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
332 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
330 | + $filtered = trim(wp_unslash($value)); |
|
331 | + $filtered = wp_kses($filtered, $allowed_html); |
|
332 | + $filtered = balanceTags($filtered); // Balances tags |
|
333 | 333 | |
334 | 334 | return $filtered; |
335 | 335 | } |
@@ -346,12 +346,12 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @return array Array of allowed HTML tags and their allowed attributes. |
348 | 348 | */ |
349 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
350 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
349 | + public static function kses_allowed_html($context = 'post', $input = array()) { |
|
350 | + $allowed_html = wp_kses_allowed_html($context); |
|
351 | 351 | |
352 | - if ( is_array( $allowed_html ) ) { |
|
352 | + if (is_array($allowed_html)) { |
|
353 | 353 | // <iframe> |
354 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
354 | + if (!isset($allowed_html['iframe']) && $context == 'post') { |
|
355 | 355 | $allowed_html['iframe'] = array( |
356 | 356 | 'class' => true, |
357 | 357 | 'id' => true, |
@@ -380,23 +380,23 @@ discard block |
||
380 | 380 | * @param @param string|array $context The context for which to retrieve tags. |
381 | 381 | * @param array $input Input field. |
382 | 382 | */ |
383 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
383 | + return apply_filters('ayecode_ui_kses_allowed_html', $allowed_html, $context, $input); |
|
384 | 384 | } |
385 | 385 | |
386 | - public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
386 | + public static function get_column_class($label_number = 2, $type = 'label') { |
|
387 | 387 | |
388 | 388 | $class = ''; |
389 | 389 | |
390 | 390 | // set default if empty |
391 | - if( $label_number === '' ){ |
|
391 | + if ($label_number === '') { |
|
392 | 392 | $label_number = 2; |
393 | 393 | } |
394 | 394 | |
395 | - if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
396 | - if ( $type == 'label' ) { |
|
397 | - $class = 'col-sm-' . absint( $label_number ); |
|
398 | - } elseif ( $type == 'input' ) { |
|
399 | - $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
395 | + if ($label_number && $label_number < 12 && $label_number > 0) { |
|
396 | + if ($type == 'label') { |
|
397 | + $class = 'col-sm-' . absint($label_number); |
|
398 | + } elseif ($type == 'input') { |
|
399 | + $class = 'col-sm-' . (12 - absint($label_number)); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | * @param string $str String to sanitize. |
416 | 416 | * @return string Sanitized string. |
417 | 417 | */ |
418 | - public static function sanitize_textarea_field( $str ) { |
|
419 | - $filtered = self::_sanitize_text_fields( $str, true ); |
|
418 | + public static function sanitize_textarea_field($str) { |
|
419 | + $filtered = self::_sanitize_text_fields($str, true); |
|
420 | 420 | |
421 | 421 | /** |
422 | 422 | * Filters a sanitized textarea field string. |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @param string $filtered The sanitized string. |
427 | 427 | * @param string $str The string prior to being sanitized. |
428 | 428 | */ |
429 | - return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
429 | + return apply_filters('sanitize_textarea_field', $filtered, $str); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -439,40 +439,40 @@ discard block |
||
439 | 439 | * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false. |
440 | 440 | * @return string Sanitized string. |
441 | 441 | */ |
442 | - public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
443 | - if ( is_object( $str ) || is_array( $str ) ) { |
|
442 | + public static function _sanitize_text_fields($str, $keep_newlines = false) { |
|
443 | + if (is_object($str) || is_array($str)) { |
|
444 | 444 | return ''; |
445 | 445 | } |
446 | 446 | |
447 | 447 | $str = (string) $str; |
448 | 448 | |
449 | - $filtered = wp_check_invalid_utf8( $str ); |
|
449 | + $filtered = wp_check_invalid_utf8($str); |
|
450 | 450 | |
451 | - if ( strpos( $filtered, '<' ) !== false ) { |
|
452 | - $filtered = wp_pre_kses_less_than( $filtered ); |
|
451 | + if (strpos($filtered, '<') !== false) { |
|
452 | + $filtered = wp_pre_kses_less_than($filtered); |
|
453 | 453 | // This will strip extra whitespace for us. |
454 | - $filtered = wp_strip_all_tags( $filtered, false ); |
|
454 | + $filtered = wp_strip_all_tags($filtered, false); |
|
455 | 455 | |
456 | 456 | // Use HTML entities in a special case to make sure no later |
457 | 457 | // newline stripping stage could lead to a functional tag. |
458 | - $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
458 | + $filtered = str_replace("<\n", "<\n", $filtered); |
|
459 | 459 | } |
460 | 460 | |
461 | - if ( ! $keep_newlines ) { |
|
462 | - $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
461 | + if (!$keep_newlines) { |
|
462 | + $filtered = preg_replace('/[\r\n\t ]+/', ' ', $filtered); |
|
463 | 463 | } |
464 | - $filtered = trim( $filtered ); |
|
464 | + $filtered = trim($filtered); |
|
465 | 465 | |
466 | 466 | $found = false; |
467 | - while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
468 | - $filtered = str_replace( $match[1], '', $filtered ); |
|
467 | + while (preg_match('`[^%](%[a-f0-9]{2})`i', $filtered, $match)) { |
|
468 | + $filtered = str_replace($match[1], '', $filtered); |
|
469 | 469 | $found = true; |
470 | 470 | } |
471 | - unset( $match ); |
|
471 | + unset($match); |
|
472 | 472 | |
473 | - if ( $found ) { |
|
473 | + if ($found) { |
|
474 | 474 | // Strip out the whitespace that may now exist after removing the octets. |
475 | - $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
475 | + $filtered = trim(preg_replace('` +`', ' ', $filtered)); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | return $filtered; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,300 +21,300 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | - * @since 1.0.13 RTL language support added. |
|
32 | - * @ver 1.0.13 |
|
33 | - * @todo decide how to implement textdomain |
|
34 | - */ |
|
35 | - class WP_Font_Awesome_Settings { |
|
36 | - |
|
37 | - /** |
|
38 | - * Class version version. |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - public $version = '1.0.13'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Class textdomain. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $textdomain = 'font-awesome-settings'; |
|
50 | - |
|
51 | - /** |
|
52 | - * Latest version of Font Awesome at time of publish published. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $latest = "5.8.2"; |
|
57 | - |
|
58 | - /** |
|
59 | - * The title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $name = 'Font Awesome'; |
|
64 | - |
|
65 | - /** |
|
66 | - * Holds the settings values. |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - private $settings; |
|
71 | - |
|
72 | - /** |
|
73 | - * WP_Font_Awesome_Settings instance. |
|
74 | - * |
|
75 | - * @access private |
|
76 | - * @since 1.0.0 |
|
77 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
78 | - */ |
|
79 | - private static $instance = null; |
|
80 | - |
|
81 | - /** |
|
82 | - * Main WP_Font_Awesome_Settings Instance. |
|
83 | - * |
|
84 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
85 | - * |
|
86 | - * @since 1.0.0 |
|
87 | - * @static |
|
88 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
89 | - */ |
|
90 | - public static function instance() { |
|
91 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
92 | - self::$instance = new WP_Font_Awesome_Settings; |
|
93 | - |
|
94 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
95 | - |
|
96 | - if ( is_admin() ) { |
|
97 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
99 | - } |
|
100 | - |
|
101 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
102 | - } |
|
103 | - |
|
104 | - return self::$instance; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Initiate the settings and add the required action hooks. |
|
109 | - * |
|
110 | - * @since 1.0.8 Settings name wrong - FIXED |
|
111 | - */ |
|
112 | - public function init() { |
|
113 | - $this->settings = $this->get_settings(); |
|
114 | - |
|
115 | - if ( $this->settings['type'] == 'CSS' ) { |
|
116 | - |
|
117 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
119 | - } |
|
120 | - |
|
121 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
123 | - } |
|
124 | - |
|
125 | - } else { |
|
126 | - |
|
127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
129 | - } |
|
130 | - |
|
131 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - // remove font awesome if set to do so |
|
137 | - if ( $this->settings['dequeue'] == '1' ) { |
|
138 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
139 | - } |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Adds the Font Awesome styles. |
|
145 | - */ |
|
146 | - public function enqueue_style() { |
|
147 | - // build url |
|
148 | - $url = $this->get_url(); |
|
149 | - |
|
150 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | - wp_enqueue_style( 'font-awesome' ); |
|
153 | - |
|
154 | - // RTL language support CSS. |
|
155 | - if ( is_rtl() ) { |
|
156 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
157 | - } |
|
158 | - |
|
159 | - if ( $this->settings['shims'] ) { |
|
160 | - $url = $this->get_url( true ); |
|
161 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Adds the Font Awesome JS. |
|
169 | - */ |
|
170 | - public function enqueue_scripts() { |
|
171 | - // build url |
|
172 | - $url = $this->get_url(); |
|
173 | - |
|
174 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
175 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome' ); |
|
178 | - |
|
179 | - if ( $this->settings['shims'] ) { |
|
180 | - $url = $this->get_url( true ); |
|
181 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Get the url of the Font Awesome files. |
|
189 | - * |
|
190 | - * @param bool $shims If this is a shim file or not. |
|
191 | - * |
|
192 | - * @return string The url to the file. |
|
193 | - */ |
|
194 | - public function get_url( $shims = false ) { |
|
195 | - $script = $shims ? 'v4-shims' : 'all'; |
|
196 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
197 | - $type = $this->settings['type']; |
|
198 | - $version = $this->settings['version']; |
|
199 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
200 | - $url = ''; |
|
201 | - |
|
202 | - if ( $type == 'KIT' && $kit_url ) { |
|
203 | - if ( $shims ) { |
|
204 | - // if its a kit then we don't add shims here |
|
205 | - return ''; |
|
206 | - } |
|
207 | - $url .= $kit_url; // CDN |
|
208 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | - } else { |
|
210 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
211 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
213 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
214 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
215 | - } |
|
216 | - |
|
217 | - return $url; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
222 | - * |
|
223 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
224 | - * |
|
225 | - * @param $url |
|
226 | - * @param $original_url |
|
227 | - * @param $_context |
|
228 | - * |
|
229 | - * @return string The filtered url. |
|
230 | - */ |
|
231 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
232 | - |
|
233 | - if ( $_context == 'display' |
|
234 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
236 | - ) {// it's a font-awesome-url (probably) |
|
237 | - |
|
238 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | - if ( $this->settings['type'] == 'JS' ) { |
|
240 | - if ( $this->settings['js-pseudo'] ) { |
|
241 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
242 | - } else { |
|
243 | - $url .= "' defer='defer"; |
|
244 | - } |
|
245 | - } |
|
246 | - } else { |
|
247 | - $url = ''; // removing the url removes the file |
|
248 | - } |
|
249 | - |
|
250 | - } |
|
251 | - |
|
252 | - return $url; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Register the database settings with WordPress. |
|
257 | - */ |
|
258 | - public function register_settings() { |
|
259 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Add the WordPress settings menu item. |
|
264 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
265 | - */ |
|
266 | - public function menu_item() { |
|
267 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
268 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | - $this, |
|
270 | - 'settings_page' |
|
271 | - ) ); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Get the current Font Awesome output settings. |
|
276 | - * |
|
277 | - * @return array The array of settings. |
|
278 | - */ |
|
279 | - public function get_settings() { |
|
280 | - |
|
281 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
282 | - |
|
283 | - $defaults = array( |
|
284 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
285 | - 'version' => '', // latest |
|
286 | - 'enqueue' => '', // front and backend |
|
287 | - 'shims' => '0', // default OFF now in 2020 |
|
288 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
289 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
290 | - 'pro' => '0', // if pro CDN url should be used |
|
291 | - 'kit-url' => '', // the kit url |
|
292 | - ); |
|
293 | - |
|
294 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
295 | - |
|
296 | - /** |
|
297 | - * Filter the Font Awesome settings. |
|
298 | - * |
|
299 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
300 | - */ |
|
301 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * The settings page html output. |
|
307 | - */ |
|
308 | - public function settings_page() { |
|
309 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
311 | - } |
|
312 | - |
|
313 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
314 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | - $this->get_latest_version( $force_api = true ); |
|
316 | - } |
|
317 | - ?> |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | + * @since 1.0.13 RTL language support added. |
|
32 | + * @ver 1.0.13 |
|
33 | + * @todo decide how to implement textdomain |
|
34 | + */ |
|
35 | + class WP_Font_Awesome_Settings { |
|
36 | + |
|
37 | + /** |
|
38 | + * Class version version. |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + public $version = '1.0.13'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Class textdomain. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $textdomain = 'font-awesome-settings'; |
|
50 | + |
|
51 | + /** |
|
52 | + * Latest version of Font Awesome at time of publish published. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $latest = "5.8.2"; |
|
57 | + |
|
58 | + /** |
|
59 | + * The title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $name = 'Font Awesome'; |
|
64 | + |
|
65 | + /** |
|
66 | + * Holds the settings values. |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + private $settings; |
|
71 | + |
|
72 | + /** |
|
73 | + * WP_Font_Awesome_Settings instance. |
|
74 | + * |
|
75 | + * @access private |
|
76 | + * @since 1.0.0 |
|
77 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
78 | + */ |
|
79 | + private static $instance = null; |
|
80 | + |
|
81 | + /** |
|
82 | + * Main WP_Font_Awesome_Settings Instance. |
|
83 | + * |
|
84 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
85 | + * |
|
86 | + * @since 1.0.0 |
|
87 | + * @static |
|
88 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
89 | + */ |
|
90 | + public static function instance() { |
|
91 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
92 | + self::$instance = new WP_Font_Awesome_Settings; |
|
93 | + |
|
94 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
95 | + |
|
96 | + if ( is_admin() ) { |
|
97 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
99 | + } |
|
100 | + |
|
101 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
102 | + } |
|
103 | + |
|
104 | + return self::$instance; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Initiate the settings and add the required action hooks. |
|
109 | + * |
|
110 | + * @since 1.0.8 Settings name wrong - FIXED |
|
111 | + */ |
|
112 | + public function init() { |
|
113 | + $this->settings = $this->get_settings(); |
|
114 | + |
|
115 | + if ( $this->settings['type'] == 'CSS' ) { |
|
116 | + |
|
117 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
119 | + } |
|
120 | + |
|
121 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
123 | + } |
|
124 | + |
|
125 | + } else { |
|
126 | + |
|
127 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
129 | + } |
|
130 | + |
|
131 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + // remove font awesome if set to do so |
|
137 | + if ( $this->settings['dequeue'] == '1' ) { |
|
138 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Adds the Font Awesome styles. |
|
145 | + */ |
|
146 | + public function enqueue_style() { |
|
147 | + // build url |
|
148 | + $url = $this->get_url(); |
|
149 | + |
|
150 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | + wp_enqueue_style( 'font-awesome' ); |
|
153 | + |
|
154 | + // RTL language support CSS. |
|
155 | + if ( is_rtl() ) { |
|
156 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
157 | + } |
|
158 | + |
|
159 | + if ( $this->settings['shims'] ) { |
|
160 | + $url = $this->get_url( true ); |
|
161 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Adds the Font Awesome JS. |
|
169 | + */ |
|
170 | + public function enqueue_scripts() { |
|
171 | + // build url |
|
172 | + $url = $this->get_url(); |
|
173 | + |
|
174 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
175 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | + wp_enqueue_script( 'font-awesome' ); |
|
178 | + |
|
179 | + if ( $this->settings['shims'] ) { |
|
180 | + $url = $this->get_url( true ); |
|
181 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Get the url of the Font Awesome files. |
|
189 | + * |
|
190 | + * @param bool $shims If this is a shim file or not. |
|
191 | + * |
|
192 | + * @return string The url to the file. |
|
193 | + */ |
|
194 | + public function get_url( $shims = false ) { |
|
195 | + $script = $shims ? 'v4-shims' : 'all'; |
|
196 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
197 | + $type = $this->settings['type']; |
|
198 | + $version = $this->settings['version']; |
|
199 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
200 | + $url = ''; |
|
201 | + |
|
202 | + if ( $type == 'KIT' && $kit_url ) { |
|
203 | + if ( $shims ) { |
|
204 | + // if its a kit then we don't add shims here |
|
205 | + return ''; |
|
206 | + } |
|
207 | + $url .= $kit_url; // CDN |
|
208 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | + } else { |
|
210 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
211 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
213 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
214 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
215 | + } |
|
216 | + |
|
217 | + return $url; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
222 | + * |
|
223 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
224 | + * |
|
225 | + * @param $url |
|
226 | + * @param $original_url |
|
227 | + * @param $_context |
|
228 | + * |
|
229 | + * @return string The filtered url. |
|
230 | + */ |
|
231 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
232 | + |
|
233 | + if ( $_context == 'display' |
|
234 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
236 | + ) {// it's a font-awesome-url (probably) |
|
237 | + |
|
238 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | + if ( $this->settings['type'] == 'JS' ) { |
|
240 | + if ( $this->settings['js-pseudo'] ) { |
|
241 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
242 | + } else { |
|
243 | + $url .= "' defer='defer"; |
|
244 | + } |
|
245 | + } |
|
246 | + } else { |
|
247 | + $url = ''; // removing the url removes the file |
|
248 | + } |
|
249 | + |
|
250 | + } |
|
251 | + |
|
252 | + return $url; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Register the database settings with WordPress. |
|
257 | + */ |
|
258 | + public function register_settings() { |
|
259 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Add the WordPress settings menu item. |
|
264 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
265 | + */ |
|
266 | + public function menu_item() { |
|
267 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
268 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | + $this, |
|
270 | + 'settings_page' |
|
271 | + ) ); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Get the current Font Awesome output settings. |
|
276 | + * |
|
277 | + * @return array The array of settings. |
|
278 | + */ |
|
279 | + public function get_settings() { |
|
280 | + |
|
281 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
282 | + |
|
283 | + $defaults = array( |
|
284 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
285 | + 'version' => '', // latest |
|
286 | + 'enqueue' => '', // front and backend |
|
287 | + 'shims' => '0', // default OFF now in 2020 |
|
288 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
289 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
290 | + 'pro' => '0', // if pro CDN url should be used |
|
291 | + 'kit-url' => '', // the kit url |
|
292 | + ); |
|
293 | + |
|
294 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
295 | + |
|
296 | + /** |
|
297 | + * Filter the Font Awesome settings. |
|
298 | + * |
|
299 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
300 | + */ |
|
301 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * The settings page html output. |
|
307 | + */ |
|
308 | + public function settings_page() { |
|
309 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
311 | + } |
|
312 | + |
|
313 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
314 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | + $this->get_latest_version( $force_api = true ); |
|
316 | + } |
|
317 | + ?> |
|
318 | 318 | <style> |
319 | 319 | .wpfas-kit-show { |
320 | 320 | display: none; |
@@ -332,10 +332,10 @@ discard block |
||
332 | 332 | <h1><?php echo esc_html( $this->name ); ?></h1> |
333 | 333 | <form method="post" action="options.php"> |
334 | 334 | <?php |
335 | - settings_fields( 'wp-font-awesome-settings' ); |
|
336 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
337 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
338 | - ?> |
|
335 | + settings_fields( 'wp-font-awesome-settings' ); |
|
336 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
337 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
338 | + ?> |
|
339 | 339 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
340 | 340 | <tr valign="top"> |
341 | 341 | <th scope="row"><label |
@@ -361,12 +361,12 @@ discard block |
||
361 | 361 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
362 | 362 | placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
363 | 363 | <span><?php |
364 | - echo sprintf( |
|
365 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
366 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
367 | - '</a>' |
|
368 | - ); |
|
369 | - ?></span> |
|
364 | + echo sprintf( |
|
365 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
366 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
367 | + '</a>' |
|
368 | + ); |
|
369 | + ?></span> |
|
370 | 370 | </td> |
371 | 371 | </tr> |
372 | 372 | |
@@ -426,14 +426,14 @@ discard block |
||
426 | 426 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
427 | 427 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
428 | 428 | <span><?php |
429 | - echo sprintf( |
|
430 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
431 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
432 | - '</a>', |
|
433 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
434 | - '</a>' |
|
435 | - ); |
|
436 | - ?></span> |
|
429 | + echo sprintf( |
|
430 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
431 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
432 | + '</a>', |
|
433 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
434 | + '</a>' |
|
435 | + ); |
|
436 | + ?></span> |
|
437 | 437 | </td> |
438 | 438 | </tr> |
439 | 439 | |
@@ -476,100 +476,100 @@ discard block |
||
476 | 476 | |
477 | 477 | </table> |
478 | 478 | <?php |
479 | - submit_button(); |
|
480 | - ?> |
|
479 | + submit_button(); |
|
480 | + ?> |
|
481 | 481 | </form> |
482 | 482 | |
483 | 483 | <div id="wpfas-version"><?php echo esc_html( $this->version ); ?></div> |
484 | 484 | </div> |
485 | 485 | |
486 | 486 | <?php |
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Check a version number is valid and if so return it or else return an empty string. |
|
491 | - * |
|
492 | - * @param $version string The version number to check. |
|
493 | - * |
|
494 | - * @since 1.0.6 |
|
495 | - * |
|
496 | - * @return string Either a valid version number or an empty string. |
|
497 | - */ |
|
498 | - public function validate_version_number( $version ) { |
|
499 | - |
|
500 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
501 | - // valid |
|
502 | - } else { |
|
503 | - $version = '';// not validated |
|
504 | - } |
|
505 | - |
|
506 | - return $version; |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * Get the latest version of Font Awesome. |
|
512 | - * |
|
513 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
514 | - * |
|
515 | - * @since 1.0.7 |
|
516 | - * @return mixed|string The latest version number found. |
|
517 | - */ |
|
518 | - public function get_latest_version( $force_api = false ) { |
|
519 | - $latest_version = $this->latest; |
|
520 | - |
|
521 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
522 | - |
|
523 | - if ( $cache === false || $force_api ) { // its not set |
|
524 | - $api_ver = $this->get_latest_version_from_api(); |
|
525 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
526 | - $latest_version = $api_ver; |
|
527 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
528 | - } |
|
529 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
531 | - $latest_version = $cache; |
|
532 | - } |
|
533 | - } |
|
534 | - |
|
535 | - return $latest_version; |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Get the latest Font Awesome version from the github API. |
|
540 | - * |
|
541 | - * @since 1.0.7 |
|
542 | - * @return string The latest version number or `0` on API fail. |
|
543 | - */ |
|
544 | - public function get_latest_version_from_api() { |
|
545 | - $version = "0"; |
|
546 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
550 | - $version = $api_response['tag_name']; |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - return $version; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Inline CSS for RTL language support. |
|
559 | - * |
|
560 | - * @since 1.0.13 |
|
561 | - * @return string Inline CSS. |
|
562 | - */ |
|
563 | - public function rtl_inline_css() { |
|
564 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
565 | - |
|
566 | - return $inline_css; |
|
567 | - } |
|
568 | - |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Run the class if found. |
|
573 | - */ |
|
574 | - WP_Font_Awesome_Settings::instance(); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Check a version number is valid and if so return it or else return an empty string. |
|
491 | + * |
|
492 | + * @param $version string The version number to check. |
|
493 | + * |
|
494 | + * @since 1.0.6 |
|
495 | + * |
|
496 | + * @return string Either a valid version number or an empty string. |
|
497 | + */ |
|
498 | + public function validate_version_number( $version ) { |
|
499 | + |
|
500 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
501 | + // valid |
|
502 | + } else { |
|
503 | + $version = '';// not validated |
|
504 | + } |
|
505 | + |
|
506 | + return $version; |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * Get the latest version of Font Awesome. |
|
512 | + * |
|
513 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
514 | + * |
|
515 | + * @since 1.0.7 |
|
516 | + * @return mixed|string The latest version number found. |
|
517 | + */ |
|
518 | + public function get_latest_version( $force_api = false ) { |
|
519 | + $latest_version = $this->latest; |
|
520 | + |
|
521 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
522 | + |
|
523 | + if ( $cache === false || $force_api ) { // its not set |
|
524 | + $api_ver = $this->get_latest_version_from_api(); |
|
525 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
526 | + $latest_version = $api_ver; |
|
527 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
528 | + } |
|
529 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
531 | + $latest_version = $cache; |
|
532 | + } |
|
533 | + } |
|
534 | + |
|
535 | + return $latest_version; |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Get the latest Font Awesome version from the github API. |
|
540 | + * |
|
541 | + * @since 1.0.7 |
|
542 | + * @return string The latest version number or `0` on API fail. |
|
543 | + */ |
|
544 | + public function get_latest_version_from_api() { |
|
545 | + $version = "0"; |
|
546 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
550 | + $version = $api_response['tag_name']; |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + return $version; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Inline CSS for RTL language support. |
|
559 | + * |
|
560 | + * @since 1.0.13 |
|
561 | + * @return string Inline CSS. |
|
562 | + */ |
|
563 | + public function rtl_inline_css() { |
|
564 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
565 | + |
|
566 | + return $inline_css; |
|
567 | + } |
|
568 | + |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Run the class if found. |
|
573 | + */ |
|
574 | + WP_Font_Awesome_Settings::instance(); |
|
575 | 575 | } |
576 | 576 | \ No newline at end of file |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Only add if the class does not already exist. |
21 | 21 | */ |
22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | * @return WP_Font_Awesome_Settings - Main instance. |
89 | 89 | */ |
90 | 90 | public static function instance() { |
91 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
91 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
92 | 92 | self::$instance = new WP_Font_Awesome_Settings; |
93 | 93 | |
94 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
94 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
95 | 95 | |
96 | - if ( is_admin() ) { |
|
97 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
96 | + if (is_admin()) { |
|
97 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
98 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
99 | 99 | } |
100 | 100 | |
101 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
101 | + do_action('wp_font_awesome_settings_loaded'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return self::$instance; |
@@ -112,30 +112,30 @@ discard block |
||
112 | 112 | public function init() { |
113 | 113 | $this->settings = $this->get_settings(); |
114 | 114 | |
115 | - if ( $this->settings['type'] == 'CSS' ) { |
|
115 | + if ($this->settings['type'] == 'CSS') { |
|
116 | 116 | |
117 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
117 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
118 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
121 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
122 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | } else { |
126 | 126 | |
127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
127 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
128 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
129 | 129 | } |
130 | 130 | |
131 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
131 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
132 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | // remove font awesome if set to do so |
137 | - if ( $this->settings['dequeue'] == '1' ) { |
|
138 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
137 | + if ($this->settings['dequeue'] == '1') { |
|
138 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -147,20 +147,20 @@ discard block |
||
147 | 147 | // build url |
148 | 148 | $url = $this->get_url(); |
149 | 149 | |
150 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | - wp_enqueue_style( 'font-awesome' ); |
|
150 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
151 | + wp_register_style('font-awesome', $url, array(), null); |
|
152 | + wp_enqueue_style('font-awesome'); |
|
153 | 153 | |
154 | 154 | // RTL language support CSS. |
155 | - if ( is_rtl() ) { |
|
156 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
155 | + if (is_rtl()) { |
|
156 | + wp_add_inline_style('font-awesome', $this->rtl_inline_css()); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( $this->settings['shims'] ) { |
|
160 | - $url = $this->get_url( true ); |
|
161 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
159 | + if ($this->settings['shims']) { |
|
160 | + $url = $this->get_url(true); |
|
161 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
162 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
163 | + wp_enqueue_style('font-awesome-shims'); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | $url = $this->get_url(); |
173 | 173 | |
174 | 174 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
175 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome' ); |
|
178 | - |
|
179 | - if ( $this->settings['shims'] ) { |
|
180 | - $url = $this->get_url( true ); |
|
181 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
175 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
176 | + wp_register_script('font-awesome', $url, array(), null); |
|
177 | + wp_enqueue_script('font-awesome'); |
|
178 | + |
|
179 | + if ($this->settings['shims']) { |
|
180 | + $url = $this->get_url(true); |
|
181 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
182 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
183 | + wp_enqueue_script('font-awesome-shims'); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return string The url to the file. |
193 | 193 | */ |
194 | - public function get_url( $shims = false ) { |
|
194 | + public function get_url($shims = false) { |
|
195 | 195 | $script = $shims ? 'v4-shims' : 'all'; |
196 | 196 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
197 | 197 | $type = $this->settings['type']; |
198 | 198 | $version = $this->settings['version']; |
199 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
199 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
200 | 200 | $url = ''; |
201 | 201 | |
202 | - if ( $type == 'KIT' && $kit_url ) { |
|
203 | - if ( $shims ) { |
|
202 | + if ($type == 'KIT' && $kit_url) { |
|
203 | + if ($shims) { |
|
204 | 204 | // if its a kit then we don't add shims here |
205 | 205 | return ''; |
206 | 206 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $url .= "?wpfas=true"; // set our var so our version is not removed |
209 | 209 | } else { |
210 | 210 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
211 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
211 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | 212 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
213 | 213 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
214 | 214 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -228,16 +228,16 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return string The filtered url. |
230 | 230 | */ |
231 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
231 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
232 | 232 | |
233 | - if ( $_context == 'display' |
|
234 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
233 | + if ($_context == 'display' |
|
234 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
235 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
236 | 236 | ) {// it's a font-awesome-url (probably) |
237 | 237 | |
238 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | - if ( $this->settings['type'] == 'JS' ) { |
|
240 | - if ( $this->settings['js-pseudo'] ) { |
|
238 | + if (strstr($url, "wpfas=true") !== false) { |
|
239 | + if ($this->settings['type'] == 'JS') { |
|
240 | + if ($this->settings['js-pseudo']) { |
|
241 | 241 | $url .= "' data-search-pseudo-elements defer='defer"; |
242 | 242 | } else { |
243 | 243 | $url .= "' defer='defer"; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * Register the database settings with WordPress. |
257 | 257 | */ |
258 | 258 | public function register_settings() { |
259 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
259 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function menu_item() { |
267 | 267 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
268 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
268 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | 269 | $this, |
270 | 270 | 'settings_page' |
271 | - ) ); |
|
271 | + )); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public function get_settings() { |
280 | 280 | |
281 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
281 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
282 | 282 | |
283 | 283 | $defaults = array( |
284 | 284 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -291,14 +291,14 @@ discard block |
||
291 | 291 | 'kit-url' => '', // the kit url |
292 | 292 | ); |
293 | 293 | |
294 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
294 | + $settings = wp_parse_args($db_settings, $defaults); |
|
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Filter the Font Awesome settings. |
298 | 298 | * |
299 | 299 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
300 | 300 | */ |
301 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
301 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | |
@@ -306,13 +306,13 @@ discard block |
||
306 | 306 | * The settings page html output. |
307 | 307 | */ |
308 | 308 | public function settings_page() { |
309 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
309 | + if (!current_user_can('manage_options')) { |
|
310 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
314 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | - $this->get_latest_version( $force_api = true ); |
|
314 | + if (isset($_REQUEST['force-version-check'])) { |
|
315 | + $this->get_latest_version($force_api = true); |
|
316 | 316 | } |
317 | 317 | ?> |
318 | 318 | <style> |
@@ -329,40 +329,40 @@ discard block |
||
329 | 329 | } |
330 | 330 | </style> |
331 | 331 | <div class="wrap"> |
332 | - <h1><?php echo esc_html( $this->name ); ?></h1> |
|
332 | + <h1><?php echo esc_html($this->name); ?></h1> |
|
333 | 333 | <form method="post" action="options.php"> |
334 | 334 | <?php |
335 | - settings_fields( 'wp-font-awesome-settings' ); |
|
336 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
335 | + settings_fields('wp-font-awesome-settings'); |
|
336 | + do_settings_sections('wp-font-awesome-settings'); |
|
337 | 337 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
338 | 338 | ?> |
339 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
|
339 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($kit_set); ?>"> |
|
340 | 340 | <tr valign="top"> |
341 | 341 | <th scope="row"><label |
342 | - for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
342 | + for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
343 | 343 | <td> |
344 | 344 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
345 | 345 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
346 | 346 | <option |
347 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
348 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
347 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
348 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
349 | 349 | <option |
350 | - value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
|
350 | + value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option> |
|
351 | 351 | </select> |
352 | 352 | </td> |
353 | 353 | </tr> |
354 | 354 | |
355 | 355 | <tr valign="top" class="wpfas-kit-show"> |
356 | 356 | <th scope="row"><label |
357 | - for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
|
357 | + for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th> |
|
358 | 358 | <td> |
359 | 359 | <input class="regular-text" id="wpfas-kit-url" type="url" |
360 | 360 | name="wp-font-awesome-settings[kit-url]" |
361 | - value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
|
362 | - placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
361 | + value="<?php echo esc_attr($this->settings['kit-url']); ?>" |
|
362 | + placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
363 | 363 | <span><?php |
364 | 364 | echo sprintf( |
365 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
365 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'), |
|
366 | 366 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
367 | 367 | '</a>' |
368 | 368 | ); |
@@ -372,31 +372,31 @@ discard block |
||
372 | 372 | |
373 | 373 | <tr valign="top" class="wpfas-kit-hide"> |
374 | 374 | <th scope="row"><label |
375 | - for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
375 | + for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
376 | 376 | <td> |
377 | 377 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
378 | 378 | <option |
379 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), esc_html( $this->get_latest_version() ) ); ?> |
|
379 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), esc_html($this->get_latest_version())); ?> |
|
380 | 380 | </option> |
381 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
381 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
382 | 382 | 5.6.0 |
383 | 383 | </option> |
384 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
384 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
385 | 385 | 5.5.0 |
386 | 386 | </option> |
387 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
387 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
388 | 388 | 5.4.0 |
389 | 389 | </option> |
390 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
390 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
391 | 391 | 5.3.0 |
392 | 392 | </option> |
393 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
393 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
394 | 394 | 5.2.0 |
395 | 395 | </option> |
396 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
396 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
397 | 397 | 5.1.0 |
398 | 398 | </option> |
399 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
399 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
400 | 400 | 4.7.1 (CSS only) |
401 | 401 | </option> |
402 | 402 | </select> |
@@ -405,29 +405,29 @@ discard block |
||
405 | 405 | |
406 | 406 | <tr valign="top"> |
407 | 407 | <th scope="row"><label |
408 | - for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
408 | + for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
409 | 409 | <td> |
410 | 410 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
411 | 411 | <option |
412 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
412 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
413 | 413 | <option |
414 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
414 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
415 | 415 | <option |
416 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
416 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
417 | 417 | </select> |
418 | 418 | </td> |
419 | 419 | </tr> |
420 | 420 | |
421 | 421 | <tr valign="top" class="wpfas-kit-hide"> |
422 | 422 | <th scope="row"><label |
423 | - for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
|
423 | + for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th> |
|
424 | 424 | <td> |
425 | 425 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
426 | 426 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
427 | - value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
|
427 | + value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro"/> |
|
428 | 428 | <span><?php |
429 | 429 | echo sprintf( |
430 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
430 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings'), |
|
431 | 431 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
432 | 432 | '</a>', |
433 | 433 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
@@ -439,38 +439,38 @@ discard block |
||
439 | 439 | |
440 | 440 | <tr valign="top" class="wpfas-kit-hide"> |
441 | 441 | <th scope="row"><label |
442 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
|
442 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label> |
|
443 | 443 | </th> |
444 | 444 | <td> |
445 | 445 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
446 | 446 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
447 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
448 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
|
447 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
448 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span> |
|
449 | 449 | </td> |
450 | 450 | </tr> |
451 | 451 | |
452 | 452 | <tr valign="top" class="wpfas-kit-hide"> |
453 | 453 | <th scope="row"><label |
454 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
454 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
455 | 455 | </th> |
456 | 456 | <td> |
457 | 457 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
458 | 458 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
459 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
459 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
460 | 460 | id="wpfas-js-pseudo"/> |
461 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
|
461 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span> |
|
462 | 462 | </td> |
463 | 463 | </tr> |
464 | 464 | |
465 | 465 | <tr valign="top"> |
466 | 466 | <th scope="row"><label |
467 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
467 | + for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
468 | 468 | <td> |
469 | 469 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
470 | 470 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
471 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
471 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
472 | 472 | id="wpfas-dequeue"/> |
473 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
|
473 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span> |
|
474 | 474 | </td> |
475 | 475 | </tr> |
476 | 476 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | ?> |
481 | 481 | </form> |
482 | 482 | |
483 | - <div id="wpfas-version"><?php echo esc_html( $this->version ); ?></div> |
|
483 | + <div id="wpfas-version"><?php echo esc_html($this->version); ?></div> |
|
484 | 484 | </div> |
485 | 485 | |
486 | 486 | <?php |
@@ -495,12 +495,12 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @return string Either a valid version number or an empty string. |
497 | 497 | */ |
498 | - public function validate_version_number( $version ) { |
|
498 | + public function validate_version_number($version) { |
|
499 | 499 | |
500 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
500 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
501 | 501 | // valid |
502 | 502 | } else { |
503 | - $version = '';// not validated |
|
503 | + $version = ''; // not validated |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | return $version; |
@@ -515,19 +515,19 @@ discard block |
||
515 | 515 | * @since 1.0.7 |
516 | 516 | * @return mixed|string The latest version number found. |
517 | 517 | */ |
518 | - public function get_latest_version( $force_api = false ) { |
|
518 | + public function get_latest_version($force_api = false) { |
|
519 | 519 | $latest_version = $this->latest; |
520 | 520 | |
521 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
521 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
522 | 522 | |
523 | - if ( $cache === false || $force_api ) { // its not set |
|
523 | + if ($cache === false || $force_api) { // its not set |
|
524 | 524 | $api_ver = $this->get_latest_version_from_api(); |
525 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
525 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
526 | 526 | $latest_version = $api_ver; |
527 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
527 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
528 | 528 | } |
529 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
529 | + } elseif ($this->validate_version_number($cache)) { |
|
530 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
531 | 531 | $latest_version = $cache; |
532 | 532 | } |
533 | 533 | } |
@@ -543,10 +543,10 @@ discard block |
||
543 | 543 | */ |
544 | 544 | public function get_latest_version_from_api() { |
545 | 545 | $version = "0"; |
546 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
546 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
547 | + if (!is_wp_error($response) && is_array($response)) { |
|
548 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
549 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
550 | 550 | $version = $api_response['tag_name']; |
551 | 551 | } |
552 | 552 | } |
@@ -1,271 +1,271 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; |
|
4 | + exit; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | if ( ! class_exists( "AyeCode_Connect_Helper" ) ) { |
8 | - /** |
|
9 | - * Allow the quick setup and connection of our AyeCode Connect plugin. |
|
10 | - * |
|
11 | - * Class AyeCode_Connect_Helper |
|
12 | - */ |
|
13 | - class AyeCode_Connect_Helper { |
|
14 | - |
|
15 | - // Hold the version number |
|
16 | - var $version = "1.0.3"; |
|
17 | - |
|
18 | - // Hold the default strings. |
|
19 | - var $strings = array(); |
|
20 | - |
|
21 | - // Hold the default pages. |
|
22 | - var $pages = array(); |
|
23 | - |
|
24 | - /** |
|
25 | - * The constructor. |
|
26 | - * |
|
27 | - * AyeCode_Connect_Helper constructor. |
|
28 | - * |
|
29 | - * @param array $strings |
|
30 | - * @param array $pages |
|
31 | - */ |
|
32 | - public function __construct( $strings = array(), $pages = array() ) { |
|
33 | - |
|
34 | - // Only fire if not localhost and the current user has the right permissions. |
|
35 | - if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
36 | - |
|
37 | - |
|
38 | - // set default strings |
|
39 | - $default_strings = array( |
|
40 | - 'connect_title' => __( "Thanks for choosing an AyeCode Product!" ), |
|
41 | - 'connect_external' => __( "Please confirm you wish to connect your site?" ), |
|
42 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
43 | - 'connect_button' => __( "Connect Site" ), |
|
44 | - 'connecting_button' => __( "Connecting..." ), |
|
45 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost." ), |
|
46 | - 'error' => __( "Something went wrong, please refresh and try again." ), |
|
47 | - ); |
|
48 | - $this->strings = array_merge( $default_strings, $strings ); |
|
49 | - |
|
50 | - |
|
51 | - // set default pages |
|
52 | - $default_pages = array(); |
|
53 | - $this->pages = array_merge( $default_pages, $pages ); |
|
54 | - |
|
55 | - // maybe show connect site notice |
|
56 | - add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
57 | - |
|
58 | - // add ajax action if not already added |
|
59 | - if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
60 | - add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - // add ajax action if not already added |
|
65 | - if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
66 | - add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
67 | - } |
|
68 | - |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Give a way to check we can connect via a external redirect. |
|
73 | - */ |
|
74 | - public function ayecode_connect_helper_installed(){ |
|
75 | - $active = array( |
|
76 | - 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
77 | - 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
78 | - 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
79 | - ); |
|
80 | - wp_send_json_success( $active ); |
|
81 | - wp_die(); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get slug from path |
|
86 | - * |
|
87 | - * @param string $key |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - private function format_plugin_slug( $key ) { |
|
92 | - $slug = explode( '/', $key ); |
|
93 | - $slug = explode( '.', end( $slug ) ); |
|
94 | - |
|
95 | - return $slug[0]; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Install and activate the AyeCode Connect Plugin |
|
100 | - */ |
|
101 | - public function ayecode_connect_install() { |
|
102 | - |
|
103 | - // bail if localhost |
|
104 | - if ( $this->is_localhost() ) { |
|
105 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
106 | - } |
|
107 | - |
|
108 | - // Explicitly clear the event. |
|
109 | - wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
110 | - |
|
111 | - $success = true; |
|
112 | - $plugin_slug = "ayecode-connect"; |
|
113 | - if ( ! empty( $plugin_slug ) ) { |
|
114 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
115 | - require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
116 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
117 | - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
118 | - |
|
119 | - WP_Filesystem(); |
|
120 | - |
|
121 | - $skin = new Automatic_Upgrader_Skin; |
|
122 | - $upgrader = new WP_Upgrader( $skin ); |
|
123 | - $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
124 | - $plugin_slug = $plugin_slug; |
|
125 | - $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
|
126 | - $installed = false; |
|
127 | - $activate = false; |
|
128 | - |
|
129 | - // See if the plugin is installed already |
|
130 | - if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
131 | - $installed = true; |
|
132 | - $activate = ! is_plugin_active( $plugin ); |
|
133 | - } |
|
134 | - |
|
135 | - // Install this thing! |
|
136 | - if ( ! $installed ) { |
|
137 | - |
|
138 | - // Suppress feedback |
|
139 | - ob_start(); |
|
140 | - |
|
141 | - try { |
|
142 | - $plugin_information = plugins_api( 'plugin_information', array( |
|
143 | - 'slug' => $plugin_slug, |
|
144 | - 'fields' => array( |
|
145 | - 'short_description' => false, |
|
146 | - 'sections' => false, |
|
147 | - 'requires' => false, |
|
148 | - 'rating' => false, |
|
149 | - 'ratings' => false, |
|
150 | - 'downloaded' => false, |
|
151 | - 'last_updated' => false, |
|
152 | - 'added' => false, |
|
153 | - 'tags' => false, |
|
154 | - 'homepage' => false, |
|
155 | - 'donate_link' => false, |
|
156 | - 'author_profile' => false, |
|
157 | - 'author' => false, |
|
158 | - ), |
|
159 | - ) ); |
|
160 | - |
|
161 | - if ( is_wp_error( $plugin_information ) ) { |
|
162 | - throw new Exception( $plugin_information->get_error_message() ); |
|
163 | - } |
|
164 | - |
|
165 | - $package = $plugin_information->download_link; |
|
166 | - $download = $upgrader->download_package( $package ); |
|
167 | - |
|
168 | - if ( is_wp_error( $download ) ) { |
|
169 | - throw new Exception( $download->get_error_message() ); |
|
170 | - } |
|
171 | - |
|
172 | - $working_dir = $upgrader->unpack_package( $download, true ); |
|
173 | - |
|
174 | - if ( is_wp_error( $working_dir ) ) { |
|
175 | - throw new Exception( $working_dir->get_error_message() ); |
|
176 | - } |
|
177 | - |
|
178 | - $result = $upgrader->install_package( array( |
|
179 | - 'source' => $working_dir, |
|
180 | - 'destination' => WP_PLUGIN_DIR, |
|
181 | - 'clear_destination' => false, |
|
182 | - 'abort_if_destination_exists' => false, |
|
183 | - 'clear_working' => true, |
|
184 | - 'hook_extra' => array( |
|
185 | - 'type' => 'plugin', |
|
186 | - 'action' => 'install', |
|
187 | - ), |
|
188 | - ) ); |
|
189 | - |
|
190 | - if ( is_wp_error( $result ) ) { |
|
191 | - throw new Exception( $result->get_error_message() ); |
|
192 | - } |
|
193 | - |
|
194 | - $activate = true; |
|
195 | - |
|
196 | - } catch ( Exception $e ) { |
|
197 | - $success = false; |
|
198 | - } |
|
199 | - |
|
200 | - // Discard feedback |
|
201 | - ob_end_clean(); |
|
202 | - } |
|
203 | - |
|
204 | - wp_clean_plugins_cache(); |
|
205 | - |
|
206 | - // Activate this thing |
|
207 | - if ( $activate ) { |
|
208 | - try { |
|
209 | - $result = activate_plugin( $plugin ); |
|
210 | - |
|
211 | - if ( is_wp_error( $result ) ) { |
|
212 | - $success = false; |
|
213 | - } else { |
|
214 | - $success = true; |
|
215 | - } |
|
216 | - } catch ( Exception $e ) { |
|
217 | - $success = false; |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
223 | - ayecode_connect();// init |
|
224 | - $args = ayecode_connect_args(); |
|
225 | - $client = new AyeCode_Connect( $args ); |
|
226 | - $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
227 | - $redirect = $client->build_connect_url( $redirect_to ); |
|
228 | - wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
229 | - } else { |
|
230 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
231 | - } |
|
232 | - wp_die(); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Check if maybe localhost. |
|
237 | - * |
|
238 | - * @return bool |
|
239 | - */ |
|
240 | - public function is_localhost() { |
|
241 | - $localhost = false; |
|
242 | - |
|
243 | - $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
244 | - $localhost_domains = array( |
|
245 | - 'localhost', |
|
246 | - 'localhost.localdomain', |
|
247 | - '127.0.0.1', |
|
248 | - '::1' |
|
249 | - ); |
|
250 | - |
|
251 | - if ( in_array( $host, $localhost_domains ) ) { |
|
252 | - $localhost = true; |
|
253 | - } |
|
254 | - |
|
255 | - return $localhost; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Show notice to connect site. |
|
260 | - */ |
|
261 | - public function ayecode_connect_install_notice() { |
|
262 | - if ( $this->maybe_show() ) { |
|
263 | - $connect_title_string = $this->strings['connect_title']; |
|
264 | - $connect_external_string = $this->strings['connect_external']; |
|
265 | - $connect_string = $this->strings['connect']; |
|
266 | - $connect_button_string = $this->strings['connect_button']; |
|
267 | - $connecting_button_string = $this->strings['connecting_button']; |
|
268 | - ?> |
|
8 | + /** |
|
9 | + * Allow the quick setup and connection of our AyeCode Connect plugin. |
|
10 | + * |
|
11 | + * Class AyeCode_Connect_Helper |
|
12 | + */ |
|
13 | + class AyeCode_Connect_Helper { |
|
14 | + |
|
15 | + // Hold the version number |
|
16 | + var $version = "1.0.3"; |
|
17 | + |
|
18 | + // Hold the default strings. |
|
19 | + var $strings = array(); |
|
20 | + |
|
21 | + // Hold the default pages. |
|
22 | + var $pages = array(); |
|
23 | + |
|
24 | + /** |
|
25 | + * The constructor. |
|
26 | + * |
|
27 | + * AyeCode_Connect_Helper constructor. |
|
28 | + * |
|
29 | + * @param array $strings |
|
30 | + * @param array $pages |
|
31 | + */ |
|
32 | + public function __construct( $strings = array(), $pages = array() ) { |
|
33 | + |
|
34 | + // Only fire if not localhost and the current user has the right permissions. |
|
35 | + if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
36 | + |
|
37 | + |
|
38 | + // set default strings |
|
39 | + $default_strings = array( |
|
40 | + 'connect_title' => __( "Thanks for choosing an AyeCode Product!" ), |
|
41 | + 'connect_external' => __( "Please confirm you wish to connect your site?" ), |
|
42 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
43 | + 'connect_button' => __( "Connect Site" ), |
|
44 | + 'connecting_button' => __( "Connecting..." ), |
|
45 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost." ), |
|
46 | + 'error' => __( "Something went wrong, please refresh and try again." ), |
|
47 | + ); |
|
48 | + $this->strings = array_merge( $default_strings, $strings ); |
|
49 | + |
|
50 | + |
|
51 | + // set default pages |
|
52 | + $default_pages = array(); |
|
53 | + $this->pages = array_merge( $default_pages, $pages ); |
|
54 | + |
|
55 | + // maybe show connect site notice |
|
56 | + add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
57 | + |
|
58 | + // add ajax action if not already added |
|
59 | + if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
60 | + add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + // add ajax action if not already added |
|
65 | + if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
66 | + add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
67 | + } |
|
68 | + |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Give a way to check we can connect via a external redirect. |
|
73 | + */ |
|
74 | + public function ayecode_connect_helper_installed(){ |
|
75 | + $active = array( |
|
76 | + 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
77 | + 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
78 | + 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
79 | + ); |
|
80 | + wp_send_json_success( $active ); |
|
81 | + wp_die(); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get slug from path |
|
86 | + * |
|
87 | + * @param string $key |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + private function format_plugin_slug( $key ) { |
|
92 | + $slug = explode( '/', $key ); |
|
93 | + $slug = explode( '.', end( $slug ) ); |
|
94 | + |
|
95 | + return $slug[0]; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Install and activate the AyeCode Connect Plugin |
|
100 | + */ |
|
101 | + public function ayecode_connect_install() { |
|
102 | + |
|
103 | + // bail if localhost |
|
104 | + if ( $this->is_localhost() ) { |
|
105 | + wp_send_json_error( $this->strings['error_localhost'] ); |
|
106 | + } |
|
107 | + |
|
108 | + // Explicitly clear the event. |
|
109 | + wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
110 | + |
|
111 | + $success = true; |
|
112 | + $plugin_slug = "ayecode-connect"; |
|
113 | + if ( ! empty( $plugin_slug ) ) { |
|
114 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
115 | + require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
116 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
117 | + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
118 | + |
|
119 | + WP_Filesystem(); |
|
120 | + |
|
121 | + $skin = new Automatic_Upgrader_Skin; |
|
122 | + $upgrader = new WP_Upgrader( $skin ); |
|
123 | + $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
124 | + $plugin_slug = $plugin_slug; |
|
125 | + $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
|
126 | + $installed = false; |
|
127 | + $activate = false; |
|
128 | + |
|
129 | + // See if the plugin is installed already |
|
130 | + if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
131 | + $installed = true; |
|
132 | + $activate = ! is_plugin_active( $plugin ); |
|
133 | + } |
|
134 | + |
|
135 | + // Install this thing! |
|
136 | + if ( ! $installed ) { |
|
137 | + |
|
138 | + // Suppress feedback |
|
139 | + ob_start(); |
|
140 | + |
|
141 | + try { |
|
142 | + $plugin_information = plugins_api( 'plugin_information', array( |
|
143 | + 'slug' => $plugin_slug, |
|
144 | + 'fields' => array( |
|
145 | + 'short_description' => false, |
|
146 | + 'sections' => false, |
|
147 | + 'requires' => false, |
|
148 | + 'rating' => false, |
|
149 | + 'ratings' => false, |
|
150 | + 'downloaded' => false, |
|
151 | + 'last_updated' => false, |
|
152 | + 'added' => false, |
|
153 | + 'tags' => false, |
|
154 | + 'homepage' => false, |
|
155 | + 'donate_link' => false, |
|
156 | + 'author_profile' => false, |
|
157 | + 'author' => false, |
|
158 | + ), |
|
159 | + ) ); |
|
160 | + |
|
161 | + if ( is_wp_error( $plugin_information ) ) { |
|
162 | + throw new Exception( $plugin_information->get_error_message() ); |
|
163 | + } |
|
164 | + |
|
165 | + $package = $plugin_information->download_link; |
|
166 | + $download = $upgrader->download_package( $package ); |
|
167 | + |
|
168 | + if ( is_wp_error( $download ) ) { |
|
169 | + throw new Exception( $download->get_error_message() ); |
|
170 | + } |
|
171 | + |
|
172 | + $working_dir = $upgrader->unpack_package( $download, true ); |
|
173 | + |
|
174 | + if ( is_wp_error( $working_dir ) ) { |
|
175 | + throw new Exception( $working_dir->get_error_message() ); |
|
176 | + } |
|
177 | + |
|
178 | + $result = $upgrader->install_package( array( |
|
179 | + 'source' => $working_dir, |
|
180 | + 'destination' => WP_PLUGIN_DIR, |
|
181 | + 'clear_destination' => false, |
|
182 | + 'abort_if_destination_exists' => false, |
|
183 | + 'clear_working' => true, |
|
184 | + 'hook_extra' => array( |
|
185 | + 'type' => 'plugin', |
|
186 | + 'action' => 'install', |
|
187 | + ), |
|
188 | + ) ); |
|
189 | + |
|
190 | + if ( is_wp_error( $result ) ) { |
|
191 | + throw new Exception( $result->get_error_message() ); |
|
192 | + } |
|
193 | + |
|
194 | + $activate = true; |
|
195 | + |
|
196 | + } catch ( Exception $e ) { |
|
197 | + $success = false; |
|
198 | + } |
|
199 | + |
|
200 | + // Discard feedback |
|
201 | + ob_end_clean(); |
|
202 | + } |
|
203 | + |
|
204 | + wp_clean_plugins_cache(); |
|
205 | + |
|
206 | + // Activate this thing |
|
207 | + if ( $activate ) { |
|
208 | + try { |
|
209 | + $result = activate_plugin( $plugin ); |
|
210 | + |
|
211 | + if ( is_wp_error( $result ) ) { |
|
212 | + $success = false; |
|
213 | + } else { |
|
214 | + $success = true; |
|
215 | + } |
|
216 | + } catch ( Exception $e ) { |
|
217 | + $success = false; |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
223 | + ayecode_connect();// init |
|
224 | + $args = ayecode_connect_args(); |
|
225 | + $client = new AyeCode_Connect( $args ); |
|
226 | + $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
227 | + $redirect = $client->build_connect_url( $redirect_to ); |
|
228 | + wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
229 | + } else { |
|
230 | + wp_send_json_error( $this->strings['error_localhost'] ); |
|
231 | + } |
|
232 | + wp_die(); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Check if maybe localhost. |
|
237 | + * |
|
238 | + * @return bool |
|
239 | + */ |
|
240 | + public function is_localhost() { |
|
241 | + $localhost = false; |
|
242 | + |
|
243 | + $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
244 | + $localhost_domains = array( |
|
245 | + 'localhost', |
|
246 | + 'localhost.localdomain', |
|
247 | + '127.0.0.1', |
|
248 | + '::1' |
|
249 | + ); |
|
250 | + |
|
251 | + if ( in_array( $host, $localhost_domains ) ) { |
|
252 | + $localhost = true; |
|
253 | + } |
|
254 | + |
|
255 | + return $localhost; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Show notice to connect site. |
|
260 | + */ |
|
261 | + public function ayecode_connect_install_notice() { |
|
262 | + if ( $this->maybe_show() ) { |
|
263 | + $connect_title_string = $this->strings['connect_title']; |
|
264 | + $connect_external_string = $this->strings['connect_external']; |
|
265 | + $connect_string = $this->strings['connect']; |
|
266 | + $connect_button_string = $this->strings['connect_button']; |
|
267 | + $connecting_button_string = $this->strings['connecting_button']; |
|
268 | + ?> |
|
269 | 269 | <div class="notice notice-info acch-notice"> |
270 | 270 | <span class="acch-float-left"> |
271 | 271 | <svg width="61px" height="61px" viewBox="0 0 61 61" version="1.1" |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | <h3 class="acch-title"><?php echo esc_html( $connect_title_string ); ?></h3> |
305 | 305 | <p> |
306 | 306 | <?php |
307 | - echo wp_kses_post( $connect_string ); |
|
308 | - ?> |
|
307 | + echo wp_kses_post( $connect_string ); |
|
308 | + ?> |
|
309 | 309 | </p> |
310 | 310 | </span> |
311 | 311 | |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | </div> |
319 | 319 | |
320 | 320 | <?php |
321 | - // only include the popup HTML if needed. |
|
322 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
323 | - ?> |
|
321 | + // only include the popup HTML if needed. |
|
322 | + if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
323 | + ?> |
|
324 | 324 | <div id="ayecode-connect-helper-external-confirm" style="display:none;"> |
325 | 325 | <div class="noticex notice-info acch-notice" style="border: none;"> |
326 | 326 | <span class="acch-float-left"> |
@@ -369,23 +369,23 @@ discard block |
||
369 | 369 | </div> |
370 | 370 | </div> |
371 | 371 | <?php |
372 | - } |
|
373 | - |
|
374 | - // add required scripts |
|
375 | - $this->script(); |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Get the JS Script. |
|
381 | - */ |
|
382 | - public function script() { |
|
383 | - |
|
384 | - // add thickbox if external request is requested |
|
385 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
386 | - add_thickbox(); |
|
387 | - } |
|
388 | - ?> |
|
372 | + } |
|
373 | + |
|
374 | + // add required scripts |
|
375 | + $this->script(); |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Get the JS Script. |
|
381 | + */ |
|
382 | + public function script() { |
|
383 | + |
|
384 | + // add thickbox if external request is requested |
|
385 | + if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
386 | + add_thickbox(); |
|
387 | + } |
|
388 | + ?> |
|
389 | 389 | <style> |
390 | 390 | .acch-title { |
391 | 391 | margin: 0; |
@@ -454,43 +454,43 @@ discard block |
||
454 | 454 | |
455 | 455 | |
456 | 456 | <?php |
457 | - // add thickbox if external request is requested |
|
458 | - if(! empty( $_REQUEST['external-connect-request'] )) { |
|
459 | - ?> |
|
457 | + // add thickbox if external request is requested |
|
458 | + if(! empty( $_REQUEST['external-connect-request'] )) { |
|
459 | + ?> |
|
460 | 460 | jQuery(function () { |
461 | 461 | setTimeout(function () { |
462 | 462 | tb_show("AyeCode Connect", "?TB_inline?width=300&height=80&inlineId=ayecode-connect-helper-external-confirm"); |
463 | 463 | }, 200); |
464 | 464 | }); |
465 | 465 | <?php |
466 | - } |
|
467 | - ?> |
|
466 | + } |
|
467 | + ?> |
|
468 | 468 | |
469 | 469 | </script> |
470 | 470 | <?php |
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Decide what pages to show on. |
|
475 | - * |
|
476 | - * @return bool |
|
477 | - */ |
|
478 | - public function maybe_show() { |
|
479 | - $show = false; |
|
480 | - |
|
481 | - // check if on a page set to show |
|
482 | - if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
483 | - |
|
484 | - // check if not active and connected |
|
485 | - if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
486 | - $show = true; |
|
487 | - } |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Decide what pages to show on. |
|
475 | + * |
|
476 | + * @return bool |
|
477 | + */ |
|
478 | + public function maybe_show() { |
|
479 | + $show = false; |
|
480 | + |
|
481 | + // check if on a page set to show |
|
482 | + if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
483 | + |
|
484 | + // check if not active and connected |
|
485 | + if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
486 | + $show = true; |
|
487 | + } |
|
488 | 488 | |
489 | - } |
|
489 | + } |
|
490 | 490 | |
491 | - return $show; |
|
492 | - } |
|
491 | + return $show; |
|
492 | + } |
|
493 | 493 | |
494 | - } |
|
494 | + } |
|
495 | 495 | |
496 | 496 | } |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -if ( ! class_exists( "AyeCode_Connect_Helper" ) ) { |
|
7 | +if (!class_exists("AyeCode_Connect_Helper")) { |
|
8 | 8 | /** |
9 | 9 | * Allow the quick setup and connection of our AyeCode Connect plugin. |
10 | 10 | * |
@@ -29,41 +29,41 @@ discard block |
||
29 | 29 | * @param array $strings |
30 | 30 | * @param array $pages |
31 | 31 | */ |
32 | - public function __construct( $strings = array(), $pages = array() ) { |
|
32 | + public function __construct($strings = array(), $pages = array()) { |
|
33 | 33 | |
34 | 34 | // Only fire if not localhost and the current user has the right permissions. |
35 | - if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
35 | + if (!$this->is_localhost() && current_user_can('manage_options')) { |
|
36 | 36 | |
37 | 37 | |
38 | 38 | // set default strings |
39 | 39 | $default_strings = array( |
40 | - 'connect_title' => __( "Thanks for choosing an AyeCode Product!" ), |
|
41 | - 'connect_external' => __( "Please confirm you wish to connect your site?" ), |
|
42 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
43 | - 'connect_button' => __( "Connect Site" ), |
|
44 | - 'connecting_button' => __( "Connecting..." ), |
|
45 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost." ), |
|
46 | - 'error' => __( "Something went wrong, please refresh and try again." ), |
|
40 | + 'connect_title' => __("Thanks for choosing an AyeCode Product!"), |
|
41 | + 'connect_external' => __("Please confirm you wish to connect your site?"), |
|
42 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
43 | + 'connect_button' => __("Connect Site"), |
|
44 | + 'connecting_button' => __("Connecting..."), |
|
45 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost."), |
|
46 | + 'error' => __("Something went wrong, please refresh and try again."), |
|
47 | 47 | ); |
48 | - $this->strings = array_merge( $default_strings, $strings ); |
|
48 | + $this->strings = array_merge($default_strings, $strings); |
|
49 | 49 | |
50 | 50 | |
51 | 51 | // set default pages |
52 | 52 | $default_pages = array(); |
53 | - $this->pages = array_merge( $default_pages, $pages ); |
|
53 | + $this->pages = array_merge($default_pages, $pages); |
|
54 | 54 | |
55 | 55 | // maybe show connect site notice |
56 | - add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
56 | + add_action('admin_notices', array($this, 'ayecode_connect_install_notice')); |
|
57 | 57 | |
58 | 58 | // add ajax action if not already added |
59 | - if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
60 | - add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
59 | + if (!has_action('wp_ajax_ayecode_connect_helper')) { |
|
60 | + add_action('wp_ajax_ayecode_connect_helper', array($this, 'ayecode_connect_install')); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | // add ajax action if not already added |
65 | - if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
66 | - add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
65 | + if (!has_action('wp_ajax_nopriv_ayecode_connect_helper_installed')) { |
|
66 | + add_action('wp_ajax_nopriv_ayecode_connect_helper_installed', array($this, 'ayecode_connect_helper_installed')); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | } |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | /** |
72 | 72 | * Give a way to check we can connect via a external redirect. |
73 | 73 | */ |
74 | - public function ayecode_connect_helper_installed(){ |
|
74 | + public function ayecode_connect_helper_installed() { |
|
75 | 75 | $active = array( |
76 | - 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
77 | - 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
78 | - 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
76 | + 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION, '2.0.0.79', '>') ? 1 : 0, |
|
77 | + 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION, '1.2.1.5', '>') ? 1 : 0, |
|
78 | + 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION, '1.0.14', '>') ? 1 : 0, |
|
79 | 79 | ); |
80 | - wp_send_json_success( $active ); |
|
80 | + wp_send_json_success($active); |
|
81 | 81 | wp_die(); |
82 | 82 | } |
83 | 83 | |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - private function format_plugin_slug( $key ) { |
|
92 | - $slug = explode( '/', $key ); |
|
93 | - $slug = explode( '.', end( $slug ) ); |
|
91 | + private function format_plugin_slug($key) { |
|
92 | + $slug = explode('/', $key); |
|
93 | + $slug = explode('.', end($slug)); |
|
94 | 94 | |
95 | 95 | return $slug[0]; |
96 | 96 | } |
@@ -101,45 +101,45 @@ discard block |
||
101 | 101 | public function ayecode_connect_install() { |
102 | 102 | |
103 | 103 | // bail if localhost |
104 | - if ( $this->is_localhost() ) { |
|
105 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
104 | + if ($this->is_localhost()) { |
|
105 | + wp_send_json_error($this->strings['error_localhost']); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Explicitly clear the event. |
109 | - wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
109 | + wp_clear_scheduled_hook('geodir_plugin_background_installer', func_get_args()); |
|
110 | 110 | |
111 | 111 | $success = true; |
112 | 112 | $plugin_slug = "ayecode-connect"; |
113 | - if ( ! empty( $plugin_slug ) ) { |
|
114 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
115 | - require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
116 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
117 | - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
113 | + if (!empty($plugin_slug)) { |
|
114 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
115 | + require_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); |
|
116 | + require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); |
|
117 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
118 | 118 | |
119 | 119 | WP_Filesystem(); |
120 | 120 | |
121 | 121 | $skin = new Automatic_Upgrader_Skin; |
122 | - $upgrader = new WP_Upgrader( $skin ); |
|
123 | - $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
122 | + $upgrader = new WP_Upgrader($skin); |
|
123 | + $installed_plugins = array_map(array($this, 'format_plugin_slug'), array_keys(get_plugins())); |
|
124 | 124 | $plugin_slug = $plugin_slug; |
125 | 125 | $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
126 | 126 | $installed = false; |
127 | 127 | $activate = false; |
128 | 128 | |
129 | 129 | // See if the plugin is installed already |
130 | - if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
130 | + if (in_array($plugin_slug, $installed_plugins)) { |
|
131 | 131 | $installed = true; |
132 | - $activate = ! is_plugin_active( $plugin ); |
|
132 | + $activate = !is_plugin_active($plugin); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | // Install this thing! |
136 | - if ( ! $installed ) { |
|
136 | + if (!$installed) { |
|
137 | 137 | |
138 | 138 | // Suppress feedback |
139 | 139 | ob_start(); |
140 | 140 | |
141 | 141 | try { |
142 | - $plugin_information = plugins_api( 'plugin_information', array( |
|
142 | + $plugin_information = plugins_api('plugin_information', array( |
|
143 | 143 | 'slug' => $plugin_slug, |
144 | 144 | 'fields' => array( |
145 | 145 | 'short_description' => false, |
@@ -156,26 +156,26 @@ discard block |
||
156 | 156 | 'author_profile' => false, |
157 | 157 | 'author' => false, |
158 | 158 | ), |
159 | - ) ); |
|
159 | + )); |
|
160 | 160 | |
161 | - if ( is_wp_error( $plugin_information ) ) { |
|
162 | - throw new Exception( $plugin_information->get_error_message() ); |
|
161 | + if (is_wp_error($plugin_information)) { |
|
162 | + throw new Exception($plugin_information->get_error_message()); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | $package = $plugin_information->download_link; |
166 | - $download = $upgrader->download_package( $package ); |
|
166 | + $download = $upgrader->download_package($package); |
|
167 | 167 | |
168 | - if ( is_wp_error( $download ) ) { |
|
169 | - throw new Exception( $download->get_error_message() ); |
|
168 | + if (is_wp_error($download)) { |
|
169 | + throw new Exception($download->get_error_message()); |
|
170 | 170 | } |
171 | 171 | |
172 | - $working_dir = $upgrader->unpack_package( $download, true ); |
|
172 | + $working_dir = $upgrader->unpack_package($download, true); |
|
173 | 173 | |
174 | - if ( is_wp_error( $working_dir ) ) { |
|
175 | - throw new Exception( $working_dir->get_error_message() ); |
|
174 | + if (is_wp_error($working_dir)) { |
|
175 | + throw new Exception($working_dir->get_error_message()); |
|
176 | 176 | } |
177 | 177 | |
178 | - $result = $upgrader->install_package( array( |
|
178 | + $result = $upgrader->install_package(array( |
|
179 | 179 | 'source' => $working_dir, |
180 | 180 | 'destination' => WP_PLUGIN_DIR, |
181 | 181 | 'clear_destination' => false, |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | 'type' => 'plugin', |
186 | 186 | 'action' => 'install', |
187 | 187 | ), |
188 | - ) ); |
|
188 | + )); |
|
189 | 189 | |
190 | - if ( is_wp_error( $result ) ) { |
|
191 | - throw new Exception( $result->get_error_message() ); |
|
190 | + if (is_wp_error($result)) { |
|
191 | + throw new Exception($result->get_error_message()); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | $activate = true; |
195 | 195 | |
196 | - } catch ( Exception $e ) { |
|
196 | + } catch (Exception $e) { |
|
197 | 197 | $success = false; |
198 | 198 | } |
199 | 199 | |
@@ -204,30 +204,30 @@ discard block |
||
204 | 204 | wp_clean_plugins_cache(); |
205 | 205 | |
206 | 206 | // Activate this thing |
207 | - if ( $activate ) { |
|
207 | + if ($activate) { |
|
208 | 208 | try { |
209 | - $result = activate_plugin( $plugin ); |
|
209 | + $result = activate_plugin($plugin); |
|
210 | 210 | |
211 | - if ( is_wp_error( $result ) ) { |
|
211 | + if (is_wp_error($result)) { |
|
212 | 212 | $success = false; |
213 | 213 | } else { |
214 | 214 | $success = true; |
215 | 215 | } |
216 | - } catch ( Exception $e ) { |
|
216 | + } catch (Exception $e) { |
|
217 | 217 | $success = false; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
223 | - ayecode_connect();// init |
|
222 | + if ($success && function_exists('ayecode_connect_args')) { |
|
223 | + ayecode_connect(); // init |
|
224 | 224 | $args = ayecode_connect_args(); |
225 | - $client = new AyeCode_Connect( $args ); |
|
226 | - $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
227 | - $redirect = $client->build_connect_url( $redirect_to ); |
|
228 | - wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
225 | + $client = new AyeCode_Connect($args); |
|
226 | + $redirect_to = !empty($_POST['redirect_to']) ? esc_url_raw($_POST['redirect_to']) : ''; |
|
227 | + $redirect = $client->build_connect_url($redirect_to); |
|
228 | + wp_send_json_success(array('connect_url' => $redirect)); |
|
229 | 229 | } else { |
230 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
230 | + wp_send_json_error($this->strings['error_localhost']); |
|
231 | 231 | } |
232 | 232 | wp_die(); |
233 | 233 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | public function is_localhost() { |
241 | 241 | $localhost = false; |
242 | 242 | |
243 | - $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
243 | + $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; |
|
244 | 244 | $localhost_domains = array( |
245 | 245 | 'localhost', |
246 | 246 | 'localhost.localdomain', |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | '::1' |
249 | 249 | ); |
250 | 250 | |
251 | - if ( in_array( $host, $localhost_domains ) ) { |
|
251 | + if (in_array($host, $localhost_domains)) { |
|
252 | 252 | $localhost = true; |
253 | 253 | } |
254 | 254 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * Show notice to connect site. |
260 | 260 | */ |
261 | 261 | public function ayecode_connect_install_notice() { |
262 | - if ( $this->maybe_show() ) { |
|
262 | + if ($this->maybe_show()) { |
|
263 | 263 | $connect_title_string = $this->strings['connect_title']; |
264 | 264 | $connect_external_string = $this->strings['connect_external']; |
265 | 265 | $connect_string = $this->strings['connect']; |
@@ -301,10 +301,10 @@ discard block |
||
301 | 301 | </svg> |
302 | 302 | </span> |
303 | 303 | <span class="acch-float-left acch-text"> |
304 | - <h3 class="acch-title"><?php echo esc_html( $connect_title_string ); ?></h3> |
|
304 | + <h3 class="acch-title"><?php echo esc_html($connect_title_string); ?></h3> |
|
305 | 305 | <p> |
306 | 306 | <?php |
307 | - echo wp_kses_post( $connect_string ); |
|
307 | + echo wp_kses_post($connect_string); |
|
308 | 308 | ?> |
309 | 309 | </p> |
310 | 310 | </span> |
@@ -312,14 +312,14 @@ discard block |
||
312 | 312 | <span class="acch-float-left acch-button"> |
313 | 313 | <button onclick="ayecode_connect_helper(this);" id="gd-connect-site" |
314 | 314 | class="button button-primary" |
315 | - data-connecting="<?php echo esc_attr( $connecting_button_string ); ?>"><?php echo esc_attr( $connect_button_string ) ?></button> |
|
315 | + data-connecting="<?php echo esc_attr($connecting_button_string); ?>"><?php echo esc_attr($connect_button_string) ?></button> |
|
316 | 316 | </span> |
317 | 317 | |
318 | 318 | </div> |
319 | 319 | |
320 | 320 | <?php |
321 | 321 | // only include the popup HTML if needed. |
322 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
322 | + if (!empty($_REQUEST['external-connect-request'])) { |
|
323 | 323 | ?> |
324 | 324 | <div id="ayecode-connect-helper-external-confirm" style="display:none;"> |
325 | 325 | <div class="noticex notice-info acch-notice" style="border: none;"> |
@@ -357,13 +357,13 @@ discard block |
||
357 | 357 | </svg> |
358 | 358 | </span> |
359 | 359 | <span class="acch-float-left acch-text"> |
360 | - <h3 class="acch-title"><?php echo esc_attr( $connect_external_string ); ?></h3> |
|
360 | + <h3 class="acch-title"><?php echo esc_attr($connect_external_string); ?></h3> |
|
361 | 361 | </span> |
362 | 362 | |
363 | 363 | <span class="acch-float-left acch-button"> |
364 | 364 | <button onclick="ayecode_connect_helper(this);" id="gd-connect-site" |
365 | 365 | class="button button-primary" |
366 | - data-connecting="<?php echo esc_attr( $connecting_button_string ); ?>"><?php echo esc_attr( $connect_button_string ) ?></button> |
|
366 | + data-connecting="<?php echo esc_attr($connecting_button_string); ?>"><?php echo esc_attr($connect_button_string) ?></button> |
|
367 | 367 | </span> |
368 | 368 | |
369 | 369 | </div> |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | public function script() { |
383 | 383 | |
384 | 384 | // add thickbox if external request is requested |
385 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
385 | + if (!empty($_REQUEST['external-connect-request'])) { |
|
386 | 386 | add_thickbox(); |
387 | 387 | } |
388 | 388 | ?> |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | url: ajaxurl, |
435 | 435 | data: { |
436 | 436 | action: 'ayecode_connect_helper', |
437 | - security: '<?php echo esc_js( wp_create_nonce( 'ayecode-connect-helper' ) );?>', |
|
437 | + security: '<?php echo esc_js(wp_create_nonce('ayecode-connect-helper')); ?>', |
|
438 | 438 | redirect_to: $current_url |
439 | 439 | }, |
440 | 440 | beforeSend: function () { |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | |
456 | 456 | <?php |
457 | 457 | // add thickbox if external request is requested |
458 | - if(! empty( $_REQUEST['external-connect-request'] )) { |
|
458 | + if (!empty($_REQUEST['external-connect-request'])) { |
|
459 | 459 | ?> |
460 | 460 | jQuery(function () { |
461 | 461 | setTimeout(function () { |
@@ -479,10 +479,10 @@ discard block |
||
479 | 479 | $show = false; |
480 | 480 | |
481 | 481 | // check if on a page set to show |
482 | - if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
482 | + if (isset($_REQUEST['page']) && in_array($_REQUEST['page'], $this->pages)) { |
|
483 | 483 | |
484 | 484 | // check if not active and connected |
485 | - if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
485 | + if (!defined('AYECODE_CONNECT_VERSION') || !get_option('ayecode_connect_blog_token')) { |
|
486 | 486 | $show = true; |
487 | 487 | } |
488 | 488 |
@@ -7,14 +7,14 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -if ( empty( $text ) ) { |
|
13 | - $text = __( 'Your IP address is:', 'invoicing' ); |
|
12 | +if (empty($text)) { |
|
13 | + $text = __('Your IP address is:', 'invoicing'); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | ?> |
17 | 17 | <div class="form-group getpaid-ip-info"> |
18 | - <span><?php echo wp_kses_post( $text ); ?></span> |
|
19 | - <strong><?php echo esc_html( wpinv_get_ip() ); ?></strong> |
|
18 | + <span><?php echo wp_kses_post($text); ?></span> |
|
19 | + <strong><?php echo esc_html(wpinv_get_ip()); ?></strong> |
|
20 | 20 | </div> |
@@ -7,21 +7,21 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class="border-top pt-4 bg-white"> |
15 | 15 | <div class="container pr-0 pl-0"> |
16 | 16 | |
17 | - <?php if ( $term_text = wpinv_get_terms_text() ) : ?> |
|
17 | + <?php if ($term_text = wpinv_get_terms_text()) : ?> |
|
18 | 18 | <div class="terms-text"> |
19 | - <?php echo wp_kses_post( wpautop( $term_text ) ); ?> |
|
19 | + <?php echo wp_kses_post(wpautop($term_text)); ?> |
|
20 | 20 | </div> |
21 | 21 | <?php endif; ?> |
22 | 22 | |
23 | 23 | <div class="footer-text d-print-none"> |
24 | - <?php echo wp_kses_post( wpinv_get_business_footer() ); ?> |
|
24 | + <?php echo wp_kses_post(wpinv_get_business_footer()); ?> |
|
25 | 25 | </div> |
26 | 26 | |
27 | 27 | </div> |
@@ -7,22 +7,22 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Print the email header. |
13 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
13 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
14 | 14 | |
15 | 15 | // Generate the custom message body. |
16 | -echo wp_kses_post( $message_body ); |
|
16 | +echo wp_kses_post($message_body); |
|
17 | 17 | |
18 | 18 | // Print invoice details. |
19 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
19 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | |
21 | 21 | // Print invoice items. |
22 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
22 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
23 | 23 | |
24 | 24 | // Print the billing details. |
25 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
25 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
26 | 26 | |
27 | 27 | // Print the email footer. |
28 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
28 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |