@@ -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,112 +11,112 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Pagination { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function get( $args = array() ) { |
|
22 | - global $wp_query, $aui_bs5; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'class' => '', |
|
26 | - 'mid_size' => 2, |
|
27 | - 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | - 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | - 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | - 'before_paging' => '', |
|
31 | - 'after_paging' => '', |
|
32 | - 'type' => 'array', |
|
33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | - 'links' => array(), // an array of links if using custom links, this includes the a tag. |
|
35 | - 'rounded_style' => false, |
|
36 | - 'custom_next_text' => '', // Custom next page text |
|
37 | - 'custom_prev_text' => '', // Custom prev page text |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * Parse incoming $args into an array and merge it with $defaults |
|
42 | - */ |
|
43 | - $args = wp_parse_args( $args, $defaults ); |
|
44 | - |
|
45 | - $output = ''; |
|
46 | - |
|
47 | - // Don't print empty markup if there's only one page. |
|
48 | - if ( $args['total'] > 1 ) { |
|
49 | - // Set up paginated links. |
|
50 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
51 | - |
|
52 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
53 | - |
|
54 | - $custom_prev_link = ''; |
|
55 | - $custom_next_link = ''; |
|
56 | - |
|
57 | - // make the output bootstrap ready |
|
58 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
59 | - if ( ! empty( $links ) ) { |
|
60 | - foreach ( $links as $link ) { |
|
61 | - $_link = $link; |
|
62 | - |
|
63 | - if ( $aui_bs5 ) { |
|
64 | - $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link'; |
|
65 | - $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active'; |
|
66 | - $links_html .= "<li class='page-item mx-0'>"; |
|
67 | - $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link ); |
|
68 | - $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
69 | - $links_html .= $link; |
|
70 | - $links_html .= "</li>"; |
|
71 | - } else { |
|
72 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
73 | - $links_html .= "<li class='page-item $active'>"; |
|
74 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
75 | - $links_html .= "</li>"; |
|
76 | - } |
|
77 | - |
|
78 | - if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) { |
|
79 | - $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link ); |
|
80 | - $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
81 | - |
|
82 | - if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) { |
|
83 | - $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link ); |
|
84 | - } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) { |
|
85 | - $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link ); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - $links_html .= "</ul>"; |
|
91 | - |
|
92 | - if ( $links ) { |
|
93 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
94 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
95 | - $output .= '</section>'; |
|
96 | - } |
|
97 | - |
|
98 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
99 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
100 | - } |
|
101 | - |
|
102 | - if ( $output ) { |
|
103 | - if ( $custom_next_link || $custom_prev_link ) { |
|
104 | - $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
105 | - $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; |
|
106 | - |
|
107 | - $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>'; |
|
108 | - } |
|
109 | - |
|
110 | - if ( ! empty( $args['before_paging'] ) ) { |
|
111 | - $output = $args['before_paging'] . $output; |
|
112 | - } |
|
113 | - |
|
114 | - if ( ! empty( $args['after_paging'] ) ) { |
|
115 | - $output = $output . $args['after_paging']; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - return $output; |
|
120 | - } |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function get( $args = array() ) { |
|
22 | + global $wp_query, $aui_bs5; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'class' => '', |
|
26 | + 'mid_size' => 2, |
|
27 | + 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | + 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | + 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | + 'before_paging' => '', |
|
31 | + 'after_paging' => '', |
|
32 | + 'type' => 'array', |
|
33 | + 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | + 'links' => array(), // an array of links if using custom links, this includes the a tag. |
|
35 | + 'rounded_style' => false, |
|
36 | + 'custom_next_text' => '', // Custom next page text |
|
37 | + 'custom_prev_text' => '', // Custom prev page text |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * Parse incoming $args into an array and merge it with $defaults |
|
42 | + */ |
|
43 | + $args = wp_parse_args( $args, $defaults ); |
|
44 | + |
|
45 | + $output = ''; |
|
46 | + |
|
47 | + // Don't print empty markup if there's only one page. |
|
48 | + if ( $args['total'] > 1 ) { |
|
49 | + // Set up paginated links. |
|
50 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
51 | + |
|
52 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
53 | + |
|
54 | + $custom_prev_link = ''; |
|
55 | + $custom_next_link = ''; |
|
56 | + |
|
57 | + // make the output bootstrap ready |
|
58 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
59 | + if ( ! empty( $links ) ) { |
|
60 | + foreach ( $links as $link ) { |
|
61 | + $_link = $link; |
|
62 | + |
|
63 | + if ( $aui_bs5 ) { |
|
64 | + $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link'; |
|
65 | + $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active'; |
|
66 | + $links_html .= "<li class='page-item mx-0'>"; |
|
67 | + $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link ); |
|
68 | + $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
69 | + $links_html .= $link; |
|
70 | + $links_html .= "</li>"; |
|
71 | + } else { |
|
72 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
73 | + $links_html .= "<li class='page-item $active'>"; |
|
74 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
75 | + $links_html .= "</li>"; |
|
76 | + } |
|
77 | + |
|
78 | + if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) { |
|
79 | + $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link ); |
|
80 | + $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
81 | + |
|
82 | + if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) { |
|
83 | + $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link ); |
|
84 | + } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) { |
|
85 | + $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link ); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + $links_html .= "</ul>"; |
|
91 | + |
|
92 | + if ( $links ) { |
|
93 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
94 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
95 | + $output .= '</section>'; |
|
96 | + } |
|
97 | + |
|
98 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
99 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
100 | + } |
|
101 | + |
|
102 | + if ( $output ) { |
|
103 | + if ( $custom_next_link || $custom_prev_link ) { |
|
104 | + $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
105 | + $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; |
|
106 | + |
|
107 | + $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>'; |
|
108 | + } |
|
109 | + |
|
110 | + if ( ! empty( $args['before_paging'] ) ) { |
|
111 | + $output = $args['before_paging'] . $output; |
|
112 | + } |
|
113 | + |
|
114 | + if ( ! empty( $args['after_paging'] ) ) { |
|
115 | + $output = $output . $args['after_paging']; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + return $output; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | } |
123 | 123 | \ No newline at end of file |
@@ -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 d-block">' . 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 d-block">' . 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 |
@@ -16,222 +16,222 @@ |
||
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | 18 | if ( ! defined( 'WPINC' ) ) { |
19 | - die; |
|
19 | + die; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class AyeCode_UI_Plugin { |
23 | 23 | |
24 | - /** |
|
25 | - * AUI Plugin constructor. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - // load AUI |
|
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | - |
|
34 | - // Maybe show example page |
|
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | - } |
|
37 | - |
|
38 | - public function maybe_show_examples(){ |
|
39 | - if ( current_user_can( 'manage_options' ) && isset( $_REQUEST['preview-aui'] ) ) { |
|
40 | - echo "<head>"; |
|
41 | - wp_head(); |
|
42 | - echo "</head>"; |
|
43 | - echo "<body class='bsui'>"; |
|
44 | - echo $this->get_examples(); |
|
45 | - wp_footer(); |
|
46 | - echo "</body>"; |
|
47 | - exit; |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public function get_examples(){ |
|
52 | - $output = ''; |
|
53 | - |
|
54 | - // open form |
|
55 | - $output .= "<form class='p-5 m-5 border rounded bg-white'>"; |
|
56 | - |
|
57 | - $output .= aui()->input( |
|
58 | - array( |
|
59 | - 'type' => 'datepicker', |
|
60 | - 'id' => 'date_example_sm', |
|
61 | - 'size' => 'sm', |
|
62 | - 'name' => 'date_example_sm', |
|
63 | - 'label' => 'Date Input Label (small)', |
|
64 | - 'help_text' => 'help text', |
|
65 | - 'label_type' => 'top', |
|
66 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
67 | - 'value' => '', |
|
68 | - 'extra_attributes' => array( |
|
69 | - 'data-enable-time' => 'true', |
|
70 | - 'data-time_24hr' => 'true', |
|
71 | - 'data-allow-input' => 'true', |
|
72 | - ), |
|
73 | - ) |
|
74 | - ); |
|
75 | - |
|
76 | - $output .= aui()->input( |
|
77 | - array( |
|
78 | - 'type' => 'datepicker', |
|
79 | - 'id' => 'date_example', |
|
80 | - //'size' => 'smx', |
|
81 | - 'name' => 'date_example', |
|
82 | - 'label' => 'Date Input Label', |
|
83 | - 'help_text' => 'help text', |
|
84 | - 'label_type' => 'top', |
|
85 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
86 | - 'value' => '', |
|
87 | - 'extra_attributes' => array( |
|
88 | - 'data-enable-time' => 'true', |
|
89 | - 'data-time_24hr' => 'true', |
|
90 | - 'data-allow-input' => 'true', |
|
91 | - ), |
|
92 | - ) |
|
93 | - ); |
|
94 | - |
|
95 | - $output .= aui()->input( |
|
96 | - array( |
|
97 | - 'type' => 'datepicker', |
|
98 | - 'id' => 'date_example_lg', |
|
99 | - 'size' => 'lg', |
|
100 | - 'name' => 'date_example_lg', |
|
101 | - 'label' => 'Date Input Label (large)', |
|
102 | - 'help_text' => 'help text', |
|
103 | - 'label_type' => 'top', |
|
104 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
105 | - 'value' => '', |
|
106 | - 'extra_attributes' => array( |
|
107 | - 'data-enable-time' => 'true', |
|
108 | - 'data-time_24hr' => 'true', |
|
109 | - //'data-allow-input' => 'true', |
|
110 | - ), |
|
111 | - ) |
|
112 | - ); |
|
113 | - |
|
114 | - // input example |
|
115 | - $output .= aui()->input( |
|
116 | - array( |
|
117 | - 'type' => 'text', |
|
118 | - 'id' => 'text-example', |
|
119 | - 'size' => 'sm', |
|
120 | - //'clear_icon' => true, |
|
121 | - 'name' => 'text-example', |
|
122 | - 'placeholder' => 'text placeholder', |
|
123 | - 'title' => 'Text input example', |
|
124 | - 'value' => '', |
|
125 | - 'required' => false, |
|
126 | - 'help_text' => 'help text', |
|
127 | - 'label' => 'Text input example label', |
|
128 | - 'label_type' => 'top' |
|
129 | - ) |
|
130 | - ); |
|
131 | - |
|
132 | - $output .= aui()->input( |
|
133 | - array( |
|
134 | - 'type' => 'search', |
|
135 | - 'id' => 'text-example', |
|
136 | - 'size' => 'sm', |
|
137 | - //'clear_icon' => true, |
|
138 | - 'name' => 'text-example', |
|
139 | - 'placeholder' => 'text placeholder', |
|
140 | - 'title' => 'Text input example', |
|
141 | - 'value' => '', |
|
142 | - 'required' => false, |
|
143 | - 'help_text' => 'help text', |
|
144 | - 'label' => 'Text input example label', |
|
145 | - 'label_type' => 'top' |
|
146 | - ) |
|
147 | - ); |
|
148 | - |
|
149 | - // input example |
|
150 | - $output .= aui()->input( |
|
151 | - array( |
|
152 | - 'type' => 'url', |
|
153 | - 'id' => 'text-example2', |
|
154 | - 'name' => 'text-example', |
|
155 | - 'placeholder' => 'url placeholder', |
|
156 | - 'title' => 'Text input example', |
|
157 | - 'value' => '', |
|
158 | - 'required' => false, |
|
159 | - 'help_text' => 'help text', |
|
160 | - 'label' => 'Text input example label' |
|
161 | - ) |
|
162 | - ); |
|
163 | - |
|
164 | - // checkbox example |
|
165 | - $output .= aui()->input( |
|
166 | - array( |
|
167 | - 'type' => 'checkbox', |
|
168 | - 'id' => 'checkbox-example', |
|
169 | - 'name' => 'checkbox-example', |
|
170 | - 'placeholder' => 'checkbox-example', |
|
171 | - 'title' => 'Checkbox example', |
|
172 | - 'value' => '1', |
|
173 | - 'checked' => true, |
|
174 | - 'required' => false, |
|
175 | - 'help_text' => 'help text', |
|
176 | - 'label' => 'Checkbox checked' |
|
177 | - ) |
|
178 | - ); |
|
179 | - |
|
180 | - // checkbox example |
|
181 | - $output .= aui()->input( |
|
182 | - array( |
|
183 | - 'type' => 'checkbox', |
|
184 | - 'id' => 'checkbox-example2', |
|
185 | - 'name' => 'checkbox-example2', |
|
186 | - 'placeholder' => 'checkbox-example', |
|
187 | - 'title' => 'Checkbox example', |
|
188 | - 'value' => '1', |
|
189 | - 'checked' => false, |
|
190 | - 'required' => false, |
|
191 | - 'help_text' => 'help text', |
|
192 | - 'label' => 'Checkbox un-checked' |
|
193 | - ) |
|
194 | - ); |
|
195 | - |
|
196 | - // switch example |
|
197 | - $output .= aui()->input( |
|
198 | - array( |
|
199 | - 'type' => 'checkbox', |
|
200 | - 'id' => 'switch-example', |
|
201 | - 'name' => 'switch-example', |
|
202 | - 'placeholder' => 'checkbox-example', |
|
203 | - 'title' => 'Switch example', |
|
204 | - 'value' => '1', |
|
205 | - 'checked' => true, |
|
206 | - 'switch' => true, |
|
207 | - 'required' => false, |
|
208 | - 'help_text' => 'help text', |
|
209 | - 'label' => 'Switch on' |
|
210 | - ) |
|
211 | - ); |
|
212 | - |
|
213 | - // switch example |
|
214 | - $output .= aui()->input( |
|
215 | - array( |
|
216 | - 'type' => 'checkbox', |
|
217 | - 'id' => 'switch-example2', |
|
218 | - 'name' => 'switch-example2', |
|
219 | - 'placeholder' => 'checkbox-example', |
|
220 | - 'title' => 'Switch example', |
|
221 | - 'value' => '1', |
|
222 | - 'checked' => false, |
|
223 | - 'switch' => true, |
|
224 | - 'required' => false, |
|
225 | - 'help_text' => 'help text', |
|
226 | - 'label' => 'Switch off' |
|
227 | - ) |
|
228 | - ); |
|
229 | - |
|
230 | - // close form |
|
231 | - $output .= "</form>"; |
|
232 | - |
|
233 | - return $output; |
|
234 | - } |
|
24 | + /** |
|
25 | + * AUI Plugin constructor. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + // load AUI |
|
32 | + require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | + |
|
34 | + // Maybe show example page |
|
35 | + add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | + } |
|
37 | + |
|
38 | + public function maybe_show_examples(){ |
|
39 | + if ( current_user_can( 'manage_options' ) && isset( $_REQUEST['preview-aui'] ) ) { |
|
40 | + echo "<head>"; |
|
41 | + wp_head(); |
|
42 | + echo "</head>"; |
|
43 | + echo "<body class='bsui'>"; |
|
44 | + echo $this->get_examples(); |
|
45 | + wp_footer(); |
|
46 | + echo "</body>"; |
|
47 | + exit; |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public function get_examples(){ |
|
52 | + $output = ''; |
|
53 | + |
|
54 | + // open form |
|
55 | + $output .= "<form class='p-5 m-5 border rounded bg-white'>"; |
|
56 | + |
|
57 | + $output .= aui()->input( |
|
58 | + array( |
|
59 | + 'type' => 'datepicker', |
|
60 | + 'id' => 'date_example_sm', |
|
61 | + 'size' => 'sm', |
|
62 | + 'name' => 'date_example_sm', |
|
63 | + 'label' => 'Date Input Label (small)', |
|
64 | + 'help_text' => 'help text', |
|
65 | + 'label_type' => 'top', |
|
66 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
67 | + 'value' => '', |
|
68 | + 'extra_attributes' => array( |
|
69 | + 'data-enable-time' => 'true', |
|
70 | + 'data-time_24hr' => 'true', |
|
71 | + 'data-allow-input' => 'true', |
|
72 | + ), |
|
73 | + ) |
|
74 | + ); |
|
75 | + |
|
76 | + $output .= aui()->input( |
|
77 | + array( |
|
78 | + 'type' => 'datepicker', |
|
79 | + 'id' => 'date_example', |
|
80 | + //'size' => 'smx', |
|
81 | + 'name' => 'date_example', |
|
82 | + 'label' => 'Date Input Label', |
|
83 | + 'help_text' => 'help text', |
|
84 | + 'label_type' => 'top', |
|
85 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
86 | + 'value' => '', |
|
87 | + 'extra_attributes' => array( |
|
88 | + 'data-enable-time' => 'true', |
|
89 | + 'data-time_24hr' => 'true', |
|
90 | + 'data-allow-input' => 'true', |
|
91 | + ), |
|
92 | + ) |
|
93 | + ); |
|
94 | + |
|
95 | + $output .= aui()->input( |
|
96 | + array( |
|
97 | + 'type' => 'datepicker', |
|
98 | + 'id' => 'date_example_lg', |
|
99 | + 'size' => 'lg', |
|
100 | + 'name' => 'date_example_lg', |
|
101 | + 'label' => 'Date Input Label (large)', |
|
102 | + 'help_text' => 'help text', |
|
103 | + 'label_type' => 'top', |
|
104 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
105 | + 'value' => '', |
|
106 | + 'extra_attributes' => array( |
|
107 | + 'data-enable-time' => 'true', |
|
108 | + 'data-time_24hr' => 'true', |
|
109 | + //'data-allow-input' => 'true', |
|
110 | + ), |
|
111 | + ) |
|
112 | + ); |
|
113 | + |
|
114 | + // input example |
|
115 | + $output .= aui()->input( |
|
116 | + array( |
|
117 | + 'type' => 'text', |
|
118 | + 'id' => 'text-example', |
|
119 | + 'size' => 'sm', |
|
120 | + //'clear_icon' => true, |
|
121 | + 'name' => 'text-example', |
|
122 | + 'placeholder' => 'text placeholder', |
|
123 | + 'title' => 'Text input example', |
|
124 | + 'value' => '', |
|
125 | + 'required' => false, |
|
126 | + 'help_text' => 'help text', |
|
127 | + 'label' => 'Text input example label', |
|
128 | + 'label_type' => 'top' |
|
129 | + ) |
|
130 | + ); |
|
131 | + |
|
132 | + $output .= aui()->input( |
|
133 | + array( |
|
134 | + 'type' => 'search', |
|
135 | + 'id' => 'text-example', |
|
136 | + 'size' => 'sm', |
|
137 | + //'clear_icon' => true, |
|
138 | + 'name' => 'text-example', |
|
139 | + 'placeholder' => 'text placeholder', |
|
140 | + 'title' => 'Text input example', |
|
141 | + 'value' => '', |
|
142 | + 'required' => false, |
|
143 | + 'help_text' => 'help text', |
|
144 | + 'label' => 'Text input example label', |
|
145 | + 'label_type' => 'top' |
|
146 | + ) |
|
147 | + ); |
|
148 | + |
|
149 | + // input example |
|
150 | + $output .= aui()->input( |
|
151 | + array( |
|
152 | + 'type' => 'url', |
|
153 | + 'id' => 'text-example2', |
|
154 | + 'name' => 'text-example', |
|
155 | + 'placeholder' => 'url placeholder', |
|
156 | + 'title' => 'Text input example', |
|
157 | + 'value' => '', |
|
158 | + 'required' => false, |
|
159 | + 'help_text' => 'help text', |
|
160 | + 'label' => 'Text input example label' |
|
161 | + ) |
|
162 | + ); |
|
163 | + |
|
164 | + // checkbox example |
|
165 | + $output .= aui()->input( |
|
166 | + array( |
|
167 | + 'type' => 'checkbox', |
|
168 | + 'id' => 'checkbox-example', |
|
169 | + 'name' => 'checkbox-example', |
|
170 | + 'placeholder' => 'checkbox-example', |
|
171 | + 'title' => 'Checkbox example', |
|
172 | + 'value' => '1', |
|
173 | + 'checked' => true, |
|
174 | + 'required' => false, |
|
175 | + 'help_text' => 'help text', |
|
176 | + 'label' => 'Checkbox checked' |
|
177 | + ) |
|
178 | + ); |
|
179 | + |
|
180 | + // checkbox example |
|
181 | + $output .= aui()->input( |
|
182 | + array( |
|
183 | + 'type' => 'checkbox', |
|
184 | + 'id' => 'checkbox-example2', |
|
185 | + 'name' => 'checkbox-example2', |
|
186 | + 'placeholder' => 'checkbox-example', |
|
187 | + 'title' => 'Checkbox example', |
|
188 | + 'value' => '1', |
|
189 | + 'checked' => false, |
|
190 | + 'required' => false, |
|
191 | + 'help_text' => 'help text', |
|
192 | + 'label' => 'Checkbox un-checked' |
|
193 | + ) |
|
194 | + ); |
|
195 | + |
|
196 | + // switch example |
|
197 | + $output .= aui()->input( |
|
198 | + array( |
|
199 | + 'type' => 'checkbox', |
|
200 | + 'id' => 'switch-example', |
|
201 | + 'name' => 'switch-example', |
|
202 | + 'placeholder' => 'checkbox-example', |
|
203 | + 'title' => 'Switch example', |
|
204 | + 'value' => '1', |
|
205 | + 'checked' => true, |
|
206 | + 'switch' => true, |
|
207 | + 'required' => false, |
|
208 | + 'help_text' => 'help text', |
|
209 | + 'label' => 'Switch on' |
|
210 | + ) |
|
211 | + ); |
|
212 | + |
|
213 | + // switch example |
|
214 | + $output .= aui()->input( |
|
215 | + array( |
|
216 | + 'type' => 'checkbox', |
|
217 | + 'id' => 'switch-example2', |
|
218 | + 'name' => 'switch-example2', |
|
219 | + 'placeholder' => 'checkbox-example', |
|
220 | + 'title' => 'Switch example', |
|
221 | + 'value' => '1', |
|
222 | + 'checked' => false, |
|
223 | + 'switch' => true, |
|
224 | + 'required' => false, |
|
225 | + 'help_text' => 'help text', |
|
226 | + 'label' => 'Switch off' |
|
227 | + ) |
|
228 | + ); |
|
229 | + |
|
230 | + // close form |
|
231 | + $output .= "</form>"; |
|
232 | + |
|
233 | + return $output; |
|
234 | + } |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | new AyeCode_UI_Plugin(); |
238 | 238 | \ No newline at end of file |
@@ -993,8 +993,8 @@ |
||
993 | 993 | aui_flip_color_scheme_on_scroll(); |
994 | 994 | |
995 | 995 | <?php |
996 | - // FSE tweaks. |
|
997 | - if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?> |
|
996 | + // FSE tweaks. |
|
997 | + if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?> |
|
998 | 998 | function aui_fse_set_data_scroll() { |
999 | 999 | console.log('init scroll'); |
1000 | 1000 | let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas"); |
@@ -15,125 +15,125 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $data_store_name = 'subscription'; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'subscription'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Item Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'customer_id' => 0, |
|
40 | - 'frequency' => 1, |
|
41 | - 'period' => 'D', |
|
42 | - 'initial_amount' => null, |
|
43 | - 'recurring_amount' => null, |
|
44 | - 'bill_times' => 0, |
|
45 | - 'transaction_id' => '', |
|
46 | - 'parent_payment_id' => null, |
|
47 | - 'product_id' => 0, |
|
48 | - 'created' => '0000-00-00 00:00:00', |
|
49 | - 'expiration' => '0000-00-00 00:00:00', |
|
50 | - 'trial_period' => '', |
|
51 | - 'status' => 'pending', |
|
52 | - 'profile_id' => '', |
|
53 | - 'gateway' => '', |
|
54 | - 'customer' => '', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * Stores the status transition information. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $status_transition = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | - * |
|
68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | - * @param bool $deprecated |
|
70 | - */ |
|
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | - |
|
73 | - parent::__construct( $subscription ); |
|
74 | - |
|
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | - $this->set_id( $subscription_id ); |
|
81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
82 | - $this->set_id( $subscription->id ); |
|
83 | - } else { |
|
84 | - $this->set_object_read( true ); |
|
85 | - } |
|
86 | - |
|
87 | - // Load the datastore. |
|
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | - |
|
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | - * |
|
99 | - * |
|
100 | - * @static |
|
101 | - * @param string $value |
|
102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | - * @since 1.0.19 |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $data_store_name = 'subscription'; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'subscription'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Item Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'customer_id' => 0, |
|
40 | + 'frequency' => 1, |
|
41 | + 'period' => 'D', |
|
42 | + 'initial_amount' => null, |
|
43 | + 'recurring_amount' => null, |
|
44 | + 'bill_times' => 0, |
|
45 | + 'transaction_id' => '', |
|
46 | + 'parent_payment_id' => null, |
|
47 | + 'product_id' => 0, |
|
48 | + 'created' => '0000-00-00 00:00:00', |
|
49 | + 'expiration' => '0000-00-00 00:00:00', |
|
50 | + 'trial_period' => '', |
|
51 | + 'status' => 'pending', |
|
52 | + 'profile_id' => '', |
|
53 | + 'gateway' => '', |
|
54 | + 'customer' => '', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * Stores the status transition information. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $status_transition = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | + * |
|
68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | + * @param bool $deprecated |
|
70 | + */ |
|
71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | + |
|
73 | + parent::__construct( $subscription ); |
|
74 | + |
|
75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | + $this->set_id( $subscription ); |
|
77 | + } elseif ( $subscription instanceof self ) { |
|
78 | + $this->set_id( $subscription->get_id() ); |
|
79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | + $this->set_id( $subscription_id ); |
|
81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
82 | + $this->set_id( $subscription->id ); |
|
83 | + } else { |
|
84 | + $this->set_object_read( true ); |
|
85 | + } |
|
86 | + |
|
87 | + // Load the datastore. |
|
88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | + |
|
90 | + if ( $this->get_id() > 0 ) { |
|
91 | + $this->data_store->read( $this ); |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | + * |
|
99 | + * |
|
100 | + * @static |
|
101 | + * @param string $value |
|
102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | + * @since 1.0.19 |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - // Trim the value. |
|
110 | - $value = trim( $value ); |
|
109 | + // Trim the value. |
|
110 | + $value = trim( $value ); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
113 | - return 0; |
|
114 | - } |
|
112 | + if ( empty( $value ) ) { |
|
113 | + return 0; |
|
114 | + } |
|
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
117 | - $field = 'parent_payment_id'; |
|
118 | - } |
|
116 | + if ( 'invoice_id' == $field ) { |
|
117 | + $field = 'parent_payment_id'; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | // Valid fields. |
121 | 121 | $fields = array( |
122 | - 'parent_payment_id', |
|
123 | - 'transaction_id', |
|
124 | - 'profile_id', |
|
125 | - ); |
|
126 | - |
|
127 | - // Ensure a field has been passed. |
|
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | - return 0; |
|
130 | - } |
|
131 | - |
|
132 | - // Maybe retrieve from the cache. |
|
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
135 | - return $subscription_id; |
|
136 | - } |
|
122 | + 'parent_payment_id', |
|
123 | + 'transaction_id', |
|
124 | + 'profile_id', |
|
125 | + ); |
|
126 | + |
|
127 | + // Ensure a field has been passed. |
|
128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | + return 0; |
|
130 | + } |
|
131 | + |
|
132 | + // Maybe retrieve from the cache. |
|
133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | + if ( ! empty( $subscription_id ) ) { |
|
135 | + return $subscription_id; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,34 +141,34 @@ discard block |
||
141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
145 | - return 0; |
|
146 | - } |
|
144 | + if ( empty( $subscription_id ) ) { |
|
145 | + return 0; |
|
146 | + } |
|
147 | 147 | |
148 | - // Update the cache with our data. |
|
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
148 | + // Update the cache with our data. |
|
149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
150 | 150 | |
151 | - return $subscription_id; |
|
152 | - } |
|
151 | + return $subscription_id; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
154 | + /** |
|
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
162 | - } |
|
158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
164 | + /** |
|
165 | 165 | * Checks if a subscription key is set. |
166 | 166 | */ |
167 | 167 | public function _isset( $key ) { |
168 | 168 | return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /* |
|
171 | + /* |
|
172 | 172 | |-------------------------------------------------------------------------- |
173 | 173 | | CRUD methods |
174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,544 +177,544 @@ discard block |
||
177 | 177 | | |
178 | 178 | */ |
179 | 179 | |
180 | - /* |
|
180 | + /* |
|
181 | 181 | |-------------------------------------------------------------------------- |
182 | 182 | | Getters |
183 | 183 | |-------------------------------------------------------------------------- |
184 | 184 | */ |
185 | 185 | |
186 | - /** |
|
187 | - * Get customer id. |
|
188 | - * |
|
189 | - * @since 1.0.19 |
|
190 | - * @param string $context View or edit context. |
|
191 | - * @return int |
|
192 | - */ |
|
193 | - public function get_customer_id( $context = 'view' ) { |
|
194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Get customer information. |
|
199 | - * |
|
200 | - * @since 1.0.19 |
|
201 | - * @param string $context View or edit context. |
|
202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
203 | - */ |
|
204 | - public function get_customer( $context = 'view' ) { |
|
205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Get parent invoice id. |
|
210 | - * |
|
211 | - * @since 1.0.19 |
|
212 | - * @param string $context View or edit context. |
|
213 | - * @return int |
|
214 | - */ |
|
215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Alias for self::get_parent_invoice_id(). |
|
221 | - * |
|
222 | - * @since 1.0.19 |
|
223 | - * @param string $context View or edit context. |
|
224 | - * @return int |
|
225 | - */ |
|
186 | + /** |
|
187 | + * Get customer id. |
|
188 | + * |
|
189 | + * @since 1.0.19 |
|
190 | + * @param string $context View or edit context. |
|
191 | + * @return int |
|
192 | + */ |
|
193 | + public function get_customer_id( $context = 'view' ) { |
|
194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Get customer information. |
|
199 | + * |
|
200 | + * @since 1.0.19 |
|
201 | + * @param string $context View or edit context. |
|
202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
203 | + */ |
|
204 | + public function get_customer( $context = 'view' ) { |
|
205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Get parent invoice id. |
|
210 | + * |
|
211 | + * @since 1.0.19 |
|
212 | + * @param string $context View or edit context. |
|
213 | + * @return int |
|
214 | + */ |
|
215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Alias for self::get_parent_invoice_id(). |
|
221 | + * |
|
222 | + * @since 1.0.19 |
|
223 | + * @param string $context View or edit context. |
|
224 | + * @return int |
|
225 | + */ |
|
226 | 226 | public function get_parent_payment_id( $context = 'view' ) { |
227 | 227 | return $this->get_parent_invoice_id( $context ); |
228 | - } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Alias for self::get_parent_invoice_id(). |
|
232 | + * |
|
233 | + * @since 1.0.0 |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + public function get_original_payment_id( $context = 'view' ) { |
|
237 | + return $this->get_parent_invoice_id( $context ); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Get parent invoice. |
|
242 | + * |
|
243 | + * @since 1.0.19 |
|
244 | + * @param string $context View or edit context. |
|
245 | + * @return WPInv_Invoice |
|
246 | + */ |
|
247 | + public function get_parent_invoice( $context = 'view' ) { |
|
248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Alias for self::get_parent_invoice(). |
|
253 | + * |
|
254 | + * @since 1.0.19 |
|
255 | + * @param string $context View or edit context. |
|
256 | + * @return WPInv_Invoice |
|
257 | + */ |
|
258 | + public function get_parent_payment( $context = 'view' ) { |
|
259 | + return $this->get_parent_invoice( $context ); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Get subscription's product id. |
|
264 | + * |
|
265 | + * @since 1.0.19 |
|
266 | + * @param string $context View or edit context. |
|
267 | + * @return int |
|
268 | + */ |
|
269 | + public function get_product_id( $context = 'view' ) { |
|
270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Get the subscription product. |
|
275 | + * |
|
276 | + * @since 1.0.19 |
|
277 | + * @param string $context View or edit context. |
|
278 | + * @return WPInv_Item |
|
279 | + */ |
|
280 | + public function get_product( $context = 'view' ) { |
|
281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Get parent invoice's gateway. |
|
286 | + * |
|
287 | + * Here for backwards compatibility. |
|
288 | + * |
|
289 | + * @since 1.0.19 |
|
290 | + * @param string $context View or edit context. |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + public function get_gateway( $context = 'view' ) { |
|
294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get the period of a renewal. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @param string $context View or edit context. |
|
302 | + * @return string |
|
303 | + */ |
|
304 | + public function get_period( $context = 'view' ) { |
|
305 | + return $this->get_prop( 'period', $context ); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Get number of periods each renewal is valid for. |
|
310 | + * |
|
311 | + * @since 1.0.19 |
|
312 | + * @param string $context View or edit context. |
|
313 | + * @return int |
|
314 | + */ |
|
315 | + public function get_frequency( $context = 'view' ) { |
|
316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Get the initial amount for the subscription. |
|
321 | + * |
|
322 | + * @since 1.0.19 |
|
323 | + * @param string $context View or edit context. |
|
324 | + * @return float |
|
325 | + */ |
|
326 | + public function get_initial_amount( $context = 'view' ) { |
|
327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Get the recurring amount for the subscription. |
|
332 | + * |
|
333 | + * @since 1.0.19 |
|
334 | + * @param string $context View or edit context. |
|
335 | + * @return float |
|
336 | + */ |
|
337 | + public function get_recurring_amount( $context = 'view' ) { |
|
338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Get number of times that this subscription can be renewed. |
|
343 | + * |
|
344 | + * @since 1.0.19 |
|
345 | + * @param string $context View or edit context. |
|
346 | + * @return int |
|
347 | + */ |
|
348 | + public function get_bill_times( $context = 'view' ) { |
|
349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Get transaction id of this subscription's parent invoice. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + * @param string $context View or edit context. |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function get_transaction_id( $context = 'view' ) { |
|
360 | + return $this->get_prop( 'transaction_id', $context ); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Get the date that the subscription was created. |
|
365 | + * |
|
366 | + * @since 1.0.19 |
|
367 | + * @param string $context View or edit context. |
|
368 | + * @return string |
|
369 | + */ |
|
370 | + public function get_created( $context = 'view' ) { |
|
371 | + return $this->get_prop( 'created', $context ); |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Alias for self::get_created(). |
|
376 | + * |
|
377 | + * @since 1.0.19 |
|
378 | + * @param string $context View or edit context. |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + public function get_date_created( $context = 'view' ) { |
|
382 | + return $this->get_created( $context ); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Retrieves the creation date in a timestamp |
|
387 | + * |
|
388 | + * @since 1.0.0 |
|
389 | + * @return int |
|
390 | + */ |
|
391 | + public function get_time_created() { |
|
392 | + $created = $this->get_date_created(); |
|
393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * Get GMT date when the subscription was created. |
|
398 | + * |
|
399 | + * @since 1.0.19 |
|
400 | + * @param string $context View or edit context. |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
404 | + $date = $this->get_date_created( $context ); |
|
405 | + |
|
406 | + if ( $date ) { |
|
407 | + $date = get_gmt_from_date( $date ); |
|
408 | + } |
|
409 | + return $date; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Get the date that the subscription will renew. |
|
414 | + * |
|
415 | + * @since 1.0.19 |
|
416 | + * @param string $context View or edit context. |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
420 | + return $this->get_prop( 'expiration', $context ); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Alias for self::get_next_renewal_date(). |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + * @param string $context View or edit context. |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function get_expiration( $context = 'view' ) { |
|
431 | + return $this->get_next_renewal_date( $context ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Retrieves the expiration date in a timestamp |
|
436 | + * |
|
437 | + * @since 1.0.0 |
|
438 | + * @return int |
|
439 | + */ |
|
440 | + public function get_expiration_time() { |
|
441 | + $expiration = $this->get_expiration(); |
|
442 | + |
|
443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | + return current_time( 'timestamp' ); |
|
445 | + } |
|
446 | + |
|
447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Get GMT date when the subscription will renew. |
|
453 | + * |
|
454 | + * @since 1.0.19 |
|
455 | + * @param string $context View or edit context. |
|
456 | + * @return string |
|
457 | + */ |
|
458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
459 | + $date = $this->get_next_renewal_date( $context ); |
|
460 | + |
|
461 | + if ( $date ) { |
|
462 | + $date = get_gmt_from_date( $date ); |
|
463 | + } |
|
464 | + return $date; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Get the subscription's trial period. |
|
469 | + * |
|
470 | + * @since 1.0.19 |
|
471 | + * @param string $context View or edit context. |
|
472 | + * @return string |
|
473 | + */ |
|
474 | + public function get_trial_period( $context = 'view' ) { |
|
475 | + return $this->get_prop( 'trial_period', $context ); |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Get the subscription's status. |
|
480 | + * |
|
481 | + * @since 1.0.19 |
|
482 | + * @param string $context View or edit context. |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + public function get_status( $context = 'view' ) { |
|
486 | + return $this->get_prop( 'status', $context ); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Get the subscription's profile id. |
|
491 | + * |
|
492 | + * @since 1.0.19 |
|
493 | + * @param string $context View or edit context. |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + public function get_profile_id( $context = 'view' ) { |
|
497 | + return $this->get_prop( 'profile_id', $context ); |
|
498 | + } |
|
499 | + |
|
500 | + /* |
|
501 | + |-------------------------------------------------------------------------- |
|
502 | + | Setters |
|
503 | + |-------------------------------------------------------------------------- |
|
504 | + */ |
|
505 | + |
|
506 | + /** |
|
507 | + * Set customer id. |
|
508 | + * |
|
509 | + * @since 1.0.19 |
|
510 | + * @param int $value The customer's id. |
|
511 | + */ |
|
512 | + public function set_customer_id( $value ) { |
|
513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Set parent invoice id. |
|
518 | + * |
|
519 | + * @since 1.0.19 |
|
520 | + * @param int $value The parent invoice id. |
|
521 | + */ |
|
522 | + public function set_parent_invoice_id( $value ) { |
|
523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Alias for self::set_parent_invoice_id(). |
|
528 | + * |
|
529 | + * @since 1.0.19 |
|
530 | + * @param int $value The parent invoice id. |
|
531 | + */ |
|
532 | + public function set_parent_payment_id( $value ) { |
|
533 | + $this->set_parent_invoice_id( $value ); |
|
534 | + } |
|
535 | + |
|
536 | + /** |
|
537 | + * Alias for self::set_parent_invoice_id(). |
|
538 | + * |
|
539 | + * @since 1.0.19 |
|
540 | + * @param int $value The parent invoice id. |
|
541 | + */ |
|
542 | + public function set_original_payment_id( $value ) { |
|
543 | + $this->set_parent_invoice_id( $value ); |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Set subscription's product id. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param int $value The subscription product id. |
|
551 | + */ |
|
552 | + public function set_product_id( $value ) { |
|
553 | + $this->set_prop( 'product_id', (int) $value ); |
|
554 | + } |
|
555 | + |
|
556 | + /** |
|
557 | + * Set the period of a renewal. |
|
558 | + * |
|
559 | + * @since 1.0.19 |
|
560 | + * @param string $value The renewal period. |
|
561 | + */ |
|
562 | + public function set_period( $value ) { |
|
563 | + $this->set_prop( 'period', $value ); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Set number of periods each renewal is valid for. |
|
568 | + * |
|
569 | + * @since 1.0.19 |
|
570 | + * @param int $value The subscription frequency. |
|
571 | + */ |
|
572 | + public function set_frequency( $value ) { |
|
573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Set the initial amount for the subscription. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + * @param float $value The initial subcription amount. |
|
582 | + */ |
|
583 | + public function set_initial_amount( $value ) { |
|
584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Set the recurring amount for the subscription. |
|
589 | + * |
|
590 | + * @since 1.0.19 |
|
591 | + * @param float $value The recurring subcription amount. |
|
592 | + */ |
|
593 | + public function set_recurring_amount( $value ) { |
|
594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Set number of times that this subscription can be renewed. |
|
599 | + * |
|
600 | + * @since 1.0.19 |
|
601 | + * @param int $value Bill times. |
|
602 | + */ |
|
603 | + public function set_bill_times( $value ) { |
|
604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
605 | + } |
|
606 | + |
|
607 | + /** |
|
608 | + * Get transaction id of this subscription's parent invoice. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @param string $value Bill times. |
|
612 | + */ |
|
613 | + public function set_transaction_id( $value ) { |
|
614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Set date when this subscription started. |
|
619 | + * |
|
620 | + * @since 1.0.19 |
|
621 | + * @param string $value strtotime compliant date. |
|
622 | + */ |
|
623 | + public function set_created( $value ) { |
|
624 | + $date = strtotime( $value ); |
|
625 | + |
|
626 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
627 | + $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
628 | + return; |
|
629 | + } |
|
630 | + |
|
631 | + $this->set_prop( 'created', '' ); |
|
229 | 632 | |
230 | - /** |
|
231 | - * Alias for self::get_parent_invoice_id(). |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * Alias for self::set_created(). |
|
232 | 637 | * |
233 | - * @since 1.0.0 |
|
234 | - * @return int |
|
638 | + * @since 1.0.19 |
|
639 | + * @param string $value strtotime compliant date. |
|
235 | 640 | */ |
236 | - public function get_original_payment_id( $context = 'view' ) { |
|
237 | - return $this->get_parent_invoice_id( $context ); |
|
641 | + public function set_date_created( $value ) { |
|
642 | + $this->set_created( $value ); |
|
238 | 643 | } |
239 | 644 | |
240 | - /** |
|
241 | - * Get parent invoice. |
|
242 | - * |
|
243 | - * @since 1.0.19 |
|
244 | - * @param string $context View or edit context. |
|
245 | - * @return WPInv_Invoice |
|
246 | - */ |
|
247 | - public function get_parent_invoice( $context = 'view' ) { |
|
248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Alias for self::get_parent_invoice(). |
|
253 | - * |
|
254 | - * @since 1.0.19 |
|
255 | - * @param string $context View or edit context. |
|
256 | - * @return WPInv_Invoice |
|
257 | - */ |
|
258 | - public function get_parent_payment( $context = 'view' ) { |
|
259 | - return $this->get_parent_invoice( $context ); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Get subscription's product id. |
|
264 | - * |
|
265 | - * @since 1.0.19 |
|
266 | - * @param string $context View or edit context. |
|
267 | - * @return int |
|
268 | - */ |
|
269 | - public function get_product_id( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Get the subscription product. |
|
275 | - * |
|
276 | - * @since 1.0.19 |
|
277 | - * @param string $context View or edit context. |
|
278 | - * @return WPInv_Item |
|
279 | - */ |
|
280 | - public function get_product( $context = 'view' ) { |
|
281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Get parent invoice's gateway. |
|
286 | - * |
|
287 | - * Here for backwards compatibility. |
|
288 | - * |
|
289 | - * @since 1.0.19 |
|
290 | - * @param string $context View or edit context. |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - public function get_gateway( $context = 'view' ) { |
|
294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get the period of a renewal. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @param string $context View or edit context. |
|
302 | - * @return string |
|
303 | - */ |
|
304 | - public function get_period( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'period', $context ); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Get number of periods each renewal is valid for. |
|
310 | - * |
|
311 | - * @since 1.0.19 |
|
312 | - * @param string $context View or edit context. |
|
313 | - * @return int |
|
314 | - */ |
|
315 | - public function get_frequency( $context = 'view' ) { |
|
316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Get the initial amount for the subscription. |
|
321 | - * |
|
322 | - * @since 1.0.19 |
|
323 | - * @param string $context View or edit context. |
|
324 | - * @return float |
|
325 | - */ |
|
326 | - public function get_initial_amount( $context = 'view' ) { |
|
327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Get the recurring amount for the subscription. |
|
332 | - * |
|
333 | - * @since 1.0.19 |
|
334 | - * @param string $context View or edit context. |
|
335 | - * @return float |
|
336 | - */ |
|
337 | - public function get_recurring_amount( $context = 'view' ) { |
|
338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Get number of times that this subscription can be renewed. |
|
343 | - * |
|
344 | - * @since 1.0.19 |
|
345 | - * @param string $context View or edit context. |
|
346 | - * @return int |
|
347 | - */ |
|
348 | - public function get_bill_times( $context = 'view' ) { |
|
349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Get transaction id of this subscription's parent invoice. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - * @param string $context View or edit context. |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function get_transaction_id( $context = 'view' ) { |
|
360 | - return $this->get_prop( 'transaction_id', $context ); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Get the date that the subscription was created. |
|
365 | - * |
|
366 | - * @since 1.0.19 |
|
367 | - * @param string $context View or edit context. |
|
368 | - * @return string |
|
369 | - */ |
|
370 | - public function get_created( $context = 'view' ) { |
|
371 | - return $this->get_prop( 'created', $context ); |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Alias for self::get_created(). |
|
376 | - * |
|
377 | - * @since 1.0.19 |
|
378 | - * @param string $context View or edit context. |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - public function get_date_created( $context = 'view' ) { |
|
382 | - return $this->get_created( $context ); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Retrieves the creation date in a timestamp |
|
387 | - * |
|
388 | - * @since 1.0.0 |
|
389 | - * @return int |
|
390 | - */ |
|
391 | - public function get_time_created() { |
|
392 | - $created = $this->get_date_created(); |
|
393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * Get GMT date when the subscription was created. |
|
398 | - * |
|
399 | - * @since 1.0.19 |
|
400 | - * @param string $context View or edit context. |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
404 | - $date = $this->get_date_created( $context ); |
|
645 | + /** |
|
646 | + * Set the date that the subscription will renew. |
|
647 | + * |
|
648 | + * @since 1.0.19 |
|
649 | + * @param string $value strtotime compliant date. |
|
650 | + */ |
|
651 | + public function set_next_renewal_date( $value ) { |
|
652 | + $date = strtotime( $value ); |
|
405 | 653 | |
406 | - if ( $date ) { |
|
407 | - $date = get_gmt_from_date( $date ); |
|
654 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
656 | + return; |
|
408 | 657 | } |
409 | - return $date; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Get the date that the subscription will renew. |
|
414 | - * |
|
415 | - * @since 1.0.19 |
|
416 | - * @param string $context View or edit context. |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'expiration', $context ); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Alias for self::get_next_renewal_date(). |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - * @param string $context View or edit context. |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function get_expiration( $context = 'view' ) { |
|
431 | - return $this->get_next_renewal_date( $context ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Retrieves the expiration date in a timestamp |
|
436 | - * |
|
437 | - * @since 1.0.0 |
|
438 | - * @return int |
|
439 | - */ |
|
440 | - public function get_expiration_time() { |
|
441 | - $expiration = $this->get_expiration(); |
|
442 | - |
|
443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | - return current_time( 'timestamp' ); |
|
445 | - } |
|
446 | - |
|
447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Get GMT date when the subscription will renew. |
|
453 | - * |
|
454 | - * @since 1.0.19 |
|
455 | - * @param string $context View or edit context. |
|
456 | - * @return string |
|
457 | - */ |
|
458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
459 | - $date = $this->get_next_renewal_date( $context ); |
|
460 | 658 | |
461 | - if ( $date ) { |
|
462 | - $date = get_gmt_from_date( $date ); |
|
463 | - } |
|
464 | - return $date; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Get the subscription's trial period. |
|
469 | - * |
|
470 | - * @since 1.0.19 |
|
471 | - * @param string $context View or edit context. |
|
472 | - * @return string |
|
473 | - */ |
|
474 | - public function get_trial_period( $context = 'view' ) { |
|
475 | - return $this->get_prop( 'trial_period', $context ); |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Get the subscription's status. |
|
480 | - * |
|
481 | - * @since 1.0.19 |
|
482 | - * @param string $context View or edit context. |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - public function get_status( $context = 'view' ) { |
|
486 | - return $this->get_prop( 'status', $context ); |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Get the subscription's profile id. |
|
491 | - * |
|
492 | - * @since 1.0.19 |
|
493 | - * @param string $context View or edit context. |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - public function get_profile_id( $context = 'view' ) { |
|
497 | - return $this->get_prop( 'profile_id', $context ); |
|
498 | - } |
|
499 | - |
|
500 | - /* |
|
501 | - |-------------------------------------------------------------------------- |
|
502 | - | Setters |
|
503 | - |-------------------------------------------------------------------------- |
|
504 | - */ |
|
659 | + $this->set_prop( 'expiration', '' ); |
|
505 | 660 | |
506 | - /** |
|
507 | - * Set customer id. |
|
508 | - * |
|
509 | - * @since 1.0.19 |
|
510 | - * @param int $value The customer's id. |
|
511 | - */ |
|
512 | - public function set_customer_id( $value ) { |
|
513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Set parent invoice id. |
|
518 | - * |
|
519 | - * @since 1.0.19 |
|
520 | - * @param int $value The parent invoice id. |
|
521 | - */ |
|
522 | - public function set_parent_invoice_id( $value ) { |
|
523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Alias for self::set_parent_invoice_id(). |
|
528 | - * |
|
529 | - * @since 1.0.19 |
|
530 | - * @param int $value The parent invoice id. |
|
531 | - */ |
|
532 | - public function set_parent_payment_id( $value ) { |
|
533 | - $this->set_parent_invoice_id( $value ); |
|
534 | - } |
|
661 | + } |
|
535 | 662 | |
536 | - /** |
|
537 | - * Alias for self::set_parent_invoice_id(). |
|
663 | + /** |
|
664 | + * Alias for self::set_next_renewal_date(). |
|
538 | 665 | * |
539 | 666 | * @since 1.0.19 |
540 | - * @param int $value The parent invoice id. |
|
667 | + * @param string $value strtotime compliant date. |
|
541 | 668 | */ |
542 | - public function set_original_payment_id( $value ) { |
|
543 | - $this->set_parent_invoice_id( $value ); |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Set subscription's product id. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param int $value The subscription product id. |
|
551 | - */ |
|
552 | - public function set_product_id( $value ) { |
|
553 | - $this->set_prop( 'product_id', (int) $value ); |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * Set the period of a renewal. |
|
558 | - * |
|
559 | - * @since 1.0.19 |
|
560 | - * @param string $value The renewal period. |
|
561 | - */ |
|
562 | - public function set_period( $value ) { |
|
563 | - $this->set_prop( 'period', $value ); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Set number of periods each renewal is valid for. |
|
568 | - * |
|
569 | - * @since 1.0.19 |
|
570 | - * @param int $value The subscription frequency. |
|
571 | - */ |
|
572 | - public function set_frequency( $value ) { |
|
573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Set the initial amount for the subscription. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - * @param float $value The initial subcription amount. |
|
582 | - */ |
|
583 | - public function set_initial_amount( $value ) { |
|
584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Set the recurring amount for the subscription. |
|
589 | - * |
|
590 | - * @since 1.0.19 |
|
591 | - * @param float $value The recurring subcription amount. |
|
592 | - */ |
|
593 | - public function set_recurring_amount( $value ) { |
|
594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Set number of times that this subscription can be renewed. |
|
599 | - * |
|
600 | - * @since 1.0.19 |
|
601 | - * @param int $value Bill times. |
|
602 | - */ |
|
603 | - public function set_bill_times( $value ) { |
|
604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
605 | - } |
|
606 | - |
|
607 | - /** |
|
608 | - * Get transaction id of this subscription's parent invoice. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @param string $value Bill times. |
|
612 | - */ |
|
613 | - public function set_transaction_id( $value ) { |
|
614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Set date when this subscription started. |
|
619 | - * |
|
620 | - * @since 1.0.19 |
|
621 | - * @param string $value strtotime compliant date. |
|
622 | - */ |
|
623 | - public function set_created( $value ) { |
|
624 | - $date = strtotime( $value ); |
|
669 | + public function set_expiration( $value ) { |
|
670 | + $this->set_next_renewal_date( $value ); |
|
671 | + } |
|
625 | 672 | |
626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
673 | + /** |
|
674 | + * Set the subscription's trial period. |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + * @param string $value trial period e.g 1 year. |
|
678 | + */ |
|
679 | + public function set_trial_period( $value ) { |
|
680 | + $this->set_prop( 'trial_period', $value ); |
|
681 | + } |
|
682 | + |
|
683 | + /** |
|
684 | + * Set the subscription's status. |
|
685 | + * |
|
686 | + * @since 1.0.19 |
|
687 | + * @param string $new_status New subscription status. |
|
688 | + */ |
|
689 | + public function set_status( $new_status ) { |
|
690 | + |
|
691 | + // Abort if this is not a valid status; |
|
692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
628 | 693 | return; |
629 | 694 | } |
630 | 695 | |
631 | - $this->set_prop( 'created', '' ); |
|
632 | - |
|
633 | - } |
|
696 | + $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
697 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
698 | + $this->status_transition = array( |
|
699 | + 'from' => $old_status, |
|
700 | + 'to' => $new_status, |
|
701 | + ); |
|
702 | + } |
|
634 | 703 | |
635 | - /** |
|
636 | - * Alias for self::set_created(). |
|
637 | - * |
|
638 | - * @since 1.0.19 |
|
639 | - * @param string $value strtotime compliant date. |
|
640 | - */ |
|
641 | - public function set_date_created( $value ) { |
|
642 | - $this->set_created( $value ); |
|
704 | + $this->set_prop( 'status', $new_status ); |
|
643 | 705 | } |
644 | 706 | |
645 | - /** |
|
646 | - * Set the date that the subscription will renew. |
|
647 | - * |
|
648 | - * @since 1.0.19 |
|
649 | - * @param string $value strtotime compliant date. |
|
650 | - */ |
|
651 | - public function set_next_renewal_date( $value ) { |
|
652 | - $date = strtotime( $value ); |
|
707 | + /** |
|
708 | + * Set the subscription's (remote) profile id. |
|
709 | + * |
|
710 | + * @since 1.0.19 |
|
711 | + * @param string $value the remote profile id. |
|
712 | + */ |
|
713 | + public function set_profile_id( $value ) { |
|
714 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
715 | + } |
|
653 | 716 | |
654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
656 | - return; |
|
657 | - } |
|
658 | - |
|
659 | - $this->set_prop( 'expiration', '' ); |
|
660 | - |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * Alias for self::set_next_renewal_date(). |
|
665 | - * |
|
666 | - * @since 1.0.19 |
|
667 | - * @param string $value strtotime compliant date. |
|
668 | - */ |
|
669 | - public function set_expiration( $value ) { |
|
670 | - $this->set_next_renewal_date( $value ); |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Set the subscription's trial period. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @param string $value trial period e.g 1 year. |
|
678 | - */ |
|
679 | - public function set_trial_period( $value ) { |
|
680 | - $this->set_prop( 'trial_period', $value ); |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Set the subscription's status. |
|
685 | - * |
|
686 | - * @since 1.0.19 |
|
687 | - * @param string $new_status New subscription status. |
|
688 | - */ |
|
689 | - public function set_status( $new_status ) { |
|
690 | - |
|
691 | - // Abort if this is not a valid status; |
|
692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
693 | - return; |
|
694 | - } |
|
695 | - |
|
696 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
697 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
698 | - $this->status_transition = array( |
|
699 | - 'from' => $old_status, |
|
700 | - 'to' => $new_status, |
|
701 | - ); |
|
702 | - } |
|
703 | - |
|
704 | - $this->set_prop( 'status', $new_status ); |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * Set the subscription's (remote) profile id. |
|
709 | - * |
|
710 | - * @since 1.0.19 |
|
711 | - * @param string $value the remote profile id. |
|
712 | - */ |
|
713 | - public function set_profile_id( $value ) { |
|
714 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
715 | - } |
|
716 | - |
|
717 | - /* |
|
717 | + /* |
|
718 | 718 | |-------------------------------------------------------------------------- |
719 | 719 | | Boolean methods |
720 | 720 | |-------------------------------------------------------------------------- |
@@ -723,55 +723,55 @@ discard block |
||
723 | 723 | | |
724 | 724 | */ |
725 | 725 | |
726 | - /** |
|
726 | + /** |
|
727 | 727 | * Checks if the subscription has a given status. |
728 | - * |
|
729 | - * @param string|array String or array of strings to check for. |
|
730 | - * @return bool |
|
728 | + * |
|
729 | + * @param string|array String or array of strings to check for. |
|
730 | + * @return bool |
|
731 | 731 | */ |
732 | 732 | public function has_status( $status ) { |
733 | 733 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
734 | - } |
|
734 | + } |
|
735 | 735 | |
736 | - /** |
|
736 | + /** |
|
737 | 737 | * Checks if the subscription has a trial period. |
738 | - * |
|
739 | - * @return bool |
|
738 | + * |
|
739 | + * @return bool |
|
740 | 740 | */ |
741 | 741 | public function has_trial_period() { |
742 | - $period = $this->get_trial_period(); |
|
742 | + $period = $this->get_trial_period(); |
|
743 | 743 | return ! empty( $period ); |
744 | - } |
|
745 | - |
|
746 | - /** |
|
747 | - * Is the subscription active? |
|
748 | - * |
|
749 | - * @return bool |
|
750 | - */ |
|
751 | - public function is_active() { |
|
752 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
753 | - } |
|
754 | - |
|
755 | - /** |
|
756 | - * Is the subscription expired? |
|
757 | - * |
|
758 | - * @return bool |
|
759 | - */ |
|
760 | - public function is_expired() { |
|
761 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
762 | - } |
|
763 | - |
|
764 | - /** |
|
765 | - * Is this the last renewals? |
|
766 | - * |
|
767 | - * @return bool |
|
768 | - */ |
|
769 | - public function is_last_renewal() { |
|
770 | - $max_bills = $this->get_bill_times(); |
|
771 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
772 | - } |
|
773 | - |
|
774 | - /* |
|
744 | + } |
|
745 | + |
|
746 | + /** |
|
747 | + * Is the subscription active? |
|
748 | + * |
|
749 | + * @return bool |
|
750 | + */ |
|
751 | + public function is_active() { |
|
752 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
753 | + } |
|
754 | + |
|
755 | + /** |
|
756 | + * Is the subscription expired? |
|
757 | + * |
|
758 | + * @return bool |
|
759 | + */ |
|
760 | + public function is_expired() { |
|
761 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
762 | + } |
|
763 | + |
|
764 | + /** |
|
765 | + * Is this the last renewals? |
|
766 | + * |
|
767 | + * @return bool |
|
768 | + */ |
|
769 | + public function is_last_renewal() { |
|
770 | + $max_bills = $this->get_bill_times(); |
|
771 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
772 | + } |
|
773 | + |
|
774 | + /* |
|
775 | 775 | |-------------------------------------------------------------------------- |
776 | 776 | | Additional methods |
777 | 777 | |-------------------------------------------------------------------------- |
@@ -780,27 +780,27 @@ discard block |
||
780 | 780 | | |
781 | 781 | */ |
782 | 782 | |
783 | - /** |
|
784 | - * Backwards compatibilty. |
|
785 | - */ |
|
786 | - public function create( $data = array() ) { |
|
783 | + /** |
|
784 | + * Backwards compatibilty. |
|
785 | + */ |
|
786 | + public function create( $data = array() ) { |
|
787 | 787 | |
788 | - // Set the properties. |
|
789 | - if ( is_array( $data ) ) { |
|
790 | - $this->set_props( $data ); |
|
791 | - } |
|
788 | + // Set the properties. |
|
789 | + if ( is_array( $data ) ) { |
|
790 | + $this->set_props( $data ); |
|
791 | + } |
|
792 | 792 | |
793 | - // Save the item. |
|
794 | - return $this->save(); |
|
793 | + // Save the item. |
|
794 | + return $this->save(); |
|
795 | 795 | |
796 | - } |
|
796 | + } |
|
797 | 797 | |
798 | - /** |
|
799 | - * Backwards compatibilty. |
|
800 | - */ |
|
801 | - public function update( $args = array() ) { |
|
802 | - return $this->create( $args ); |
|
803 | - } |
|
798 | + /** |
|
799 | + * Backwards compatibilty. |
|
800 | + */ |
|
801 | + public function update( $args = array() ) { |
|
802 | + return $this->create( $args ); |
|
803 | + } |
|
804 | 804 | |
805 | 805 | /** |
806 | 806 | * Retrieve renewal payments for a subscription |
@@ -810,22 +810,22 @@ discard block |
||
810 | 810 | */ |
811 | 811 | public function get_child_payments( $hide_pending = true ) { |
812 | 812 | |
813 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
813 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
814 | 814 | |
815 | - if ( ! $hide_pending ) { |
|
816 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
817 | - } |
|
815 | + if ( ! $hide_pending ) { |
|
816 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
817 | + } |
|
818 | 818 | |
819 | 819 | return get_posts( |
820 | - array( |
|
821 | - 'post_parent' => $this->get_parent_payment_id(), |
|
822 | - 'numberposts' => -1, |
|
823 | - 'post_status' => $statuses, |
|
824 | - 'orderby' => 'ID', |
|
825 | - 'order' => 'ASC', |
|
826 | - 'post_type' => 'wpi_invoice', |
|
827 | - ) |
|
828 | - ); |
|
820 | + array( |
|
821 | + 'post_parent' => $this->get_parent_payment_id(), |
|
822 | + 'numberposts' => -1, |
|
823 | + 'post_status' => $statuses, |
|
824 | + 'orderby' => 'ID', |
|
825 | + 'order' => 'ASC', |
|
826 | + 'post_type' => 'wpi_invoice', |
|
827 | + ) |
|
828 | + ); |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | /** |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * @return int |
836 | 836 | */ |
837 | 837 | public function get_total_payments() { |
838 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
838 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -859,187 +859,187 @@ discard block |
||
859 | 859 | * |
860 | 860 | * @since 2.4 |
861 | 861 | * @param array $args Array of values for the payment, including amount and transaction ID |
862 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
862 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
863 | 863 | * @return bool |
864 | 864 | */ |
865 | 865 | public function add_payment( $args = array(), $invoice = false ) { |
866 | 866 | |
867 | - // Process each payment once. |
|
867 | + // Process each payment once. |
|
868 | 868 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
869 | 869 | return false; |
870 | 870 | } |
871 | 871 | |
872 | - // Are we creating a new invoice? |
|
873 | - if ( empty( $invoice ) ) { |
|
874 | - $invoice = $this->create_payment( false ); |
|
872 | + // Are we creating a new invoice? |
|
873 | + if ( empty( $invoice ) ) { |
|
874 | + $invoice = $this->create_payment( false ); |
|
875 | 875 | |
876 | - if ( empty( $invoice ) ) { |
|
877 | - return false; |
|
878 | - } |
|
879 | - } |
|
876 | + if ( empty( $invoice ) ) { |
|
877 | + return false; |
|
878 | + } |
|
879 | + } |
|
880 | 880 | |
881 | - // Maybe set a transaction id. |
|
882 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
883 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
884 | - } |
|
881 | + // Maybe set a transaction id. |
|
882 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
883 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
884 | + } |
|
885 | 885 | |
886 | - // Set the completed date. |
|
887 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
886 | + // Set the completed date. |
|
887 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
888 | 888 | |
889 | - // And the gateway. |
|
890 | - if ( ! empty( $args['gateway'] ) ) { |
|
891 | - $invoice->set_gateway( $args['gateway'] ); |
|
892 | - } |
|
889 | + // And the gateway. |
|
890 | + if ( ! empty( $args['gateway'] ) ) { |
|
891 | + $invoice->set_gateway( $args['gateway'] ); |
|
892 | + } |
|
893 | 893 | |
894 | - $invoice->set_status( 'wpi-renewal' ); |
|
895 | - $invoice->save(); |
|
894 | + $invoice->set_status( 'wpi-renewal' ); |
|
895 | + $invoice->save(); |
|
896 | 896 | |
897 | - if ( ! $invoice->exists() ) { |
|
898 | - return false; |
|
899 | - } |
|
897 | + if ( ! $invoice->exists() ) { |
|
898 | + return false; |
|
899 | + } |
|
900 | 900 | |
901 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
902 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
901 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
902 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
903 | 903 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
904 | 904 | |
905 | 905 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
906 | 906 | |
907 | 907 | return $invoice->get_id(); |
908 | - } |
|
908 | + } |
|
909 | 909 | |
910 | - /** |
|
910 | + /** |
|
911 | 911 | * Creates a new invoice and returns it. |
912 | 912 | * |
913 | 913 | * @since 1.0.19 |
914 | - * @param bool $save Whether we should save the invoice. |
|
914 | + * @param bool $save Whether we should save the invoice. |
|
915 | 915 | * @return WPInv_Invoice|bool |
916 | 916 | */ |
917 | 917 | public function create_payment( $save = true ) { |
918 | 918 | |
919 | - $parent_invoice = $this->get_parent_payment(); |
|
920 | - |
|
921 | - if ( ! $parent_invoice->exists() ) { |
|
922 | - return false; |
|
923 | - } |
|
924 | - |
|
925 | - // Duplicate the parent invoice. |
|
926 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
927 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
928 | - $invoice->set_subscription_id( $this->get_id() ); |
|
929 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
930 | - |
|
931 | - // Set invoice items. |
|
932 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
933 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
934 | - $invoice_items = array(); |
|
935 | - |
|
936 | - foreach ( $invoice->get_items() as $item ) { |
|
937 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
938 | - $invoice_items[] = $item; |
|
939 | - } |
|
940 | - } |
|
941 | - |
|
942 | - $invoice->set_items( $invoice_items ); |
|
943 | - |
|
944 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
945 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
946 | - } |
|
947 | - |
|
948 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
949 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
950 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
951 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
952 | - } |
|
953 | - |
|
954 | - $invoice->recalculate_total(); |
|
955 | - $invoice->set_status( 'wpi-pending' ); |
|
956 | - |
|
957 | - if ( ! $save ) { |
|
958 | - return $invoice; |
|
959 | - } |
|
960 | - |
|
961 | - $invoice->save(); |
|
962 | - |
|
963 | - return $invoice->exists() ? $invoice : false; |
|
964 | - } |
|
965 | - |
|
966 | - /** |
|
967 | - * Renews or completes a subscription |
|
968 | - * |
|
969 | - * @since 1.0.0 |
|
970 | - * @return int The subscription's id |
|
971 | - */ |
|
972 | - public function renew( $calculate_from = null ) { |
|
973 | - |
|
974 | - // Complete subscription if applicable |
|
975 | - if ( $this->is_last_renewal() ) { |
|
976 | - return $this->complete(); |
|
977 | - } |
|
978 | - |
|
979 | - // Calculate new expiration |
|
980 | - $frequency = $this->get_frequency(); |
|
981 | - $period = $this->get_period(); |
|
982 | - $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
983 | - $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
984 | - |
|
985 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
986 | - $this->set_status( 'active' ); |
|
987 | - $this->save(); |
|
988 | - |
|
989 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
990 | - |
|
991 | - return $this->get_id(); |
|
992 | - } |
|
993 | - |
|
994 | - /** |
|
995 | - * Marks a subscription as completed |
|
996 | - * |
|
997 | - * Subscription is completed when the number of payments matches the billing_times field |
|
998 | - * |
|
999 | - * @since 1.0.0 |
|
1000 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1001 | - */ |
|
1002 | - public function complete() { |
|
1003 | - |
|
1004 | - // Only mark a subscription as complete if it's not already cancelled. |
|
1005 | - if ( $this->has_status( 'cancelled' ) ) { |
|
1006 | - return false; |
|
1007 | - } |
|
1008 | - |
|
1009 | - $this->set_status( 'completed' ); |
|
1010 | - return $this->save(); |
|
1011 | - |
|
1012 | - } |
|
1013 | - |
|
1014 | - /** |
|
1015 | - * Marks a subscription as expired |
|
1016 | - * |
|
1017 | - * @since 1.0.0 |
|
1018 | - * @param bool $check_expiration |
|
1019 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1020 | - */ |
|
1021 | - public function expire( $check_expiration = false ) { |
|
1022 | - |
|
1023 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1024 | - // Do not mark as expired since real expiration date is in the future |
|
1025 | - return false; |
|
1026 | - } |
|
1027 | - |
|
1028 | - $this->set_status( 'expired' ); |
|
1029 | - return $this->save(); |
|
1030 | - |
|
1031 | - } |
|
1032 | - |
|
1033 | - /** |
|
1034 | - * Marks a subscription as failing |
|
1035 | - * |
|
1036 | - * @since 2.4.2 |
|
1037 | - * @return int Subscription id. |
|
1038 | - */ |
|
1039 | - public function failing() { |
|
1040 | - $this->set_status( 'failing' ); |
|
1041 | - return $this->save(); |
|
1042 | - } |
|
919 | + $parent_invoice = $this->get_parent_payment(); |
|
920 | + |
|
921 | + if ( ! $parent_invoice->exists() ) { |
|
922 | + return false; |
|
923 | + } |
|
924 | + |
|
925 | + // Duplicate the parent invoice. |
|
926 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
927 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
928 | + $invoice->set_subscription_id( $this->get_id() ); |
|
929 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
930 | + |
|
931 | + // Set invoice items. |
|
932 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
933 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
934 | + $invoice_items = array(); |
|
935 | + |
|
936 | + foreach ( $invoice->get_items() as $item ) { |
|
937 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
938 | + $invoice_items[] = $item; |
|
939 | + } |
|
940 | + } |
|
941 | + |
|
942 | + $invoice->set_items( $invoice_items ); |
|
943 | + |
|
944 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
945 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
946 | + } |
|
947 | + |
|
948 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
949 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
950 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
951 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
952 | + } |
|
953 | + |
|
954 | + $invoice->recalculate_total(); |
|
955 | + $invoice->set_status( 'wpi-pending' ); |
|
956 | + |
|
957 | + if ( ! $save ) { |
|
958 | + return $invoice; |
|
959 | + } |
|
960 | + |
|
961 | + $invoice->save(); |
|
962 | + |
|
963 | + return $invoice->exists() ? $invoice : false; |
|
964 | + } |
|
965 | + |
|
966 | + /** |
|
967 | + * Renews or completes a subscription |
|
968 | + * |
|
969 | + * @since 1.0.0 |
|
970 | + * @return int The subscription's id |
|
971 | + */ |
|
972 | + public function renew( $calculate_from = null ) { |
|
973 | + |
|
974 | + // Complete subscription if applicable |
|
975 | + if ( $this->is_last_renewal() ) { |
|
976 | + return $this->complete(); |
|
977 | + } |
|
978 | + |
|
979 | + // Calculate new expiration |
|
980 | + $frequency = $this->get_frequency(); |
|
981 | + $period = $this->get_period(); |
|
982 | + $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
983 | + $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
984 | + |
|
985 | + $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
986 | + $this->set_status( 'active' ); |
|
987 | + $this->save(); |
|
988 | + |
|
989 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
990 | + |
|
991 | + return $this->get_id(); |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * Marks a subscription as completed |
|
996 | + * |
|
997 | + * Subscription is completed when the number of payments matches the billing_times field |
|
998 | + * |
|
999 | + * @since 1.0.0 |
|
1000 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1001 | + */ |
|
1002 | + public function complete() { |
|
1003 | + |
|
1004 | + // Only mark a subscription as complete if it's not already cancelled. |
|
1005 | + if ( $this->has_status( 'cancelled' ) ) { |
|
1006 | + return false; |
|
1007 | + } |
|
1008 | + |
|
1009 | + $this->set_status( 'completed' ); |
|
1010 | + return $this->save(); |
|
1011 | + |
|
1012 | + } |
|
1013 | + |
|
1014 | + /** |
|
1015 | + * Marks a subscription as expired |
|
1016 | + * |
|
1017 | + * @since 1.0.0 |
|
1018 | + * @param bool $check_expiration |
|
1019 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1020 | + */ |
|
1021 | + public function expire( $check_expiration = false ) { |
|
1022 | + |
|
1023 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1024 | + // Do not mark as expired since real expiration date is in the future |
|
1025 | + return false; |
|
1026 | + } |
|
1027 | + |
|
1028 | + $this->set_status( 'expired' ); |
|
1029 | + return $this->save(); |
|
1030 | + |
|
1031 | + } |
|
1032 | + |
|
1033 | + /** |
|
1034 | + * Marks a subscription as failing |
|
1035 | + * |
|
1036 | + * @since 2.4.2 |
|
1037 | + * @return int Subscription id. |
|
1038 | + */ |
|
1039 | + public function failing() { |
|
1040 | + $this->set_status( 'failing' ); |
|
1041 | + return $this->save(); |
|
1042 | + } |
|
1043 | 1043 | |
1044 | 1044 | /** |
1045 | 1045 | * Marks a subscription as cancelled |
@@ -1048,19 +1048,19 @@ discard block |
||
1048 | 1048 | * @return int Subscription id. |
1049 | 1049 | */ |
1050 | 1050 | public function cancel() { |
1051 | - $this->set_status( 'cancelled' ); |
|
1052 | - return $this->save(); |
|
1051 | + $this->set_status( 'cancelled' ); |
|
1052 | + return $this->save(); |
|
1053 | 1053 | } |
1054 | 1054 | |
1055 | - /** |
|
1056 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1057 | - * |
|
1058 | - * @since 1.0.0 |
|
1059 | - * @return bool |
|
1060 | - */ |
|
1061 | - public function can_cancel() { |
|
1062 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1063 | - } |
|
1055 | + /** |
|
1056 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1057 | + * |
|
1058 | + * @since 1.0.0 |
|
1059 | + * @return bool |
|
1060 | + */ |
|
1061 | + public function can_cancel() { |
|
1062 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1063 | + } |
|
1064 | 1064 | |
1065 | 1065 | /** |
1066 | 1066 | * Returns an array of subscription statuses that can be cancelled |
@@ -1073,109 +1073,109 @@ discard block |
||
1073 | 1073 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1074 | 1074 | } |
1075 | 1075 | |
1076 | - /** |
|
1077 | - * Retrieves the URL to cancel subscription |
|
1078 | - * |
|
1079 | - * @since 1.0.0 |
|
1080 | - * @return string |
|
1081 | - */ |
|
1082 | - public function get_cancel_url() { |
|
1083 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1084 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1085 | - } |
|
1086 | - |
|
1087 | - /** |
|
1088 | - * Retrieves the URL to view a subscription |
|
1089 | - * |
|
1090 | - * @since 1.0.19 |
|
1091 | - * @return string |
|
1092 | - */ |
|
1093 | - public function get_view_url() { |
|
1094 | - |
|
1095 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1096 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1097 | - |
|
1098 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1099 | - } |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Determines if subscription can be manually renewed |
|
1103 | - * |
|
1104 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1105 | - * that can be renewed manually |
|
1106 | - * |
|
1107 | - * @since 2.5 |
|
1108 | - * @return bool |
|
1109 | - */ |
|
1110 | - public function can_renew() { |
|
1111 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1112 | - } |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * Retrieves the URL to renew a subscription |
|
1116 | - * |
|
1117 | - * @since 2.5 |
|
1118 | - * @return string |
|
1119 | - */ |
|
1120 | - public function get_renew_url() { |
|
1121 | - $url = wp_nonce_url( |
|
1076 | + /** |
|
1077 | + * Retrieves the URL to cancel subscription |
|
1078 | + * |
|
1079 | + * @since 1.0.0 |
|
1080 | + * @return string |
|
1081 | + */ |
|
1082 | + public function get_cancel_url() { |
|
1083 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1084 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1085 | + } |
|
1086 | + |
|
1087 | + /** |
|
1088 | + * Retrieves the URL to view a subscription |
|
1089 | + * |
|
1090 | + * @since 1.0.19 |
|
1091 | + * @return string |
|
1092 | + */ |
|
1093 | + public function get_view_url() { |
|
1094 | + |
|
1095 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1096 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1097 | + |
|
1098 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1099 | + } |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Determines if subscription can be manually renewed |
|
1103 | + * |
|
1104 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1105 | + * that can be renewed manually |
|
1106 | + * |
|
1107 | + * @since 2.5 |
|
1108 | + * @return bool |
|
1109 | + */ |
|
1110 | + public function can_renew() { |
|
1111 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1112 | + } |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * Retrieves the URL to renew a subscription |
|
1116 | + * |
|
1117 | + * @since 2.5 |
|
1118 | + * @return string |
|
1119 | + */ |
|
1120 | + public function get_renew_url() { |
|
1121 | + $url = wp_nonce_url( |
|
1122 | 1122 | add_query_arg( |
1123 | 1123 | array( |
1124 | - 'getpaid-action' => 'renew_subscription', |
|
1125 | - 'sub_id' => $this->get_id, |
|
1124 | + 'getpaid-action' => 'renew_subscription', |
|
1125 | + 'sub_id' => $this->get_id, |
|
1126 | 1126 | ) |
1127 | 1127 | ), |
1128 | 1128 | 'getpaid-nonce' |
1129 | 1129 | ); |
1130 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1131 | - } |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * Determines if subscription can have their payment method updated |
|
1135 | - * |
|
1136 | - * @since 1.0.0 |
|
1137 | - * @return bool |
|
1138 | - */ |
|
1139 | - public function can_update() { |
|
1140 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1141 | - } |
|
1142 | - |
|
1143 | - /** |
|
1144 | - * Retrieves the URL to update subscription |
|
1145 | - * |
|
1146 | - * @since 1.0.0 |
|
1147 | - * @return string |
|
1148 | - */ |
|
1149 | - public function get_update_url() { |
|
1150 | - $url = add_query_arg( |
|
1130 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1131 | + } |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * Determines if subscription can have their payment method updated |
|
1135 | + * |
|
1136 | + * @since 1.0.0 |
|
1137 | + * @return bool |
|
1138 | + */ |
|
1139 | + public function can_update() { |
|
1140 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1141 | + } |
|
1142 | + |
|
1143 | + /** |
|
1144 | + * Retrieves the URL to update subscription |
|
1145 | + * |
|
1146 | + * @since 1.0.0 |
|
1147 | + * @return string |
|
1148 | + */ |
|
1149 | + public function get_update_url() { |
|
1150 | + $url = add_query_arg( |
|
1151 | 1151 | array( |
1152 | - 'action' => 'update', |
|
1153 | - 'subscription_id' => $this->get_id(), |
|
1152 | + 'action' => 'update', |
|
1153 | + 'subscription_id' => $this->get_id(), |
|
1154 | 1154 | ) |
1155 | 1155 | ); |
1156 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * Retrieves the subscription status label |
|
1161 | - * |
|
1162 | - * @since 1.0.0 |
|
1163 | - * @return string |
|
1164 | - */ |
|
1165 | - public function get_status_label() { |
|
1166 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1167 | - } |
|
1168 | - |
|
1169 | - /** |
|
1170 | - * Retrieves the subscription status class |
|
1171 | - * |
|
1172 | - * @since 1.0.19 |
|
1173 | - * @return string |
|
1174 | - */ |
|
1175 | - public function get_status_class() { |
|
1176 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1177 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
1178 | - } |
|
1156 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * Retrieves the subscription status label |
|
1161 | + * |
|
1162 | + * @since 1.0.0 |
|
1163 | + * @return string |
|
1164 | + */ |
|
1165 | + public function get_status_label() { |
|
1166 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1167 | + } |
|
1168 | + |
|
1169 | + /** |
|
1170 | + * Retrieves the subscription status class |
|
1171 | + * |
|
1172 | + * @since 1.0.19 |
|
1173 | + * @return string |
|
1174 | + */ |
|
1175 | + public function get_status_class() { |
|
1176 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1177 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
1178 | + } |
|
1179 | 1179 | |
1180 | 1180 | /** |
1181 | 1181 | * Retrieves the subscription status label |
@@ -1185,11 +1185,11 @@ discard block |
||
1185 | 1185 | */ |
1186 | 1186 | public function get_status_label_html() { |
1187 | 1187 | |
1188 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1189 | - $class = esc_attr( $this->get_status_class() ); |
|
1190 | - $status = sanitize_html_class( $this->get_status() ); |
|
1188 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1189 | + $class = esc_attr( $this->get_status_class() ); |
|
1190 | + $status = sanitize_html_class( $this->get_status() ); |
|
1191 | 1191 | |
1192 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1192 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | 1195 | /** |
@@ -1200,75 +1200,75 @@ discard block |
||
1200 | 1200 | * @return bool |
1201 | 1201 | */ |
1202 | 1202 | public function payment_exists( $txn_id = '' ) { |
1203 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1203 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1204 | 1204 | return ! empty( $invoice_id ); |
1205 | - } |
|
1206 | - |
|
1207 | - /** |
|
1208 | - * Handle the status transition. |
|
1209 | - */ |
|
1210 | - protected function status_transition() { |
|
1211 | - $status_transition = $this->status_transition; |
|
1212 | - |
|
1213 | - // Reset status transition variable. |
|
1214 | - $this->status_transition = false; |
|
1215 | - |
|
1216 | - if ( $status_transition ) { |
|
1217 | - try { |
|
1218 | - |
|
1219 | - // Fire a hook for the status change. |
|
1220 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1221 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1222 | - |
|
1223 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1224 | - |
|
1225 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1226 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1227 | - |
|
1228 | - // Note the transition occurred. |
|
1229 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1230 | - |
|
1231 | - // Fire another hook. |
|
1232 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1233 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1234 | - |
|
1235 | - } else { |
|
1236 | - /* translators: %s: new invoice status */ |
|
1237 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1238 | - |
|
1239 | - // Note the transition occurred. |
|
1240 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1241 | - |
|
1242 | - } |
|
1243 | - } catch ( Exception $e ) { |
|
1244 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1245 | - } |
|
1246 | - } |
|
1247 | - |
|
1248 | - } |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * Save data to the database. |
|
1252 | - * |
|
1253 | - * @since 1.0.19 |
|
1254 | - * @return int subscription ID |
|
1255 | - */ |
|
1256 | - public function save() { |
|
1257 | - parent::save(); |
|
1258 | - $this->status_transition(); |
|
1259 | - return $this->get_id(); |
|
1260 | - } |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Activates a subscription. |
|
1264 | - * |
|
1265 | - * @since 1.0.19 |
|
1266 | - * @return int subscription ID |
|
1267 | - */ |
|
1268 | - public function activate() { |
|
1269 | - $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1270 | - $this->set_status( $status ); |
|
1271 | - return $this->save(); |
|
1272 | - } |
|
1205 | + } |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * Handle the status transition. |
|
1209 | + */ |
|
1210 | + protected function status_transition() { |
|
1211 | + $status_transition = $this->status_transition; |
|
1212 | + |
|
1213 | + // Reset status transition variable. |
|
1214 | + $this->status_transition = false; |
|
1215 | + |
|
1216 | + if ( $status_transition ) { |
|
1217 | + try { |
|
1218 | + |
|
1219 | + // Fire a hook for the status change. |
|
1220 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1221 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1222 | + |
|
1223 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1224 | + |
|
1225 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1226 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1227 | + |
|
1228 | + // Note the transition occurred. |
|
1229 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1230 | + |
|
1231 | + // Fire another hook. |
|
1232 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1233 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1234 | + |
|
1235 | + } else { |
|
1236 | + /* translators: %s: new invoice status */ |
|
1237 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1238 | + |
|
1239 | + // Note the transition occurred. |
|
1240 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1241 | + |
|
1242 | + } |
|
1243 | + } catch ( Exception $e ) { |
|
1244 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1245 | + } |
|
1246 | + } |
|
1247 | + |
|
1248 | + } |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * Save data to the database. |
|
1252 | + * |
|
1253 | + * @since 1.0.19 |
|
1254 | + * @return int subscription ID |
|
1255 | + */ |
|
1256 | + public function save() { |
|
1257 | + parent::save(); |
|
1258 | + $this->status_transition(); |
|
1259 | + return $this->get_id(); |
|
1260 | + } |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * Activates a subscription. |
|
1264 | + * |
|
1265 | + * @since 1.0.19 |
|
1266 | + * @return int subscription ID |
|
1267 | + */ |
|
1268 | + public function activate() { |
|
1269 | + $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1270 | + $this->set_status( $status ); |
|
1271 | + return $this->save(); |
|
1272 | + } |
|
1273 | 1273 | |
1274 | 1274 | } |
@@ -13,741 +13,741 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | - |
|
30 | - // Invoice table columns. |
|
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | - |
|
36 | - // Items table columns. |
|
37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | - |
|
44 | - // Payment forms columns. |
|
45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | - |
|
49 | - // Discount table columns. |
|
50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | - |
|
53 | - // Deleting posts. |
|
54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | - |
|
57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Post updated messages. |
|
62 | - */ |
|
63 | - public static function post_updated_messages( $messages ) { |
|
64 | - global $post; |
|
65 | - |
|
66 | - $messages['wpi_discount'] = array( |
|
67 | - 0 => '', |
|
68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | - ); |
|
79 | - |
|
80 | - $messages['wpi_payment_form'] = array( |
|
81 | - 0 => '', |
|
82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | - ); |
|
93 | - |
|
94 | - return $messages; |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Post row actions. |
|
100 | - */ |
|
101 | - public static function post_row_actions( $actions, $post ) { |
|
102 | - |
|
103 | - $post = get_post( $post ); |
|
104 | - |
|
105 | - // We do not want to edit the default payment form. |
|
106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | - |
|
108 | - if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | - unset( $actions['trash'] ); |
|
110 | - unset( $actions['inline hide-if-no-js'] ); |
|
111 | - } |
|
112 | - |
|
113 | - $actions['duplicate'] = sprintf( |
|
114 | - '<a href="%1$s">%2$s</a>', |
|
115 | - esc_url( |
|
116 | - wp_nonce_url( |
|
117 | - add_query_arg( |
|
118 | - array( |
|
119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
120 | - 'form_id' => $post->ID, |
|
121 | - ) |
|
122 | - ), |
|
123 | - 'getpaid-nonce', |
|
124 | - 'getpaid-nonce' |
|
125 | - ) |
|
126 | - ), |
|
127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | - ); |
|
129 | - |
|
130 | - $actions['reset'] = sprintf( |
|
131 | - '<a href="%1$s" style="color: #800">%2$s</a>', |
|
132 | - esc_url( |
|
133 | - wp_nonce_url( |
|
134 | - add_query_arg( |
|
135 | - array( |
|
136 | - 'getpaid-admin-action' => 'reset_form_stats', |
|
137 | - 'form_id' => $post->ID, |
|
138 | - ) |
|
139 | - ), |
|
140 | - 'getpaid-nonce', |
|
141 | - 'getpaid-nonce' |
|
142 | - ) |
|
143 | - ), |
|
144 | - esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - // Link to item payment form. |
|
149 | - if ( 'wpi_item' == $post->post_type ) { |
|
150 | - |
|
151 | - if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
152 | - |
|
153 | - $actions['buy'] = sprintf( |
|
154 | - '<a href="%1$s">%2$s</a>', |
|
155 | - esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
156 | - esc_html( __( 'Buy', 'invoicing' ) ) |
|
157 | - ); |
|
158 | - |
|
159 | - } |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
19 | + |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
22 | + |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | + |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | + |
|
30 | + // Invoice table columns. |
|
31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | + |
|
36 | + // Items table columns. |
|
37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | + |
|
44 | + // Payment forms columns. |
|
45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | + |
|
49 | + // Discount table columns. |
|
50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | + |
|
53 | + // Deleting posts. |
|
54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | + |
|
57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Post updated messages. |
|
62 | + */ |
|
63 | + public static function post_updated_messages( $messages ) { |
|
64 | + global $post; |
|
65 | + |
|
66 | + $messages['wpi_discount'] = array( |
|
67 | + 0 => '', |
|
68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | + ); |
|
79 | + |
|
80 | + $messages['wpi_payment_form'] = array( |
|
81 | + 0 => '', |
|
82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | + ); |
|
93 | + |
|
94 | + return $messages; |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Post row actions. |
|
100 | + */ |
|
101 | + public static function post_row_actions( $actions, $post ) { |
|
102 | + |
|
103 | + $post = get_post( $post ); |
|
104 | + |
|
105 | + // We do not want to edit the default payment form. |
|
106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | + |
|
108 | + if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | + unset( $actions['trash'] ); |
|
110 | + unset( $actions['inline hide-if-no-js'] ); |
|
111 | + } |
|
112 | + |
|
113 | + $actions['duplicate'] = sprintf( |
|
114 | + '<a href="%1$s">%2$s</a>', |
|
115 | + esc_url( |
|
116 | + wp_nonce_url( |
|
117 | + add_query_arg( |
|
118 | + array( |
|
119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
120 | + 'form_id' => $post->ID, |
|
121 | + ) |
|
122 | + ), |
|
123 | + 'getpaid-nonce', |
|
124 | + 'getpaid-nonce' |
|
125 | + ) |
|
126 | + ), |
|
127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | + ); |
|
129 | + |
|
130 | + $actions['reset'] = sprintf( |
|
131 | + '<a href="%1$s" style="color: #800">%2$s</a>', |
|
132 | + esc_url( |
|
133 | + wp_nonce_url( |
|
134 | + add_query_arg( |
|
135 | + array( |
|
136 | + 'getpaid-admin-action' => 'reset_form_stats', |
|
137 | + 'form_id' => $post->ID, |
|
138 | + ) |
|
139 | + ), |
|
140 | + 'getpaid-nonce', |
|
141 | + 'getpaid-nonce' |
|
142 | + ) |
|
143 | + ), |
|
144 | + esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + // Link to item payment form. |
|
149 | + if ( 'wpi_item' == $post->post_type ) { |
|
150 | + |
|
151 | + if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
152 | + |
|
153 | + $actions['buy'] = sprintf( |
|
154 | + '<a href="%1$s">%2$s</a>', |
|
155 | + esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
156 | + esc_html( __( 'Buy', 'invoicing' ) ) |
|
157 | + ); |
|
158 | + |
|
159 | + } |
|
160 | 160 | } |
161 | 161 | |
162 | - return $actions; |
|
163 | - } |
|
162 | + return $actions; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
165 | + /** |
|
166 | 166 | * Remove bulk edit option from admin side quote listing |
167 | 167 | * |
168 | 168 | * @since 1.0.0 |
169 | 169 | * @param array $actions post actions |
170 | - * @param WP_Post $post |
|
170 | + * @param WP_Post $post |
|
171 | 171 | * @return array $actions actions without edit option |
172 | 172 | */ |
173 | 173 | public static function filter_invoice_row_actions( $actions, $post ) { |
174 | 174 | |
175 | 175 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
176 | 176 | |
177 | - $actions = array(); |
|
178 | - $invoice = new WPInv_Invoice( $post ); |
|
179 | - |
|
180 | - $actions['edit'] = sprintf( |
|
181 | - '<a href="%1$s">%2$s</a>', |
|
182 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
183 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
184 | - ); |
|
185 | - |
|
186 | - if ( ! $invoice->is_draft() ) { |
|
187 | - |
|
188 | - $actions['view'] = sprintf( |
|
189 | - '<a href="%1$s">%2$s</a>', |
|
190 | - esc_url( $invoice->get_view_url() ), |
|
191 | - sprintf( |
|
192 | - // translators: %s is the invoice type |
|
193 | - esc_html__( 'View %s', 'invoicing' ), |
|
194 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
195 | - ) |
|
196 | - ); |
|
197 | - |
|
198 | - $actions['send'] = sprintf( |
|
199 | - '<a href="%1$s">%2$s</a>', |
|
200 | - esc_url( |
|
201 | - wp_nonce_url( |
|
202 | - add_query_arg( |
|
203 | - array( |
|
204 | - 'getpaid-admin-action' => 'send_invoice', |
|
205 | - 'invoice_id' => $invoice->get_id(), |
|
206 | - ) |
|
207 | - ), |
|
208 | - 'getpaid-nonce', |
|
209 | - 'getpaid-nonce' |
|
210 | - ) |
|
211 | - ), |
|
212 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
213 | - ); |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - $actions['duplicate'] = sprintf( |
|
218 | - '<a href="%1$s">%2$s</a>', |
|
219 | - esc_url( |
|
220 | - wp_nonce_url( |
|
221 | - add_query_arg( |
|
222 | - array( |
|
223 | - 'getpaid-admin-action' => 'duplicate_invoice', |
|
224 | - 'invoice_id' => $post->ID, |
|
225 | - ) |
|
226 | - ), |
|
227 | - 'getpaid-nonce', |
|
228 | - 'getpaid-nonce' |
|
229 | - ) |
|
230 | - ), |
|
231 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
232 | - ); |
|
177 | + $actions = array(); |
|
178 | + $invoice = new WPInv_Invoice( $post ); |
|
179 | + |
|
180 | + $actions['edit'] = sprintf( |
|
181 | + '<a href="%1$s">%2$s</a>', |
|
182 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
183 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
184 | + ); |
|
185 | + |
|
186 | + if ( ! $invoice->is_draft() ) { |
|
187 | + |
|
188 | + $actions['view'] = sprintf( |
|
189 | + '<a href="%1$s">%2$s</a>', |
|
190 | + esc_url( $invoice->get_view_url() ), |
|
191 | + sprintf( |
|
192 | + // translators: %s is the invoice type |
|
193 | + esc_html__( 'View %s', 'invoicing' ), |
|
194 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
195 | + ) |
|
196 | + ); |
|
197 | + |
|
198 | + $actions['send'] = sprintf( |
|
199 | + '<a href="%1$s">%2$s</a>', |
|
200 | + esc_url( |
|
201 | + wp_nonce_url( |
|
202 | + add_query_arg( |
|
203 | + array( |
|
204 | + 'getpaid-admin-action' => 'send_invoice', |
|
205 | + 'invoice_id' => $invoice->get_id(), |
|
206 | + ) |
|
207 | + ), |
|
208 | + 'getpaid-nonce', |
|
209 | + 'getpaid-nonce' |
|
210 | + ) |
|
211 | + ), |
|
212 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
213 | + ); |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + $actions['duplicate'] = sprintf( |
|
218 | + '<a href="%1$s">%2$s</a>', |
|
219 | + esc_url( |
|
220 | + wp_nonce_url( |
|
221 | + add_query_arg( |
|
222 | + array( |
|
223 | + 'getpaid-admin-action' => 'duplicate_invoice', |
|
224 | + 'invoice_id' => $post->ID, |
|
225 | + ) |
|
226 | + ), |
|
227 | + 'getpaid-nonce', |
|
228 | + 'getpaid-nonce' |
|
229 | + ) |
|
230 | + ), |
|
231 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
232 | + ); |
|
233 | 233 | |
234 | 234 | } |
235 | 235 | |
236 | 236 | return $actions; |
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Returns an array of invoice table columns. |
|
241 | - */ |
|
242 | - public static function invoice_columns( $columns ) { |
|
243 | - |
|
244 | - $columns = array( |
|
245 | - 'cb' => $columns['cb'], |
|
246 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
247 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
248 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
249 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
250 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
251 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
252 | - 'status' => __( 'Status', 'invoicing' ), |
|
253 | - ); |
|
254 | - |
|
255 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Displays invoice table columns. |
|
260 | - */ |
|
261 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
262 | - |
|
263 | - $invoice = new WPInv_Invoice( $post_id ); |
|
264 | - |
|
265 | - switch ( $column_name ) { |
|
266 | - |
|
267 | - case 'invoice_date': |
|
268 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
269 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
270 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
271 | - break; |
|
272 | - |
|
273 | - case 'payment_date': |
|
274 | - if ( $invoice->is_paid() ) { |
|
275 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
276 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
277 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
278 | - } else { |
|
279 | - echo '—'; |
|
280 | - } |
|
281 | - |
|
282 | - break; |
|
283 | - |
|
284 | - case 'amount': |
|
285 | - $amount = $invoice->get_total(); |
|
286 | - $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
287 | - |
|
288 | - if ( $invoice->is_refunded() ) { |
|
289 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
290 | - echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
291 | - } else { |
|
292 | - |
|
293 | - $discount = $invoice->get_total_discount(); |
|
294 | - |
|
295 | - if ( ! empty( $discount ) ) { |
|
296 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
297 | - echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
298 | - } else { |
|
299 | - echo wp_kses_post( $formated_amount ); |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - break; |
|
304 | - |
|
305 | - case 'status': |
|
306 | - $status = esc_html( $invoice->get_status() ); |
|
307 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
308 | - |
|
309 | - // If it is paid, show the gateway title. |
|
310 | - if ( $invoice->is_paid() ) { |
|
311 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
312 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
313 | - |
|
314 | - echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
315 | - } else { |
|
316 | - echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
317 | - } |
|
318 | - |
|
319 | - // If it is not paid, display the overdue and view status. |
|
320 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
321 | - |
|
322 | - // Invoice view status. |
|
323 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
324 | - echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
325 | - } else { |
|
326 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
327 | - } |
|
328 | - |
|
329 | - // Display the overview status. |
|
330 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
331 | - $due_date = $invoice->get_due_date(); |
|
332 | - $fomatted = getpaid_format_date( $due_date ); |
|
333 | - |
|
334 | - if ( ! empty( $fomatted ) ) { |
|
335 | - $date = wp_sprintf( |
|
336 | - // translators: %s is the due date. |
|
337 | - __( 'Due %s', 'invoicing' ), |
|
338 | - $fomatted |
|
339 | - ); |
|
340 | - echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
341 | - } |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - break; |
|
346 | - |
|
347 | - case 'recurring': |
|
348 | - if ( $invoice->is_recurring() ) { |
|
349 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
350 | - } else { |
|
351 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
352 | - } |
|
353 | - break; |
|
354 | - |
|
355 | - case 'number': |
|
356 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
357 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
358 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
359 | - |
|
360 | - echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
361 | - |
|
362 | - do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
363 | - break; |
|
364 | - |
|
365 | - case 'customer': |
|
366 | - $customer_name = $invoice->get_user_full_name(); |
|
367 | - |
|
368 | - if ( empty( $customer_name ) ) { |
|
369 | - $customer_name = $invoice->get_email(); |
|
370 | - } |
|
371 | - |
|
372 | - if ( ! empty( $customer_name ) ) { |
|
373 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
374 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
375 | - echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
376 | - } else { |
|
377 | - echo '<div>—</div>'; |
|
378 | - } |
|
379 | - |
|
380 | - break; |
|
381 | - |
|
382 | - } |
|
383 | - |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Displays invoice bulk actions. |
|
388 | - */ |
|
389 | - public static function invoice_bulk_actions( $actions ) { |
|
390 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
391 | - return $actions; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Processes invoice bulk actions. |
|
396 | - */ |
|
397 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
398 | - |
|
399 | - if ( 'resend-invoice' === $action ) { |
|
400 | - foreach ( $post_ids as $post_id ) { |
|
401 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - return $redirect_url; |
|
406 | - |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Returns an array of payment forms table columns. |
|
411 | - */ |
|
412 | - public static function payment_form_columns( $columns ) { |
|
413 | - |
|
414 | - $columns = array( |
|
415 | - 'cb' => $columns['cb'], |
|
416 | - 'title' => __( 'Name', 'invoicing' ), |
|
417 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
418 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
419 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
420 | - 'items' => __( 'Items', 'invoicing' ), |
|
421 | - 'date' => __( 'Date', 'invoicing' ), |
|
422 | - ); |
|
423 | - |
|
424 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
425 | - |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Displays payment form table columns. |
|
430 | - */ |
|
431 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
432 | - |
|
433 | - // Retrieve the payment form. |
|
434 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
435 | - |
|
436 | - switch ( $column_name ) { |
|
437 | - |
|
438 | - case 'earnings': |
|
439 | - echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
440 | - break; |
|
441 | - |
|
442 | - case 'refunds': |
|
443 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
444 | - break; |
|
445 | - |
|
446 | - case 'refunds': |
|
447 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
448 | - break; |
|
449 | - |
|
450 | - case 'shortcode': |
|
451 | - if ( $form->is_default() ) { |
|
452 | - echo '—'; |
|
453 | - } else { |
|
454 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
455 | - } |
|
456 | - |
|
457 | - break; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Returns an array of invoice table columns. |
|
241 | + */ |
|
242 | + public static function invoice_columns( $columns ) { |
|
243 | + |
|
244 | + $columns = array( |
|
245 | + 'cb' => $columns['cb'], |
|
246 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
247 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
248 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
249 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
250 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
251 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
252 | + 'status' => __( 'Status', 'invoicing' ), |
|
253 | + ); |
|
254 | + |
|
255 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Displays invoice table columns. |
|
260 | + */ |
|
261 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
262 | + |
|
263 | + $invoice = new WPInv_Invoice( $post_id ); |
|
264 | + |
|
265 | + switch ( $column_name ) { |
|
266 | + |
|
267 | + case 'invoice_date': |
|
268 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
269 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
270 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
271 | + break; |
|
272 | + |
|
273 | + case 'payment_date': |
|
274 | + if ( $invoice->is_paid() ) { |
|
275 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
276 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
277 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
278 | + } else { |
|
279 | + echo '—'; |
|
280 | + } |
|
281 | + |
|
282 | + break; |
|
283 | + |
|
284 | + case 'amount': |
|
285 | + $amount = $invoice->get_total(); |
|
286 | + $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
287 | + |
|
288 | + if ( $invoice->is_refunded() ) { |
|
289 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
290 | + echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
291 | + } else { |
|
292 | + |
|
293 | + $discount = $invoice->get_total_discount(); |
|
294 | + |
|
295 | + if ( ! empty( $discount ) ) { |
|
296 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
297 | + echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
298 | + } else { |
|
299 | + echo wp_kses_post( $formated_amount ); |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + break; |
|
304 | + |
|
305 | + case 'status': |
|
306 | + $status = esc_html( $invoice->get_status() ); |
|
307 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
308 | + |
|
309 | + // If it is paid, show the gateway title. |
|
310 | + if ( $invoice->is_paid() ) { |
|
311 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
312 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
313 | + |
|
314 | + echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
315 | + } else { |
|
316 | + echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
317 | + } |
|
318 | + |
|
319 | + // If it is not paid, display the overdue and view status. |
|
320 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
321 | + |
|
322 | + // Invoice view status. |
|
323 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
324 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
325 | + } else { |
|
326 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
327 | + } |
|
328 | + |
|
329 | + // Display the overview status. |
|
330 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
331 | + $due_date = $invoice->get_due_date(); |
|
332 | + $fomatted = getpaid_format_date( $due_date ); |
|
333 | + |
|
334 | + if ( ! empty( $fomatted ) ) { |
|
335 | + $date = wp_sprintf( |
|
336 | + // translators: %s is the due date. |
|
337 | + __( 'Due %s', 'invoicing' ), |
|
338 | + $fomatted |
|
339 | + ); |
|
340 | + echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
341 | + } |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + break; |
|
346 | + |
|
347 | + case 'recurring': |
|
348 | + if ( $invoice->is_recurring() ) { |
|
349 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
350 | + } else { |
|
351 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
352 | + } |
|
353 | + break; |
|
354 | + |
|
355 | + case 'number': |
|
356 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
357 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
358 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
359 | + |
|
360 | + echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
361 | + |
|
362 | + do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
363 | + break; |
|
364 | + |
|
365 | + case 'customer': |
|
366 | + $customer_name = $invoice->get_user_full_name(); |
|
367 | + |
|
368 | + if ( empty( $customer_name ) ) { |
|
369 | + $customer_name = $invoice->get_email(); |
|
370 | + } |
|
371 | + |
|
372 | + if ( ! empty( $customer_name ) ) { |
|
373 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
374 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
375 | + echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
376 | + } else { |
|
377 | + echo '<div>—</div>'; |
|
378 | + } |
|
379 | + |
|
380 | + break; |
|
458 | 381 | |
459 | - case 'items': |
|
460 | - $items = $form->get_items(); |
|
461 | - |
|
462 | - if ( $form->is_default() || empty( $items ) ) { |
|
463 | - echo '—'; |
|
464 | - return; |
|
465 | - } |
|
466 | - |
|
467 | - $_items = array(); |
|
468 | - |
|
469 | - foreach ( $items as $item ) { |
|
470 | - $url = $item->get_edit_url(); |
|
471 | - |
|
472 | - if ( empty( $url ) ) { |
|
473 | - $_items[] = esc_html( $item->get_name() ); |
|
474 | - } else { |
|
475 | - $_items[] = sprintf( |
|
476 | - '<a href="%s">%s</a>', |
|
477 | - esc_url( $url ), |
|
478 | - esc_html( $item->get_name() ) |
|
479 | - ); |
|
480 | - } |
|
382 | + } |
|
383 | + |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Displays invoice bulk actions. |
|
388 | + */ |
|
389 | + public static function invoice_bulk_actions( $actions ) { |
|
390 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
391 | + return $actions; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Processes invoice bulk actions. |
|
396 | + */ |
|
397 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
398 | + |
|
399 | + if ( 'resend-invoice' === $action ) { |
|
400 | + foreach ( $post_ids as $post_id ) { |
|
401 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + return $redirect_url; |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Returns an array of payment forms table columns. |
|
411 | + */ |
|
412 | + public static function payment_form_columns( $columns ) { |
|
413 | + |
|
414 | + $columns = array( |
|
415 | + 'cb' => $columns['cb'], |
|
416 | + 'title' => __( 'Name', 'invoicing' ), |
|
417 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
418 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
419 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
420 | + 'items' => __( 'Items', 'invoicing' ), |
|
421 | + 'date' => __( 'Date', 'invoicing' ), |
|
422 | + ); |
|
423 | + |
|
424 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
425 | + |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Displays payment form table columns. |
|
430 | + */ |
|
431 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
432 | + |
|
433 | + // Retrieve the payment form. |
|
434 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
435 | + |
|
436 | + switch ( $column_name ) { |
|
437 | + |
|
438 | + case 'earnings': |
|
439 | + echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
440 | + break; |
|
441 | + |
|
442 | + case 'refunds': |
|
443 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
444 | + break; |
|
445 | + |
|
446 | + case 'refunds': |
|
447 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
448 | + break; |
|
449 | + |
|
450 | + case 'shortcode': |
|
451 | + if ( $form->is_default() ) { |
|
452 | + echo '—'; |
|
453 | + } else { |
|
454 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
455 | + } |
|
456 | + |
|
457 | + break; |
|
458 | + |
|
459 | + case 'items': |
|
460 | + $items = $form->get_items(); |
|
461 | + |
|
462 | + if ( $form->is_default() || empty( $items ) ) { |
|
463 | + echo '—'; |
|
464 | + return; |
|
465 | + } |
|
466 | + |
|
467 | + $_items = array(); |
|
468 | + |
|
469 | + foreach ( $items as $item ) { |
|
470 | + $url = $item->get_edit_url(); |
|
471 | + |
|
472 | + if ( empty( $url ) ) { |
|
473 | + $_items[] = esc_html( $item->get_name() ); |
|
474 | + } else { |
|
475 | + $_items[] = sprintf( |
|
476 | + '<a href="%s">%s</a>', |
|
477 | + esc_url( $url ), |
|
478 | + esc_html( $item->get_name() ) |
|
479 | + ); |
|
480 | + } |
|
481 | 481 | } |
482 | 482 | |
483 | - echo wp_kses_post( implode( '<br>', $_items ) ); |
|
483 | + echo wp_kses_post( implode( '<br>', $_items ) ); |
|
484 | + |
|
485 | + break; |
|
486 | + |
|
487 | + } |
|
488 | + |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Filters post states. |
|
493 | + */ |
|
494 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
495 | + |
|
496 | + if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
497 | + $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
498 | + } |
|
499 | + |
|
500 | + return $post_states; |
|
501 | + |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Returns an array of coupon table columns. |
|
506 | + */ |
|
507 | + public static function discount_columns( $columns ) { |
|
508 | + |
|
509 | + $columns = array( |
|
510 | + 'cb' => $columns['cb'], |
|
511 | + 'title' => __( 'Name', 'invoicing' ), |
|
512 | + 'code' => __( 'Code', 'invoicing' ), |
|
513 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
514 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
515 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
516 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
517 | + ); |
|
518 | + |
|
519 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
520 | + } |
|
484 | 521 | |
485 | - break; |
|
522 | + /** |
|
523 | + * Filters post states. |
|
524 | + */ |
|
525 | + public static function filter_discount_state( $post_states, $post ) { |
|
486 | 526 | |
487 | - } |
|
527 | + if ( 'wpi_discount' === $post->post_type ) { |
|
488 | 528 | |
489 | - } |
|
529 | + $discount = new WPInv_Discount( $post ); |
|
490 | 530 | |
491 | - /** |
|
492 | - * Filters post states. |
|
493 | - */ |
|
494 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
531 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
495 | 532 | |
496 | - if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
497 | - $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
498 | - } |
|
533 | + if ( 'publish' !== $status ) { |
|
534 | + return array( |
|
535 | + 'discount_status' => wpinv_discount_status( $status ), |
|
536 | + ); |
|
537 | + } |
|
538 | + |
|
539 | + return array(); |
|
540 | + |
|
541 | + } |
|
542 | + |
|
543 | + return $post_states; |
|
499 | 544 | |
500 | - return $post_states; |
|
545 | + } |
|
501 | 546 | |
502 | - } |
|
547 | + /** |
|
548 | + * Returns an array of items table columns. |
|
549 | + */ |
|
550 | + public static function item_columns( $columns ) { |
|
551 | + |
|
552 | + $columns = array( |
|
553 | + 'cb' => $columns['cb'], |
|
554 | + 'title' => __( 'Name', 'invoicing' ), |
|
555 | + 'price' => __( 'Price', 'invoicing' ), |
|
556 | + 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
557 | + 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
558 | + 'type' => __( 'Type', 'invoicing' ), |
|
559 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
560 | + ); |
|
561 | + |
|
562 | + if ( ! wpinv_use_taxes() ) { |
|
563 | + unset( $columns['vat_rule'] ); |
|
564 | + unset( $columns['vat_class'] ); |
|
565 | + } |
|
503 | 566 | |
504 | - /** |
|
505 | - * Returns an array of coupon table columns. |
|
506 | - */ |
|
507 | - public static function discount_columns( $columns ) { |
|
567 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
568 | + } |
|
508 | 569 | |
509 | - $columns = array( |
|
510 | - 'cb' => $columns['cb'], |
|
511 | - 'title' => __( 'Name', 'invoicing' ), |
|
512 | - 'code' => __( 'Code', 'invoicing' ), |
|
513 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
514 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
515 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
516 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
517 | - ); |
|
570 | + /** |
|
571 | + * Returns an array of sortable items table columns. |
|
572 | + */ |
|
573 | + public static function sortable_item_columns( $columns ) { |
|
574 | + |
|
575 | + return array_merge( |
|
576 | + $columns, |
|
577 | + array( |
|
578 | + 'price' => 'price', |
|
579 | + 'vat_rule' => 'vat_rule', |
|
580 | + 'vat_class' => 'vat_class', |
|
581 | + 'type' => 'type', |
|
582 | + ) |
|
583 | + ); |
|
518 | 584 | |
519 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
520 | - } |
|
585 | + } |
|
521 | 586 | |
522 | - /** |
|
523 | - * Filters post states. |
|
524 | - */ |
|
525 | - public static function filter_discount_state( $post_states, $post ) { |
|
587 | + /** |
|
588 | + * Displays items table columns. |
|
589 | + */ |
|
590 | + public static function display_item_columns( $column_name, $post_id ) { |
|
526 | 591 | |
527 | - if ( 'wpi_discount' === $post->post_type ) { |
|
592 | + $item = new WPInv_Item( $post_id ); |
|
528 | 593 | |
529 | - $discount = new WPInv_Discount( $post ); |
|
594 | + switch ( $column_name ) { |
|
530 | 595 | |
531 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
596 | + case 'price': |
|
597 | + if ( ! $item->is_recurring() ) { |
|
598 | + echo wp_kses_post( $item->get_the_price() ); |
|
599 | + break; |
|
600 | + } |
|
532 | 601 | |
533 | - if ( 'publish' !== $status ) { |
|
534 | - return array( |
|
535 | - 'discount_status' => wpinv_discount_status( $status ), |
|
536 | - ); |
|
537 | - } |
|
602 | + $price = wp_sprintf( |
|
603 | + __( '%1$s / %2$s', 'invoicing' ), |
|
604 | + $item->get_the_price(), |
|
605 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
606 | + ); |
|
538 | 607 | |
539 | - return array(); |
|
608 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
609 | + echo wp_kses_post( $price ); |
|
610 | + break; |
|
611 | + } |
|
540 | 612 | |
541 | - } |
|
613 | + echo wp_kses_post( $item->get_the_initial_price() ); |
|
542 | 614 | |
543 | - return $post_states; |
|
615 | + echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
616 | + break; |
|
544 | 617 | |
545 | - } |
|
618 | + case 'vat_rule': |
|
619 | + echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
620 | + break; |
|
546 | 621 | |
547 | - /** |
|
548 | - * Returns an array of items table columns. |
|
549 | - */ |
|
550 | - public static function item_columns( $columns ) { |
|
622 | + case 'vat_class': |
|
623 | + echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
624 | + break; |
|
551 | 625 | |
552 | - $columns = array( |
|
553 | - 'cb' => $columns['cb'], |
|
554 | - 'title' => __( 'Name', 'invoicing' ), |
|
555 | - 'price' => __( 'Price', 'invoicing' ), |
|
556 | - 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
557 | - 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
558 | - 'type' => __( 'Type', 'invoicing' ), |
|
559 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
560 | - ); |
|
626 | + case 'shortcode': |
|
627 | + if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
628 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
629 | + } else { |
|
630 | + echo '—'; |
|
631 | + } |
|
561 | 632 | |
562 | - if ( ! wpinv_use_taxes() ) { |
|
563 | - unset( $columns['vat_rule'] ); |
|
564 | - unset( $columns['vat_class'] ); |
|
565 | - } |
|
633 | + break; |
|
566 | 634 | |
567 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
568 | - } |
|
635 | + case 'type': |
|
636 | + echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
637 | + break; |
|
569 | 638 | |
570 | - /** |
|
571 | - * Returns an array of sortable items table columns. |
|
572 | - */ |
|
573 | - public static function sortable_item_columns( $columns ) { |
|
574 | - |
|
575 | - return array_merge( |
|
576 | - $columns, |
|
577 | - array( |
|
578 | - 'price' => 'price', |
|
579 | - 'vat_rule' => 'vat_rule', |
|
580 | - 'vat_class' => 'vat_class', |
|
581 | - 'type' => 'type', |
|
582 | - ) |
|
583 | - ); |
|
584 | - |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Displays items table columns. |
|
589 | - */ |
|
590 | - public static function display_item_columns( $column_name, $post_id ) { |
|
591 | - |
|
592 | - $item = new WPInv_Item( $post_id ); |
|
593 | - |
|
594 | - switch ( $column_name ) { |
|
595 | - |
|
596 | - case 'price': |
|
597 | - if ( ! $item->is_recurring() ) { |
|
598 | - echo wp_kses_post( $item->get_the_price() ); |
|
599 | - break; |
|
600 | - } |
|
601 | - |
|
602 | - $price = wp_sprintf( |
|
603 | - __( '%1$s / %2$s', 'invoicing' ), |
|
604 | - $item->get_the_price(), |
|
605 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
606 | - ); |
|
607 | - |
|
608 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
609 | - echo wp_kses_post( $price ); |
|
610 | - break; |
|
611 | - } |
|
612 | - |
|
613 | - echo wp_kses_post( $item->get_the_initial_price() ); |
|
614 | - |
|
615 | - echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
616 | - break; |
|
617 | - |
|
618 | - case 'vat_rule': |
|
619 | - echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
620 | - break; |
|
621 | - |
|
622 | - case 'vat_class': |
|
623 | - echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
624 | - break; |
|
625 | - |
|
626 | - case 'shortcode': |
|
627 | - if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
628 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
629 | - } else { |
|
630 | - echo '—'; |
|
631 | - } |
|
632 | - |
|
633 | - break; |
|
634 | - |
|
635 | - case 'type': |
|
636 | - echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
637 | - break; |
|
638 | - |
|
639 | - } |
|
640 | - |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Lets users filter items using taxes. |
|
645 | - */ |
|
646 | - public static function add_item_filters( $post_type ) { |
|
647 | - |
|
648 | - // Abort if we're not dealing with items. |
|
649 | - if ( 'wpi_item' !== $post_type ) { |
|
650 | - return; |
|
651 | - } |
|
652 | - |
|
653 | - // Filter by vat rules. |
|
654 | - if ( wpinv_use_taxes() ) { |
|
655 | - |
|
656 | - // Sanitize selected vat rule. |
|
657 | - $vat_rule = ''; |
|
658 | - $vat_rules = getpaid_get_tax_rules(); |
|
659 | - if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
660 | - $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
661 | - } |
|
662 | - |
|
663 | - // Filter by VAT rule. |
|
664 | - wpinv_html_select( |
|
665 | - array( |
|
666 | - 'options' => array_merge( |
|
667 | - array( |
|
668 | - '' => __( 'All Tax Rules', 'invoicing' ), |
|
669 | - ), |
|
670 | - $vat_rules |
|
671 | - ), |
|
672 | - 'name' => 'vat_rule', |
|
673 | - 'id' => 'vat_rule', |
|
674 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
675 | - 'show_option_all' => false, |
|
676 | - 'show_option_none' => false, |
|
677 | - ) |
|
678 | - ); |
|
679 | - |
|
680 | - // Filter by VAT class. |
|
681 | - |
|
682 | - // Sanitize selected vat rule. |
|
683 | - $vat_class = ''; |
|
684 | - $vat_classes = getpaid_get_tax_classes(); |
|
685 | - if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
686 | - $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
687 | - } |
|
688 | - |
|
689 | - wpinv_html_select( |
|
690 | - array( |
|
691 | - 'options' => array_merge( |
|
692 | - array( |
|
693 | - '' => __( 'All Tax Classes', 'invoicing' ), |
|
694 | - ), |
|
695 | - $vat_classes |
|
696 | - ), |
|
697 | - 'name' => 'vat_class', |
|
698 | - 'id' => 'vat_class', |
|
699 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
700 | - 'show_option_all' => false, |
|
701 | - 'show_option_none' => false, |
|
702 | - ) |
|
703 | - ); |
|
704 | - |
|
705 | - } |
|
706 | - |
|
707 | - // Filter by item type. |
|
708 | - $type = ''; |
|
709 | - if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
710 | - $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
711 | - } |
|
712 | - |
|
713 | - wpinv_html_select( |
|
714 | - array( |
|
715 | - 'options' => array_merge( |
|
716 | - array( |
|
717 | - '' => __( 'All item types', 'invoicing' ), |
|
718 | - ), |
|
719 | - wpinv_get_item_types() |
|
720 | - ), |
|
721 | - 'name' => 'type', |
|
722 | - 'id' => 'type', |
|
723 | - 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
724 | - 'show_option_all' => false, |
|
725 | - 'show_option_none' => false, |
|
726 | - ) |
|
727 | - ); |
|
728 | - |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Filters the item query. |
|
733 | - */ |
|
734 | - public static function filter_item_query( $query ) { |
|
735 | - |
|
736 | - // modify the query only if it admin and main query. |
|
737 | - if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
738 | - return $query; |
|
739 | - } |
|
740 | - |
|
741 | - // we want to modify the query for our items. |
|
742 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
743 | - return $query; |
|
744 | - } |
|
745 | - |
|
746 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
747 | - $query->query_vars['meta_query'] = array(); |
|
748 | - } |
|
749 | - |
|
750 | - // Filter vat rule type |
|
639 | + } |
|
640 | + |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Lets users filter items using taxes. |
|
645 | + */ |
|
646 | + public static function add_item_filters( $post_type ) { |
|
647 | + |
|
648 | + // Abort if we're not dealing with items. |
|
649 | + if ( 'wpi_item' !== $post_type ) { |
|
650 | + return; |
|
651 | + } |
|
652 | + |
|
653 | + // Filter by vat rules. |
|
654 | + if ( wpinv_use_taxes() ) { |
|
655 | + |
|
656 | + // Sanitize selected vat rule. |
|
657 | + $vat_rule = ''; |
|
658 | + $vat_rules = getpaid_get_tax_rules(); |
|
659 | + if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
660 | + $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
661 | + } |
|
662 | + |
|
663 | + // Filter by VAT rule. |
|
664 | + wpinv_html_select( |
|
665 | + array( |
|
666 | + 'options' => array_merge( |
|
667 | + array( |
|
668 | + '' => __( 'All Tax Rules', 'invoicing' ), |
|
669 | + ), |
|
670 | + $vat_rules |
|
671 | + ), |
|
672 | + 'name' => 'vat_rule', |
|
673 | + 'id' => 'vat_rule', |
|
674 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
675 | + 'show_option_all' => false, |
|
676 | + 'show_option_none' => false, |
|
677 | + ) |
|
678 | + ); |
|
679 | + |
|
680 | + // Filter by VAT class. |
|
681 | + |
|
682 | + // Sanitize selected vat rule. |
|
683 | + $vat_class = ''; |
|
684 | + $vat_classes = getpaid_get_tax_classes(); |
|
685 | + if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
686 | + $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
687 | + } |
|
688 | + |
|
689 | + wpinv_html_select( |
|
690 | + array( |
|
691 | + 'options' => array_merge( |
|
692 | + array( |
|
693 | + '' => __( 'All Tax Classes', 'invoicing' ), |
|
694 | + ), |
|
695 | + $vat_classes |
|
696 | + ), |
|
697 | + 'name' => 'vat_class', |
|
698 | + 'id' => 'vat_class', |
|
699 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
700 | + 'show_option_all' => false, |
|
701 | + 'show_option_none' => false, |
|
702 | + ) |
|
703 | + ); |
|
704 | + |
|
705 | + } |
|
706 | + |
|
707 | + // Filter by item type. |
|
708 | + $type = ''; |
|
709 | + if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
710 | + $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
711 | + } |
|
712 | + |
|
713 | + wpinv_html_select( |
|
714 | + array( |
|
715 | + 'options' => array_merge( |
|
716 | + array( |
|
717 | + '' => __( 'All item types', 'invoicing' ), |
|
718 | + ), |
|
719 | + wpinv_get_item_types() |
|
720 | + ), |
|
721 | + 'name' => 'type', |
|
722 | + 'id' => 'type', |
|
723 | + 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
724 | + 'show_option_all' => false, |
|
725 | + 'show_option_none' => false, |
|
726 | + ) |
|
727 | + ); |
|
728 | + |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Filters the item query. |
|
733 | + */ |
|
734 | + public static function filter_item_query( $query ) { |
|
735 | + |
|
736 | + // modify the query only if it admin and main query. |
|
737 | + if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
738 | + return $query; |
|
739 | + } |
|
740 | + |
|
741 | + // we want to modify the query for our items. |
|
742 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
743 | + return $query; |
|
744 | + } |
|
745 | + |
|
746 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
747 | + $query->query_vars['meta_query'] = array(); |
|
748 | + } |
|
749 | + |
|
750 | + // Filter vat rule type |
|
751 | 751 | if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
752 | 752 | $query->query_vars['meta_query'][] = array( |
753 | 753 | 'key' => '_wpinv_vat_rule', |
@@ -772,97 +772,97 @@ discard block |
||
772 | 772 | 'value' => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
773 | 773 | 'compare' => '=', |
774 | 774 | ); |
775 | - } |
|
776 | - |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Reorders items. |
|
781 | - */ |
|
782 | - public static function reorder_items( $vars ) { |
|
783 | - global $typenow; |
|
784 | - |
|
785 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
786 | - return $vars; |
|
787 | - } |
|
788 | - |
|
789 | - // By item type. |
|
790 | - if ( 'type' === $vars['orderby'] ) { |
|
791 | - return array_merge( |
|
792 | - $vars, |
|
793 | - array( |
|
794 | - 'meta_key' => '_wpinv_type', |
|
795 | - 'orderby' => 'meta_value', |
|
796 | - ) |
|
797 | - ); |
|
798 | - } |
|
799 | - |
|
800 | - // By vat class. |
|
801 | - if ( 'vat_class' === $vars['orderby'] ) { |
|
802 | - return array_merge( |
|
803 | - $vars, |
|
804 | - array( |
|
805 | - 'meta_key' => '_wpinv_vat_class', |
|
806 | - 'orderby' => 'meta_value', |
|
807 | - ) |
|
808 | - ); |
|
809 | - } |
|
810 | - |
|
811 | - // By vat rule. |
|
812 | - if ( 'vat_rule' === $vars['orderby'] ) { |
|
813 | - return array_merge( |
|
814 | - $vars, |
|
815 | - array( |
|
816 | - 'meta_key' => '_wpinv_vat_rule', |
|
817 | - 'orderby' => 'meta_value', |
|
818 | - ) |
|
819 | - ); |
|
820 | - } |
|
821 | - |
|
822 | - // By price. |
|
823 | - if ( 'price' === $vars['orderby'] ) { |
|
824 | - return array_merge( |
|
825 | - $vars, |
|
826 | - array( |
|
827 | - 'meta_key' => '_wpinv_price', |
|
828 | - 'orderby' => 'meta_value_num', |
|
829 | - ) |
|
830 | - ); |
|
831 | - } |
|
832 | - |
|
833 | - return $vars; |
|
834 | - |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Fired when deleting a post. |
|
839 | - */ |
|
840 | - public static function delete_post( $post_id ) { |
|
841 | - |
|
842 | - switch ( get_post_type( $post_id ) ) { |
|
843 | - |
|
844 | - case 'wpi_item': |
|
845 | - do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
846 | - break; |
|
847 | - |
|
848 | - case 'wpi_payment_form': |
|
849 | - do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
850 | - break; |
|
851 | - |
|
852 | - case 'wpi_discount': |
|
853 | - do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
854 | - break; |
|
855 | - |
|
856 | - case 'wpi_invoice': |
|
857 | - $invoice = new WPInv_Invoice( $post_id ); |
|
858 | - do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
859 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
860 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
861 | - break; |
|
862 | - } |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
775 | + } |
|
776 | + |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Reorders items. |
|
781 | + */ |
|
782 | + public static function reorder_items( $vars ) { |
|
783 | + global $typenow; |
|
784 | + |
|
785 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
786 | + return $vars; |
|
787 | + } |
|
788 | + |
|
789 | + // By item type. |
|
790 | + if ( 'type' === $vars['orderby'] ) { |
|
791 | + return array_merge( |
|
792 | + $vars, |
|
793 | + array( |
|
794 | + 'meta_key' => '_wpinv_type', |
|
795 | + 'orderby' => 'meta_value', |
|
796 | + ) |
|
797 | + ); |
|
798 | + } |
|
799 | + |
|
800 | + // By vat class. |
|
801 | + if ( 'vat_class' === $vars['orderby'] ) { |
|
802 | + return array_merge( |
|
803 | + $vars, |
|
804 | + array( |
|
805 | + 'meta_key' => '_wpinv_vat_class', |
|
806 | + 'orderby' => 'meta_value', |
|
807 | + ) |
|
808 | + ); |
|
809 | + } |
|
810 | + |
|
811 | + // By vat rule. |
|
812 | + if ( 'vat_rule' === $vars['orderby'] ) { |
|
813 | + return array_merge( |
|
814 | + $vars, |
|
815 | + array( |
|
816 | + 'meta_key' => '_wpinv_vat_rule', |
|
817 | + 'orderby' => 'meta_value', |
|
818 | + ) |
|
819 | + ); |
|
820 | + } |
|
821 | + |
|
822 | + // By price. |
|
823 | + if ( 'price' === $vars['orderby'] ) { |
|
824 | + return array_merge( |
|
825 | + $vars, |
|
826 | + array( |
|
827 | + 'meta_key' => '_wpinv_price', |
|
828 | + 'orderby' => 'meta_value_num', |
|
829 | + ) |
|
830 | + ); |
|
831 | + } |
|
832 | + |
|
833 | + return $vars; |
|
834 | + |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Fired when deleting a post. |
|
839 | + */ |
|
840 | + public static function delete_post( $post_id ) { |
|
841 | + |
|
842 | + switch ( get_post_type( $post_id ) ) { |
|
843 | + |
|
844 | + case 'wpi_item': |
|
845 | + do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
846 | + break; |
|
847 | + |
|
848 | + case 'wpi_payment_form': |
|
849 | + do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
850 | + break; |
|
851 | + |
|
852 | + case 'wpi_discount': |
|
853 | + do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
854 | + break; |
|
855 | + |
|
856 | + case 'wpi_invoice': |
|
857 | + $invoice = new WPInv_Invoice( $post_id ); |
|
858 | + do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
859 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
860 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
861 | + break; |
|
862 | + } |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | 866 | * Add a post display state for special GetPaid pages in the page list table. |
867 | 867 | * |
868 | 868 | * @param array $post_states An array of post display states. |
@@ -876,21 +876,21 @@ discard block |
||
876 | 876 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
877 | 877 | } |
878 | 878 | |
879 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
879 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
880 | 880 | |
881 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
882 | - $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
883 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
884 | - $label |
|
885 | - ); |
|
886 | - } |
|
881 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
882 | + $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
883 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
884 | + $label |
|
885 | + ); |
|
886 | + } |
|
887 | 887 | } |
888 | 888 | |
889 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
889 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
890 | 890 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
891 | 891 | } |
892 | 892 | |
893 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
893 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
894 | 894 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
895 | 895 | } |
896 | 896 |
@@ -14,93 +14,93 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
29 | - |
|
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | + |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct() { |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
68 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
69 | 69 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
77 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
78 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
79 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
80 | - |
|
81 | - // Setup/welcome |
|
82 | - if ( ! empty( $_GET['page'] ) ) { |
|
83 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
84 | - case 'gp-setup': |
|
85 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
86 | - break; |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Register admin scripts |
|
94 | - * |
|
95 | - */ |
|
96 | - public function enqeue_scripts() { |
|
70 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
71 | + add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
76 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
77 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
78 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
79 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
80 | + |
|
81 | + // Setup/welcome |
|
82 | + if ( ! empty( $_GET['page'] ) ) { |
|
83 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
84 | + case 'gp-setup': |
|
85 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
86 | + break; |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Register admin scripts |
|
94 | + * |
|
95 | + */ |
|
96 | + public function enqeue_scripts() { |
|
97 | 97 | global $current_screen, $pagenow; |
98 | 98 | |
99 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
100 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
99 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
100 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
101 | 101 | |
102 | 102 | if ( ! empty( $current_screen->post_type ) ) { |
103 | - $page = $current_screen->post_type; |
|
103 | + $page = $current_screen->post_type; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // General styles. |
@@ -121,53 +121,53 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | // Payment form scripts. |
124 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
124 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
125 | 125 | $this->load_payment_form_scripts(); |
126 | 126 | } |
127 | 127 | |
128 | - if ( $page == 'wpinv-subscriptions' ) { |
|
129 | - wp_enqueue_script( 'postbox' ); |
|
130 | - } |
|
128 | + if ( $page == 'wpinv-subscriptions' ) { |
|
129 | + wp_enqueue_script( 'postbox' ); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | - * Returns admin js translations. |
|
136 | - * |
|
137 | - */ |
|
138 | - protected function get_admin_i18() { |
|
135 | + * Returns admin js translations. |
|
136 | + * |
|
137 | + */ |
|
138 | + protected function get_admin_i18() { |
|
139 | 139 | global $post; |
140 | 140 | |
141 | - $date_range = array( |
|
142 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
143 | - ); |
|
141 | + $date_range = array( |
|
142 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
143 | + ); |
|
144 | 144 | |
145 | - if ( $date_range['period'] == 'custom' ) { |
|
145 | + if ( $date_range['period'] == 'custom' ) { |
|
146 | 146 | |
147 | - if ( isset( $_GET['from'] ) ) { |
|
148 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
149 | - } |
|
147 | + if ( isset( $_GET['from'] ) ) { |
|
148 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
149 | + } |
|
150 | 150 | |
151 | - if ( isset( $_GET['to'] ) ) { |
|
152 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
153 | - } |
|
151 | + if ( isset( $_GET['to'] ) ) { |
|
152 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
153 | + } |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | $i18n = array( |
157 | 157 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
158 | 158 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
159 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
160 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
161 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
162 | - 'date_range' => $date_range, |
|
159 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
160 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
161 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
162 | + 'date_range' => $date_range, |
|
163 | 163 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
164 | 164 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
165 | 165 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
166 | 166 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
167 | 167 | 'tax' => wpinv_tax_amount(), |
168 | 168 | 'discount' => 0, |
169 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
170 | - 'currency' => wpinv_get_currency(), |
|
169 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
170 | + 'currency' => wpinv_get_currency(), |
|
171 | 171 | 'currency_pos' => wpinv_currency_position(), |
172 | 172 | 'thousand_sep' => wpinv_thousands_separator(), |
173 | 173 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -187,118 +187,118 @@ discard block |
||
187 | 187 | 'item_description' => __( 'Item Description', 'invoicing' ), |
188 | 188 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
189 | 189 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
190 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
191 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
192 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
193 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
194 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
190 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
191 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
192 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
193 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
194 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
195 | 195 | ); |
196 | 196 | |
197 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
197 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
198 | 198 | |
199 | - $invoice = new WPInv_Invoice( $post ); |
|
200 | - $i18n['save_invoice'] = sprintf( |
|
201 | - __( 'Save %s', 'invoicing' ), |
|
202 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
203 | - ); |
|
199 | + $invoice = new WPInv_Invoice( $post ); |
|
200 | + $i18n['save_invoice'] = sprintf( |
|
201 | + __( 'Save %s', 'invoicing' ), |
|
202 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
203 | + ); |
|
204 | 204 | |
205 | - $i18n['invoice_description'] = sprintf( |
|
206 | - __( '%s Description', 'invoicing' ), |
|
207 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
208 | - ); |
|
205 | + $i18n['invoice_description'] = sprintf( |
|
206 | + __( '%s Description', 'invoicing' ), |
|
207 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
208 | + ); |
|
209 | 209 | |
210 | - } |
|
211 | - return $i18n; |
|
212 | - } |
|
210 | + } |
|
211 | + return $i18n; |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Change the admin footer text on GetPaid admin pages. |
|
216 | - * |
|
217 | - * @since 2.0.0 |
|
218 | - * @param string $footer_text |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - public function admin_footer_text( $footer_text ) { |
|
222 | - global $current_screen; |
|
214 | + /** |
|
215 | + * Change the admin footer text on GetPaid admin pages. |
|
216 | + * |
|
217 | + * @since 2.0.0 |
|
218 | + * @param string $footer_text |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + public function admin_footer_text( $footer_text ) { |
|
222 | + global $current_screen; |
|
223 | 223 | |
224 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
224 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
225 | 225 | |
226 | 226 | if ( ! empty( $current_screen->post_type ) ) { |
227 | - $page = $current_screen->post_type; |
|
227 | + $page = $current_screen->post_type; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // General styles. |
231 | 231 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
232 | 232 | |
233 | - // Change the footer text |
|
234 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
233 | + // Change the footer text |
|
234 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
235 | 235 | |
236 | - $rating_url = esc_url( |
|
237 | - wp_nonce_url( |
|
238 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
239 | - 'getpaid-nonce', |
|
240 | - 'getpaid-nonce' |
|
236 | + $rating_url = esc_url( |
|
237 | + wp_nonce_url( |
|
238 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
239 | + 'getpaid-nonce', |
|
240 | + 'getpaid-nonce' |
|
241 | 241 | ) |
242 | - ); |
|
242 | + ); |
|
243 | 243 | |
244 | - $footer_text = sprintf( |
|
245 | - /* translators: %s: five stars */ |
|
246 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
247 | - "<a href='$rating_url'>★★★★★</a>" |
|
248 | - ); |
|
244 | + $footer_text = sprintf( |
|
245 | + /* translators: %s: five stars */ |
|
246 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
247 | + "<a href='$rating_url'>★★★★★</a>" |
|
248 | + ); |
|
249 | 249 | |
250 | - } else { |
|
250 | + } else { |
|
251 | 251 | |
252 | - $footer_text = sprintf( |
|
253 | - /* translators: %s: GetPaid */ |
|
254 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
255 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
256 | - ); |
|
252 | + $footer_text = sprintf( |
|
253 | + /* translators: %s: GetPaid */ |
|
254 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
255 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
256 | + ); |
|
257 | 257 | |
258 | - } |
|
258 | + } |
|
259 | 259 | } |
260 | 260 | |
261 | - return $footer_text; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Redirects to wp.org to rate the plugin. |
|
266 | - * |
|
267 | - * @since 2.0.0 |
|
268 | - */ |
|
269 | - public function redirect_to_wordpress_rating_page() { |
|
270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
272 | - exit; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Loads payment form js. |
|
277 | - * |
|
278 | - */ |
|
279 | - protected function load_payment_form_scripts() { |
|
261 | + return $footer_text; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Redirects to wp.org to rate the plugin. |
|
266 | + * |
|
267 | + * @since 2.0.0 |
|
268 | + */ |
|
269 | + public function redirect_to_wordpress_rating_page() { |
|
270 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
272 | + exit; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Loads payment form js. |
|
277 | + * |
|
278 | + */ |
|
279 | + protected function load_payment_form_scripts() { |
|
280 | 280 | global $post; |
281 | 281 | |
282 | 282 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
283 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
285 | 285 | |
286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
286 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
288 | 288 | |
289 | - wp_localize_script( |
|
289 | + wp_localize_script( |
|
290 | 290 | 'wpinv-admin-payment-form-script', |
291 | 291 | 'wpinvPaymentFormAdmin', |
292 | 292 | array( |
293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | - 'currency' => wpinv_currency_symbol(), |
|
296 | - 'position' => wpinv_currency_position(), |
|
297 | - 'decimals' => (int) wpinv_decimals(), |
|
298 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
293 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | + 'currency' => wpinv_currency_symbol(), |
|
296 | + 'position' => wpinv_currency_position(), |
|
297 | + 'decimals' => (int) wpinv_decimals(), |
|
298 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
@@ -307,19 +307,19 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | - * Add our classes to admin pages. |
|
310 | + * Add our classes to admin pages. |
|
311 | 311 | * |
312 | 312 | * @param string $classes |
313 | 313 | * @return string |
314 | - * |
|
315 | - */ |
|
314 | + * |
|
315 | + */ |
|
316 | 316 | public function admin_body_class( $classes ) { |
317 | - global $pagenow, $post, $current_screen; |
|
317 | + global $pagenow, $post, $current_screen; |
|
318 | 318 | |
319 | 319 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
320 | 320 | |
321 | 321 | if ( ! empty( $current_screen->post_type ) ) { |
322 | - $page = $current_screen->post_type; |
|
322 | + $page = $current_screen->post_type; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -328,70 +328,70 @@ discard block |
||
328 | 328 | |
329 | 329 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
333 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
335 | 335 | } |
336 | 336 | |
337 | - return $classes; |
|
337 | + return $classes; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
341 | - * Maybe show the AyeCode Connect Notice. |
|
342 | - */ |
|
343 | - public function init_ayecode_connect_helper() { |
|
341 | + * Maybe show the AyeCode Connect Notice. |
|
342 | + */ |
|
343 | + public function init_ayecode_connect_helper() { |
|
344 | 344 | |
345 | - // Register with the deactivation survey class. |
|
346 | - AyeCode_Deactivation_Survey::instance( |
|
345 | + // Register with the deactivation survey class. |
|
346 | + AyeCode_Deactivation_Survey::instance( |
|
347 | 347 | array( |
348 | - 'slug' => 'invoicing', |
|
349 | - 'version' => WPINV_VERSION, |
|
350 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
348 | + 'slug' => 'invoicing', |
|
349 | + 'version' => WPINV_VERSION, |
|
350 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | |
356 | 356 | new AyeCode_Connect_Helper( |
357 | 357 | array( |
358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
358 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
365 | 365 | ), |
366 | 366 | array( 'wpi-addons' ) |
367 | 367 | ); |
368 | 368 | |
369 | 369 | } |
370 | 370 | |
371 | - /** |
|
372 | - * Redirect users to settings on activation. |
|
373 | - * |
|
374 | - * @return void |
|
375 | - */ |
|
376 | - public function activation_redirect() { |
|
371 | + /** |
|
372 | + * Redirect users to settings on activation. |
|
373 | + * |
|
374 | + * @return void |
|
375 | + */ |
|
376 | + public function activation_redirect() { |
|
377 | 377 | |
378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
379 | 379 | |
380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | - return; |
|
382 | - } |
|
380 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | 383 | |
384 | - // Bail if activating from network, or bulk |
|
385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | - return; |
|
387 | - } |
|
384 | + // Bail if activating from network, or bulk |
|
385 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | + return; |
|
387 | + } |
|
388 | 388 | |
389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
390 | 390 | |
391 | 391 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
392 | 392 | exit; |
393 | 393 | |
394 | - } |
|
394 | + } |
|
395 | 395 | |
396 | 396 | /** |
397 | 397 | * Fires an admin action after verifying that a user can fire them. |
@@ -405,564 +405,564 @@ discard block |
||
405 | 405 | |
406 | 406 | } |
407 | 407 | |
408 | - /** |
|
408 | + /** |
|
409 | 409 | * Duplicate invoice. |
410 | - * |
|
411 | - * @param array $args |
|
410 | + * |
|
411 | + * @param array $args |
|
412 | 412 | */ |
413 | 413 | public function duplicate_invoice( $args ) { |
414 | 414 | |
415 | - if ( empty( $args['invoice_id'] ) ) { |
|
416 | - return; |
|
417 | - } |
|
415 | + if ( empty( $args['invoice_id'] ) ) { |
|
416 | + return; |
|
417 | + } |
|
418 | 418 | |
419 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
419 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
420 | 420 | |
421 | - if ( ! $invoice->exists() ) { |
|
422 | - return; |
|
423 | - } |
|
421 | + if ( ! $invoice->exists() ) { |
|
422 | + return; |
|
423 | + } |
|
424 | 424 | |
425 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
426 | - $new_invoice->save(); |
|
425 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
426 | + $new_invoice->save(); |
|
427 | 427 | |
428 | - if ( $new_invoice->exists() ) { |
|
428 | + if ( $new_invoice->exists() ) { |
|
429 | 429 | |
430 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
430 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
431 | 431 | |
432 | - wp_safe_redirect( |
|
433 | - add_query_arg( |
|
434 | - array( |
|
435 | - 'action' => 'edit', |
|
436 | - 'post' => $new_invoice->get_id(), |
|
437 | - ), |
|
438 | - admin_url( 'post.php' ) |
|
439 | - ) |
|
440 | - ); |
|
441 | - exit; |
|
432 | + wp_safe_redirect( |
|
433 | + add_query_arg( |
|
434 | + array( |
|
435 | + 'action' => 'edit', |
|
436 | + 'post' => $new_invoice->get_id(), |
|
437 | + ), |
|
438 | + admin_url( 'post.php' ) |
|
439 | + ) |
|
440 | + ); |
|
441 | + exit; |
|
442 | 442 | |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
445 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | - /** |
|
449 | + /** |
|
450 | 450 | * Sends a payment reminder to a customer. |
451 | - * |
|
452 | - * @param array $args |
|
451 | + * |
|
452 | + * @param array $args |
|
453 | 453 | */ |
454 | 454 | public function duplicate_payment_form( $args ) { |
455 | 455 | |
456 | - if ( empty( $args['form_id'] ) ) { |
|
457 | - return; |
|
458 | - } |
|
459 | - |
|
460 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
456 | + if ( empty( $args['form_id'] ) ) { |
|
457 | + return; |
|
458 | + } |
|
461 | 459 | |
462 | - if ( ! $form->exists() ) { |
|
463 | - return; |
|
464 | - } |
|
460 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
465 | 461 | |
466 | - $new_form = new GetPaid_Payment_Form(); |
|
467 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
468 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
469 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
470 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
471 | - $new_form->save(); |
|
462 | + if ( ! $form->exists() ) { |
|
463 | + return; |
|
464 | + } |
|
472 | 465 | |
473 | - if ( $new_form->exists() ) { |
|
474 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
475 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
476 | - } else { |
|
477 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
478 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
479 | - } |
|
466 | + $new_form = new GetPaid_Payment_Form(); |
|
467 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
468 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
469 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
470 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
471 | + $new_form->save(); |
|
472 | + |
|
473 | + if ( $new_form->exists() ) { |
|
474 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
475 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
476 | + } else { |
|
477 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
478 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
479 | + } |
|
480 | 480 | |
481 | - wp_redirect( $url ); |
|
482 | - exit; |
|
483 | - } |
|
481 | + wp_redirect( $url ); |
|
482 | + exit; |
|
483 | + } |
|
484 | 484 | |
485 | - /** |
|
485 | + /** |
|
486 | 486 | * Resets form stats. |
487 | - * |
|
488 | - * @param array $args |
|
487 | + * |
|
488 | + * @param array $args |
|
489 | 489 | */ |
490 | 490 | public function reset_form_stats( $args ) { |
491 | 491 | |
492 | - if ( empty( $args['form_id'] ) ) { |
|
493 | - return; |
|
494 | - } |
|
492 | + if ( empty( $args['form_id'] ) ) { |
|
493 | + return; |
|
494 | + } |
|
495 | 495 | |
496 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
496 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
497 | 497 | |
498 | - if ( ! $form->exists() ) { |
|
499 | - return; |
|
500 | - } |
|
498 | + if ( ! $form->exists() ) { |
|
499 | + return; |
|
500 | + } |
|
501 | 501 | |
502 | - $form->set_earned( 0 ); |
|
503 | - $form->set_refunded( 0 ); |
|
504 | - $form->set_cancelled( 0 ); |
|
505 | - $form->set_failed( 0 ); |
|
506 | - $form->save(); |
|
502 | + $form->set_earned( 0 ); |
|
503 | + $form->set_refunded( 0 ); |
|
504 | + $form->set_cancelled( 0 ); |
|
505 | + $form->set_failed( 0 ); |
|
506 | + $form->save(); |
|
507 | 507 | |
508 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
508 | + $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
509 | 509 | |
510 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
511 | - exit; |
|
512 | - } |
|
510 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
511 | + exit; |
|
512 | + } |
|
513 | 513 | |
514 | - /** |
|
514 | + /** |
|
515 | 515 | * Sends a payment reminder to a customer. |
516 | - * |
|
517 | - * @param array $args |
|
516 | + * |
|
517 | + * @param array $args |
|
518 | 518 | */ |
519 | 519 | public function send_customer_invoice( $args ) { |
520 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
521 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
522 | - exit; |
|
523 | - } |
|
520 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
521 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
522 | + exit; |
|
523 | + } |
|
524 | 524 | |
525 | - /** |
|
525 | + /** |
|
526 | 526 | * Sends a payment reminder to a customer. |
527 | - * |
|
528 | - * @param array $args |
|
527 | + * |
|
528 | + * @param array $args |
|
529 | 529 | */ |
530 | 530 | public function send_customer_payment_reminder( $args ) { |
531 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
531 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
532 | 532 | |
533 | - if ( $sent ) { |
|
534 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
535 | - } else { |
|
536 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
537 | - } |
|
533 | + if ( $sent ) { |
|
534 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
535 | + } else { |
|
536 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
537 | + } |
|
538 | 538 | |
539 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
540 | - exit; |
|
541 | - } |
|
539 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
540 | + exit; |
|
541 | + } |
|
542 | 542 | |
543 | - /** |
|
543 | + /** |
|
544 | 544 | * Resets tax rates. |
545 | - * |
|
545 | + * |
|
546 | 546 | */ |
547 | 547 | public function admin_reset_tax_rates() { |
548 | 548 | |
549 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
550 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
551 | - exit; |
|
549 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
550 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
551 | + exit; |
|
552 | 552 | |
553 | - } |
|
553 | + } |
|
554 | 554 | |
555 | - /** |
|
555 | + /** |
|
556 | 556 | * Resets admin pages. |
557 | - * |
|
557 | + * |
|
558 | 558 | */ |
559 | 559 | public function admin_create_missing_pages() { |
560 | - $installer = new GetPaid_Installer(); |
|
561 | - $installer->create_pages(); |
|
562 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
563 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
564 | - exit; |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * Refreshes the permalinks. |
|
569 | - */ |
|
570 | - public function admin_refresh_permalinks() { |
|
571 | - flush_rewrite_rules(); |
|
572 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
573 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
574 | - exit; |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
560 | + $installer = new GetPaid_Installer(); |
|
561 | + $installer->create_pages(); |
|
562 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
563 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
564 | + exit; |
|
565 | + } |
|
566 | + |
|
567 | + /** |
|
568 | + * Refreshes the permalinks. |
|
569 | + */ |
|
570 | + public function admin_refresh_permalinks() { |
|
571 | + flush_rewrite_rules(); |
|
572 | + $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
573 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
574 | + exit; |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | 578 | * Creates an missing admin tables. |
579 | - * |
|
579 | + * |
|
580 | 580 | */ |
581 | 581 | public function admin_create_missing_tables() { |
582 | - global $wpdb; |
|
583 | - $installer = new GetPaid_Installer(); |
|
582 | + global $wpdb; |
|
583 | + $installer = new GetPaid_Installer(); |
|
584 | 584 | |
585 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
586 | - $installer->create_subscriptions_table(); |
|
585 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
586 | + $installer->create_subscriptions_table(); |
|
587 | 587 | |
588 | - if ( $wpdb->last_error !== '' ) { |
|
589 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
590 | - } |
|
591 | - } |
|
588 | + if ( $wpdb->last_error !== '' ) { |
|
589 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
590 | + } |
|
591 | + } |
|
592 | 592 | |
593 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
594 | - $installer->create_invoices_table(); |
|
593 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
594 | + $installer->create_invoices_table(); |
|
595 | 595 | |
596 | - if ( '' !== $wpdb->last_error ) { |
|
597 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
598 | - } |
|
599 | - } |
|
596 | + if ( '' !== $wpdb->last_error ) { |
|
597 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
598 | + } |
|
599 | + } |
|
600 | 600 | |
601 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
602 | - $installer->create_invoice_items_table(); |
|
601 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
602 | + $installer->create_invoice_items_table(); |
|
603 | 603 | |
604 | - if ( '' !== $wpdb->last_error ) { |
|
605 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
606 | - } |
|
607 | - } |
|
604 | + if ( '' !== $wpdb->last_error ) { |
|
605 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
606 | + } |
|
607 | + } |
|
608 | 608 | |
609 | - if ( ! $this->has_notices() ) { |
|
610 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
611 | - } |
|
609 | + if ( ! $this->has_notices() ) { |
|
610 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
611 | + } |
|
612 | 612 | |
613 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
614 | - exit; |
|
615 | - } |
|
613 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
614 | + exit; |
|
615 | + } |
|
616 | 616 | |
617 | - /** |
|
617 | + /** |
|
618 | 618 | * Migrates old invoices to the new database tables. |
619 | - * |
|
619 | + * |
|
620 | 620 | */ |
621 | 621 | public function admin_migrate_old_invoices() { |
622 | 622 | |
623 | - // Migrate the invoices. |
|
624 | - $installer = new GetPaid_Installer(); |
|
625 | - $installer->migrate_old_invoices(); |
|
623 | + // Migrate the invoices. |
|
624 | + $installer = new GetPaid_Installer(); |
|
625 | + $installer->migrate_old_invoices(); |
|
626 | 626 | |
627 | - // Show an admin message. |
|
628 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
627 | + // Show an admin message. |
|
628 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
629 | 629 | |
630 | - // Redirect the admin. |
|
631 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
632 | - exit; |
|
630 | + // Redirect the admin. |
|
631 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
632 | + exit; |
|
633 | 633 | |
634 | - } |
|
634 | + } |
|
635 | 635 | |
636 | - /** |
|
636 | + /** |
|
637 | 637 | * Download customers. |
638 | - * |
|
638 | + * |
|
639 | 639 | */ |
640 | 640 | public function admin_download_customers() { |
641 | - global $wpdb; |
|
642 | - |
|
643 | - $output = fopen( 'php://output', 'w' ); |
|
644 | - |
|
645 | - if ( false === $output ) { |
|
646 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
647 | - } |
|
641 | + global $wpdb; |
|
648 | 642 | |
649 | - header( 'Content-Type:text/csv' ); |
|
650 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
643 | + $output = fopen( 'php://output', 'w' ); |
|
651 | 644 | |
652 | - $post_types = ''; |
|
645 | + if ( false === $output ) { |
|
646 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
647 | + } |
|
653 | 648 | |
654 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
655 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
656 | - } |
|
649 | + header( 'Content-Type:text/csv' ); |
|
650 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
657 | 651 | |
658 | - $post_types = rtrim( $post_types, ' OR' ); |
|
652 | + $post_types = ''; |
|
659 | 653 | |
660 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
654 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
655 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
656 | + } |
|
661 | 657 | |
662 | - $columns = array( |
|
663 | - 'name' => __( 'Name', 'invoicing' ), |
|
664 | - 'email' => __( 'Email', 'invoicing' ), |
|
665 | - 'country' => __( 'Country', 'invoicing' ), |
|
666 | - 'state' => __( 'State', 'invoicing' ), |
|
667 | - 'city' => __( 'City', 'invoicing' ), |
|
668 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
669 | - 'address' => __( 'Address', 'invoicing' ), |
|
670 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
671 | - 'company' => __( 'Company', 'invoicing' ), |
|
672 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
673 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
674 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
675 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
676 | - ); |
|
658 | + $post_types = rtrim( $post_types, ' OR' ); |
|
659 | + |
|
660 | + $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
661 | + |
|
662 | + $columns = array( |
|
663 | + 'name' => __( 'Name', 'invoicing' ), |
|
664 | + 'email' => __( 'Email', 'invoicing' ), |
|
665 | + 'country' => __( 'Country', 'invoicing' ), |
|
666 | + 'state' => __( 'State', 'invoicing' ), |
|
667 | + 'city' => __( 'City', 'invoicing' ), |
|
668 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
669 | + 'address' => __( 'Address', 'invoicing' ), |
|
670 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
671 | + 'company' => __( 'Company', 'invoicing' ), |
|
672 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
673 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
674 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
675 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
676 | + ); |
|
677 | 677 | |
678 | - // Output the csv column headers. |
|
679 | - fputcsv( $output, array_values( $columns ) ); |
|
678 | + // Output the csv column headers. |
|
679 | + fputcsv( $output, array_values( $columns ) ); |
|
680 | 680 | |
681 | - // Loop through |
|
682 | - $table = new WPInv_Customers_Table(); |
|
683 | - foreach ( $customers as $customer_id ) { |
|
681 | + // Loop through |
|
682 | + $table = new WPInv_Customers_Table(); |
|
683 | + foreach ( $customers as $customer_id ) { |
|
684 | 684 | |
685 | - $user = get_user_by( 'id', $customer_id ); |
|
686 | - $row = array(); |
|
687 | - if ( empty( $user ) ) { |
|
688 | - continue; |
|
689 | - } |
|
685 | + $user = get_user_by( 'id', $customer_id ); |
|
686 | + $row = array(); |
|
687 | + if ( empty( $user ) ) { |
|
688 | + continue; |
|
689 | + } |
|
690 | 690 | |
691 | - foreach ( array_keys( $columns ) as $column ) { |
|
691 | + foreach ( array_keys( $columns ) as $column ) { |
|
692 | 692 | |
693 | - $method = 'column_' . $column; |
|
693 | + $method = 'column_' . $column; |
|
694 | 694 | |
695 | - if ( 'name' == $column ) { |
|
696 | - $value = esc_html( $user->display_name ); |
|
697 | - } elseif ( 'email' == $column ) { |
|
698 | - $value = sanitize_email( $user->user_email ); |
|
699 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
700 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
701 | - } |
|
695 | + if ( 'name' == $column ) { |
|
696 | + $value = esc_html( $user->display_name ); |
|
697 | + } elseif ( 'email' == $column ) { |
|
698 | + $value = sanitize_email( $user->user_email ); |
|
699 | + } elseif ( is_callable( array( $table, $method ) ) ) { |
|
700 | + $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
701 | + } |
|
702 | 702 | |
703 | - if ( empty( $value ) ) { |
|
704 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
705 | - } |
|
703 | + if ( empty( $value ) ) { |
|
704 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
705 | + } |
|
706 | 706 | |
707 | - $row[] = $value; |
|
707 | + $row[] = $value; |
|
708 | 708 | |
709 | - } |
|
709 | + } |
|
710 | 710 | |
711 | - fputcsv( $output, $row ); |
|
712 | - } |
|
711 | + fputcsv( $output, $row ); |
|
712 | + } |
|
713 | 713 | |
714 | - fclose( $output ); |
|
715 | - exit; |
|
714 | + fclose( $output ); |
|
715 | + exit; |
|
716 | 716 | |
717 | - } |
|
717 | + } |
|
718 | 718 | |
719 | - /** |
|
719 | + /** |
|
720 | 720 | * Installs a plugin. |
721 | - * |
|
722 | - * @param array $data |
|
721 | + * |
|
722 | + * @param array $data |
|
723 | 723 | */ |
724 | 724 | public function admin_install_plugin( $data ) { |
725 | 725 | |
726 | - if ( ! empty( $data['plugins'] ) ) { |
|
727 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
728 | - wp_cache_flush(); |
|
726 | + if ( ! empty( $data['plugins'] ) ) { |
|
727 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
728 | + wp_cache_flush(); |
|
729 | 729 | |
730 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
731 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
732 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | - $installed = $upgrader->install( $plugin_zip ); |
|
730 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
731 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
732 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | + $installed = $upgrader->install( $plugin_zip ); |
|
734 | 734 | |
735 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
736 | - activate_plugin( $file, '', false, true ); |
|
737 | - } else { |
|
738 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
739 | - } |
|
735 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
736 | + activate_plugin( $file, '', false, true ); |
|
737 | + } else { |
|
738 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
739 | + } |
|
740 | 740 | } |
741 | 741 | } |
742 | 742 | |
743 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
744 | - wp_safe_redirect( $redirect ); |
|
745 | - exit; |
|
743 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
744 | + wp_safe_redirect( $redirect ); |
|
745 | + exit; |
|
746 | 746 | |
747 | - } |
|
747 | + } |
|
748 | 748 | |
749 | - /** |
|
749 | + /** |
|
750 | 750 | * Connects a gateway. |
751 | - * |
|
752 | - * @param array $data |
|
751 | + * |
|
752 | + * @param array $data |
|
753 | 753 | */ |
754 | 754 | public function admin_connect_gateway( $data ) { |
755 | 755 | |
756 | - if ( ! empty( $data['plugin'] ) ) { |
|
756 | + if ( ! empty( $data['plugin'] ) ) { |
|
757 | 757 | |
758 | - $gateway = sanitize_key( $data['plugin'] ); |
|
759 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
758 | + $gateway = sanitize_key( $data['plugin'] ); |
|
759 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
760 | 760 | |
761 | - if ( ! empty( $connect_url ) ) { |
|
762 | - wp_redirect( $connect_url ); |
|
763 | - exit; |
|
764 | - } |
|
761 | + if ( ! empty( $connect_url ) ) { |
|
762 | + wp_redirect( $connect_url ); |
|
763 | + exit; |
|
764 | + } |
|
765 | 765 | |
766 | - if ( 'stripe' == $data['plugin'] ) { |
|
767 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
768 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
769 | - wp_cache_flush(); |
|
766 | + if ( 'stripe' == $data['plugin'] ) { |
|
767 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
768 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
769 | + wp_cache_flush(); |
|
770 | 770 | |
771 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
772 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
773 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
774 | - $upgrader->install( $plugin_zip ); |
|
775 | - } |
|
771 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
772 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
773 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
774 | + $upgrader->install( $plugin_zip ); |
|
775 | + } |
|
776 | 776 | |
777 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
778 | - } |
|
777 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
778 | + } |
|
779 | 779 | |
780 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
781 | - if ( ! empty( $connect_url ) ) { |
|
782 | - wp_redirect( $connect_url ); |
|
783 | - exit; |
|
784 | - } |
|
780 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
781 | + if ( ! empty( $connect_url ) ) { |
|
782 | + wp_redirect( $connect_url ); |
|
783 | + exit; |
|
784 | + } |
|
785 | 785 | } |
786 | 786 | |
787 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
788 | - wp_safe_redirect( $redirect ); |
|
789 | - exit; |
|
787 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
788 | + wp_safe_redirect( $redirect ); |
|
789 | + exit; |
|
790 | 790 | |
791 | - } |
|
791 | + } |
|
792 | 792 | |
793 | - /** |
|
793 | + /** |
|
794 | 794 | * Recalculates discounts. |
795 | - * |
|
795 | + * |
|
796 | 796 | */ |
797 | 797 | public function admin_recalculate_discounts() { |
798 | - global $wpdb; |
|
798 | + global $wpdb; |
|
799 | 799 | |
800 | - // Fetch all invoices that have discount codes. |
|
801 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
802 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
800 | + // Fetch all invoices that have discount codes. |
|
801 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
802 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
803 | 803 | |
804 | - foreach ( $invoices as $invoice ) { |
|
804 | + foreach ( $invoices as $invoice ) { |
|
805 | 805 | |
806 | - $invoice = new WPInv_Invoice( $invoice ); |
|
806 | + $invoice = new WPInv_Invoice( $invoice ); |
|
807 | 807 | |
808 | - if ( ! $invoice->exists() ) { |
|
809 | - continue; |
|
810 | - } |
|
808 | + if ( ! $invoice->exists() ) { |
|
809 | + continue; |
|
810 | + } |
|
811 | 811 | |
812 | - // Abort if the discount does not exist or does not apply here. |
|
813 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
814 | - if ( ! $discount->exists() ) { |
|
815 | - continue; |
|
816 | - } |
|
812 | + // Abort if the discount does not exist or does not apply here. |
|
813 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
814 | + if ( ! $discount->exists() ) { |
|
815 | + continue; |
|
816 | + } |
|
817 | 817 | |
818 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
819 | - $invoice->recalculate_total(); |
|
818 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
819 | + $invoice->recalculate_total(); |
|
820 | 820 | |
821 | - if ( $invoice->get_total_discount() > 0 ) { |
|
822 | - $invoice->save(); |
|
823 | - } |
|
821 | + if ( $invoice->get_total_discount() > 0 ) { |
|
822 | + $invoice->save(); |
|
823 | + } |
|
824 | 824 | } |
825 | 825 | |
826 | - // Show an admin message. |
|
827 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
826 | + // Show an admin message. |
|
827 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
828 | 828 | |
829 | - // Redirect the admin. |
|
830 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
831 | - exit; |
|
829 | + // Redirect the admin. |
|
830 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
831 | + exit; |
|
832 | 832 | |
833 | - } |
|
833 | + } |
|
834 | 834 | |
835 | 835 | /** |
836 | - * Returns an array of admin notices. |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
836 | + * Returns an array of admin notices. |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | 839 | * @return array |
840 | - */ |
|
841 | - public function get_notices() { |
|
842 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
840 | + */ |
|
841 | + public function get_notices() { |
|
842 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
843 | 843 | return is_array( $notices ) ? $notices : array(); |
844 | - } |
|
844 | + } |
|
845 | 845 | |
846 | - /** |
|
847 | - * Checks if we have any admin notices. |
|
848 | - * |
|
849 | - * @since 2.0.4 |
|
846 | + /** |
|
847 | + * Checks if we have any admin notices. |
|
848 | + * |
|
849 | + * @since 2.0.4 |
|
850 | 850 | * @return array |
851 | - */ |
|
852 | - public function has_notices() { |
|
853 | - return count( $this->get_notices() ) > 0; |
|
854 | - } |
|
855 | - |
|
856 | - /** |
|
857 | - * Clears all admin notices |
|
858 | - * |
|
859 | - * @access public |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function clear_notices() { |
|
863 | - delete_option( 'wpinv_admin_notices' ); |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * Saves a new admin notice |
|
868 | - * |
|
869 | - * @access public |
|
870 | - * @since 1.0.19 |
|
871 | - */ |
|
872 | - public function save_notice( $type, $message ) { |
|
873 | - $notices = $this->get_notices(); |
|
874 | - |
|
875 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
876 | - $notices[ $type ] = array(); |
|
877 | - } |
|
878 | - |
|
879 | - $notices[ $type ][] = $message; |
|
880 | - |
|
881 | - update_option( 'wpinv_admin_notices', $notices ); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Displays a success notice |
|
886 | - * |
|
887 | - * @param string $msg The message to qeue. |
|
888 | - * @access public |
|
889 | - * @since 1.0.19 |
|
890 | - */ |
|
891 | - public function show_success( $msg ) { |
|
892 | - $this->save_notice( 'success', $msg ); |
|
893 | - } |
|
894 | - |
|
895 | - /** |
|
896 | - * Displays a error notice |
|
897 | - * |
|
898 | - * @access public |
|
899 | - * @param string $msg The message to qeue. |
|
900 | - * @since 1.0.19 |
|
901 | - */ |
|
902 | - public function show_error( $msg ) { |
|
903 | - $this->save_notice( 'error', $msg ); |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * Displays a warning notice |
|
908 | - * |
|
909 | - * @access public |
|
910 | - * @param string $msg The message to qeue. |
|
911 | - * @since 1.0.19 |
|
912 | - */ |
|
913 | - public function show_warning( $msg ) { |
|
914 | - $this->save_notice( 'warning', $msg ); |
|
915 | - } |
|
916 | - |
|
917 | - /** |
|
918 | - * Displays a info notice |
|
919 | - * |
|
920 | - * @access public |
|
921 | - * @param string $msg The message to qeue. |
|
922 | - * @since 1.0.19 |
|
923 | - */ |
|
924 | - public function show_info( $msg ) { |
|
925 | - $this->save_notice( 'info', $msg ); |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * Show notices |
|
930 | - * |
|
931 | - * @access public |
|
932 | - * @since 1.0.19 |
|
933 | - */ |
|
934 | - public function show_notices() { |
|
851 | + */ |
|
852 | + public function has_notices() { |
|
853 | + return count( $this->get_notices() ) > 0; |
|
854 | + } |
|
855 | + |
|
856 | + /** |
|
857 | + * Clears all admin notices |
|
858 | + * |
|
859 | + * @access public |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function clear_notices() { |
|
863 | + delete_option( 'wpinv_admin_notices' ); |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * Saves a new admin notice |
|
868 | + * |
|
869 | + * @access public |
|
870 | + * @since 1.0.19 |
|
871 | + */ |
|
872 | + public function save_notice( $type, $message ) { |
|
873 | + $notices = $this->get_notices(); |
|
874 | + |
|
875 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
876 | + $notices[ $type ] = array(); |
|
877 | + } |
|
878 | + |
|
879 | + $notices[ $type ][] = $message; |
|
880 | + |
|
881 | + update_option( 'wpinv_admin_notices', $notices ); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Displays a success notice |
|
886 | + * |
|
887 | + * @param string $msg The message to qeue. |
|
888 | + * @access public |
|
889 | + * @since 1.0.19 |
|
890 | + */ |
|
891 | + public function show_success( $msg ) { |
|
892 | + $this->save_notice( 'success', $msg ); |
|
893 | + } |
|
894 | + |
|
895 | + /** |
|
896 | + * Displays a error notice |
|
897 | + * |
|
898 | + * @access public |
|
899 | + * @param string $msg The message to qeue. |
|
900 | + * @since 1.0.19 |
|
901 | + */ |
|
902 | + public function show_error( $msg ) { |
|
903 | + $this->save_notice( 'error', $msg ); |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * Displays a warning notice |
|
908 | + * |
|
909 | + * @access public |
|
910 | + * @param string $msg The message to qeue. |
|
911 | + * @since 1.0.19 |
|
912 | + */ |
|
913 | + public function show_warning( $msg ) { |
|
914 | + $this->save_notice( 'warning', $msg ); |
|
915 | + } |
|
916 | + |
|
917 | + /** |
|
918 | + * Displays a info notice |
|
919 | + * |
|
920 | + * @access public |
|
921 | + * @param string $msg The message to qeue. |
|
922 | + * @since 1.0.19 |
|
923 | + */ |
|
924 | + public function show_info( $msg ) { |
|
925 | + $this->save_notice( 'info', $msg ); |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * Show notices |
|
930 | + * |
|
931 | + * @access public |
|
932 | + * @since 1.0.19 |
|
933 | + */ |
|
934 | + public function show_notices() { |
|
935 | 935 | |
936 | 936 | $notices = $this->get_notices(); |
937 | 937 | $this->clear_notices(); |
938 | 938 | |
939 | - foreach ( $notices as $type => $messages ) { |
|
939 | + foreach ( $notices as $type => $messages ) { |
|
940 | 940 | |
941 | - if ( ! is_array( $messages ) ) { |
|
942 | - continue; |
|
943 | - } |
|
941 | + if ( ! is_array( $messages ) ) { |
|
942 | + continue; |
|
943 | + } |
|
944 | 944 | |
945 | 945 | $type = esc_attr( $type ); |
946 | - foreach ( $messages as $message ) { |
|
947 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
946 | + foreach ( $messages as $message ) { |
|
947 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
951 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
952 | - |
|
953 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
954 | - $url = wp_nonce_url( |
|
955 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
956 | - 'getpaid-nonce', |
|
957 | - 'getpaid-nonce' |
|
958 | - ); |
|
959 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
960 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
961 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
962 | - break; |
|
963 | - } |
|
951 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
952 | + |
|
953 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
954 | + $url = wp_nonce_url( |
|
955 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
956 | + 'getpaid-nonce', |
|
957 | + 'getpaid-nonce' |
|
958 | + ); |
|
959 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
960 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
961 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
962 | + break; |
|
963 | + } |
|
964 | 964 | } |
965 | 965 | |
966 | - } |
|
966 | + } |
|
967 | 967 | |
968 | 968 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -16,84 +16,84 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class GetPaid_Meta_Box_Invoice_Address { |
18 | 18 | |
19 | - /** |
|
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
24 | - public static function output( $post ) { |
|
25 | - |
|
26 | - // Prepare the invoice. |
|
27 | - $invoice = new WPInv_Invoice( $post ); |
|
28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | - $customer = new WP_User( $customer ); |
|
30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
32 | - |
|
33 | - // Address fields. |
|
34 | - $address_fields = array( |
|
35 | - 'first_name' => array( |
|
36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
37 | - 'type' => 'text', |
|
38 | - ), |
|
39 | - 'last_name' => array( |
|
40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | - 'type' => 'text', |
|
42 | - ), |
|
43 | - 'company' => array( |
|
44 | - 'label' => __( 'Company', 'invoicing' ), |
|
45 | - 'type' => 'text', |
|
46 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | - ), |
|
48 | - 'vat_number' => array( |
|
49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | - 'type' => 'text', |
|
51 | - ), |
|
52 | - 'address' => array( |
|
53 | - 'label' => __( 'Address', 'invoicing' ), |
|
54 | - 'type' => 'text', |
|
55 | - ), |
|
56 | - 'city' => array( |
|
57 | - 'label' => __( 'City', 'invoicing' ), |
|
58 | - 'type' => 'text', |
|
59 | - ), |
|
60 | - 'country' => array( |
|
61 | - 'label' => __( 'Country', 'invoicing' ), |
|
62 | - 'type' => 'select', |
|
63 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
64 | - 'options' => wpinv_get_country_list(), |
|
65 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
66 | - ), |
|
67 | - 'state' => array( |
|
68 | - 'label' => __( 'State', 'invoicing' ), |
|
69 | - 'type' => 'text', |
|
70 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
71 | - ), |
|
72 | - 'zip' => array( |
|
73 | - 'label' => __( 'Zip', 'invoicing' ), |
|
74 | - 'type' => 'text', |
|
75 | - ), |
|
76 | - 'phone' => array( |
|
77 | - 'label' => __( 'Phone', 'invoicing' ), |
|
78 | - 'type' => 'text', |
|
79 | - ), |
|
80 | - ); |
|
81 | - |
|
82 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
83 | - |
|
84 | - if ( ! empty( $states ) ) { |
|
85 | - $address_fields['state']['type'] = 'select'; |
|
86 | - $address_fields['state']['options'] = $states; |
|
87 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
88 | - } |
|
89 | - |
|
90 | - // Maybe remove the VAT field. |
|
91 | - if ( ! wpinv_use_taxes() ) { |
|
92 | - unset( $address_fields['vat_number'] ); |
|
93 | - } |
|
94 | - |
|
95 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
96 | - ?> |
|
19 | + /** |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | + public static function output( $post ) { |
|
25 | + |
|
26 | + // Prepare the invoice. |
|
27 | + $invoice = new WPInv_Invoice( $post ); |
|
28 | + $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | + $customer = new WP_User( $customer ); |
|
30 | + $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | + wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
32 | + |
|
33 | + // Address fields. |
|
34 | + $address_fields = array( |
|
35 | + 'first_name' => array( |
|
36 | + 'label' => __( 'First Name', 'invoicing' ), |
|
37 | + 'type' => 'text', |
|
38 | + ), |
|
39 | + 'last_name' => array( |
|
40 | + 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | + 'type' => 'text', |
|
42 | + ), |
|
43 | + 'company' => array( |
|
44 | + 'label' => __( 'Company', 'invoicing' ), |
|
45 | + 'type' => 'text', |
|
46 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | + ), |
|
48 | + 'vat_number' => array( |
|
49 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | + 'type' => 'text', |
|
51 | + ), |
|
52 | + 'address' => array( |
|
53 | + 'label' => __( 'Address', 'invoicing' ), |
|
54 | + 'type' => 'text', |
|
55 | + ), |
|
56 | + 'city' => array( |
|
57 | + 'label' => __( 'City', 'invoicing' ), |
|
58 | + 'type' => 'text', |
|
59 | + ), |
|
60 | + 'country' => array( |
|
61 | + 'label' => __( 'Country', 'invoicing' ), |
|
62 | + 'type' => 'select', |
|
63 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
64 | + 'options' => wpinv_get_country_list(), |
|
65 | + 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
66 | + ), |
|
67 | + 'state' => array( |
|
68 | + 'label' => __( 'State', 'invoicing' ), |
|
69 | + 'type' => 'text', |
|
70 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
71 | + ), |
|
72 | + 'zip' => array( |
|
73 | + 'label' => __( 'Zip', 'invoicing' ), |
|
74 | + 'type' => 'text', |
|
75 | + ), |
|
76 | + 'phone' => array( |
|
77 | + 'label' => __( 'Phone', 'invoicing' ), |
|
78 | + 'type' => 'text', |
|
79 | + ), |
|
80 | + ); |
|
81 | + |
|
82 | + $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
83 | + |
|
84 | + if ( ! empty( $states ) ) { |
|
85 | + $address_fields['state']['type'] = 'select'; |
|
86 | + $address_fields['state']['options'] = $states; |
|
87 | + $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
88 | + } |
|
89 | + |
|
90 | + // Maybe remove the VAT field. |
|
91 | + if ( ! wpinv_use_taxes() ) { |
|
92 | + unset( $address_fields['vat_number'] ); |
|
93 | + } |
|
94 | + |
|
95 | + $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
96 | + ?> |
|
97 | 97 | |
98 | 98 | <style> |
99 | 99 | #wpinv-address label { |
@@ -118,19 +118,19 @@ discard block |
||
118 | 118 | <div id="getpaid-invoice-email-wrapper" class="d-none"> |
119 | 119 | <input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" /> |
120 | 120 | <?php |
121 | - aui()->input( |
|
122 | - array( |
|
123 | - 'type' => 'text', |
|
124 | - 'id' => 'getpaid-invoice-new-user-email', |
|
125 | - 'name' => 'wpinv_email', |
|
126 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
127 | - 'label_type' => 'vertical', |
|
128 | - 'placeholder' => '[email protected]', |
|
129 | - 'class' => 'form-control-sm', |
|
130 | - ), |
|
131 | - true |
|
132 | - ); |
|
133 | - ?> |
|
121 | + aui()->input( |
|
122 | + array( |
|
123 | + 'type' => 'text', |
|
124 | + 'id' => 'getpaid-invoice-new-user-email', |
|
125 | + 'name' => 'wpinv_email', |
|
126 | + 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
127 | + 'label_type' => 'vertical', |
|
128 | + 'placeholder' => '[email protected]', |
|
129 | + 'class' => 'form-control-sm', |
|
130 | + ), |
|
131 | + true |
|
132 | + ); |
|
133 | + ?> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | 136 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
@@ -154,39 +154,39 @@ discard block |
||
154 | 154 | <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper"> |
155 | 155 | <?php |
156 | 156 | |
157 | - if ( 'select' === $field['type'] ) { |
|
158 | - aui()->select( |
|
159 | - array( |
|
160 | - 'id' => 'wpinv_' . $key, |
|
161 | - 'name' => 'wpinv_' . $key, |
|
162 | - 'label' => $field['label'], |
|
163 | - 'label_type' => 'vertical', |
|
164 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
165 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
166 | - 'value' => $invoice->get( $key, 'edit' ), |
|
167 | - 'options' => $field['options'], |
|
168 | - 'data-allow-clear' => 'false', |
|
169 | - 'select2' => true, |
|
170 | - ), |
|
171 | - true |
|
172 | - ); |
|
173 | - } else { |
|
174 | - aui()->input( |
|
175 | - array( |
|
176 | - 'type' => $field['type'], |
|
177 | - 'id' => 'wpinv_' . $key, |
|
178 | - 'name' => 'wpinv_' . $key, |
|
179 | - 'label' => $field['label'], |
|
180 | - 'label_type' => 'vertical', |
|
181 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
182 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
183 | - 'value' => $invoice->get( $key, 'edit' ), |
|
184 | - ), |
|
185 | - true |
|
186 | - ); |
|
187 | - } |
|
188 | - |
|
189 | - ?> |
|
157 | + if ( 'select' === $field['type'] ) { |
|
158 | + aui()->select( |
|
159 | + array( |
|
160 | + 'id' => 'wpinv_' . $key, |
|
161 | + 'name' => 'wpinv_' . $key, |
|
162 | + 'label' => $field['label'], |
|
163 | + 'label_type' => 'vertical', |
|
164 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
165 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
166 | + 'value' => $invoice->get( $key, 'edit' ), |
|
167 | + 'options' => $field['options'], |
|
168 | + 'data-allow-clear' => 'false', |
|
169 | + 'select2' => true, |
|
170 | + ), |
|
171 | + true |
|
172 | + ); |
|
173 | + } else { |
|
174 | + aui()->input( |
|
175 | + array( |
|
176 | + 'type' => $field['type'], |
|
177 | + 'id' => 'wpinv_' . $key, |
|
178 | + 'name' => 'wpinv_' . $key, |
|
179 | + 'label' => $field['label'], |
|
180 | + 'label_type' => 'vertical', |
|
181 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
182 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
183 | + 'value' => $invoice->get( $key, 'edit' ), |
|
184 | + ), |
|
185 | + true |
|
186 | + ); |
|
187 | + } |
|
188 | + |
|
189 | + ?> |
|
190 | 190 | </div> |
191 | 191 | <?php endforeach; ?> |
192 | 192 | </div> |
@@ -197,48 +197,48 @@ discard block |
||
197 | 197 | <div class="row"> |
198 | 198 | <div class="col-12 col-sm-6"> |
199 | 199 | <?php |
200 | - aui()->select( |
|
201 | - array( |
|
202 | - 'id' => 'wpinv_template', |
|
203 | - 'name' => 'wpinv_template', |
|
204 | - 'label' => __( 'Template', 'invoicing' ), |
|
205 | - 'label_type' => 'vertical', |
|
206 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
207 | - 'class' => 'form-control-sm', |
|
208 | - 'value' => $invoice->get_template( 'edit' ), |
|
209 | - 'options' => array( |
|
210 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
211 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
212 | - ), |
|
213 | - 'data-allow-clear' => 'false', |
|
214 | - 'select2' => true, |
|
215 | - ), |
|
216 | - true |
|
217 | - ); |
|
218 | - ?> |
|
200 | + aui()->select( |
|
201 | + array( |
|
202 | + 'id' => 'wpinv_template', |
|
203 | + 'name' => 'wpinv_template', |
|
204 | + 'label' => __( 'Template', 'invoicing' ), |
|
205 | + 'label_type' => 'vertical', |
|
206 | + 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
207 | + 'class' => 'form-control-sm', |
|
208 | + 'value' => $invoice->get_template( 'edit' ), |
|
209 | + 'options' => array( |
|
210 | + 'quantity' => __( 'Quantity', 'invoicing' ), |
|
211 | + 'hours' => __( 'Hours', 'invoicing' ), |
|
212 | + ), |
|
213 | + 'data-allow-clear' => 'false', |
|
214 | + 'select2' => true, |
|
215 | + ), |
|
216 | + true |
|
217 | + ); |
|
218 | + ?> |
|
219 | 219 | </div> |
220 | 220 | <div class="col-12 col-sm-6"> |
221 | 221 | <?php |
222 | 222 | |
223 | - // Set currency. |
|
224 | - aui()->select( |
|
225 | - array( |
|
226 | - 'id' => 'wpinv_currency', |
|
227 | - 'name' => 'wpinv_currency', |
|
228 | - 'label' => __( 'Currency', 'invoicing' ), |
|
229 | - 'label_type' => 'vertical', |
|
230 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
231 | - 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
232 | - 'value' => $invoice->get_currency( 'edit' ), |
|
233 | - 'required' => false, |
|
234 | - 'data-allow-clear' => 'false', |
|
235 | - 'select2' => true, |
|
236 | - 'options' => wpinv_get_currencies(), |
|
237 | - ), |
|
238 | - true |
|
239 | - ); |
|
240 | - |
|
241 | - ?> |
|
223 | + // Set currency. |
|
224 | + aui()->select( |
|
225 | + array( |
|
226 | + 'id' => 'wpinv_currency', |
|
227 | + 'name' => 'wpinv_currency', |
|
228 | + 'label' => __( 'Currency', 'invoicing' ), |
|
229 | + 'label_type' => 'vertical', |
|
230 | + 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
231 | + 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
232 | + 'value' => $invoice->get_currency( 'edit' ), |
|
233 | + 'required' => false, |
|
234 | + 'data-allow-clear' => 'false', |
|
235 | + 'select2' => true, |
|
236 | + 'options' => wpinv_get_currencies(), |
|
237 | + ), |
|
238 | + true |
|
239 | + ); |
|
240 | + |
|
241 | + ?> |
|
242 | 242 | </div> |
243 | 243 | </div> |
244 | 244 | |
@@ -248,123 +248,123 @@ discard block |
||
248 | 248 | <div class="row"> |
249 | 249 | <div class="col-12 col-sm-6"> |
250 | 250 | <?php |
251 | - aui()->input( |
|
252 | - array( |
|
253 | - 'type' => 'text', |
|
254 | - 'id' => 'wpinv_company_id', |
|
255 | - 'name' => 'wpinv_company_id', |
|
256 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
257 | - 'label_type' => 'vertical', |
|
258 | - 'placeholder' => '', |
|
259 | - 'class' => 'form-control-sm', |
|
260 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
261 | - ), |
|
262 | - true |
|
263 | - ); |
|
264 | - ?> |
|
251 | + aui()->input( |
|
252 | + array( |
|
253 | + 'type' => 'text', |
|
254 | + 'id' => 'wpinv_company_id', |
|
255 | + 'name' => 'wpinv_company_id', |
|
256 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
257 | + 'label_type' => 'vertical', |
|
258 | + 'placeholder' => '', |
|
259 | + 'class' => 'form-control-sm', |
|
260 | + 'value' => $invoice->get_company_id( 'edit' ), |
|
261 | + ), |
|
262 | + true |
|
263 | + ); |
|
264 | + ?> |
|
265 | 265 | </div> |
266 | 266 | </div> |
267 | 267 | |
268 | 268 | <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
269 | 269 | </div> |
270 | 270 | <?php |
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Save meta box data. |
|
275 | - * |
|
276 | - * @param int $post_id |
|
277 | - * @param array $posted the posted data. |
|
278 | - */ |
|
279 | - public static function save( $post_id, $posted ) { |
|
280 | - |
|
281 | - // Prepare the invoice. |
|
282 | - $invoice = new WPInv_Invoice( $post_id ); |
|
283 | - |
|
284 | - // Load new data. |
|
285 | - $invoice->set_props( |
|
286 | - array( |
|
287 | - 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
288 | - 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
289 | - 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
290 | - 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
291 | - 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
292 | - 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
293 | - 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
294 | - 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
295 | - 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
296 | - 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
297 | - 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
298 | - 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
299 | - 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
300 | - 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
301 | - 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
302 | - 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
303 | - 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
304 | - 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
305 | - 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
306 | - 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
307 | - 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
308 | - 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
309 | - ) |
|
310 | - ); |
|
311 | - |
|
312 | - // Discount code. |
|
313 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
314 | - |
|
315 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
316 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
317 | - } |
|
318 | - |
|
319 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
320 | - if ( $discount->exists() ) { |
|
321 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
322 | - } else { |
|
323 | - $invoice->remove_discount( 'discount_code' ); |
|
324 | - } |
|
325 | - |
|
326 | - // Recalculate totals. |
|
327 | - $invoice->recalculate_total(); |
|
328 | - |
|
329 | - } |
|
330 | - |
|
331 | - // If we're creating a new user... |
|
332 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
333 | - |
|
334 | - // Attempt to create the user. |
|
335 | - $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
336 | - |
|
337 | - // If successful, update the invoice author. |
|
338 | - if ( is_numeric( $user ) ) { |
|
339 | - $invoice->set_author( $user ); |
|
340 | - } else { |
|
341 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - // Do not send new invoice notifications. |
|
346 | - $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
347 | - |
|
348 | - // Save the invoice. |
|
349 | - $invoice->save(); |
|
350 | - |
|
351 | - // Save the user address. |
|
352 | - getpaid_save_invoice_user_address( $invoice ); |
|
353 | - |
|
354 | - // Undo do not send new invoice notifications. |
|
355 | - $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
356 | - |
|
357 | - // (Maybe) send new user notification. |
|
358 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
359 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
360 | - wp_send_new_user_notifications( $user, 'user' ); |
|
361 | - } |
|
362 | - |
|
363 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
364 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
365 | - } |
|
366 | - |
|
367 | - // Fires after an invoice is saved. |
|
368 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
369 | - } |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Save meta box data. |
|
275 | + * |
|
276 | + * @param int $post_id |
|
277 | + * @param array $posted the posted data. |
|
278 | + */ |
|
279 | + public static function save( $post_id, $posted ) { |
|
280 | + |
|
281 | + // Prepare the invoice. |
|
282 | + $invoice = new WPInv_Invoice( $post_id ); |
|
283 | + |
|
284 | + // Load new data. |
|
285 | + $invoice->set_props( |
|
286 | + array( |
|
287 | + 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
288 | + 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
289 | + 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
290 | + 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
291 | + 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
292 | + 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
293 | + 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
294 | + 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
295 | + 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
296 | + 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
297 | + 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
298 | + 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
299 | + 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
300 | + 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
301 | + 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
302 | + 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
303 | + 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
304 | + 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
305 | + 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
306 | + 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
307 | + 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
308 | + 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
309 | + ) |
|
310 | + ); |
|
311 | + |
|
312 | + // Discount code. |
|
313 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
314 | + |
|
315 | + if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
316 | + $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
317 | + } |
|
318 | + |
|
319 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
320 | + if ( $discount->exists() ) { |
|
321 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
322 | + } else { |
|
323 | + $invoice->remove_discount( 'discount_code' ); |
|
324 | + } |
|
325 | + |
|
326 | + // Recalculate totals. |
|
327 | + $invoice->recalculate_total(); |
|
328 | + |
|
329 | + } |
|
330 | + |
|
331 | + // If we're creating a new user... |
|
332 | + if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
333 | + |
|
334 | + // Attempt to create the user. |
|
335 | + $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
336 | + |
|
337 | + // If successful, update the invoice author. |
|
338 | + if ( is_numeric( $user ) ) { |
|
339 | + $invoice->set_author( $user ); |
|
340 | + } else { |
|
341 | + wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + // Do not send new invoice notifications. |
|
346 | + $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
347 | + |
|
348 | + // Save the invoice. |
|
349 | + $invoice->save(); |
|
350 | + |
|
351 | + // Save the user address. |
|
352 | + getpaid_save_invoice_user_address( $invoice ); |
|
353 | + |
|
354 | + // Undo do not send new invoice notifications. |
|
355 | + $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
356 | + |
|
357 | + // (Maybe) send new user notification. |
|
358 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
359 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
360 | + wp_send_new_user_notifications( $user, 'user' ); |
|
361 | + } |
|
362 | + |
|
363 | + if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
364 | + getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
365 | + } |
|
366 | + |
|
367 | + // Fires after an invoice is saved. |
|
368 | + do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
369 | + } |
|
370 | 370 | } |
@@ -12,184 +12,184 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
133 | 125 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
138 | 131 | |
139 | - return $invoice; |
|
140 | - } |
|
132 | + $invoice = $submission->get_invoice(); |
|
141 | 133 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
150 | 138 | |
151 | - $submission = $this->payment_form_submission; |
|
139 | + return $invoice; |
|
140 | + } |
|
152 | 141 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | 157 | $invoice->set_items( $items ); |
158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | + $invoice->set_currency( $submission->get_currency() ); |
|
163 | 163 | |
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | - } |
|
164 | + if ( $submission->has_shipping() ) { |
|
165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | + } |
|
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
171 | + if ( $submission->has_discount_code() ) { |
|
172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
173 | - } |
|
174 | - |
|
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | - return $invoice; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves the submission's customer. |
|
181 | - * |
|
182 | - * @return int The customer id. |
|
183 | - */ |
|
184 | - protected function get_submission_customer() { |
|
185 | - $submission = $this->payment_form_submission; |
|
186 | - |
|
187 | - // If this is an existing invoice... |
|
188 | - if ( $submission->has_invoice() ) { |
|
189 | - return $submission->get_invoice()->get_user_id(); |
|
190 | - } |
|
191 | - |
|
192 | - // (Maybe) create the user. |
|
173 | + } |
|
174 | + |
|
175 | + getpaid_maybe_add_default_address( $invoice ); |
|
176 | + return $invoice; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves the submission's customer. |
|
181 | + * |
|
182 | + * @return int The customer id. |
|
183 | + */ |
|
184 | + protected function get_submission_customer() { |
|
185 | + $submission = $this->payment_form_submission; |
|
186 | + |
|
187 | + // If this is an existing invoice... |
|
188 | + if ( $submission->has_invoice() ) { |
|
189 | + return $submission->get_invoice()->get_user_id(); |
|
190 | + } |
|
191 | + |
|
192 | + // (Maybe) create the user. |
|
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | if ( empty( $user ) ) { |
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | + $name = implode( '', array_filter( $name ) ); |
|
202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
203 | 203 | |
204 | - // (Maybe) send new user notification. |
|
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
208 | - } |
|
209 | - } |
|
204 | + // (Maybe) send new user notification. |
|
205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | 211 | if ( is_wp_error( $user ) ) { |
212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
214 | 214 | |
215 | 215 | if ( is_numeric( $user ) ) { |
216 | 216 | return $user; |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - return $user->ID; |
|
219 | + return $user->ID; |
|
220 | 220 | |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Prepares submission data for saving to the database. |
225 | 225 | * |
226 | - * @return array |
|
226 | + * @return array |
|
227 | 227 | */ |
228 | 228 | public function prepare_submission_data_for_saving() { |
229 | 229 | |
230 | - $submission = $this->payment_form_submission; |
|
230 | + $submission = $this->payment_form_submission; |
|
231 | 231 | |
232 | - // Prepared submission details. |
|
232 | + // Prepared submission details. |
|
233 | 233 | $prepared = array( |
234 | - 'all' => array(), |
|
235 | - 'meta' => array(), |
|
236 | - ); |
|
234 | + 'all' => array(), |
|
235 | + 'meta' => array(), |
|
236 | + ); |
|
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | - // Loop through the submitted details. |
|
241 | + // Loop through the submitted details. |
|
242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
243 | 243 | |
244 | - // Skip premade fields. |
|
244 | + // Skip premade fields. |
|
245 | 245 | if ( ! empty( $field['premade'] ) ) { |
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | - // Ensure address is provided. |
|
250 | - if ( 'address' === $field['type'] ) { |
|
249 | + // Ensure address is provided. |
|
250 | + if ( 'address' === $field['type'] ) { |
|
251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ( $field['fields'] as $address_field ) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
266 | 266 | // Handle misc fields. |
267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
268 | 268 | |
269 | - // Uploads. |
|
270 | - if ( 'file_upload' === $field['type'] ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
269 | + // Uploads. |
|
270 | + if ( 'file_upload' === $field['type'] ) { |
|
271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | - } |
|
273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | + } |
|
276 | 276 | |
277 | - $value = array(); |
|
277 | + $value = array(); |
|
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | - $value[] = sprintf( |
|
281 | - '<a href="%s" target="_blank">%s</a>', |
|
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
284 | - ); |
|
285 | - } |
|
279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + $value[] = sprintf( |
|
281 | + '<a href="%s" target="_blank">%s</a>', |
|
282 | + esc_url_raw( $url ), |
|
283 | + esc_html( $name ) |
|
284 | + ); |
|
285 | + } |
|
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode( ' | ', $value ); |
|
288 | 288 | |
289 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
290 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | - } else { |
|
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | - } |
|
289 | + } elseif ( 'checkbox' === $field['type'] ) { |
|
290 | + $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | + } else { |
|
292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
@@ -298,192 +298,192 @@ discard block |
||
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | - } |
|
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | + } |
|
304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | 305 | |
306 | 306 | } |
307 | - } |
|
307 | + } |
|
308 | 308 | |
309 | - return $prepared; |
|
309 | + return $prepared; |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
313 | + /** |
|
314 | 314 | * Retrieves address details. |
315 | 315 | * |
316 | - * @return array |
|
317 | - * @param WPInv_Invoice $invoice |
|
318 | - * @param string $type |
|
316 | + * @return array |
|
317 | + * @param WPInv_Invoice $invoice |
|
318 | + * @param string $type |
|
319 | 319 | */ |
320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
321 | 321 | |
322 | - $data = $this->payment_form_submission->get_data(); |
|
323 | - $type = sanitize_key( $type ); |
|
324 | - $address = array(); |
|
325 | - $prepared = array(); |
|
322 | + $data = $this->payment_form_submission->get_data(); |
|
323 | + $type = sanitize_key( $type ); |
|
324 | + $address = array(); |
|
325 | + $prepared = array(); |
|
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
329 | - } |
|
327 | + if ( ! empty( $data[ $type ] ) ) { |
|
328 | + $address = $data[ $type ]; |
|
329 | + } |
|
330 | 330 | |
331 | - // Clean address details. |
|
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | - } |
|
331 | + // Clean address details. |
|
332 | + foreach ( $address as $key => $value ) { |
|
333 | + $key = sanitize_key( $key ); |
|
334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
335 | + $value = wpinv_clean( $value ); |
|
336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | + } |
|
338 | 338 | |
339 | - // Filter address details. |
|
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
339 | + // Filter address details. |
|
340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | 341 | |
342 | - // Remove non-whitelisted values. |
|
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
342 | + // Remove non-whitelisted values. |
|
343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
347 | + /** |
|
348 | 348 | * Prepares the billing details. |
349 | 349 | * |
350 | - * @return array |
|
351 | - * @param WPInv_Invoice $invoice |
|
350 | + * @return array |
|
351 | + * @param WPInv_Invoice $invoice |
|
352 | 352 | */ |
353 | 353 | protected function prepare_billing_info( &$invoice ) { |
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | 356 | |
357 | - // Update the invoice with the billing details. |
|
358 | - $invoice->set_props( $billing_address ); |
|
357 | + // Update the invoice with the billing details. |
|
358 | + $invoice->set_props( $billing_address ); |
|
359 | 359 | |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
362 | + /** |
|
363 | 363 | * Prepares the shipping details. |
364 | 364 | * |
365 | - * @return array |
|
366 | - * @param WPInv_Invoice $invoice |
|
365 | + * @return array |
|
366 | + * @param WPInv_Invoice $invoice |
|
367 | 367 | */ |
368 | 368 | protected function prepare_shipping_info( $invoice ) { |
369 | 369 | |
370 | - $data = $this->payment_form_submission->get_data(); |
|
370 | + $data = $this->payment_form_submission->get_data(); |
|
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | - } |
|
372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + } |
|
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | 377 | |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Confirms the submission is valid and send users to the gateway. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice |
|
384 | - * @param array $prepared_payment_form_data |
|
385 | - * @param array $shipping |
|
386 | - */ |
|
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
380 | + /** |
|
381 | + * Confirms the submission is valid and send users to the gateway. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice |
|
384 | + * @param array $prepared_payment_form_data |
|
385 | + * @param array $shipping |
|
386 | + */ |
|
387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
388 | 388 | |
389 | - // Ensure the invoice exists. |
|
389 | + // Ensure the invoice exists. |
|
390 | 390 | if ( ! $invoice->exists() ) { |
391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
392 | 392 | } |
393 | 393 | |
394 | - // Save payment form data. |
|
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
394 | + // Save payment form data. |
|
395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | - } |
|
400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + } |
|
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | - } |
|
407 | - } |
|
404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + } |
|
407 | + } |
|
408 | 408 | |
409 | - // Save payment form data. |
|
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
409 | + // Save payment form data. |
|
410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | 411 | if ( ! empty( $shipping ) ) { |
412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - // Backwards compatibility. |
|
415 | + // Backwards compatibility. |
|
416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
417 | 417 | |
418 | - try { |
|
419 | - $this->process_payment( $invoice ); |
|
420 | - } catch ( Exception $e ) { |
|
421 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
422 | - } |
|
418 | + try { |
|
419 | + $this->process_payment( $invoice ); |
|
420 | + } catch ( Exception $e ) { |
|
421 | + wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
422 | + } |
|
423 | 423 | |
424 | 424 | // If we are here, there was an error. |
425 | - wpinv_send_back_to_checkout( $invoice ); |
|
425 | + wpinv_send_back_to_checkout( $invoice ); |
|
426 | 426 | |
427 | - } |
|
427 | + } |
|
428 | 428 | |
429 | - /** |
|
430 | - * Processes the actual payment. |
|
431 | - * |
|
432 | - * @param WPInv_Invoice $invoice |
|
433 | - */ |
|
434 | - protected function process_payment( $invoice ) { |
|
429 | + /** |
|
430 | + * Processes the actual payment. |
|
431 | + * |
|
432 | + * @param WPInv_Invoice $invoice |
|
433 | + */ |
|
434 | + protected function process_payment( $invoice ) { |
|
435 | 435 | |
436 | - // Clear any checkout errors. |
|
437 | - wpinv_clear_errors(); |
|
436 | + // Clear any checkout errors. |
|
437 | + wpinv_clear_errors(); |
|
438 | 438 | |
439 | - // No need to send free invoices to the gateway. |
|
440 | - if ( $invoice->is_free() ) { |
|
441 | - $this->process_free_payment( $invoice ); |
|
442 | - } |
|
439 | + // No need to send free invoices to the gateway. |
|
440 | + if ( $invoice->is_free() ) { |
|
441 | + $this->process_free_payment( $invoice ); |
|
442 | + } |
|
443 | 443 | |
444 | - $submission = $this->payment_form_submission; |
|
444 | + $submission = $this->payment_form_submission; |
|
445 | 445 | |
446 | - // Fires before sending to the gateway. |
|
447 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
446 | + // Fires before sending to the gateway. |
|
447 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
448 | 448 | |
449 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
450 | - $submission_data = $submission->get_data(); |
|
451 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
452 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
449 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
450 | + $submission_data = $submission->get_data(); |
|
451 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
452 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
453 | 453 | |
454 | - // Validate the currency. |
|
455 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
456 | - wpinv_set_error( 'invalid_currency' ); |
|
457 | - } |
|
454 | + // Validate the currency. |
|
455 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
456 | + wpinv_set_error( 'invalid_currency' ); |
|
457 | + } |
|
458 | 458 | |
459 | - // Check to see if we have any errors. |
|
460 | - if ( wpinv_get_errors() ) { |
|
461 | - wpinv_send_back_to_checkout( $invoice ); |
|
462 | - } |
|
459 | + // Check to see if we have any errors. |
|
460 | + if ( wpinv_get_errors() ) { |
|
461 | + wpinv_send_back_to_checkout( $invoice ); |
|
462 | + } |
|
463 | 463 | |
464 | - // Send info to the gateway for payment processing |
|
465 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
464 | + // Send info to the gateway for payment processing |
|
465 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
466 | 466 | |
467 | - // Backwards compatibility. |
|
468 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
467 | + // Backwards compatibility. |
|
468 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
469 | 469 | |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - /** |
|
473 | - * Marks the invoice as paid in case the checkout is free. |
|
474 | - * |
|
475 | - * @param WPInv_Invoice $invoice |
|
476 | - */ |
|
477 | - protected function process_free_payment( $invoice ) { |
|
472 | + /** |
|
473 | + * Marks the invoice as paid in case the checkout is free. |
|
474 | + * |
|
475 | + * @param WPInv_Invoice $invoice |
|
476 | + */ |
|
477 | + protected function process_free_payment( $invoice ) { |
|
478 | 478 | |
479 | - $invoice->set_gateway( 'none' ); |
|
480 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
481 | - $invoice->mark_paid(); |
|
482 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
479 | + $invoice->set_gateway( 'none' ); |
|
480 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
481 | + $invoice->mark_paid(); |
|
482 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
483 | 483 | |
484 | - } |
|
484 | + } |
|
485 | 485 | |
486 | - /** |
|
486 | + /** |
|
487 | 487 | * Sends a redrect response to payment details. |
488 | 488 | * |
489 | 489 | */ |