@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
83 | 83 | |
84 | - $invoice_statuses = array( |
|
85 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
84 | + $invoice_statuses = array( |
|
85 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
86 | 86 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
87 | 87 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
88 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
89 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
90 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
88 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
89 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
90 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
91 | 91 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
92 | 92 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
93 | 93 | ); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $invoice = $invoice->get_post_type(); |
105 | 105 | } |
106 | 106 | |
107 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
107 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -222,25 +222,25 @@ discard block |
||
222 | 222 | * @return string |
223 | 223 | */ |
224 | 224 | function getpaid_get_price_format() { |
225 | - $currency_pos = wpinv_currency_position(); |
|
226 | - $format = '%1$s%2$s'; |
|
225 | + $currency_pos = wpinv_currency_position(); |
|
226 | + $format = '%1$s%2$s'; |
|
227 | 227 | |
228 | - switch ( $currency_pos ) { |
|
229 | - case 'left': |
|
230 | - $format = '%1$s%2$s'; |
|
231 | - break; |
|
232 | - case 'right': |
|
233 | - $format = '%2$s%1$s'; |
|
234 | - break; |
|
235 | - case 'left_space': |
|
236 | - $format = '%1$s %2$s'; |
|
237 | - break; |
|
238 | - case 'right_space': |
|
239 | - $format = '%2$s %1$s'; |
|
240 | - break; |
|
241 | - } |
|
228 | + switch ( $currency_pos ) { |
|
229 | + case 'left': |
|
230 | + $format = '%1$s%2$s'; |
|
231 | + break; |
|
232 | + case 'right': |
|
233 | + $format = '%2$s%1$s'; |
|
234 | + break; |
|
235 | + case 'left_space': |
|
236 | + $format = '%1$s %2$s'; |
|
237 | + break; |
|
238 | + case 'right_space': |
|
239 | + $format = '%2$s %1$s'; |
|
240 | + break; |
|
241 | + } |
|
242 | 242 | |
243 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
243 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -343,13 +343,13 @@ discard block |
||
343 | 343 | * @param mixed $value Value. |
344 | 344 | */ |
345 | 345 | function getpaid_maybe_define_constant( $name, $value ) { |
346 | - if ( ! defined( $name ) ) { |
|
347 | - define( $name, $value ); |
|
348 | - } |
|
346 | + if ( ! defined( $name ) ) { |
|
347 | + define( $name, $value ); |
|
348 | + } |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | function wpinv_get_php_arg_separator_output() { |
352 | - return ini_get( 'arg_separator.output' ); |
|
352 | + return ini_get( 'arg_separator.output' ); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | function wpinv_rgb_from_hex( $color ) { |
@@ -700,11 +700,11 @@ discard block |
||
700 | 700 | $list = array(); |
701 | 701 | } |
702 | 702 | |
703 | - if ( ! is_array( $list ) ) { |
|
704 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
705 | - } |
|
703 | + if ( ! is_array( $list ) ) { |
|
704 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
705 | + } |
|
706 | 706 | |
707 | - return $list; |
|
707 | + return $list; |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | /** |
@@ -724,9 +724,9 @@ discard block |
||
724 | 724 | } |
725 | 725 | |
726 | 726 | $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
727 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
727 | + wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
728 | 728 | |
729 | - return $data; |
|
729 | + return $data; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | /** |
@@ -755,17 +755,17 @@ discard block |
||
755 | 755 | */ |
756 | 756 | function wpinv_clean( $var ) { |
757 | 757 | |
758 | - if ( is_array( $var ) ) { |
|
759 | - return array_map( 'wpinv_clean', $var ); |
|
758 | + if ( is_array( $var ) ) { |
|
759 | + return array_map( 'wpinv_clean', $var ); |
|
760 | 760 | } |
761 | 761 | |
762 | 762 | if ( is_object( $var ) ) { |
763 | - $object_vars = get_object_vars( $var ); |
|
764 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
765 | - $var->$property_name = wpinv_clean( $property_value ); |
|
763 | + $object_vars = get_object_vars( $var ); |
|
764 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
765 | + $var->$property_name = wpinv_clean( $property_value ); |
|
766 | 766 | } |
767 | 767 | return $var; |
768 | - } |
|
768 | + } |
|
769 | 769 | |
770 | 770 | return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
771 | 771 | } |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | */ |
779 | 779 | function getpaid_convert_price_string_to_options( $str ) { |
780 | 780 | |
781 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
781 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
782 | 782 | $options = array(); |
783 | 783 | |
784 | 784 | foreach ( $raw_options as $option ) { |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | * @return string |
857 | 857 | */ |
858 | 858 | function getpaid_date_format() { |
859 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
859 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | /** |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | * @return string |
866 | 866 | */ |
867 | 867 | function getpaid_time_format() { |
868 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
868 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | /** |
@@ -878,15 +878,15 @@ discard block |
||
878 | 878 | function getpaid_limit_length( $string, $limit ) { |
879 | 879 | $str_limit = $limit - 3; |
880 | 880 | |
881 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
882 | - if ( mb_strlen( $string ) > $limit ) { |
|
883 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
884 | - } |
|
885 | - } else { |
|
886 | - if ( strlen( $string ) > $limit ) { |
|
887 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
888 | - } |
|
889 | - } |
|
881 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
882 | + if ( mb_strlen( $string ) > $limit ) { |
|
883 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
884 | + } |
|
885 | + } else { |
|
886 | + if ( strlen( $string ) > $limit ) { |
|
887 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
888 | + } |
|
889 | + } |
|
890 | 890 | return $string; |
891 | 891 | |
892 | 892 | } |
@@ -14,500 +14,500 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax instance. |
|
40 | - * |
|
41 | - * @var WPInv_EUVat |
|
42 | - */ |
|
43 | - public $tax; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array An array of payment gateways. |
|
47 | - */ |
|
48 | - public $gateways; |
|
49 | - |
|
50 | - /** |
|
51 | - * Class constructor. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - $this->define_constants(); |
|
55 | - $this->includes(); |
|
56 | - $this->init_hooks(); |
|
57 | - $this->set_properties(); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets a custom data property. |
|
62 | - * |
|
63 | - * @param string $prop The prop to set. |
|
64 | - * @param mixed $value The value to retrieve. |
|
65 | - */ |
|
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Gets a custom data property. |
|
72 | - * |
|
73 | - * @param string $prop The prop to set. |
|
74 | - * @return mixed The value. |
|
75 | - */ |
|
76 | - public function get( $prop ) { |
|
77 | - |
|
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
80 | - } |
|
81 | - |
|
82 | - return null; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Define class properties. |
|
87 | - */ |
|
88 | - public function set_properties() { |
|
89 | - |
|
90 | - // Sessions. |
|
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | - $this->tax = new WPInv_EUVat(); |
|
94 | - $this->tax->init(); |
|
95 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | - |
|
97 | - // Init other objects. |
|
98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
101 | - $this->set( 'api', new WPInv_API() ); |
|
102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | - $this->set( 'template', new GetPaid_Template() ); |
|
104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | - |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Define plugin constants. |
|
115 | - */ |
|
116 | - public function define_constants() { |
|
117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | - $this->version = WPINV_VERSION; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Hook into actions and filters. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - */ |
|
127 | - protected function init_hooks() { |
|
128 | - /* Internationalize the text strings used. */ |
|
129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | - |
|
131 | - // Init the plugin after WordPress inits. |
|
132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
134 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | - |
|
137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | - } |
|
140 | - |
|
141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | - |
|
147 | - // Fires after registering actions. |
|
148 | - do_action( 'wpinv_actions', $this ); |
|
149 | - do_action( 'getpaid_actions', $this ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - public function plugins_loaded() { |
|
154 | - /* Internationalize the text strings used. */ |
|
155 | - $this->load_textdomain(); |
|
156 | - |
|
157 | - do_action( 'wpinv_loaded' ); |
|
158 | - |
|
159 | - // Fix oxygen page builder conflict |
|
160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
161 | - wpinv_oxygen_fix_conflict(); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Load the translation of the plugin. |
|
167 | - * |
|
168 | - * @since 1.0 |
|
169 | - */ |
|
170 | - public function load_textdomain( $locale = NULL ) { |
|
171 | - if ( empty( $locale ) ) { |
|
172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | - } |
|
174 | - |
|
175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | - |
|
177 | - unload_textdomain( 'invoicing' ); |
|
178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | - |
|
181 | - /** |
|
182 | - * Define language constants. |
|
183 | - */ |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Include required core files used in admin and on the frontend. |
|
189 | - */ |
|
190 | - public function includes() { |
|
191 | - |
|
192 | - // Start with the settings. |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | - |
|
195 | - // Packages/libraries. |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | - |
|
199 | - // Load functions. |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | - |
|
216 | - // Register autoloader. |
|
217 | - try { |
|
218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | - } catch ( Exception $e ) { |
|
220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | - } |
|
222 | - |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | - |
|
245 | - /** |
|
246 | - * Load the tax class. |
|
247 | - */ |
|
248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | - } |
|
251 | - |
|
252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | - GetPaid_Post_Types_Admin::init(); |
|
254 | - |
|
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | - // load the user class only on the users.php page |
|
264 | - global $pagenow; |
|
265 | - if($pagenow=='users.php'){ |
|
266 | - new WPInv_Admin_Users(); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - // Register cli commands |
|
271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | - } |
|
275 | - |
|
276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Class autoloader |
|
281 | - * |
|
282 | - * @param string $class_name The name of the class to load. |
|
283 | - * @access public |
|
284 | - * @since 1.0.19 |
|
285 | - * @return void |
|
286 | - */ |
|
287 | - public function autoload( $class_name ) { |
|
288 | - |
|
289 | - // Normalize the class name... |
|
290 | - $class_name = strtolower( $class_name ); |
|
291 | - |
|
292 | - // ... and make sure it is our class. |
|
293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | - return; |
|
295 | - } |
|
296 | - |
|
297 | - // Next, prepare the file name from the class. |
|
298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | - |
|
300 | - // Base path of the classes. |
|
301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | - |
|
303 | - // And an array of possible locations in order of importance. |
|
304 | - $locations = array( |
|
305 | - "$plugin_path/includes", |
|
306 | - "$plugin_path/includes/data-stores", |
|
307 | - "$plugin_path/includes/gateways", |
|
308 | - "$plugin_path/includes/payments", |
|
309 | - "$plugin_path/includes/api", |
|
310 | - "$plugin_path/includes/admin", |
|
311 | - "$plugin_path/includes/admin/meta-boxes", |
|
312 | - ); |
|
313 | - |
|
314 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
315 | - |
|
316 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | - include trailingslashit( $location ) . $file_name; |
|
318 | - break; |
|
319 | - } |
|
320 | - |
|
321 | - } |
|
322 | - |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Inits hooks etc. |
|
327 | - */ |
|
328 | - public function init() { |
|
329 | - |
|
330 | - // Fires before getpaid inits. |
|
331 | - do_action( 'before_getpaid_init', $this ); |
|
332 | - |
|
333 | - // Load default gateways. |
|
334 | - $gateways = apply_filters( |
|
335 | - 'getpaid_default_gateways', |
|
336 | - array( |
|
337 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
338 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
339 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
340 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
341 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
342 | - ) |
|
343 | - ); |
|
344 | - |
|
345 | - foreach ( $gateways as $id => $class ) { |
|
346 | - $this->gateways[ $id ] = new $class(); |
|
347 | - } |
|
348 | - |
|
349 | - // Fires after getpaid inits. |
|
350 | - do_action( 'getpaid_init', $this ); |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Checks if this is an IPN request and processes it. |
|
356 | - */ |
|
357 | - public function maybe_process_ipn() { |
|
358 | - |
|
359 | - // Ensure that this is an IPN request. |
|
360 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
361 | - return; |
|
362 | - } |
|
363 | - |
|
364 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
365 | - |
|
366 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
368 | - exit; |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - public function enqueue_scripts() { |
|
373 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
374 | - |
|
375 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
378 | - |
|
379 | - // Register scripts |
|
380 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
382 | - |
|
383 | - $localize = array(); |
|
384 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
386 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
387 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
388 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
389 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
390 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax instance. |
|
40 | + * |
|
41 | + * @var WPInv_EUVat |
|
42 | + */ |
|
43 | + public $tax; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array An array of payment gateways. |
|
47 | + */ |
|
48 | + public $gateways; |
|
49 | + |
|
50 | + /** |
|
51 | + * Class constructor. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + $this->define_constants(); |
|
55 | + $this->includes(); |
|
56 | + $this->init_hooks(); |
|
57 | + $this->set_properties(); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets a custom data property. |
|
62 | + * |
|
63 | + * @param string $prop The prop to set. |
|
64 | + * @param mixed $value The value to retrieve. |
|
65 | + */ |
|
66 | + public function set( $prop, $value ) { |
|
67 | + $this->data[ $prop ] = $value; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Gets a custom data property. |
|
72 | + * |
|
73 | + * @param string $prop The prop to set. |
|
74 | + * @return mixed The value. |
|
75 | + */ |
|
76 | + public function get( $prop ) { |
|
77 | + |
|
78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
79 | + return $this->data[ $prop ]; |
|
80 | + } |
|
81 | + |
|
82 | + return null; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Define class properties. |
|
87 | + */ |
|
88 | + public function set_properties() { |
|
89 | + |
|
90 | + // Sessions. |
|
91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | + $this->tax = new WPInv_EUVat(); |
|
94 | + $this->tax->init(); |
|
95 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | + |
|
97 | + // Init other objects. |
|
98 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | + $this->set( 'notes', new WPInv_Notes() ); |
|
101 | + $this->set( 'api', new WPInv_API() ); |
|
102 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | + $this->set( 'template', new GetPaid_Template() ); |
|
104 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | + |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Define plugin constants. |
|
115 | + */ |
|
116 | + public function define_constants() { |
|
117 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | + $this->version = WPINV_VERSION; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Hook into actions and filters. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + */ |
|
127 | + protected function init_hooks() { |
|
128 | + /* Internationalize the text strings used. */ |
|
129 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | + |
|
131 | + // Init the plugin after WordPress inits. |
|
132 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
134 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
135 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | + |
|
137 | + if ( class_exists( 'BuddyPress' ) ) { |
|
138 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | + } |
|
140 | + |
|
141 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | + |
|
147 | + // Fires after registering actions. |
|
148 | + do_action( 'wpinv_actions', $this ); |
|
149 | + do_action( 'getpaid_actions', $this ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + public function plugins_loaded() { |
|
154 | + /* Internationalize the text strings used. */ |
|
155 | + $this->load_textdomain(); |
|
156 | + |
|
157 | + do_action( 'wpinv_loaded' ); |
|
158 | + |
|
159 | + // Fix oxygen page builder conflict |
|
160 | + if ( function_exists( 'ct_css_output' ) ) { |
|
161 | + wpinv_oxygen_fix_conflict(); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Load the translation of the plugin. |
|
167 | + * |
|
168 | + * @since 1.0 |
|
169 | + */ |
|
170 | + public function load_textdomain( $locale = NULL ) { |
|
171 | + if ( empty( $locale ) ) { |
|
172 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | + } |
|
174 | + |
|
175 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | + |
|
177 | + unload_textdomain( 'invoicing' ); |
|
178 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | + |
|
181 | + /** |
|
182 | + * Define language constants. |
|
183 | + */ |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Include required core files used in admin and on the frontend. |
|
189 | + */ |
|
190 | + public function includes() { |
|
191 | + |
|
192 | + // Start with the settings. |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | + |
|
195 | + // Packages/libraries. |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | + |
|
199 | + // Load functions. |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | + |
|
216 | + // Register autoloader. |
|
217 | + try { |
|
218 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | + } catch ( Exception $e ) { |
|
220 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | + } |
|
222 | + |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | + |
|
245 | + /** |
|
246 | + * Load the tax class. |
|
247 | + */ |
|
248 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | + } |
|
251 | + |
|
252 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | + GetPaid_Post_Types_Admin::init(); |
|
254 | + |
|
255 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | + // load the user class only on the users.php page |
|
264 | + global $pagenow; |
|
265 | + if($pagenow=='users.php'){ |
|
266 | + new WPInv_Admin_Users(); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + // Register cli commands |
|
271 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | + } |
|
275 | + |
|
276 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | + } |
|
391 | 278 | |
392 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
393 | - |
|
394 | - wp_enqueue_script( 'jquery-blockui' ); |
|
279 | + /** |
|
280 | + * Class autoloader |
|
281 | + * |
|
282 | + * @param string $class_name The name of the class to load. |
|
283 | + * @access public |
|
284 | + * @since 1.0.19 |
|
285 | + * @return void |
|
286 | + */ |
|
287 | + public function autoload( $class_name ) { |
|
288 | + |
|
289 | + // Normalize the class name... |
|
290 | + $class_name = strtolower( $class_name ); |
|
291 | + |
|
292 | + // ... and make sure it is our class. |
|
293 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | + return; |
|
295 | + } |
|
296 | + |
|
297 | + // Next, prepare the file name from the class. |
|
298 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | + |
|
300 | + // Base path of the classes. |
|
301 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | + |
|
303 | + // And an array of possible locations in order of importance. |
|
304 | + $locations = array( |
|
305 | + "$plugin_path/includes", |
|
306 | + "$plugin_path/includes/data-stores", |
|
307 | + "$plugin_path/includes/gateways", |
|
308 | + "$plugin_path/includes/payments", |
|
309 | + "$plugin_path/includes/api", |
|
310 | + "$plugin_path/includes/admin", |
|
311 | + "$plugin_path/includes/admin/meta-boxes", |
|
312 | + ); |
|
313 | + |
|
314 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
315 | + |
|
316 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | + include trailingslashit( $location ) . $file_name; |
|
318 | + break; |
|
319 | + } |
|
320 | + |
|
321 | + } |
|
322 | + |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Inits hooks etc. |
|
327 | + */ |
|
328 | + public function init() { |
|
329 | + |
|
330 | + // Fires before getpaid inits. |
|
331 | + do_action( 'before_getpaid_init', $this ); |
|
332 | + |
|
333 | + // Load default gateways. |
|
334 | + $gateways = apply_filters( |
|
335 | + 'getpaid_default_gateways', |
|
336 | + array( |
|
337 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
338 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
339 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
340 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
341 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
342 | + ) |
|
343 | + ); |
|
344 | + |
|
345 | + foreach ( $gateways as $id => $class ) { |
|
346 | + $this->gateways[ $id ] = new $class(); |
|
347 | + } |
|
348 | + |
|
349 | + // Fires after getpaid inits. |
|
350 | + do_action( 'getpaid_init', $this ); |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Checks if this is an IPN request and processes it. |
|
356 | + */ |
|
357 | + public function maybe_process_ipn() { |
|
358 | + |
|
359 | + // Ensure that this is an IPN request. |
|
360 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
361 | + return; |
|
362 | + } |
|
363 | + |
|
364 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
365 | + |
|
366 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
368 | + exit; |
|
369 | + |
|
370 | + } |
|
395 | 371 | |
396 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
397 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
372 | + public function enqueue_scripts() { |
|
373 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
398 | 374 | |
399 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
400 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
401 | - |
|
402 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
403 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
404 | - } |
|
405 | - |
|
406 | - public function wpinv_actions() { |
|
407 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
408 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
409 | - } |
|
410 | - } |
|
375 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
411 | 378 | |
412 | - /** |
|
379 | + // Register scripts |
|
380 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
382 | + |
|
383 | + $localize = array(); |
|
384 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
386 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
387 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
388 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
389 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
390 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
391 | + |
|
392 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
393 | + |
|
394 | + wp_enqueue_script( 'jquery-blockui' ); |
|
395 | + |
|
396 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
397 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
398 | + |
|
399 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
400 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
401 | + |
|
402 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
403 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
404 | + } |
|
405 | + |
|
406 | + public function wpinv_actions() { |
|
407 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
408 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | 413 | * Fires an action after verifying that a user can fire them. |
414 | - * |
|
415 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
416 | - * current user owns the invoice/subscription. |
|
414 | + * |
|
415 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
416 | + * current user owns the invoice/subscription. |
|
417 | 417 | */ |
418 | 418 | public function maybe_do_authenticated_action() { |
419 | 419 | |
420 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
420 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
421 | 421 | |
422 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
423 | - if ( is_user_logged_in() ) { |
|
424 | - do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
425 | - } |
|
422 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
423 | + if ( is_user_logged_in() ) { |
|
424 | + do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
425 | + } |
|
426 | 426 | |
427 | - do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
427 | + do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
428 | 428 | |
429 | - } |
|
429 | + } |
|
430 | 430 | |
431 | 431 | |
432 | 432 | } |
433 | 433 | |
434 | - public function pre_get_posts( $wp_query ) { |
|
435 | - |
|
436 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
437 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
438 | - } |
|
439 | - |
|
440 | - return $wp_query; |
|
441 | - } |
|
442 | - |
|
443 | - public function bp_invoicing_init() { |
|
444 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Register widgets |
|
449 | - * |
|
450 | - */ |
|
451 | - public function register_widgets() { |
|
452 | - $widgets = apply_filters( |
|
453 | - 'getpaid_widget_classes', |
|
454 | - array( |
|
455 | - 'WPInv_Checkout_Widget', |
|
456 | - 'WPInv_History_Widget', |
|
457 | - 'WPInv_Receipt_Widget', |
|
458 | - 'WPInv_Subscriptions_Widget', |
|
459 | - 'WPInv_Buy_Item_Widget', |
|
460 | - 'WPInv_Messages_Widget', |
|
461 | - 'WPInv_GetPaid_Widget' |
|
462 | - ) |
|
463 | - ); |
|
464 | - |
|
465 | - foreach ( $widgets as $widget ) { |
|
466 | - register_widget( $widget ); |
|
467 | - } |
|
434 | + public function pre_get_posts( $wp_query ) { |
|
435 | + |
|
436 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
437 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
438 | + } |
|
439 | + |
|
440 | + return $wp_query; |
|
441 | + } |
|
442 | + |
|
443 | + public function bp_invoicing_init() { |
|
444 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Register widgets |
|
449 | + * |
|
450 | + */ |
|
451 | + public function register_widgets() { |
|
452 | + $widgets = apply_filters( |
|
453 | + 'getpaid_widget_classes', |
|
454 | + array( |
|
455 | + 'WPInv_Checkout_Widget', |
|
456 | + 'WPInv_History_Widget', |
|
457 | + 'WPInv_Receipt_Widget', |
|
458 | + 'WPInv_Subscriptions_Widget', |
|
459 | + 'WPInv_Buy_Item_Widget', |
|
460 | + 'WPInv_Messages_Widget', |
|
461 | + 'WPInv_GetPaid_Widget' |
|
462 | + ) |
|
463 | + ); |
|
464 | + |
|
465 | + foreach ( $widgets as $widget ) { |
|
466 | + register_widget( $widget ); |
|
467 | + } |
|
468 | 468 | |
469 | - } |
|
469 | + } |
|
470 | 470 | |
471 | - /** |
|
472 | - * Remove our pages from yoast sitemaps. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - * @param int[] $excluded_posts_ids |
|
476 | - */ |
|
477 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
471 | + /** |
|
472 | + * Remove our pages from yoast sitemaps. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + * @param int[] $excluded_posts_ids |
|
476 | + */ |
|
477 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
478 | 478 | |
479 | - // Ensure that we have an array. |
|
480 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
481 | - $excluded_posts_ids = array(); |
|
482 | - } |
|
479 | + // Ensure that we have an array. |
|
480 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
481 | + $excluded_posts_ids = array(); |
|
482 | + } |
|
483 | 483 | |
484 | - // Prepare our pages. |
|
485 | - $our_pages = array(); |
|
484 | + // Prepare our pages. |
|
485 | + $our_pages = array(); |
|
486 | 486 | |
487 | - // Checkout page. |
|
488 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
487 | + // Checkout page. |
|
488 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
489 | 489 | |
490 | - // Success page. |
|
491 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
490 | + // Success page. |
|
491 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
492 | 492 | |
493 | - // Failure page. |
|
494 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
493 | + // Failure page. |
|
494 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
495 | 495 | |
496 | - // History page. |
|
497 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
496 | + // History page. |
|
497 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
498 | 498 | |
499 | - // Subscriptions page. |
|
500 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
499 | + // Subscriptions page. |
|
500 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
501 | 501 | |
502 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
502 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
503 | 503 | |
504 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
505 | - return array_unique( $excluded_posts_ids ); |
|
504 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
505 | + return array_unique( $excluded_posts_ids ); |
|
506 | 506 | |
507 | - } |
|
507 | + } |
|
508 | 508 | |
509 | - public function wp_footer() { |
|
510 | - echo ' |
|
509 | + public function wp_footer() { |
|
510 | + echo ' |
|
511 | 511 | <div class="bsui"> |
512 | 512 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
513 | 513 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -518,6 +518,6 @@ discard block |
||
518 | 518 | </div> |
519 | 519 | </div> |
520 | 520 | '; |
521 | - } |
|
521 | + } |
|
522 | 522 | |
523 | 523 | } |
@@ -12,443 +12,443 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - return array( |
|
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | - ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Helper function to send an email. |
|
154 | - * |
|
155 | - * @param WPInv_Invoice $invoice |
|
156 | - * @param GetPaid_Notification_Email $email |
|
157 | - * @param string $type |
|
158 | - * @param string|array $recipients |
|
159 | - * @param array $extra_args Extra template args. |
|
160 | - */ |
|
161 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | - |
|
163 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | - |
|
165 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
166 | - $merge_tags = $email->get_merge_tags(); |
|
167 | - |
|
168 | - $result = $mailer->send( |
|
169 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | - $email->get_content( $merge_tags, $extra_args ), |
|
172 | - $email->get_attachments() |
|
173 | - ); |
|
174 | - |
|
175 | - // Maybe send a copy to the admin. |
|
176 | - if ( $email->include_admin_bcc() ) { |
|
177 | - $mailer->send( |
|
178 | - wpinv_get_admin_email(), |
|
179 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | - $email->get_content( $merge_tags ), |
|
181 | - $email->get_attachments() |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - if ( ! $result ) { |
|
186 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | - } |
|
188 | - |
|
189 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
190 | - |
|
191 | - return $result; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Also send emails to any cc users. |
|
196 | - * |
|
197 | - * @param array $recipients |
|
198 | - * @param GetPaid_Notification_Email $email |
|
199 | - */ |
|
200 | - public function filter_email_recipients( $recipients, $email ) { |
|
201 | - |
|
202 | - if ( ! $email->is_admin_email() ) { |
|
203 | - $cc = $email->object->get_email_cc(); |
|
204 | - |
|
205 | - if ( ! empty( $cc ) ) { |
|
206 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
208 | - } |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - return $recipients; |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Sends a new invoice notification. |
|
218 | - * |
|
219 | - * @param WPInv_Invoice $invoice |
|
220 | - */ |
|
221 | - public function new_invoice( $invoice ) { |
|
222 | - |
|
223 | - // Only send this email for invoices created via the admin page. |
|
224 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
225 | - return; |
|
226 | - } |
|
227 | - |
|
228 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
229 | - $recipient = wpinv_get_admin_email(); |
|
230 | - |
|
231 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
232 | - |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Sends a cancelled invoice notification. |
|
237 | - * |
|
238 | - * @param WPInv_Invoice $invoice |
|
239 | - */ |
|
240 | - public function cancelled_invoice( $invoice ) { |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + return array( |
|
130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | + '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | + '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | + '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | + ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Helper function to send an email. |
|
154 | + * |
|
155 | + * @param WPInv_Invoice $invoice |
|
156 | + * @param GetPaid_Notification_Email $email |
|
157 | + * @param string $type |
|
158 | + * @param string|array $recipients |
|
159 | + * @param array $extra_args Extra template args. |
|
160 | + */ |
|
161 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | + |
|
163 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | + |
|
165 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
166 | + $merge_tags = $email->get_merge_tags(); |
|
167 | + |
|
168 | + $result = $mailer->send( |
|
169 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | + $email->get_content( $merge_tags, $extra_args ), |
|
172 | + $email->get_attachments() |
|
173 | + ); |
|
174 | + |
|
175 | + // Maybe send a copy to the admin. |
|
176 | + if ( $email->include_admin_bcc() ) { |
|
177 | + $mailer->send( |
|
178 | + wpinv_get_admin_email(), |
|
179 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | + $email->get_content( $merge_tags ), |
|
181 | + $email->get_attachments() |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + if ( ! $result ) { |
|
186 | + $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | + } |
|
188 | + |
|
189 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
190 | + |
|
191 | + return $result; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Also send emails to any cc users. |
|
196 | + * |
|
197 | + * @param array $recipients |
|
198 | + * @param GetPaid_Notification_Email $email |
|
199 | + */ |
|
200 | + public function filter_email_recipients( $recipients, $email ) { |
|
201 | + |
|
202 | + if ( ! $email->is_admin_email() ) { |
|
203 | + $cc = $email->object->get_email_cc(); |
|
204 | + |
|
205 | + if ( ! empty( $cc ) ) { |
|
206 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
208 | + } |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + return $recipients; |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Sends a new invoice notification. |
|
218 | + * |
|
219 | + * @param WPInv_Invoice $invoice |
|
220 | + */ |
|
221 | + public function new_invoice( $invoice ) { |
|
222 | + |
|
223 | + // Only send this email for invoices created via the admin page. |
|
224 | + if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | + |
|
228 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
229 | + $recipient = wpinv_get_admin_email(); |
|
230 | + |
|
231 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
232 | + |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Sends a cancelled invoice notification. |
|
237 | + * |
|
238 | + * @param WPInv_Invoice $invoice |
|
239 | + */ |
|
240 | + public function cancelled_invoice( $invoice ) { |
|
241 | 241 | |
242 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
243 | - $recipient = wpinv_get_admin_email(); |
|
242 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
243 | + $recipient = wpinv_get_admin_email(); |
|
244 | 244 | |
245 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
245 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Sends a failed invoice notification. |
|
251 | - * |
|
252 | - * @param WPInv_Invoice $invoice |
|
253 | - */ |
|
254 | - public function failed_invoice( $invoice ) { |
|
249 | + /** |
|
250 | + * Sends a failed invoice notification. |
|
251 | + * |
|
252 | + * @param WPInv_Invoice $invoice |
|
253 | + */ |
|
254 | + public function failed_invoice( $invoice ) { |
|
255 | 255 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
257 | - $recipient = wpinv_get_admin_email(); |
|
256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
257 | + $recipient = wpinv_get_admin_email(); |
|
258 | 258 | |
259 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
259 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
260 | 260 | |
261 | - } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * Sends a notification whenever an invoice is put on hold. |
|
265 | - * |
|
266 | - * @param WPInv_Invoice $invoice |
|
267 | - */ |
|
268 | - public function onhold_invoice( $invoice ) { |
|
263 | + /** |
|
264 | + * Sends a notification whenever an invoice is put on hold. |
|
265 | + * |
|
266 | + * @param WPInv_Invoice $invoice |
|
267 | + */ |
|
268 | + public function onhold_invoice( $invoice ) { |
|
269 | 269 | |
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | - $recipient = $invoice->get_email(); |
|
270 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $recipient = $invoice->get_email(); |
|
272 | 272 | |
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
273 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | 274 | |
275 | - } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
279 | - * |
|
280 | - * @param WPInv_Invoice $invoice |
|
281 | - */ |
|
282 | - public function processing_invoice( $invoice ) { |
|
277 | + /** |
|
278 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
279 | + * |
|
280 | + * @param WPInv_Invoice $invoice |
|
281 | + */ |
|
282 | + public function processing_invoice( $invoice ) { |
|
283 | 283 | |
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | - $recipient = $invoice->get_email(); |
|
284 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $recipient = $invoice->get_email(); |
|
286 | 286 | |
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
287 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | 288 | |
289 | - } |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Sends a notification whenever an invoice is paid. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice |
|
295 | - */ |
|
296 | - public function completed_invoice( $invoice ) { |
|
291 | + /** |
|
292 | + * Sends a notification whenever an invoice is paid. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice |
|
295 | + */ |
|
296 | + public function completed_invoice( $invoice ) { |
|
297 | 297 | |
298 | - // (Maybe) abort if it is a renewal invoice. |
|
299 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
300 | - return; |
|
301 | - } |
|
298 | + // (Maybe) abort if it is a renewal invoice. |
|
299 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
300 | + return; |
|
301 | + } |
|
302 | 302 | |
303 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
304 | - $recipient = $invoice->get_email(); |
|
303 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
304 | + $recipient = $invoice->get_email(); |
|
305 | 305 | |
306 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
306 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - /** |
|
311 | - * Sends a notification whenever an invoice is refunded. |
|
312 | - * |
|
313 | - * @param WPInv_Invoice $invoice |
|
314 | - */ |
|
315 | - public function refunded_invoice( $invoice ) { |
|
310 | + /** |
|
311 | + * Sends a notification whenever an invoice is refunded. |
|
312 | + * |
|
313 | + * @param WPInv_Invoice $invoice |
|
314 | + */ |
|
315 | + public function refunded_invoice( $invoice ) { |
|
316 | 316 | |
317 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
318 | - $recipient = $invoice->get_email(); |
|
317 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
318 | + $recipient = $invoice->get_email(); |
|
319 | 319 | |
320 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
320 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
321 | 321 | |
322 | - } |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * Notifies a user about new invoices |
|
326 | - * |
|
327 | - * @param WPInv_Invoice $invoice |
|
328 | - */ |
|
329 | - public function user_invoice( $invoice ) { |
|
324 | + /** |
|
325 | + * Notifies a user about new invoices |
|
326 | + * |
|
327 | + * @param WPInv_Invoice $invoice |
|
328 | + */ |
|
329 | + public function user_invoice( $invoice ) { |
|
330 | 330 | |
331 | - // Only send this email for invoices created via the admin page. |
|
332 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
333 | - return; |
|
334 | - } |
|
331 | + // Only send this email for invoices created via the admin page. |
|
332 | + if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
333 | + return; |
|
334 | + } |
|
335 | 335 | |
336 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
337 | - $recipient = $invoice->get_email(); |
|
336 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
337 | + $recipient = $invoice->get_email(); |
|
338 | 338 | |
339 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
339 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
340 | 340 | |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * Checks if an invoice is a payment form invoice. |
|
345 | - * |
|
346 | - * @param int $invoice |
|
347 | - * @return bool |
|
348 | - */ |
|
349 | - public function is_payment_form_invoice( $invoice ) { |
|
350 | - return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
351 | - } |
|
343 | + /** |
|
344 | + * Checks if an invoice is a payment form invoice. |
|
345 | + * |
|
346 | + * @param int $invoice |
|
347 | + * @return bool |
|
348 | + */ |
|
349 | + public function is_payment_form_invoice( $invoice ) { |
|
350 | + return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Notifies admin about new invoice notes |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - * @param string $note |
|
358 | - */ |
|
359 | - public function user_note( $invoice, $note ) { |
|
353 | + /** |
|
354 | + * Notifies admin about new invoice notes |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + * @param string $note |
|
358 | + */ |
|
359 | + public function user_note( $invoice, $note ) { |
|
360 | 360 | |
361 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
362 | - $recipient = $invoice->get_email(); |
|
363 | - |
|
364 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
365 | - |
|
366 | - } |
|
361 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
362 | + $recipient = $invoice->get_email(); |
|
363 | + |
|
364 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
365 | + |
|
366 | + } |
|
367 | 367 | |
368 | - /** |
|
369 | - * (Force) Sends overdue notices. |
|
370 | - * |
|
371 | - * @param WPInv_Invoice $invoice |
|
372 | - */ |
|
373 | - public function force_send_overdue_notice( $invoice ) { |
|
374 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Sends overdue notices. |
|
380 | - * |
|
381 | - * @TODO: Create an invoices query class. |
|
382 | - */ |
|
383 | - public function overdue() { |
|
384 | - global $wpdb; |
|
385 | - |
|
386 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
387 | - |
|
388 | - // Fetch reminder days. |
|
389 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
390 | - |
|
391 | - // Abort if non is set. |
|
392 | - if ( empty( $reminder_days ) ) { |
|
393 | - return; |
|
394 | - } |
|
395 | - |
|
396 | - // Retrieve date query. |
|
397 | - $date_query = $this->get_date_query( $reminder_days ); |
|
398 | - |
|
399 | - // Invoices table. |
|
400 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
401 | - |
|
402 | - // Fetch invoices. |
|
403 | - $invoices = $wpdb->get_col( |
|
404 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
368 | + /** |
|
369 | + * (Force) Sends overdue notices. |
|
370 | + * |
|
371 | + * @param WPInv_Invoice $invoice |
|
372 | + */ |
|
373 | + public function force_send_overdue_notice( $invoice ) { |
|
374 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Sends overdue notices. |
|
380 | + * |
|
381 | + * @TODO: Create an invoices query class. |
|
382 | + */ |
|
383 | + public function overdue() { |
|
384 | + global $wpdb; |
|
385 | + |
|
386 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
387 | + |
|
388 | + // Fetch reminder days. |
|
389 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
390 | + |
|
391 | + // Abort if non is set. |
|
392 | + if ( empty( $reminder_days ) ) { |
|
393 | + return; |
|
394 | + } |
|
395 | + |
|
396 | + // Retrieve date query. |
|
397 | + $date_query = $this->get_date_query( $reminder_days ); |
|
398 | + |
|
399 | + // Invoices table. |
|
400 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
401 | + |
|
402 | + // Fetch invoices. |
|
403 | + $invoices = $wpdb->get_col( |
|
404 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
405 | 405 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
406 | 406 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
407 | 407 | |
408 | - foreach ( $invoices as $invoice ) { |
|
408 | + foreach ( $invoices as $invoice ) { |
|
409 | 409 | |
410 | - // Only send this email for invoices created via the admin page. |
|
411 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | - $invoice = new WPInv_Invoice( $invoice ); |
|
413 | - $email->object = $invoice; |
|
410 | + // Only send this email for invoices created via the admin page. |
|
411 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | + $invoice = new WPInv_Invoice( $invoice ); |
|
413 | + $email->object = $invoice; |
|
414 | 414 | |
415 | - if ( $invoice->needs_payment() ) { |
|
416 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
417 | - } |
|
415 | + if ( $invoice->needs_payment() ) { |
|
416 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
417 | + } |
|
418 | 418 | |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Calculates the date query for an invoices query |
|
427 | - * |
|
428 | - * @param array $reminder_days |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public function get_date_query( $reminder_days ) { |
|
425 | + /** |
|
426 | + * Calculates the date query for an invoices query |
|
427 | + * |
|
428 | + * @param array $reminder_days |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public function get_date_query( $reminder_days ) { |
|
432 | 432 | |
433 | - $date_query = array( |
|
434 | - 'relation' => 'OR' |
|
435 | - ); |
|
433 | + $date_query = array( |
|
434 | + 'relation' => 'OR' |
|
435 | + ); |
|
436 | 436 | |
437 | - foreach ( $reminder_days as $days ) { |
|
438 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
437 | + foreach ( $reminder_days as $days ) { |
|
438 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
439 | 439 | |
440 | - $date_query[] = array( |
|
441 | - 'year' => $date['year'], |
|
442 | - 'month' => $date['month'], |
|
443 | - 'day' => $date['day'], |
|
444 | - ); |
|
440 | + $date_query[] = array( |
|
441 | + 'year' => $date['year'], |
|
442 | + 'month' => $date['month'], |
|
443 | + 'day' => $date['day'], |
|
444 | + ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
448 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
449 | 449 | |
450 | - return $date_query->get_sql(); |
|
450 | + return $date_query->get_sql(); |
|
451 | 451 | |
452 | - } |
|
452 | + } |
|
453 | 453 | |
454 | 454 | } |
@@ -12,234 +12,234 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
15 | + /** |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
26 | - |
|
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | - |
|
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | - |
|
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | - |
|
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
44 | - global $wpinv_euvat; |
|
45 | - |
|
46 | - // For invoices... |
|
47 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
48 | - $invoice = new WPInv_Invoice( $post ); |
|
49 | - |
|
50 | - // Resend invoice. |
|
51 | - if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) { |
|
52 | - |
|
53 | - add_meta_box( |
|
54 | - 'wpinv-mb-resend-invoice', |
|
55 | - sprintf( |
|
56 | - __( 'Resend %s', 'invoicing' ), |
|
57 | - ucfirst( $invoice->get_type() ) |
|
58 | - ), |
|
59 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
60 | - $post_type, |
|
61 | - 'side', |
|
62 | - 'low' |
|
63 | - ); |
|
64 | - |
|
65 | - } |
|
66 | - |
|
67 | - // Subscriptions. |
|
68 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
69 | - if ( ! empty( $subscription ) ) { |
|
70 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
71 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
72 | - } |
|
73 | - |
|
74 | - // Invoice details. |
|
75 | - add_meta_box( |
|
76 | - 'wpinv-details', |
|
77 | - sprintf( |
|
78 | - __( '%s Details', 'invoicing' ), |
|
79 | - ucfirst( $invoice->get_type() ) |
|
80 | - ), |
|
81 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
82 | - $post_type, |
|
83 | - 'side' |
|
84 | - ); |
|
85 | - |
|
86 | - // Payment details. |
|
87 | - if ( ! $invoice->is_draft() ) { |
|
88 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
89 | - } |
|
90 | - |
|
91 | - // Billing details. |
|
92 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
26 | + |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | + |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | + |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | + |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
44 | + global $wpinv_euvat; |
|
45 | + |
|
46 | + // For invoices... |
|
47 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
48 | + $invoice = new WPInv_Invoice( $post ); |
|
49 | + |
|
50 | + // Resend invoice. |
|
51 | + if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) { |
|
52 | + |
|
53 | + add_meta_box( |
|
54 | + 'wpinv-mb-resend-invoice', |
|
55 | + sprintf( |
|
56 | + __( 'Resend %s', 'invoicing' ), |
|
57 | + ucfirst( $invoice->get_type() ) |
|
58 | + ), |
|
59 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
60 | + $post_type, |
|
61 | + 'side', |
|
62 | + 'low' |
|
63 | + ); |
|
64 | + |
|
65 | + } |
|
66 | + |
|
67 | + // Subscriptions. |
|
68 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
69 | + if ( ! empty( $subscription ) ) { |
|
70 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
71 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
72 | + } |
|
73 | + |
|
74 | + // Invoice details. |
|
75 | + add_meta_box( |
|
76 | + 'wpinv-details', |
|
77 | + sprintf( |
|
78 | + __( '%s Details', 'invoicing' ), |
|
79 | + ucfirst( $invoice->get_type() ) |
|
80 | + ), |
|
81 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
82 | + $post_type, |
|
83 | + 'side' |
|
84 | + ); |
|
85 | + |
|
86 | + // Payment details. |
|
87 | + if ( ! $invoice->is_draft() ) { |
|
88 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
89 | + } |
|
90 | + |
|
91 | + // Billing details. |
|
92 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
93 | 93 | |
94 | - // Invoice items. |
|
95 | - add_meta_box( |
|
96 | - 'wpinv-items', |
|
97 | - sprintf( |
|
98 | - __( '%s Items', 'invoicing' ), |
|
99 | - ucfirst( $invoice->get_type() ) |
|
100 | - ), |
|
101 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
102 | - $post_type, |
|
103 | - 'normal', |
|
104 | - 'high' |
|
105 | - ); |
|
94 | + // Invoice items. |
|
95 | + add_meta_box( |
|
96 | + 'wpinv-items', |
|
97 | + sprintf( |
|
98 | + __( '%s Items', 'invoicing' ), |
|
99 | + ucfirst( $invoice->get_type() ) |
|
100 | + ), |
|
101 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
102 | + $post_type, |
|
103 | + 'normal', |
|
104 | + 'high' |
|
105 | + ); |
|
106 | 106 | |
107 | - // Invoice notes. |
|
108 | - add_meta_box( |
|
109 | - 'wpinv-notes', |
|
110 | - sprintf( |
|
111 | - __( '%s Notes', 'invoicing' ), |
|
112 | - ucfirst( $invoice->get_type() ) |
|
113 | - ), |
|
114 | - 'WPInv_Meta_Box_Notes::output', |
|
115 | - $post_type, |
|
116 | - 'side', |
|
117 | - 'low' |
|
118 | - ); |
|
119 | - |
|
120 | - // Payment form information. |
|
121 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
122 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - // For payment forms. |
|
127 | - if ( $post_type == 'wpi_payment_form' ) { |
|
128 | - |
|
129 | - // Design payment form. |
|
130 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
131 | - |
|
132 | - // Payment form information. |
|
133 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
134 | - |
|
135 | - } |
|
136 | - |
|
137 | - // For invoice items. |
|
138 | - if ( $post_type == 'wpi_item' ) { |
|
139 | - |
|
140 | - // Item details. |
|
141 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
142 | - |
|
143 | - // If taxes are enabled, register the tax metabox. |
|
144 | - if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
145 | - add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
146 | - } |
|
147 | - |
|
148 | - // Item info. |
|
149 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - // For invoice discounts. |
|
154 | - if ( $post_type == 'wpi_discount' ) { |
|
155 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
156 | - } |
|
107 | + // Invoice notes. |
|
108 | + add_meta_box( |
|
109 | + 'wpinv-notes', |
|
110 | + sprintf( |
|
111 | + __( '%s Notes', 'invoicing' ), |
|
112 | + ucfirst( $invoice->get_type() ) |
|
113 | + ), |
|
114 | + 'WPInv_Meta_Box_Notes::output', |
|
115 | + $post_type, |
|
116 | + 'side', |
|
117 | + 'low' |
|
118 | + ); |
|
119 | + |
|
120 | + // Payment form information. |
|
121 | + if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
122 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + // For payment forms. |
|
127 | + if ( $post_type == 'wpi_payment_form' ) { |
|
128 | + |
|
129 | + // Design payment form. |
|
130 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
131 | + |
|
132 | + // Payment form information. |
|
133 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
134 | + |
|
135 | + } |
|
136 | + |
|
137 | + // For invoice items. |
|
138 | + if ( $post_type == 'wpi_item' ) { |
|
139 | + |
|
140 | + // Item details. |
|
141 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
142 | + |
|
143 | + // If taxes are enabled, register the tax metabox. |
|
144 | + if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
145 | + add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
146 | + } |
|
147 | + |
|
148 | + // Item info. |
|
149 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + // For invoice discounts. |
|
154 | + if ( $post_type == 'wpi_discount' ) { |
|
155 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Remove some metaboxes. |
|
163 | - */ |
|
164 | - public static function remove_meta_boxes() { |
|
165 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
166 | - } |
|
161 | + /** |
|
162 | + * Remove some metaboxes. |
|
163 | + */ |
|
164 | + public static function remove_meta_boxes() { |
|
165 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * Rename other metaboxes. |
|
170 | - */ |
|
171 | - public static function rename_meta_boxes() { |
|
168 | + /** |
|
169 | + * Rename other metaboxes. |
|
170 | + */ |
|
171 | + public static function rename_meta_boxes() { |
|
172 | 172 | |
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Check if we're saving, then trigger an action based on the post type. |
|
177 | - * |
|
178 | - * @param int $post_id Post ID. |
|
179 | - * @param object $post Post object. |
|
180 | - */ |
|
181 | - public static function save_meta_boxes( $post_id, $post ) { |
|
182 | - $post_id = absint( $post_id ); |
|
183 | - $data = wp_unslash( $_POST ); |
|
184 | - |
|
185 | - // Do not save for ajax requests. |
|
186 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
187 | - return; |
|
188 | - } |
|
189 | - |
|
190 | - // $post_id and $post are required |
|
191 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
192 | - return; |
|
193 | - } |
|
194 | - |
|
195 | - // Dont' save meta boxes for revisions or autosaves. |
|
196 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
197 | - return; |
|
198 | - } |
|
199 | - |
|
200 | - // Check the nonce. |
|
201 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
202 | - return; |
|
203 | - } |
|
204 | - |
|
205 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
206 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
207 | - return; |
|
208 | - } |
|
209 | - |
|
210 | - // Check user has permission to edit. |
|
211 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
212 | - return; |
|
213 | - } |
|
214 | - |
|
215 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
216 | - |
|
217 | - // We need this save event to run once to avoid potential endless loops. |
|
218 | - self::$saved_meta_boxes = true; |
|
219 | - |
|
220 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
221 | - |
|
222 | - } |
|
223 | - |
|
224 | - // Ensure this is our post type. |
|
225 | - $post_types_map = array( |
|
226 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
227 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
228 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
229 | - ); |
|
230 | - |
|
231 | - // Is this our post type? |
|
232 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
233 | - return; |
|
234 | - } |
|
235 | - |
|
236 | - // We need this save event to run once to avoid potential endless loops. |
|
237 | - self::$saved_meta_boxes = true; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Check if we're saving, then trigger an action based on the post type. |
|
177 | + * |
|
178 | + * @param int $post_id Post ID. |
|
179 | + * @param object $post Post object. |
|
180 | + */ |
|
181 | + public static function save_meta_boxes( $post_id, $post ) { |
|
182 | + $post_id = absint( $post_id ); |
|
183 | + $data = wp_unslash( $_POST ); |
|
184 | + |
|
185 | + // Do not save for ajax requests. |
|
186 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
187 | + return; |
|
188 | + } |
|
189 | + |
|
190 | + // $post_id and $post are required |
|
191 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
192 | + return; |
|
193 | + } |
|
194 | + |
|
195 | + // Dont' save meta boxes for revisions or autosaves. |
|
196 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
197 | + return; |
|
198 | + } |
|
199 | + |
|
200 | + // Check the nonce. |
|
201 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
202 | + return; |
|
203 | + } |
|
204 | + |
|
205 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
206 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
207 | + return; |
|
208 | + } |
|
209 | + |
|
210 | + // Check user has permission to edit. |
|
211 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
212 | + return; |
|
213 | + } |
|
214 | + |
|
215 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
216 | + |
|
217 | + // We need this save event to run once to avoid potential endless loops. |
|
218 | + self::$saved_meta_boxes = true; |
|
219 | + |
|
220 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
221 | + |
|
222 | + } |
|
223 | + |
|
224 | + // Ensure this is our post type. |
|
225 | + $post_types_map = array( |
|
226 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
227 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
228 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
229 | + ); |
|
230 | + |
|
231 | + // Is this our post type? |
|
232 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
233 | + return; |
|
234 | + } |
|
235 | + |
|
236 | + // We need this save event to run once to avoid potential endless loops. |
|
237 | + self::$saved_meta_boxes = true; |
|
238 | 238 | |
239 | - // Save the post. |
|
240 | - $class = $post_types_map[ $post->post_type ]; |
|
241 | - $class::save( $post_id, $_POST, $post ); |
|
239 | + // Save the post. |
|
240 | + $class = $post_types_map[ $post->post_type ]; |
|
241 | + $class::save( $post_id, $_POST, $post ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | 245 | } |
@@ -14,62 +14,62 @@ 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 | - */ |
|
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 | 28 | public $admin_url; |
29 | 29 | |
30 | 30 | /** |
31 | - * Class constructor. |
|
32 | - */ |
|
33 | - public function __construct(){ |
|
31 | + * Class constructor. |
|
32 | + */ |
|
33 | + public function __construct(){ |
|
34 | 34 | |
35 | 35 | $this->admin_path = plugin_dir_path( __FILE__ ); |
36 | 36 | $this->admin_url = plugins_url( '/', __FILE__ ); |
37 | 37 | |
38 | 38 | if ( is_admin() ) { |
39 | - $this->init_admin_hooks(); |
|
39 | + $this->init_admin_hooks(); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Init action and filter hooks |
|
46 | - * |
|
47 | - */ |
|
48 | - private function init_admin_hooks() { |
|
45 | + * Init action and filter hooks |
|
46 | + * |
|
47 | + */ |
|
48 | + private function init_admin_hooks() { |
|
49 | 49 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
50 | 50 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
51 | 51 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
52 | 52 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
53 | 53 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
54 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * Register admin scripts |
|
63 | - * |
|
64 | - */ |
|
65 | - public function enqeue_scripts() { |
|
62 | + * Register admin scripts |
|
63 | + * |
|
64 | + */ |
|
65 | + public function enqeue_scripts() { |
|
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
68 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
70 | 70 | |
71 | 71 | if ( ! empty( $current_screen->post_type ) ) { |
72 | - $page = $current_screen->post_type; |
|
72 | + $page = $current_screen->post_type; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
@@ -93,30 +93,30 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | 100 | if ( $page == 'wpinv-subscriptions' ) { |
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | - } |
|
101 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | + } |
|
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | - } |
|
105 | + if ( $page == 'wpinv-reports' ) { |
|
106 | + wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | + } |
|
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
111 | - } |
|
109 | + if ( $page == 'wpinv-subscriptions' ) { |
|
110 | + wp_enqueue_script( 'postbox' ); |
|
111 | + } |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns admin js translations. |
|
117 | - * |
|
118 | - */ |
|
119 | - protected function get_admin_i18() { |
|
116 | + * Returns admin js translations. |
|
117 | + * |
|
118 | + */ |
|
119 | + protected function get_admin_i18() { |
|
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | $i18n = array( |
@@ -152,50 +152,50 @@ discard block |
||
152 | 152 | 'searching' => __( 'Searching', 'invoicing' ), |
153 | 153 | ); |
154 | 154 | |
155 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
155 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
156 | 156 | |
157 | - $invoice = new WPInv_Invoice( $post ); |
|
158 | - $i18n['save_invoice'] = sprintf( |
|
159 | - __( 'Save %s', 'invoicing' ), |
|
160 | - ucfirst( $invoice->get_type() ) |
|
161 | - ); |
|
157 | + $invoice = new WPInv_Invoice( $post ); |
|
158 | + $i18n['save_invoice'] = sprintf( |
|
159 | + __( 'Save %s', 'invoicing' ), |
|
160 | + ucfirst( $invoice->get_type() ) |
|
161 | + ); |
|
162 | 162 | |
163 | - $i18n['invoice_description'] = sprintf( |
|
164 | - __( '%s Description', 'invoicing' ), |
|
165 | - ucfirst( $invoice->get_type() ) |
|
166 | - ); |
|
163 | + $i18n['invoice_description'] = sprintf( |
|
164 | + __( '%s Description', 'invoicing' ), |
|
165 | + ucfirst( $invoice->get_type() ) |
|
166 | + ); |
|
167 | 167 | |
168 | - } |
|
169 | - return $i18n; |
|
168 | + } |
|
169 | + return $i18n; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | - * Loads payment form js. |
|
174 | - * |
|
175 | - */ |
|
176 | - protected function load_payment_form_scripts() { |
|
173 | + * Loads payment form js. |
|
174 | + * |
|
175 | + */ |
|
176 | + protected function load_payment_form_scripts() { |
|
177 | 177 | global $post; |
178 | 178 | |
179 | 179 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
180 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
181 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
180 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
181 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
182 | 182 | |
183 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
184 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
183 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
184 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
185 | 185 | |
186 | - wp_localize_script( |
|
186 | + wp_localize_script( |
|
187 | 187 | 'wpinv-admin-payment-form-script', |
188 | 188 | 'wpinvPaymentFormAdmin', |
189 | 189 | array( |
190 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
191 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
192 | - 'currency' => wpinv_currency_symbol(), |
|
193 | - 'position' => wpinv_currency_position(), |
|
194 | - 'decimals' => (int) wpinv_decimals(), |
|
195 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
196 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
197 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
198 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
190 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
191 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
192 | + 'currency' => wpinv_currency_symbol(), |
|
193 | + 'position' => wpinv_currency_position(), |
|
194 | + 'decimals' => (int) wpinv_decimals(), |
|
195 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
196 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
197 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
198 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
199 | 199 | ) |
200 | 200 | ); |
201 | 201 | |
@@ -204,20 +204,20 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Add our classes to admin pages. |
|
207 | + * Add our classes to admin pages. |
|
208 | 208 | * |
209 | 209 | * @param string $classes |
210 | 210 | * @return string |
211 | - * |
|
212 | - */ |
|
211 | + * |
|
212 | + */ |
|
213 | 213 | public function admin_body_class( $classes ) { |
214 | - global $pagenow, $post, $current_screen; |
|
214 | + global $pagenow, $post, $current_screen; |
|
215 | 215 | |
216 | 216 | |
217 | 217 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
218 | 218 | |
219 | 219 | if ( ! empty( $current_screen->post_type ) ) { |
220 | - $page = $current_screen->post_type; |
|
220 | + $page = $current_screen->post_type; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -226,33 +226,33 @@ discard block |
||
226 | 226 | |
227 | 227 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
228 | 228 | $classes .= ' wpinv-cpt wpinv'; |
229 | - } |
|
229 | + } |
|
230 | 230 | |
231 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
231 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
232 | 232 | $classes .= ' getpaid-is-invoice-cpt'; |
233 | 233 | } |
234 | 234 | |
235 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
236 | - $classes .= ' wpi-editable-n'; |
|
237 | - } |
|
235 | + if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
236 | + $classes .= ' wpi-editable-n'; |
|
237 | + } |
|
238 | 238 | |
239 | - return $classes; |
|
239 | + return $classes; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Maybe show the AyeCode Connect Notice. |
|
244 | - */ |
|
245 | - public function init_ayecode_connect_helper(){ |
|
243 | + * Maybe show the AyeCode Connect Notice. |
|
244 | + */ |
|
245 | + public function init_ayecode_connect_helper(){ |
|
246 | 246 | |
247 | 247 | new AyeCode_Connect_Helper( |
248 | 248 | array( |
249 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
250 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
251 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
252 | - 'connect_button' => __("Connect Site","invoicing"), |
|
253 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
254 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
255 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
249 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
250 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
251 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
252 | + 'connect_button' => __("Connect Site","invoicing"), |
|
253 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
254 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
255 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
256 | 256 | ), |
257 | 257 | array( 'wpi-addons' ) |
258 | 258 | ); |
@@ -264,21 +264,21 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function activation_redirect() { |
266 | 266 | |
267 | - // Bail if no activation redirect. |
|
268 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
269 | - return; |
|
270 | - } |
|
267 | + // Bail if no activation redirect. |
|
268 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
269 | + return; |
|
270 | + } |
|
271 | 271 | |
272 | - // Delete the redirect transient. |
|
273 | - delete_transient( '_wpinv_activation_redirect' ); |
|
272 | + // Delete the redirect transient. |
|
273 | + delete_transient( '_wpinv_activation_redirect' ); |
|
274 | 274 | |
275 | - // Bail if activating from network, or bulk |
|
276 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
277 | - return; |
|
278 | - } |
|
275 | + // Bail if activating from network, or bulk |
|
276 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
277 | + return; |
|
278 | + } |
|
279 | 279 | |
280 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
281 | - exit; |
|
280 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
281 | + exit; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -293,150 +293,150 @@ discard block |
||
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | - /** |
|
296 | + /** |
|
297 | 297 | * Sends a payment reminder to a customer. |
298 | - * |
|
299 | - * @param array $args |
|
298 | + * |
|
299 | + * @param array $args |
|
300 | 300 | */ |
301 | 301 | public function send_customer_invoice( $args ) { |
302 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
302 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
303 | 303 | |
304 | - if ( $sent ) { |
|
305 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
306 | - } else { |
|
307 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
308 | - } |
|
304 | + if ( $sent ) { |
|
305 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
306 | + } else { |
|
307 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
308 | + } |
|
309 | 309 | |
310 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
311 | - exit; |
|
312 | - } |
|
310 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
311 | + exit; |
|
312 | + } |
|
313 | 313 | |
314 | - /** |
|
314 | + /** |
|
315 | 315 | * Sends a payment reminder to a customer. |
316 | - * |
|
317 | - * @param array $args |
|
316 | + * |
|
317 | + * @param array $args |
|
318 | 318 | */ |
319 | 319 | public function send_customer_payment_reminder( $args ) { |
320 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
320 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
321 | 321 | |
322 | - if ( $sent ) { |
|
323 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
324 | - } else { |
|
325 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
326 | - } |
|
322 | + if ( $sent ) { |
|
323 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
324 | + } else { |
|
325 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
326 | + } |
|
327 | 327 | |
328 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
329 | - exit; |
|
330 | - } |
|
328 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
329 | + exit; |
|
330 | + } |
|
331 | 331 | |
332 | 332 | /** |
333 | - * Returns an array of admin notices. |
|
334 | - * |
|
335 | - * @since 1.0.19 |
|
333 | + * Returns an array of admin notices. |
|
334 | + * |
|
335 | + * @since 1.0.19 |
|
336 | 336 | * @return array |
337 | - */ |
|
338 | - public function get_notices() { |
|
339 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
337 | + */ |
|
338 | + public function get_notices() { |
|
339 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
340 | 340 | return is_array( $notices ) ? $notices : array(); |
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Clears all admin notices |
|
345 | - * |
|
346 | - * @access public |
|
347 | - * @since 1.0.19 |
|
348 | - */ |
|
349 | - public function clear_notices() { |
|
350 | - delete_option( 'wpinv_admin_notices' ); |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Saves a new admin notice |
|
355 | - * |
|
356 | - * @access public |
|
357 | - * @since 1.0.19 |
|
358 | - */ |
|
359 | - public function save_notice( $type, $message ) { |
|
360 | - $notices = $this->get_notices(); |
|
361 | - |
|
362 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
363 | - $notices[ $type ] = array(); |
|
364 | - } |
|
365 | - |
|
366 | - $notices[ $type ][] = $message; |
|
367 | - |
|
368 | - update_option( 'wpinv_admin_notices', $notices ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Displays a success notice |
|
373 | - * |
|
374 | - * @param string $msg The message to qeue. |
|
375 | - * @access public |
|
376 | - * @since 1.0.19 |
|
377 | - */ |
|
378 | - public function show_success( $msg ) { |
|
379 | - $this->save_notice( 'success', $msg ); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Displays a error notice |
|
384 | - * |
|
385 | - * @access public |
|
386 | - * @param string $msg The message to qeue. |
|
387 | - * @since 1.0.19 |
|
388 | - */ |
|
389 | - public function show_error( $msg ) { |
|
390 | - $this->save_notice( 'error', $msg ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Displays a warning notice |
|
395 | - * |
|
396 | - * @access public |
|
397 | - * @param string $msg The message to qeue. |
|
398 | - * @since 1.0.19 |
|
399 | - */ |
|
400 | - public function show_warning( $msg ) { |
|
401 | - $this->save_notice( 'warning', $msg ); |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Displays a info notice |
|
406 | - * |
|
407 | - * @access public |
|
408 | - * @param string $msg The message to qeue. |
|
409 | - * @since 1.0.19 |
|
410 | - */ |
|
411 | - public function show_info( $msg ) { |
|
412 | - $this->save_notice( 'info', $msg ); |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Show notices |
|
417 | - * |
|
418 | - * @access public |
|
419 | - * @since 1.0.19 |
|
420 | - */ |
|
421 | - public function show_notices() { |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Clears all admin notices |
|
345 | + * |
|
346 | + * @access public |
|
347 | + * @since 1.0.19 |
|
348 | + */ |
|
349 | + public function clear_notices() { |
|
350 | + delete_option( 'wpinv_admin_notices' ); |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Saves a new admin notice |
|
355 | + * |
|
356 | + * @access public |
|
357 | + * @since 1.0.19 |
|
358 | + */ |
|
359 | + public function save_notice( $type, $message ) { |
|
360 | + $notices = $this->get_notices(); |
|
361 | + |
|
362 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
363 | + $notices[ $type ] = array(); |
|
364 | + } |
|
365 | + |
|
366 | + $notices[ $type ][] = $message; |
|
367 | + |
|
368 | + update_option( 'wpinv_admin_notices', $notices ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Displays a success notice |
|
373 | + * |
|
374 | + * @param string $msg The message to qeue. |
|
375 | + * @access public |
|
376 | + * @since 1.0.19 |
|
377 | + */ |
|
378 | + public function show_success( $msg ) { |
|
379 | + $this->save_notice( 'success', $msg ); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Displays a error notice |
|
384 | + * |
|
385 | + * @access public |
|
386 | + * @param string $msg The message to qeue. |
|
387 | + * @since 1.0.19 |
|
388 | + */ |
|
389 | + public function show_error( $msg ) { |
|
390 | + $this->save_notice( 'error', $msg ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Displays a warning notice |
|
395 | + * |
|
396 | + * @access public |
|
397 | + * @param string $msg The message to qeue. |
|
398 | + * @since 1.0.19 |
|
399 | + */ |
|
400 | + public function show_warning( $msg ) { |
|
401 | + $this->save_notice( 'warning', $msg ); |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Displays a info notice |
|
406 | + * |
|
407 | + * @access public |
|
408 | + * @param string $msg The message to qeue. |
|
409 | + * @since 1.0.19 |
|
410 | + */ |
|
411 | + public function show_info( $msg ) { |
|
412 | + $this->save_notice( 'info', $msg ); |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Show notices |
|
417 | + * |
|
418 | + * @access public |
|
419 | + * @since 1.0.19 |
|
420 | + */ |
|
421 | + public function show_notices() { |
|
422 | 422 | |
423 | 423 | $notices = $this->get_notices(); |
424 | 424 | $this->clear_notices(); |
425 | 425 | |
426 | - foreach ( $notices as $type => $messages ) { |
|
426 | + foreach ( $notices as $type => $messages ) { |
|
427 | 427 | |
428 | - if ( ! is_array( $messages ) ) { |
|
429 | - continue; |
|
430 | - } |
|
428 | + if ( ! is_array( $messages ) ) { |
|
429 | + continue; |
|
430 | + } |
|
431 | 431 | |
432 | 432 | $type = sanitize_key( $type ); |
433 | - foreach ( $messages as $message ) { |
|
433 | + foreach ( $messages as $message ) { |
|
434 | 434 | $message = wp_kses_post( $message ); |
435 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
435 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | } |
439 | 439 | |
440 | - } |
|
440 | + } |
|
441 | 441 | |
442 | 442 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,122 +175,122 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
184 | - $templates[] = $slug . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | + $templates[] = $slug . '.php'; |
|
185 | 185 | |
186 | - // Allow template parts to be filtered |
|
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
186 | + // Allow template parts to be filtered |
|
187 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | 188 | |
189 | - // Return the part that is found |
|
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
189 | + // Return the part that is found |
|
190 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
194 | - // No file found yet |
|
195 | - $located = false; |
|
194 | + // No file found yet |
|
195 | + $located = false; |
|
196 | 196 | |
197 | - // Try to find a template file |
|
198 | - foreach ( (array)$template_names as $template_name ) { |
|
197 | + // Try to find a template file |
|
198 | + foreach ( (array)$template_names as $template_name ) { |
|
199 | 199 | |
200 | - // Continue if template is empty |
|
201 | - if ( empty( $template_name ) ) |
|
202 | - continue; |
|
200 | + // Continue if template is empty |
|
201 | + if ( empty( $template_name ) ) |
|
202 | + continue; |
|
203 | 203 | |
204 | - // Trim off any slashes from the template name |
|
205 | - $template_name = ltrim( $template_name, '/' ); |
|
204 | + // Trim off any slashes from the template name |
|
205 | + $template_name = ltrim( $template_name, '/' ); |
|
206 | 206 | |
207 | - // try locating this template file by looping through the template paths |
|
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
207 | + // try locating this template file by looping through the template paths |
|
208 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
211 | - $located = $template_path . $template_name; |
|
212 | - break; |
|
213 | - } |
|
214 | - } |
|
210 | + if( file_exists( $template_path . $template_name ) ) { |
|
211 | + $located = $template_path . $template_name; |
|
212 | + break; |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
217 | - break; |
|
218 | - } |
|
219 | - } |
|
216 | + if( !empty( $located ) ) { |
|
217 | + break; |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | + load_template( $located, $require_once ); |
|
223 | 223 | |
224 | - return $located; |
|
224 | + return $located; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | function wpinv_get_theme_template_paths() { |
228 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
228 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
229 | 229 | |
230 | - $file_paths = array( |
|
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | - 100 => wpinv_get_templates_dir() |
|
234 | - ); |
|
230 | + $file_paths = array( |
|
231 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | + 100 => wpinv_get_templates_dir() |
|
234 | + ); |
|
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
237 | 237 | |
238 | - // sort the file paths based on priority |
|
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
238 | + // sort the file paths based on priority |
|
239 | + ksort( $file_paths, SORT_NUMERIC ); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map( 'trailingslashit', $file_paths ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | - $pages = array(); |
|
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
246 | + $pages = array(); |
|
247 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | - return; |
|
254 | - } |
|
252 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | + return; |
|
254 | + } |
|
255 | 255 | |
256 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
256 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
257 | 257 | } |
258 | 258 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
259 | 259 | |
260 | 260 | function wpinv_add_body_classes( $class ) { |
261 | - $classes = (array)$class; |
|
261 | + $classes = (array)$class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
264 | - $classes[] = 'wpinv-checkout'; |
|
265 | - $classes[] = 'wpinv-page'; |
|
266 | - } |
|
263 | + if( wpinv_is_checkout() ) { |
|
264 | + $classes[] = 'wpinv-checkout'; |
|
265 | + $classes[] = 'wpinv-page'; |
|
266 | + } |
|
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
269 | - $classes[] = 'wpinv-success'; |
|
270 | - $classes[] = 'wpinv-page'; |
|
271 | - } |
|
268 | + if( wpinv_is_success_page() ) { |
|
269 | + $classes[] = 'wpinv-success'; |
|
270 | + $classes[] = 'wpinv-page'; |
|
271 | + } |
|
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
274 | - $classes[] = 'wpinv-failed-transaction'; |
|
275 | - $classes[] = 'wpinv-page'; |
|
276 | - } |
|
273 | + if( wpinv_is_failed_transaction_page() ) { |
|
274 | + $classes[] = 'wpinv-failed-transaction'; |
|
275 | + $classes[] = 'wpinv-page'; |
|
276 | + } |
|
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
279 | - $classes[] = 'wpinv-history'; |
|
280 | - $classes[] = 'wpinv-page'; |
|
281 | - } |
|
278 | + if( wpinv_is_invoice_history_page() ) { |
|
279 | + $classes[] = 'wpinv-history'; |
|
280 | + $classes[] = 'wpinv-page'; |
|
281 | + } |
|
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
284 | - $classes[] = 'wpinv-subscription'; |
|
285 | - $classes[] = 'wpinv-page'; |
|
286 | - } |
|
283 | + if( wpinv_is_subscriptions_history_page() ) { |
|
284 | + $classes[] = 'wpinv-subscription'; |
|
285 | + $classes[] = 'wpinv-page'; |
|
286 | + } |
|
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
289 | - $classes[] = 'wpinv-test-mode'; |
|
290 | - $classes[] = 'wpinv-page'; |
|
291 | - } |
|
288 | + if( wpinv_is_test_mode() ) { |
|
289 | + $classes[] = 'wpinv-test-mode'; |
|
290 | + $classes[] = 'wpinv-page'; |
|
291 | + } |
|
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique( $classes ); |
|
294 | 294 | } |
295 | 295 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
296 | 296 | |
@@ -859,21 +859,21 @@ discard block |
||
859 | 859 | |
860 | 860 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
861 | 861 | |
862 | - // Remove unavailable tags. |
|
862 | + // Remove unavailable tags. |
|
863 | 863 | $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
864 | 864 | |
865 | 865 | // Clean up white space. |
866 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
866 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
867 | 867 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
868 | 868 | |
869 | 869 | // Break newlines apart and remove empty lines/trim commas and white space. |
870 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
870 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
871 | 871 | |
872 | 872 | // Add html breaks. |
873 | - $formatted_address = implode( $separator, $formatted_address ); |
|
873 | + $formatted_address = implode( $separator, $formatted_address ); |
|
874 | 874 | |
875 | - // We're done! |
|
876 | - return $formatted_address; |
|
875 | + // We're done! |
|
876 | + return $formatted_address; |
|
877 | 877 | |
878 | 878 | } |
879 | 879 | |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | function wpinv_empty_cart_message() { |
1078 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1078 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1343,10 +1343,10 @@ discard block |
||
1343 | 1343 | |
1344 | 1344 | if ( 0 == count( $form->get_items() ) ) { |
1345 | 1345 | echo aui()->alert( |
1346 | - array( |
|
1347 | - 'type' => 'warning', |
|
1348 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1349 | - ) |
|
1346 | + array( |
|
1347 | + 'type' => 'warning', |
|
1348 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1349 | + ) |
|
1350 | 1350 | ); |
1351 | 1351 | return; |
1352 | 1352 | } |
@@ -1364,21 +1364,21 @@ discard block |
||
1364 | 1364 | $invoice = wpinv_get_invoice( $invoice_id ); |
1365 | 1365 | |
1366 | 1366 | if ( empty( $invoice ) ) { |
1367 | - echo aui()->alert( |
|
1368 | - array( |
|
1369 | - 'type' => 'warning', |
|
1370 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1371 | - ) |
|
1367 | + echo aui()->alert( |
|
1368 | + array( |
|
1369 | + 'type' => 'warning', |
|
1370 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1371 | + ) |
|
1372 | 1372 | ); |
1373 | 1373 | return; |
1374 | 1374 | } |
1375 | 1375 | |
1376 | 1376 | if ( $invoice->is_paid() ) { |
1377 | - echo aui()->alert( |
|
1378 | - array( |
|
1379 | - 'type' => 'warning', |
|
1380 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1381 | - ) |
|
1377 | + echo aui()->alert( |
|
1378 | + array( |
|
1379 | + 'type' => 'warning', |
|
1380 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1381 | + ) |
|
1382 | 1382 | ); |
1383 | 1383 | return; |
1384 | 1384 | } |
@@ -1440,7 +1440,7 @@ discard block |
||
1440 | 1440 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1441 | 1441 | } |
1442 | 1442 | |
1443 | - if ( ! empty( $items ) ) { |
|
1443 | + if ( ! empty( $items ) ) { |
|
1444 | 1444 | $items = esc_attr( $items ); |
1445 | 1445 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1446 | 1446 | } |
@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
19 | - public static function init() { |
|
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
19 | + public static function init() { |
|
20 | + add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | + add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
29 | - |
|
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
29 | + |
|
30 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | + getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | + getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | + if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
61 | + global $wp_query; |
|
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -256,24 +256,24 @@ discard block |
||
256 | 256 | check_ajax_referer( 'getpaid_form_nonce' ); |
257 | 257 | |
258 | 258 | // Is the request set up correctly? |
259 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
260 | - echo aui()->alert( |
|
261 | - array( |
|
262 | - 'type' => 'warning', |
|
263 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
264 | - ) |
|
259 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
260 | + echo aui()->alert( |
|
261 | + array( |
|
262 | + 'type' => 'warning', |
|
263 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
264 | + ) |
|
265 | 265 | ); |
266 | 266 | exit; |
267 | 267 | } |
268 | 268 | |
269 | 269 | // Payment form or button? |
270 | - if ( ! empty( $_GET['form'] ) ) { |
|
270 | + if ( ! empty( $_GET['form'] ) ) { |
|
271 | 271 | getpaid_display_payment_form( $_GET['form'] ); |
272 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
273 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
272 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
273 | + getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
274 | 274 | } else { |
275 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
276 | - getpaid_display_item_payment_form( $items ); |
|
275 | + $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
276 | + getpaid_display_item_payment_form( $items ); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | exit; |
@@ -40,86 +40,86 @@ discard block |
||
40 | 40 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
41 | 41 | <?php |
42 | 42 | |
43 | - foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : |
|
43 | + foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : |
|
44 | 44 | |
45 | - $column_id = sanitize_html_class( $column_id ); |
|
46 | - $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
45 | + $column_id = sanitize_html_class( $column_id ); |
|
46 | + $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
47 | 47 | |
48 | - echo "<td class='$column_id $class'>"; |
|
49 | - switch ( $column_id ) { |
|
48 | + echo "<td class='$column_id $class'>"; |
|
49 | + switch ( $column_id ) { |
|
50 | 50 | |
51 | - case 'invoice-number': |
|
52 | - echo wpinv_invoice_link( $invoice ); |
|
53 | - break; |
|
51 | + case 'invoice-number': |
|
52 | + echo wpinv_invoice_link( $invoice ); |
|
53 | + break; |
|
54 | 54 | |
55 | - case 'created-date': |
|
56 | - echo getpaid_format_date_value( $invoice->get_date_created() ); |
|
57 | - break; |
|
55 | + case 'created-date': |
|
56 | + echo getpaid_format_date_value( $invoice->get_date_created() ); |
|
57 | + break; |
|
58 | 58 | |
59 | - case 'payment-date': |
|
59 | + case 'payment-date': |
|
60 | 60 | |
61 | - if ( $invoice->needs_payment() ) { |
|
62 | - echo "—"; |
|
63 | - } else { |
|
64 | - echo getpaid_format_date_value( $invoice->get_date_completed() ); |
|
65 | - } |
|
61 | + if ( $invoice->needs_payment() ) { |
|
62 | + echo "—"; |
|
63 | + } else { |
|
64 | + echo getpaid_format_date_value( $invoice->get_date_completed() ); |
|
65 | + } |
|
66 | 66 | |
67 | - break; |
|
67 | + break; |
|
68 | 68 | |
69 | - case 'invoice-status': |
|
70 | - echo $invoice->get_status_label_html(); |
|
69 | + case 'invoice-status': |
|
70 | + echo $invoice->get_status_label_html(); |
|
71 | 71 | |
72 | - break; |
|
72 | + break; |
|
73 | 73 | |
74 | - case 'invoice-total': |
|
75 | - echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) ); |
|
74 | + case 'invoice-total': |
|
75 | + echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) ); |
|
76 | 76 | |
77 | - break; |
|
77 | + break; |
|
78 | 78 | |
79 | - case 'invoice-actions': |
|
79 | + case 'invoice-actions': |
|
80 | 80 | |
81 | - $actions = array( |
|
81 | + $actions = array( |
|
82 | 82 | |
83 | - 'pay' => array( |
|
84 | - 'url' => $invoice->get_checkout_payment_url(), |
|
85 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
83 | + 'pay' => array( |
|
84 | + 'url' => $invoice->get_checkout_payment_url(), |
|
85 | + 'name' => __( 'Pay Now', 'invoicing' ), |
|
86 | 86 | 'class' => 'btn-success' |
87 | - ), |
|
87 | + ), |
|
88 | 88 | |
89 | 89 | 'print' => array( |
90 | - 'url' => $invoice->get_view_url(), |
|
91 | - 'name' => __( 'View', 'invoicing' ), |
|
90 | + 'url' => $invoice->get_view_url(), |
|
91 | + 'name' => __( 'View', 'invoicing' ), |
|
92 | 92 | 'class' => 'btn-secondary', |
93 | 93 | 'attrs' => 'target="_blank"' |
94 | - ) |
|
95 | - ); |
|
94 | + ) |
|
95 | + ); |
|
96 | 96 | |
97 | - if ( ! $invoice->needs_payment() ) { |
|
98 | - unset( $actions['pay'] ); |
|
99 | - } |
|
97 | + if ( ! $invoice->needs_payment() ) { |
|
98 | + unset( $actions['pay'] ); |
|
99 | + } |
|
100 | 100 | |
101 | - $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice, $post_type ); |
|
101 | + $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice, $post_type ); |
|
102 | 102 | |
103 | - foreach ( $actions as $key => $action ) { |
|
104 | - $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
105 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
106 | - } |
|
103 | + foreach ( $actions as $key => $action ) { |
|
104 | + $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
105 | + echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
106 | + } |
|
107 | 107 | |
108 | - break; |
|
108 | + break; |
|
109 | 109 | |
110 | - default: |
|
111 | - do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
112 | - break; |
|
110 | + default: |
|
111 | + do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
112 | + break; |
|
113 | 113 | |
114 | 114 | |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
117 | + do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
118 | 118 | |
119 | - echo '</td>'; |
|
119 | + echo '</td>'; |
|
120 | 120 | |
121 | - endforeach; |
|
122 | - ?> |
|
121 | + endforeach; |
|
122 | + ?> |
|
123 | 123 | </tr> |
124 | 124 | |
125 | 125 | <?php endforeach; ?> |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | <?php if ( 1 < $invoices->max_num_pages ) : ?> |
133 | 133 | <div class="invoicing-Pagination"> |
134 | 134 | <?php |
135 | - $big = 999999; |
|
136 | - |
|
137 | - echo paginate_links( array( |
|
138 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
139 | - 'format' => '?paged=%#%', |
|
140 | - 'total' => $invoices->max_num_pages, |
|
141 | - ) ); |
|
142 | - ?> |
|
135 | + $big = 999999; |
|
136 | + |
|
137 | + echo paginate_links( array( |
|
138 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
139 | + 'format' => '?paged=%#%', |
|
140 | + 'total' => $invoices->max_num_pages, |
|
141 | + ) ); |
|
142 | + ?> |
|
143 | 143 | </div> |
144 | 144 | <?php endif; ?> |
145 | 145 |
@@ -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,1012 +11,1012 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Input { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function input($args = array()){ |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'text', |
|
24 | - 'name' => '', |
|
25 | - 'class' => '', |
|
26 | - 'wrap_class' => '', |
|
27 | - 'id' => '', |
|
28 | - 'placeholder'=> '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'required' => false, |
|
32 | - 'label' => '', |
|
33 | - 'label_after'=> false, |
|
34 | - 'label_class'=> '', |
|
35 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
36 | - 'help_text' => '', |
|
37 | - 'validation_text' => '', |
|
38 | - 'validation_pattern' => '', |
|
39 | - 'no_wrap' => false, |
|
40 | - 'input_group_right' => '', |
|
41 | - 'input_group_left' => '', |
|
42 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
43 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
44 | - 'step' => '', |
|
45 | - 'switch' => false, // to show checkbox as a switch |
|
46 | - 'checked' => false, // set a checkbox or radio as selected |
|
47 | - 'password_toggle' => true, // toggle view/hide password |
|
48 | - 'element_require' => '', // [%element_id%] == "1" |
|
49 | - 'extra_attributes' => array() // an array of extra attributes |
|
50 | - ); |
|
51 | - |
|
52 | - /** |
|
53 | - * Parse incoming $args into an array and merge it with $defaults |
|
54 | - */ |
|
55 | - $args = wp_parse_args( $args, $defaults ); |
|
56 | - $output = ''; |
|
57 | - if ( ! empty( $args['type'] ) ) { |
|
58 | - // hidden label option needs to be empty |
|
59 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
60 | - |
|
61 | - $type = sanitize_html_class( $args['type'] ); |
|
62 | - |
|
63 | - $help_text = ''; |
|
64 | - $label = ''; |
|
65 | - $label_after = $args['label_after']; |
|
66 | - $label_args = array( |
|
67 | - 'title'=> $args['label'], |
|
68 | - 'for'=> $args['id'], |
|
69 | - 'class' => $args['label_class']." ", |
|
70 | - 'label_type' => $args['label_type'] |
|
71 | - ); |
|
72 | - |
|
73 | - // floating labels need label after |
|
74 | - if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
75 | - $label_after = true; |
|
76 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
77 | - } |
|
78 | - |
|
79 | - // Some special sauce for files |
|
80 | - if($type=='file' ){ |
|
81 | - $label_after = true; // if type file we need the label after |
|
82 | - $args['class'] .= ' custom-file-input '; |
|
83 | - }elseif($type=='checkbox'){ |
|
84 | - $label_after = true; // if type file we need the label after |
|
85 | - $args['class'] .= ' custom-control-input '; |
|
86 | - }elseif($type=='datepicker' || $type=='timepicker'){ |
|
87 | - $type = 'text'; |
|
88 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
89 | - $args['class'] .= ' bg-initial '; |
|
90 | - |
|
91 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
92 | - // enqueue the script |
|
93 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
94 | - $aui_settings->enqueue_flatpickr(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - // open/type |
|
99 | - $output .= '<input type="' . $type . '" '; |
|
100 | - |
|
101 | - // name |
|
102 | - if(!empty($args['name'])){ |
|
103 | - $output .= ' name="'.esc_attr($args['name']).'" '; |
|
104 | - } |
|
105 | - |
|
106 | - // id |
|
107 | - if(!empty($args['id'])){ |
|
108 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
109 | - } |
|
110 | - |
|
111 | - // placeholder |
|
112 | - if(isset($args['placeholder']) && '' != $args['placeholder'] ){ |
|
113 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
114 | - } |
|
115 | - |
|
116 | - // title |
|
117 | - if(!empty($args['title'])){ |
|
118 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
119 | - } |
|
120 | - |
|
121 | - // value |
|
122 | - if(!empty($args['value'])){ |
|
123 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
124 | - } |
|
125 | - |
|
126 | - // checked, for radio and checkboxes |
|
127 | - if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
128 | - $output .= ' checked '; |
|
129 | - } |
|
130 | - |
|
131 | - // validation text |
|
132 | - if(!empty($args['validation_text'])){ |
|
133 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
134 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
135 | - } |
|
136 | - |
|
137 | - // validation_pattern |
|
138 | - if(!empty($args['validation_pattern'])){ |
|
139 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
140 | - } |
|
141 | - |
|
142 | - // step (for numbers) |
|
143 | - if(!empty($args['step'])){ |
|
144 | - $output .= ' step="'.$args['step'].'" '; |
|
145 | - } |
|
146 | - |
|
147 | - // required |
|
148 | - if(!empty($args['required'])){ |
|
149 | - $output .= ' required '; |
|
150 | - } |
|
151 | - |
|
152 | - // class |
|
153 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
154 | - $output .= ' class="form-control '.$class.'" '; |
|
155 | - |
|
156 | - // data-attributes |
|
157 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
158 | - |
|
159 | - // extra attributes |
|
160 | - if(!empty($args['extra_attributes'])){ |
|
161 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
162 | - } |
|
163 | - |
|
164 | - // close |
|
165 | - $output .= ' >'; |
|
166 | - |
|
167 | - |
|
168 | - // label |
|
169 | - if(!empty($args['label'])){ |
|
170 | - if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
171 | - elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
172 | - $label = self::label( $label_args, $type ); |
|
173 | - } |
|
174 | - |
|
175 | - // help text |
|
176 | - if(!empty($args['help_text'])){ |
|
177 | - $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - // set help text in the correct possition |
|
182 | - if($label_after){ |
|
183 | - $output .= $label . $help_text; |
|
184 | - } |
|
185 | - |
|
186 | - // some input types need a separate wrap |
|
187 | - if($type == 'file') { |
|
188 | - $output = self::wrap( array( |
|
189 | - 'content' => $output, |
|
190 | - 'class' => 'form-group custom-file' |
|
191 | - ) ); |
|
192 | - }elseif($type == 'checkbox'){ |
|
193 | - $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
194 | - $output = self::wrap( array( |
|
195 | - 'content' => $output, |
|
196 | - 'class' => 'custom-control '.$wrap_class |
|
197 | - ) ); |
|
198 | - |
|
199 | - if($args['label_type']=='horizontal'){ |
|
200 | - $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
201 | - } |
|
202 | - }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
203 | - |
|
204 | - |
|
205 | - // allow password field to toggle view |
|
206 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function input($args = array()){ |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'text', |
|
24 | + 'name' => '', |
|
25 | + 'class' => '', |
|
26 | + 'wrap_class' => '', |
|
27 | + 'id' => '', |
|
28 | + 'placeholder'=> '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'required' => false, |
|
32 | + 'label' => '', |
|
33 | + 'label_after'=> false, |
|
34 | + 'label_class'=> '', |
|
35 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
36 | + 'help_text' => '', |
|
37 | + 'validation_text' => '', |
|
38 | + 'validation_pattern' => '', |
|
39 | + 'no_wrap' => false, |
|
40 | + 'input_group_right' => '', |
|
41 | + 'input_group_left' => '', |
|
42 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
43 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
44 | + 'step' => '', |
|
45 | + 'switch' => false, // to show checkbox as a switch |
|
46 | + 'checked' => false, // set a checkbox or radio as selected |
|
47 | + 'password_toggle' => true, // toggle view/hide password |
|
48 | + 'element_require' => '', // [%element_id%] == "1" |
|
49 | + 'extra_attributes' => array() // an array of extra attributes |
|
50 | + ); |
|
51 | + |
|
52 | + /** |
|
53 | + * Parse incoming $args into an array and merge it with $defaults |
|
54 | + */ |
|
55 | + $args = wp_parse_args( $args, $defaults ); |
|
56 | + $output = ''; |
|
57 | + if ( ! empty( $args['type'] ) ) { |
|
58 | + // hidden label option needs to be empty |
|
59 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
60 | + |
|
61 | + $type = sanitize_html_class( $args['type'] ); |
|
62 | + |
|
63 | + $help_text = ''; |
|
64 | + $label = ''; |
|
65 | + $label_after = $args['label_after']; |
|
66 | + $label_args = array( |
|
67 | + 'title'=> $args['label'], |
|
68 | + 'for'=> $args['id'], |
|
69 | + 'class' => $args['label_class']." ", |
|
70 | + 'label_type' => $args['label_type'] |
|
71 | + ); |
|
72 | + |
|
73 | + // floating labels need label after |
|
74 | + if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
75 | + $label_after = true; |
|
76 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
77 | + } |
|
78 | + |
|
79 | + // Some special sauce for files |
|
80 | + if($type=='file' ){ |
|
81 | + $label_after = true; // if type file we need the label after |
|
82 | + $args['class'] .= ' custom-file-input '; |
|
83 | + }elseif($type=='checkbox'){ |
|
84 | + $label_after = true; // if type file we need the label after |
|
85 | + $args['class'] .= ' custom-control-input '; |
|
86 | + }elseif($type=='datepicker' || $type=='timepicker'){ |
|
87 | + $type = 'text'; |
|
88 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
89 | + $args['class'] .= ' bg-initial '; |
|
90 | + |
|
91 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
92 | + // enqueue the script |
|
93 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
94 | + $aui_settings->enqueue_flatpickr(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + // open/type |
|
99 | + $output .= '<input type="' . $type . '" '; |
|
100 | + |
|
101 | + // name |
|
102 | + if(!empty($args['name'])){ |
|
103 | + $output .= ' name="'.esc_attr($args['name']).'" '; |
|
104 | + } |
|
105 | + |
|
106 | + // id |
|
107 | + if(!empty($args['id'])){ |
|
108 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
109 | + } |
|
110 | + |
|
111 | + // placeholder |
|
112 | + if(isset($args['placeholder']) && '' != $args['placeholder'] ){ |
|
113 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
114 | + } |
|
115 | + |
|
116 | + // title |
|
117 | + if(!empty($args['title'])){ |
|
118 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
119 | + } |
|
120 | + |
|
121 | + // value |
|
122 | + if(!empty($args['value'])){ |
|
123 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
124 | + } |
|
125 | + |
|
126 | + // checked, for radio and checkboxes |
|
127 | + if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
128 | + $output .= ' checked '; |
|
129 | + } |
|
130 | + |
|
131 | + // validation text |
|
132 | + if(!empty($args['validation_text'])){ |
|
133 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
134 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
135 | + } |
|
136 | + |
|
137 | + // validation_pattern |
|
138 | + if(!empty($args['validation_pattern'])){ |
|
139 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
140 | + } |
|
141 | + |
|
142 | + // step (for numbers) |
|
143 | + if(!empty($args['step'])){ |
|
144 | + $output .= ' step="'.$args['step'].'" '; |
|
145 | + } |
|
146 | + |
|
147 | + // required |
|
148 | + if(!empty($args['required'])){ |
|
149 | + $output .= ' required '; |
|
150 | + } |
|
151 | + |
|
152 | + // class |
|
153 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
154 | + $output .= ' class="form-control '.$class.'" '; |
|
155 | + |
|
156 | + // data-attributes |
|
157 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
158 | + |
|
159 | + // extra attributes |
|
160 | + if(!empty($args['extra_attributes'])){ |
|
161 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
162 | + } |
|
163 | + |
|
164 | + // close |
|
165 | + $output .= ' >'; |
|
166 | + |
|
167 | + |
|
168 | + // label |
|
169 | + if(!empty($args['label'])){ |
|
170 | + if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
171 | + elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
172 | + $label = self::label( $label_args, $type ); |
|
173 | + } |
|
174 | + |
|
175 | + // help text |
|
176 | + if(!empty($args['help_text'])){ |
|
177 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + // set help text in the correct possition |
|
182 | + if($label_after){ |
|
183 | + $output .= $label . $help_text; |
|
184 | + } |
|
185 | + |
|
186 | + // some input types need a separate wrap |
|
187 | + if($type == 'file') { |
|
188 | + $output = self::wrap( array( |
|
189 | + 'content' => $output, |
|
190 | + 'class' => 'form-group custom-file' |
|
191 | + ) ); |
|
192 | + }elseif($type == 'checkbox'){ |
|
193 | + $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
194 | + $output = self::wrap( array( |
|
195 | + 'content' => $output, |
|
196 | + 'class' => 'custom-control '.$wrap_class |
|
197 | + ) ); |
|
198 | + |
|
199 | + if($args['label_type']=='horizontal'){ |
|
200 | + $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
201 | + } |
|
202 | + }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
203 | + |
|
204 | + |
|
205 | + // allow password field to toggle view |
|
206 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
207 | 207 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
208 | 208 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
209 | 209 | if($el.hasClass(\'fa-eye\')) |
210 | 210 | {$eli.attr(\'type\',\'text\');} |
211 | 211 | else{$eli.attr(\'type\',\'password\');}" |
212 | 212 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
213 | - } |
|
214 | - |
|
215 | - // input group wraps |
|
216 | - if($args['input_group_left'] || $args['input_group_right']){ |
|
217 | - $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
218 | - if($args['input_group_left']){ |
|
219 | - $output = self::wrap( array( |
|
220 | - 'content' => $output, |
|
221 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
222 | - 'input_group_left' => $args['input_group_left'], |
|
223 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
224 | - ) ); |
|
225 | - } |
|
226 | - if($args['input_group_right']){ |
|
227 | - $output = self::wrap( array( |
|
228 | - 'content' => $output, |
|
229 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
230 | - 'input_group_right' => $args['input_group_right'], |
|
231 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
232 | - ) ); |
|
233 | - } |
|
234 | - |
|
235 | - } |
|
236 | - |
|
237 | - if(!$label_after){ |
|
238 | - $output .= $help_text; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
243 | - $output = self::wrap( array( |
|
244 | - 'content' => $output, |
|
245 | - 'class' => 'col-sm-10', |
|
246 | - ) ); |
|
247 | - } |
|
248 | - |
|
249 | - if(!$label_after){ |
|
250 | - $output = $label . $output; |
|
251 | - } |
|
252 | - |
|
253 | - // wrap |
|
254 | - if(!$args['no_wrap']){ |
|
255 | - |
|
256 | - $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
257 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
258 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
259 | - $output = self::wrap(array( |
|
260 | - 'content' => $output, |
|
261 | - 'class' => $wrap_class, |
|
262 | - 'element_require' => $args['element_require'], |
|
263 | - 'argument_id' => $args['id'] |
|
264 | - )); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - } |
|
270 | - |
|
271 | - return $output; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Build the component. |
|
276 | - * |
|
277 | - * @param array $args |
|
278 | - * |
|
279 | - * @return string The rendered component. |
|
280 | - */ |
|
281 | - public static function textarea($args = array()){ |
|
282 | - $defaults = array( |
|
283 | - 'name' => '', |
|
284 | - 'class' => '', |
|
285 | - 'wrap_class' => '', |
|
286 | - 'id' => '', |
|
287 | - 'placeholder'=> '', |
|
288 | - 'title' => '', |
|
289 | - 'value' => '', |
|
290 | - 'required' => false, |
|
291 | - 'label' => '', |
|
292 | - 'label_after'=> false, |
|
293 | - 'label_class' => '', |
|
294 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
295 | - 'help_text' => '', |
|
296 | - 'validation_text' => '', |
|
297 | - 'validation_pattern' => '', |
|
298 | - 'no_wrap' => false, |
|
299 | - 'rows' => '', |
|
300 | - 'wysiwyg' => false, |
|
301 | - 'element_require' => '', // [%element_id%] == "1" |
|
302 | - ); |
|
303 | - |
|
304 | - /** |
|
305 | - * Parse incoming $args into an array and merge it with $defaults |
|
306 | - */ |
|
307 | - $args = wp_parse_args( $args, $defaults ); |
|
308 | - $output = ''; |
|
309 | - |
|
310 | - // hidden label option needs to be empty |
|
311 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
312 | - |
|
313 | - // floating labels don't work with wysiwyg so set it as top |
|
314 | - if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
315 | - $args['label_type'] = 'top'; |
|
316 | - } |
|
317 | - |
|
318 | - $label_after = $args['label_after']; |
|
319 | - |
|
320 | - // floating labels need label after |
|
321 | - if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
322 | - $label_after = true; |
|
323 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
324 | - } |
|
325 | - |
|
326 | - // label |
|
327 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
328 | - }elseif(!empty($args['label']) && !$label_after){ |
|
329 | - $label_args = array( |
|
330 | - 'title'=> $args['label'], |
|
331 | - 'for'=> $args['id'], |
|
332 | - 'class' => $args['label_class']." ", |
|
333 | - 'label_type' => $args['label_type'] |
|
334 | - ); |
|
335 | - $output .= self::label( $label_args ); |
|
336 | - } |
|
337 | - |
|
338 | - // maybe horizontal label |
|
339 | - if($args['label_type']=='horizontal'){ |
|
340 | - $output .= '<div class="col-sm-10">'; |
|
341 | - } |
|
342 | - |
|
343 | - if(!empty($args['wysiwyg'])){ |
|
344 | - ob_start(); |
|
345 | - $content = $args['value']; |
|
346 | - $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
347 | - $settings = array( |
|
348 | - 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
349 | - 'quicktags' => false, |
|
350 | - 'media_buttons' => false, |
|
351 | - 'editor_class' => 'form-control', |
|
352 | - 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
353 | - 'teeny' => true, |
|
354 | - ); |
|
355 | - |
|
356 | - // maybe set settings if array |
|
357 | - if(is_array($args['wysiwyg'])){ |
|
358 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
359 | - } |
|
360 | - |
|
361 | - wp_editor( $content, $editor_id, $settings ); |
|
362 | - $output .= ob_get_clean(); |
|
363 | - }else{ |
|
364 | - |
|
365 | - // open |
|
366 | - $output .= '<textarea '; |
|
367 | - |
|
368 | - // name |
|
369 | - if(!empty($args['name'])){ |
|
370 | - $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
371 | - } |
|
372 | - |
|
373 | - // id |
|
374 | - if(!empty($args['id'])){ |
|
375 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
376 | - } |
|
377 | - |
|
378 | - // placeholder |
|
379 | - if(isset($args['placeholder']) && '' != $args['placeholder']){ |
|
380 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
381 | - } |
|
382 | - |
|
383 | - // title |
|
384 | - if(!empty($args['title'])){ |
|
385 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
386 | - } |
|
387 | - |
|
388 | - // validation text |
|
389 | - if(!empty($args['validation_text'])){ |
|
390 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
391 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
392 | - } |
|
393 | - |
|
394 | - // validation_pattern |
|
395 | - if(!empty($args['validation_pattern'])){ |
|
396 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
397 | - } |
|
398 | - |
|
399 | - // required |
|
400 | - if(!empty($args['required'])){ |
|
401 | - $output .= ' required '; |
|
402 | - } |
|
403 | - |
|
404 | - // rows |
|
405 | - if(!empty($args['rows'])){ |
|
406 | - $output .= ' rows="'.absint($args['rows']).'" '; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - // class |
|
411 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
412 | - $output .= ' class="form-control '.$class.'" '; |
|
413 | - |
|
414 | - |
|
415 | - // close tag |
|
416 | - $output .= ' >'; |
|
417 | - |
|
418 | - // value |
|
419 | - if(!empty($args['value'])){ |
|
420 | - $output .= sanitize_textarea_field($args['value']); |
|
421 | - } |
|
422 | - |
|
423 | - // closing tag |
|
424 | - $output .= '</textarea>'; |
|
425 | - |
|
426 | - } |
|
427 | - |
|
428 | - if(!empty($args['label']) && $label_after){ |
|
429 | - $label_args = array( |
|
430 | - 'title'=> $args['label'], |
|
431 | - 'for'=> $args['id'], |
|
432 | - 'class' => $args['label_class']." ", |
|
433 | - 'label_type' => $args['label_type'] |
|
434 | - ); |
|
435 | - $output .= self::label( $label_args ); |
|
436 | - } |
|
437 | - |
|
438 | - // help text |
|
439 | - if(!empty($args['help_text'])){ |
|
440 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
441 | - } |
|
442 | - |
|
443 | - // maybe horizontal label |
|
444 | - if($args['label_type']=='horizontal'){ |
|
445 | - $output .= '</div>'; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - // wrap |
|
450 | - if(!$args['no_wrap']){ |
|
451 | - $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
452 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
453 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
454 | - $output = self::wrap(array( |
|
455 | - 'content' => $output, |
|
456 | - 'class' => $wrap_class, |
|
457 | - 'element_require' => $args['element_require'], |
|
458 | - 'argument_id' => $args['id'] |
|
459 | - )); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - return $output; |
|
464 | - } |
|
465 | - |
|
466 | - public static function label($args = array(), $type = ''){ |
|
467 | - //<label for="exampleInputEmail1">Email address</label> |
|
468 | - $defaults = array( |
|
469 | - 'title' => 'div', |
|
470 | - 'for' => '', |
|
471 | - 'class' => '', |
|
472 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
473 | - ); |
|
474 | - |
|
475 | - /** |
|
476 | - * Parse incoming $args into an array and merge it with $defaults |
|
477 | - */ |
|
478 | - $args = wp_parse_args( $args, $defaults ); |
|
479 | - $output = ''; |
|
480 | - |
|
481 | - if($args['title']){ |
|
482 | - |
|
483 | - // maybe hide labels //@todo set a global option for visibility class |
|
484 | - if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
485 | - $class = $args['class']; |
|
486 | - }else{ |
|
487 | - $class = 'sr-only '.$args['class']; |
|
488 | - } |
|
489 | - |
|
490 | - // maybe horizontal |
|
491 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
492 | - $class .= ' col-sm-2 col-form-label'; |
|
493 | - } |
|
494 | - |
|
495 | - // open |
|
496 | - $output .= '<label '; |
|
497 | - |
|
498 | - // for |
|
499 | - if(!empty($args['for'])){ |
|
500 | - $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
501 | - } |
|
502 | - |
|
503 | - // class |
|
504 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
505 | - $output .= ' class="'.$class.'" '; |
|
506 | - |
|
507 | - // close |
|
508 | - $output .= '>'; |
|
509 | - |
|
510 | - |
|
511 | - // title, don't escape fully as can contain html |
|
512 | - if(!empty($args['title'])){ |
|
513 | - $output .= wp_kses_post($args['title']); |
|
514 | - } |
|
515 | - |
|
516 | - // close wrap |
|
517 | - $output .= '</label>'; |
|
518 | - |
|
519 | - |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - return $output; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Wrap some content in a HTML wrapper. |
|
528 | - * |
|
529 | - * @param array $args |
|
530 | - * |
|
531 | - * @return string |
|
532 | - */ |
|
533 | - public static function wrap($args = array()){ |
|
534 | - $defaults = array( |
|
535 | - 'type' => 'div', |
|
536 | - 'class' => 'form-group', |
|
537 | - 'content' => '', |
|
538 | - 'input_group_left' => '', |
|
539 | - 'input_group_right' => '', |
|
540 | - 'input_group_left_inside' => false, |
|
541 | - 'input_group_right_inside' => false, |
|
542 | - 'element_require' => '', |
|
543 | - 'argument_id' => '', |
|
544 | - ); |
|
545 | - |
|
546 | - /** |
|
547 | - * Parse incoming $args into an array and merge it with $defaults |
|
548 | - */ |
|
549 | - $args = wp_parse_args( $args, $defaults ); |
|
550 | - $output = ''; |
|
551 | - if($args['type']){ |
|
552 | - |
|
553 | - // open |
|
554 | - $output .= '<'.sanitize_html_class($args['type']); |
|
555 | - |
|
556 | - // element require |
|
557 | - if(!empty($args['element_require'])){ |
|
558 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
559 | - $args['class'] .= " aui-conditional-field"; |
|
560 | - } |
|
561 | - |
|
562 | - // argument_id |
|
563 | - if( !empty($args['argument_id']) ){ |
|
564 | - $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
565 | - } |
|
566 | - |
|
567 | - // class |
|
568 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
569 | - $output .= ' class="'.$class.'" '; |
|
570 | - |
|
571 | - // close wrap |
|
572 | - $output .= ' >'; |
|
573 | - |
|
574 | - |
|
575 | - // Input group left |
|
576 | - if(!empty($args['input_group_left'])){ |
|
577 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
578 | - $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
579 | - $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
580 | - } |
|
581 | - |
|
582 | - // content |
|
583 | - $output .= $args['content']; |
|
584 | - |
|
585 | - // Input group right |
|
586 | - if(!empty($args['input_group_right'])){ |
|
587 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
588 | - $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
589 | - $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - // close wrap |
|
594 | - $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
595 | - |
|
596 | - |
|
597 | - }else{ |
|
598 | - $output = $args['content']; |
|
599 | - } |
|
600 | - |
|
601 | - return $output; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Build the component. |
|
606 | - * |
|
607 | - * @param array $args |
|
608 | - * |
|
609 | - * @return string The rendered component. |
|
610 | - */ |
|
611 | - public static function select($args = array()){ |
|
612 | - $defaults = array( |
|
613 | - 'class' => '', |
|
614 | - 'wrap_class' => '', |
|
615 | - 'id' => '', |
|
616 | - 'title' => '', |
|
617 | - 'value' => '', // can be an array or a string |
|
618 | - 'required' => false, |
|
619 | - 'label' => '', |
|
620 | - 'label_after'=> false, |
|
621 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
622 | - 'label_class' => '', |
|
623 | - 'help_text' => '', |
|
624 | - 'placeholder'=> '', |
|
625 | - 'options' => array(), // array or string |
|
626 | - 'icon' => '', |
|
627 | - 'multiple' => false, |
|
628 | - 'select2' => false, |
|
629 | - 'no_wrap' => false, |
|
630 | - 'element_require' => '', // [%element_id%] == "1" |
|
631 | - 'extra_attributes' => array(), // an array of extra attributes |
|
632 | - ); |
|
633 | - |
|
634 | - /** |
|
635 | - * Parse incoming $args into an array and merge it with $defaults |
|
636 | - */ |
|
637 | - $args = wp_parse_args( $args, $defaults ); |
|
638 | - $output = ''; |
|
639 | - |
|
640 | - // for now lets hide floating labels |
|
641 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
642 | - |
|
643 | - // hidden label option needs to be empty |
|
644 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
645 | - |
|
646 | - |
|
647 | - $label_after = $args['label_after']; |
|
648 | - |
|
649 | - // floating labels need label after |
|
650 | - if( $args['label_type'] == 'floating' ){ |
|
651 | - $label_after = true; |
|
652 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
653 | - } |
|
654 | - |
|
655 | - // Maybe setup select2 |
|
656 | - $is_select2 = false; |
|
657 | - if(!empty($args['select2'])){ |
|
658 | - $args['class'] .= ' aui-select2'; |
|
659 | - $is_select2 = true; |
|
660 | - }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
661 | - $is_select2 = true; |
|
662 | - } |
|
663 | - |
|
664 | - // select2 tags |
|
665 | - if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
666 | - $args['data-tags'] = 'true'; |
|
667 | - $args['data-token-separators'] = "[',']"; |
|
668 | - $args['multiple'] = true; |
|
669 | - } |
|
670 | - |
|
671 | - // select2 placeholder |
|
672 | - if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){ |
|
673 | - $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
674 | - $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
675 | - } |
|
676 | - |
|
677 | - // label |
|
678 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
679 | - }elseif(!empty($args['label']) && !$label_after){ |
|
680 | - $label_args = array( |
|
681 | - 'title'=> $args['label'], |
|
682 | - 'for'=> $args['id'], |
|
683 | - 'class' => $args['label_class']." ", |
|
684 | - 'label_type' => $args['label_type'] |
|
685 | - ); |
|
686 | - $output .= self::label($label_args); |
|
687 | - } |
|
688 | - |
|
689 | - // maybe horizontal label |
|
690 | - if($args['label_type']=='horizontal'){ |
|
691 | - $output .= '<div class="col-sm-10">'; |
|
692 | - } |
|
693 | - |
|
694 | - // open/type |
|
695 | - $output .= '<select '; |
|
696 | - |
|
697 | - // style |
|
698 | - if($is_select2){ |
|
699 | - $output .= " style='width:100%;' "; |
|
700 | - } |
|
701 | - |
|
702 | - // element require |
|
703 | - if(!empty($args['element_require'])){ |
|
704 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
705 | - $args['class'] .= " aui-conditional-field"; |
|
706 | - } |
|
707 | - |
|
708 | - // class |
|
709 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
710 | - $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
711 | - |
|
712 | - // name |
|
713 | - if(!empty($args['name'])){ |
|
714 | - $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
715 | - } |
|
716 | - |
|
717 | - // id |
|
718 | - if(!empty($args['id'])){ |
|
719 | - $output .= AUI_Component_Helper::id($args['id']); |
|
720 | - } |
|
721 | - |
|
722 | - // title |
|
723 | - if(!empty($args['title'])){ |
|
724 | - $output .= AUI_Component_Helper::title($args['title']); |
|
725 | - } |
|
726 | - |
|
727 | - // data-attributes |
|
728 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
729 | - |
|
730 | - // aria-attributes |
|
731 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
732 | - |
|
733 | - // extra attributes |
|
734 | - if(!empty($args['extra_attributes'])){ |
|
735 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
736 | - } |
|
737 | - |
|
738 | - // required |
|
739 | - if(!empty($args['required'])){ |
|
740 | - $output .= ' required '; |
|
741 | - } |
|
742 | - |
|
743 | - // multiple |
|
744 | - if(!empty($args['multiple'])){ |
|
745 | - $output .= ' multiple '; |
|
746 | - } |
|
747 | - |
|
748 | - // close opening tag |
|
749 | - $output .= ' >'; |
|
750 | - |
|
751 | - // placeholder |
|
752 | - if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){ |
|
753 | - $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
754 | - }elseif($is_select2 && !empty($args['placeholder'])){ |
|
755 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
756 | - } |
|
757 | - |
|
758 | - // Options |
|
759 | - if(!empty($args['options'])){ |
|
760 | - |
|
761 | - if(!is_array($args['options'])){ |
|
762 | - $output .= $args['options']; // not the preferred way but an option |
|
763 | - }else{ |
|
764 | - foreach($args['options'] as $val => $name){ |
|
765 | - $selected = ''; |
|
766 | - if(is_array($name)){ |
|
767 | - if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
768 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
769 | - |
|
770 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
771 | - } else { |
|
772 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
773 | - $option_value = isset($name['value']) ? $name['value'] : ''; |
|
774 | - if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
775 | - $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
776 | - } elseif(!empty($args['value'])) { |
|
777 | - $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
778 | - } |
|
779 | - |
|
780 | - $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
781 | - } |
|
782 | - }else{ |
|
783 | - if(!empty($args['value'])){ |
|
784 | - if(is_array($args['value'])){ |
|
785 | - $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
786 | - } elseif(!empty($args['value'])) { |
|
787 | - $selected = selected( $args['value'], $val, false); |
|
788 | - } |
|
789 | - } |
|
790 | - $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
791 | - } |
|
792 | - } |
|
793 | - } |
|
794 | - |
|
795 | - } |
|
796 | - |
|
797 | - // closing tag |
|
798 | - $output .= '</select>'; |
|
799 | - |
|
800 | - if(!empty($args['label']) && $label_after){ |
|
801 | - $label_args = array( |
|
802 | - 'title'=> $args['label'], |
|
803 | - 'for'=> $args['id'], |
|
804 | - 'class' => $args['label_class']." ", |
|
805 | - 'label_type' => $args['label_type'] |
|
806 | - ); |
|
807 | - $output .= self::label($label_args); |
|
808 | - } |
|
809 | - |
|
810 | - // help text |
|
811 | - if(!empty($args['help_text'])){ |
|
812 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
813 | - } |
|
814 | - |
|
815 | - // maybe horizontal label |
|
816 | - if($args['label_type']=='horizontal'){ |
|
817 | - $output .= '</div>'; |
|
818 | - } |
|
819 | - |
|
820 | - |
|
821 | - // wrap |
|
822 | - if(!$args['no_wrap']){ |
|
823 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
824 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
825 | - $output = self::wrap(array( |
|
826 | - 'content' => $output, |
|
827 | - 'class' => $wrap_class, |
|
828 | - 'element_require' => $args['element_require'], |
|
829 | - 'argument_id' => $args['id'] |
|
830 | - )); |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - return $output; |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Build the component. |
|
839 | - * |
|
840 | - * @param array $args |
|
841 | - * |
|
842 | - * @return string The rendered component. |
|
843 | - */ |
|
844 | - public static function radio($args = array()){ |
|
845 | - $defaults = array( |
|
846 | - 'class' => '', |
|
847 | - 'wrap_class' => '', |
|
848 | - 'id' => '', |
|
849 | - 'title' => '', |
|
850 | - 'horizontal' => false, // sets the lable horizontal |
|
851 | - 'value' => '', |
|
852 | - 'label' => '', |
|
853 | - 'label_class'=> '', |
|
854 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
855 | - 'inline' => true, |
|
856 | - 'required' => false, |
|
857 | - 'options' => array(), |
|
858 | - 'icon' => '', |
|
859 | - 'no_wrap' => false, |
|
860 | - 'element_require' => '', // [%element_id%] == "1" |
|
861 | - 'extra_attributes' => array() // an array of extra attributes |
|
862 | - ); |
|
863 | - |
|
864 | - /** |
|
865 | - * Parse incoming $args into an array and merge it with $defaults |
|
866 | - */ |
|
867 | - $args = wp_parse_args( $args, $defaults ); |
|
868 | - |
|
869 | - // for now lets use horizontal for floating |
|
870 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
871 | - |
|
872 | - $label_args = array( |
|
873 | - 'title'=> $args['label'], |
|
874 | - 'class' => $args['label_class']." pt-0 ", |
|
875 | - 'label_type' => $args['label_type'] |
|
876 | - ); |
|
877 | - |
|
878 | - $output = ''; |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - // label before |
|
883 | - if(!empty($args['label'])){ |
|
884 | - $output .= self::label( $label_args, 'radio' ); |
|
885 | - } |
|
886 | - |
|
887 | - // maybe horizontal label |
|
888 | - if($args['label_type']=='horizontal'){ |
|
889 | - $output .= '<div class="col-sm-10">'; |
|
890 | - } |
|
891 | - |
|
892 | - if(!empty($args['options'])){ |
|
893 | - $count = 0; |
|
894 | - foreach($args['options'] as $value => $label){ |
|
895 | - $option_args = $args; |
|
896 | - $option_args['value'] = $value; |
|
897 | - $option_args['label'] = $label; |
|
898 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
899 | - $output .= self::radio_option($option_args,$count); |
|
900 | - $count++; |
|
901 | - } |
|
902 | - } |
|
903 | - |
|
904 | - // maybe horizontal label |
|
905 | - if($args['label_type']=='horizontal'){ |
|
906 | - $output .= '</div>'; |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - // wrap |
|
911 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
912 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
913 | - $output = self::wrap(array( |
|
914 | - 'content' => $output, |
|
915 | - 'class' => $wrap_class, |
|
916 | - 'element_require' => $args['element_require'], |
|
917 | - 'argument_id' => $args['id'] |
|
918 | - )); |
|
919 | - |
|
920 | - |
|
921 | - return $output; |
|
922 | - } |
|
923 | - |
|
924 | - /** |
|
925 | - * Build the component. |
|
926 | - * |
|
927 | - * @param array $args |
|
928 | - * |
|
929 | - * @return string The rendered component. |
|
930 | - */ |
|
931 | - public static function radio_option($args = array(),$count = ''){ |
|
932 | - $defaults = array( |
|
933 | - 'class' => '', |
|
934 | - 'id' => '', |
|
935 | - 'title' => '', |
|
936 | - 'value' => '', |
|
937 | - 'required' => false, |
|
938 | - 'inline' => true, |
|
939 | - 'label' => '', |
|
940 | - 'options' => array(), |
|
941 | - 'icon' => '', |
|
942 | - 'no_wrap' => false, |
|
943 | - 'extra_attributes' => array() // an array of extra attributes |
|
944 | - ); |
|
945 | - |
|
946 | - /** |
|
947 | - * Parse incoming $args into an array and merge it with $defaults |
|
948 | - */ |
|
949 | - $args = wp_parse_args( $args, $defaults ); |
|
950 | - |
|
951 | - $output = ''; |
|
952 | - |
|
953 | - // open/type |
|
954 | - $output .= '<input type="radio"'; |
|
955 | - |
|
956 | - // class |
|
957 | - $output .= ' class="form-check-input" '; |
|
958 | - |
|
959 | - // name |
|
960 | - if(!empty($args['name'])){ |
|
961 | - $output .= AUI_Component_Helper::name($args['name']); |
|
962 | - } |
|
963 | - |
|
964 | - // id |
|
965 | - if(!empty($args['id'])){ |
|
966 | - $output .= AUI_Component_Helper::id($args['id'].$count); |
|
967 | - } |
|
968 | - |
|
969 | - // title |
|
970 | - if(!empty($args['title'])){ |
|
971 | - $output .= AUI_Component_Helper::title($args['title']); |
|
972 | - } |
|
973 | - |
|
974 | - // value |
|
975 | - if(isset($args['value'])){ |
|
976 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
977 | - } |
|
978 | - |
|
979 | - // checked, for radio and checkboxes |
|
980 | - if( $args['checked'] ){ |
|
981 | - $output .= ' checked '; |
|
982 | - } |
|
983 | - |
|
984 | - // data-attributes |
|
985 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
986 | - |
|
987 | - // aria-attributes |
|
988 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
989 | - |
|
990 | - // extra attributes |
|
991 | - if(!empty($args['extra_attributes'])){ |
|
992 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
993 | - } |
|
994 | - |
|
995 | - // required |
|
996 | - if(!empty($args['required'])){ |
|
997 | - $output .= ' required '; |
|
998 | - } |
|
999 | - |
|
1000 | - // close opening tag |
|
1001 | - $output .= ' >'; |
|
1002 | - |
|
1003 | - // label |
|
1004 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
1005 | - }elseif(!empty($args['label'])){ |
|
1006 | - $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
1007 | - } |
|
1008 | - |
|
1009 | - // wrap |
|
1010 | - if(!$args['no_wrap']){ |
|
1011 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1012 | - $output = self::wrap(array( |
|
1013 | - 'content' => $output, |
|
1014 | - 'class' => $wrap_class |
|
1015 | - )); |
|
1016 | - } |
|
1017 | - |
|
1018 | - |
|
1019 | - return $output; |
|
1020 | - } |
|
213 | + } |
|
214 | + |
|
215 | + // input group wraps |
|
216 | + if($args['input_group_left'] || $args['input_group_right']){ |
|
217 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
218 | + if($args['input_group_left']){ |
|
219 | + $output = self::wrap( array( |
|
220 | + 'content' => $output, |
|
221 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
222 | + 'input_group_left' => $args['input_group_left'], |
|
223 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
224 | + ) ); |
|
225 | + } |
|
226 | + if($args['input_group_right']){ |
|
227 | + $output = self::wrap( array( |
|
228 | + 'content' => $output, |
|
229 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
230 | + 'input_group_right' => $args['input_group_right'], |
|
231 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
232 | + ) ); |
|
233 | + } |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + if(!$label_after){ |
|
238 | + $output .= $help_text; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
243 | + $output = self::wrap( array( |
|
244 | + 'content' => $output, |
|
245 | + 'class' => 'col-sm-10', |
|
246 | + ) ); |
|
247 | + } |
|
248 | + |
|
249 | + if(!$label_after){ |
|
250 | + $output = $label . $output; |
|
251 | + } |
|
252 | + |
|
253 | + // wrap |
|
254 | + if(!$args['no_wrap']){ |
|
255 | + |
|
256 | + $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
257 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
258 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
259 | + $output = self::wrap(array( |
|
260 | + 'content' => $output, |
|
261 | + 'class' => $wrap_class, |
|
262 | + 'element_require' => $args['element_require'], |
|
263 | + 'argument_id' => $args['id'] |
|
264 | + )); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + } |
|
270 | + |
|
271 | + return $output; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Build the component. |
|
276 | + * |
|
277 | + * @param array $args |
|
278 | + * |
|
279 | + * @return string The rendered component. |
|
280 | + */ |
|
281 | + public static function textarea($args = array()){ |
|
282 | + $defaults = array( |
|
283 | + 'name' => '', |
|
284 | + 'class' => '', |
|
285 | + 'wrap_class' => '', |
|
286 | + 'id' => '', |
|
287 | + 'placeholder'=> '', |
|
288 | + 'title' => '', |
|
289 | + 'value' => '', |
|
290 | + 'required' => false, |
|
291 | + 'label' => '', |
|
292 | + 'label_after'=> false, |
|
293 | + 'label_class' => '', |
|
294 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
295 | + 'help_text' => '', |
|
296 | + 'validation_text' => '', |
|
297 | + 'validation_pattern' => '', |
|
298 | + 'no_wrap' => false, |
|
299 | + 'rows' => '', |
|
300 | + 'wysiwyg' => false, |
|
301 | + 'element_require' => '', // [%element_id%] == "1" |
|
302 | + ); |
|
303 | + |
|
304 | + /** |
|
305 | + * Parse incoming $args into an array and merge it with $defaults |
|
306 | + */ |
|
307 | + $args = wp_parse_args( $args, $defaults ); |
|
308 | + $output = ''; |
|
309 | + |
|
310 | + // hidden label option needs to be empty |
|
311 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
312 | + |
|
313 | + // floating labels don't work with wysiwyg so set it as top |
|
314 | + if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
315 | + $args['label_type'] = 'top'; |
|
316 | + } |
|
317 | + |
|
318 | + $label_after = $args['label_after']; |
|
319 | + |
|
320 | + // floating labels need label after |
|
321 | + if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
322 | + $label_after = true; |
|
323 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
324 | + } |
|
325 | + |
|
326 | + // label |
|
327 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
328 | + }elseif(!empty($args['label']) && !$label_after){ |
|
329 | + $label_args = array( |
|
330 | + 'title'=> $args['label'], |
|
331 | + 'for'=> $args['id'], |
|
332 | + 'class' => $args['label_class']." ", |
|
333 | + 'label_type' => $args['label_type'] |
|
334 | + ); |
|
335 | + $output .= self::label( $label_args ); |
|
336 | + } |
|
337 | + |
|
338 | + // maybe horizontal label |
|
339 | + if($args['label_type']=='horizontal'){ |
|
340 | + $output .= '<div class="col-sm-10">'; |
|
341 | + } |
|
342 | + |
|
343 | + if(!empty($args['wysiwyg'])){ |
|
344 | + ob_start(); |
|
345 | + $content = $args['value']; |
|
346 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
347 | + $settings = array( |
|
348 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
349 | + 'quicktags' => false, |
|
350 | + 'media_buttons' => false, |
|
351 | + 'editor_class' => 'form-control', |
|
352 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
353 | + 'teeny' => true, |
|
354 | + ); |
|
355 | + |
|
356 | + // maybe set settings if array |
|
357 | + if(is_array($args['wysiwyg'])){ |
|
358 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
359 | + } |
|
360 | + |
|
361 | + wp_editor( $content, $editor_id, $settings ); |
|
362 | + $output .= ob_get_clean(); |
|
363 | + }else{ |
|
364 | + |
|
365 | + // open |
|
366 | + $output .= '<textarea '; |
|
367 | + |
|
368 | + // name |
|
369 | + if(!empty($args['name'])){ |
|
370 | + $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
371 | + } |
|
372 | + |
|
373 | + // id |
|
374 | + if(!empty($args['id'])){ |
|
375 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
376 | + } |
|
377 | + |
|
378 | + // placeholder |
|
379 | + if(isset($args['placeholder']) && '' != $args['placeholder']){ |
|
380 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
381 | + } |
|
382 | + |
|
383 | + // title |
|
384 | + if(!empty($args['title'])){ |
|
385 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
386 | + } |
|
387 | + |
|
388 | + // validation text |
|
389 | + if(!empty($args['validation_text'])){ |
|
390 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
391 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
392 | + } |
|
393 | + |
|
394 | + // validation_pattern |
|
395 | + if(!empty($args['validation_pattern'])){ |
|
396 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
397 | + } |
|
398 | + |
|
399 | + // required |
|
400 | + if(!empty($args['required'])){ |
|
401 | + $output .= ' required '; |
|
402 | + } |
|
403 | + |
|
404 | + // rows |
|
405 | + if(!empty($args['rows'])){ |
|
406 | + $output .= ' rows="'.absint($args['rows']).'" '; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + // class |
|
411 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
412 | + $output .= ' class="form-control '.$class.'" '; |
|
413 | + |
|
414 | + |
|
415 | + // close tag |
|
416 | + $output .= ' >'; |
|
417 | + |
|
418 | + // value |
|
419 | + if(!empty($args['value'])){ |
|
420 | + $output .= sanitize_textarea_field($args['value']); |
|
421 | + } |
|
422 | + |
|
423 | + // closing tag |
|
424 | + $output .= '</textarea>'; |
|
425 | + |
|
426 | + } |
|
427 | + |
|
428 | + if(!empty($args['label']) && $label_after){ |
|
429 | + $label_args = array( |
|
430 | + 'title'=> $args['label'], |
|
431 | + 'for'=> $args['id'], |
|
432 | + 'class' => $args['label_class']." ", |
|
433 | + 'label_type' => $args['label_type'] |
|
434 | + ); |
|
435 | + $output .= self::label( $label_args ); |
|
436 | + } |
|
437 | + |
|
438 | + // help text |
|
439 | + if(!empty($args['help_text'])){ |
|
440 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
441 | + } |
|
442 | + |
|
443 | + // maybe horizontal label |
|
444 | + if($args['label_type']=='horizontal'){ |
|
445 | + $output .= '</div>'; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + // wrap |
|
450 | + if(!$args['no_wrap']){ |
|
451 | + $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
452 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
453 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
454 | + $output = self::wrap(array( |
|
455 | + 'content' => $output, |
|
456 | + 'class' => $wrap_class, |
|
457 | + 'element_require' => $args['element_require'], |
|
458 | + 'argument_id' => $args['id'] |
|
459 | + )); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + return $output; |
|
464 | + } |
|
465 | + |
|
466 | + public static function label($args = array(), $type = ''){ |
|
467 | + //<label for="exampleInputEmail1">Email address</label> |
|
468 | + $defaults = array( |
|
469 | + 'title' => 'div', |
|
470 | + 'for' => '', |
|
471 | + 'class' => '', |
|
472 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
473 | + ); |
|
474 | + |
|
475 | + /** |
|
476 | + * Parse incoming $args into an array and merge it with $defaults |
|
477 | + */ |
|
478 | + $args = wp_parse_args( $args, $defaults ); |
|
479 | + $output = ''; |
|
480 | + |
|
481 | + if($args['title']){ |
|
482 | + |
|
483 | + // maybe hide labels //@todo set a global option for visibility class |
|
484 | + if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
485 | + $class = $args['class']; |
|
486 | + }else{ |
|
487 | + $class = 'sr-only '.$args['class']; |
|
488 | + } |
|
489 | + |
|
490 | + // maybe horizontal |
|
491 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
492 | + $class .= ' col-sm-2 col-form-label'; |
|
493 | + } |
|
494 | + |
|
495 | + // open |
|
496 | + $output .= '<label '; |
|
497 | + |
|
498 | + // for |
|
499 | + if(!empty($args['for'])){ |
|
500 | + $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
501 | + } |
|
502 | + |
|
503 | + // class |
|
504 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
505 | + $output .= ' class="'.$class.'" '; |
|
506 | + |
|
507 | + // close |
|
508 | + $output .= '>'; |
|
509 | + |
|
510 | + |
|
511 | + // title, don't escape fully as can contain html |
|
512 | + if(!empty($args['title'])){ |
|
513 | + $output .= wp_kses_post($args['title']); |
|
514 | + } |
|
515 | + |
|
516 | + // close wrap |
|
517 | + $output .= '</label>'; |
|
518 | + |
|
519 | + |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + return $output; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Wrap some content in a HTML wrapper. |
|
528 | + * |
|
529 | + * @param array $args |
|
530 | + * |
|
531 | + * @return string |
|
532 | + */ |
|
533 | + public static function wrap($args = array()){ |
|
534 | + $defaults = array( |
|
535 | + 'type' => 'div', |
|
536 | + 'class' => 'form-group', |
|
537 | + 'content' => '', |
|
538 | + 'input_group_left' => '', |
|
539 | + 'input_group_right' => '', |
|
540 | + 'input_group_left_inside' => false, |
|
541 | + 'input_group_right_inside' => false, |
|
542 | + 'element_require' => '', |
|
543 | + 'argument_id' => '', |
|
544 | + ); |
|
545 | + |
|
546 | + /** |
|
547 | + * Parse incoming $args into an array and merge it with $defaults |
|
548 | + */ |
|
549 | + $args = wp_parse_args( $args, $defaults ); |
|
550 | + $output = ''; |
|
551 | + if($args['type']){ |
|
552 | + |
|
553 | + // open |
|
554 | + $output .= '<'.sanitize_html_class($args['type']); |
|
555 | + |
|
556 | + // element require |
|
557 | + if(!empty($args['element_require'])){ |
|
558 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
559 | + $args['class'] .= " aui-conditional-field"; |
|
560 | + } |
|
561 | + |
|
562 | + // argument_id |
|
563 | + if( !empty($args['argument_id']) ){ |
|
564 | + $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
565 | + } |
|
566 | + |
|
567 | + // class |
|
568 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
569 | + $output .= ' class="'.$class.'" '; |
|
570 | + |
|
571 | + // close wrap |
|
572 | + $output .= ' >'; |
|
573 | + |
|
574 | + |
|
575 | + // Input group left |
|
576 | + if(!empty($args['input_group_left'])){ |
|
577 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
578 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
579 | + $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
580 | + } |
|
581 | + |
|
582 | + // content |
|
583 | + $output .= $args['content']; |
|
584 | + |
|
585 | + // Input group right |
|
586 | + if(!empty($args['input_group_right'])){ |
|
587 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
588 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
589 | + $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + // close wrap |
|
594 | + $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
595 | + |
|
596 | + |
|
597 | + }else{ |
|
598 | + $output = $args['content']; |
|
599 | + } |
|
600 | + |
|
601 | + return $output; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Build the component. |
|
606 | + * |
|
607 | + * @param array $args |
|
608 | + * |
|
609 | + * @return string The rendered component. |
|
610 | + */ |
|
611 | + public static function select($args = array()){ |
|
612 | + $defaults = array( |
|
613 | + 'class' => '', |
|
614 | + 'wrap_class' => '', |
|
615 | + 'id' => '', |
|
616 | + 'title' => '', |
|
617 | + 'value' => '', // can be an array or a string |
|
618 | + 'required' => false, |
|
619 | + 'label' => '', |
|
620 | + 'label_after'=> false, |
|
621 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
622 | + 'label_class' => '', |
|
623 | + 'help_text' => '', |
|
624 | + 'placeholder'=> '', |
|
625 | + 'options' => array(), // array or string |
|
626 | + 'icon' => '', |
|
627 | + 'multiple' => false, |
|
628 | + 'select2' => false, |
|
629 | + 'no_wrap' => false, |
|
630 | + 'element_require' => '', // [%element_id%] == "1" |
|
631 | + 'extra_attributes' => array(), // an array of extra attributes |
|
632 | + ); |
|
633 | + |
|
634 | + /** |
|
635 | + * Parse incoming $args into an array and merge it with $defaults |
|
636 | + */ |
|
637 | + $args = wp_parse_args( $args, $defaults ); |
|
638 | + $output = ''; |
|
639 | + |
|
640 | + // for now lets hide floating labels |
|
641 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
642 | + |
|
643 | + // hidden label option needs to be empty |
|
644 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
645 | + |
|
646 | + |
|
647 | + $label_after = $args['label_after']; |
|
648 | + |
|
649 | + // floating labels need label after |
|
650 | + if( $args['label_type'] == 'floating' ){ |
|
651 | + $label_after = true; |
|
652 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
653 | + } |
|
654 | + |
|
655 | + // Maybe setup select2 |
|
656 | + $is_select2 = false; |
|
657 | + if(!empty($args['select2'])){ |
|
658 | + $args['class'] .= ' aui-select2'; |
|
659 | + $is_select2 = true; |
|
660 | + }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
661 | + $is_select2 = true; |
|
662 | + } |
|
663 | + |
|
664 | + // select2 tags |
|
665 | + if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
666 | + $args['data-tags'] = 'true'; |
|
667 | + $args['data-token-separators'] = "[',']"; |
|
668 | + $args['multiple'] = true; |
|
669 | + } |
|
670 | + |
|
671 | + // select2 placeholder |
|
672 | + if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){ |
|
673 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
674 | + $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
675 | + } |
|
676 | + |
|
677 | + // label |
|
678 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
679 | + }elseif(!empty($args['label']) && !$label_after){ |
|
680 | + $label_args = array( |
|
681 | + 'title'=> $args['label'], |
|
682 | + 'for'=> $args['id'], |
|
683 | + 'class' => $args['label_class']." ", |
|
684 | + 'label_type' => $args['label_type'] |
|
685 | + ); |
|
686 | + $output .= self::label($label_args); |
|
687 | + } |
|
688 | + |
|
689 | + // maybe horizontal label |
|
690 | + if($args['label_type']=='horizontal'){ |
|
691 | + $output .= '<div class="col-sm-10">'; |
|
692 | + } |
|
693 | + |
|
694 | + // open/type |
|
695 | + $output .= '<select '; |
|
696 | + |
|
697 | + // style |
|
698 | + if($is_select2){ |
|
699 | + $output .= " style='width:100%;' "; |
|
700 | + } |
|
701 | + |
|
702 | + // element require |
|
703 | + if(!empty($args['element_require'])){ |
|
704 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
705 | + $args['class'] .= " aui-conditional-field"; |
|
706 | + } |
|
707 | + |
|
708 | + // class |
|
709 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
710 | + $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
711 | + |
|
712 | + // name |
|
713 | + if(!empty($args['name'])){ |
|
714 | + $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
715 | + } |
|
716 | + |
|
717 | + // id |
|
718 | + if(!empty($args['id'])){ |
|
719 | + $output .= AUI_Component_Helper::id($args['id']); |
|
720 | + } |
|
721 | + |
|
722 | + // title |
|
723 | + if(!empty($args['title'])){ |
|
724 | + $output .= AUI_Component_Helper::title($args['title']); |
|
725 | + } |
|
726 | + |
|
727 | + // data-attributes |
|
728 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
729 | + |
|
730 | + // aria-attributes |
|
731 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
732 | + |
|
733 | + // extra attributes |
|
734 | + if(!empty($args['extra_attributes'])){ |
|
735 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
736 | + } |
|
737 | + |
|
738 | + // required |
|
739 | + if(!empty($args['required'])){ |
|
740 | + $output .= ' required '; |
|
741 | + } |
|
742 | + |
|
743 | + // multiple |
|
744 | + if(!empty($args['multiple'])){ |
|
745 | + $output .= ' multiple '; |
|
746 | + } |
|
747 | + |
|
748 | + // close opening tag |
|
749 | + $output .= ' >'; |
|
750 | + |
|
751 | + // placeholder |
|
752 | + if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){ |
|
753 | + $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
754 | + }elseif($is_select2 && !empty($args['placeholder'])){ |
|
755 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
756 | + } |
|
757 | + |
|
758 | + // Options |
|
759 | + if(!empty($args['options'])){ |
|
760 | + |
|
761 | + if(!is_array($args['options'])){ |
|
762 | + $output .= $args['options']; // not the preferred way but an option |
|
763 | + }else{ |
|
764 | + foreach($args['options'] as $val => $name){ |
|
765 | + $selected = ''; |
|
766 | + if(is_array($name)){ |
|
767 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
768 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
769 | + |
|
770 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
771 | + } else { |
|
772 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
773 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
774 | + if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
775 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
776 | + } elseif(!empty($args['value'])) { |
|
777 | + $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
778 | + } |
|
779 | + |
|
780 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
781 | + } |
|
782 | + }else{ |
|
783 | + if(!empty($args['value'])){ |
|
784 | + if(is_array($args['value'])){ |
|
785 | + $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
786 | + } elseif(!empty($args['value'])) { |
|
787 | + $selected = selected( $args['value'], $val, false); |
|
788 | + } |
|
789 | + } |
|
790 | + $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
791 | + } |
|
792 | + } |
|
793 | + } |
|
794 | + |
|
795 | + } |
|
796 | + |
|
797 | + // closing tag |
|
798 | + $output .= '</select>'; |
|
799 | + |
|
800 | + if(!empty($args['label']) && $label_after){ |
|
801 | + $label_args = array( |
|
802 | + 'title'=> $args['label'], |
|
803 | + 'for'=> $args['id'], |
|
804 | + 'class' => $args['label_class']." ", |
|
805 | + 'label_type' => $args['label_type'] |
|
806 | + ); |
|
807 | + $output .= self::label($label_args); |
|
808 | + } |
|
809 | + |
|
810 | + // help text |
|
811 | + if(!empty($args['help_text'])){ |
|
812 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
813 | + } |
|
814 | + |
|
815 | + // maybe horizontal label |
|
816 | + if($args['label_type']=='horizontal'){ |
|
817 | + $output .= '</div>'; |
|
818 | + } |
|
819 | + |
|
820 | + |
|
821 | + // wrap |
|
822 | + if(!$args['no_wrap']){ |
|
823 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
824 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
825 | + $output = self::wrap(array( |
|
826 | + 'content' => $output, |
|
827 | + 'class' => $wrap_class, |
|
828 | + 'element_require' => $args['element_require'], |
|
829 | + 'argument_id' => $args['id'] |
|
830 | + )); |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + return $output; |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Build the component. |
|
839 | + * |
|
840 | + * @param array $args |
|
841 | + * |
|
842 | + * @return string The rendered component. |
|
843 | + */ |
|
844 | + public static function radio($args = array()){ |
|
845 | + $defaults = array( |
|
846 | + 'class' => '', |
|
847 | + 'wrap_class' => '', |
|
848 | + 'id' => '', |
|
849 | + 'title' => '', |
|
850 | + 'horizontal' => false, // sets the lable horizontal |
|
851 | + 'value' => '', |
|
852 | + 'label' => '', |
|
853 | + 'label_class'=> '', |
|
854 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
855 | + 'inline' => true, |
|
856 | + 'required' => false, |
|
857 | + 'options' => array(), |
|
858 | + 'icon' => '', |
|
859 | + 'no_wrap' => false, |
|
860 | + 'element_require' => '', // [%element_id%] == "1" |
|
861 | + 'extra_attributes' => array() // an array of extra attributes |
|
862 | + ); |
|
863 | + |
|
864 | + /** |
|
865 | + * Parse incoming $args into an array and merge it with $defaults |
|
866 | + */ |
|
867 | + $args = wp_parse_args( $args, $defaults ); |
|
868 | + |
|
869 | + // for now lets use horizontal for floating |
|
870 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
871 | + |
|
872 | + $label_args = array( |
|
873 | + 'title'=> $args['label'], |
|
874 | + 'class' => $args['label_class']." pt-0 ", |
|
875 | + 'label_type' => $args['label_type'] |
|
876 | + ); |
|
877 | + |
|
878 | + $output = ''; |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + // label before |
|
883 | + if(!empty($args['label'])){ |
|
884 | + $output .= self::label( $label_args, 'radio' ); |
|
885 | + } |
|
886 | + |
|
887 | + // maybe horizontal label |
|
888 | + if($args['label_type']=='horizontal'){ |
|
889 | + $output .= '<div class="col-sm-10">'; |
|
890 | + } |
|
891 | + |
|
892 | + if(!empty($args['options'])){ |
|
893 | + $count = 0; |
|
894 | + foreach($args['options'] as $value => $label){ |
|
895 | + $option_args = $args; |
|
896 | + $option_args['value'] = $value; |
|
897 | + $option_args['label'] = $label; |
|
898 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
899 | + $output .= self::radio_option($option_args,$count); |
|
900 | + $count++; |
|
901 | + } |
|
902 | + } |
|
903 | + |
|
904 | + // maybe horizontal label |
|
905 | + if($args['label_type']=='horizontal'){ |
|
906 | + $output .= '</div>'; |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + // wrap |
|
911 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
912 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
913 | + $output = self::wrap(array( |
|
914 | + 'content' => $output, |
|
915 | + 'class' => $wrap_class, |
|
916 | + 'element_require' => $args['element_require'], |
|
917 | + 'argument_id' => $args['id'] |
|
918 | + )); |
|
919 | + |
|
920 | + |
|
921 | + return $output; |
|
922 | + } |
|
923 | + |
|
924 | + /** |
|
925 | + * Build the component. |
|
926 | + * |
|
927 | + * @param array $args |
|
928 | + * |
|
929 | + * @return string The rendered component. |
|
930 | + */ |
|
931 | + public static function radio_option($args = array(),$count = ''){ |
|
932 | + $defaults = array( |
|
933 | + 'class' => '', |
|
934 | + 'id' => '', |
|
935 | + 'title' => '', |
|
936 | + 'value' => '', |
|
937 | + 'required' => false, |
|
938 | + 'inline' => true, |
|
939 | + 'label' => '', |
|
940 | + 'options' => array(), |
|
941 | + 'icon' => '', |
|
942 | + 'no_wrap' => false, |
|
943 | + 'extra_attributes' => array() // an array of extra attributes |
|
944 | + ); |
|
945 | + |
|
946 | + /** |
|
947 | + * Parse incoming $args into an array and merge it with $defaults |
|
948 | + */ |
|
949 | + $args = wp_parse_args( $args, $defaults ); |
|
950 | + |
|
951 | + $output = ''; |
|
952 | + |
|
953 | + // open/type |
|
954 | + $output .= '<input type="radio"'; |
|
955 | + |
|
956 | + // class |
|
957 | + $output .= ' class="form-check-input" '; |
|
958 | + |
|
959 | + // name |
|
960 | + if(!empty($args['name'])){ |
|
961 | + $output .= AUI_Component_Helper::name($args['name']); |
|
962 | + } |
|
963 | + |
|
964 | + // id |
|
965 | + if(!empty($args['id'])){ |
|
966 | + $output .= AUI_Component_Helper::id($args['id'].$count); |
|
967 | + } |
|
968 | + |
|
969 | + // title |
|
970 | + if(!empty($args['title'])){ |
|
971 | + $output .= AUI_Component_Helper::title($args['title']); |
|
972 | + } |
|
973 | + |
|
974 | + // value |
|
975 | + if(isset($args['value'])){ |
|
976 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
977 | + } |
|
978 | + |
|
979 | + // checked, for radio and checkboxes |
|
980 | + if( $args['checked'] ){ |
|
981 | + $output .= ' checked '; |
|
982 | + } |
|
983 | + |
|
984 | + // data-attributes |
|
985 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
986 | + |
|
987 | + // aria-attributes |
|
988 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
989 | + |
|
990 | + // extra attributes |
|
991 | + if(!empty($args['extra_attributes'])){ |
|
992 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
993 | + } |
|
994 | + |
|
995 | + // required |
|
996 | + if(!empty($args['required'])){ |
|
997 | + $output .= ' required '; |
|
998 | + } |
|
999 | + |
|
1000 | + // close opening tag |
|
1001 | + $output .= ' >'; |
|
1002 | + |
|
1003 | + // label |
|
1004 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
1005 | + }elseif(!empty($args['label'])){ |
|
1006 | + $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
1007 | + } |
|
1008 | + |
|
1009 | + // wrap |
|
1010 | + if(!$args['no_wrap']){ |
|
1011 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1012 | + $output = self::wrap(array( |
|
1013 | + 'content' => $output, |
|
1014 | + 'class' => $wrap_class |
|
1015 | + )); |
|
1016 | + } |
|
1017 | + |
|
1018 | + |
|
1019 | + return $output; |
|
1020 | + } |
|
1021 | 1021 | |
1022 | 1022 | } |
1023 | 1023 | \ No newline at end of file |