Passed
Push — master ( 17cabb...9e37cd )
by Brian
05:13
created
vendor/ayecode/wp-ayecode-ui/includes/ayecode-ui-settings.php 3 patches
Spacing   +381 added lines, -381 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
 /**
13 13
  * Bail if we are not in WP.
14 14
  */
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if (!defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
19 19
 /**
20 20
  * Only add if the class does not already exist.
21 21
  */
22
-if ( ! class_exists( 'AyeCode_UI_Settings' ) ) {
22
+if (!class_exists('AyeCode_UI_Settings')) {
23 23
 
24 24
 	/**
25 25
 	 * A Class to be able to change settings for Font Awesome.
@@ -98,23 +98,23 @@  discard block
 block discarded – undo
98 98
 		 * @return AyeCode_UI_Settings - Main instance.
99 99
 		 */
100 100
 		public static function instance() {
101
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
101
+			if (!isset(self::$instance) && !(self::$instance instanceof AyeCode_UI_Settings)) {
102 102
 
103 103
 				self::$instance = new AyeCode_UI_Settings;
104 104
 
105
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
105
+				add_action('init', array(self::$instance, 'init')); // set settings
106 106
 
107
-				if ( is_admin() ) {
108
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
107
+				if (is_admin()) {
108
+					add_action('admin_menu', array(self::$instance, 'menu_item'));
109
+					add_action('admin_init', array(self::$instance, 'register_settings'));
110 110
 
111 111
 					// Maybe show example page
112
-					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
112
+					add_action('template_redirect', array(self::$instance, 'maybe_show_examples'));
113 113
 				}
114 114
 
115
-				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
115
+				add_action('customize_register', array(self::$instance, 'customizer_settings'));
116 116
 
117
-				do_action( 'ayecode_ui_settings_loaded' );
117
+				do_action('ayecode_ui_settings_loaded');
118 118
 			}
119 119
 
120 120
 			return self::$instance;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 		/**
124 124
 		 * Setup some constants.
125 125
 		 */
126
-		public function constants(){
126
+		public function constants() {
127 127
 			define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128 128
 			define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129 129
 			if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
@@ -143,25 +143,25 @@  discard block
 block discarded – undo
143 143
 			 *
144 144
 			 * We load super early in case there is a theme version that might change the colors
145 145
 			 */
146
-			if ( $this->settings['css'] ) {
147
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
146
+			if ($this->settings['css']) {
147
+				add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 1);
148 148
 			}
149
-			if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
149
+			if ($this->settings['css_backend'] && $this->load_admin_scripts()) {
150
+				add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 1);
151 151
 			}
152 152
 
153 153
 			// maybe load JS
154
-			if ( $this->settings['js'] ) {
154
+			if ($this->settings['js']) {
155 155
 				$priority = $this->is_bs3_compat() ? 100 : 1;
156
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
156
+				add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), $priority);
157 157
 			}
158
-			if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
158
+			if ($this->settings['js_backend'] && $this->load_admin_scripts()) {
159
+				add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 1);
160 160
 			}
161 161
 
162 162
 			// Maybe set the HTML font size
163
-			if ( $this->settings['html_font_size'] ) {
164
-				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
163
+			if ($this->settings['html_font_size']) {
164
+				add_action('wp_footer', array($this, 'html_font_size'), 10);
165 165
 			}
166 166
 
167 167
 
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 		 *
173 173
 		 * @return bool
174 174
 		 */
175
-		public function load_admin_scripts(){
175
+		public function load_admin_scripts() {
176 176
 			$result = true;
177 177
 
178 178
 			// check if specifically disabled
179
-			if(!empty($this->settings['disable_admin'])){
180
-				$url_parts = explode("\n",$this->settings['disable_admin']);
181
-				foreach($url_parts as $part){
182
-					if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
179
+			if (!empty($this->settings['disable_admin'])) {
180
+				$url_parts = explode("\n", $this->settings['disable_admin']);
181
+				foreach ($url_parts as $part) {
182
+					if (strpos($_SERVER['REQUEST_URI'], trim($part)) !== false) {
183 183
 						return false; // return early, no point checking further
184 184
 					}
185 185
 				}
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
 		/**
192 192
 		 * Add a html font size to the footer.
193 193
 		 */
194
-		public function html_font_size(){
194
+		public function html_font_size() {
195 195
 			$this->settings = $this->get_settings();
196
-			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
196
+			echo "<style>html{font-size:" . absint($this->settings['html_font_size']) . "px;}</style>";
197 197
 		}
198 198
 
199 199
 		/**
@@ -201,10 +201,10 @@  discard block
 block discarded – undo
201 201
 		 * 
202 202
 		 * @return bool
203 203
 		 */
204
-		public function is_aui_screen(){
204
+		public function is_aui_screen() {
205 205
 			$load = false;
206 206
 			// check if we should load or not
207
-			if ( is_admin() ) {
207
+			if (is_admin()) {
208 208
 				// Only enable on set pages
209 209
 				$aui_screens = array(
210 210
 					'page',
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
 					'settings_page_ayecode-ui-settings',
213 213
 					'appearance_page_gutenberg-widgets'
214 214
 				);
215
-				$screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
215
+				$screen_ids = apply_filters('aui_screen_ids', $aui_screens);
216 216
 
217 217
 				$screen = get_current_screen();
218 218
 
219 219
 //				echo '###'.$screen->id;
220 220
 				
221
-				if ( $screen && in_array( $screen->id, $screen_ids ) ) {
221
+				if ($screen && in_array($screen->id, $screen_ids)) {
222 222
 					$load = true;
223 223
 				}
224 224
 			}
@@ -231,25 +231,25 @@  discard block
 block discarded – undo
231 231
 		 */
232 232
 		public function enqueue_style() {
233 233
 
234
-			if( is_admin() && !$this->is_aui_screen()){
234
+			if (is_admin() && !$this->is_aui_screen()) {
235 235
 				// don't add wp-admin scripts if not requested to
236
-			}else{
236
+			} else {
237 237
 				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
238 238
 
239 239
 				$rtl = is_rtl() ? '-rtl' : '';
240 240
 
241
-				if($this->settings[$css_setting]){
242
-					$compatibility = $this->settings[$css_setting]=='core' ? false : true;
243
-					$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
244
-					wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
245
-					wp_enqueue_style( 'ayecode-ui' );
241
+				if ($this->settings[$css_setting]) {
242
+					$compatibility = $this->settings[$css_setting] == 'core' ? false : true;
243
+					$url = $this->settings[$css_setting] == 'core' ? $this->url . 'assets/css/ayecode-ui' . $rtl . '.css' : $this->url . 'assets/css/ayecode-ui-compatibility' . $rtl . '.css';
244
+					wp_register_style('ayecode-ui', $url, array(), $this->latest);
245
+					wp_enqueue_style('ayecode-ui');
246 246
 
247 247
 					// flatpickr
248
-					wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
248
+					wp_register_style('flatpickr', $this->url . 'assets/css/flatpickr.min.css', array(), $this->latest);
249 249
 
250 250
 
251 251
 					// fix some wp-admin issues
252
-					if(is_admin()){
252
+					if (is_admin()) {
253 253
 						$custom_css = "
254 254
                 body{
255 255
                     background-color: #f1f1f1;
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
 						    padding: 0;
296 296
 						}
297 297
 					";
298
-						wp_add_inline_style( 'ayecode-ui', $custom_css );
298
+						wp_add_inline_style('ayecode-ui', $custom_css);
299 299
 					}
300 300
 
301 301
 					// custom changes
302
-					wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
302
+					wp_add_inline_style('ayecode-ui', self::custom_css($compatibility));
303 303
 
304 304
 				}
305 305
 			}
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 				function aui_init_flatpickr(){
560 560
 					if ( typeof jQuery.fn.flatpickr === "function" && !$aui_doing_init_flatpickr) {
561 561
 						$aui_doing_init_flatpickr = true;
562
-						<?php if ( ! empty( $flatpickr_locale ) ) { ?>try{flatpickr.localize(<?php echo $flatpickr_locale; ?>);}catch(err){console.log(err.message);}<?php } ?>
562
+						<?php if (!empty($flatpickr_locale)) { ?>try{flatpickr.localize(<?php echo $flatpickr_locale; ?>);}catch(err){console.log(err.message);}<?php } ?>
563 563
 						jQuery('input[data-aui-init="flatpickr"]:not(.flatpickr-input)').flatpickr();
564 564
 					}
565 565
 					$aui_doing_init_flatpickr = false;
@@ -989,10 +989,10 @@  discard block
 block discarded – undo
989 989
 			/*
990 990
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
991 991
 			 */
992
-			return str_replace( array(
992
+			return str_replace(array(
993 993
 				'<script>',
994 994
 				'</script>'
995
-			), '', self::minify_js($output) );
995
+			), '', self::minify_js($output));
996 996
 		}
997 997
 
998 998
 
@@ -1006,13 +1006,13 @@  discard block
 block discarded – undo
1006 1006
 			ob_start();
1007 1007
 			?>
1008 1008
 			<script>
1009
-				<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1009
+				<?php if (defined('FUSION_BUILDER_VERSION')) { ?>
1010 1010
 				/* With Avada builder */
1011 1011
 
1012 1012
 				<?php } ?>
1013 1013
 			</script>
1014 1014
 			<?php
1015
-			return str_replace( array(
1015
+			return str_replace(array(
1016 1016
 				'<script>',
1017 1017
 				'</script>'
1018 1018
 			), '', ob_get_clean());
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
 		 *
1024 1024
 		 * If this remains small then its best to use this than to add another JS file.
1025 1025
 		 */
1026
-		public function inline_script_file_browser(){
1026
+		public function inline_script_file_browser() {
1027 1027
 			ob_start();
1028 1028
 			?>
1029 1029
 			<script>
@@ -1038,10 +1038,10 @@  discard block
 block discarded – undo
1038 1038
 			/*
1039 1039
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1040 1040
 			 */
1041
-			return str_replace( array(
1041
+			return str_replace(array(
1042 1042
 				'<script>',
1043 1043
 				'</script>'
1044
-			), '', $output );
1044
+			), '', $output);
1045 1045
 		}
1046 1046
 
1047 1047
 		/**
@@ -1049,50 +1049,50 @@  discard block
 block discarded – undo
1049 1049
 		 */
1050 1050
 		public function enqueue_scripts() {
1051 1051
 
1052
-			if( is_admin() && !$this->is_aui_screen()){
1052
+			if (is_admin() && !$this->is_aui_screen()) {
1053 1053
 				// don't add wp-admin scripts if not requested to
1054
-			}else {
1054
+			} else {
1055 1055
 
1056 1056
 				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1057 1057
 
1058 1058
 				// select2
1059
-				wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
1059
+				wp_register_script('select2', $this->url . 'assets/js/select2.min.js', array('jquery'), $this->select2_version);
1060 1060
 
1061 1061
 				// flatpickr
1062
-				wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
1062
+				wp_register_script('flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest);
1063 1063
 
1064 1064
 				// Bootstrap file browser
1065
-				wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
1066
-				wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
1065
+				wp_register_script('aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version);
1066
+				wp_add_inline_script('aui-custom-file-input', $this->inline_script_file_browser());
1067 1067
 
1068 1068
 				$load_inline = false;
1069 1069
 
1070
-				if ( $this->settings[ $js_setting ] == 'core-popper' ) {
1070
+				if ($this->settings[$js_setting] == 'core-popper') {
1071 1071
 					// Bootstrap bundle
1072 1072
 					$url = $this->url . 'assets/js/bootstrap.bundle.min.js';
1073
-					wp_register_script( 'bootstrap-js-bundle', $url, array(
1073
+					wp_register_script('bootstrap-js-bundle', $url, array(
1074 1074
 						'select2',
1075 1075
 						'jquery'
1076
-					), $this->latest, $this->is_bs3_compat() );
1076
+					), $this->latest, $this->is_bs3_compat());
1077 1077
 					// if in admin then add to footer for compatibility.
1078
-					is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
1078
+					is_admin() ? wp_enqueue_script('bootstrap-js-bundle', '', null, null, true) : wp_enqueue_script('bootstrap-js-bundle');
1079 1079
 					$script = $this->inline_script();
1080
-					wp_add_inline_script( 'bootstrap-js-bundle', $script );
1081
-				} elseif ( $this->settings[ $js_setting ] == 'popper' ) {
1080
+					wp_add_inline_script('bootstrap-js-bundle', $script);
1081
+				} elseif ($this->settings[$js_setting] == 'popper') {
1082 1082
 					$url = $this->url . 'assets/js/popper.min.js';
1083
-					wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
1084
-					wp_enqueue_script( 'bootstrap-js-popper' );
1083
+					wp_register_script('bootstrap-js-popper', $url, array('select2', 'jquery'), $this->latest);
1084
+					wp_enqueue_script('bootstrap-js-popper');
1085 1085
 					$load_inline = true;
1086 1086
 				} else {
1087 1087
 					$load_inline = true;
1088 1088
 				}
1089 1089
 
1090 1090
 				// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
1091
-				if ( $load_inline ) {
1092
-					wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
1093
-					wp_enqueue_script( 'bootstrap-dummy' );
1091
+				if ($load_inline) {
1092
+					wp_register_script('bootstrap-dummy', '', array('select2', 'jquery'));
1093
+					wp_enqueue_script('bootstrap-dummy');
1094 1094
 					$script = $this->inline_script();
1095
-					wp_add_inline_script( 'bootstrap-dummy', $script );
1095
+					wp_add_inline_script('bootstrap-dummy', $script);
1096 1096
 				}
1097 1097
 			}
1098 1098
 
@@ -1101,9 +1101,9 @@  discard block
 block discarded – undo
1101 1101
 		/**
1102 1102
 		 * Enqueue flatpickr if called.
1103 1103
 		 */
1104
-		public function enqueue_flatpickr(){
1105
-			wp_enqueue_style( 'flatpickr' );
1106
-			wp_enqueue_script( 'flatpickr' );
1104
+		public function enqueue_flatpickr() {
1105
+			wp_enqueue_style('flatpickr');
1106
+			wp_enqueue_script('flatpickr');
1107 1107
 		}
1108 1108
 
1109 1109
 		/**
@@ -1115,15 +1115,15 @@  discard block
 block discarded – undo
1115 1115
 
1116 1116
 			$url = '';
1117 1117
 			// check if we are inside a plugin
1118
-			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
1118
+			$file_dir = str_replace("/includes", "", wp_normalize_path(dirname(__FILE__)));
1119 1119
 
1120 1120
 			// add check in-case user has changed wp-content dir name.
1121 1121
 			$wp_content_folder_name = basename(WP_CONTENT_DIR);
1122
-			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
1123
-			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
1122
+			$dir_parts = explode("/$wp_content_folder_name/", $file_dir);
1123
+			$url_parts = explode("/$wp_content_folder_name/", plugins_url());
1124 1124
 
1125
-			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
1126
-				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
1125
+			if (!empty($url_parts[0]) && !empty($dir_parts[1])) {
1126
+				$url = trailingslashit($url_parts[0] . "/$wp_content_folder_name/" . $dir_parts[1]);
1127 1127
 			}
1128 1128
 
1129 1129
 			return $url;
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
 		 * Register the database settings with WordPress.
1134 1134
 		 */
1135 1135
 		public function register_settings() {
1136
-			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
1136
+			register_setting('ayecode-ui-settings', 'ayecode-ui-settings');
1137 1137
 		}
1138 1138
 
1139 1139
 		/**
@@ -1142,10 +1142,10 @@  discard block
 block discarded – undo
1142 1142
 		 */
1143 1143
 		public function menu_item() {
1144 1144
 			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
1145
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1145
+			call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1146 1146
 				$this,
1147 1147
 				'settings_page'
1148
-			) );
1148
+			));
1149 1149
 		}
1150 1150
 
1151 1151
 		/**
@@ -1153,7 +1153,7 @@  discard block
 block discarded – undo
1153 1153
 		 *
1154 1154
 		 * @return array
1155 1155
 		 */
1156
-		public function theme_js_settings(){
1156
+		public function theme_js_settings() {
1157 1157
 			return array(
1158 1158
 				'ayetheme' => 'popper',
1159 1159
 				'listimia' => 'required',
@@ -1169,17 +1169,17 @@  discard block
 block discarded – undo
1169 1169
 		 */
1170 1170
 		public function get_settings() {
1171 1171
 
1172
-			$db_settings = get_option( 'ayecode-ui-settings' );
1172
+			$db_settings = get_option('ayecode-ui-settings');
1173 1173
 			$js_default = 'core-popper';
1174 1174
 			$js_default_backend = $js_default;
1175 1175
 
1176 1176
 			// maybe set defaults (if no settings set)
1177
-			if(empty($db_settings)){
1178
-				$active_theme = strtolower( get_template() ); // active parent theme.
1177
+			if (empty($db_settings)) {
1178
+				$active_theme = strtolower(get_template()); // active parent theme.
1179 1179
 				$theme_js_settings = self::theme_js_settings();
1180
-				if(isset($theme_js_settings[$active_theme])){
1180
+				if (isset($theme_js_settings[$active_theme])) {
1181 1181
 					$js_default = $theme_js_settings[$active_theme];
1182
-					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1182
+					$js_default_backend = isset($theme_js_settings[$active_theme . "_backend"]) ? $theme_js_settings[$active_theme . "_backend"] : $js_default;
1183 1183
 				}
1184 1184
 			}
1185 1185
 
@@ -1192,14 +1192,14 @@  discard block
 block discarded – undo
1192 1192
 				'disable_admin'     =>  '', // URL snippets to disable loading on admin
1193 1193
 			);
1194 1194
 
1195
-			$settings = wp_parse_args( $db_settings, $defaults );
1195
+			$settings = wp_parse_args($db_settings, $defaults);
1196 1196
 
1197 1197
 			/**
1198 1198
 			 * Filter the Bootstrap settings.
1199 1199
 			 *
1200 1200
 			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1201 1201
 			 */
1202
-			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1202
+			return $this->settings = apply_filters('ayecode-ui-settings', $settings, $db_settings, $defaults);
1203 1203
 		}
1204 1204
 
1205 1205
 
@@ -1207,90 +1207,90 @@  discard block
 block discarded – undo
1207 1207
 		 * The settings page html output.
1208 1208
 		 */
1209 1209
 		public function settings_page() {
1210
-			if ( ! current_user_can( 'manage_options' ) ) {
1211
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1210
+			if (!current_user_can('manage_options')) {
1211
+				wp_die(__('You do not have sufficient permissions to access this page.', 'aui'));
1212 1212
 			}
1213 1213
 			?>
1214 1214
 			<div class="wrap">
1215 1215
 				<h1><?php echo $this->name; ?></h1>
1216
-				<p><?php _e("Here you can adjust settings if you are having compatibility issues.",'aui');?></p>
1216
+				<p><?php _e("Here you can adjust settings if you are having compatibility issues.", 'aui'); ?></p>
1217 1217
 				<form method="post" action="options.php">
1218 1218
 					<?php
1219
-					settings_fields( 'ayecode-ui-settings' );
1220
-					do_settings_sections( 'ayecode-ui-settings' );
1219
+					settings_fields('ayecode-ui-settings');
1220
+					do_settings_sections('ayecode-ui-settings');
1221 1221
 					?>
1222 1222
 
1223
-					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
1223
+					<h2><?php _e('Frontend', 'aui'); ?></h2>
1224 1224
 					<table class="form-table wpbs-table-settings">
1225 1225
 						<tr valign="top">
1226 1226
 							<th scope="row"><label
1227
-									for="wpbs-css"><?php _e( 'Load CSS', 'aui' ); ?></label></th>
1227
+									for="wpbs-css"><?php _e('Load CSS', 'aui'); ?></label></th>
1228 1228
 							<td>
1229 1229
 								<select name="ayecode-ui-settings[css]" id="wpbs-css">
1230
-									<option	value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode (default)', 'aui' ); ?></option>
1231
-									<option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php _e( 'Full Mode', 'aui' ); ?></option>
1232
-									<option	value="" <?php selected( $this->settings['css'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option>
1230
+									<option	value="compatibility" <?php selected($this->settings['css'], 'compatibility'); ?>><?php _e('Compatibility Mode (default)', 'aui'); ?></option>
1231
+									<option value="core" <?php selected($this->settings['css'], 'core'); ?>><?php _e('Full Mode', 'aui'); ?></option>
1232
+									<option	value="" <?php selected($this->settings['css'], ''); ?>><?php _e('Disabled', 'aui'); ?></option>
1233 1233
 								</select>
1234 1234
 							</td>
1235 1235
 						</tr>
1236 1236
 
1237 1237
 						<tr valign="top">
1238 1238
 							<th scope="row"><label
1239
-									for="wpbs-js"><?php _e( 'Load JS', 'aui' ); ?></label></th>
1239
+									for="wpbs-js"><?php _e('Load JS', 'aui'); ?></label></th>
1240 1240
 							<td>
1241 1241
 								<select name="ayecode-ui-settings[js]" id="wpbs-js">
1242
-									<option	value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option>
1243
-									<option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option>
1244
-									<option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option>
1245
-									<option	value="" <?php selected( $this->settings['js'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option>
1242
+									<option	value="core-popper" <?php selected($this->settings['js'], 'core-popper'); ?>><?php _e('Core + Popper (default)', 'aui'); ?></option>
1243
+									<option value="popper" <?php selected($this->settings['js'], 'popper'); ?>><?php _e('Popper', 'aui'); ?></option>
1244
+									<option value="required" <?php selected($this->settings['js'], 'required'); ?>><?php _e('Required functions only', 'aui'); ?></option>
1245
+									<option	value="" <?php selected($this->settings['js'], ''); ?>><?php _e('Disabled (not recommended)', 'aui'); ?></option>
1246 1246
 								</select>
1247 1247
 							</td>
1248 1248
 						</tr>
1249 1249
 
1250 1250
 						<tr valign="top">
1251 1251
 							<th scope="row"><label
1252
-									for="wpbs-font_size"><?php _e( 'HTML Font Size (px)', 'aui' ); ?></label></th>
1252
+									for="wpbs-font_size"><?php _e('HTML Font Size (px)', 'aui'); ?></label></th>
1253 1253
 							<td>
1254
-								<input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint( $this->settings['html_font_size']); ?>" placeholder="16" />
1255
-								<p class="description" ><?php _e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.",'aui');?></p>
1254
+								<input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint($this->settings['html_font_size']); ?>" placeholder="16" />
1255
+								<p class="description" ><?php _e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.", 'aui'); ?></p>
1256 1256
 							</td>
1257 1257
 						</tr>
1258 1258
 
1259 1259
 					</table>
1260 1260
 
1261
-					<h2><?php _e( 'Backend', 'aui' ); ?> (wp-admin)</h2>
1261
+					<h2><?php _e('Backend', 'aui'); ?> (wp-admin)</h2>
1262 1262
 					<table class="form-table wpbs-table-settings">
1263 1263
 						<tr valign="top">
1264 1264
 							<th scope="row"><label
1265
-									for="wpbs-css-admin"><?php _e( 'Load CSS', 'aui' ); ?></label></th>
1265
+									for="wpbs-css-admin"><?php _e('Load CSS', 'aui'); ?></label></th>
1266 1266
 							<td>
1267 1267
 								<select name="ayecode-ui-settings[css_backend]" id="wpbs-css-admin">
1268
-									<option	value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode (default)', 'aui' ); ?></option>
1269
-									<option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php _e( 'Full Mode (will cause style issues)', 'aui' ); ?></option>
1270
-									<option	value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option>
1268
+									<option	value="compatibility" <?php selected($this->settings['css_backend'], 'compatibility'); ?>><?php _e('Compatibility Mode (default)', 'aui'); ?></option>
1269
+									<option value="core" <?php selected($this->settings['css_backend'], 'core'); ?>><?php _e('Full Mode (will cause style issues)', 'aui'); ?></option>
1270
+									<option	value="" <?php selected($this->settings['css_backend'], ''); ?>><?php _e('Disabled', 'aui'); ?></option>
1271 1271
 								</select>
1272 1272
 							</td>
1273 1273
 						</tr>
1274 1274
 
1275 1275
 						<tr valign="top">
1276 1276
 							<th scope="row"><label
1277
-									for="wpbs-js-admin"><?php _e( 'Load JS', 'aui' ); ?></label></th>
1277
+									for="wpbs-js-admin"><?php _e('Load JS', 'aui'); ?></label></th>
1278 1278
 							<td>
1279 1279
 								<select name="ayecode-ui-settings[js_backend]" id="wpbs-js-admin">
1280
-									<option	value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option>
1281
-									<option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option>
1282
-									<option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option>
1283
-									<option	value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option>
1280
+									<option	value="core-popper" <?php selected($this->settings['js_backend'], 'core-popper'); ?>><?php _e('Core + Popper (default)', 'aui'); ?></option>
1281
+									<option value="popper" <?php selected($this->settings['js_backend'], 'popper'); ?>><?php _e('Popper', 'aui'); ?></option>
1282
+									<option value="required" <?php selected($this->settings['js_backend'], 'required'); ?>><?php _e('Required functions only', 'aui'); ?></option>
1283
+									<option	value="" <?php selected($this->settings['js_backend'], ''); ?>><?php _e('Disabled (not recommended)', 'aui'); ?></option>
1284 1284
 								</select>
1285 1285
 							</td>
1286 1286
 						</tr>
1287 1287
 
1288 1288
 						<tr valign="top">
1289 1289
 							<th scope="row"><label
1290
-									for="wpbs-disable-admin"><?php _e( 'Disable load on URL', 'aui' ); ?></label></th>
1290
+									for="wpbs-disable-admin"><?php _e('Disable load on URL', 'aui'); ?></label></th>
1291 1291
 							<td>
1292
-								<p><?php _e( 'If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'aui' ); ?></p>
1293
-								<textarea name="ayecode-ui-settings[disable_admin]" rows="10" cols="50" id="wpbs-disable-admin" class="large-text code" spellcheck="false" placeholder="myplugin.php &#10;action=go"><?php echo $this->settings['disable_admin'];?></textarea>
1292
+								<p><?php _e('If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'aui'); ?></p>
1293
+								<textarea name="ayecode-ui-settings[disable_admin]" rows="10" cols="50" id="wpbs-disable-admin" class="large-text code" spellcheck="false" placeholder="myplugin.php &#10;action=go"><?php echo $this->settings['disable_admin']; ?></textarea>
1294 1294
 
1295 1295
 							</td>
1296 1296
 						</tr>
@@ -1308,9 +1308,9 @@  discard block
 block discarded – undo
1308 1308
 			<?php
1309 1309
 		}
1310 1310
 
1311
-		public function customizer_settings($wp_customize){
1311
+		public function customizer_settings($wp_customize) {
1312 1312
 			$wp_customize->add_section('aui_settings', array(
1313
-				'title'    => __('AyeCode UI','aui'),
1313
+				'title'    => __('AyeCode UI', 'aui'),
1314 1314
 				'priority' => 120,
1315 1315
 			));
1316 1316
 
@@ -1324,8 +1324,8 @@  discard block
 block discarded – undo
1324 1324
 				'type'              => 'option',
1325 1325
 				'transport'         => 'refresh',
1326 1326
 			));
1327
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1328
-				'label'    => __('Primary Color','aui'),
1327
+			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1328
+				'label'    => __('Primary Color', 'aui'),
1329 1329
 				'section'  => 'aui_settings',
1330 1330
 				'settings' => 'aui_options[color_primary]',
1331 1331
 			)));
@@ -1337,8 +1337,8 @@  discard block
 block discarded – undo
1337 1337
 				'type'              => 'option',
1338 1338
 				'transport'         => 'refresh',
1339 1339
 			));
1340
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1341
-				'label'    => __('Secondary Color','aui'),
1340
+			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1341
+				'label'    => __('Secondary Color', 'aui'),
1342 1342
 				'section'  => 'aui_settings',
1343 1343
 				'settings' => 'aui_options[color_secondary]',
1344 1344
 			)));
@@ -1364,12 +1364,12 @@  discard block
 block discarded – undo
1364 1364
 			.collapse.show:not(.in){display: inherit;}
1365 1365
 			.fade.show{opacity: 1;}
1366 1366
 
1367
-			<?php if( defined( 'SVQ_THEME_VERSION' ) ){ ?>
1367
+			<?php if (defined('SVQ_THEME_VERSION')) { ?>
1368 1368
 			/* KLEO theme specific */
1369 1369
 			.kleo-main-header .navbar-collapse.collapse.show:not(.in){display: block !important;}
1370 1370
 			<?php } ?>
1371 1371
 
1372
-			<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1372
+			<?php if (defined('FUSION_BUILDER_VERSION')) { ?>
1373 1373
 			/* With Avada builder */
1374 1374
 			body.modal-open .modal.in  {opacity:1;z-index: 99999}
1375 1375
 			body.modal-open .modal.bsui.in .modal-content  {box-shadow: none;}
@@ -1377,10 +1377,10 @@  discard block
 block discarded – undo
1377 1377
 			<?php } ?>
1378 1378
 			</style>
1379 1379
 			<?php
1380
-			return str_replace( array(
1380
+			return str_replace(array(
1381 1381
 				'<style>',
1382 1382
 				'</style>'
1383
-			), '', self::minify_css( ob_get_clean() ) );
1383
+			), '', self::minify_css(ob_get_clean()));
1384 1384
 		}
1385 1385
 
1386 1386
 
@@ -1397,16 +1397,16 @@  discard block
 block discarded – undo
1397 1397
 				<?php
1398 1398
 
1399 1399
 					// BS v3 compat
1400
-					if( self::is_bs3_compat() ){
1400
+					if (self::is_bs3_compat()) {
1401 1401
 					    echo self::bs3_compat_css();
1402 1402
 					}
1403 1403
 
1404
-					if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1405
-						echo self::css_primary($primary_color,$compatibility);
1404
+					if (!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL) {
1405
+						echo self::css_primary($primary_color, $compatibility);
1406 1406
 					}
1407 1407
 
1408
-					if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1409
-						echo self::css_secondary($settings['color_secondary'],$compatibility);
1408
+					if (!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL) {
1409
+						echo self::css_secondary($settings['color_secondary'], $compatibility);
1410 1410
 					}
1411 1411
 
1412 1412
 					// Set admin bar z-index lower when modal is open.
@@ -1419,10 +1419,10 @@  discard block
 block discarded – undo
1419 1419
 			/*
1420 1420
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1421 1421
 			 */
1422
-			return str_replace( array(
1422
+			return str_replace(array(
1423 1423
 				'<style>',
1424 1424
 				'</style>'
1425
-			), '', self::minify_css( ob_get_clean() ) );
1425
+			), '', self::minify_css(ob_get_clean()));
1426 1426
 		}
1427 1427
 
1428 1428
 		/**
@@ -1430,48 +1430,48 @@  discard block
 block discarded – undo
1430 1430
 		 *
1431 1431
 		 * @return bool
1432 1432
 		 */
1433
-		public static function is_bs3_compat(){
1433
+		public static function is_bs3_compat() {
1434 1434
 			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1435 1435
 		}
1436 1436
 
1437
-		public static function css_primary($color_code,$compatibility){;
1437
+		public static function css_primary($color_code, $compatibility) {;
1438 1438
 			$color_code = sanitize_hex_color($color_code);
1439
-			if(!$color_code){return '';}
1439
+			if (!$color_code) {return ''; }
1440 1440
 			/**
1441 1441
 			 * c = color, b = background color, o = border-color, f = fill
1442 1442
 			 */
1443 1443
 			$selectors = array(
1444 1444
 				'a' => array('c'),
1445
-				'.btn-primary' => array('b','o'),
1446
-				'.btn-primary.disabled' => array('b','o'),
1447
-				'.btn-primary:disabled' => array('b','o'),
1448
-				'.btn-outline-primary' => array('c','o'),
1449
-				'.btn-outline-primary:hover' => array('b','o'),
1450
-				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1451
-				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1452
-				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1445
+				'.btn-primary' => array('b', 'o'),
1446
+				'.btn-primary.disabled' => array('b', 'o'),
1447
+				'.btn-primary:disabled' => array('b', 'o'),
1448
+				'.btn-outline-primary' => array('c', 'o'),
1449
+				'.btn-outline-primary:hover' => array('b', 'o'),
1450
+				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b', 'o'),
1451
+				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b', 'o'),
1452
+				'.show>.btn-outline-primary.dropdown-toggle' => array('b', 'o'),
1453 1453
 				'.btn-link' => array('c'),
1454 1454
 				'.dropdown-item.active' => array('b'),
1455
-				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1456
-				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1455
+				'.custom-control-input:checked~.custom-control-label::before' => array('b', 'o'),
1456
+				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b', 'o'),
1457 1457
 //				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1458 1458
 //				'.custom-range::-moz-range-thumb' => array('b'),
1459 1459
 //				'.custom-range::-ms-thumb' => array('b'),
1460 1460
 				'.nav-pills .nav-link.active' => array('b'),
1461 1461
 				'.nav-pills .show>.nav-link' => array('b'),
1462 1462
 				'.page-link' => array('c'),
1463
-				'.page-item.active .page-link' => array('b','o'),
1463
+				'.page-item.active .page-link' => array('b', 'o'),
1464 1464
 				'.badge-primary' => array('b'),
1465
-				'.alert-primary' => array('b','o'),
1465
+				'.alert-primary' => array('b', 'o'),
1466 1466
 				'.progress-bar' => array('b'),
1467
-				'.list-group-item.active' => array('b','o'),
1468
-				'.bg-primary' => array('b','f'),
1467
+				'.list-group-item.active' => array('b', 'o'),
1468
+				'.bg-primary' => array('b', 'f'),
1469 1469
 				'.btn-link.btn-primary' => array('c'),
1470 1470
 				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1471 1471
 			);
1472 1472
 
1473 1473
 			$important_selectors = array(
1474
-				'.bg-primary' => array('b','f'),
1474
+				'.bg-primary' => array('b', 'f'),
1475 1475
 				'.border-primary' => array('o'),
1476 1476
 				'.text-primary' => array('c'),
1477 1477
 			);
@@ -1488,116 +1488,116 @@  discard block
 block discarded – undo
1488 1488
 			$output = '';
1489 1489
 
1490 1490
 			// build rules into each type
1491
-			foreach($selectors as $selector => $types){
1492
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1493
-				$types = array_combine($types,$types);
1494
-				if(isset($types['c'])){$color[] = $selector;}
1495
-				if(isset($types['b'])){$background[] = $selector;}
1496
-				if(isset($types['o'])){$border[] = $selector;}
1497
-				if(isset($types['f'])){$fill[] = $selector;}
1491
+			foreach ($selectors as $selector => $types) {
1492
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
1493
+				$types = array_combine($types, $types);
1494
+				if (isset($types['c'])) {$color[] = $selector; }
1495
+				if (isset($types['b'])) {$background[] = $selector; }
1496
+				if (isset($types['o'])) {$border[] = $selector; }
1497
+				if (isset($types['f'])) {$fill[] = $selector; }
1498 1498
 			}
1499 1499
 
1500 1500
 			// build rules into each type
1501
-			foreach($important_selectors as $selector => $types){
1502
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1503
-				$types = array_combine($types,$types);
1504
-				if(isset($types['c'])){$color_i[] = $selector;}
1505
-				if(isset($types['b'])){$background_i[] = $selector;}
1506
-				if(isset($types['o'])){$border_i[] = $selector;}
1507
-				if(isset($types['f'])){$fill_i[] = $selector;}
1501
+			foreach ($important_selectors as $selector => $types) {
1502
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
1503
+				$types = array_combine($types, $types);
1504
+				if (isset($types['c'])) {$color_i[] = $selector; }
1505
+				if (isset($types['b'])) {$background_i[] = $selector; }
1506
+				if (isset($types['o'])) {$border_i[] = $selector; }
1507
+				if (isset($types['f'])) {$fill_i[] = $selector; }
1508 1508
 			}
1509 1509
 
1510 1510
 			// add any color rules
1511
-			if(!empty($color)){
1512
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1511
+			if (!empty($color)) {
1512
+				$output .= implode(",", $color) . "{color: $color_code;} ";
1513 1513
 			}
1514
-			if(!empty($color_i)){
1515
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1514
+			if (!empty($color_i)) {
1515
+				$output .= implode(",", $color_i) . "{color: $color_code !important;} ";
1516 1516
 			}
1517 1517
 
1518 1518
 			// add any background color rules
1519
-			if(!empty($background)){
1520
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1519
+			if (!empty($background)) {
1520
+				$output .= implode(",", $background) . "{background-color: $color_code;} ";
1521 1521
 			}
1522
-			if(!empty($background_i)){
1523
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1522
+			if (!empty($background_i)) {
1523
+				$output .= implode(",", $background_i) . "{background-color: $color_code !important;} ";
1524 1524
 			}
1525 1525
 
1526 1526
 			// add any border color rules
1527
-			if(!empty($border)){
1528
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1527
+			if (!empty($border)) {
1528
+				$output .= implode(",", $border) . "{border-color: $color_code;} ";
1529 1529
 			}
1530
-			if(!empty($border_i)){
1531
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1530
+			if (!empty($border_i)) {
1531
+				$output .= implode(",", $border_i) . "{border-color: $color_code !important;} ";
1532 1532
 			}
1533 1533
 
1534 1534
 			// add any fill color rules
1535
-			if(!empty($fill)){
1536
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1535
+			if (!empty($fill)) {
1536
+				$output .= implode(",", $fill) . "{fill: $color_code;} ";
1537 1537
 			}
1538
-			if(!empty($fill_i)){
1539
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1538
+			if (!empty($fill_i)) {
1539
+				$output .= implode(",", $fill_i) . "{fill: $color_code !important;} ";
1540 1540
 			}
1541 1541
 
1542 1542
 
1543 1543
 			$prefix = $compatibility ? ".bsui " : "";
1544 1544
 
1545 1545
 			// darken
1546
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1547
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1548
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1546
+			$darker_075 = self::css_hex_lighten_darken($color_code, "-0.075");
1547
+			$darker_10 = self::css_hex_lighten_darken($color_code, "-0.10");
1548
+			$darker_125 = self::css_hex_lighten_darken($color_code, "-0.125");
1549 1549
 
1550 1550
 			// lighten
1551
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1551
+			$lighten_25 = self::css_hex_lighten_darken($color_code, "0.25");
1552 1552
 
1553 1553
 			// opacity see https://css-tricks.com/8-digit-hex-codes/
1554
-			$op_25 = $color_code."40"; // 25% opacity
1554
+			$op_25 = $color_code . "40"; // 25% opacity
1555 1555
 
1556 1556
 
1557 1557
 			// button states
1558
-			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1559
-			$output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1560
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1561
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1558
+			$output .= $prefix . " .btn-primary:hover{background-color: " . $darker_075 . ";    border-color: " . $darker_10 . ";} ";
1559
+			$output .= $prefix . " .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1560
+			$output .= $prefix . " .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: " . $darker_10 . ";    border-color: " . $darker_125 . ";} ";
1561
+			$output .= $prefix . " .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1562 1562
 
1563 1563
 
1564 1564
 			// dropdown's
1565
-			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1565
+			$output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1566 1566
 
1567 1567
 
1568 1568
 			// input states
1569
-			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1569
+			$output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} ";
1570 1570
 
1571 1571
 			// page link
1572
-			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1572
+			$output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1573 1573
 
1574 1574
 			return $output;
1575 1575
 		}
1576 1576
 
1577
-		public static function css_secondary($color_code,$compatibility){;
1577
+		public static function css_secondary($color_code, $compatibility) {;
1578 1578
 			$color_code = sanitize_hex_color($color_code);
1579
-			if(!$color_code){return '';}
1579
+			if (!$color_code) {return ''; }
1580 1580
 			/**
1581 1581
 			 * c = color, b = background color, o = border-color, f = fill
1582 1582
 			 */
1583 1583
 			$selectors = array(
1584
-				'.btn-secondary' => array('b','o'),
1585
-				'.btn-secondary.disabled' => array('b','o'),
1586
-				'.btn-secondary:disabled' => array('b','o'),
1587
-				'.btn-outline-secondary' => array('c','o'),
1588
-				'.btn-outline-secondary:hover' => array('b','o'),
1584
+				'.btn-secondary' => array('b', 'o'),
1585
+				'.btn-secondary.disabled' => array('b', 'o'),
1586
+				'.btn-secondary:disabled' => array('b', 'o'),
1587
+				'.btn-outline-secondary' => array('c', 'o'),
1588
+				'.btn-outline-secondary:hover' => array('b', 'o'),
1589 1589
 				'.btn-outline-secondary.disabled' => array('c'),
1590 1590
 				'.btn-outline-secondary:disabled' => array('c'),
1591
-				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1592
-				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1593
-				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1591
+				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b', 'o'),
1592
+				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b', 'o'),
1593
+				'.btn-outline-secondary.dropdown-toggle' => array('b', 'o'),
1594 1594
 				'.badge-secondary' => array('b'),
1595
-				'.alert-secondary' => array('b','o'),
1595
+				'.alert-secondary' => array('b', 'o'),
1596 1596
 				'.btn-link.btn-secondary' => array('c'),
1597 1597
 			);
1598 1598
 
1599 1599
 			$important_selectors = array(
1600
-				'.bg-secondary' => array('b','f'),
1600
+				'.bg-secondary' => array('b', 'f'),
1601 1601
 				'.border-secondary' => array('o'),
1602 1602
 				'.text-secondary' => array('c'),
1603 1603
 			);
@@ -1614,77 +1614,77 @@  discard block
 block discarded – undo
1614 1614
 			$output = '';
1615 1615
 
1616 1616
 			// build rules into each type
1617
-			foreach($selectors as $selector => $types){
1618
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1619
-				$types = array_combine($types,$types);
1620
-				if(isset($types['c'])){$color[] = $selector;}
1621
-				if(isset($types['b'])){$background[] = $selector;}
1622
-				if(isset($types['o'])){$border[] = $selector;}
1623
-				if(isset($types['f'])){$fill[] = $selector;}
1617
+			foreach ($selectors as $selector => $types) {
1618
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
1619
+				$types = array_combine($types, $types);
1620
+				if (isset($types['c'])) {$color[] = $selector; }
1621
+				if (isset($types['b'])) {$background[] = $selector; }
1622
+				if (isset($types['o'])) {$border[] = $selector; }
1623
+				if (isset($types['f'])) {$fill[] = $selector; }
1624 1624
 			}
1625 1625
 
1626 1626
 			// build rules into each type
1627
-			foreach($important_selectors as $selector => $types){
1628
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1629
-				$types = array_combine($types,$types);
1630
-				if(isset($types['c'])){$color_i[] = $selector;}
1631
-				if(isset($types['b'])){$background_i[] = $selector;}
1632
-				if(isset($types['o'])){$border_i[] = $selector;}
1633
-				if(isset($types['f'])){$fill_i[] = $selector;}
1627
+			foreach ($important_selectors as $selector => $types) {
1628
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
1629
+				$types = array_combine($types, $types);
1630
+				if (isset($types['c'])) {$color_i[] = $selector; }
1631
+				if (isset($types['b'])) {$background_i[] = $selector; }
1632
+				if (isset($types['o'])) {$border_i[] = $selector; }
1633
+				if (isset($types['f'])) {$fill_i[] = $selector; }
1634 1634
 			}
1635 1635
 
1636 1636
 			// add any color rules
1637
-			if(!empty($color)){
1638
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1637
+			if (!empty($color)) {
1638
+				$output .= implode(",", $color) . "{color: $color_code;} ";
1639 1639
 			}
1640
-			if(!empty($color_i)){
1641
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1640
+			if (!empty($color_i)) {
1641
+				$output .= implode(",", $color_i) . "{color: $color_code !important;} ";
1642 1642
 			}
1643 1643
 
1644 1644
 			// add any background color rules
1645
-			if(!empty($background)){
1646
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1645
+			if (!empty($background)) {
1646
+				$output .= implode(",", $background) . "{background-color: $color_code;} ";
1647 1647
 			}
1648
-			if(!empty($background_i)){
1649
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1648
+			if (!empty($background_i)) {
1649
+				$output .= implode(",", $background_i) . "{background-color: $color_code !important;} ";
1650 1650
 			}
1651 1651
 
1652 1652
 			// add any border color rules
1653
-			if(!empty($border)){
1654
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1653
+			if (!empty($border)) {
1654
+				$output .= implode(",", $border) . "{border-color: $color_code;} ";
1655 1655
 			}
1656
-			if(!empty($border_i)){
1657
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1656
+			if (!empty($border_i)) {
1657
+				$output .= implode(",", $border_i) . "{border-color: $color_code !important;} ";
1658 1658
 			}
1659 1659
 
1660 1660
 			// add any fill color rules
1661
-			if(!empty($fill)){
1662
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1661
+			if (!empty($fill)) {
1662
+				$output .= implode(",", $fill) . "{fill: $color_code;} ";
1663 1663
 			}
1664
-			if(!empty($fill_i)){
1665
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1664
+			if (!empty($fill_i)) {
1665
+				$output .= implode(",", $fill_i) . "{fill: $color_code !important;} ";
1666 1666
 			}
1667 1667
 
1668 1668
 
1669 1669
 			$prefix = $compatibility ? ".bsui " : "";
1670 1670
 
1671 1671
 			// darken
1672
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1673
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1674
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1672
+			$darker_075 = self::css_hex_lighten_darken($color_code, "-0.075");
1673
+			$darker_10 = self::css_hex_lighten_darken($color_code, "-0.10");
1674
+			$darker_125 = self::css_hex_lighten_darken($color_code, "-0.125");
1675 1675
 
1676 1676
 			// lighten
1677
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1677
+			$lighten_25 = self::css_hex_lighten_darken($color_code, "0.25");
1678 1678
 
1679 1679
 			// opacity see https://css-tricks.com/8-digit-hex-codes/
1680
-			$op_25 = $color_code."40"; // 25% opacity
1680
+			$op_25 = $color_code . "40"; // 25% opacity
1681 1681
 
1682 1682
 
1683 1683
 			// button states
1684
-			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1685
-			$output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1686
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1687
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1684
+			$output .= $prefix . " .btn-secondary:hover{background-color: " . $darker_075 . ";    border-color: " . $darker_10 . ";} ";
1685
+			$output .= $prefix . " .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1686
+			$output .= $prefix . " .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: " . $darker_10 . ";    border-color: " . $darker_125 . ";} ";
1687
+			$output .= $prefix . " .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1688 1688
 
1689 1689
 
1690 1690
 			return $output;
@@ -1720,8 +1720,8 @@  discard block
 block discarded – undo
1720 1720
 		/**
1721 1721
 		 * Check if we should display examples.
1722 1722
 		 */
1723
-		public function maybe_show_examples(){
1724
-			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1723
+		public function maybe_show_examples() {
1724
+			if (current_user_can('manage_options') && isset($_REQUEST['preview-aui'])) {
1725 1725
 				echo "<head>";
1726 1726
 				wp_head();
1727 1727
 				echo "</head>";
@@ -1737,7 +1737,7 @@  discard block
 block discarded – undo
1737 1737
 		 *
1738 1738
 		 * @return string
1739 1739
 		 */
1740
-		public function get_examples(){
1740
+		public function get_examples() {
1741 1741
 			$output = '';
1742 1742
 
1743 1743
 
@@ -1843,74 +1843,74 @@  discard block
 block discarded – undo
1843 1843
 		 */
1844 1844
 		public static function calendar_params() {
1845 1845
 			$params = array(
1846
-				'month_long_1' => __( 'January', 'aui' ),
1847
-				'month_long_2' => __( 'February', 'aui' ),
1848
-				'month_long_3' => __( 'March', 'aui' ),
1849
-				'month_long_4' => __( 'April', 'aui' ),
1850
-				'month_long_5' => __( 'May', 'aui' ),
1851
-				'month_long_6' => __( 'June', 'aui' ),
1852
-				'month_long_7' => __( 'July', 'aui' ),
1853
-				'month_long_8' => __( 'August', 'aui' ),
1854
-				'month_long_9' => __( 'September', 'aui' ),
1855
-				'month_long_10' => __( 'October', 'aui' ),
1856
-				'month_long_11' => __( 'November', 'aui' ),
1857
-				'month_long_12' => __( 'December', 'aui' ),
1858
-				'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ),
1859
-				'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ),
1860
-				'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ),
1861
-				'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ),
1862
-				'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ),
1863
-				'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ),
1864
-				'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ),
1865
-				'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ),
1866
-				'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ),
1867
-				'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ),
1868
-				'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ),
1869
-				'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ),
1870
-				'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ),
1871
-				'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ),
1872
-				'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ),
1873
-				'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ),
1874
-				'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ),
1875
-				'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ),
1876
-				'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ),
1877
-				'day_s2_1' => __( 'Su', 'aui' ),
1878
-				'day_s2_2' => __( 'Mo', 'aui' ),
1879
-				'day_s2_3' => __( 'Tu', 'aui' ),
1880
-				'day_s2_4' => __( 'We', 'aui' ),
1881
-				'day_s2_5' => __( 'Th', 'aui' ),
1882
-				'day_s2_6' => __( 'Fr', 'aui' ),
1883
-				'day_s2_7' => __( 'Sa', 'aui' ),
1884
-				'day_s3_1' => __( 'Sun', 'aui' ),
1885
-				'day_s3_2' => __( 'Mon', 'aui' ),
1886
-				'day_s3_3' => __( 'Tue', 'aui' ),
1887
-				'day_s3_4' => __( 'Wed', 'aui' ),
1888
-				'day_s3_5' => __( 'Thu', 'aui' ),
1889
-				'day_s3_6' => __( 'Fri', 'aui' ),
1890
-				'day_s3_7' => __( 'Sat', 'aui' ),
1891
-				'day_s5_1' => __( 'Sunday', 'aui' ),
1892
-				'day_s5_2' => __( 'Monday', 'aui' ),
1893
-				'day_s5_3' => __( 'Tuesday', 'aui' ),
1894
-				'day_s5_4' => __( 'Wednesday', 'aui' ),
1895
-				'day_s5_5' => __( 'Thursday', 'aui' ),
1896
-				'day_s5_6' => __( 'Friday', 'aui' ),
1897
-				'day_s5_7' => __( 'Saturday', 'aui' ),
1898
-				'am_lower' => __( 'am', 'aui' ),
1899
-				'pm_lower' => __( 'pm', 'aui' ),
1900
-				'am_upper' => __( 'AM', 'aui' ),
1901
-				'pm_upper' => __( 'PM', 'aui' ),
1902
-				'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
1846
+				'month_long_1' => __('January', 'aui'),
1847
+				'month_long_2' => __('February', 'aui'),
1848
+				'month_long_3' => __('March', 'aui'),
1849
+				'month_long_4' => __('April', 'aui'),
1850
+				'month_long_5' => __('May', 'aui'),
1851
+				'month_long_6' => __('June', 'aui'),
1852
+				'month_long_7' => __('July', 'aui'),
1853
+				'month_long_8' => __('August', 'aui'),
1854
+				'month_long_9' => __('September', 'aui'),
1855
+				'month_long_10' => __('October', 'aui'),
1856
+				'month_long_11' => __('November', 'aui'),
1857
+				'month_long_12' => __('December', 'aui'),
1858
+				'month_s_1' => _x('Jan', 'January abbreviation', 'aui'),
1859
+				'month_s_2' => _x('Feb', 'February abbreviation', 'aui'),
1860
+				'month_s_3' => _x('Mar', 'March abbreviation', 'aui'),
1861
+				'month_s_4' => _x('Apr', 'April abbreviation', 'aui'),
1862
+				'month_s_5' => _x('May', 'May abbreviation', 'aui'),
1863
+				'month_s_6' => _x('Jun', 'June abbreviation', 'aui'),
1864
+				'month_s_7' => _x('Jul', 'July abbreviation', 'aui'),
1865
+				'month_s_8' => _x('Aug', 'August abbreviation', 'aui'),
1866
+				'month_s_9' => _x('Sep', 'September abbreviation', 'aui'),
1867
+				'month_s_10' => _x('Oct', 'October abbreviation', 'aui'),
1868
+				'month_s_11' => _x('Nov', 'November abbreviation', 'aui'),
1869
+				'month_s_12' => _x('Dec', 'December abbreviation', 'aui'),
1870
+				'day_s1_1' => _x('S', 'Sunday initial', 'aui'),
1871
+				'day_s1_2' => _x('M', 'Monday initial', 'aui'),
1872
+				'day_s1_3' => _x('T', 'Tuesday initial', 'aui'),
1873
+				'day_s1_4' => _x('W', 'Wednesday initial', 'aui'),
1874
+				'day_s1_5' => _x('T', 'Friday initial', 'aui'),
1875
+				'day_s1_6' => _x('F', 'Thursday initial', 'aui'),
1876
+				'day_s1_7' => _x('S', 'Saturday initial', 'aui'),
1877
+				'day_s2_1' => __('Su', 'aui'),
1878
+				'day_s2_2' => __('Mo', 'aui'),
1879
+				'day_s2_3' => __('Tu', 'aui'),
1880
+				'day_s2_4' => __('We', 'aui'),
1881
+				'day_s2_5' => __('Th', 'aui'),
1882
+				'day_s2_6' => __('Fr', 'aui'),
1883
+				'day_s2_7' => __('Sa', 'aui'),
1884
+				'day_s3_1' => __('Sun', 'aui'),
1885
+				'day_s3_2' => __('Mon', 'aui'),
1886
+				'day_s3_3' => __('Tue', 'aui'),
1887
+				'day_s3_4' => __('Wed', 'aui'),
1888
+				'day_s3_5' => __('Thu', 'aui'),
1889
+				'day_s3_6' => __('Fri', 'aui'),
1890
+				'day_s3_7' => __('Sat', 'aui'),
1891
+				'day_s5_1' => __('Sunday', 'aui'),
1892
+				'day_s5_2' => __('Monday', 'aui'),
1893
+				'day_s5_3' => __('Tuesday', 'aui'),
1894
+				'day_s5_4' => __('Wednesday', 'aui'),
1895
+				'day_s5_5' => __('Thursday', 'aui'),
1896
+				'day_s5_6' => __('Friday', 'aui'),
1897
+				'day_s5_7' => __('Saturday', 'aui'),
1898
+				'am_lower' => __('am', 'aui'),
1899
+				'pm_lower' => __('pm', 'aui'),
1900
+				'am_upper' => __('AM', 'aui'),
1901
+				'pm_upper' => __('PM', 'aui'),
1902
+				'firstDayOfWeek' => (int) get_option('start_of_week'),
1903 1903
 				'time_24hr' => false,
1904
-				'year' => __( 'Year', 'aui' ),
1905
-				'hour' => __( 'Hour', 'aui' ),
1906
-				'minute' => __( 'Minute', 'aui' ),
1907
-				'weekAbbreviation' => __( 'Wk', 'aui' ),
1908
-				'rangeSeparator' => __( ' to ', 'aui' ),
1909
-				'scrollTitle' => __( 'Scroll to increment', 'aui' ),
1910
-				'toggleTitle' => __( 'Click to toggle', 'aui' )
1904
+				'year' => __('Year', 'aui'),
1905
+				'hour' => __('Hour', 'aui'),
1906
+				'minute' => __('Minute', 'aui'),
1907
+				'weekAbbreviation' => __('Wk', 'aui'),
1908
+				'rangeSeparator' => __(' to ', 'aui'),
1909
+				'scrollTitle' => __('Scroll to increment', 'aui'),
1910
+				'toggleTitle' => __('Click to toggle', 'aui')
1911 1911
 			);
1912 1912
 
1913
-			return apply_filters( 'ayecode_ui_calendar_params', $params );
1913
+			return apply_filters('ayecode_ui_calendar_params', $params);
1914 1914
 		}
1915 1915
 
1916 1916
 		/**
@@ -1923,47 +1923,47 @@  discard block
 block discarded – undo
1923 1923
 		public static function flatpickr_locale() {
1924 1924
 			$params = self::calendar_params();
1925 1925
 
1926
-			if ( is_string( $params ) ) {
1927
-				$params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
1926
+			if (is_string($params)) {
1927
+				$params = html_entity_decode($params, ENT_QUOTES, 'UTF-8');
1928 1928
 			} else {
1929
-				foreach ( (array) $params as $key => $value ) {
1930
-					if ( ! is_scalar( $value ) ) {
1929
+				foreach ((array) $params as $key => $value) {
1930
+					if (!is_scalar($value)) {
1931 1931
 						continue;
1932 1932
 					}
1933 1933
 
1934
-					$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
1934
+					$params[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
1935 1935
 				}
1936 1936
 			}
1937 1937
 
1938 1938
 			$day_s3 = array();
1939 1939
 			$day_s5 = array();
1940 1940
 
1941
-			for ( $i = 1; $i <= 7; $i ++ ) {
1942
-				$day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
1943
-				$day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
1941
+			for ($i = 1; $i <= 7; $i++) {
1942
+				$day_s3[] = addslashes($params['day_s3_' . $i]);
1943
+				$day_s5[] = addslashes($params['day_s3_' . $i]);
1944 1944
 			}
1945 1945
 
1946 1946
 			$month_s = array();
1947 1947
 			$month_long = array();
1948 1948
 
1949
-			for ( $i = 1; $i <= 12; $i ++ ) {
1950
-				$month_s[] = addslashes( $params[ 'month_s_' . $i ] );
1951
-				$month_long[] = addslashes( $params[ 'month_long_' . $i ] );
1949
+			for ($i = 1; $i <= 12; $i++) {
1950
+				$month_s[] = addslashes($params['month_s_' . $i]);
1951
+				$month_long[] = addslashes($params['month_long_' . $i]);
1952 1952
 			}
1953 1953
 
1954 1954
 ob_start();
1955
-if ( 0 ) { ?><script><?php } ?>
1955
+if (0) { ?><script><?php } ?>
1956 1956
 {
1957 1957
 	weekdays: {
1958
-		shorthand: ['<?php echo implode( "','", $day_s3 ); ?>'],
1959
-		longhand: ['<?php echo implode( "','", $day_s5 ); ?>'],
1958
+		shorthand: ['<?php echo implode("','", $day_s3); ?>'],
1959
+		longhand: ['<?php echo implode("','", $day_s5); ?>'],
1960 1960
 	},
1961 1961
 	months: {
1962
-		shorthand: ['<?php echo implode( "','", $month_s ); ?>'],
1963
-		longhand: ['<?php echo implode( "','", $month_long ); ?>'],
1962
+		shorthand: ['<?php echo implode("','", $month_s); ?>'],
1963
+		longhand: ['<?php echo implode("','", $month_long); ?>'],
1964 1964
 	},
1965 1965
 	daysInMonth: [31,28,31,30,31,30,31,31,30,31,30,31],
1966
-	firstDayOfWeek: <?php echo (int) $params[ 'firstDayOfWeek' ]; ?>,
1966
+	firstDayOfWeek: <?php echo (int) $params['firstDayOfWeek']; ?>,
1967 1967
 	ordinal: function (nth) {
1968 1968
 		var s = nth % 100;
1969 1969
 		if (s > 3 && s < 21)
@@ -1979,21 +1979,21 @@  discard block
 block discarded – undo
1979 1979
 				return "th";
1980 1980
 		}
1981 1981
 	},
1982
-	rangeSeparator: '<?php echo addslashes( $params[ 'rangeSeparator' ] ); ?>',
1983
-	weekAbbreviation: '<?php echo addslashes( $params[ 'weekAbbreviation' ] ); ?>',
1984
-	scrollTitle: '<?php echo addslashes( $params[ 'scrollTitle' ] ); ?>',
1985
-	toggleTitle: '<?php echo addslashes( $params[ 'toggleTitle' ] ); ?>',
1986
-	amPM: ['<?php echo addslashes( $params[ 'am_upper' ] ); ?>','<?php echo addslashes( $params[ 'pm_upper' ] ); ?>'],
1987
-	yearAriaLabel: '<?php echo addslashes( $params[ 'year' ] ); ?>',
1988
-	hourAriaLabel: '<?php echo addslashes( $params[ 'hour' ] ); ?>',
1989
-	minuteAriaLabel: '<?php echo addslashes( $params[ 'minute' ] ); ?>',
1990
-	time_24hr: <?php echo ( $params[ 'time_24hr' ] ? 'true' : 'false' ) ; ?>
1982
+	rangeSeparator: '<?php echo addslashes($params['rangeSeparator']); ?>',
1983
+	weekAbbreviation: '<?php echo addslashes($params['weekAbbreviation']); ?>',
1984
+	scrollTitle: '<?php echo addslashes($params['scrollTitle']); ?>',
1985
+	toggleTitle: '<?php echo addslashes($params['toggleTitle']); ?>',
1986
+	amPM: ['<?php echo addslashes($params['am_upper']); ?>','<?php echo addslashes($params['pm_upper']); ?>'],
1987
+	yearAriaLabel: '<?php echo addslashes($params['year']); ?>',
1988
+	hourAriaLabel: '<?php echo addslashes($params['hour']); ?>',
1989
+	minuteAriaLabel: '<?php echo addslashes($params['minute']); ?>',
1990
+	time_24hr: <?php echo ($params['time_24hr'] ? 'true' : 'false'); ?>
1991 1991
 }
1992
-<?php if ( 0 ) { ?></script><?php } ?>
1992
+<?php if (0) { ?></script><?php } ?>
1993 1993
 <?php
1994 1994
 			$locale = ob_get_clean();
1995 1995
 
1996
-			return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
1996
+			return apply_filters('ayecode_ui_flatpickr_locale', trim($locale));
1997 1997
 		}
1998 1998
 
1999 1999
 		/**
@@ -2005,20 +2005,20 @@  discard block
 block discarded – undo
2005 2005
 		 */
2006 2006
 		public static function select2_params() {
2007 2007
 			$params = array(
2008
-				'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'aui' ),
2009
-				'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'aui' ),
2010
-				'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'aui' ),
2011
-				'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ),
2012
-				'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ),
2013
-				'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'aui' ),
2014
-				'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ),
2015
-				'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ),
2016
-				'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ),
2017
-				'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'aui' ),
2018
-				'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'aui' )
2008
+				'i18n_select_state_text'    => esc_attr__('Select an option&hellip;', 'aui'),
2009
+				'i18n_no_matches'           => _x('No matches found', 'enhanced select', 'aui'),
2010
+				'i18n_ajax_error'           => _x('Loading failed', 'enhanced select', 'aui'),
2011
+				'i18n_input_too_short_1'    => _x('Please enter 1 or more characters', 'enhanced select', 'aui'),
2012
+				'i18n_input_too_short_n'    => _x('Please enter %item% or more characters', 'enhanced select', 'aui'),
2013
+				'i18n_input_too_long_1'     => _x('Please delete 1 character', 'enhanced select', 'aui'),
2014
+				'i18n_input_too_long_n'     => _x('Please delete %item% characters', 'enhanced select', 'aui'),
2015
+				'i18n_selection_too_long_1' => _x('You can only select 1 item', 'enhanced select', 'aui'),
2016
+				'i18n_selection_too_long_n' => _x('You can only select %item% items', 'enhanced select', 'aui'),
2017
+				'i18n_load_more'            => _x('Loading more results&hellip;', 'enhanced select', 'aui'),
2018
+				'i18n_searching'            => _x('Searching&hellip;', 'enhanced select', 'aui')
2019 2019
 			);
2020 2020
 
2021
-			return apply_filters( 'ayecode_ui_select2_params', $params );
2021
+			return apply_filters('ayecode_ui_select2_params', $params);
2022 2022
 		}
2023 2023
 
2024 2024
 		/**
@@ -2031,17 +2031,17 @@  discard block
 block discarded – undo
2031 2031
 		public static function select2_locale() {
2032 2032
 			$params = self::select2_params();
2033 2033
 
2034
-			foreach ( (array) $params as $key => $value ) {
2035
-				if ( ! is_scalar( $value ) ) {
2034
+			foreach ((array) $params as $key => $value) {
2035
+				if (!is_scalar($value)) {
2036 2036
 					continue;
2037 2037
 				}
2038 2038
 
2039
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2039
+				$params[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
2040 2040
 			}
2041 2041
 
2042
-			$locale = json_encode( $params );
2042
+			$locale = json_encode($params);
2043 2043
 
2044
-			return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2044
+			return apply_filters('ayecode_ui_select2_locale', trim($locale));
2045 2045
 		}
2046 2046
 
2047 2047
 		/**
@@ -2054,35 +2054,35 @@  discard block
 block discarded – undo
2054 2054
 		public static function timeago_locale() {
2055 2055
 			$params = array(
2056 2056
 				'prefix_ago' => '',
2057
-				'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ),
2058
-				'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ',
2057
+				'suffix_ago' => ' ' . _x('ago', 'time ago', 'aui'),
2058
+				'prefix_after' => _x('after', 'time ago', 'aui') . ' ',
2059 2059
 				'suffix_after' => '',
2060
-				'seconds' => _x( 'less than a minute', 'time ago', 'aui' ),
2061
-				'minute' => _x( 'about a minute', 'time ago', 'aui' ),
2062
-				'minutes' => _x( '%d minutes', 'time ago', 'aui' ),
2063
-				'hour' => _x( 'about an hour', 'time ago', 'aui' ),
2064
-				'hours' => _x( 'about %d hours', 'time ago', 'aui' ),
2065
-				'day' => _x( 'a day', 'time ago', 'aui' ),
2066
-				'days' => _x( '%d days', 'time ago', 'aui' ),
2067
-				'month' => _x( 'about a month', 'time ago', 'aui' ),
2068
-				'months' => _x( '%d months', 'time ago', 'aui' ),
2069
-				'year' => _x( 'about a year', 'time ago', 'aui' ),
2070
-				'years' => _x( '%d years', 'time ago', 'aui' ),
2060
+				'seconds' => _x('less than a minute', 'time ago', 'aui'),
2061
+				'minute' => _x('about a minute', 'time ago', 'aui'),
2062
+				'minutes' => _x('%d minutes', 'time ago', 'aui'),
2063
+				'hour' => _x('about an hour', 'time ago', 'aui'),
2064
+				'hours' => _x('about %d hours', 'time ago', 'aui'),
2065
+				'day' => _x('a day', 'time ago', 'aui'),
2066
+				'days' => _x('%d days', 'time ago', 'aui'),
2067
+				'month' => _x('about a month', 'time ago', 'aui'),
2068
+				'months' => _x('%d months', 'time ago', 'aui'),
2069
+				'year' => _x('about a year', 'time ago', 'aui'),
2070
+				'years' => _x('%d years', 'time ago', 'aui'),
2071 2071
 			);
2072 2072
 
2073
-			$params = apply_filters( 'ayecode_ui_timeago_params', $params );
2073
+			$params = apply_filters('ayecode_ui_timeago_params', $params);
2074 2074
 
2075
-			foreach ( (array) $params as $key => $value ) {
2076
-				if ( ! is_scalar( $value ) ) {
2075
+			foreach ((array) $params as $key => $value) {
2076
+				if (!is_scalar($value)) {
2077 2077
 					continue;
2078 2078
 				}
2079 2079
 
2080
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2080
+				$params[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
2081 2081
 			}
2082 2082
 
2083
-			$locale = json_encode( $params );
2083
+			$locale = json_encode($params);
2084 2084
 
2085
-			return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) );
2085
+			return apply_filters('ayecode_ui_timeago_locale', trim($locale));
2086 2086
 		}
2087 2087
 
2088 2088
 		/**
@@ -2093,7 +2093,7 @@  discard block
 block discarded – undo
2093 2093
 		 * @return mixed
2094 2094
 		 */
2095 2095
 		public static function minify_js($input) {
2096
-			if(trim($input) === "") return $input;
2096
+			if (trim($input) === "") return $input;
2097 2097
 			return preg_replace(
2098 2098
 				array(
2099 2099
 					// Remove comment(s)
@@ -2125,7 +2125,7 @@  discard block
 block discarded – undo
2125 2125
 		 * @return mixed
2126 2126
 		 */
2127 2127
 		public static function minify_css($input) {
2128
-			if(trim($input) === "") return $input;
2128
+			if (trim($input) === "") return $input;
2129 2129
 			return preg_replace(
2130 2130
 				array(
2131 2131
 					// Remove comment(s)
Please login to merge, or discard this patch.
Braces   +14 added lines, -6 removed lines patch added patch discarded remove patch
@@ -126,8 +126,12 @@  discard block
 block discarded – undo
126 126
 		public function constants(){
127 127
 			define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128 128
 			define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
-			if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
-			if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
129
+			if (!defined('AUI_PRIMARY_COLOR')) {
130
+			    define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
131
+			}
132
+			if (!defined('AUI_SECONDARY_COLOR')) {
133
+			    define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
134
+			}
131 135
 		}
132 136
 
133 137
 		/**
@@ -233,7 +237,7 @@  discard block
 block discarded – undo
233 237
 
234 238
 			if( is_admin() && !$this->is_aui_screen()){
235 239
 				// don't add wp-admin scripts if not requested to
236
-			}else{
240
+			} else{
237 241
 				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
238 242
 
239 243
 				$rtl = is_rtl() ? '-rtl' : '';
@@ -1051,7 +1055,7 @@  discard block
 block discarded – undo
1051 1055
 
1052 1056
 			if( is_admin() && !$this->is_aui_screen()){
1053 1057
 				// don't add wp-admin scripts if not requested to
1054
-			}else {
1058
+			} else {
1055 1059
 
1056 1060
 				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1057 1061
 
@@ -2093,7 +2097,9 @@  discard block
 block discarded – undo
2093 2097
 		 * @return mixed
2094 2098
 		 */
2095 2099
 		public static function minify_js($input) {
2096
-			if(trim($input) === "") return $input;
2100
+			if(trim($input) === "") {
2101
+			    return $input;
2102
+			}
2097 2103
 			return preg_replace(
2098 2104
 				array(
2099 2105
 					// Remove comment(s)
@@ -2125,7 +2131,9 @@  discard block
 block discarded – undo
2125 2131
 		 * @return mixed
2126 2132
 		 */
2127 2133
 		public static function minify_css($input) {
2128
-			if(trim($input) === "") return $input;
2134
+			if(trim($input) === "") {
2135
+			    return $input;
2136
+			}
2129 2137
 			return preg_replace(
2130 2138
 				array(
2131 2139
 					// Remove comment(s)
Please login to merge, or discard this patch.
Indentation   +1223 added lines, -1223 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,236 +21,236 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'AyeCode_UI_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class AyeCode_UI_Settings
28
-	 * @ver 1.0.0
29
-	 * @todo decide how to implement textdomain
30
-	 */
31
-	class AyeCode_UI_Settings {
32
-
33
-		/**
34
-		 * Class version version.
35
-		 *
36
-		 * @var string
37
-		 */
38
-		public $version = '0.1.48';
39
-
40
-		/**
41
-		 * Class textdomain.
42
-		 *
43
-		 * @var string
44
-		 */
45
-		public $textdomain = 'aui';
46
-
47
-		/**
48
-		 * Latest version of Bootstrap at time of publish published.
49
-		 *
50
-		 * @var string
51
-		 */
52
-		public $latest = "4.5.3";
53
-
54
-		/**
55
-		 * Current version of select2 being used.
56
-		 *
57
-		 * @var string
58
-		 */
59
-		public $select2_version = "4.0.11";
60
-
61
-		/**
62
-		 * The title.
63
-		 *
64
-		 * @var string
65
-		 */
66
-		public $name = 'AyeCode UI';
67
-
68
-		/**
69
-		 * The relative url to the assets.
70
-		 *
71
-		 * @var string
72
-		 */
73
-		public $url = '';
74
-
75
-		/**
76
-		 * Holds the settings values.
77
-		 *
78
-		 * @var array
79
-		 */
80
-		private $settings;
81
-
82
-		/**
83
-		 * AyeCode_UI_Settings instance.
84
-		 *
85
-		 * @access private
86
-		 * @since  1.0.0
87
-		 * @var    AyeCode_UI_Settings There can be only one!
88
-		 */
89
-		private static $instance = null;
90
-
91
-		/**
92
-		 * Main AyeCode_UI_Settings Instance.
93
-		 *
94
-		 * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
-		 *
96
-		 * @since 1.0.0
97
-		 * @static
98
-		 * @return AyeCode_UI_Settings - Main instance.
99
-		 */
100
-		public static function instance() {
101
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
-
103
-				self::$instance = new AyeCode_UI_Settings;
104
-
105
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
106
-
107
-				if ( is_admin() ) {
108
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
110
-
111
-					// Maybe show example page
112
-					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
113
-				}
114
-
115
-				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
116
-
117
-				do_action( 'ayecode_ui_settings_loaded' );
118
-			}
119
-
120
-			return self::$instance;
121
-		}
122
-
123
-		/**
124
-		 * Setup some constants.
125
-		 */
126
-		public function constants(){
127
-			define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128
-			define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
-			if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
-			if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
131
-		}
132
-
133
-		/**
134
-		 * Initiate the settings and add the required action hooks.
135
-		 */
136
-		public function init() {
137
-			$this->constants();
138
-			$this->settings = $this->get_settings();
139
-			$this->url = $this->get_url();
140
-
141
-			/**
142
-			 * Maybe load CSS
143
-			 *
144
-			 * We load super early in case there is a theme version that might change the colors
145
-			 */
146
-			if ( $this->settings['css'] ) {
147
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
148
-			}
149
-			if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
151
-			}
152
-
153
-			// maybe load JS
154
-			if ( $this->settings['js'] ) {
155
-				$priority = $this->is_bs3_compat() ? 100 : 1;
156
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
157
-			}
158
-			if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
160
-			}
161
-
162
-			// Maybe set the HTML font size
163
-			if ( $this->settings['html_font_size'] ) {
164
-				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
165
-			}
166
-
167
-
168
-		}
169
-
170
-		/**
171
-		 * Check if we should load the admin scripts or not.
172
-		 *
173
-		 * @return bool
174
-		 */
175
-		public function load_admin_scripts(){
176
-			$result = true;
177
-
178
-			// check if specifically disabled
179
-			if(!empty($this->settings['disable_admin'])){
180
-				$url_parts = explode("\n",$this->settings['disable_admin']);
181
-				foreach($url_parts as $part){
182
-					if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
183
-						return false; // return early, no point checking further
184
-					}
185
-				}
186
-			}
187
-
188
-			return $result;
189
-		}
190
-
191
-		/**
192
-		 * Add a html font size to the footer.
193
-		 */
194
-		public function html_font_size(){
195
-			$this->settings = $this->get_settings();
196
-			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
197
-		}
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class AyeCode_UI_Settings
28
+     * @ver 1.0.0
29
+     * @todo decide how to implement textdomain
30
+     */
31
+    class AyeCode_UI_Settings {
32
+
33
+        /**
34
+         * Class version version.
35
+         *
36
+         * @var string
37
+         */
38
+        public $version = '0.1.48';
39
+
40
+        /**
41
+         * Class textdomain.
42
+         *
43
+         * @var string
44
+         */
45
+        public $textdomain = 'aui';
46
+
47
+        /**
48
+         * Latest version of Bootstrap at time of publish published.
49
+         *
50
+         * @var string
51
+         */
52
+        public $latest = "4.5.3";
53
+
54
+        /**
55
+         * Current version of select2 being used.
56
+         *
57
+         * @var string
58
+         */
59
+        public $select2_version = "4.0.11";
60
+
61
+        /**
62
+         * The title.
63
+         *
64
+         * @var string
65
+         */
66
+        public $name = 'AyeCode UI';
67
+
68
+        /**
69
+         * The relative url to the assets.
70
+         *
71
+         * @var string
72
+         */
73
+        public $url = '';
74
+
75
+        /**
76
+         * Holds the settings values.
77
+         *
78
+         * @var array
79
+         */
80
+        private $settings;
81
+
82
+        /**
83
+         * AyeCode_UI_Settings instance.
84
+         *
85
+         * @access private
86
+         * @since  1.0.0
87
+         * @var    AyeCode_UI_Settings There can be only one!
88
+         */
89
+        private static $instance = null;
90
+
91
+        /**
92
+         * Main AyeCode_UI_Settings Instance.
93
+         *
94
+         * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
+         *
96
+         * @since 1.0.0
97
+         * @static
98
+         * @return AyeCode_UI_Settings - Main instance.
99
+         */
100
+        public static function instance() {
101
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
+
103
+                self::$instance = new AyeCode_UI_Settings;
104
+
105
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
106
+
107
+                if ( is_admin() ) {
108
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
110
+
111
+                    // Maybe show example page
112
+                    add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
113
+                }
198 114
 
199
-		/**
200
-		 * Check if the current admin screen should load scripts.
201
-		 * 
202
-		 * @return bool
203
-		 */
204
-		public function is_aui_screen(){
205
-			$load = false;
206
-			// check if we should load or not
207
-			if ( is_admin() ) {
208
-				// Only enable on set pages
209
-				$aui_screens = array(
210
-					'page',
211
-					'post',
212
-					'settings_page_ayecode-ui-settings',
213
-					'appearance_page_gutenberg-widgets'
214
-				);
215
-				$screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
216
-
217
-				$screen = get_current_screen();
115
+                add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
116
+
117
+                do_action( 'ayecode_ui_settings_loaded' );
118
+            }
119
+
120
+            return self::$instance;
121
+        }
122
+
123
+        /**
124
+         * Setup some constants.
125
+         */
126
+        public function constants(){
127
+            define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128
+            define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
+            if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
+            if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
131
+        }
132
+
133
+        /**
134
+         * Initiate the settings and add the required action hooks.
135
+         */
136
+        public function init() {
137
+            $this->constants();
138
+            $this->settings = $this->get_settings();
139
+            $this->url = $this->get_url();
140
+
141
+            /**
142
+             * Maybe load CSS
143
+             *
144
+             * We load super early in case there is a theme version that might change the colors
145
+             */
146
+            if ( $this->settings['css'] ) {
147
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
148
+            }
149
+            if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
151
+            }
152
+
153
+            // maybe load JS
154
+            if ( $this->settings['js'] ) {
155
+                $priority = $this->is_bs3_compat() ? 100 : 1;
156
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
157
+            }
158
+            if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
160
+            }
161
+
162
+            // Maybe set the HTML font size
163
+            if ( $this->settings['html_font_size'] ) {
164
+                add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
165
+            }
166
+
167
+
168
+        }
169
+
170
+        /**
171
+         * Check if we should load the admin scripts or not.
172
+         *
173
+         * @return bool
174
+         */
175
+        public function load_admin_scripts(){
176
+            $result = true;
177
+
178
+            // check if specifically disabled
179
+            if(!empty($this->settings['disable_admin'])){
180
+                $url_parts = explode("\n",$this->settings['disable_admin']);
181
+                foreach($url_parts as $part){
182
+                    if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
183
+                        return false; // return early, no point checking further
184
+                    }
185
+                }
186
+            }
187
+
188
+            return $result;
189
+        }
190
+
191
+        /**
192
+         * Add a html font size to the footer.
193
+         */
194
+        public function html_font_size(){
195
+            $this->settings = $this->get_settings();
196
+            echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
197
+        }
198
+
199
+        /**
200
+         * Check if the current admin screen should load scripts.
201
+         * 
202
+         * @return bool
203
+         */
204
+        public function is_aui_screen(){
205
+            $load = false;
206
+            // check if we should load or not
207
+            if ( is_admin() ) {
208
+                // Only enable on set pages
209
+                $aui_screens = array(
210
+                    'page',
211
+                    'post',
212
+                    'settings_page_ayecode-ui-settings',
213
+                    'appearance_page_gutenberg-widgets'
214
+                );
215
+                $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
216
+
217
+                $screen = get_current_screen();
218 218
 
219 219
 //				echo '###'.$screen->id;
220 220
 				
221
-				if ( $screen && in_array( $screen->id, $screen_ids ) ) {
222
-					$load = true;
223
-				}
224
-			}
221
+                if ( $screen && in_array( $screen->id, $screen_ids ) ) {
222
+                    $load = true;
223
+                }
224
+            }
225 225
 
226
-			return $load;
227
-		}
226
+            return $load;
227
+        }
228 228
 
229
-		/**
230
-		 * Adds the styles.
231
-		 */
232
-		public function enqueue_style() {
229
+        /**
230
+         * Adds the styles.
231
+         */
232
+        public function enqueue_style() {
233 233
 
234
-			if( is_admin() && !$this->is_aui_screen()){
235
-				// don't add wp-admin scripts if not requested to
236
-			}else{
237
-				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
234
+            if( is_admin() && !$this->is_aui_screen()){
235
+                // don't add wp-admin scripts if not requested to
236
+            }else{
237
+                $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
238 238
 
239
-				$rtl = is_rtl() ? '-rtl' : '';
239
+                $rtl = is_rtl() ? '-rtl' : '';
240 240
 
241
-				if($this->settings[$css_setting]){
242
-					$compatibility = $this->settings[$css_setting]=='core' ? false : true;
243
-					$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
244
-					wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
245
-					wp_enqueue_style( 'ayecode-ui' );
241
+                if($this->settings[$css_setting]){
242
+                    $compatibility = $this->settings[$css_setting]=='core' ? false : true;
243
+                    $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
244
+                    wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
245
+                    wp_enqueue_style( 'ayecode-ui' );
246 246
 
247
-					// flatpickr
248
-					wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
247
+                    // flatpickr
248
+                    wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
249 249
 
250 250
 
251
-					// fix some wp-admin issues
252
-					if(is_admin()){
253
-						$custom_css = "
251
+                    // fix some wp-admin issues
252
+                    if(is_admin()){
253
+                        $custom_css = "
254 254
                 body{
255 255
                     background-color: #f1f1f1;
256 256
                     font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
@@ -292,35 +292,35 @@  discard block
 block discarded – undo
292 292
 				}
293 293
                 ";
294 294
 
295
-						// @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
296
-						$custom_css .= "
295
+                        // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
296
+                        $custom_css .= "
297 297
 						.edit-post-sidebar input[type=color].components-text-control__input{
298 298
 						    padding: 0;
299 299
 						}
300 300
 					";
301
-						wp_add_inline_style( 'ayecode-ui', $custom_css );
302
-					}
301
+                        wp_add_inline_style( 'ayecode-ui', $custom_css );
302
+                    }
303 303
 
304
-					// custom changes
305
-					wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
304
+                    // custom changes
305
+                    wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
306 306
 
307
-				}
308
-			}
307
+                }
308
+            }
309 309
 
310 310
 
311
-		}
311
+        }
312
+
313
+        /**
314
+         * Get inline script used if bootstrap enqueued
315
+         *
316
+         * If this remains small then its best to use this than to add another JS file.
317
+         */
318
+        public function inline_script() {
319
+            // Flatpickr calendar locale
320
+            $flatpickr_locale = self::flatpickr_locale();
312 321
 
313
-		/**
314
-		 * Get inline script used if bootstrap enqueued
315
-		 *
316
-		 * If this remains small then its best to use this than to add another JS file.
317
-		 */
318
-		public function inline_script() {
319
-			// Flatpickr calendar locale
320
-			$flatpickr_locale = self::flatpickr_locale();
321
-
322
-			ob_start();
323
-			?>
322
+            ob_start();
323
+            ?>
324 324
 			<script>
325 325
 				/**
326 326
 				 * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ).
@@ -985,29 +985,29 @@  discard block
 block discarded – undo
985 985
 
986 986
 			</script>
987 987
 			<?php
988
-			$output = ob_get_clean();
988
+            $output = ob_get_clean();
989 989
 
990 990
 
991 991
 
992
-			/*
992
+            /*
993 993
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
994 994
 			 */
995
-			return str_replace( array(
996
-				'<script>',
997
-				'</script>'
998
-			), '', self::minify_js($output) );
999
-		}
1000
-
1001
-
1002
-		/**
1003
-		 * JS to help with conflict issues with other plugins and themes using bootstrap v3.
1004
-		 *
1005
-		 * @TODO we may need this when other conflicts arrise.
1006
-		 * @return mixed
1007
-		 */
1008
-		public static function bs3_compat_js() {
1009
-			ob_start();
1010
-			?>
995
+            return str_replace( array(
996
+                '<script>',
997
+                '</script>'
998
+            ), '', self::minify_js($output) );
999
+        }
1000
+
1001
+
1002
+        /**
1003
+         * JS to help with conflict issues with other plugins and themes using bootstrap v3.
1004
+         *
1005
+         * @TODO we may need this when other conflicts arrise.
1006
+         * @return mixed
1007
+         */
1008
+        public static function bs3_compat_js() {
1009
+            ob_start();
1010
+            ?>
1011 1011
 			<script>
1012 1012
 				<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1013 1013
 				/* With Avada builder */
@@ -1015,20 +1015,20 @@  discard block
 block discarded – undo
1015 1015
 				<?php } ?>
1016 1016
 			</script>
1017 1017
 			<?php
1018
-			return str_replace( array(
1019
-				'<script>',
1020
-				'</script>'
1021
-			), '', ob_get_clean());
1022
-		}
1023
-
1024
-		/**
1025
-		 * Get inline script used if bootstrap file browser enqueued.
1026
-		 *
1027
-		 * If this remains small then its best to use this than to add another JS file.
1028
-		 */
1029
-		public function inline_script_file_browser(){
1030
-			ob_start();
1031
-			?>
1018
+            return str_replace( array(
1019
+                '<script>',
1020
+                '</script>'
1021
+            ), '', ob_get_clean());
1022
+        }
1023
+
1024
+        /**
1025
+         * Get inline script used if bootstrap file browser enqueued.
1026
+         *
1027
+         * If this remains small then its best to use this than to add another JS file.
1028
+         */
1029
+        public function inline_script_file_browser(){
1030
+            ob_start();
1031
+            ?>
1032 1032
 			<script>
1033 1033
 				// run on doc ready
1034 1034
 				jQuery(document).ready(function () {
@@ -1036,192 +1036,192 @@  discard block
 block discarded – undo
1036 1036
 				});
1037 1037
 			</script>
1038 1038
 			<?php
1039
-			$output = ob_get_clean();
1039
+            $output = ob_get_clean();
1040 1040
 
1041
-			/*
1041
+            /*
1042 1042
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1043 1043
 			 */
1044
-			return str_replace( array(
1045
-				'<script>',
1046
-				'</script>'
1047
-			), '', $output );
1048
-		}
1049
-
1050
-		/**
1051
-		 * Adds the Font Awesome JS.
1052
-		 */
1053
-		public function enqueue_scripts() {
1054
-
1055
-			if( is_admin() && !$this->is_aui_screen()){
1056
-				// don't add wp-admin scripts if not requested to
1057
-			}else {
1058
-
1059
-				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1060
-
1061
-				// select2
1062
-				wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
1063
-
1064
-				// flatpickr
1065
-				wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
1066
-
1067
-				// Bootstrap file browser
1068
-				wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
1069
-				wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
1070
-
1071
-				$load_inline = false;
1072
-
1073
-				if ( $this->settings[ $js_setting ] == 'core-popper' ) {
1074
-					// Bootstrap bundle
1075
-					$url = $this->url . 'assets/js/bootstrap.bundle.min.js';
1076
-					wp_register_script( 'bootstrap-js-bundle', $url, array(
1077
-						'select2',
1078
-						'jquery'
1079
-					), $this->latest, $this->is_bs3_compat() );
1080
-					// if in admin then add to footer for compatibility.
1081
-					is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
1082
-					$script = $this->inline_script();
1083
-					wp_add_inline_script( 'bootstrap-js-bundle', $script );
1084
-				} elseif ( $this->settings[ $js_setting ] == 'popper' ) {
1085
-					$url = $this->url . 'assets/js/popper.min.js';
1086
-					wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
1087
-					wp_enqueue_script( 'bootstrap-js-popper' );
1088
-					$load_inline = true;
1089
-				} else {
1090
-					$load_inline = true;
1091
-				}
1092
-
1093
-				// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
1094
-				if ( $load_inline ) {
1095
-					wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
1096
-					wp_enqueue_script( 'bootstrap-dummy' );
1097
-					$script = $this->inline_script();
1098
-					wp_add_inline_script( 'bootstrap-dummy', $script );
1099
-				}
1100
-			}
1101
-
1102
-		}
1103
-
1104
-		/**
1105
-		 * Enqueue flatpickr if called.
1106
-		 */
1107
-		public function enqueue_flatpickr(){
1108
-			wp_enqueue_style( 'flatpickr' );
1109
-			wp_enqueue_script( 'flatpickr' );
1110
-		}
1111
-
1112
-		/**
1113
-		 * Get the url path to the current folder.
1114
-		 *
1115
-		 * @return string
1116
-		 */
1117
-		public function get_url() {
1118
-
1119
-			$url = '';
1120
-			// check if we are inside a plugin
1121
-			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
1122
-
1123
-			// add check in-case user has changed wp-content dir name.
1124
-			$wp_content_folder_name = basename(WP_CONTENT_DIR);
1125
-			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
1126
-			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
1127
-
1128
-			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
1129
-				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
1130
-			}
1131
-
1132
-			return $url;
1133
-		}
1134
-
1135
-		/**
1136
-		 * Register the database settings with WordPress.
1137
-		 */
1138
-		public function register_settings() {
1139
-			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
1140
-		}
1141
-
1142
-		/**
1143
-		 * Add the WordPress settings menu item.
1144
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
1145
-		 */
1146
-		public function menu_item() {
1147
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
1148
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1149
-				$this,
1150
-				'settings_page'
1151
-			) );
1152
-		}
1153
-
1154
-		/**
1155
-		 * Get a list of themes and their default JS settings.
1156
-		 *
1157
-		 * @return array
1158
-		 */
1159
-		public function theme_js_settings(){
1160
-			return array(
1161
-				'ayetheme' => 'popper',
1162
-				'listimia' => 'required',
1163
-				'listimia_backend' => 'core-popper',
1164
-				//'avada'    => 'required', // removed as we now add compatibility
1165
-			);
1166
-		}
1167
-
1168
-		/**
1169
-		 * Get the current Font Awesome output settings.
1170
-		 *
1171
-		 * @return array The array of settings.
1172
-		 */
1173
-		public function get_settings() {
1174
-
1175
-			$db_settings = get_option( 'ayecode-ui-settings' );
1176
-			$js_default = 'core-popper';
1177
-			$js_default_backend = $js_default;
1178
-
1179
-			// maybe set defaults (if no settings set)
1180
-			if(empty($db_settings)){
1181
-				$active_theme = strtolower( get_template() ); // active parent theme.
1182
-				$theme_js_settings = self::theme_js_settings();
1183
-				if(isset($theme_js_settings[$active_theme])){
1184
-					$js_default = $theme_js_settings[$active_theme];
1185
-					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1186
-				}
1187
-			}
1188
-
1189
-			$defaults = array(
1190
-				'css'       => 'compatibility', // core, compatibility
1191
-				'js'        => $js_default, // js to load, core-popper, popper
1192
-				'html_font_size'        => '16', // js to load, core-popper, popper
1193
-				'css_backend'       => 'compatibility', // core, compatibility
1194
-				'js_backend'        => $js_default_backend, // js to load, core-popper, popper
1195
-				'disable_admin'     =>  '', // URL snippets to disable loading on admin
1196
-			);
1197
-
1198
-			$settings = wp_parse_args( $db_settings, $defaults );
1199
-
1200
-			/**
1201
-			 * Filter the Bootstrap settings.
1202
-			 *
1203
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1204
-			 */
1205
-			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1206
-		}
1207
-
1044
+            return str_replace( array(
1045
+                '<script>',
1046
+                '</script>'
1047
+            ), '', $output );
1048
+        }
1049
+
1050
+        /**
1051
+         * Adds the Font Awesome JS.
1052
+         */
1053
+        public function enqueue_scripts() {
1054
+
1055
+            if( is_admin() && !$this->is_aui_screen()){
1056
+                // don't add wp-admin scripts if not requested to
1057
+            }else {
1058
+
1059
+                $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1060
+
1061
+                // select2
1062
+                wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
1063
+
1064
+                // flatpickr
1065
+                wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
1066
+
1067
+                // Bootstrap file browser
1068
+                wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
1069
+                wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
1070
+
1071
+                $load_inline = false;
1072
+
1073
+                if ( $this->settings[ $js_setting ] == 'core-popper' ) {
1074
+                    // Bootstrap bundle
1075
+                    $url = $this->url . 'assets/js/bootstrap.bundle.min.js';
1076
+                    wp_register_script( 'bootstrap-js-bundle', $url, array(
1077
+                        'select2',
1078
+                        'jquery'
1079
+                    ), $this->latest, $this->is_bs3_compat() );
1080
+                    // if in admin then add to footer for compatibility.
1081
+                    is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
1082
+                    $script = $this->inline_script();
1083
+                    wp_add_inline_script( 'bootstrap-js-bundle', $script );
1084
+                } elseif ( $this->settings[ $js_setting ] == 'popper' ) {
1085
+                    $url = $this->url . 'assets/js/popper.min.js';
1086
+                    wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
1087
+                    wp_enqueue_script( 'bootstrap-js-popper' );
1088
+                    $load_inline = true;
1089
+                } else {
1090
+                    $load_inline = true;
1091
+                }
1208 1092
 
1209
-		/**
1210
-		 * The settings page html output.
1211
-		 */
1212
-		public function settings_page() {
1213
-			if ( ! current_user_can( 'manage_options' ) ) {
1214
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1215
-			}
1216
-			?>
1093
+                // Load needed inline scripts by faking the loading of a script if the main script is not being loaded
1094
+                if ( $load_inline ) {
1095
+                    wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
1096
+                    wp_enqueue_script( 'bootstrap-dummy' );
1097
+                    $script = $this->inline_script();
1098
+                    wp_add_inline_script( 'bootstrap-dummy', $script );
1099
+                }
1100
+            }
1101
+
1102
+        }
1103
+
1104
+        /**
1105
+         * Enqueue flatpickr if called.
1106
+         */
1107
+        public function enqueue_flatpickr(){
1108
+            wp_enqueue_style( 'flatpickr' );
1109
+            wp_enqueue_script( 'flatpickr' );
1110
+        }
1111
+
1112
+        /**
1113
+         * Get the url path to the current folder.
1114
+         *
1115
+         * @return string
1116
+         */
1117
+        public function get_url() {
1118
+
1119
+            $url = '';
1120
+            // check if we are inside a plugin
1121
+            $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
1122
+
1123
+            // add check in-case user has changed wp-content dir name.
1124
+            $wp_content_folder_name = basename(WP_CONTENT_DIR);
1125
+            $dir_parts = explode("/$wp_content_folder_name/",$file_dir);
1126
+            $url_parts = explode("/$wp_content_folder_name/",plugins_url());
1127
+
1128
+            if(!empty($url_parts[0]) && !empty($dir_parts[1])){
1129
+                $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
1130
+            }
1131
+
1132
+            return $url;
1133
+        }
1134
+
1135
+        /**
1136
+         * Register the database settings with WordPress.
1137
+         */
1138
+        public function register_settings() {
1139
+            register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
1140
+        }
1141
+
1142
+        /**
1143
+         * Add the WordPress settings menu item.
1144
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
1145
+         */
1146
+        public function menu_item() {
1147
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
1148
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1149
+                $this,
1150
+                'settings_page'
1151
+            ) );
1152
+        }
1153
+
1154
+        /**
1155
+         * Get a list of themes and their default JS settings.
1156
+         *
1157
+         * @return array
1158
+         */
1159
+        public function theme_js_settings(){
1160
+            return array(
1161
+                'ayetheme' => 'popper',
1162
+                'listimia' => 'required',
1163
+                'listimia_backend' => 'core-popper',
1164
+                //'avada'    => 'required', // removed as we now add compatibility
1165
+            );
1166
+        }
1167
+
1168
+        /**
1169
+         * Get the current Font Awesome output settings.
1170
+         *
1171
+         * @return array The array of settings.
1172
+         */
1173
+        public function get_settings() {
1174
+
1175
+            $db_settings = get_option( 'ayecode-ui-settings' );
1176
+            $js_default = 'core-popper';
1177
+            $js_default_backend = $js_default;
1178
+
1179
+            // maybe set defaults (if no settings set)
1180
+            if(empty($db_settings)){
1181
+                $active_theme = strtolower( get_template() ); // active parent theme.
1182
+                $theme_js_settings = self::theme_js_settings();
1183
+                if(isset($theme_js_settings[$active_theme])){
1184
+                    $js_default = $theme_js_settings[$active_theme];
1185
+                    $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1186
+                }
1187
+            }
1188
+
1189
+            $defaults = array(
1190
+                'css'       => 'compatibility', // core, compatibility
1191
+                'js'        => $js_default, // js to load, core-popper, popper
1192
+                'html_font_size'        => '16', // js to load, core-popper, popper
1193
+                'css_backend'       => 'compatibility', // core, compatibility
1194
+                'js_backend'        => $js_default_backend, // js to load, core-popper, popper
1195
+                'disable_admin'     =>  '', // URL snippets to disable loading on admin
1196
+            );
1197
+
1198
+            $settings = wp_parse_args( $db_settings, $defaults );
1199
+
1200
+            /**
1201
+             * Filter the Bootstrap settings.
1202
+             *
1203
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1204
+             */
1205
+            return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1206
+        }
1207
+
1208
+
1209
+        /**
1210
+         * The settings page html output.
1211
+         */
1212
+        public function settings_page() {
1213
+            if ( ! current_user_can( 'manage_options' ) ) {
1214
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1215
+            }
1216
+            ?>
1217 1217
 			<div class="wrap">
1218 1218
 				<h1><?php echo $this->name; ?></h1>
1219 1219
 				<p><?php _e("Here you can adjust settings if you are having compatibility issues.",'aui');?></p>
1220 1220
 				<form method="post" action="options.php">
1221 1221
 					<?php
1222
-					settings_fields( 'ayecode-ui-settings' );
1223
-					do_settings_sections( 'ayecode-ui-settings' );
1224
-					?>
1222
+                    settings_fields( 'ayecode-ui-settings' );
1223
+                    do_settings_sections( 'ayecode-ui-settings' );
1224
+                    ?>
1225 1225
 
1226 1226
 					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
1227 1227
 					<table class="form-table wpbs-table-settings">
@@ -1301,60 +1301,60 @@  discard block
 block discarded – undo
1301 1301
 					</table>
1302 1302
 
1303 1303
 					<?php
1304
-					submit_button();
1305
-					?>
1304
+                    submit_button();
1305
+                    ?>
1306 1306
 				</form>
1307 1307
 
1308 1308
 				<div id="wpbs-version"><?php echo $this->version; ?></div>
1309 1309
 			</div>
1310 1310
 
1311 1311
 			<?php
1312
-		}
1313
-
1314
-		public function customizer_settings($wp_customize){
1315
-			$wp_customize->add_section('aui_settings', array(
1316
-				'title'    => __('AyeCode UI','aui'),
1317
-				'priority' => 120,
1318
-			));
1319
-
1320
-			//  =============================
1321
-			//  = Color Picker              =
1322
-			//  =============================
1323
-			$wp_customize->add_setting('aui_options[color_primary]', array(
1324
-				'default'           => AUI_PRIMARY_COLOR,
1325
-				'sanitize_callback' => 'sanitize_hex_color',
1326
-				'capability'        => 'edit_theme_options',
1327
-				'type'              => 'option',
1328
-				'transport'         => 'refresh',
1329
-			));
1330
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1331
-				'label'    => __('Primary Color','aui'),
1332
-				'section'  => 'aui_settings',
1333
-				'settings' => 'aui_options[color_primary]',
1334
-			)));
1335
-
1336
-			$wp_customize->add_setting('aui_options[color_secondary]', array(
1337
-				'default'           => '#6c757d',
1338
-				'sanitize_callback' => 'sanitize_hex_color',
1339
-				'capability'        => 'edit_theme_options',
1340
-				'type'              => 'option',
1341
-				'transport'         => 'refresh',
1342
-			));
1343
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1344
-				'label'    => __('Secondary Color','aui'),
1345
-				'section'  => 'aui_settings',
1346
-				'settings' => 'aui_options[color_secondary]',
1347
-			)));
1348
-		}
1349
-
1350
-		/**
1351
-		 * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1352
-		 *
1353
-		 * @return mixed
1354
-		 */
1355
-		public static function bs3_compat_css() {
1356
-			ob_start();
1357
-			?>
1312
+        }
1313
+
1314
+        public function customizer_settings($wp_customize){
1315
+            $wp_customize->add_section('aui_settings', array(
1316
+                'title'    => __('AyeCode UI','aui'),
1317
+                'priority' => 120,
1318
+            ));
1319
+
1320
+            //  =============================
1321
+            //  = Color Picker              =
1322
+            //  =============================
1323
+            $wp_customize->add_setting('aui_options[color_primary]', array(
1324
+                'default'           => AUI_PRIMARY_COLOR,
1325
+                'sanitize_callback' => 'sanitize_hex_color',
1326
+                'capability'        => 'edit_theme_options',
1327
+                'type'              => 'option',
1328
+                'transport'         => 'refresh',
1329
+            ));
1330
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1331
+                'label'    => __('Primary Color','aui'),
1332
+                'section'  => 'aui_settings',
1333
+                'settings' => 'aui_options[color_primary]',
1334
+            )));
1335
+
1336
+            $wp_customize->add_setting('aui_options[color_secondary]', array(
1337
+                'default'           => '#6c757d',
1338
+                'sanitize_callback' => 'sanitize_hex_color',
1339
+                'capability'        => 'edit_theme_options',
1340
+                'type'              => 'option',
1341
+                'transport'         => 'refresh',
1342
+            ));
1343
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1344
+                'label'    => __('Secondary Color','aui'),
1345
+                'section'  => 'aui_settings',
1346
+                'settings' => 'aui_options[color_secondary]',
1347
+            )));
1348
+        }
1349
+
1350
+        /**
1351
+         * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1352
+         *
1353
+         * @return mixed
1354
+         */
1355
+        public static function bs3_compat_css() {
1356
+            ob_start();
1357
+            ?>
1358 1358
 			<style>
1359 1359
 			/* Bootstrap 3 compatibility */
1360 1360
 			body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;}
@@ -1380,579 +1380,579 @@  discard block
 block discarded – undo
1380 1380
 			<?php } ?>
1381 1381
 			</style>
1382 1382
 			<?php
1383
-			return str_replace( array(
1384
-				'<style>',
1385
-				'</style>'
1386
-			), '', self::minify_css( ob_get_clean() ) );
1387
-		}
1383
+            return str_replace( array(
1384
+                '<style>',
1385
+                '</style>'
1386
+            ), '', self::minify_css( ob_get_clean() ) );
1387
+        }
1388 1388
 
1389 1389
 
1390
-		public static function custom_css($compatibility = true) {
1391
-			$settings = get_option('aui_options');
1390
+        public static function custom_css($compatibility = true) {
1391
+            $settings = get_option('aui_options');
1392 1392
 
1393
-			ob_start();
1393
+            ob_start();
1394 1394
 
1395
-			$primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR;
1396
-			$secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR;
1397
-				//AUI_PRIMARY_COLOR_ORIGINAL
1398
-			?>
1395
+            $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR;
1396
+            $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR;
1397
+                //AUI_PRIMARY_COLOR_ORIGINAL
1398
+            ?>
1399 1399
 			<style>
1400 1400
 				<?php
1401 1401
 
1402
-					// BS v3 compat
1403
-					if( self::is_bs3_compat() ){
1404
-					    echo self::bs3_compat_css();
1405
-					}
1402
+                    // BS v3 compat
1403
+                    if( self::is_bs3_compat() ){
1404
+                        echo self::bs3_compat_css();
1405
+                    }
1406 1406
 
1407
-					if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1408
-						echo self::css_primary($primary_color,$compatibility);
1409
-					}
1407
+                    if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1408
+                        echo self::css_primary($primary_color,$compatibility);
1409
+                    }
1410 1410
 
1411
-					if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1412
-						echo self::css_secondary($settings['color_secondary'],$compatibility);
1413
-					}
1411
+                    if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1412
+                        echo self::css_secondary($settings['color_secondary'],$compatibility);
1413
+                    }
1414 1414
 
1415
-					// Set admin bar z-index lower when modal is open.
1416
-					echo ' body.modal-open #wpadminbar{z-index:999}';
1415
+                    // Set admin bar z-index lower when modal is open.
1416
+                    echo ' body.modal-open #wpadminbar{z-index:999}';
1417 1417
                 ?>
1418 1418
 			</style>
1419 1419
 			<?php
1420 1420
 
1421 1421
 
1422
-			/*
1422
+            /*
1423 1423
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1424 1424
 			 */
1425
-			return str_replace( array(
1426
-				'<style>',
1427
-				'</style>'
1428
-			), '', self::minify_css( ob_get_clean() ) );
1429
-		}
1430
-
1431
-		/**
1432
-		 * Check if we should add booststrap 3 compatibility changes.
1433
-		 *
1434
-		 * @return bool
1435
-		 */
1436
-		public static function is_bs3_compat(){
1437
-			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1438
-		}
1439
-
1440
-		public static function css_primary($color_code,$compatibility){;
1441
-			$color_code = sanitize_hex_color($color_code);
1442
-			if(!$color_code){return '';}
1443
-			/**
1444
-			 * c = color, b = background color, o = border-color, f = fill
1445
-			 */
1446
-			$selectors = array(
1447
-				'a' => array('c'),
1448
-				'.btn-primary' => array('b','o'),
1449
-				'.btn-primary.disabled' => array('b','o'),
1450
-				'.btn-primary:disabled' => array('b','o'),
1451
-				'.btn-outline-primary' => array('c','o'),
1452
-				'.btn-outline-primary:hover' => array('b','o'),
1453
-				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1454
-				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1455
-				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1456
-				'.btn-link' => array('c'),
1457
-				'.dropdown-item.active' => array('b'),
1458
-				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1459
-				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1425
+            return str_replace( array(
1426
+                '<style>',
1427
+                '</style>'
1428
+            ), '', self::minify_css( ob_get_clean() ) );
1429
+        }
1430
+
1431
+        /**
1432
+         * Check if we should add booststrap 3 compatibility changes.
1433
+         *
1434
+         * @return bool
1435
+         */
1436
+        public static function is_bs3_compat(){
1437
+            return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1438
+        }
1439
+
1440
+        public static function css_primary($color_code,$compatibility){;
1441
+            $color_code = sanitize_hex_color($color_code);
1442
+            if(!$color_code){return '';}
1443
+            /**
1444
+             * c = color, b = background color, o = border-color, f = fill
1445
+             */
1446
+            $selectors = array(
1447
+                'a' => array('c'),
1448
+                '.btn-primary' => array('b','o'),
1449
+                '.btn-primary.disabled' => array('b','o'),
1450
+                '.btn-primary:disabled' => array('b','o'),
1451
+                '.btn-outline-primary' => array('c','o'),
1452
+                '.btn-outline-primary:hover' => array('b','o'),
1453
+                '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1454
+                '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1455
+                '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1456
+                '.btn-link' => array('c'),
1457
+                '.dropdown-item.active' => array('b'),
1458
+                '.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1459
+                '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1460 1460
 //				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1461 1461
 //				'.custom-range::-moz-range-thumb' => array('b'),
1462 1462
 //				'.custom-range::-ms-thumb' => array('b'),
1463
-				'.nav-pills .nav-link.active' => array('b'),
1464
-				'.nav-pills .show>.nav-link' => array('b'),
1465
-				'.page-link' => array('c'),
1466
-				'.page-item.active .page-link' => array('b','o'),
1467
-				'.badge-primary' => array('b'),
1468
-				'.alert-primary' => array('b','o'),
1469
-				'.progress-bar' => array('b'),
1470
-				'.list-group-item.active' => array('b','o'),
1471
-				'.bg-primary' => array('b','f'),
1472
-				'.btn-link.btn-primary' => array('c'),
1473
-				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1474
-			);
1475
-
1476
-			$important_selectors = array(
1477
-				'.bg-primary' => array('b','f'),
1478
-				'.border-primary' => array('o'),
1479
-				'.text-primary' => array('c'),
1480
-			);
1481
-
1482
-			$color = array();
1483
-			$color_i = array();
1484
-			$background = array();
1485
-			$background_i = array();
1486
-			$border = array();
1487
-			$border_i = array();
1488
-			$fill = array();
1489
-			$fill_i = array();
1490
-
1491
-			$output = '';
1492
-
1493
-			// build rules into each type
1494
-			foreach($selectors as $selector => $types){
1495
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1496
-				$types = array_combine($types,$types);
1497
-				if(isset($types['c'])){$color[] = $selector;}
1498
-				if(isset($types['b'])){$background[] = $selector;}
1499
-				if(isset($types['o'])){$border[] = $selector;}
1500
-				if(isset($types['f'])){$fill[] = $selector;}
1501
-			}
1502
-
1503
-			// build rules into each type
1504
-			foreach($important_selectors as $selector => $types){
1505
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1506
-				$types = array_combine($types,$types);
1507
-				if(isset($types['c'])){$color_i[] = $selector;}
1508
-				if(isset($types['b'])){$background_i[] = $selector;}
1509
-				if(isset($types['o'])){$border_i[] = $selector;}
1510
-				if(isset($types['f'])){$fill_i[] = $selector;}
1511
-			}
1512
-
1513
-			// add any color rules
1514
-			if(!empty($color)){
1515
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1516
-			}
1517
-			if(!empty($color_i)){
1518
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1519
-			}
1520
-
1521
-			// add any background color rules
1522
-			if(!empty($background)){
1523
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1524
-			}
1525
-			if(!empty($background_i)){
1526
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1527
-			}
1528
-
1529
-			// add any border color rules
1530
-			if(!empty($border)){
1531
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1532
-			}
1533
-			if(!empty($border_i)){
1534
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1535
-			}
1536
-
1537
-			// add any fill color rules
1538
-			if(!empty($fill)){
1539
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1540
-			}
1541
-			if(!empty($fill_i)){
1542
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1543
-			}
1544
-
1545
-
1546
-			$prefix = $compatibility ? ".bsui " : "";
1547
-
1548
-			// darken
1549
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1550
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1551
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1552
-
1553
-			// lighten
1554
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1555
-
1556
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1557
-			$op_25 = $color_code."40"; // 25% opacity
1558
-
1559
-
1560
-			// button states
1561
-			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1562
-			$output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1563
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1564
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1565
-
1566
-
1567
-			// dropdown's
1568
-			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1569
-
1570
-
1571
-			// input states
1572
-			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1573
-
1574
-			// page link
1575
-			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1576
-
1577
-			return $output;
1578
-		}
1579
-
1580
-		public static function css_secondary($color_code,$compatibility){;
1581
-			$color_code = sanitize_hex_color($color_code);
1582
-			if(!$color_code){return '';}
1583
-			/**
1584
-			 * c = color, b = background color, o = border-color, f = fill
1585
-			 */
1586
-			$selectors = array(
1587
-				'.btn-secondary' => array('b','o'),
1588
-				'.btn-secondary.disabled' => array('b','o'),
1589
-				'.btn-secondary:disabled' => array('b','o'),
1590
-				'.btn-outline-secondary' => array('c','o'),
1591
-				'.btn-outline-secondary:hover' => array('b','o'),
1592
-				'.btn-outline-secondary.disabled' => array('c'),
1593
-				'.btn-outline-secondary:disabled' => array('c'),
1594
-				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1595
-				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1596
-				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1597
-				'.badge-secondary' => array('b'),
1598
-				'.alert-secondary' => array('b','o'),
1599
-				'.btn-link.btn-secondary' => array('c'),
1600
-			);
1601
-
1602
-			$important_selectors = array(
1603
-				'.bg-secondary' => array('b','f'),
1604
-				'.border-secondary' => array('o'),
1605
-				'.text-secondary' => array('c'),
1606
-			);
1607
-
1608
-			$color = array();
1609
-			$color_i = array();
1610
-			$background = array();
1611
-			$background_i = array();
1612
-			$border = array();
1613
-			$border_i = array();
1614
-			$fill = array();
1615
-			$fill_i = array();
1616
-
1617
-			$output = '';
1618
-
1619
-			// build rules into each type
1620
-			foreach($selectors as $selector => $types){
1621
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1622
-				$types = array_combine($types,$types);
1623
-				if(isset($types['c'])){$color[] = $selector;}
1624
-				if(isset($types['b'])){$background[] = $selector;}
1625
-				if(isset($types['o'])){$border[] = $selector;}
1626
-				if(isset($types['f'])){$fill[] = $selector;}
1627
-			}
1628
-
1629
-			// build rules into each type
1630
-			foreach($important_selectors as $selector => $types){
1631
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1632
-				$types = array_combine($types,$types);
1633
-				if(isset($types['c'])){$color_i[] = $selector;}
1634
-				if(isset($types['b'])){$background_i[] = $selector;}
1635
-				if(isset($types['o'])){$border_i[] = $selector;}
1636
-				if(isset($types['f'])){$fill_i[] = $selector;}
1637
-			}
1638
-
1639
-			// add any color rules
1640
-			if(!empty($color)){
1641
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1642
-			}
1643
-			if(!empty($color_i)){
1644
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1645
-			}
1646
-
1647
-			// add any background color rules
1648
-			if(!empty($background)){
1649
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1650
-			}
1651
-			if(!empty($background_i)){
1652
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1653
-			}
1654
-
1655
-			// add any border color rules
1656
-			if(!empty($border)){
1657
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1658
-			}
1659
-			if(!empty($border_i)){
1660
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1661
-			}
1662
-
1663
-			// add any fill color rules
1664
-			if(!empty($fill)){
1665
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1666
-			}
1667
-			if(!empty($fill_i)){
1668
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1669
-			}
1670
-
1671
-
1672
-			$prefix = $compatibility ? ".bsui " : "";
1673
-
1674
-			// darken
1675
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1676
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1677
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1678
-
1679
-			// lighten
1680
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1681
-
1682
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1683
-			$op_25 = $color_code."40"; // 25% opacity
1684
-
1685
-
1686
-			// button states
1687
-			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1688
-			$output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1689
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1690
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1691
-
1692
-
1693
-			return $output;
1694
-		}
1695
-
1696
-		/**
1697
-		 * Increases or decreases the brightness of a color by a percentage of the current brightness.
1698
-		 *
1699
-		 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1700
-		 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1701
-		 *
1702
-		 * @return  string
1703
-		 */
1704
-		public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1705
-			$hexCode = ltrim($hexCode, '#');
1706
-
1707
-			if (strlen($hexCode) == 3) {
1708
-				$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1709
-			}
1710
-
1711
-			$hexCode = array_map('hexdec', str_split($hexCode, 2));
1712
-
1713
-			foreach ($hexCode as & $color) {
1714
-				$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1715
-				$adjustAmount = ceil($adjustableLimit * $adjustPercent);
1716
-
1717
-				$color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1718
-			}
1719
-
1720
-			return '#' . implode($hexCode);
1721
-		}
1722
-
1723
-		/**
1724
-		 * Check if we should display examples.
1725
-		 */
1726
-		public function maybe_show_examples(){
1727
-			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1728
-				echo "<head>";
1729
-				wp_head();
1730
-				echo "</head>";
1731
-				echo "<body>";
1732
-				echo $this->get_examples();
1733
-				echo "</body>";
1734
-				exit;
1735
-			}
1736
-		}
1737
-
1738
-		/**
1739
-		 * Get developer examples.
1740
-		 *
1741
-		 * @return string
1742
-		 */
1743
-		public function get_examples(){
1744
-			$output = '';
1745
-
1746
-
1747
-			// open form
1748
-			$output .= "<form class='p-5 m-5 border rounded'>";
1749
-
1750
-			// input example
1751
-			$output .= aui()->input(array(
1752
-				'type'  =>  'text',
1753
-				'id'    =>  'text-example',
1754
-				'name'    =>  'text-example',
1755
-				'placeholder'   => 'text placeholder',
1756
-				'title'   => 'Text input example',
1757
-				'value' =>  '',
1758
-				'required'  => false,
1759
-				'help_text' => 'help text',
1760
-				'label' => 'Text input example label'
1761
-			));
1762
-
1763
-			// input example
1764
-			$output .= aui()->input(array(
1765
-				'type'  =>  'url',
1766
-				'id'    =>  'text-example2',
1767
-				'name'    =>  'text-example',
1768
-				'placeholder'   => 'url placeholder',
1769
-				'title'   => 'Text input example',
1770
-				'value' =>  '',
1771
-				'required'  => false,
1772
-				'help_text' => 'help text',
1773
-				'label' => 'Text input example label'
1774
-			));
1775
-
1776
-			// checkbox example
1777
-			$output .= aui()->input(array(
1778
-				'type'  =>  'checkbox',
1779
-				'id'    =>  'checkbox-example',
1780
-				'name'    =>  'checkbox-example',
1781
-				'placeholder'   => 'checkbox-example',
1782
-				'title'   => 'Checkbox example',
1783
-				'value' =>  '1',
1784
-				'checked'   => true,
1785
-				'required'  => false,
1786
-				'help_text' => 'help text',
1787
-				'label' => 'Checkbox checked'
1788
-			));
1789
-
1790
-			// checkbox example
1791
-			$output .= aui()->input(array(
1792
-				'type'  =>  'checkbox',
1793
-				'id'    =>  'checkbox-example2',
1794
-				'name'    =>  'checkbox-example2',
1795
-				'placeholder'   => 'checkbox-example',
1796
-				'title'   => 'Checkbox example',
1797
-				'value' =>  '1',
1798
-				'checked'   => false,
1799
-				'required'  => false,
1800
-				'help_text' => 'help text',
1801
-				'label' => 'Checkbox un-checked'
1802
-			));
1803
-
1804
-			// switch example
1805
-			$output .= aui()->input(array(
1806
-				'type'  =>  'checkbox',
1807
-				'id'    =>  'switch-example',
1808
-				'name'    =>  'switch-example',
1809
-				'placeholder'   => 'checkbox-example',
1810
-				'title'   => 'Switch example',
1811
-				'value' =>  '1',
1812
-				'checked'   => true,
1813
-				'switch'    => true,
1814
-				'required'  => false,
1815
-				'help_text' => 'help text',
1816
-				'label' => 'Switch on'
1817
-			));
1818
-
1819
-			// switch example
1820
-			$output .= aui()->input(array(
1821
-				'type'  =>  'checkbox',
1822
-				'id'    =>  'switch-example2',
1823
-				'name'    =>  'switch-example2',
1824
-				'placeholder'   => 'checkbox-example',
1825
-				'title'   => 'Switch example',
1826
-				'value' =>  '1',
1827
-				'checked'   => false,
1828
-				'switch'    => true,
1829
-				'required'  => false,
1830
-				'help_text' => 'help text',
1831
-				'label' => 'Switch off'
1832
-			));
1833
-
1834
-			// close form
1835
-			$output .= "</form>";
1836
-
1837
-			return $output;
1838
-		}
1839
-
1840
-		/**
1841
-		 * Calendar params.
1842
-		 *
1843
-		 * @since 0.1.44
1844
-		 *
1845
-		 * @return array Calendar params.
1846
-		 */
1847
-		public static function calendar_params() {
1848
-			$params = array(
1849
-				'month_long_1' => __( 'January', 'aui' ),
1850
-				'month_long_2' => __( 'February', 'aui' ),
1851
-				'month_long_3' => __( 'March', 'aui' ),
1852
-				'month_long_4' => __( 'April', 'aui' ),
1853
-				'month_long_5' => __( 'May', 'aui' ),
1854
-				'month_long_6' => __( 'June', 'aui' ),
1855
-				'month_long_7' => __( 'July', 'aui' ),
1856
-				'month_long_8' => __( 'August', 'aui' ),
1857
-				'month_long_9' => __( 'September', 'aui' ),
1858
-				'month_long_10' => __( 'October', 'aui' ),
1859
-				'month_long_11' => __( 'November', 'aui' ),
1860
-				'month_long_12' => __( 'December', 'aui' ),
1861
-				'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ),
1862
-				'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ),
1863
-				'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ),
1864
-				'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ),
1865
-				'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ),
1866
-				'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ),
1867
-				'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ),
1868
-				'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ),
1869
-				'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ),
1870
-				'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ),
1871
-				'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ),
1872
-				'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ),
1873
-				'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ),
1874
-				'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ),
1875
-				'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ),
1876
-				'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ),
1877
-				'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ),
1878
-				'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ),
1879
-				'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ),
1880
-				'day_s2_1' => __( 'Su', 'aui' ),
1881
-				'day_s2_2' => __( 'Mo', 'aui' ),
1882
-				'day_s2_3' => __( 'Tu', 'aui' ),
1883
-				'day_s2_4' => __( 'We', 'aui' ),
1884
-				'day_s2_5' => __( 'Th', 'aui' ),
1885
-				'day_s2_6' => __( 'Fr', 'aui' ),
1886
-				'day_s2_7' => __( 'Sa', 'aui' ),
1887
-				'day_s3_1' => __( 'Sun', 'aui' ),
1888
-				'day_s3_2' => __( 'Mon', 'aui' ),
1889
-				'day_s3_3' => __( 'Tue', 'aui' ),
1890
-				'day_s3_4' => __( 'Wed', 'aui' ),
1891
-				'day_s3_5' => __( 'Thu', 'aui' ),
1892
-				'day_s3_6' => __( 'Fri', 'aui' ),
1893
-				'day_s3_7' => __( 'Sat', 'aui' ),
1894
-				'day_s5_1' => __( 'Sunday', 'aui' ),
1895
-				'day_s5_2' => __( 'Monday', 'aui' ),
1896
-				'day_s5_3' => __( 'Tuesday', 'aui' ),
1897
-				'day_s5_4' => __( 'Wednesday', 'aui' ),
1898
-				'day_s5_5' => __( 'Thursday', 'aui' ),
1899
-				'day_s5_6' => __( 'Friday', 'aui' ),
1900
-				'day_s5_7' => __( 'Saturday', 'aui' ),
1901
-				'am_lower' => __( 'am', 'aui' ),
1902
-				'pm_lower' => __( 'pm', 'aui' ),
1903
-				'am_upper' => __( 'AM', 'aui' ),
1904
-				'pm_upper' => __( 'PM', 'aui' ),
1905
-				'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
1906
-				'time_24hr' => false,
1907
-				'year' => __( 'Year', 'aui' ),
1908
-				'hour' => __( 'Hour', 'aui' ),
1909
-				'minute' => __( 'Minute', 'aui' ),
1910
-				'weekAbbreviation' => __( 'Wk', 'aui' ),
1911
-				'rangeSeparator' => __( ' to ', 'aui' ),
1912
-				'scrollTitle' => __( 'Scroll to increment', 'aui' ),
1913
-				'toggleTitle' => __( 'Click to toggle', 'aui' )
1914
-			);
1915
-
1916
-			return apply_filters( 'ayecode_ui_calendar_params', $params );
1917
-		}
1918
-
1919
-		/**
1920
-		 * Flatpickr calendar localize.
1921
-		 *
1922
-		 * @since 0.1.44
1923
-		 *
1924
-		 * @return string Calendar locale.
1925
-		 */
1926
-		public static function flatpickr_locale() {
1927
-			$params = self::calendar_params();
1928
-
1929
-			if ( is_string( $params ) ) {
1930
-				$params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
1931
-			} else {
1932
-				foreach ( (array) $params as $key => $value ) {
1933
-					if ( ! is_scalar( $value ) ) {
1934
-						continue;
1935
-					}
1936
-
1937
-					$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
1938
-				}
1939
-			}
1463
+                '.nav-pills .nav-link.active' => array('b'),
1464
+                '.nav-pills .show>.nav-link' => array('b'),
1465
+                '.page-link' => array('c'),
1466
+                '.page-item.active .page-link' => array('b','o'),
1467
+                '.badge-primary' => array('b'),
1468
+                '.alert-primary' => array('b','o'),
1469
+                '.progress-bar' => array('b'),
1470
+                '.list-group-item.active' => array('b','o'),
1471
+                '.bg-primary' => array('b','f'),
1472
+                '.btn-link.btn-primary' => array('c'),
1473
+                '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1474
+            );
1475
+
1476
+            $important_selectors = array(
1477
+                '.bg-primary' => array('b','f'),
1478
+                '.border-primary' => array('o'),
1479
+                '.text-primary' => array('c'),
1480
+            );
1481
+
1482
+            $color = array();
1483
+            $color_i = array();
1484
+            $background = array();
1485
+            $background_i = array();
1486
+            $border = array();
1487
+            $border_i = array();
1488
+            $fill = array();
1489
+            $fill_i = array();
1490
+
1491
+            $output = '';
1492
+
1493
+            // build rules into each type
1494
+            foreach($selectors as $selector => $types){
1495
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1496
+                $types = array_combine($types,$types);
1497
+                if(isset($types['c'])){$color[] = $selector;}
1498
+                if(isset($types['b'])){$background[] = $selector;}
1499
+                if(isset($types['o'])){$border[] = $selector;}
1500
+                if(isset($types['f'])){$fill[] = $selector;}
1501
+            }
1502
+
1503
+            // build rules into each type
1504
+            foreach($important_selectors as $selector => $types){
1505
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1506
+                $types = array_combine($types,$types);
1507
+                if(isset($types['c'])){$color_i[] = $selector;}
1508
+                if(isset($types['b'])){$background_i[] = $selector;}
1509
+                if(isset($types['o'])){$border_i[] = $selector;}
1510
+                if(isset($types['f'])){$fill_i[] = $selector;}
1511
+            }
1512
+
1513
+            // add any color rules
1514
+            if(!empty($color)){
1515
+                $output .= implode(",",$color) . "{color: $color_code;} ";
1516
+            }
1517
+            if(!empty($color_i)){
1518
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1519
+            }
1520
+
1521
+            // add any background color rules
1522
+            if(!empty($background)){
1523
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1524
+            }
1525
+            if(!empty($background_i)){
1526
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1527
+            }
1528
+
1529
+            // add any border color rules
1530
+            if(!empty($border)){
1531
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1532
+            }
1533
+            if(!empty($border_i)){
1534
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1535
+            }
1536
+
1537
+            // add any fill color rules
1538
+            if(!empty($fill)){
1539
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1540
+            }
1541
+            if(!empty($fill_i)){
1542
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1543
+            }
1544
+
1545
+
1546
+            $prefix = $compatibility ? ".bsui " : "";
1547
+
1548
+            // darken
1549
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1550
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1551
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1552
+
1553
+            // lighten
1554
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1555
+
1556
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1557
+            $op_25 = $color_code."40"; // 25% opacity
1558
+
1559
+
1560
+            // button states
1561
+            $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1562
+            $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1563
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1564
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1565
+
1566
+
1567
+            // dropdown's
1568
+            $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1569
+
1570
+
1571
+            // input states
1572
+            $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1573
+
1574
+            // page link
1575
+            $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1576
+
1577
+            return $output;
1578
+        }
1579
+
1580
+        public static function css_secondary($color_code,$compatibility){;
1581
+            $color_code = sanitize_hex_color($color_code);
1582
+            if(!$color_code){return '';}
1583
+            /**
1584
+             * c = color, b = background color, o = border-color, f = fill
1585
+             */
1586
+            $selectors = array(
1587
+                '.btn-secondary' => array('b','o'),
1588
+                '.btn-secondary.disabled' => array('b','o'),
1589
+                '.btn-secondary:disabled' => array('b','o'),
1590
+                '.btn-outline-secondary' => array('c','o'),
1591
+                '.btn-outline-secondary:hover' => array('b','o'),
1592
+                '.btn-outline-secondary.disabled' => array('c'),
1593
+                '.btn-outline-secondary:disabled' => array('c'),
1594
+                '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1595
+                '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1596
+                '.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1597
+                '.badge-secondary' => array('b'),
1598
+                '.alert-secondary' => array('b','o'),
1599
+                '.btn-link.btn-secondary' => array('c'),
1600
+            );
1601
+
1602
+            $important_selectors = array(
1603
+                '.bg-secondary' => array('b','f'),
1604
+                '.border-secondary' => array('o'),
1605
+                '.text-secondary' => array('c'),
1606
+            );
1607
+
1608
+            $color = array();
1609
+            $color_i = array();
1610
+            $background = array();
1611
+            $background_i = array();
1612
+            $border = array();
1613
+            $border_i = array();
1614
+            $fill = array();
1615
+            $fill_i = array();
1616
+
1617
+            $output = '';
1618
+
1619
+            // build rules into each type
1620
+            foreach($selectors as $selector => $types){
1621
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1622
+                $types = array_combine($types,$types);
1623
+                if(isset($types['c'])){$color[] = $selector;}
1624
+                if(isset($types['b'])){$background[] = $selector;}
1625
+                if(isset($types['o'])){$border[] = $selector;}
1626
+                if(isset($types['f'])){$fill[] = $selector;}
1627
+            }
1628
+
1629
+            // build rules into each type
1630
+            foreach($important_selectors as $selector => $types){
1631
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1632
+                $types = array_combine($types,$types);
1633
+                if(isset($types['c'])){$color_i[] = $selector;}
1634
+                if(isset($types['b'])){$background_i[] = $selector;}
1635
+                if(isset($types['o'])){$border_i[] = $selector;}
1636
+                if(isset($types['f'])){$fill_i[] = $selector;}
1637
+            }
1638
+
1639
+            // add any color rules
1640
+            if(!empty($color)){
1641
+                $output .= implode(",",$color) . "{color: $color_code;} ";
1642
+            }
1643
+            if(!empty($color_i)){
1644
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1645
+            }
1646
+
1647
+            // add any background color rules
1648
+            if(!empty($background)){
1649
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1650
+            }
1651
+            if(!empty($background_i)){
1652
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1653
+            }
1654
+
1655
+            // add any border color rules
1656
+            if(!empty($border)){
1657
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1658
+            }
1659
+            if(!empty($border_i)){
1660
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1661
+            }
1662
+
1663
+            // add any fill color rules
1664
+            if(!empty($fill)){
1665
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1666
+            }
1667
+            if(!empty($fill_i)){
1668
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1669
+            }
1670
+
1671
+
1672
+            $prefix = $compatibility ? ".bsui " : "";
1673
+
1674
+            // darken
1675
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1676
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1677
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1678
+
1679
+            // lighten
1680
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1681
+
1682
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1683
+            $op_25 = $color_code."40"; // 25% opacity
1684
+
1685
+
1686
+            // button states
1687
+            $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1688
+            $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1689
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1690
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1691
+
1692
+
1693
+            return $output;
1694
+        }
1695
+
1696
+        /**
1697
+         * Increases or decreases the brightness of a color by a percentage of the current brightness.
1698
+         *
1699
+         * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1700
+         * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1701
+         *
1702
+         * @return  string
1703
+         */
1704
+        public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1705
+            $hexCode = ltrim($hexCode, '#');
1706
+
1707
+            if (strlen($hexCode) == 3) {
1708
+                $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1709
+            }
1710
+
1711
+            $hexCode = array_map('hexdec', str_split($hexCode, 2));
1712
+
1713
+            foreach ($hexCode as & $color) {
1714
+                $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1715
+                $adjustAmount = ceil($adjustableLimit * $adjustPercent);
1716
+
1717
+                $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1718
+            }
1719
+
1720
+            return '#' . implode($hexCode);
1721
+        }
1722
+
1723
+        /**
1724
+         * Check if we should display examples.
1725
+         */
1726
+        public function maybe_show_examples(){
1727
+            if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1728
+                echo "<head>";
1729
+                wp_head();
1730
+                echo "</head>";
1731
+                echo "<body>";
1732
+                echo $this->get_examples();
1733
+                echo "</body>";
1734
+                exit;
1735
+            }
1736
+        }
1737
+
1738
+        /**
1739
+         * Get developer examples.
1740
+         *
1741
+         * @return string
1742
+         */
1743
+        public function get_examples(){
1744
+            $output = '';
1745
+
1746
+
1747
+            // open form
1748
+            $output .= "<form class='p-5 m-5 border rounded'>";
1749
+
1750
+            // input example
1751
+            $output .= aui()->input(array(
1752
+                'type'  =>  'text',
1753
+                'id'    =>  'text-example',
1754
+                'name'    =>  'text-example',
1755
+                'placeholder'   => 'text placeholder',
1756
+                'title'   => 'Text input example',
1757
+                'value' =>  '',
1758
+                'required'  => false,
1759
+                'help_text' => 'help text',
1760
+                'label' => 'Text input example label'
1761
+            ));
1762
+
1763
+            // input example
1764
+            $output .= aui()->input(array(
1765
+                'type'  =>  'url',
1766
+                'id'    =>  'text-example2',
1767
+                'name'    =>  'text-example',
1768
+                'placeholder'   => 'url placeholder',
1769
+                'title'   => 'Text input example',
1770
+                'value' =>  '',
1771
+                'required'  => false,
1772
+                'help_text' => 'help text',
1773
+                'label' => 'Text input example label'
1774
+            ));
1775
+
1776
+            // checkbox example
1777
+            $output .= aui()->input(array(
1778
+                'type'  =>  'checkbox',
1779
+                'id'    =>  'checkbox-example',
1780
+                'name'    =>  'checkbox-example',
1781
+                'placeholder'   => 'checkbox-example',
1782
+                'title'   => 'Checkbox example',
1783
+                'value' =>  '1',
1784
+                'checked'   => true,
1785
+                'required'  => false,
1786
+                'help_text' => 'help text',
1787
+                'label' => 'Checkbox checked'
1788
+            ));
1789
+
1790
+            // checkbox example
1791
+            $output .= aui()->input(array(
1792
+                'type'  =>  'checkbox',
1793
+                'id'    =>  'checkbox-example2',
1794
+                'name'    =>  'checkbox-example2',
1795
+                'placeholder'   => 'checkbox-example',
1796
+                'title'   => 'Checkbox example',
1797
+                'value' =>  '1',
1798
+                'checked'   => false,
1799
+                'required'  => false,
1800
+                'help_text' => 'help text',
1801
+                'label' => 'Checkbox un-checked'
1802
+            ));
1803
+
1804
+            // switch example
1805
+            $output .= aui()->input(array(
1806
+                'type'  =>  'checkbox',
1807
+                'id'    =>  'switch-example',
1808
+                'name'    =>  'switch-example',
1809
+                'placeholder'   => 'checkbox-example',
1810
+                'title'   => 'Switch example',
1811
+                'value' =>  '1',
1812
+                'checked'   => true,
1813
+                'switch'    => true,
1814
+                'required'  => false,
1815
+                'help_text' => 'help text',
1816
+                'label' => 'Switch on'
1817
+            ));
1818
+
1819
+            // switch example
1820
+            $output .= aui()->input(array(
1821
+                'type'  =>  'checkbox',
1822
+                'id'    =>  'switch-example2',
1823
+                'name'    =>  'switch-example2',
1824
+                'placeholder'   => 'checkbox-example',
1825
+                'title'   => 'Switch example',
1826
+                'value' =>  '1',
1827
+                'checked'   => false,
1828
+                'switch'    => true,
1829
+                'required'  => false,
1830
+                'help_text' => 'help text',
1831
+                'label' => 'Switch off'
1832
+            ));
1833
+
1834
+            // close form
1835
+            $output .= "</form>";
1836
+
1837
+            return $output;
1838
+        }
1839
+
1840
+        /**
1841
+         * Calendar params.
1842
+         *
1843
+         * @since 0.1.44
1844
+         *
1845
+         * @return array Calendar params.
1846
+         */
1847
+        public static function calendar_params() {
1848
+            $params = array(
1849
+                'month_long_1' => __( 'January', 'aui' ),
1850
+                'month_long_2' => __( 'February', 'aui' ),
1851
+                'month_long_3' => __( 'March', 'aui' ),
1852
+                'month_long_4' => __( 'April', 'aui' ),
1853
+                'month_long_5' => __( 'May', 'aui' ),
1854
+                'month_long_6' => __( 'June', 'aui' ),
1855
+                'month_long_7' => __( 'July', 'aui' ),
1856
+                'month_long_8' => __( 'August', 'aui' ),
1857
+                'month_long_9' => __( 'September', 'aui' ),
1858
+                'month_long_10' => __( 'October', 'aui' ),
1859
+                'month_long_11' => __( 'November', 'aui' ),
1860
+                'month_long_12' => __( 'December', 'aui' ),
1861
+                'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ),
1862
+                'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ),
1863
+                'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ),
1864
+                'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ),
1865
+                'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ),
1866
+                'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ),
1867
+                'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ),
1868
+                'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ),
1869
+                'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ),
1870
+                'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ),
1871
+                'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ),
1872
+                'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ),
1873
+                'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ),
1874
+                'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ),
1875
+                'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ),
1876
+                'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ),
1877
+                'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ),
1878
+                'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ),
1879
+                'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ),
1880
+                'day_s2_1' => __( 'Su', 'aui' ),
1881
+                'day_s2_2' => __( 'Mo', 'aui' ),
1882
+                'day_s2_3' => __( 'Tu', 'aui' ),
1883
+                'day_s2_4' => __( 'We', 'aui' ),
1884
+                'day_s2_5' => __( 'Th', 'aui' ),
1885
+                'day_s2_6' => __( 'Fr', 'aui' ),
1886
+                'day_s2_7' => __( 'Sa', 'aui' ),
1887
+                'day_s3_1' => __( 'Sun', 'aui' ),
1888
+                'day_s3_2' => __( 'Mon', 'aui' ),
1889
+                'day_s3_3' => __( 'Tue', 'aui' ),
1890
+                'day_s3_4' => __( 'Wed', 'aui' ),
1891
+                'day_s3_5' => __( 'Thu', 'aui' ),
1892
+                'day_s3_6' => __( 'Fri', 'aui' ),
1893
+                'day_s3_7' => __( 'Sat', 'aui' ),
1894
+                'day_s5_1' => __( 'Sunday', 'aui' ),
1895
+                'day_s5_2' => __( 'Monday', 'aui' ),
1896
+                'day_s5_3' => __( 'Tuesday', 'aui' ),
1897
+                'day_s5_4' => __( 'Wednesday', 'aui' ),
1898
+                'day_s5_5' => __( 'Thursday', 'aui' ),
1899
+                'day_s5_6' => __( 'Friday', 'aui' ),
1900
+                'day_s5_7' => __( 'Saturday', 'aui' ),
1901
+                'am_lower' => __( 'am', 'aui' ),
1902
+                'pm_lower' => __( 'pm', 'aui' ),
1903
+                'am_upper' => __( 'AM', 'aui' ),
1904
+                'pm_upper' => __( 'PM', 'aui' ),
1905
+                'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
1906
+                'time_24hr' => false,
1907
+                'year' => __( 'Year', 'aui' ),
1908
+                'hour' => __( 'Hour', 'aui' ),
1909
+                'minute' => __( 'Minute', 'aui' ),
1910
+                'weekAbbreviation' => __( 'Wk', 'aui' ),
1911
+                'rangeSeparator' => __( ' to ', 'aui' ),
1912
+                'scrollTitle' => __( 'Scroll to increment', 'aui' ),
1913
+                'toggleTitle' => __( 'Click to toggle', 'aui' )
1914
+            );
1915
+
1916
+            return apply_filters( 'ayecode_ui_calendar_params', $params );
1917
+        }
1918
+
1919
+        /**
1920
+         * Flatpickr calendar localize.
1921
+         *
1922
+         * @since 0.1.44
1923
+         *
1924
+         * @return string Calendar locale.
1925
+         */
1926
+        public static function flatpickr_locale() {
1927
+            $params = self::calendar_params();
1928
+
1929
+            if ( is_string( $params ) ) {
1930
+                $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
1931
+            } else {
1932
+                foreach ( (array) $params as $key => $value ) {
1933
+                    if ( ! is_scalar( $value ) ) {
1934
+                        continue;
1935
+                    }
1936
+
1937
+                    $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
1938
+                }
1939
+            }
1940 1940
 
1941
-			$day_s3 = array();
1942
-			$day_s5 = array();
1941
+            $day_s3 = array();
1942
+            $day_s5 = array();
1943 1943
 
1944
-			for ( $i = 1; $i <= 7; $i ++ ) {
1945
-				$day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
1946
-				$day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
1947
-			}
1944
+            for ( $i = 1; $i <= 7; $i ++ ) {
1945
+                $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
1946
+                $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
1947
+            }
1948 1948
 
1949
-			$month_s = array();
1950
-			$month_long = array();
1949
+            $month_s = array();
1950
+            $month_long = array();
1951 1951
 
1952
-			for ( $i = 1; $i <= 12; $i ++ ) {
1953
-				$month_s[] = addslashes( $params[ 'month_s_' . $i ] );
1954
-				$month_long[] = addslashes( $params[ 'month_long_' . $i ] );
1955
-			}
1952
+            for ( $i = 1; $i <= 12; $i ++ ) {
1953
+                $month_s[] = addslashes( $params[ 'month_s_' . $i ] );
1954
+                $month_long[] = addslashes( $params[ 'month_long_' . $i ] );
1955
+            }
1956 1956
 
1957 1957
 ob_start();
1958 1958
 if ( 0 ) { ?><script><?php } ?>
@@ -1994,184 +1994,184 @@  discard block
 block discarded – undo
1994 1994
 }
1995 1995
 <?php if ( 0 ) { ?></script><?php } ?>
1996 1996
 <?php
1997
-			$locale = ob_get_clean();
1998
-
1999
-			return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
2000
-		}
2001
-
2002
-		/**
2003
-		 * Select2 JS params.
2004
-		 *
2005
-		 * @since 0.1.44
2006
-		 *
2007
-		 * @return array Select2 JS params.
2008
-		 */
2009
-		public static function select2_params() {
2010
-			$params = array(
2011
-				'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'aui' ),
2012
-				'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'aui' ),
2013
-				'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'aui' ),
2014
-				'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ),
2015
-				'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ),
2016
-				'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'aui' ),
2017
-				'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ),
2018
-				'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ),
2019
-				'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ),
2020
-				'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'aui' ),
2021
-				'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'aui' )
2022
-			);
2023
-
2024
-			return apply_filters( 'ayecode_ui_select2_params', $params );
2025
-		}
2026
-
2027
-		/**
2028
-		 * Select2 JS localize.
2029
-		 *
2030
-		 * @since 0.1.44
2031
-		 *
2032
-		 * @return string Select2 JS locale.
2033
-		 */
2034
-		public static function select2_locale() {
2035
-			$params = self::select2_params();
2036
-
2037
-			foreach ( (array) $params as $key => $value ) {
2038
-				if ( ! is_scalar( $value ) ) {
2039
-					continue;
2040
-				}
2041
-
2042
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2043
-			}
2044
-
2045
-			$locale = json_encode( $params );
2046
-
2047
-			return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2048
-		}
2049
-
2050
-		/**
2051
-		 * Time ago JS localize.
2052
-		 *
2053
-		 * @since 0.1.47
2054
-		 *
2055
-		 * @return string Time ago JS locale.
2056
-		 */
2057
-		public static function timeago_locale() {
2058
-			$params = array(
2059
-				'prefix_ago' => '',
2060
-				'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ),
2061
-				'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ',
2062
-				'suffix_after' => '',
2063
-				'seconds' => _x( 'less than a minute', 'time ago', 'aui' ),
2064
-				'minute' => _x( 'about a minute', 'time ago', 'aui' ),
2065
-				'minutes' => _x( '%d minutes', 'time ago', 'aui' ),
2066
-				'hour' => _x( 'about an hour', 'time ago', 'aui' ),
2067
-				'hours' => _x( 'about %d hours', 'time ago', 'aui' ),
2068
-				'day' => _x( 'a day', 'time ago', 'aui' ),
2069
-				'days' => _x( '%d days', 'time ago', 'aui' ),
2070
-				'month' => _x( 'about a month', 'time ago', 'aui' ),
2071
-				'months' => _x( '%d months', 'time ago', 'aui' ),
2072
-				'year' => _x( 'about a year', 'time ago', 'aui' ),
2073
-				'years' => _x( '%d years', 'time ago', 'aui' ),
2074
-			);
2075
-
2076
-			$params = apply_filters( 'ayecode_ui_timeago_params', $params );
2077
-
2078
-			foreach ( (array) $params as $key => $value ) {
2079
-				if ( ! is_scalar( $value ) ) {
2080
-					continue;
2081
-				}
2082
-
2083
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2084
-			}
2085
-
2086
-			$locale = json_encode( $params );
2087
-
2088
-			return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) );
2089
-		}
2090
-
2091
-		/**
2092
-		 * JavaScript Minifier
2093
-		 *
2094
-		 * @param $input
2095
-		 *
2096
-		 * @return mixed
2097
-		 */
2098
-		public static function minify_js($input) {
2099
-			if(trim($input) === "") return $input;
2100
-			return preg_replace(
2101
-				array(
2102
-					// Remove comment(s)
2103
-					'#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
2104
-					// Remove white-space(s) outside the string and regex
2105
-					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
2106
-					// Remove the last semicolon
2107
-					'#;+\}#',
2108
-					// Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
2109
-					'#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
2110
-					// --ibid. From `foo['bar']` to `foo.bar`
2111
-					'#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
2112
-				),
2113
-				array(
2114
-					'$1',
2115
-					'$1$2',
2116
-					'}',
2117
-					'$1$3',
2118
-					'$1.$3'
2119
-				),
2120
-				$input);
2121
-		}
1997
+            $locale = ob_get_clean();
1998
+
1999
+            return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
2000
+        }
2001
+
2002
+        /**
2003
+         * Select2 JS params.
2004
+         *
2005
+         * @since 0.1.44
2006
+         *
2007
+         * @return array Select2 JS params.
2008
+         */
2009
+        public static function select2_params() {
2010
+            $params = array(
2011
+                'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'aui' ),
2012
+                'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'aui' ),
2013
+                'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'aui' ),
2014
+                'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ),
2015
+                'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ),
2016
+                'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'aui' ),
2017
+                'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ),
2018
+                'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ),
2019
+                'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ),
2020
+                'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'aui' ),
2021
+                'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'aui' )
2022
+            );
2023
+
2024
+            return apply_filters( 'ayecode_ui_select2_params', $params );
2025
+        }
2026
+
2027
+        /**
2028
+         * Select2 JS localize.
2029
+         *
2030
+         * @since 0.1.44
2031
+         *
2032
+         * @return string Select2 JS locale.
2033
+         */
2034
+        public static function select2_locale() {
2035
+            $params = self::select2_params();
2036
+
2037
+            foreach ( (array) $params as $key => $value ) {
2038
+                if ( ! is_scalar( $value ) ) {
2039
+                    continue;
2040
+                }
2122 2041
 
2123
-		/**
2124
-		 * Minify CSS
2125
-		 *
2126
-		 * @param $input
2127
-		 *
2128
-		 * @return mixed
2129
-		 */
2130
-		public static function minify_css($input) {
2131
-			if(trim($input) === "") return $input;
2132
-			return preg_replace(
2133
-				array(
2134
-					// Remove comment(s)
2135
-					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
2136
-					// Remove unused white-space(s)
2137
-					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
2138
-					// Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0`
2139
-					'#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
2140
-					// Replace `:0 0 0 0` with `:0`
2141
-					'#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
2142
-					// Replace `background-position:0` with `background-position:0 0`
2143
-					'#(background-position):0(?=[;\}])#si',
2144
-					// Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space
2145
-					'#(?<=[\s:,\-])0+\.(\d+)#s',
2146
-					// Minify string value
2147
-					'#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
2148
-					'#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si',
2149
-					// Minify HEX color code
2150
-					'#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
2151
-					// Replace `(border|outline):none` with `(border|outline):0`
2152
-					'#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
2153
-					// Remove empty selector(s)
2154
-					'#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
2155
-				),
2156
-				array(
2157
-					'$1',
2158
-					'$1$2$3$4$5$6$7',
2159
-					'$1',
2160
-					':0',
2161
-					'$1:0 0',
2162
-					'.$1',
2163
-					'$1$3',
2164
-					'$1$2$4$5',
2165
-					'$1$2$3',
2166
-					'$1:0',
2167
-					'$1$2'
2168
-				),
2169
-				$input);
2170
-		}
2171
-	}
2042
+                $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2043
+            }
2044
+
2045
+            $locale = json_encode( $params );
2046
+
2047
+            return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2048
+        }
2049
+
2050
+        /**
2051
+         * Time ago JS localize.
2052
+         *
2053
+         * @since 0.1.47
2054
+         *
2055
+         * @return string Time ago JS locale.
2056
+         */
2057
+        public static function timeago_locale() {
2058
+            $params = array(
2059
+                'prefix_ago' => '',
2060
+                'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ),
2061
+                'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ',
2062
+                'suffix_after' => '',
2063
+                'seconds' => _x( 'less than a minute', 'time ago', 'aui' ),
2064
+                'minute' => _x( 'about a minute', 'time ago', 'aui' ),
2065
+                'minutes' => _x( '%d minutes', 'time ago', 'aui' ),
2066
+                'hour' => _x( 'about an hour', 'time ago', 'aui' ),
2067
+                'hours' => _x( 'about %d hours', 'time ago', 'aui' ),
2068
+                'day' => _x( 'a day', 'time ago', 'aui' ),
2069
+                'days' => _x( '%d days', 'time ago', 'aui' ),
2070
+                'month' => _x( 'about a month', 'time ago', 'aui' ),
2071
+                'months' => _x( '%d months', 'time ago', 'aui' ),
2072
+                'year' => _x( 'about a year', 'time ago', 'aui' ),
2073
+                'years' => _x( '%d years', 'time ago', 'aui' ),
2074
+            );
2075
+
2076
+            $params = apply_filters( 'ayecode_ui_timeago_params', $params );
2077
+
2078
+            foreach ( (array) $params as $key => $value ) {
2079
+                if ( ! is_scalar( $value ) ) {
2080
+                    continue;
2081
+                }
2172 2082
 
2173
-	/**
2174
-	 * Run the class if found.
2175
-	 */
2176
-	AyeCode_UI_Settings::instance();
2083
+                $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2084
+            }
2085
+
2086
+            $locale = json_encode( $params );
2087
+
2088
+            return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) );
2089
+        }
2090
+
2091
+        /**
2092
+         * JavaScript Minifier
2093
+         *
2094
+         * @param $input
2095
+         *
2096
+         * @return mixed
2097
+         */
2098
+        public static function minify_js($input) {
2099
+            if(trim($input) === "") return $input;
2100
+            return preg_replace(
2101
+                array(
2102
+                    // Remove comment(s)
2103
+                    '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
2104
+                    // Remove white-space(s) outside the string and regex
2105
+                    '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
2106
+                    // Remove the last semicolon
2107
+                    '#;+\}#',
2108
+                    // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
2109
+                    '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
2110
+                    // --ibid. From `foo['bar']` to `foo.bar`
2111
+                    '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
2112
+                ),
2113
+                array(
2114
+                    '$1',
2115
+                    '$1$2',
2116
+                    '}',
2117
+                    '$1$3',
2118
+                    '$1.$3'
2119
+                ),
2120
+                $input);
2121
+        }
2122
+
2123
+        /**
2124
+         * Minify CSS
2125
+         *
2126
+         * @param $input
2127
+         *
2128
+         * @return mixed
2129
+         */
2130
+        public static function minify_css($input) {
2131
+            if(trim($input) === "") return $input;
2132
+            return preg_replace(
2133
+                array(
2134
+                    // Remove comment(s)
2135
+                    '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
2136
+                    // Remove unused white-space(s)
2137
+                    '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
2138
+                    // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0`
2139
+                    '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
2140
+                    // Replace `:0 0 0 0` with `:0`
2141
+                    '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
2142
+                    // Replace `background-position:0` with `background-position:0 0`
2143
+                    '#(background-position):0(?=[;\}])#si',
2144
+                    // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space
2145
+                    '#(?<=[\s:,\-])0+\.(\d+)#s',
2146
+                    // Minify string value
2147
+                    '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
2148
+                    '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si',
2149
+                    // Minify HEX color code
2150
+                    '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
2151
+                    // Replace `(border|outline):none` with `(border|outline):0`
2152
+                    '#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
2153
+                    // Remove empty selector(s)
2154
+                    '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
2155
+                ),
2156
+                array(
2157
+                    '$1',
2158
+                    '$1$2$3$4$5$6$7',
2159
+                    '$1',
2160
+                    ':0',
2161
+                    '$1:0 0',
2162
+                    '.$1',
2163
+                    '$1$3',
2164
+                    '$1$2$4$5',
2165
+                    '$1$2$3',
2166
+                    '$1:0',
2167
+                    '$1$2'
2168
+                ),
2169
+                $input);
2170
+        }
2171
+    }
2172
+
2173
+    /**
2174
+     * Run the class if found.
2175
+     */
2176
+    AyeCode_UI_Settings::instance();
2177 2177
 }
2178 2178
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -12,473 +12,473 @@
 block discarded – undo
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
-		$merge_tags = 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}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
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( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
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
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-
163
-			}
164
-
165
-		}
166
-
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
-	}
169
-
170
-	/**
171
-	 * Helper function to send an email.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice
174
-	 * @param GetPaid_Notification_Email $email
175
-	 * @param string $type
176
-	 * @param string|array $recipients
177
-	 * @param array $extra_args Extra template args.
178
-	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
-
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
-
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
184
-			return;
185
-		}
186
-
187
-		$mailer     = new GetPaid_Notification_Email_Sender();
188
-		$merge_tags = $email->get_merge_tags();
189
-
190
-		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
194
-			$email->get_attachments()
195
-		);
196
-
197
-		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
199
-			$mailer->send(
200
-				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
203
-				$email->get_attachments()
204
-			);
205
-		}
206
-
207
-		if ( $result ) {
208
-			$invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
209
-		} else {
210
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
211
-		}
212
-
213
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
214
-
215
-		return $result;
216
-	}
217
-
218
-	/**
219
-	 * Also send emails to any cc users.
220
-	 *
221
-	 * @param array $recipients
222
-	 * @param GetPaid_Notification_Email $email
223
-	 */
224
-	public function filter_email_recipients( $recipients, $email ) {
225
-
226
-		if ( ! $email->is_admin_email() ) {
227
-			$cc = $email->object->get_email_cc();
228
-
229
-			if ( ! empty( $cc ) ) {
230
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
232
-			}
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
+        $merge_tags = 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}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
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( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
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
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar ( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+
163
+            }
164
+
165
+        }
166
+
167
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
+    }
169
+
170
+    /**
171
+     * Helper function to send an email.
172
+     *
173
+     * @param WPInv_Invoice $invoice
174
+     * @param GetPaid_Notification_Email $email
175
+     * @param string $type
176
+     * @param string|array $recipients
177
+     * @param array $extra_args Extra template args.
178
+     */
179
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
+
181
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
+
183
+        if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
184
+            return;
185
+        }
186
+
187
+        $mailer     = new GetPaid_Notification_Email_Sender();
188
+        $merge_tags = $email->get_merge_tags();
189
+
190
+        $result = $mailer->send(
191
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
+            $email->get_content( $merge_tags, $extra_args ),
194
+            $email->get_attachments()
195
+        );
196
+
197
+        // Maybe send a copy to the admin.
198
+        if ( $email->include_admin_bcc() ) {
199
+            $mailer->send(
200
+                wpinv_get_admin_email(),
201
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
+                $email->get_content( $merge_tags ),
203
+                $email->get_attachments()
204
+            );
205
+        }
206
+
207
+        if ( $result ) {
208
+            $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
209
+        } else {
210
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
211
+        }
212
+
213
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
214
+
215
+        return $result;
216
+    }
217
+
218
+    /**
219
+     * Also send emails to any cc users.
220
+     *
221
+     * @param array $recipients
222
+     * @param GetPaid_Notification_Email $email
223
+     */
224
+    public function filter_email_recipients( $recipients, $email ) {
225
+
226
+        if ( ! $email->is_admin_email() ) {
227
+            $cc = $email->object->get_email_cc();
228
+
229
+            if ( ! empty( $cc ) ) {
230
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
232
+            }
233 233
 
234
-		}
234
+        }
235 235
 
236
-		return $recipients;
236
+        return $recipients;
237 237
 
238
-	}
238
+    }
239 239
 
240
-	/**
241
-	 * Sends a new invoice notification.
242
-	 *
243
-	 * @param WPInv_Invoice $invoice
244
-	 */
245
-	public function new_invoice( $invoice ) {
240
+    /**
241
+     * Sends a new invoice notification.
242
+     *
243
+     * @param WPInv_Invoice $invoice
244
+     */
245
+    public function new_invoice( $invoice ) {
246 246
 
247
-		// Only send this email for invoices created via the admin page.
248
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
249
-			return;
250
-		}
247
+        // Only send this email for invoices created via the admin page.
248
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
249
+            return;
250
+        }
251 251
 
252
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
253
-		$recipient = wpinv_get_admin_email();
252
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
253
+        $recipient = wpinv_get_admin_email();
254 254
 
255
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
255
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
256 256
 
257
-	}
257
+    }
258 258
 
259
-	/**
260
-	 * Sends a cancelled invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function cancelled_invoice( $invoice ) {
259
+    /**
260
+     * Sends a cancelled invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function cancelled_invoice( $invoice ) {
265 265
 
266
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
267
-		$recipient = wpinv_get_admin_email();
266
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
267
+        $recipient = wpinv_get_admin_email();
268 268
 
269
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
269
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
270 270
 
271
-	}
271
+    }
272 272
 
273
-	/**
274
-	 * Sends a failed invoice notification.
275
-	 *
276
-	 * @param WPInv_Invoice $invoice
277
-	 */
278
-	public function failed_invoice( $invoice ) {
273
+    /**
274
+     * Sends a failed invoice notification.
275
+     *
276
+     * @param WPInv_Invoice $invoice
277
+     */
278
+    public function failed_invoice( $invoice ) {
279 279
 
280
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
281
-		$recipient = wpinv_get_admin_email();
280
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
281
+        $recipient = wpinv_get_admin_email();
282 282
 
283
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
283
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
284 284
 
285
-	}
285
+    }
286 286
 
287
-	/**
288
-	 * Sends a notification whenever an invoice is put on hold.
289
-	 *
290
-	 * @param WPInv_Invoice $invoice
291
-	 */
292
-	public function onhold_invoice( $invoice ) {
287
+    /**
288
+     * Sends a notification whenever an invoice is put on hold.
289
+     *
290
+     * @param WPInv_Invoice $invoice
291
+     */
292
+    public function onhold_invoice( $invoice ) {
293 293
 
294
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
-		$recipient = $invoice->get_email();
294
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
+        $recipient = $invoice->get_email();
296 296
 
297
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
297
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Sends a notification whenever an invoice is marked as processing payment.
303
-	 *
304
-	 * @param WPInv_Invoice $invoice
305
-	 */
306
-	public function processing_invoice( $invoice ) {
301
+    /**
302
+     * Sends a notification whenever an invoice is marked as processing payment.
303
+     *
304
+     * @param WPInv_Invoice $invoice
305
+     */
306
+    public function processing_invoice( $invoice ) {
307 307
 
308
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
-		$recipient = $invoice->get_email();
308
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
+        $recipient = $invoice->get_email();
310 310
 
311
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
311
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
312 312
 
313
-	}
313
+    }
314 314
 
315
-	/**
316
-	 * Sends a notification whenever an invoice is paid.
317
-	 *
318
-	 * @param WPInv_Invoice $invoice
319
-	 */
320
-	public function completed_invoice( $invoice ) {
315
+    /**
316
+     * Sends a notification whenever an invoice is paid.
317
+     *
318
+     * @param WPInv_Invoice $invoice
319
+     */
320
+    public function completed_invoice( $invoice ) {
321 321
 
322
-		// (Maybe) abort if it is a renewal invoice.
323
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
324
-			return;
325
-		}
322
+        // (Maybe) abort if it is a renewal invoice.
323
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
324
+            return;
325
+        }
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
-		$recipient = $invoice->get_email();
327
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
+        $recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331 331
 
332
-	}
332
+    }
333 333
 
334
-	/**
335
-	 * Sends a notification whenever an invoice is refunded.
336
-	 *
337
-	 * @param WPInv_Invoice $invoice
338
-	 */
339
-	public function refunded_invoice( $invoice ) {
334
+    /**
335
+     * Sends a notification whenever an invoice is refunded.
336
+     *
337
+     * @param WPInv_Invoice $invoice
338
+     */
339
+    public function refunded_invoice( $invoice ) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
-		$recipient = $invoice->get_email();
341
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
+        $recipient = $invoice->get_email();
343 343
 
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
344
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
345 345
 
346
-	}
346
+    }
347 347
 
348
-	/**
349
-	 * Notifies a user about new invoices
350
-	 *
351
-	 * @param WPInv_Invoice $invoice
352
-	 * @param bool $force
353
-	 */
354
-	public function user_invoice( $invoice, $force = false ) {
348
+    /**
349
+     * Notifies a user about new invoices
350
+     *
351
+     * @param WPInv_Invoice $invoice
352
+     * @param bool $force
353
+     */
354
+    public function user_invoice( $invoice, $force = false ) {
355 355
 
356
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
357
-			return;
358
-		}
359
-
360
-		// Only send this email for invoices created via the admin page.
361
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
362
-			return;
363
-		}
356
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
357
+            return;
358
+        }
359
+
360
+        // Only send this email for invoices created via the admin page.
361
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
362
+            return;
363
+        }
364 364
 
365
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
366
-		$recipient = $invoice->get_email();
365
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
366
+        $recipient = $invoice->get_email();
367 367
 
368
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
368
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
369 369
 
370
-	}
371
-
372
-	/**
373
-	 * Checks if an invoice is a payment form invoice.
374
-	 *
375
-	 * @param int $invoice
376
-	 * @return bool
377
-	 */
378
-	public function is_payment_form_invoice( $invoice ) {
379
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
381
-	}
370
+    }
371
+
372
+    /**
373
+     * Checks if an invoice is a payment form invoice.
374
+     *
375
+     * @param int $invoice
376
+     * @return bool
377
+     */
378
+    public function is_payment_form_invoice( $invoice ) {
379
+        $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
+        return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
381
+    }
382 382
 
383
-	/**
384
-	 * Notifies admin about new invoice notes
385
-	 *
386
-	 * @param WPInv_Invoice $invoice
387
-	 * @param string $note
388
-	 */
389
-	public function user_note( $invoice, $note ) {
390
-
391
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
392
-		$recipient = $invoice->get_email();
383
+    /**
384
+     * Notifies admin about new invoice notes
385
+     *
386
+     * @param WPInv_Invoice $invoice
387
+     * @param string $note
388
+     */
389
+    public function user_note( $invoice, $note ) {
390
+
391
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
392
+        $recipient = $invoice->get_email();
393 393
 
394
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
395
-
396
-	}
397
-
398
-	/**
399
-	 * (Force) Sends overdue notices.
400
-	 *
401
-	 * @param WPInv_Invoice $invoice
402
-	 */
403
-	public function force_send_overdue_notice( $invoice ) {
404
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
405
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
406
-	}
407
-
408
-	/**
409
-	 * Sends overdue notices.
410
-	 *
411
-	 * @TODO: Create an invoices query class.
412
-	 */
413
-	public function overdue() {
414
-		global $wpdb;
415
-
416
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
417
-
418
-		// Fetch reminder days.
419
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
420
-
421
-		// Abort if non is set.
422
-		if ( empty( $reminder_days ) ) {
423
-			return;
424
-		}
425
-
426
-		// Retrieve date query.
427
-		$date_query = $this->get_date_query( $reminder_days );
428
-
429
-		// Invoices table.
430
-		$table = $wpdb->prefix . 'getpaid_invoices';
431
-
432
-		// Fetch invoices.
433
-		$invoices  = $wpdb->get_col(
434
-			"SELECT posts.ID FROM $wpdb->posts as posts
394
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
395
+
396
+    }
397
+
398
+    /**
399
+     * (Force) Sends overdue notices.
400
+     *
401
+     * @param WPInv_Invoice $invoice
402
+     */
403
+    public function force_send_overdue_notice( $invoice ) {
404
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
405
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
406
+    }
407
+
408
+    /**
409
+     * Sends overdue notices.
410
+     *
411
+     * @TODO: Create an invoices query class.
412
+     */
413
+    public function overdue() {
414
+        global $wpdb;
415
+
416
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
417
+
418
+        // Fetch reminder days.
419
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
420
+
421
+        // Abort if non is set.
422
+        if ( empty( $reminder_days ) ) {
423
+            return;
424
+        }
425
+
426
+        // Retrieve date query.
427
+        $date_query = $this->get_date_query( $reminder_days );
428
+
429
+        // Invoices table.
430
+        $table = $wpdb->prefix . 'getpaid_invoices';
431
+
432
+        // Fetch invoices.
433
+        $invoices  = $wpdb->get_col(
434
+            "SELECT posts.ID FROM $wpdb->posts as posts
435 435
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
436 436
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
437 437
 
438
-		foreach ( $invoices as $invoice ) {
438
+        foreach ( $invoices as $invoice ) {
439 439
 
440
-			// Only send this email for invoices created via the admin page.
441
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
442
-				$invoice       = new WPInv_Invoice( $invoice );
443
-				$email->object = $invoice;
440
+            // Only send this email for invoices created via the admin page.
441
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
442
+                $invoice       = new WPInv_Invoice( $invoice );
443
+                $email->object = $invoice;
444 444
 
445
-				if ( $invoice->needs_payment() ) {
446
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
447
-				}
445
+                if ( $invoice->needs_payment() ) {
446
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
447
+                }
448 448
 
449
-			}
449
+            }
450 450
 
451
-		}
451
+        }
452 452
 
453
-	}
453
+    }
454 454
 
455
-	/**
456
-	 * Calculates the date query for an invoices query
457
-	 *
458
-	 * @param array $reminder_days
459
-	 * @return string
460
-	 */
461
-	public function get_date_query( $reminder_days ) {
455
+    /**
456
+     * Calculates the date query for an invoices query
457
+     *
458
+     * @param array $reminder_days
459
+     * @return string
460
+     */
461
+    public function get_date_query( $reminder_days ) {
462 462
 
463
-		$date_query = array(
464
-			'relation'  => 'OR'
465
-		);
463
+        $date_query = array(
464
+            'relation'  => 'OR'
465
+        );
466 466
 
467
-		foreach ( $reminder_days as $days ) {
468
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
467
+        foreach ( $reminder_days as $days ) {
468
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
469 469
 
470
-			$date_query[] = array(
471
-				'year'  => $date['year'],
472
-				'month' => $date['month'],
473
-				'day'   => $date['day'],
474
-			);
470
+            $date_query[] = array(
471
+                'year'  => $date['year'],
472
+                'month' => $date['month'],
473
+                'day'   => $date['day'],
474
+            );
475 475
 
476
-		}
476
+        }
477 477
 
478
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
478
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
479 479
 
480
-		return $date_query->get_sql();
480
+        return $date_query->get_sql();
481 481
 
482
-	}
482
+    }
483 483
 
484 484
 }
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 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 );
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 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,52 +119,52 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		$merge_tags = 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}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
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( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
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' ),
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}'       => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())),
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(strtolower($invoice->get_label())),
144
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_label())),
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 148
 		);
149 149
 
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
150
+		$payment_form_data = $invoice->get_meta('payment_form_data', true);
151 151
 
152
-		if ( is_array( $payment_form_data ) ) {
152
+		if (is_array($payment_form_data)) {
153 153
 
154
-			foreach ( $payment_form_data as $label => $value ) {
154
+			foreach ($payment_form_data as $label => $value) {
155 155
 
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
156
+				$label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label));
157
+				$value = is_array($value) ? implode(', ', $value) : $value;
158 158
 
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
159
+				if (is_scalar($value)) {
160
+					$merge_tags["{{$label}}"] = wp_kses_post($value);
161 161
 				}
162 162
 
163 163
 			}
164 164
 
165 165
 		}
166 166
 
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
167
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
168 168
 	}
169 169
 
170 170
 	/**
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 * @param string|array $recipients
177 177
 	 * @param array $extra_args Extra template args.
178 178
 	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
179
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
180 180
 
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
181
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
182 182
 
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
183
+		if (apply_filters('getpaid_skip_invoice_email', false, $type, $invoice)) {
184 184
 			return;
185 185
 		}
186 186
 
@@ -188,29 +188,29 @@  discard block
 block discarded – undo
188 188
 		$merge_tags = $email->get_merge_tags();
189 189
 
190 190
 		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
191
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
192
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
193
+			$email->get_content($merge_tags, $extra_args),
194 194
 			$email->get_attachments()
195 195
 		);
196 196
 
197 197
 		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
198
+		if ($email->include_admin_bcc()) {
199 199
 			$mailer->send(
200 200
 				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
201
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
202
+				$email->get_content($merge_tags),
203 203
 				$email->get_attachments()
204 204
 			);
205 205
 		}
206 206
 
207
-		if ( $result ) {
208
-			$invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
207
+		if ($result) {
208
+			$invoice->add_note(sprintf(__('Successfully sent %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
209 209
 		} else {
210
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
210
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);	
211 211
 		}
212 212
 
213
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
213
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
214 214
 
215 215
 		return $result;
216 216
 	}
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 	 * @param array $recipients
222 222
 	 * @param GetPaid_Notification_Email $email
223 223
 	 */
224
-	public function filter_email_recipients( $recipients, $email ) {
224
+	public function filter_email_recipients($recipients, $email) {
225 225
 
226
-		if ( ! $email->is_admin_email() ) {
226
+		if (!$email->is_admin_email()) {
227 227
 			$cc = $email->object->get_email_cc();
228 228
 
229
-			if ( ! empty( $cc ) ) {
230
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
229
+			if (!empty($cc)) {
230
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
231
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
232 232
 			}
233 233
 
234 234
 		}
@@ -242,17 +242,17 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @param WPInv_Invoice $invoice
244 244
 	 */
245
-	public function new_invoice( $invoice ) {
245
+	public function new_invoice($invoice) {
246 246
 
247 247
 		// Only send this email for invoices created via the admin page.
248
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
248
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
249 249
 			return;
250 250
 		}
251 251
 
252
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
252
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
253 253
 		$recipient = wpinv_get_admin_email();
254 254
 
255
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
255
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
256 256
 
257 257
 	}
258 258
 
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @param WPInv_Invoice $invoice
263 263
 	 */
264
-	public function cancelled_invoice( $invoice ) {
264
+	public function cancelled_invoice($invoice) {
265 265
 
266
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
266
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
267 267
 		$recipient = wpinv_get_admin_email();
268 268
 
269
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
269
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
270 270
 
271 271
 	}
272 272
 
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * @param WPInv_Invoice $invoice
277 277
 	 */
278
-	public function failed_invoice( $invoice ) {
278
+	public function failed_invoice($invoice) {
279 279
 
280
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
280
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
281 281
 		$recipient = wpinv_get_admin_email();
282 282
 
283
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
283
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
284 284
 
285 285
 	}
286 286
 
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 	 *
290 290
 	 * @param WPInv_Invoice $invoice
291 291
 	 */
292
-	public function onhold_invoice( $invoice ) {
292
+	public function onhold_invoice($invoice) {
293 293
 
294
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
294
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
295 295
 		$recipient = $invoice->get_email();
296 296
 
297
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
297
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
298 298
 
299 299
 	}
300 300
 
@@ -303,12 +303,12 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param WPInv_Invoice $invoice
305 305
 	 */
306
-	public function processing_invoice( $invoice ) {
306
+	public function processing_invoice($invoice) {
307 307
 
308
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
308
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
309 309
 		$recipient = $invoice->get_email();
310 310
 
311
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
311
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
312 312
 
313 313
 	}
314 314
 
@@ -317,17 +317,17 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @param WPInv_Invoice $invoice
319 319
 	 */
320
-	public function completed_invoice( $invoice ) {
320
+	public function completed_invoice($invoice) {
321 321
 
322 322
 		// (Maybe) abort if it is a renewal invoice.
323
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
323
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
324 324
 			return;
325 325
 		}
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
327
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
328 328
 		$recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
331 331
 
332 332
 	}
333 333
 
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
 	 *
337 337
 	 * @param WPInv_Invoice $invoice
338 338
 	 */
339
-	public function refunded_invoice( $invoice ) {
339
+	public function refunded_invoice($invoice) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
341
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
342 342
 		$recipient = $invoice->get_email();
343 343
 
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
344
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
345 345
 
346 346
 	}
347 347
 
@@ -351,21 +351,21 @@  discard block
 block discarded – undo
351 351
 	 * @param WPInv_Invoice $invoice
352 352
 	 * @param bool $force
353 353
 	 */
354
-	public function user_invoice( $invoice, $force = false ) {
354
+	public function user_invoice($invoice, $force = false) {
355 355
 
356
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
356
+		if (!empty($GLOBALS['wpinv_skip_invoice_notification'])) {
357 357
 			return;
358 358
 		}
359 359
 
360 360
 		// Only send this email for invoices created via the admin page.
361
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
361
+		if (!$invoice->is_type('invoice') || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
362 362
 			return;
363 363
 		}
364 364
 
365
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
365
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
366 366
 		$recipient = $invoice->get_email();
367 367
 
368
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
368
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
369 369
 
370 370
 	}
371 371
 
@@ -375,9 +375,9 @@  discard block
 block discarded – undo
375 375
 	 * @param int $invoice
376 376
 	 * @return bool
377 377
 	 */
378
-	public function is_payment_form_invoice( $invoice ) {
379
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
378
+	public function is_payment_form_invoice($invoice) {
379
+		$is_payment_form_invoice = empty($_GET['getpaid-admin-action']) && ('payment_form' == get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' == get_post_meta($invoice, 'wpinv_created_via', true));
380
+		return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice);
381 381
 	}
382 382
 
383 383
 	/**
@@ -386,12 +386,12 @@  discard block
 block discarded – undo
386 386
 	 * @param WPInv_Invoice $invoice
387 387
 	 * @param string $note
388 388
 	 */
389
-	public function user_note( $invoice, $note ) {
389
+	public function user_note($invoice, $note) {
390 390
 
391
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
391
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
392 392
 		$recipient = $invoice->get_email();
393 393
 
394
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
394
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
395 395
 
396 396
 	}
397 397
 
@@ -400,9 +400,9 @@  discard block
 block discarded – undo
400 400
 	 *
401 401
 	 * @param WPInv_Invoice $invoice
402 402
 	 */
403
-	public function force_send_overdue_notice( $invoice ) {
404
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
405
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
403
+	public function force_send_overdue_notice($invoice) {
404
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
405
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
406 406
 	}
407 407
 
408 408
 	/**
@@ -413,37 +413,37 @@  discard block
 block discarded – undo
413 413
 	public function overdue() {
414 414
 		global $wpdb;
415 415
 
416
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
416
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
417 417
 
418 418
 		// Fetch reminder days.
419
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
419
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
420 420
 
421 421
 		// Abort if non is set.
422
-		if ( empty( $reminder_days ) ) {
422
+		if (empty($reminder_days)) {
423 423
 			return;
424 424
 		}
425 425
 
426 426
 		// Retrieve date query.
427
-		$date_query = $this->get_date_query( $reminder_days );
427
+		$date_query = $this->get_date_query($reminder_days);
428 428
 
429 429
 		// Invoices table.
430 430
 		$table = $wpdb->prefix . 'getpaid_invoices';
431 431
 
432 432
 		// Fetch invoices.
433
-		$invoices  = $wpdb->get_col(
433
+		$invoices = $wpdb->get_col(
434 434
 			"SELECT posts.ID FROM $wpdb->posts as posts
435 435
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
436 436
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
437 437
 
438
-		foreach ( $invoices as $invoice ) {
438
+		foreach ($invoices as $invoice) {
439 439
 
440 440
 			// Only send this email for invoices created via the admin page.
441
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
442
-				$invoice       = new WPInv_Invoice( $invoice );
441
+			if (!$this->is_payment_form_invoice($invoice)) {
442
+				$invoice       = new WPInv_Invoice($invoice);
443 443
 				$email->object = $invoice;
444 444
 
445
-				if ( $invoice->needs_payment() ) {
446
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
445
+				if ($invoice->needs_payment()) {
446
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
447 447
 				}
448 448
 
449 449
 			}
@@ -458,14 +458,14 @@  discard block
 block discarded – undo
458 458
 	 * @param array $reminder_days
459 459
 	 * @return string
460 460
 	 */
461
-	public function get_date_query( $reminder_days ) {
461
+	public function get_date_query($reminder_days) {
462 462
 
463 463
 		$date_query = array(
464 464
 			'relation'  => 'OR'
465 465
 		);
466 466
 
467
-		foreach ( $reminder_days as $days ) {
468
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
467
+		foreach ($reminder_days as $days) {
468
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
469 469
 
470 470
 			$date_query[] = array(
471 471
 				'year'  => $date['year'],
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 
476 476
 		}
477 477
 
478
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
478
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
479 479
 
480 480
 		return $date_query->get_sql();
481 481
 
Please login to merge, or discard this patch.
includes/class-getpaid-notification-email-sender.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Notification_Email_Sender {
14 14
 
15 15
     /**
16
-	 * Whether or not we should inline CSS into the email.
17
-	 */
18
-	public $inline_css = true;
16
+     * Whether or not we should inline CSS into the email.
17
+     */
18
+    public $inline_css = true;
19 19
 
20 20
     /**
21
-	 * The wp_mail() data.
22
-	 */
21
+     * The wp_mail() data.
22
+     */
23 23
     public $wp_mail_data = null;
24 24
 
25 25
     /**
26
-	 * Sends a new email.
26
+     * Sends a new email.
27 27
      * 
28 28
      * @param string|array $to The recipients email or an array of recipient emails.
29 29
      * @param string $subject The email's subject.
@@ -31,49 +31,49 @@  discard block
 block discarded – undo
31 31
      * @param array $attachments The email attachments.
32 32
      * 
33 33
      * @return bool
34
-	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
34
+     */
35
+    public function send( $to, $subject, $email, $attachments = array() ) {
36 36
 
37
-		/*
37
+        /*
38 38
 		 * Allow to filter data on per-email basis.
39 39
 		 */
40
-		$data = apply_filters(
41
-			'getpaid_email_data',
42
-			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
-				'headers'     => $this->get_headers(),
47
-				'attachments' => $attachments,
48
-			),
49
-			$this
50
-		);
40
+        $data = apply_filters(
41
+            'getpaid_email_data',
42
+            array(
43
+                'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
+                'subject'     => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ),
45
+                'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
+                'headers'     => $this->get_headers(),
47
+                'attachments' => $attachments,
48
+            ),
49
+            $this
50
+        );
51 51
 
52 52
         // Remove slashes.
53 53
         $data               = (array) wp_unslash( $data );
54 54
 
55 55
         // Cache it.
56
-		$this->wp_mail_data = $data;
56
+        $this->wp_mail_data = $data;
57 57
 
58
-		// Attach our own hooks.
59
-		$this->before_sending();
58
+        // Attach our own hooks.
59
+        $this->before_sending();
60 60
 
61 61
         $result = false;
62 62
 
63 63
         foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
64
+            $result = $this->_send( $to, $data );
65 65
         }
66 66
 
67
-		// Remove our hooks.
68
-		$this->after_sending();		
67
+        // Remove our hooks.
68
+        $this->after_sending();		
69 69
 
70
-		$this->wp_mail_data = null;
70
+        $this->wp_mail_data = null;
71 71
 
72
-		return $result;
73
-	}
72
+        return $result;
73
+    }
74 74
 
75
-	/**
76
-	 * Does the actual sending.
75
+    /**
76
+     * Does the actual sending.
77 77
      * 
78 78
      * @param string $to The recipient's email.
79 79
      * @param array $data The email's data.
@@ -81,81 +81,81 @@  discard block
 block discarded – undo
81 81
      * @param array $attachments The email attachments.
82 82
      * 
83 83
      * @return bool
84
-	 */
85
-	protected function _send( $to, $data ) {
86
-
87
-		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
-
90
-		// Send the actual email.
91
-		$result = call_user_func(
92
-			$sending_function,
93
-			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
-			$data['email'],
96
-			$data['headers'],
97
-			$data['attachments']
98
-		);
99
-
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
-		}
104
-
105
-		return $result;
106
-	}
84
+     */
85
+    protected function _send( $to, $data ) {
86
+
87
+        // Prepare the sending function.
88
+        $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
+
90
+        // Send the actual email.
91
+        $result = call_user_func(
92
+            $sending_function,
93
+            $to,
94
+            html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
+            $data['email'],
96
+            $data['headers'],
97
+            $data['attachments']
98
+        );
99
+
100
+        if ( ! $result ) {
101
+            $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
+            wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
+        }
104
+
105
+        return $result;
106
+    }
107 107
     
108 108
     /**
109
-	 * Retrieves email headers.
110
-	 */
111
-	public function get_headers() {
109
+     * Retrieves email headers.
110
+     */
111
+    public function get_headers() {
112 112
 
113
-		$name       = $this->get_from_name();
114
-		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
113
+        $name       = $this->get_from_name();
114
+        $reply_to   = $this->get_reply_to();
115
+        $headers    = array( "Reply-To:$name <$reply_to>" );
116 116
 
117
-		return apply_filters( 'getpaid_email_headers',  $headers, $this );
117
+        return apply_filters( 'getpaid_email_headers',  $headers, $this );
118 118
 
119
-	}
119
+    }
120 120
 
121 121
     /**
122
-	 * Fires before an email is sent
123
-	 *
124
-	 * @since 1.0.0
125
-	 */
126
-	public function before_sending() {
122
+     * Fires before an email is sent
123
+     *
124
+     * @since 1.0.0
125
+     */
126
+    public function before_sending() {
127 127
 
128 128
         do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
129
+        add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
+        add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
+        add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
+        add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
133 133
 
134
-	}
134
+    }
135 135
 
136 136
     /**
137
-	 * Returns the from name.
138
-	 */
139
-	public function get_from_name() {
137
+     * Returns the from name.
138
+     */
139
+    public function get_from_name() {
140 140
 
141 141
         $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name =  get_bloginfo( 'name' );
143
+        if ( empty( $from_name ) ) {
144
+            $from_name =  get_bloginfo( 'name' );
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+        return wp_specialchars_decode( $from_name, ENT_QUOTES );
148 148
     }
149 149
 
150 150
     /**
151
-	 * Returns the from email.
152
-	 */
153
-	public function get_from_address() {
151
+     * Returns the from email.
152
+     */
153
+    public function get_from_address() {
154 154
 
155 155
         $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
158
-			$from_address =  $this->default_from_address();
157
+        if ( ! is_email( $from_address ) ) {
158
+            $from_address =  $this->default_from_address();
159 159
         }
160 160
         
161 161
         return $from_address;
@@ -163,75 +163,75 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     /**
166
-	 * The default emails from address.
167
-	 * 
168
-	 * Defaults to wordpress@$sitename
169
-	 * Some hosts will block outgoing mail from this address if it doesn't exist,
170
-	 * but there's no easy alternative. Defaulting to admin_email might appear to be
171
-	 * another option, but some hosts may refuse to relay mail from an unknown domain.
172
-	 *
173
-	 */
174
-	public function default_from_address() {
175
-
176
-		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
180
-		}
181
-
182
-		$from_email = 'wordpress@' . $sitename;
183
-
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
166
+     * The default emails from address.
167
+     * 
168
+     * Defaults to wordpress@$sitename
169
+     * Some hosts will block outgoing mail from this address if it doesn't exist,
170
+     * but there's no easy alternative. Defaulting to admin_email might appear to be
171
+     * another option, but some hosts may refuse to relay mail from an unknown domain.
172
+     *
173
+     */
174
+    public function default_from_address() {
175
+
176
+        // Get the site domain and get rid of www.
177
+        $sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
+        if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
+            $sitename = substr( $sitename, 4 );
180
+        }
181
+
182
+        $from_email = 'wordpress@' . $sitename;
183
+
184
+        return apply_filters( 'getpaid_default_from_address', $from_email );
185 185
 
186 186
     }
187 187
     
188 188
     /**
189
-	 * Get the email reply-to.
190
-	 *
191
-	 *
192
-	 * @return string The email reply-to address.
193
-	 */
194
-	public function get_reply_to() {
189
+     * Get the email reply-to.
190
+     *
191
+     *
192
+     * @return string The email reply-to address.
193
+     */
194
+    public function get_reply_to() {
195 195
 
196
-		$reply_to = wpinv_get_admin_email();
196
+        $reply_to = wpinv_get_admin_email();
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to =  get_option( 'admin_email' );
200
-		}
198
+        if ( ! is_email( $reply_to ) ) {
199
+            $reply_to =  get_option( 'admin_email' );
200
+        }
201 201
 
202
-		return $reply_to;
202
+        return $reply_to;
203 203
     }
204 204
     
205 205
     /**
206
-	 * Get the email content type.
207
-	 *
208
-	 */
209
-	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
206
+     * Get the email content type.
207
+     *
208
+     */
209
+    public function get_content_type() {
210
+        return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
211 211
     }
212 212
     
213 213
     /**
214
-	 * Ensures that our email messages are not messed up by template plugins.
215
-	 *
216
-	 * @return array wp_mail_data.
217
-	 */
218
-	public function ensure_email_content( $args ) {
219
-		$args['message'] = $this->wp_mail_data['email'];
220
-		return $args;
214
+     * Ensures that our email messages are not messed up by template plugins.
215
+     *
216
+     * @return array wp_mail_data.
217
+     */
218
+    public function ensure_email_content( $args ) {
219
+        $args['message'] = $this->wp_mail_data['email'];
220
+        return $args;
221 221
     }
222 222
     
223 223
     /**
224
-	 * A little house keeping after an email is sent.
225
-	 *
226
- 	 */
227
-	public function after_sending() {
224
+     * A little house keeping after an email is sent.
225
+     *
226
+     */
227
+    public function after_sending() {
228 228
 
229 229
         do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
230
+        remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
+        remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
+        remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
+        remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
234 234
 
235
-	}
235
+    }
236 236
 
237 237
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This function is responsible for sending emails.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      * 
33 33
      * @return bool
34 34
 	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
35
+	public function send($to, $subject, $email, $attachments = array()) {
36 36
 
37 37
 		/*
38 38
 		 * Allow to filter data on per-email basis.
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 		$data = apply_filters(
41 41
 			'getpaid_email_data',
42 42
 			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
43
+				'to'          => array_filter(array_unique(wpinv_parse_list($to))),
44
+				'subject'     => htmlspecialchars_decode(strip_tags($subject), ENT_QUOTES),
45
+				'email'       => apply_filters('wpinv_mail_content', $email),
46 46
 				'headers'     => $this->get_headers(),
47 47
 				'attachments' => $attachments,
48 48
 			),
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		);
51 51
 
52 52
         // Remove slashes.
53
-        $data               = (array) wp_unslash( $data );
53
+        $data = (array) wp_unslash($data);
54 54
 
55 55
         // Cache it.
56 56
 		$this->wp_mail_data = $data;
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 
61 61
         $result = false;
62 62
 
63
-        foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
63
+        foreach ($this->wp_mail_data['to'] as $to) {
64
+			$result = $this->_send($to, $data);
65 65
         }
66 66
 
67 67
 		// Remove our hooks.
@@ -82,24 +82,24 @@  discard block
 block discarded – undo
82 82
      * 
83 83
      * @return bool
84 84
 	 */
85
-	protected function _send( $to, $data ) {
85
+	protected function _send($to, $data) {
86 86
 
87 87
 		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
88
+		$sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail');
89 89
 
90 90
 		// Send the actual email.
91 91
 		$result = call_user_func(
92 92
 			$sending_function,
93 93
 			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
94
+			html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')),
95 95
 			$data['email'],
96 96
 			$data['headers'],
97 97
 			$data['attachments']
98 98
 		);
99 99
 
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
100
+		if (!$result) {
101
+			$log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']);
102
+			wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__);
103 103
 		}
104 104
 
105 105
 		return $result;
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 
113 113
 		$name       = $this->get_from_name();
114 114
 		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
115
+		$headers    = array("Reply-To:$name <$reply_to>");
116 116
 
117
-		return apply_filters( 'getpaid_email_headers',  $headers, $this );
117
+		return apply_filters('getpaid_email_headers', $headers, $this);
118 118
 
119 119
 	}
120 120
 
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function before_sending() {
127 127
 
128
-        do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
128
+        do_action('getpaid_before_send_email', $this);
129
+		add_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
130
+		add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
131
+		add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
132
+		add_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
133 133
 
134 134
 	}
135 135
 
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function get_from_name() {
140 140
 
141
-        $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
141
+        $from_name = wpinv_get_option('email_from_name', get_bloginfo('name'));
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name =  get_bloginfo( 'name' );
143
+		if (empty($from_name)) {
144
+			$from_name = get_bloginfo('name');
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+		return wp_specialchars_decode($from_name, ENT_QUOTES);
148 148
     }
149 149
 
150 150
     /**
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function get_from_address() {
154 154
 
155
-        $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
155
+        $from_address = wpinv_get_option('email_from', $this->default_from_address());
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
158
-			$from_address =  $this->default_from_address();
157
+		if (!is_email($from_address)) {
158
+			$from_address = $this->default_from_address();
159 159
         }
160 160
         
161 161
         return $from_address;
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	public function default_from_address() {
175 175
 
176 176
 		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
177
+		$sitename = strtolower($_SERVER['SERVER_NAME']);
178
+		if (substr($sitename, 0, 4) == 'www.') {
179
+			$sitename = substr($sitename, 4);
180 180
 		}
181 181
 
182 182
 		$from_email = 'wordpress@' . $sitename;
183 183
 
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
184
+		return apply_filters('getpaid_default_from_address', $from_email);
185 185
 
186 186
     }
187 187
     
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 
196 196
 		$reply_to = wpinv_get_admin_email();
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to =  get_option( 'admin_email' );
198
+		if (!is_email($reply_to)) {
199
+			$reply_to = get_option('admin_email');
200 200
 		}
201 201
 
202 202
 		return $reply_to;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 */
209 209
 	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
210
+		return apply_filters('getpaid_email_content_type', 'text/html', $this);
211 211
     }
212 212
     
213 213
     /**
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return array wp_mail_data.
217 217
 	 */
218
-	public function ensure_email_content( $args ) {
218
+	public function ensure_email_content($args) {
219 219
 		$args['message'] = $this->wp_mail_data['email'];
220 220
 		return $args;
221 221
     }
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
  	 */
227 227
 	public function after_sending() {
228 228
 
229
-        do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
229
+        do_action('getpaid_after_send_email', $this->wp_mail_data);
230
+		remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
231
+		remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
232
+		remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
233
+		remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
234 234
 
235 235
 	}
236 236
 
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 2 patches
Indentation   +429 added lines, -429 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wpinv_subscriptions_page() {
16 16
 
17
-	?>
17
+    ?>
18 18
 
19 19
 	<div class="wrap">
20 20
 		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 
23 23
 			<?php
24 24
 
25
-				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
25
+                // Verify user permissions.
26
+                if ( ! wpinv_current_user_can_manage_invoicing() ) {
27 27
 
28
-					echo aui()->alert(
29
-						array(
30
-							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
-						)
33
-					);
28
+                    echo aui()->alert(
29
+                        array(
30
+                            'type'    => 'danger',
31
+                            'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
+                        )
33
+                    );
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+                } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
36 36
 
37
-					// Display a single subscription.
38
-					wpinv_recurring_subscription_details();
39
-				} else {
37
+                    // Display a single subscription.
38
+                    wpinv_recurring_subscription_details();
39
+                } else {
40 40
 
41
-					// Display a list of available subscriptions.
42
-					getpaid_print_subscriptions_list();
43
-				}
41
+                    // Display a list of available subscriptions.
42
+                    getpaid_print_subscriptions_list();
43
+                }
44 44
 
45
-			?>
45
+            ?>
46 46
 
47 47
 		</div>
48 48
 	</div>
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function getpaid_print_subscriptions_list() {
61 61
 
62
-	$subscribers_table = new WPInv_Subscriptions_List_Table();
63
-	$subscribers_table->prepare_items();
62
+    $subscribers_table = new WPInv_Subscriptions_List_Table();
63
+    $subscribers_table->prepare_items();
64 64
 
65
-	?>
65
+    ?>
66 66
 	<form id="subscribers-filter" class="bsui" method="get">
67 67
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
68 68
 		<?php $subscribers_table->views(); ?>
@@ -80,41 +80,41 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83
-	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->exists() ) {
83
+    // Fetch the subscription.
84
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
85
+    if ( ! $sub->exists() ) {
86 86
 
87
-		echo aui()->alert(
88
-			array(
89
-				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
91
-			)
92
-		);
87
+        echo aui()->alert(
88
+            array(
89
+                'type'    => 'danger',
90
+                'content' => __( 'Subscription not found.', 'invoicing' ),
91
+            )
92
+        );
93 93
 
94
-		return;
95
-	}
94
+        return;
95
+    }
96 96
 
97
-	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
97
+    // Use metaboxes to display the subscription details.
98
+    add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
99
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100 100
 
101
-	$subscription_id     = $sub->get_id();
102
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
103
-	$subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
101
+    $subscription_id     = $sub->get_id();
102
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
103
+    $subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
104 104
 
105
-	if ( 1 < count( $subscription_groups ) ) {
106
-		add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
107
-	}
105
+    if ( 1 < count( $subscription_groups ) ) {
106
+        add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
107
+    }
108 108
 
109
-	if ( ! empty( $subscription_group ) ) {
110
-		add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
111
-	}
109
+    if ( ! empty( $subscription_group ) ) {
110
+        add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
111
+    }
112 112
 
113
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
113
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
114 114
 
115
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
115
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
116 116
 
117
-	?>
117
+    ?>
118 118
 
119 119
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
120 120
 
@@ -154,45 +154,45 @@  discard block
 block discarded – undo
154 154
  */
155 155
 function getpaid_admin_subscription_details_metabox( $sub ) {
156 156
 
157
-	// Subscription items.
158
-	$subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
159
-	$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
160
-
161
-	// Prepare subscription detail columns.
162
-	$fields = apply_filters(
163
-		'getpaid_subscription_admin_page_fields',
164
-		array(
165
-			'subscription'   => __( 'Subscription', 'invoicing' ),
166
-			'customer'       => __( 'Customer', 'invoicing' ),
167
-			'amount'         => __( 'Amount', 'invoicing' ),
168
-			'start_date'     => __( 'Start Date', 'invoicing' ),
169
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
170
-			'renewals'       => __( 'Payments', 'invoicing' ),
171
-			'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
172
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
173
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
174
-			'status'         => __( 'Status', 'invoicing' ),
175
-		)
176
-	);
177
-
178
-	if ( ! $sub->is_active() ) {
179
-
180
-		if ( isset( $fields['renews_on'] ) ) {
181
-			unset( $fields['renews_on'] );
182
-		}
183
-
184
-		if ( isset( $fields['gateway'] ) ) {
185
-			unset( $fields['gateway'] );
186
-		}
187
-
188
-	}
189
-
190
-	$profile_id = $sub->get_profile_id();
191
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
192
-		unset( $fields['profile_id'] );
193
-	}
194
-
195
-	?>
157
+    // Subscription items.
158
+    $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
159
+    $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
160
+
161
+    // Prepare subscription detail columns.
162
+    $fields = apply_filters(
163
+        'getpaid_subscription_admin_page_fields',
164
+        array(
165
+            'subscription'   => __( 'Subscription', 'invoicing' ),
166
+            'customer'       => __( 'Customer', 'invoicing' ),
167
+            'amount'         => __( 'Amount', 'invoicing' ),
168
+            'start_date'     => __( 'Start Date', 'invoicing' ),
169
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
170
+            'renewals'       => __( 'Payments', 'invoicing' ),
171
+            'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
172
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
173
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
174
+            'status'         => __( 'Status', 'invoicing' ),
175
+        )
176
+    );
177
+
178
+    if ( ! $sub->is_active() ) {
179
+
180
+        if ( isset( $fields['renews_on'] ) ) {
181
+            unset( $fields['renews_on'] );
182
+        }
183
+
184
+        if ( isset( $fields['gateway'] ) ) {
185
+            unset( $fields['gateway'] );
186
+        }
187
+
188
+    }
189
+
190
+    $profile_id = $sub->get_profile_id();
191
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
192
+        unset( $fields['profile_id'] );
193
+    }
194
+
195
+    ?>
196 196
 
197 197
 		<table class="table table-borderless" style="font-size: 14px;">
198 198
 			<tbody>
@@ -226,20 +226,20 @@  discard block
 block discarded – undo
226 226
  */
227 227
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
228 228
 
229
-	$username = __( '(Missing User)', 'invoicing' );
229
+    $username = __( '(Missing User)', 'invoicing' );
230 230
 
231
-	$user = get_userdata( $subscription->get_customer_id() );
232
-	if ( $user ) {
231
+    $user = get_userdata( $subscription->get_customer_id() );
232
+    if ( $user ) {
233 233
 
234
-		$username = sprintf(
235
-			'<a href="user-edit.php?user_id=%s">%s</a>',
236
-			absint( $user->ID ),
237
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
238
-		);
234
+        $username = sprintf(
235
+            '<a href="user-edit.php?user_id=%s">%s</a>',
236
+            absint( $user->ID ),
237
+            ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
238
+        );
239 239
 
240
-	}
240
+    }
241 241
 
242
-	echo  $username;
242
+    echo  $username;
243 243
 }
244 244
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
245 245
 
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
  * @param WPInv_Subscription $subscription
250 250
  */
251 251
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
252
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
253
-	echo "<span>$amount</span>";
252
+    $amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
253
+    echo "<span>$amount</span>";
254 254
 }
255 255
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
256 256
 
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
  * @param WPInv_Subscription $subscription
261 261
  */
262 262
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
263
-	echo  '#' . absint( $subscription->get_id() );
263
+    echo  '#' . absint( $subscription->get_id() );
264 264
 }
265 265
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
266 266
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
  * @param WPInv_Subscription $subscription
271 271
  */
272 272
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
273
-	echo getpaid_format_date_value( $subscription->get_date_created() );
273
+    echo getpaid_format_date_value( $subscription->get_date_created() );
274 274
 }
275 275
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
276 276
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
  * @param WPInv_Subscription $subscription
281 281
  */
282 282
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
283
-	echo getpaid_format_date_value( $subscription->get_expiration() );
283
+    echo getpaid_format_date_value( $subscription->get_expiration() );
284 284
 }
285 285
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
286 286
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
  * @param WPInv_Subscription $subscription
291 291
  */
292 292
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
293
-	$max_bills = $subscription->get_bill_times();
294
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
293
+    $max_bills = $subscription->get_bill_times();
294
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
295 295
 }
296 296
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
297 297
 /**
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
  */
303 303
 function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) {
304 304
 
305
-	if ( empty( $subscription_group ) ) {
306
-		echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
307
-		return;
308
-	}
305
+    if ( empty( $subscription_group ) ) {
306
+        echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
307
+        return;
308
+    }
309 309
 
310
-	$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
311
-	echo implode( ' | ', $markup );
310
+    $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
311
+    echo implode( ' | ', $markup );
312 312
 
313 313
 }
314 314
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 );
@@ -320,13 +320,13 @@  discard block
 block discarded – undo
320 320
  */
321 321
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
322 322
 
323
-	$gateway = $subscription->get_gateway();
323
+    $gateway = $subscription->get_gateway();
324 324
 
325
-	if ( ! empty( $gateway ) ) {
326
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
327
-	} else {
328
-		echo "&mdash;";
329
-	}
325
+    if ( ! empty( $gateway ) ) {
326
+        echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
327
+    } else {
328
+        echo "&mdash;";
329
+    }
330 330
 
331 331
 }
332 332
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
  * @param WPInv_Subscription $subscription
338 338
  */
339 339
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
340
-	echo $subscription->get_status_label_html();
340
+    echo $subscription->get_status_label_html();
341 341
 }
342 342
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
343 343
 
@@ -348,29 +348,29 @@  discard block
 block discarded – undo
348 348
  */
349 349
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
350 350
 
351
-	$profile_id = $subscription->get_profile_id();
352
-
353
-	$input = aui()->input(
354
-		array(
355
-			'type'        => 'text',
356
-			'id'          => 'wpinv_subscription_profile_id',
357
-			'name'        => 'wpinv_subscription_profile_id',
358
-			'label'       => __( 'Profile Id', 'invoicing' ),
359
-			'label_type'  => 'hidden',
360
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
361
-			'value'       => sanitize_text_field( $profile_id ),
362
-			'input_group_right' => '',
363
-			'no_wrap'     => true,
364
-		)
365
-	);
366
-
367
-	echo str_ireplace( 'form-control', 'regular-text', $input );
368
-
369
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
370
-	if ( ! empty( $url ) ) {
371
-		$url = esc_url_raw( $url );
372
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
373
-	}
351
+    $profile_id = $subscription->get_profile_id();
352
+
353
+    $input = aui()->input(
354
+        array(
355
+            'type'        => 'text',
356
+            'id'          => 'wpinv_subscription_profile_id',
357
+            'name'        => 'wpinv_subscription_profile_id',
358
+            'label'       => __( 'Profile Id', 'invoicing' ),
359
+            'label_type'  => 'hidden',
360
+            'placeholder' => __( 'Profile Id', 'invoicing' ),
361
+            'value'       => sanitize_text_field( $profile_id ),
362
+            'input_group_right' => '',
363
+            'no_wrap'     => true,
364
+        )
365
+    );
366
+
367
+    echo str_ireplace( 'form-control', 'regular-text', $input );
368
+
369
+    $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
370
+    if ( ! empty( $url ) ) {
371
+        $url = esc_url_raw( $url );
372
+        echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
373
+    }
374 374
 
375 375
 }
376 376
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -382,39 +382,39 @@  discard block
 block discarded – undo
382 382
  */
383 383
 function getpaid_admin_subscription_update_metabox( $subscription ) {
384 384
 
385
-	?>
385
+    ?>
386 386
 	<div class="mt-3">
387 387
 
388 388
 		<?php
389
-			echo aui()->select(
390
-				array(
391
-					'options'          => getpaid_get_subscription_statuses(),
392
-					'name'             => 'subscription_status',
393
-					'id'               => 'subscription_status_update_select',
394
-					'required'         => true,
395
-					'no_wrap'          => false,
396
-					'label'            => __( 'Subscription Status', 'invoicing' ),
397
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
398
-					'select2'          => true,
399
-					'value'            => $subscription->get_status( 'edit' ),
400
-				)
401
-			);
402
-		?>
389
+            echo aui()->select(
390
+                array(
391
+                    'options'          => getpaid_get_subscription_statuses(),
392
+                    'name'             => 'subscription_status',
393
+                    'id'               => 'subscription_status_update_select',
394
+                    'required'         => true,
395
+                    'no_wrap'          => false,
396
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
397
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
398
+                    'select2'          => true,
399
+                    'value'            => $subscription->get_status( 'edit' ),
400
+                )
401
+            );
402
+        ?>
403 403
 
404 404
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
405 405
 
406 406
 		<?php
407
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
407
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
408 408
 
409
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
410
-			$anchor = __( 'Renew Subscription', 'invoicing' );
411
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
409
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
410
+            $anchor = __( 'Renew Subscription', 'invoicing' );
411
+            $title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
412 412
 
413
-			if ( $subscription->is_active() ) {
414
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
415
-			}
413
+            if ( $subscription->is_active() ) {
414
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
415
+            }
416 416
 
417
-	echo '</div></div>';
417
+    echo '</div></div>';
418 418
 }
419 419
 
420 420
 /**
@@ -425,33 +425,33 @@  discard block
 block discarded – undo
425 425
  */
426 426
 function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) {
427 427
 
428
-	$columns = apply_filters(
429
-		'getpaid_subscription_related_invoices_columns',
430
-		array(
431
-			'invoice'      => __( 'Invoice', 'invoicing' ),
432
-			'relationship' => __( 'Relationship', 'invoicing' ),
433
-			'date'         => __( 'Date', 'invoicing' ),
434
-			'status'       => __( 'Status', 'invoicing' ),
435
-			'total'        => __( 'Total', 'invoicing' ),
436
-		),
437
-		$subscription
438
-	);
439
-
440
-	// Prepare the invoices.
441
-	$payments = $subscription->get_child_payments( ! is_admin() );
442
-	$parent   = $subscription->get_parent_invoice();
443
-
444
-	if ( $parent->exists() ) {
445
-		$payments = array_merge( array( $parent ), $payments );
446
-	}
447
-
448
-	$table_class = 'w-100 bg-white';
449
-
450
-	if ( ! is_admin() ) {
451
-		$table_class = 'table table-bordered';
452
-	}
453
-
454
-	?>
428
+    $columns = apply_filters(
429
+        'getpaid_subscription_related_invoices_columns',
430
+        array(
431
+            'invoice'      => __( 'Invoice', 'invoicing' ),
432
+            'relationship' => __( 'Relationship', 'invoicing' ),
433
+            'date'         => __( 'Date', 'invoicing' ),
434
+            'status'       => __( 'Status', 'invoicing' ),
435
+            'total'        => __( 'Total', 'invoicing' ),
436
+        ),
437
+        $subscription
438
+    );
439
+
440
+    // Prepare the invoices.
441
+    $payments = $subscription->get_child_payments( ! is_admin() );
442
+    $parent   = $subscription->get_parent_invoice();
443
+
444
+    if ( $parent->exists() ) {
445
+        $payments = array_merge( array( $parent ), $payments );
446
+    }
447
+
448
+    $table_class = 'w-100 bg-white';
449
+
450
+    if ( ! is_admin() ) {
451
+        $table_class = 'table table-bordered';
452
+    }
453
+
454
+    ?>
455 455
 		<div class="m-0" style="overflow: auto;">
456 456
 
457 457
 			<table class="<?php echo $table_class; ?>">
@@ -459,14 +459,14 @@  discard block
 block discarded – undo
459 459
 				<thead>
460 460
 					<tr>
461 461
 						<?php
462
-							foreach ( $columns as $key => $label ) {
463
-								$key   = esc_attr( $key );
464
-								$label = sanitize_text_field( $label );
465
-								$class = 'text-left';
466
-
467
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
468
-							}
469
-						?>
462
+                            foreach ( $columns as $key => $label ) {
463
+                                $key   = esc_attr( $key );
464
+                                $label = sanitize_text_field( $label );
465
+                                $class = 'text-left';
466
+
467
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
468
+                            }
469
+                        ?>
470 470
 					</tr>
471 471
 				</thead>
472 472
 
@@ -482,73 +482,73 @@  discard block
 block discarded – undo
482 482
 
483 483
 					<?php
484 484
 
485
-						foreach( $payments as $payment ) :
485
+                        foreach( $payments as $payment ) :
486 486
 
487
-							// Ensure that we have an invoice.
488
-							$payment = new WPInv_Invoice( $payment );
487
+                            // Ensure that we have an invoice.
488
+                            $payment = new WPInv_Invoice( $payment );
489 489
 
490
-							// Abort if the invoice is invalid...
491
-							if ( ! $payment->exists() ) {
492
-								continue;
493
-							}
490
+                            // Abort if the invoice is invalid...
491
+                            if ( ! $payment->exists() ) {
492
+                                continue;
493
+                            }
494 494
 
495
-							// ... or belongs to a different subscription.
496
-							if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
497
-								continue;
498
-							}
495
+                            // ... or belongs to a different subscription.
496
+                            if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
497
+                                continue;
498
+                            }
499 499
 
500
-							echo '<tr>';
500
+                            echo '<tr>';
501 501
 
502
-								foreach ( array_keys( $columns ) as $key ) {
502
+                                foreach ( array_keys( $columns ) as $key ) {
503 503
 
504
-									$class = 'text-left';
504
+                                    $class = 'text-left';
505 505
 
506
-									echo "<td class='p-2 $class'>";
506
+                                    echo "<td class='p-2 $class'>";
507 507
 
508
-										switch( $key ) {
508
+                                        switch( $key ) {
509 509
 
510
-											case 'total':
511
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
512
-												break;
510
+                                            case 'total':
511
+                                                echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
512
+                                                break;
513 513
 
514
-											case 'relationship':
515
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
516
-												break;
514
+                                            case 'relationship':
515
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
516
+                                                break;
517 517
 
518
-											case 'date':
519
-												echo getpaid_format_date_value( $payment->get_date_created() );
520
-												break;
518
+                                            case 'date':
519
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
520
+                                                break;
521 521
 
522
-											case 'status':
522
+                                            case 'status':
523 523
 
524
-												$status = $payment->get_status_nicename();
525
-												if ( is_admin() ) {
526
-													$status = $payment->get_status_label_html();
527
-												}
524
+                                                $status = $payment->get_status_nicename();
525
+                                                if ( is_admin() ) {
526
+                                                    $status = $payment->get_status_label_html();
527
+                                                }
528 528
 
529
-												echo $status;
530
-												break;
529
+                                                echo $status;
530
+                                                break;
531 531
 
532
-											case 'invoice':
533
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
532
+                                            case 'invoice':
533
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
534 534
 
535
-												if ( ! is_admin() ) {
536
-													$link = esc_url( $payment->get_view_url() );
537
-												}
535
+                                                if ( ! is_admin() ) {
536
+                                                    $link = esc_url( $payment->get_view_url() );
537
+                                                }
538 538
 
539
-												$invoice = sanitize_text_field( $payment->get_number() );
540
-												echo "<a href='$link'>$invoice</a>";
541
-												break;
542
-										}
539
+                                                $invoice = sanitize_text_field( $payment->get_number() );
540
+                                                echo "<a href='$link'>$invoice</a>";
541
+                                                break;
542
+                                        }
543 543
 
544
-									echo '</td>';
544
+                                    echo '</td>';
545 545
 
546
-								}
546
+                                }
547 547
 
548
-							echo '</tr>';
548
+                            echo '</tr>';
549 549
 
550
-						endforeach;
551
-					?>
550
+                        endforeach;
551
+                    ?>
552 552
 
553 553
 				</tbody>
554 554
 
@@ -566,42 +566,42 @@  discard block
 block discarded – undo
566 566
  */
567 567
 function getpaid_admin_subscription_item_details_metabox( $subscription ) {
568 568
 
569
-	// Fetch the subscription group.
570
-	$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
569
+    // Fetch the subscription group.
570
+    $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
571 571
 
572
-	if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
573
-		return;
574
-	}
572
+    if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
573
+        return;
574
+    }
575 575
 
576
-	// Prepare table columns.
577
-	$columns = apply_filters(
578
-		'getpaid_subscription_item_details_columns',
579
-		array(
580
-			'item_name'    => __( 'Item', 'invoicing' ),
581
-			'price'        => __( 'Price', 'invoicing' ),
582
-			'tax'          => __( 'Tax', 'invoicing' ),
583
-			'discount'     => __( 'Discount', 'invoicing' ),
584
-			//'initial'      => __( 'Initial Amount', 'invoicing' ),
585
-			'recurring'    => __( 'Subtotal', 'invoicing' ),
586
-		),
587
-		$subscription
588
-	);
576
+    // Prepare table columns.
577
+    $columns = apply_filters(
578
+        'getpaid_subscription_item_details_columns',
579
+        array(
580
+            'item_name'    => __( 'Item', 'invoicing' ),
581
+            'price'        => __( 'Price', 'invoicing' ),
582
+            'tax'          => __( 'Tax', 'invoicing' ),
583
+            'discount'     => __( 'Discount', 'invoicing' ),
584
+            //'initial'      => __( 'Initial Amount', 'invoicing' ),
585
+            'recurring'    => __( 'Subtotal', 'invoicing' ),
586
+        ),
587
+        $subscription
588
+    );
589 589
 
590
-	// Prepare the invoices.
590
+    // Prepare the invoices.
591 591
 
592
-	$invoice = $subscription->get_parent_invoice();
592
+    $invoice = $subscription->get_parent_invoice();
593 593
 
594
-	if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
595
-		unset( $columns['tax'] );
596
-	}
594
+    if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
595
+        unset( $columns['tax'] );
596
+    }
597 597
 
598
-	$table_class = 'w-100 bg-white';
598
+    $table_class = 'w-100 bg-white';
599 599
 
600
-	if ( ! is_admin() ) {
601
-		$table_class = 'table table-bordered';
602
-	}
600
+    if ( ! is_admin() ) {
601
+        $table_class = 'table table-bordered';
602
+    }
603 603
 
604
-	?>
604
+    ?>
605 605
 		<div class="m-0" style="overflow: auto;">
606 606
 
607 607
 			<table class="<?php echo $table_class; ?>">
@@ -610,14 +610,14 @@  discard block
 block discarded – undo
610 610
 					<tr>
611 611
 						<?php
612 612
 
613
-							foreach ( $columns as $key => $label ) {
614
-								$key   = esc_attr( $key );
615
-								$label = sanitize_text_field( $label );
616
-								$class = 'text-left';
613
+                            foreach ( $columns as $key => $label ) {
614
+                                $key   = esc_attr( $key );
615
+                                $label = sanitize_text_field( $label );
616
+                                $class = 'text-left';
617 617
 
618
-								echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
619
-							}
620
-						?>
618
+                                echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
619
+                            }
620
+                        ?>
621 621
 					</tr>
622 622
 				</thead>
623 623
 
@@ -625,106 +625,106 @@  discard block
 block discarded – undo
625 625
 
626 626
 					<?php
627 627
 
628
-						foreach( $subscription_group['items'] as $subscription_group_item ) :
628
+                        foreach( $subscription_group['items'] as $subscription_group_item ) :
629 629
 
630
-							echo '<tr>';
630
+                            echo '<tr>';
631 631
 
632
-								foreach ( array_keys( $columns ) as $key ) {
632
+                                foreach ( array_keys( $columns ) as $key ) {
633 633
 
634
-									$class = 'text-left';
634
+                                    $class = 'text-left';
635 635
 
636
-									echo "<td class='p-2 $class'>";
636
+                                    echo "<td class='p-2 $class'>";
637 637
 
638
-										switch( $key ) {
638
+                                        switch( $key ) {
639 639
 
640
-											case 'item_name':
641
-												$item_name = get_the_title( $subscription_group_item['item_id'] );
642
-												$item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
640
+                                            case 'item_name':
641
+                                                $item_name = get_the_title( $subscription_group_item['item_id'] );
642
+                                                $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
643 643
 
644
-												if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
645
-													echo sanitize_text_field( $item_name );
646
-												} else {
647
-													printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (float) $subscription_group_item['quantity'] );
648
-												}
644
+                                                if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
645
+                                                    echo sanitize_text_field( $item_name );
646
+                                                } else {
647
+                                                    printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (float) $subscription_group_item['quantity'] );
648
+                                                }
649 649
 
650
-												break;
650
+                                                break;
651 651
 
652
-											case 'price':
653
-												echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
654
-												break;
652
+                                            case 'price':
653
+                                                echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
654
+                                                break;
655 655
 
656
-											case 'tax':
657
-												echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
658
-												break;
656
+                                            case 'tax':
657
+                                                echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
658
+                                                break;
659 659
 
660
-											case 'discount':
661
-												echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
662
-												break;
660
+                                            case 'discount':
661
+                                                echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
662
+                                                break;
663 663
 
664
-											case 'initial':
665
-												echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
666
-												break;
664
+                                            case 'initial':
665
+                                                echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
666
+                                                break;
667 667
 
668
-											case 'recurring':
669
-												echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
670
-												break;
668
+                                            case 'recurring':
669
+                                                echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
670
+                                                break;
671 671
 
672
-										}
672
+                                        }
673 673
 
674
-									echo '</td>';
674
+                                    echo '</td>';
675 675
 
676
-								}
676
+                                }
677 677
 
678
-							echo '</tr>';
678
+                            echo '</tr>';
679 679
 
680
-						endforeach;
680
+                        endforeach;
681 681
 
682
-						foreach( $subscription_group['fees'] as $subscription_group_fee ) :
682
+                        foreach( $subscription_group['fees'] as $subscription_group_fee ) :
683 683
 
684
-							echo '<tr>';
684
+                            echo '<tr>';
685 685
 
686
-								foreach ( array_keys( $columns ) as $key ) {
686
+                                foreach ( array_keys( $columns ) as $key ) {
687 687
 
688
-									$class = 'text-left';
688
+                                    $class = 'text-left';
689 689
 
690
-									echo "<td class='p-2 $class'>";
690
+                                    echo "<td class='p-2 $class'>";
691 691
 
692
-										switch( $key ) {
692
+                                        switch( $key ) {
693 693
 
694
-											case 'item_name':
695
-												echo sanitize_text_field( $subscription_group_fee['name'] );
696
-												break;
694
+                                            case 'item_name':
695
+                                                echo sanitize_text_field( $subscription_group_fee['name'] );
696
+                                                break;
697 697
 
698
-											case 'price':
699
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
700
-												break;
698
+                                            case 'price':
699
+                                                echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
700
+                                                break;
701 701
 
702
-											case 'tax':
703
-												echo "&mdash;";
704
-												break;
702
+                                            case 'tax':
703
+                                                echo "&mdash;";
704
+                                                break;
705 705
 
706
-											case 'discount':
707
-												echo "&mdash;";
708
-												break;
706
+                                            case 'discount':
707
+                                                echo "&mdash;";
708
+                                                break;
709 709
 
710
-											case 'initial':
711
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
712
-												break;
710
+                                            case 'initial':
711
+                                                echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
712
+                                                break;
713 713
 
714
-											case 'recurring':
715
-												echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
716
-												break;
714
+                                            case 'recurring':
715
+                                                echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
716
+                                                break;
717 717
 
718
-										}
718
+                                        }
719 719
 
720
-									echo '</td>';
720
+                                    echo '</td>';
721 721
 
722
-								}
722
+                                }
723 723
 
724
-							echo '</tr>';
724
+                            echo '</tr>';
725 725
 
726
-						endforeach;
727
-					?>
726
+                        endforeach;
727
+                    ?>
728 728
 
729 729
 				</tbody>
730 730
 
@@ -743,38 +743,38 @@  discard block
 block discarded – undo
743 743
  */
744 744
 function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) {
745 745
 
746
-	// Fetch the subscription groups.
747
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
748
-
749
-	if ( empty( $subscription_groups ) ) {
750
-		return;
751
-	}
752
-
753
-	// Prepare table columns.
754
-	$columns = apply_filters(
755
-		'getpaid_subscription_related_subscriptions_columns',
756
-		array(
757
-			'subscription'      => __( 'Subscription', 'invoicing' ),
758
-			'start_date'        => __( 'Start Date', 'invoicing' ),
759
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
760
-			'renewals'          => __( 'Payments', 'invoicing' ),
761
-			'item'              => __( 'Items', 'invoicing' ),
762
-			'status'            => __( 'Status', 'invoicing' ),
763
-		),
764
-		$subscription
765
-	);
766
-
767
-	if ( $subscription->get_status() == 'pending' ) {
768
-		unset( $columns['start_date'], $columns['renewal_date'] );
769
-	}
770
-
771
-	$table_class = 'w-100 bg-white';
772
-
773
-	if ( ! is_admin() ) {
774
-		$table_class = 'table table-bordered';
775
-	}
776
-
777
-	?>
746
+    // Fetch the subscription groups.
747
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
748
+
749
+    if ( empty( $subscription_groups ) ) {
750
+        return;
751
+    }
752
+
753
+    // Prepare table columns.
754
+    $columns = apply_filters(
755
+        'getpaid_subscription_related_subscriptions_columns',
756
+        array(
757
+            'subscription'      => __( 'Subscription', 'invoicing' ),
758
+            'start_date'        => __( 'Start Date', 'invoicing' ),
759
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
760
+            'renewals'          => __( 'Payments', 'invoicing' ),
761
+            'item'              => __( 'Items', 'invoicing' ),
762
+            'status'            => __( 'Status', 'invoicing' ),
763
+        ),
764
+        $subscription
765
+    );
766
+
767
+    if ( $subscription->get_status() == 'pending' ) {
768
+        unset( $columns['start_date'], $columns['renewal_date'] );
769
+    }
770
+
771
+    $table_class = 'w-100 bg-white';
772
+
773
+    if ( ! is_admin() ) {
774
+        $table_class = 'table table-bordered';
775
+    }
776
+
777
+    ?>
778 778
 		<div class="m-0" style="overflow: auto;">
779 779
 
780 780
 			<table class="<?php echo $table_class; ?>">
@@ -783,14 +783,14 @@  discard block
 block discarded – undo
783 783
 					<tr>
784 784
 						<?php
785 785
 
786
-							foreach ( $columns as $key => $label ) {
787
-								$key   = esc_attr( $key );
788
-								$label = sanitize_text_field( $label );
789
-								$class = 'text-left';
786
+                            foreach ( $columns as $key => $label ) {
787
+                                $key   = esc_attr( $key );
788
+                                $label = sanitize_text_field( $label );
789
+                                $class = 'text-left';
790 790
 
791
-								echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
792
-							}
793
-						?>
791
+                                echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
792
+                            }
793
+                        ?>
794 794
 					</tr>
795 795
 				</thead>
796 796
 
@@ -798,74 +798,74 @@  discard block
 block discarded – undo
798 798
 
799 799
 					<?php
800 800
 
801
-						foreach( $subscription_groups as $subscription_group ) :
801
+                        foreach( $subscription_groups as $subscription_group ) :
802 802
 
803
-							// Do not list current subscription.
804
-							if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
805
-								continue;
806
-							}
803
+                            // Do not list current subscription.
804
+                            if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
805
+                                continue;
806
+                            }
807 807
 
808
-							// Ensure the subscription exists.
809
-							$_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
808
+                            // Ensure the subscription exists.
809
+                            $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
810 810
 
811
-							if ( ! $_suscription->exists() ) {
812
-								continue;
813
-							}
811
+                            if ( ! $_suscription->exists() ) {
812
+                                continue;
813
+                            }
814 814
 
815
-							echo '<tr>';
815
+                            echo '<tr>';
816 816
 
817
-								foreach ( array_keys( $columns ) as $key ) {
817
+                                foreach ( array_keys( $columns ) as $key ) {
818 818
 
819
-									$class = 'text-left';
819
+                                    $class = 'text-left';
820 820
 
821
-									echo "<td class='p-2 $class'>";
821
+                                    echo "<td class='p-2 $class'>";
822 822
 
823
-										switch( $key ) {
823
+                                        switch( $key ) {
824 824
 
825
-											case 'status':
826
-												echo $_suscription->get_status_label_html();
827
-												break;
825
+                                            case 'status':
826
+                                                echo $_suscription->get_status_label_html();
827
+                                                break;
828 828
 
829
-											case 'item':
830
-												$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
831
-												echo implode( ' | ', $markup );
832
-												break;
829
+                                            case 'item':
830
+                                                $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
831
+                                                echo implode( ' | ', $markup );
832
+                                                break;
833 833
 
834
-											case 'renewals':
835
-												$max_bills = $_suscription->get_bill_times();
836
-												echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
837
-												break;
834
+                                            case 'renewals':
835
+                                                $max_bills = $_suscription->get_bill_times();
836
+                                                echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
837
+                                                break;
838 838
 
839
-											case 'renewal_date':
840
-												echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
841
-												break;
839
+                                            case 'renewal_date':
840
+                                                echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
841
+                                                break;
842 842
 
843
-											case 'start_date':
844
-												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
845
-												break;
843
+                                            case 'start_date':
844
+                                                echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
845
+                                                break;
846 846
 
847
-											case 'subscription':
848
-												$url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
849
-												printf(
850
-													'%1$s#%2$s%3$s',
851
-													'<a href="' . esc_url( $url ) . '">',
852
-													'<strong>' . intval( $_suscription->get_id() ) . '</strong>',
853
-													'</a>'
854
-												);
847
+                                            case 'subscription':
848
+                                                $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
849
+                                                printf(
850
+                                                    '%1$s#%2$s%3$s',
851
+                                                    '<a href="' . esc_url( $url ) . '">',
852
+                                                    '<strong>' . intval( $_suscription->get_id() ) . '</strong>',
853
+                                                    '</a>'
854
+                                                );
855 855
 
856
-												echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
857
-												break;
856
+                                                echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
857
+                                                break;
858 858
 
859
-										}
859
+                                        }
860 860
 
861
-									echo '</td>';
861
+                                    echo '</td>';
862 862
 
863
-								}
863
+                                }
864 864
 
865
-							echo '</tr>';
865
+                            echo '</tr>';
866 866
 
867
-						endforeach;
868
-					?>
867
+                        endforeach;
868
+                    ?>
869 869
 
870 870
 				</tbody>
871 871
 
Please login to merge, or discard this patch.
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Contains functions that display the subscriptions admin page.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Render the Subscriptions page
@@ -17,22 +17,22 @@  discard block
 block discarded – undo
17 17
 	?>
18 18
 
19 19
 	<div class="wrap">
20
-		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
20
+		<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
21 21
 		<div class="bsui">
22 22
 
23 23
 			<?php
24 24
 
25 25
 				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
26
+				if (!wpinv_current_user_can_manage_invoicing()) {
27 27
 
28 28
 					echo aui()->alert(
29 29
 						array(
30 30
 							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
31
+							'content' => __('You are not permitted to view this page.', 'invoicing'),
32 32
 						)
33 33
 					);
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+				} else if (!empty($_GET['id']) && is_numeric($_GET['id'])) {
36 36
 
37 37
 					// Display a single subscription.
38 38
 					wpinv_recurring_subscription_details();
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83 83
 	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->exists() ) {
84
+	$sub = new WPInv_Subscription((int) $_GET['id']);
85
+	if (!$sub->exists()) {
86 86
 
87 87
 		echo aui()->alert(
88 88
 			array(
89 89
 				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
90
+				'content' => __('Subscription not found.', 'invoicing'),
91 91
 			)
92 92
 		);
93 93
 
@@ -95,45 +95,45 @@  discard block
 block discarded – undo
95 95
 	}
96 96
 
97 97
 	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
98
+	add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high');
99
+	add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side');
100 100
 
101 101
 	$subscription_id     = $sub->get_id();
102
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
103
-	$subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
102
+	$subscription_groups = getpaid_get_invoice_subscription_groups($sub->get_parent_invoice_id());
103
+	$subscription_group  = wp_list_filter($subscription_groups, compact('subscription_id'));
104 104
 
105
-	if ( 1 < count( $subscription_groups ) ) {
106
-		add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
105
+	if (1 < count($subscription_groups)) {
106
+		add_meta_box('getpaid_admin_subscription_related_subscriptions_metabox', __('Related Subscriptions', 'invoicing'), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced');
107 107
 	}
108 108
 
109
-	if ( ! empty( $subscription_group ) ) {
110
-		add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
109
+	if (!empty($subscription_group)) {
110
+		add_meta_box('getpaid_admin_subscription_item_details_metabox', __('Subscription Items', 'invoicing'), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low');
111 111
 	}
112 112
 
113
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
113
+	add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Related Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced');
114 114
 
115
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
115
+	do_action('getpaid_admin_single_subscription_register_metabox', $sub);
116 116
 
117 117
 	?>
118 118
 
119
-		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
119
+		<form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>">
120 120
 
121
-			<?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?>
122
-			<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
123
-			<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
121
+			<?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?>
122
+			<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
123
+			<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
124 124
 			<input type="hidden" name="getpaid-admin-action" value="update_single_subscription" />
125
-			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" />
125
+			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" />
126 126
 
127 127
 			<div id="poststuff">
128 128
 				<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
129 129
 
130 130
 					<div id="postbox-container-1" class="postbox-container">
131
-						<?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?>
131
+						<?php do_meta_boxes(get_current_screen(), 'side', $sub); ?>
132 132
 					</div>
133 133
 
134 134
 					<div id="postbox-container-2" class="postbox-container">
135
-						<?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?>
136
-						<?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?>
135
+						<?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?>
136
+						<?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?>
137 137
 					</div>
138 138
 
139 139
 				</div>
@@ -152,44 +152,44 @@  discard block
 block discarded – undo
152 152
  *
153 153
  * @param WPInv_Subscription $sub
154 154
  */
155
-function getpaid_admin_subscription_details_metabox( $sub ) {
155
+function getpaid_admin_subscription_details_metabox($sub) {
156 156
 
157 157
 	// Subscription items.
158
-	$subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
159
-	$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
158
+	$subscription_group = getpaid_get_invoice_subscription_group($sub->get_parent_invoice_id(), $sub->get_id());
159
+	$items_count        = empty($subscription_group) ? 1 : count($subscription_group['items']);
160 160
 
161 161
 	// Prepare subscription detail columns.
162 162
 	$fields = apply_filters(
163 163
 		'getpaid_subscription_admin_page_fields',
164 164
 		array(
165
-			'subscription'   => __( 'Subscription', 'invoicing' ),
166
-			'customer'       => __( 'Customer', 'invoicing' ),
167
-			'amount'         => __( 'Amount', 'invoicing' ),
168
-			'start_date'     => __( 'Start Date', 'invoicing' ),
169
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
170
-			'renewals'       => __( 'Payments', 'invoicing' ),
171
-			'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
172
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
173
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
174
-			'status'         => __( 'Status', 'invoicing' ),
165
+			'subscription'   => __('Subscription', 'invoicing'),
166
+			'customer'       => __('Customer', 'invoicing'),
167
+			'amount'         => __('Amount', 'invoicing'),
168
+			'start_date'     => __('Start Date', 'invoicing'),
169
+			'renews_on'      => __('Next Payment', 'invoicing'),
170
+			'renewals'       => __('Payments', 'invoicing'),
171
+			'item'           => _n('Item', 'Items', $items_count, 'invoicing'),
172
+			'gateway'        => __('Payment Method', 'invoicing'),
173
+			'profile_id'     => __('Profile ID', 'invoicing'),
174
+			'status'         => __('Status', 'invoicing'),
175 175
 		)
176 176
 	);
177 177
 
178
-	if ( ! $sub->is_active() ) {
178
+	if (!$sub->is_active()) {
179 179
 
180
-		if ( isset( $fields['renews_on'] ) ) {
181
-			unset( $fields['renews_on'] );
180
+		if (isset($fields['renews_on'])) {
181
+			unset($fields['renews_on']);
182 182
 		}
183 183
 
184
-		if ( isset( $fields['gateway'] ) ) {
185
-			unset( $fields['gateway'] );
184
+		if (isset($fields['gateway'])) {
185
+			unset($fields['gateway']);
186 186
 		}
187 187
 
188 188
 	}
189 189
 
190 190
 	$profile_id = $sub->get_profile_id();
191
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
192
-		unset( $fields['profile_id'] );
191
+	if (empty($profile_id) && isset($fields['profile_id'])) {
192
+		unset($fields['profile_id']);
193 193
 	}
194 194
 
195 195
 	?>
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
 		<table class="table table-borderless" style="font-size: 14px;">
198 198
 			<tbody>
199 199
 
200
-				<?php foreach ( $fields as $key => $label ) : ?>
200
+				<?php foreach ($fields as $key => $label) : ?>
201 201
 
202
-					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>">
202
+					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>">
203 203
 
204 204
 						<th class="w-25" style="font-weight: 500;">
205
-							<?php echo sanitize_text_field( $label ); ?>
205
+							<?php echo sanitize_text_field($label); ?>
206 206
 						</th>
207 207
 
208 208
 						<td class="w-75 text-muted">
209
-							<?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub, $subscription_group ); ?>
209
+							<?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub, $subscription_group); ?>
210 210
 						</td>
211 211
 
212 212
 					</tr>
@@ -224,129 +224,129 @@  discard block
 block discarded – undo
224 224
  *
225 225
  * @param WPInv_Subscription $subscription
226 226
  */
227
-function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
227
+function getpaid_admin_subscription_metabox_display_customer($subscription) {
228 228
 
229
-	$username = __( '(Missing User)', 'invoicing' );
229
+	$username = __('(Missing User)', 'invoicing');
230 230
 
231
-	$user = get_userdata( $subscription->get_customer_id() );
232
-	if ( $user ) {
231
+	$user = get_userdata($subscription->get_customer_id());
232
+	if ($user) {
233 233
 
234 234
 		$username = sprintf(
235 235
 			'<a href="user-edit.php?user_id=%s">%s</a>',
236
-			absint( $user->ID ),
237
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
236
+			absint($user->ID),
237
+			!empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email)
238 238
 		);
239 239
 
240 240
 	}
241 241
 
242 242
 	echo  $username;
243 243
 }
244
-add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
244
+add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer');
245 245
 
246 246
 /**
247 247
  * Displays the subscription amount.
248 248
  *
249 249
  * @param WPInv_Subscription $subscription
250 250
  */
251
-function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
252
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
251
+function getpaid_admin_subscription_metabox_display_amount($subscription) {
252
+	$amount = sanitize_text_field(getpaid_get_formatted_subscription_amount($subscription));
253 253
 	echo "<span>$amount</span>";
254 254
 }
255
-add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
255
+add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount');
256 256
 
257 257
 /**
258 258
  * Displays the subscription id.
259 259
  *
260 260
  * @param WPInv_Subscription $subscription
261 261
  */
262
-function getpaid_admin_subscription_metabox_display_id( $subscription ) {
263
-	echo  '#' . absint( $subscription->get_id() );
262
+function getpaid_admin_subscription_metabox_display_id($subscription) {
263
+	echo  '#' . absint($subscription->get_id());
264 264
 }
265
-add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
265
+add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id');
266 266
 
267 267
 /**
268 268
  * Displays the subscription renewal date.
269 269
  *
270 270
  * @param WPInv_Subscription $subscription
271 271
  */
272
-function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
273
-	echo getpaid_format_date_value( $subscription->get_date_created() );
272
+function getpaid_admin_subscription_metabox_display_start_date($subscription) {
273
+	echo getpaid_format_date_value($subscription->get_date_created());
274 274
 }
275
-add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
275
+add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date');
276 276
 
277 277
 /**
278 278
  * Displays the subscription renewal date.
279 279
  *
280 280
  * @param WPInv_Subscription $subscription
281 281
  */
282
-function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
283
-	echo getpaid_format_date_value( $subscription->get_expiration() );
282
+function getpaid_admin_subscription_metabox_display_renews_on($subscription) {
283
+	echo getpaid_format_date_value($subscription->get_expiration());
284 284
 }
285
-add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
285
+add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on');
286 286
 
287 287
 /**
288 288
  * Displays the subscription renewal count.
289 289
  *
290 290
  * @param WPInv_Subscription $subscription
291 291
  */
292
-function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
292
+function getpaid_admin_subscription_metabox_display_renewals($subscription) {
293 293
 	$max_bills = $subscription->get_bill_times();
294
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
294
+	echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
295 295
 }
296
-add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
296
+add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals');
297 297
 /**
298 298
  * Displays the subscription item.
299 299
  *
300 300
  * @param WPInv_Subscription $subscription
301 301
  * @param false|array $subscription_group
302 302
  */
303
-function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) {
303
+function getpaid_admin_subscription_metabox_display_item($subscription, $subscription_group = false) {
304 304
 
305
-	if ( empty( $subscription_group ) ) {
306
-		echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
305
+	if (empty($subscription_group)) {
306
+		echo WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id());
307 307
 		return;
308 308
 	}
309 309
 
310
-	$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
311
-	echo implode( ' | ', $markup );
310
+	$markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items']));
311
+	echo implode(' | ', $markup);
312 312
 
313 313
 }
314
-add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 );
314
+add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2);
315 315
 
316 316
 /**
317 317
  * Displays the subscription gateway.
318 318
  *
319 319
  * @param WPInv_Subscription $subscription
320 320
  */
321
-function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
321
+function getpaid_admin_subscription_metabox_display_gateway($subscription) {
322 322
 
323 323
 	$gateway = $subscription->get_gateway();
324 324
 
325
-	if ( ! empty( $gateway ) ) {
326
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
325
+	if (!empty($gateway)) {
326
+		echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway));
327 327
 	} else {
328 328
 		echo "&mdash;";
329 329
 	}
330 330
 
331 331
 }
332
-add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
332
+add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway');
333 333
 
334 334
 /**
335 335
  * Displays the subscription status.
336 336
  *
337 337
  * @param WPInv_Subscription $subscription
338 338
  */
339
-function getpaid_admin_subscription_metabox_display_status( $subscription ) {
339
+function getpaid_admin_subscription_metabox_display_status($subscription) {
340 340
 	echo $subscription->get_status_label_html();
341 341
 }
342
-add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
342
+add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status');
343 343
 
344 344
 /**
345 345
  * Displays the subscription profile id.
346 346
  *
347 347
  * @param WPInv_Subscription $subscription
348 348
  */
349
-function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
349
+function getpaid_admin_subscription_metabox_display_profile_id($subscription) {
350 350
 
351 351
 	$profile_id = $subscription->get_profile_id();
352 352
 
@@ -355,32 +355,32 @@  discard block
 block discarded – undo
355 355
 			'type'        => 'text',
356 356
 			'id'          => 'wpinv_subscription_profile_id',
357 357
 			'name'        => 'wpinv_subscription_profile_id',
358
-			'label'       => __( 'Profile Id', 'invoicing' ),
358
+			'label'       => __('Profile Id', 'invoicing'),
359 359
 			'label_type'  => 'hidden',
360
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
361
-			'value'       => sanitize_text_field( $profile_id ),
360
+			'placeholder' => __('Profile Id', 'invoicing'),
361
+			'value'       => sanitize_text_field($profile_id),
362 362
 			'input_group_right' => '',
363 363
 			'no_wrap'     => true,
364 364
 		)
365 365
 	);
366 366
 
367
-	echo str_ireplace( 'form-control', 'regular-text', $input );
367
+	echo str_ireplace('form-control', 'regular-text', $input);
368 368
 
369
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
370
-	if ( ! empty( $url ) ) {
371
-		$url = esc_url_raw( $url );
372
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
369
+	$url = apply_filters('getpaid_remote_subscription_profile_url', '', $subscription);
370
+	if (!empty($url)) {
371
+		$url = esc_url_raw($url);
372
+		echo '&nbsp;<a href="' . $url . '" title="' . __('View in Gateway', 'invoicing') . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
373 373
 	}
374 374
 
375 375
 }
376
-add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
376
+add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id');
377 377
 
378 378
 /**
379 379
  * Displays the subscriptions update metabox.
380 380
  *
381 381
  * @param WPInv_Subscription $subscription
382 382
  */
383
-function getpaid_admin_subscription_update_metabox( $subscription ) {
383
+function getpaid_admin_subscription_update_metabox($subscription) {
384 384
 
385 385
 	?>
386 386
 	<div class="mt-3">
@@ -393,10 +393,10 @@  discard block
 block discarded – undo
393 393
 					'id'               => 'subscription_status_update_select',
394 394
 					'required'         => true,
395 395
 					'no_wrap'          => false,
396
-					'label'            => __( 'Subscription Status', 'invoicing' ),
397
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
396
+					'label'            => __('Subscription Status', 'invoicing'),
397
+					'help_text'        => __('Updating the status will trigger related actions and hooks', 'invoicing'),
398 398
 					'select2'          => true,
399
-					'value'            => $subscription->get_status( 'edit' ),
399
+					'value'            => $subscription->get_status('edit'),
400 400
 				)
401 401
 			);
402 402
 		?>
@@ -404,13 +404,13 @@  discard block
 block discarded – undo
404 404
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
405 405
 
406 406
 		<?php
407
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
407
+			submit_button(__('Update', 'invoicing'), 'primary', 'submit', false);
408 408
 
409
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
410
-			$anchor = __( 'Renew Subscription', 'invoicing' );
411
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
409
+			$url    = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce'));
410
+			$anchor = __('Renew Subscription', 'invoicing');
411
+			$title  = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing');
412 412
 
413
-			if ( $subscription->is_active() ) {
413
+			if ($subscription->is_active()) {
414 414
 				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
415 415
 			}
416 416
 
@@ -423,31 +423,31 @@  discard block
 block discarded – undo
423 423
  * @param WPInv_Subscription $subscription
424 424
  * @param bool $strict Whether or not to skip invoices of sibling subscriptions
425 425
  */
426
-function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) {
426
+function getpaid_admin_subscription_invoice_details_metabox($subscription, $strict = true) {
427 427
 
428 428
 	$columns = apply_filters(
429 429
 		'getpaid_subscription_related_invoices_columns',
430 430
 		array(
431
-			'invoice'      => __( 'Invoice', 'invoicing' ),
432
-			'relationship' => __( 'Relationship', 'invoicing' ),
433
-			'date'         => __( 'Date', 'invoicing' ),
434
-			'status'       => __( 'Status', 'invoicing' ),
435
-			'total'        => __( 'Total', 'invoicing' ),
431
+			'invoice'      => __('Invoice', 'invoicing'),
432
+			'relationship' => __('Relationship', 'invoicing'),
433
+			'date'         => __('Date', 'invoicing'),
434
+			'status'       => __('Status', 'invoicing'),
435
+			'total'        => __('Total', 'invoicing'),
436 436
 		),
437 437
 		$subscription
438 438
 	);
439 439
 
440 440
 	// Prepare the invoices.
441
-	$payments = $subscription->get_child_payments( ! is_admin() );
441
+	$payments = $subscription->get_child_payments(!is_admin());
442 442
 	$parent   = $subscription->get_parent_invoice();
443 443
 
444
-	if ( $parent->exists() ) {
445
-		$payments = array_merge( array( $parent ), $payments );
444
+	if ($parent->exists()) {
445
+		$payments = array_merge(array($parent), $payments);
446 446
 	}
447 447
 
448 448
 	$table_class = 'w-100 bg-white';
449 449
 
450
-	if ( ! is_admin() ) {
450
+	if (!is_admin()) {
451 451
 		$table_class = 'table table-bordered';
452 452
 	}
453 453
 
@@ -459,9 +459,9 @@  discard block
 block discarded – undo
459 459
 				<thead>
460 460
 					<tr>
461 461
 						<?php
462
-							foreach ( $columns as $key => $label ) {
463
-								$key   = esc_attr( $key );
464
-								$label = sanitize_text_field( $label );
462
+							foreach ($columns as $key => $label) {
463
+								$key   = esc_attr($key);
464
+								$label = sanitize_text_field($label);
465 465
 								$class = 'text-left';
466 466
 
467 467
 								echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -472,57 +472,57 @@  discard block
 block discarded – undo
472 472
 
473 473
 				<tbody>
474 474
 
475
-					<?php if ( empty( $payments ) ) : ?>
475
+					<?php if (empty($payments)) : ?>
476 476
 						<tr>
477 477
 							<td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted">
478
-								<?php _e( 'This subscription has no invoices.', 'invoicing' ); ?>
478
+								<?php _e('This subscription has no invoices.', 'invoicing'); ?>
479 479
 							</td>
480 480
 						</tr>
481 481
 					<?php endif; ?>
482 482
 
483 483
 					<?php
484 484
 
485
-						foreach( $payments as $payment ) :
485
+						foreach ($payments as $payment) :
486 486
 
487 487
 							// Ensure that we have an invoice.
488
-							$payment = new WPInv_Invoice( $payment );
488
+							$payment = new WPInv_Invoice($payment);
489 489
 
490 490
 							// Abort if the invoice is invalid...
491
-							if ( ! $payment->exists() ) {
491
+							if (!$payment->exists()) {
492 492
 								continue;
493 493
 							}
494 494
 
495 495
 							// ... or belongs to a different subscription.
496
-							if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
496
+							if ($strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id()) {
497 497
 								continue;
498 498
 							}
499 499
 
500 500
 							echo '<tr>';
501 501
 
502
-								foreach ( array_keys( $columns ) as $key ) {
502
+								foreach (array_keys($columns) as $key) {
503 503
 
504 504
 									$class = 'text-left';
505 505
 
506 506
 									echo "<td class='p-2 $class'>";
507 507
 
508
-										switch( $key ) {
508
+										switch ($key) {
509 509
 
510 510
 											case 'total':
511
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
511
+												echo '<strong>' . wpinv_price($payment->get_total(), $payment->get_currency()) . '</strong>';
512 512
 												break;
513 513
 
514 514
 											case 'relationship':
515
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
515
+												echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing');
516 516
 												break;
517 517
 
518 518
 											case 'date':
519
-												echo getpaid_format_date_value( $payment->get_date_created() );
519
+												echo getpaid_format_date_value($payment->get_date_created());
520 520
 												break;
521 521
 
522 522
 											case 'status':
523 523
 
524 524
 												$status = $payment->get_status_nicename();
525
-												if ( is_admin() ) {
525
+												if (is_admin()) {
526 526
 													$status = $payment->get_status_label_html();
527 527
 												}
528 528
 
@@ -530,13 +530,13 @@  discard block
 block discarded – undo
530 530
 												break;
531 531
 
532 532
 											case 'invoice':
533
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
533
+												$link = esc_url(get_edit_post_link($payment->get_id()));
534 534
 
535
-												if ( ! is_admin() ) {
536
-													$link = esc_url( $payment->get_view_url() );
535
+												if (!is_admin()) {
536
+													$link = esc_url($payment->get_view_url());
537 537
 												}
538 538
 
539
-												$invoice = sanitize_text_field( $payment->get_number() );
539
+												$invoice = sanitize_text_field($payment->get_number());
540 540
 												echo "<a href='$link'>$invoice</a>";
541 541
 												break;
542 542
 										}
@@ -564,12 +564,12 @@  discard block
 block discarded – undo
564 564
  *
565 565
  * @param WPInv_Subscription $subscription
566 566
  */
567
-function getpaid_admin_subscription_item_details_metabox( $subscription ) {
567
+function getpaid_admin_subscription_item_details_metabox($subscription) {
568 568
 
569 569
 	// Fetch the subscription group.
570
-	$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
570
+	$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_payment_id(), $subscription->get_id());
571 571
 
572
-	if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
572
+	if (empty($subscription_group) || empty($subscription_group['items'])) {
573 573
 		return;
574 574
 	}
575 575
 
@@ -577,12 +577,12 @@  discard block
 block discarded – undo
577 577
 	$columns = apply_filters(
578 578
 		'getpaid_subscription_item_details_columns',
579 579
 		array(
580
-			'item_name'    => __( 'Item', 'invoicing' ),
581
-			'price'        => __( 'Price', 'invoicing' ),
582
-			'tax'          => __( 'Tax', 'invoicing' ),
583
-			'discount'     => __( 'Discount', 'invoicing' ),
580
+			'item_name'    => __('Item', 'invoicing'),
581
+			'price'        => __('Price', 'invoicing'),
582
+			'tax'          => __('Tax', 'invoicing'),
583
+			'discount'     => __('Discount', 'invoicing'),
584 584
 			//'initial'      => __( 'Initial Amount', 'invoicing' ),
585
-			'recurring'    => __( 'Subtotal', 'invoicing' ),
585
+			'recurring'    => __('Subtotal', 'invoicing'),
586 586
 		),
587 587
 		$subscription
588 588
 	);
@@ -591,13 +591,13 @@  discard block
 block discarded – undo
591 591
 
592 592
 	$invoice = $subscription->get_parent_invoice();
593 593
 
594
-	if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
595
-		unset( $columns['tax'] );
594
+	if ((!wpinv_use_taxes() || !$invoice->is_taxable()) && isset($columns['tax'])) {
595
+		unset($columns['tax']);
596 596
 	}
597 597
 
598 598
 	$table_class = 'w-100 bg-white';
599 599
 
600
-	if ( ! is_admin() ) {
600
+	if (!is_admin()) {
601 601
 		$table_class = 'table table-bordered';
602 602
 	}
603 603
 
@@ -610,9 +610,9 @@  discard block
 block discarded – undo
610 610
 					<tr>
611 611
 						<?php
612 612
 
613
-							foreach ( $columns as $key => $label ) {
614
-								$key   = esc_attr( $key );
615
-								$label = sanitize_text_field( $label );
613
+							foreach ($columns as $key => $label) {
614
+								$key   = esc_attr($key);
615
+								$label = sanitize_text_field($label);
616 616
 								$class = 'text-left';
617 617
 
618 618
 								echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -625,48 +625,48 @@  discard block
 block discarded – undo
625 625
 
626 626
 					<?php
627 627
 
628
-						foreach( $subscription_group['items'] as $subscription_group_item ) :
628
+						foreach ($subscription_group['items'] as $subscription_group_item) :
629 629
 
630 630
 							echo '<tr>';
631 631
 
632
-								foreach ( array_keys( $columns ) as $key ) {
632
+								foreach (array_keys($columns) as $key) {
633 633
 
634 634
 									$class = 'text-left';
635 635
 
636 636
 									echo "<td class='p-2 $class'>";
637 637
 
638
-										switch( $key ) {
638
+										switch ($key) {
639 639
 
640 640
 											case 'item_name':
641
-												$item_name = get_the_title( $subscription_group_item['item_id'] );
642
-												$item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
641
+												$item_name = get_the_title($subscription_group_item['item_id']);
642
+												$item_name = empty($item_name) ? $subscription_group_item['item_name'] : $item_name;
643 643
 
644
-												if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
645
-													echo sanitize_text_field( $item_name );
644
+												if ($invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity']) {
645
+													echo sanitize_text_field($item_name);
646 646
 												} else {
647
-													printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (float) $subscription_group_item['quantity'] );
647
+													printf('%1$s x %2$d', sanitize_text_field($item_name), (float) $subscription_group_item['quantity']);
648 648
 												}
649 649
 
650 650
 												break;
651 651
 
652 652
 											case 'price':
653
-												echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
653
+												echo wpinv_price($subscription_group_item['item_price'], $invoice->get_currency());
654 654
 												break;
655 655
 
656 656
 											case 'tax':
657
-												echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
657
+												echo wpinv_price($subscription_group_item['tax'], $invoice->get_currency());
658 658
 												break;
659 659
 
660 660
 											case 'discount':
661
-												echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
661
+												echo wpinv_price($subscription_group_item['discount'], $invoice->get_currency());
662 662
 												break;
663 663
 
664 664
 											case 'initial':
665
-												echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
665
+												echo wpinv_price($subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency());
666 666
 												break;
667 667
 
668 668
 											case 'recurring':
669
-												echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
669
+												echo '<strong>' . wpinv_price($subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency()) . '</strong>';
670 670
 												break;
671 671
 
672 672
 										}
@@ -679,24 +679,24 @@  discard block
 block discarded – undo
679 679
 
680 680
 						endforeach;
681 681
 
682
-						foreach( $subscription_group['fees'] as $subscription_group_fee ) :
682
+						foreach ($subscription_group['fees'] as $subscription_group_fee) :
683 683
 
684 684
 							echo '<tr>';
685 685
 
686
-								foreach ( array_keys( $columns ) as $key ) {
686
+								foreach (array_keys($columns) as $key) {
687 687
 
688 688
 									$class = 'text-left';
689 689
 
690 690
 									echo "<td class='p-2 $class'>";
691 691
 
692
-										switch( $key ) {
692
+										switch ($key) {
693 693
 
694 694
 											case 'item_name':
695
-												echo sanitize_text_field( $subscription_group_fee['name'] );
695
+												echo sanitize_text_field($subscription_group_fee['name']);
696 696
 												break;
697 697
 
698 698
 											case 'price':
699
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
699
+												echo wpinv_price($subscription_group_fee['initial_fee'], $invoice->get_currency());
700 700
 												break;
701 701
 
702 702
 											case 'tax':
@@ -708,11 +708,11 @@  discard block
 block discarded – undo
708 708
 												break;
709 709
 
710 710
 											case 'initial':
711
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
711
+												echo wpinv_price($subscription_group_fee['initial_fee'], $invoice->get_currency());
712 712
 												break;
713 713
 
714 714
 											case 'recurring':
715
-												echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
715
+												echo '<strong>' . wpinv_price($subscription_group_fee['recurring_fee'], $invoice->get_currency()) . '</strong>';
716 716
 												break;
717 717
 
718 718
 										}
@@ -741,12 +741,12 @@  discard block
 block discarded – undo
741 741
  * @param WPInv_Subscription $subscription
742 742
  * @param bool $skip_current
743 743
  */
744
-function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) {
744
+function getpaid_admin_subscription_related_subscriptions_metabox($subscription, $skip_current = true) {
745 745
 
746 746
 	// Fetch the subscription groups.
747
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
747
+	$subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_payment_id());
748 748
 
749
-	if ( empty( $subscription_groups ) ) {
749
+	if (empty($subscription_groups)) {
750 750
 		return;
751 751
 	}
752 752
 
@@ -754,23 +754,23 @@  discard block
 block discarded – undo
754 754
 	$columns = apply_filters(
755 755
 		'getpaid_subscription_related_subscriptions_columns',
756 756
 		array(
757
-			'subscription'      => __( 'Subscription', 'invoicing' ),
758
-			'start_date'        => __( 'Start Date', 'invoicing' ),
759
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
760
-			'renewals'          => __( 'Payments', 'invoicing' ),
761
-			'item'              => __( 'Items', 'invoicing' ),
762
-			'status'            => __( 'Status', 'invoicing' ),
757
+			'subscription'      => __('Subscription', 'invoicing'),
758
+			'start_date'        => __('Start Date', 'invoicing'),
759
+			'renewal_date'      => __('Next Payment', 'invoicing'),
760
+			'renewals'          => __('Payments', 'invoicing'),
761
+			'item'              => __('Items', 'invoicing'),
762
+			'status'            => __('Status', 'invoicing'),
763 763
 		),
764 764
 		$subscription
765 765
 	);
766 766
 
767
-	if ( $subscription->get_status() == 'pending' ) {
768
-		unset( $columns['start_date'], $columns['renewal_date'] );
767
+	if ($subscription->get_status() == 'pending') {
768
+		unset($columns['start_date'], $columns['renewal_date']);
769 769
 	}
770 770
 
771 771
 	$table_class = 'w-100 bg-white';
772 772
 
773
-	if ( ! is_admin() ) {
773
+	if (!is_admin()) {
774 774
 		$table_class = 'table table-bordered';
775 775
 	}
776 776
 
@@ -783,9 +783,9 @@  discard block
 block discarded – undo
783 783
 					<tr>
784 784
 						<?php
785 785
 
786
-							foreach ( $columns as $key => $label ) {
787
-								$key   = esc_attr( $key );
788
-								$label = sanitize_text_field( $label );
786
+							foreach ($columns as $key => $label) {
787
+								$key   = esc_attr($key);
788
+								$label = sanitize_text_field($label);
789 789
 								$class = 'text-left';
790 790
 
791 791
 								echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -798,62 +798,62 @@  discard block
 block discarded – undo
798 798
 
799 799
 					<?php
800 800
 
801
-						foreach( $subscription_groups as $subscription_group ) :
801
+						foreach ($subscription_groups as $subscription_group) :
802 802
 
803 803
 							// Do not list current subscription.
804
-							if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
804
+							if ($skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id()) {
805 805
 								continue;
806 806
 							}
807 807
 
808 808
 							// Ensure the subscription exists.
809
-							$_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
809
+							$_suscription = new WPInv_Subscription($subscription_group['subscription_id']);
810 810
 
811
-							if ( ! $_suscription->exists() ) {
811
+							if (!$_suscription->exists()) {
812 812
 								continue;
813 813
 							}
814 814
 
815 815
 							echo '<tr>';
816 816
 
817
-								foreach ( array_keys( $columns ) as $key ) {
817
+								foreach (array_keys($columns) as $key) {
818 818
 
819 819
 									$class = 'text-left';
820 820
 
821 821
 									echo "<td class='p-2 $class'>";
822 822
 
823
-										switch( $key ) {
823
+										switch ($key) {
824 824
 
825 825
 											case 'status':
826 826
 												echo $_suscription->get_status_label_html();
827 827
 												break;
828 828
 
829 829
 											case 'item':
830
-												$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
831
-												echo implode( ' | ', $markup );
830
+												$markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items']));
831
+												echo implode(' | ', $markup);
832 832
 												break;
833 833
 
834 834
 											case 'renewals':
835 835
 												$max_bills = $_suscription->get_bill_times();
836
-												echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
836
+												echo $_suscription->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
837 837
 												break;
838 838
 
839 839
 											case 'renewal_date':
840
-												echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
840
+												echo $_suscription->is_active() ? getpaid_format_date_value($_suscription->get_expiration()) : "&mdash;";
841 841
 												break;
842 842
 
843 843
 											case 'start_date':
844
-												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
844
+												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value($_suscription->get_date_created());
845 845
 												break;
846 846
 
847 847
 											case 'subscription':
848
-												$url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
848
+												$url = is_admin() ? admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($_suscription->get_id())) : $_suscription->get_view_url();
849 849
 												printf(
850 850
 													'%1$s#%2$s%3$s',
851
-													'<a href="' . esc_url( $url ) . '">',
852
-													'<strong>' . intval( $_suscription->get_id() ) . '</strong>',
851
+													'<a href="' . esc_url($url) . '">',
852
+													'<strong>' . intval($_suscription->get_id()) . '</strong>',
853 853
 													'</a>'
854 854
 												);
855 855
 
856
-												echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
856
+												echo WPInv_Subscriptions_List_Table::column_amount($_suscription);
857 857
 												break;
858 858
 
859 859
 										}
Please login to merge, or discard this patch.
includes/subscription-functions.php 2 patches
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
  */
51 51
 function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52 52
     $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
53
+    $matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54 54
     return reset( $matching_group );
55 55
 }
56 56
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
  */
64 64
 function getpaid_get_subscription( $subscription ) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
68
-	}
66
+    if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
+        $subscription = new WPInv_Subscription( $subscription );
68
+    }
69 69
 
70
-	return $subscription->exists() ? $subscription : false;
70
+    return $subscription->exists() ? $subscription : false;
71 71
 }
72 72
 
73 73
 /**
@@ -81,28 +81,28 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
83 83
 
84
-	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
86
-		$args['fields'] = 'id';
87
-		$args['number'] = 1;
88
-	}
84
+    // Do not retrieve all fields if we just want the count.
85
+    if ( 'count' == $return ) {
86
+        $args['fields'] = 'id';
87
+        $args['number'] = 1;
88
+    }
89 89
 
90
-	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
92
-		$args['count_total'] = false;
93
-	}
90
+    // Do not count all matches if we just want the results.
91
+    if ( 'results' == $return ) {
92
+        $args['count_total'] = false;
93
+    }
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+    $query = new GetPaid_Subscriptions_Query( $args );
96 96
 
97
-	if ( 'results' == $return ) {
98
-		return $query->get_results();
99
-	}
97
+    if ( 'results' == $return ) {
98
+        return $query->get_results();
99
+    }
100 100
 
101
-	if ( 'count' == $return ) {
102
-		return $query->get_total();
103
-	}
101
+    if ( 'count' == $return ) {
102
+        return $query->get_total();
103
+    }
104 104
 
105
-	return $query;
105
+    return $query;
106 106
 }
107 107
 
108 108
 /**
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function getpaid_get_subscription_statuses() {
114 114
 
115
-	return apply_filters(
116
-		'getpaid_get_subscription_statuses',
117
-		array(
118
-			'pending'    => __( 'Pending', 'invoicing' ),
119
-			'trialling'  => __( 'Trialing', 'invoicing' ),
120
-			'active'     => __( 'Active', 'invoicing' ),
121
-			'failing'    => __( 'Failing', 'invoicing' ),
122
-			'expired'    => __( 'Expired', 'invoicing' ),
123
-			'completed'  => __( 'Complete', 'invoicing' ),
124
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
125
-		)
126
-	);
115
+    return apply_filters(
116
+        'getpaid_get_subscription_statuses',
117
+        array(
118
+            'pending'    => __( 'Pending', 'invoicing' ),
119
+            'trialling'  => __( 'Trialing', 'invoicing' ),
120
+            'active'     => __( 'Active', 'invoicing' ),
121
+            'failing'    => __( 'Failing', 'invoicing' ),
122
+            'expired'    => __( 'Expired', 'invoicing' ),
123
+            'completed'  => __( 'Complete', 'invoicing' ),
124
+            'cancelled'  => __( 'Cancelled', 'invoicing' ),
125
+        )
126
+    );
127 127
 
128 128
 }
129 129
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
  * @return string
134 134
  */
135 135
 function getpaid_get_subscription_status_label( $status ) {
136
-	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
136
+    $statuses = getpaid_get_subscription_statuses();
137
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
138 138
 }
139 139
 
140 140
 /**
@@ -144,18 +144,18 @@  discard block
 block discarded – undo
144 144
  */
145 145
 function getpaid_get_subscription_status_classes() {
146 146
 
147
-	return apply_filters(
148
-		'getpaid_get_subscription_status_classes',
149
-		array(
150
-			'pending'    => 'badge-dark',
151
-			'trialling'  => 'badge-info',
152
-			'active'     => 'badge-success',
153
-			'failing'    => 'badge-warning',
154
-			'expired'    => 'badge-danger',
155
-			'completed'  => 'badge-primary',
156
-			'cancelled'  => 'badge-secondary',
157
-		)
158
-	);
147
+    return apply_filters(
148
+        'getpaid_get_subscription_status_classes',
149
+        array(
150
+            'pending'    => 'badge-dark',
151
+            'trialling'  => 'badge-info',
152
+            'active'     => 'badge-success',
153
+            'failing'    => 'badge-warning',
154
+            'expired'    => 'badge-danger',
155
+            'completed'  => 'badge-primary',
156
+            'cancelled'  => 'badge-secondary',
157
+        )
158
+    );
159 159
 
160 160
 }
161 161
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function getpaid_get_subscription_status_counts( $args = array() ) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
170
-	$counts   = array();
169
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
170
+    $counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
-	}
172
+    foreach ( $statuses as $status ) {
173
+        $_args             = wp_parse_args( "status=$status", $args );
174
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
+    }
176 176
 
177
-	return $counts;
177
+    return $counts;
178 178
 
179 179
 }
180 180
 
@@ -185,32 +185,32 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function getpaid_get_subscription_periods() {
187 187
 
188
-	return apply_filters(
189
-		'getpaid_get_subscription_periods',
190
-		array(
188
+    return apply_filters(
189
+        'getpaid_get_subscription_periods',
190
+        array(
191 191
 
192
-			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
195
-			),
192
+            'day'   => array(
193
+                'singular' => __( '%s day', 'invoicing' ),
194
+                'plural'   => __( '%d days', 'invoicing' ),
195
+            ),
196 196
 
197
-			'week'   => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
200
-			),
197
+            'week'   => array(
198
+                'singular' => __( '%s week', 'invoicing' ),
199
+                'plural'   => __( '%d weeks', 'invoicing' ),
200
+            ),
201 201
 
202
-			'month'   => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
205
-			),
202
+            'month'   => array(
203
+                'singular' => __( '%s month', 'invoicing' ),
204
+                'plural'   => __( '%d months', 'invoicing' ),
205
+            ),
206 206
 
207
-			'year'   => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
210
-			),
207
+            'year'   => array(
208
+                'singular' => __( '%s year', 'invoicing' ),
209
+                'plural'   => __( '%d years', 'invoicing' ),
210
+            ),
211 211
 
212
-		)
213
-	);
212
+        )
213
+    );
214 214
 
215 215
 }
216 216
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
  * @return int
222 222
  */
223 223
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
224
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
225 225
 }
226 226
 
227 227
 /**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
  * @return string
232 232
  */
233 233
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
234
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
235 235
 }
236 236
 
237 237
 /**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
  * @return string
243 243
  */
244 244
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
245
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
+    return strtolower( sanitize_text_field( $label ) );
247 247
 }
248 248
 
249 249
 /**
@@ -254,22 +254,22 @@  discard block
 block discarded – undo
254 254
  */
255 255
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
256 256
 
257
-	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
257
+    $periods = getpaid_get_subscription_periods();
258
+    $period  = strtolower( $period );
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
-	}
260
+    if ( isset( $periods[ $period ] ) ) {
261
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
+    }
263 263
 
264
-	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
268
-		}
269
-	}
264
+    // Backwards compatibility.
265
+    foreach ( $periods as $key => $data ) {
266
+        if ( strpos( $key, $period ) === 0 ) {
267
+            return sprintf( $data['singular'], $singular_prefix );
268
+        }
269
+    }
270 270
 
271
-	// Invalid string.
272
-	return '';
271
+    // Invalid string.
272
+    return '';
273 273
 }
274 274
 
275 275
 /**
@@ -281,22 +281,22 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
283 283
 
284
-	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
284
+    $periods = getpaid_get_subscription_periods();
285
+    $period  = strtolower( $period );
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
289
-	}
287
+    if ( isset( $periods[ $period ] ) ) {
288
+        return sprintf( $periods[ $period ]['plural'], $interval );
289
+    }
290 290
 
291
-	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
295
-		}
296
-	}
291
+    // Backwards compatibility.
292
+    foreach ( $periods as $key => $data ) {
293
+        if ( strpos( $key, $period ) === 0 ) {
294
+            return sprintf( $data['plural'], $interval );
295
+        }
296
+    }
297 297
 
298
-	// Invalid string.
299
-	return '';
298
+    // Invalid string.
299
+    return '';
300 300
 }
301 301
 
302 302
 /**
@@ -307,101 +307,101 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function getpaid_get_formatted_subscription_amount( $subscription ) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
-	$bill_times = $subscription->get_bill_times();
310
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
+    $bill_times = $subscription->get_bill_times();
314 314
 
315
-	if ( ! empty( $bill_times ) ) {
316
-		$bill_times = $subscription->get_frequency() * $bill_times;
317
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
318
-	}
315
+    if ( ! empty( $bill_times ) ) {
316
+        $bill_times = $subscription->get_frequency() * $bill_times;
317
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
318
+    }
319 319
 
320
-	// Trial periods.
321
-	if ( $subscription->has_trial_period() ) {
320
+    // Trial periods.
321
+    if ( $subscription->has_trial_period() ) {
322 322
 
323
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
323
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
325 325
 
326
-		if ( empty( $bill_times ) ) {
326
+        if ( empty( $bill_times ) ) {
327 327
 
328
-			return sprintf(
328
+            return sprintf(
329 329
 
330
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
332
-				$initial,
333
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
334
-				$recurring,
335
-				$period
330
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
+                _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
332
+                $initial,
333
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
334
+                $recurring,
335
+                $period
336 336
 	
337
-			);
337
+            );
338 338
 
339
-		}
339
+        }
340 340
 
341
-		return sprintf(
341
+        return sprintf(
342 342
 
343
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
344
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
345
-			$initial,
346
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
347
-			$recurring,
348
-			$period,
349
-			$bill_times
350
-		);
343
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
344
+            _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
345
+            $initial,
346
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
347
+            $recurring,
348
+            $period,
349
+            $bill_times
350
+        );
351 351
 
352
-	}
352
+    }
353 353
 
354
-	if ( $initial != $recurring ) {
354
+    if ( $initial != $recurring ) {
355 355
 
356
-		if ( empty( $bill_times ) ) {
356
+        if ( empty( $bill_times ) ) {
357 357
 
358
-			return sprintf(
358
+            return sprintf(
359 359
 
360
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
362
-				$initial,
363
-				$recurring,
364
-				$period
360
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
+                _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
362
+                $initial,
363
+                $recurring,
364
+                $period
365 365
 	
366
-			);
366
+            );
367 367
 
368
-		}
368
+        }
369 369
 
370
-		return sprintf(
370
+        return sprintf(
371 371
 
372
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
374
-			$initial,
375
-			$recurring,
376
-			$period,
377
-			$bill_times
372
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
374
+            $initial,
375
+            $recurring,
376
+            $period,
377
+            $bill_times
378 378
 
379
-		);
379
+        );
380 380
 
381
-	}
381
+    }
382 382
 
383
-	if ( empty( $bill_times ) ) {
383
+    if ( empty( $bill_times ) ) {
384 384
 
385
-		return sprintf(
385
+        return sprintf(
386 386
 
387
-			// translators: $1: is the recurring amount, $2: is the recurring period
388
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
389
-			$initial,
390
-			$period
387
+            // translators: $1: is the recurring amount, $2: is the recurring period
388
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
389
+            $initial,
390
+            $period
391 391
 	
392
-		);
392
+        );
393 393
 
394
-	}
394
+    }
395 395
 
396
-	return sprintf(
396
+    return sprintf(
397 397
 
398
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
400
-		$bill_times,
401
-		$initial,
402
-		$period
398
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
400
+        $bill_times,
401
+        $initial,
402
+        $period
403 403
 
404
-	);
404
+    );
405 405
 
406 406
 }
407 407
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
  * @return WPInv_Subscription|false
413 413
  */
414 414
 function getpaid_get_invoice_subscription( $invoice ) {
415
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
415
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
416 416
 }
417 417
 
418 418
 /**
@@ -421,10 +421,10 @@  discard block
 block discarded – undo
421 421
  * @param WPInv_Invoice $invoice
422 422
  */
423 423
 function getpaid_activate_invoice_subscription( $invoice ) {
424
-	$subscription = getpaid_get_invoice_subscription( $invoice );
425
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
426
-		$subscription->activate();
427
-	}
424
+    $subscription = getpaid_get_invoice_subscription( $invoice );
425
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
426
+        $subscription->activate();
427
+    }
428 428
 }
429 429
 
430 430
 /**
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
  * @return WPInv_Subscriptions
434 434
  */
435 435
 function getpaid_subscriptions() {
436
-	return getpaid()->get( 'subscriptions' );
436
+    return getpaid()->get( 'subscriptions' );
437 437
 }
438 438
 
439 439
 /**
@@ -452,15 +452,15 @@  discard block
 block discarded – undo
452 452
         return false;
453 453
     }
454 454
 
455
-	// Fetch the invoice subscription.
456
-	$subscription = getpaid_get_subscriptions(
457
-		array(
458
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
459
-			'number'     => 1,
460
-		)
461
-	);
455
+    // Fetch the invoice subscription.
456
+    $subscription = getpaid_get_subscriptions(
457
+        array(
458
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
459
+            'number'     => 1,
460
+        )
461
+    );
462 462
 
463
-	return empty( $subscription ) ? false : $subscription[0];
463
+    return empty( $subscription ) ? false : $subscription[0];
464 464
 
465 465
 }
466 466
 
@@ -477,48 +477,48 @@  discard block
 block discarded – undo
477 477
  */
478 478
 function getpaid_get_recurring_item_key( $cart_item ) {
479 479
 
480
-	$cart_key     = 'renews_';
481
-	$interval     = $cart_item->get_recurring_interval();
482
-	$period       = $cart_item->get_recurring_period( true );
483
-	$length       = $cart_item->get_recurring_limit() * $interval;
484
-	$trial_period = $cart_item->get_trial_period( true );
485
-	$trial_length = $cart_item->get_trial_interval();
486
-
487
-	// First start with the billing interval and period
488
-	switch ( $interval ) {
489
-		case 1 :
490
-			if ( 'day' == $period ) {
491
-				$cart_key .= 'daily';
492
-			} else {
493
-				$cart_key .= sprintf( '%sly', $period );
494
-			}
495
-			break;
496
-		case 2 :
497
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
498
-			break;
499
-		case 3 :
500
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
501
-		break;
502
-		default:
503
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
504
-			break;
505
-	}
506
-
507
-	// Maybe add the optional maximum billing periods...
508
-	if ( $length > 0 ) {
509
-		$cart_key .= '_for_';
510
-		$cart_key .= sprintf( '%d_%s', $length, $period );
511
-		if ( $length > 1 ) {
512
-			$cart_key .= 's';
513
-		}
514
-	}
515
-
516
-	// And an optional free trial.
517
-	if ( $cart_item->has_free_trial() ) {
518
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
519
-	}
520
-
521
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
480
+    $cart_key     = 'renews_';
481
+    $interval     = $cart_item->get_recurring_interval();
482
+    $period       = $cart_item->get_recurring_period( true );
483
+    $length       = $cart_item->get_recurring_limit() * $interval;
484
+    $trial_period = $cart_item->get_trial_period( true );
485
+    $trial_length = $cart_item->get_trial_interval();
486
+
487
+    // First start with the billing interval and period
488
+    switch ( $interval ) {
489
+        case 1 :
490
+            if ( 'day' == $period ) {
491
+                $cart_key .= 'daily';
492
+            } else {
493
+                $cart_key .= sprintf( '%sly', $period );
494
+            }
495
+            break;
496
+        case 2 :
497
+            $cart_key .= sprintf( 'every_2nd_%s', $period );
498
+            break;
499
+        case 3 :
500
+            $cart_key .= sprintf( 'every_3rd_%s', $period );
501
+        break;
502
+        default:
503
+            $cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
504
+            break;
505
+    }
506
+
507
+    // Maybe add the optional maximum billing periods...
508
+    if ( $length > 0 ) {
509
+        $cart_key .= '_for_';
510
+        $cart_key .= sprintf( '%d_%s', $length, $period );
511
+        if ( $length > 1 ) {
512
+            $cart_key .= 's';
513
+        }
514
+    }
515
+
516
+    // And an optional free trial.
517
+    if ( $cart_item->has_free_trial() ) {
518
+        $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
519
+    }
520
+
521
+    return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
522 522
 }
523 523
 
524 524
 /**
@@ -529,17 +529,17 @@  discard block
 block discarded – undo
529 529
  */
530 530
 function getpaid_get_subscription_groups( $invoice ) {
531 531
 
532
-	// Generate subscription groups.
533
-	$subscription_groups = array();
534
-	foreach ( $invoice->get_items() as $item ) {
532
+    // Generate subscription groups.
533
+    $subscription_groups = array();
534
+    foreach ( $invoice->get_items() as $item ) {
535 535
 
536
-		if ( $item->is_recurring() ) {
537
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
538
-		}
536
+        if ( $item->is_recurring() ) {
537
+            $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
538
+        }
539 539
 
540
-	}
540
+    }
541 541
 
542
-	return $subscription_groups;
542
+    return $subscription_groups;
543 543
 }
544 544
 
545 545
 /**
@@ -553,57 +553,57 @@  discard block
 block discarded – undo
553 553
  */
554 554
 function getpaid_calculate_subscription_totals( $invoice ) {
555 555
 
556
-	// Generate subscription groups.
557
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
556
+    // Generate subscription groups.
557
+    $subscription_groups = getpaid_get_subscription_groups( $invoice );
558 558
 
559
-	// Now let's calculate the totals for each group of subscriptions
560
-	$subscription_totals = array();
559
+    // Now let's calculate the totals for each group of subscriptions
560
+    $subscription_totals = array();
561 561
 
562
-	foreach ( $subscription_groups as $subscription_key => $items ) {
562
+    foreach ( $subscription_groups as $subscription_key => $items ) {
563 563
 
564
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
564
+        if ( empty( $subscription_totals[ $subscription_key ] ) ) {
565 565
 
566
-			$subscription_totals[ $subscription_key ] = array(
567
-				'initial_total'   => 0,
568
-				'recurring_total' => 0,
569
-				'items'           => array(),
570
-				'trialling'       => false,
571
-			);
566
+            $subscription_totals[ $subscription_key ] = array(
567
+                'initial_total'   => 0,
568
+                'recurring_total' => 0,
569
+                'items'           => array(),
570
+                'trialling'       => false,
571
+            );
572 572
 
573
-		}
573
+        }
574 574
 
575
-		/**
576
-		 * Get the totals of the group.
577
-		 * @var GetPaid_Form_Item $item
578
-		 */
579
-		foreach ( $items as $item ) {
575
+        /**
576
+         * Get the totals of the group.
577
+         * @var GetPaid_Form_Item $item
578
+         */
579
+        foreach ( $items as $item ) {
580 580
 
581
-			$subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
581
+            $subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
+            $subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
+            $subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
+            $subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
+            $subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
+            $subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
+            $subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
588 588
 
589
-			// Calculate the next renewal date.
590
-			$period       = $item->get_recurring_period( true );
591
-			$interval     = $item->get_recurring_interval();
589
+            // Calculate the next renewal date.
590
+            $period       = $item->get_recurring_period( true );
591
+            $interval     = $item->get_recurring_interval();
592 592
 
593
-			// If the subscription item has a trial period...
594
-			if ( $item->has_free_trial() ) {
595
-				$period   = $item->get_trial_period( true );
596
-				$interval = $item->get_trial_interval();
597
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
598
-			}
593
+            // If the subscription item has a trial period...
594
+            if ( $item->has_free_trial() ) {
595
+                $period   = $item->get_trial_period( true );
596
+                $interval = $item->get_trial_interval();
597
+                $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
598
+            }
599 599
 
600
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
600
+            $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
601 601
 
602
-		}
602
+        }
603 603
 
604
-	}
604
+    }
605 605
 
606
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
606
+    return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
607 607
 }
608 608
 
609 609
 /**
@@ -614,17 +614,17 @@  discard block
 block discarded – undo
614 614
  */
615 615
 function getpaid_should_group_subscriptions( $invoice ) {
616 616
 
617
-	$recurring_items = 0;
617
+    $recurring_items = 0;
618 618
 
619
-	foreach ( $invoice->get_items() as $item ) {
619
+    foreach ( $invoice->get_items() as $item ) {
620 620
 
621
-		if ( $item->is_recurring() ) {
622
-			$recurring_items ++;
623
-		}
621
+        if ( $item->is_recurring() ) {
622
+            $recurring_items ++;
623
+        }
624 624
 
625
-	}
625
+    }
626 626
 
627
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
627
+    return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
628 628
 }
629 629
 
630 630
 /**
@@ -635,40 +635,40 @@  discard block
 block discarded – undo
635 635
  * @return int
636 636
  */
637 637
 function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
638
-	global $wpdb;
638
+    global $wpdb;
639 639
 
640
-	$parent_invoice_id = (int) $parent_invoice_id;
640
+    $parent_invoice_id = (int) $parent_invoice_id;
641 641
 
642
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
642
+    if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
643 643
 
644
-		return (int) $wpdb->get_var(
645
-			$wpdb->prepare(
646
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
647
-				$parent_invoice_id,
648
-				$parent_invoice_id
649
-			)
650
-		);
644
+        return (int) $wpdb->get_var(
645
+            $wpdb->prepare(
646
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
647
+                $parent_invoice_id,
648
+                $parent_invoice_id
649
+            )
650
+        );
651 651
 
652
-	}
652
+    }
653 653
 	
654
-	$invoice_ids = $wpdb->get_col(
655
-		$wpdb->prepare(
656
-			"SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
657
-			$parent_invoice_id,
658
-			$parent_invoice_id
659
-		)
660
-	);
654
+    $invoice_ids = $wpdb->get_col(
655
+        $wpdb->prepare(
656
+            "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
657
+            $parent_invoice_id,
658
+            $parent_invoice_id
659
+        )
660
+    );
661 661
 
662
-	$count = 0;
662
+    $count = 0;
663 663
 
664
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
664
+    foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
665 665
 
666
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
-			$count ++;
668
-			continue;
669
-		}
666
+        if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
+            $count ++;
668
+            continue;
669
+        }
670 670
 
671
-	}
671
+    }
672 672
 
673
-	return $count;
673
+    return $count;
674 674
 }
Please login to merge, or discard this patch.
Spacing   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -13,18 +13,18 @@  discard block
 block discarded – undo
13 13
  * @return      WPInv_Subscription[]|WPInv_Subscription|false
14 14
  * @since       2.3.0
15 15
  */
16
-function getpaid_get_invoice_subscriptions( $invoice ) {
16
+function getpaid_get_invoice_subscriptions($invoice) {
17 17
 
18 18
     // Retrieve subscription groups.
19
-    $subscription_ids = wp_list_pluck( getpaid_get_invoice_subscription_groups( $invoice->get_id() ), 'subscription_id' );
19
+    $subscription_ids = wp_list_pluck(getpaid_get_invoice_subscription_groups($invoice->get_id()), 'subscription_id');
20 20
 
21 21
     // No subscription groups, normal subscription.
22
-    if ( empty( $subscription_ids ) ) {
23
-        return getpaid_subscriptions()->get_invoice_subscription( $invoice );
22
+    if (empty($subscription_ids)) {
23
+        return getpaid_subscriptions()->get_invoice_subscription($invoice);
24 24
     }
25 25
 
26 26
     // Subscription groups.
27
-    return array_filter( array_map( 'getpaid_get_subscription', $subscription_ids ) );
27
+    return array_filter(array_map('getpaid_get_subscription', $subscription_ids));
28 28
 
29 29
 }
30 30
 
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
  * @return      array
36 36
  * @since       2.3.0
37 37
  */
38
-function getpaid_get_invoice_subscription_groups( $invoice_id ) {
39
-    $subscription_groups = get_post_meta( $invoice_id, 'getpaid_subscription_groups', true );
40
-    return empty( $subscription_groups ) ? array() : $subscription_groups;
38
+function getpaid_get_invoice_subscription_groups($invoice_id) {
39
+    $subscription_groups = get_post_meta($invoice_id, 'getpaid_subscription_groups', true);
40
+    return empty($subscription_groups) ? array() : $subscription_groups;
41 41
 }
42 42
 
43 43
 /**
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
  * @return      array|false
49 49
  * @since       2.3.0
50 50
  */
51
-function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52
-    $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54
-    return reset( $matching_group );
51
+function getpaid_get_invoice_subscription_group($invoice_id, $subscription_id) {
52
+    $subscription_groups = getpaid_get_invoice_subscription_groups($invoice_id);
53
+	$matching_group = wp_list_filter($subscription_groups, compact('subscription_id'));
54
+    return reset($matching_group);
55 55
 }
56 56
 
57 57
 /**
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
  * @since       2.3.0
62 62
  * @return WPInv_Subscription|false
63 63
  */
64
-function getpaid_get_subscription( $subscription ) {
64
+function getpaid_get_subscription($subscription) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
66
+	if (!is_a($subscription, 'WPInv_Subscription')) {
67
+		$subscription = new WPInv_Subscription($subscription);
68 68
 	}
69 69
 
70 70
 	return $subscription->exists() ? $subscription : false;
@@ -79,26 +79,26 @@  discard block
 block discarded – undo
79 79
  *
80 80
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
81 81
  */
82
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
82
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
83 83
 
84 84
 	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
85
+	if ('count' == $return) {
86 86
 		$args['fields'] = 'id';
87 87
 		$args['number'] = 1;
88 88
 	}
89 89
 
90 90
 	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
91
+	if ('results' == $return) {
92 92
 		$args['count_total'] = false;
93 93
 	}
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+	$query = new GetPaid_Subscriptions_Query($args);
96 96
 
97
-	if ( 'results' == $return ) {
97
+	if ('results' == $return) {
98 98
 		return $query->get_results();
99 99
 	}
100 100
 
101
-	if ( 'count' == $return ) {
101
+	if ('count' == $return) {
102 102
 		return $query->get_total();
103 103
 	}
104 104
 
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 	return apply_filters(
116 116
 		'getpaid_get_subscription_statuses',
117 117
 		array(
118
-			'pending'    => __( 'Pending', 'invoicing' ),
119
-			'trialling'  => __( 'Trialing', 'invoicing' ),
120
-			'active'     => __( 'Active', 'invoicing' ),
121
-			'failing'    => __( 'Failing', 'invoicing' ),
122
-			'expired'    => __( 'Expired', 'invoicing' ),
123
-			'completed'  => __( 'Complete', 'invoicing' ),
124
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
118
+			'pending'    => __('Pending', 'invoicing'),
119
+			'trialling'  => __('Trialing', 'invoicing'),
120
+			'active'     => __('Active', 'invoicing'),
121
+			'failing'    => __('Failing', 'invoicing'),
122
+			'expired'    => __('Expired', 'invoicing'),
123
+			'completed'  => __('Complete', 'invoicing'),
124
+			'cancelled'  => __('Cancelled', 'invoicing'),
125 125
 		)
126 126
 	);
127 127
 
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
  *
133 133
  * @return string
134 134
  */
135
-function getpaid_get_subscription_status_label( $status ) {
135
+function getpaid_get_subscription_status_label($status) {
136 136
 	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
137
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
138 138
 }
139 139
 
140 140
 /**
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
  *
165 165
  * @return array
166 166
  */
167
-function getpaid_get_subscription_status_counts( $args = array() ) {
167
+function getpaid_get_subscription_status_counts($args = array()) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
169
+	$statuses = array_keys(getpaid_get_subscription_statuses());
170 170
 	$counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
172
+	foreach ($statuses as $status) {
173
+		$_args             = wp_parse_args("status=$status", $args);
174
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
175 175
 	}
176 176
 
177 177
 	return $counts;
@@ -190,23 +190,23 @@  discard block
 block discarded – undo
190 190
 		array(
191 191
 
192 192
 			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
193
+				'singular' => __('%s day', 'invoicing'),
194
+				'plural'   => __('%d days', 'invoicing'),
195 195
 			),
196 196
 
197 197
 			'week'   => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
198
+				'singular' => __('%s week', 'invoicing'),
199
+				'plural'   => __('%d weeks', 'invoicing'),
200 200
 			),
201 201
 
202 202
 			'month'   => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
203
+				'singular' => __('%s month', 'invoicing'),
204
+				'plural'   => __('%d months', 'invoicing'),
205 205
 			),
206 206
 
207 207
 			'year'   => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
208
+				'singular' => __('%s year', 'invoicing'),
209
+				'plural'   => __('%d years', 'invoicing'),
210 210
 			),
211 211
 
212 212
 		)
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
  * @param string $trial_period
221 221
  * @return int
222 222
  */
223
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
223
+function getpaid_get_subscription_trial_period_interval($trial_period) {
224
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
225 225
 }
226 226
 
227 227
 /**
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
  * @param string $trial_period
231 231
  * @return string
232 232
  */
233
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
233
+function getpaid_get_subscription_trial_period_period($trial_period) {
234
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
235 235
 }
236 236
 
237 237
 /**
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
  * @param int $interval
242 242
  * @return string
243 243
  */
244
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
244
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
245
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
246
+	return strtolower(sanitize_text_field($label));
247 247
 }
248 248
 
249 249
 /**
@@ -252,19 +252,19 @@  discard block
 block discarded – undo
252 252
  * @param string $period
253 253
  * @return string
254 254
  */
255
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
255
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
256 256
 
257 257
 	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
258
+	$period  = strtolower($period);
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
260
+	if (isset($periods[$period])) {
261
+		return sprintf($periods[$period]['singular'], $singular_prefix);
262 262
 	}
263 263
 
264 264
 	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
265
+	foreach ($periods as $key => $data) {
266
+		if (strpos($key, $period) === 0) {
267
+			return sprintf($data['singular'], $singular_prefix);
268 268
 		}
269 269
 	}
270 270
 
@@ -279,19 +279,19 @@  discard block
 block discarded – undo
279 279
  * @param int $interval
280 280
  * @return string
281 281
  */
282
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
282
+function getpaid_get_plural_subscription_period_label($period, $interval) {
283 283
 
284 284
 	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
285
+	$period  = strtolower($period);
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
287
+	if (isset($periods[$period])) {
288
+		return sprintf($periods[$period]['plural'], $interval);
289 289
 	}
290 290
 
291 291
 	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
292
+	foreach ($periods as $key => $data) {
293
+		if (strpos($key, $period) === 0) {
294
+			return sprintf($data['plural'], $interval);
295 295
 		}
296 296
 	}
297 297
 
@@ -305,32 +305,32 @@  discard block
 block discarded – undo
305 305
  * @param WPInv_Subscription $subscription
306 306
  * @return string
307 307
  */
308
-function getpaid_get_formatted_subscription_amount( $subscription ) {
308
+function getpaid_get_formatted_subscription_amount($subscription) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
310
+	$initial    = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency());
311
+	$recurring  = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency());
312
+	$period     = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
313 313
 	$bill_times = $subscription->get_bill_times();
314 314
 
315
-	if ( ! empty( $bill_times ) ) {
315
+	if (!empty($bill_times)) {
316 316
 		$bill_times = $subscription->get_frequency() * $bill_times;
317
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
317
+		$bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times);
318 318
 	}
319 319
 
320 320
 	// Trial periods.
321
-	if ( $subscription->has_trial_period() ) {
321
+	if ($subscription->has_trial_period()) {
322 322
 
323
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
323
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
324
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
325 325
 
326
-		if ( empty( $bill_times ) ) {
326
+		if (empty($bill_times)) {
327 327
 
328 328
 			return sprintf(
329 329
 
330 330
 				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
331
+				_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
332 332
 				$initial,
333
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
333
+				getpaid_get_subscription_period_label($trial_period, $trial_interval),
334 334
 				$recurring,
335 335
 				$period
336 336
 	
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
 		return sprintf(
342 342
 
343 343
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
344
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
344
+			_x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'),
345 345
 			$initial,
346
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
346
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
347 347
 			$recurring,
348 348
 			$period,
349 349
 			$bill_times
@@ -351,14 +351,14 @@  discard block
 block discarded – undo
351 351
 
352 352
 	}
353 353
 
354
-	if ( $initial != $recurring ) {
354
+	if ($initial != $recurring) {
355 355
 
356
-		if ( empty( $bill_times ) ) {
356
+		if (empty($bill_times)) {
357 357
 
358 358
 			return sprintf(
359 359
 
360 360
 				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
361
+				_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
362 362
 				$initial,
363 363
 				$recurring,
364 364
 				$period
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 		return sprintf(
371 371
 
372 372
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
373
+			_x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'),
374 374
 			$initial,
375 375
 			$recurring,
376 376
 			$period,
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
 
381 381
 	}
382 382
 
383
-	if ( empty( $bill_times ) ) {
383
+	if (empty($bill_times)) {
384 384
 
385 385
 		return sprintf(
386 386
 
387 387
 			// translators: $1: is the recurring amount, $2: is the recurring period
388
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
388
+			_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
389 389
 			$initial,
390 390
 			$period
391 391
 	
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 	return sprintf(
397 397
 
398 398
 		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
399
+		_x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
400 400
 		$bill_times,
401 401
 		$initial,
402 402
 		$period
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
  * @param WPInv_Invoice $invoice
412 412
  * @return WPInv_Subscription|false
413 413
  */
414
-function getpaid_get_invoice_subscription( $invoice ) {
415
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
414
+function getpaid_get_invoice_subscription($invoice) {
415
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
416 416
 }
417 417
 
418 418
 /**
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
  *
421 421
  * @param WPInv_Invoice $invoice
422 422
  */
423
-function getpaid_activate_invoice_subscription( $invoice ) {
424
-	$subscription = getpaid_get_invoice_subscription( $invoice );
425
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
423
+function getpaid_activate_invoice_subscription($invoice) {
424
+	$subscription = getpaid_get_invoice_subscription($invoice);
425
+	if (is_a($subscription, 'WPInv_Subscription')) {
426 426
 		$subscription->activate();
427 427
 	}
428 428
 }
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
  * @return WPInv_Subscriptions
434 434
  */
435 435
 function getpaid_subscriptions() {
436
-	return getpaid()->get( 'subscriptions' );
436
+	return getpaid()->get('subscriptions');
437 437
 }
438 438
 
439 439
 /**
@@ -442,13 +442,13 @@  discard block
 block discarded – undo
442 442
  * @since 2.3.0
443 443
  * @return WPInv_Subscription|bool
444 444
  */
445
-function wpinv_get_invoice_subscription( $invoice ) {
445
+function wpinv_get_invoice_subscription($invoice) {
446 446
 
447 447
     // Retrieve the invoice.
448
-    $invoice = new WPInv_Invoice( $invoice );
448
+    $invoice = new WPInv_Invoice($invoice);
449 449
 
450 450
     // Ensure it is a recurring invoice.
451
-    if ( ! $invoice->is_recurring() ) {
451
+    if (!$invoice->is_recurring()) {
452 452
         return false;
453 453
     }
454 454
 
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		)
461 461
 	);
462 462
 
463
-	return empty( $subscription ) ? false : $subscription[0];
463
+	return empty($subscription) ? false : $subscription[0];
464 464
 
465 465
 }
466 466
 
@@ -475,50 +475,50 @@  discard block
 block discarded – undo
475 475
  * @param GetPaid_Form_Item|WPInv_Item $cart_item
476 476
  * @return string
477 477
  */
478
-function getpaid_get_recurring_item_key( $cart_item ) {
478
+function getpaid_get_recurring_item_key($cart_item) {
479 479
 
480 480
 	$cart_key     = 'renews_';
481 481
 	$interval     = $cart_item->get_recurring_interval();
482
-	$period       = $cart_item->get_recurring_period( true );
482
+	$period       = $cart_item->get_recurring_period(true);
483 483
 	$length       = $cart_item->get_recurring_limit() * $interval;
484
-	$trial_period = $cart_item->get_trial_period( true );
484
+	$trial_period = $cart_item->get_trial_period(true);
485 485
 	$trial_length = $cart_item->get_trial_interval();
486 486
 
487 487
 	// First start with the billing interval and period
488
-	switch ( $interval ) {
488
+	switch ($interval) {
489 489
 		case 1 :
490
-			if ( 'day' == $period ) {
490
+			if ('day' == $period) {
491 491
 				$cart_key .= 'daily';
492 492
 			} else {
493
-				$cart_key .= sprintf( '%sly', $period );
493
+				$cart_key .= sprintf('%sly', $period);
494 494
 			}
495 495
 			break;
496 496
 		case 2 :
497
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
497
+			$cart_key .= sprintf('every_2nd_%s', $period);
498 498
 			break;
499 499
 		case 3 :
500
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
500
+			$cart_key .= sprintf('every_3rd_%s', $period);
501 501
 		break;
502 502
 		default:
503
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
503
+			$cart_key .= sprintf('every_%dth_%s', $interval, $period);
504 504
 			break;
505 505
 	}
506 506
 
507 507
 	// Maybe add the optional maximum billing periods...
508
-	if ( $length > 0 ) {
508
+	if ($length > 0) {
509 509
 		$cart_key .= '_for_';
510
-		$cart_key .= sprintf( '%d_%s', $length, $period );
511
-		if ( $length > 1 ) {
510
+		$cart_key .= sprintf('%d_%s', $length, $period);
511
+		if ($length > 1) {
512 512
 			$cart_key .= 's';
513 513
 		}
514 514
 	}
515 515
 
516 516
 	// And an optional free trial.
517
-	if ( $cart_item->has_free_trial() ) {
518
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
517
+	if ($cart_item->has_free_trial()) {
518
+		$cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period);
519 519
 	}
520 520
 
521
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
521
+	return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item);
522 522
 }
523 523
 
524 524
 /**
@@ -527,14 +527,14 @@  discard block
 block discarded – undo
527 527
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
528 528
  * @return array
529 529
  */
530
-function getpaid_get_subscription_groups( $invoice ) {
530
+function getpaid_get_subscription_groups($invoice) {
531 531
 
532 532
 	// Generate subscription groups.
533 533
 	$subscription_groups = array();
534
-	foreach ( $invoice->get_items() as $item ) {
534
+	foreach ($invoice->get_items() as $item) {
535 535
 
536
-		if ( $item->is_recurring() ) {
537
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
536
+		if ($item->is_recurring()) {
537
+			$subscription_groups[getpaid_get_recurring_item_key($item)][] = $item;
538 538
 		}
539 539
 
540 540
 	}
@@ -551,19 +551,19 @@  discard block
 block discarded – undo
551 551
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
552 552
  * @return array
553 553
  */
554
-function getpaid_calculate_subscription_totals( $invoice ) {
554
+function getpaid_calculate_subscription_totals($invoice) {
555 555
 
556 556
 	// Generate subscription groups.
557
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
557
+	$subscription_groups = getpaid_get_subscription_groups($invoice);
558 558
 
559 559
 	// Now let's calculate the totals for each group of subscriptions
560 560
 	$subscription_totals = array();
561 561
 
562
-	foreach ( $subscription_groups as $subscription_key => $items ) {
562
+	foreach ($subscription_groups as $subscription_key => $items) {
563 563
 
564
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
564
+		if (empty($subscription_totals[$subscription_key])) {
565 565
 
566
-			$subscription_totals[ $subscription_key ] = array(
566
+			$subscription_totals[$subscription_key] = array(
567 567
 				'initial_total'   => 0,
568 568
 				'recurring_total' => 0,
569 569
 				'items'           => array(),
@@ -576,34 +576,34 @@  discard block
 block discarded – undo
576 576
 		 * Get the totals of the group.
577 577
 		 * @var GetPaid_Form_Item $item
578 578
 		 */
579
-		foreach ( $items as $item ) {
579
+		foreach ($items as $item) {
580 580
 
581
-			$subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
581
+			$subscription_totals[$subscription_key]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
+			$subscription_totals[$subscription_key]['item_id']                 = $item->get_id();
583
+			$subscription_totals[$subscription_key]['period']                  = $item->get_recurring_period(true);
584
+			$subscription_totals[$subscription_key]['interval']                = $item->get_recurring_interval();
585
+			$subscription_totals[$subscription_key]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
+			$subscription_totals[$subscription_key]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
+			$subscription_totals[$subscription_key]['recurring_limit']         = $item->get_recurring_limit();
588 588
 
589 589
 			// Calculate the next renewal date.
590
-			$period       = $item->get_recurring_period( true );
590
+			$period       = $item->get_recurring_period(true);
591 591
 			$interval     = $item->get_recurring_interval();
592 592
 
593 593
 			// If the subscription item has a trial period...
594
-			if ( $item->has_free_trial() ) {
595
-				$period   = $item->get_trial_period( true );
594
+			if ($item->has_free_trial()) {
595
+				$period   = $item->get_trial_period(true);
596 596
 				$interval = $item->get_trial_interval();
597
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
597
+				$subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period;
598 598
 			}
599 599
 
600
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
600
+			$subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp')));
601 601
 
602 602
 		}
603 603
 
604 604
 	}
605 605
 
606
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
606
+	return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice);
607 607
 }
608 608
 
609 609
 /**
@@ -612,19 +612,19 @@  discard block
 block discarded – undo
612 612
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
613 613
  * @return array
614 614
  */
615
-function getpaid_should_group_subscriptions( $invoice ) {
615
+function getpaid_should_group_subscriptions($invoice) {
616 616
 
617 617
 	$recurring_items = 0;
618 618
 
619
-	foreach ( $invoice->get_items() as $item ) {
619
+	foreach ($invoice->get_items() as $item) {
620 620
 
621
-		if ( $item->is_recurring() ) {
622
-			$recurring_items ++;
621
+		if ($item->is_recurring()) {
622
+			$recurring_items++;
623 623
 		}
624 624
 
625 625
 	}
626 626
 
627
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
627
+	return apply_filters('getpaid_should_group_subscriptions', $recurring_items > 1, $invoice);
628 628
 }
629 629
 
630 630
 /**
@@ -634,12 +634,12 @@  discard block
 block discarded – undo
634 634
  * @param int|false $subscription_id
635 635
  * @return int
636 636
  */
637
-function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
637
+function getpaid_count_subscription_invoices($parent_invoice_id, $subscription_id = false) {
638 638
 	global $wpdb;
639 639
 
640 640
 	$parent_invoice_id = (int) $parent_invoice_id;
641 641
 
642
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
642
+	if (false === $subscription_id || !(bool) get_post_meta($parent_invoice_id, '_wpinv_subscription_id', true)) {
643 643
 
644 644
 		return (int) $wpdb->get_var(
645 645
 			$wpdb->prepare(
@@ -661,10 +661,10 @@  discard block
 block discarded – undo
661 661
 
662 662
 	$count = 0;
663 663
 
664
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
664
+	foreach (wp_parse_id_list($invoice_ids) as $invoice_id) {
665 665
 
666
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
-			$count ++;
666
+		if ($invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta($invoice_id, '_wpinv_subscription_id', true)) {
667
+			$count++;
668 668
 			continue;
669 669
 		}
670 670
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -12,230 +12,230 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26 26
 
27 27
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Validate VAT number.
35
-		$this->validate_vat( $submission );
36
-
37
-		if ( $this->skip_taxes ) {
38
-			return;
39
-		}
40
-
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
43
-		}
44
-
45
-		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
-		}
49
-
50
-	}
51
-
52
-	/**
53
-	 * Maybe process tax.
54
-	 *
55
-	 * @since 1.0.19
56
-	 * @param GetPaid_Form_Item $item
57
-	 * @param GetPaid_Payment_Form_Submission $submission
58
-	 */
59
-	public function process_item_tax( $item, $submission ) {
60
-
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
-
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
-
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
-
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
74
-				continue;
75
-			}
76
-
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
-
80
-		}
81
-
82
-	}
83
-
84
-	/**
85
-	 * Checks if the submission has a digital item.
86
-	 *
87
-	 * @param GetPaid_Payment_Form_Submission $submission
88
-	 * @since 1.0.19
89
-	 * @return bool
90
-	 */
91
-	public function has_digital_item( $submission ) {
92
-
93
-		foreach ( $submission->get_items() as $item ) {
94
-
95
-			if ( 'digital' == $item->get_vat_rule() ) {
96
-				return true;
97
-			}
98
-
99
-		}
100
-
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Checks if this is an eu store.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @return bool
109
-	 */
110
-	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
112
-	}
113
-
114
-	/**
115
-	 * Checks if this is an eu country.
116
-	 *
117
-	 * @param string $country
118
-	 * @since 1.0.19
119
-	 * @return bool
120
-	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
123
-	}
124
-
125
-	/**
126
-	 * Checks if this is an eu purchase.
127
-	 *
128
-	 * @param string $customer_country
129
-	 * @since 1.0.19
130
-	 * @return bool
131
-	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
-	}
135
-
136
-	/**
137
-	 * Retrieves the vat number.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 * @since 1.0.19
141
-	 * @return string
142
-	 */
143
-	public function get_vat_number( $submission ) {
144
-
145
-		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
149
-		}
150
-
151
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
-	}
153
-
154
-	/**
155
-	 * Retrieves the company.
156
-	 *
157
-	 * @param GetPaid_Payment_Form_Submission $submission
158
-	 * @since 1.0.19
159
-	 * @return string
160
-	 */
161
-	public function get_company( $submission ) {
162
-
163
-		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
167
-		}
168
-
169
-		// Retrieve from the invoice.
170
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
-	}
172
-
173
-	/**
174
-	 * Checks if we require a VAT number.
175
-	 *
176
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
177
-	 * @param bool $country_in_eu Whether the customer country is from the EU
178
-	 * @since 1.0.19
179
-	 * @return string
180
-	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
-
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
185
-		$is_eu       = $ip_in_eu || $country_in_eu;
186
-
187
-		return $prevent_b2c && $is_eu;
188
-	}
189
-
190
-	/**
191
-	 * Validate VAT data.
192
-	 *
193
-	 * @param GetPaid_Payment_Form_Submission $submission
194
-	 * @since 1.0.19
195
-	 */
196
-	public function validate_vat( $submission ) {
197
-
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
199
-
200
-		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Validate VAT number.
35
+        $this->validate_vat( $submission );
36
+
37
+        if ( $this->skip_taxes ) {
202 38
             return;
203
-		}
39
+        }
40
+
41
+        foreach ( $submission->get_items() as $item ) {
42
+            $this->process_item_tax( $item, $submission );
43
+        }
44
+
45
+        // Process any existing invoice taxes.
46
+        if ( $submission->has_invoice() ) {
47
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
+        }
49
+
50
+    }
51
+
52
+    /**
53
+     * Maybe process tax.
54
+     *
55
+     * @since 1.0.19
56
+     * @param GetPaid_Form_Item $item
57
+     * @param GetPaid_Payment_Form_Submission $submission
58
+     */
59
+    public function process_item_tax( $item, $submission ) {
60
+
61
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
+
66
+        foreach ( $taxes as $name => $amount ) {
67
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
+
70
+            $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
+
72
+            if ( ! isset( $this->taxes[ $name ] ) ) {
73
+                $this->taxes[ $name ] = $tax;
74
+                continue;
75
+            }
76
+
77
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
+
80
+        }
81
+
82
+    }
83
+
84
+    /**
85
+     * Checks if the submission has a digital item.
86
+     *
87
+     * @param GetPaid_Payment_Form_Submission $submission
88
+     * @since 1.0.19
89
+     * @return bool
90
+     */
91
+    public function has_digital_item( $submission ) {
92
+
93
+        foreach ( $submission->get_items() as $item ) {
94
+
95
+            if ( 'digital' == $item->get_vat_rule() ) {
96
+                return true;
97
+            }
98
+
99
+        }
204 100
 
205
-		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
207
-		$ip_country  = getpaid_get_ip_country();
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Checks if this is an eu store.
106
+     *
107
+     * @since 1.0.19
108
+     * @return bool
109
+     */
110
+    public static function is_eu_store() {
111
+        return self::is_eu_country( wpinv_get_default_country() );
112
+    }
113
+
114
+    /**
115
+     * Checks if this is an eu country.
116
+     *
117
+     * @param string $country
118
+     * @since 1.0.19
119
+     * @return bool
120
+     */
121
+    public static function is_eu_country( $country ) {
122
+        return getpaid_is_eu_state( $country );
123
+    }
124
+
125
+    /**
126
+     * Checks if this is an eu purchase.
127
+     *
128
+     * @param string $customer_country
129
+     * @since 1.0.19
130
+     * @return bool
131
+     */
132
+    public static function is_eu_transaction( $customer_country ) {
133
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
+    }
135
+
136
+    /**
137
+     * Retrieves the vat number.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     * @since 1.0.19
141
+     * @return string
142
+     */
143
+    public function get_vat_number( $submission ) {
144
+
145
+        // Retrieve from the posted number.
146
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
+        if ( ! is_null( $vat_number ) ) {
148
+            return wpinv_clean( $vat_number );
149
+        }
150
+
151
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
+    }
153
+
154
+    /**
155
+     * Retrieves the company.
156
+     *
157
+     * @param GetPaid_Payment_Form_Submission $submission
158
+     * @since 1.0.19
159
+     * @return string
160
+     */
161
+    public function get_company( $submission ) {
162
+
163
+        // Retrieve from the posted data.
164
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
165
+        if ( ! empty( $company ) ) {
166
+            return wpinv_clean( $company );
167
+        }
168
+
169
+        // Retrieve from the invoice.
170
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
+    }
172
+
173
+    /**
174
+     * Checks if we require a VAT number.
175
+     *
176
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
177
+     * @param bool $country_in_eu Whether the customer country is from the EU
178
+     * @since 1.0.19
179
+     * @return string
180
+     */
181
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
+
183
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
+        $prevent_b2c = ! empty( $prevent_b2c );
185
+        $is_eu       = $ip_in_eu || $country_in_eu;
186
+
187
+        return $prevent_b2c && $is_eu;
188
+    }
189
+
190
+    /**
191
+     * Validate VAT data.
192
+     *
193
+     * @param GetPaid_Payment_Form_Submission $submission
194
+     * @since 1.0.19
195
+     */
196
+    public function validate_vat( $submission ) {
197
+
198
+        $in_eu = $this->is_eu_transaction( $submission->country );
199
+
200
+        // Abort if we are not validating vat numbers.
201
+        if ( ! $in_eu ) {
202
+            return;
203
+        }
204
+
205
+        // Prepare variables.
206
+        $vat_number  = $this->get_vat_number( $submission );
207
+        $ip_country  = getpaid_get_ip_country();
208 208
         $is_eu       = $this->is_eu_country( $submission->country );
209 209
         $is_ip_eu    = $this->is_eu_country( $ip_country );
210 210
 
211
-		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
-			return;
214
-		}
211
+        // Maybe abort early for initial fetches.
212
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
+            return;
214
+        }
215 215
 
216
-		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases,
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new Exception(
221
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
222
-			);
219
+            // Ensure that a vat number has been specified.
220
+            throw new Exception(
221
+                __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
222
+            );
223 223
 
224
-		}
224
+        }
225 225
 
226
-		if ( empty( $vat_number ) ) {
227
-			return;
228
-		}
226
+        if ( empty( $vat_number ) ) {
227
+            return;
228
+        }
229 229
 
230
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
232
-		}
230
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
+            throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
232
+        }
233 233
 
234
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
235
-			return;
236
-		}
234
+        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
235
+            return;
236
+        }
237 237
 
238
-		$this->skip_taxes = true;
239
-	}
238
+        $this->skip_taxes = true;
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission taxes class
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param GetPaid_Payment_Form_Submission $submission
31 31
 	 */
32
-	public function __construct( $submission ) {
32
+	public function __construct($submission) {
33 33
 
34 34
 		// Validate VAT number.
35
-		$this->validate_vat( $submission );
35
+		$this->validate_vat($submission);
36 36
 
37
-		if ( $this->skip_taxes ) {
37
+		if ($this->skip_taxes) {
38 38
 			return;
39 39
 		}
40 40
 
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
41
+		foreach ($submission->get_items() as $item) {
42
+			$this->process_item_tax($item, $submission);
43 43
 		}
44 44
 
45 45
 		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
46
+		if ($submission->has_invoice()) {
47
+			$this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes);
48 48
 		}
49 49
 
50 50
 	}
@@ -56,26 +56,26 @@  discard block
 block discarded – undo
56 56
 	 * @param GetPaid_Form_Item $item
57 57
 	 * @param GetPaid_Payment_Form_Submission $submission
58 58
 	 */
59
-	public function process_item_tax( $item, $submission ) {
59
+	public function process_item_tax($item, $submission) {
60 60
 
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
61
+		$rates    = getpaid_get_item_tax_rates($item, $submission->country, $submission->state);
62
+		$rates    = getpaid_filter_item_tax_rates($item, $rates);
63
+		$taxes    = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates);
64
+		$r_taxes  = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates);
65 65
 
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
66
+		foreach ($taxes as $name => $amount) {
67
+			$recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0;
68
+			$tax       = getpaid_prepare_item_tax($item, $name, $amount, $recurring);
69 69
 
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
70
+			$item->item_tax += wpinv_sanitize_amount($tax['initial_tax']);
71 71
 
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
72
+			if (!isset($this->taxes[$name])) {
73
+				$this->taxes[$name] = $tax;
74 74
 				continue;
75 75
 			}
76 76
 
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
+			$this->taxes[$name]['initial_tax']   += $tax['initial_tax'];
78
+			$this->taxes[$name]['recurring_tax'] += $tax['recurring_tax'];
79 79
 
80 80
 		}
81 81
 
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 	 * @since 1.0.19
89 89
 	 * @return bool
90 90
 	 */
91
-	public function has_digital_item( $submission ) {
91
+	public function has_digital_item($submission) {
92 92
 
93
-		foreach ( $submission->get_items() as $item ) {
93
+		foreach ($submission->get_items() as $item) {
94 94
 
95
-			if ( 'digital' == $item->get_vat_rule() ) {
95
+			if ('digital' == $item->get_vat_rule()) {
96 96
 				return true;
97 97
 			}
98 98
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 * @return bool
109 109
 	 */
110 110
 	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
111
+		return self::is_eu_country(wpinv_get_default_country());
112 112
 	}
113 113
 
114 114
 	/**
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 * @since 1.0.19
119 119
 	 * @return bool
120 120
 	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
121
+	public static function is_eu_country($country) {
122
+		return getpaid_is_eu_state($country);
123 123
 	}
124 124
 
125 125
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @since 1.0.19
130 130
 	 * @return bool
131 131
 	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
+	public static function is_eu_transaction($customer_country) {
133
+		return self::is_eu_country($customer_country) && self::is_eu_store();
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @since 1.0.19
141 141
 	 * @return string
142 142
 	 */
143
-	public function get_vat_number( $submission ) {
143
+	public function get_vat_number($submission) {
144 144
 
145 145
 		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
146
+		$vat_number = $submission->get_field('wpinv_vat_number', 'billing');
147
+		if (!is_null($vat_number)) {
148
+			return wpinv_clean($vat_number);
149 149
 		}
150 150
 
151 151
 		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 	 * @since 1.0.19
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_company( $submission ) {
161
+	public function get_company($submission) {
162 162
 
163 163
 		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
164
+		$company = $submission->get_field('wpinv_company', 'billing');
165
+		if (!empty($company)) {
166
+			return wpinv_clean($company);
167 167
 		}
168 168
 
169 169
 		// Retrieve from the invoice.
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 	 * @since 1.0.19
179 179
 	 * @return string
180 180
 	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
181
+	public function requires_vat($ip_in_eu, $country_in_eu) {
182 182
 
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
183
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
184
+		$prevent_b2c = !empty($prevent_b2c);
185 185
 		$is_eu       = $ip_in_eu || $country_in_eu;
186 186
 
187 187
 		return $prevent_b2c && $is_eu;
@@ -193,45 +193,45 @@  discard block
 block discarded – undo
193 193
 	 * @param GetPaid_Payment_Form_Submission $submission
194 194
 	 * @since 1.0.19
195 195
 	 */
196
-	public function validate_vat( $submission ) {
196
+	public function validate_vat($submission) {
197 197
 
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
198
+		$in_eu = $this->is_eu_transaction($submission->country);
199 199
 
200 200
 		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
201
+		if (!$in_eu) {
202 202
             return;
203 203
 		}
204 204
 
205 205
 		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
206
+		$vat_number  = $this->get_vat_number($submission);
207 207
 		$ip_country  = getpaid_get_ip_country();
208
-        $is_eu       = $this->is_eu_country( $submission->country );
209
-        $is_ip_eu    = $this->is_eu_country( $ip_country );
208
+        $is_eu       = $this->is_eu_country($submission->country);
209
+        $is_ip_eu    = $this->is_eu_country($ip_country);
210 210
 
211 211
 		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
212
+		if ($submission->is_initial_fetch() && empty($vat_number)) {
213 213
 			return;
214 214
 		}
215 215
 
216 216
 		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
217
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
218 218
 
219 219
 			// Ensure that a vat number has been specified.
220 220
 			throw new Exception(
221
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
221
+				__('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing')
222 222
 			);
223 223
 
224 224
 		}
225 225
 
226
-		if ( empty( $vat_number ) ) {
226
+		if (empty($vat_number)) {
227 227
 			return;
228 228
 		}
229 229
 
230
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
230
+		if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) {
231
+			throw new Exception(__('Your VAT number is invalid', 'invoicing'));
232 232
 		}
233 233
 
234
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
234
+		if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) {
235 235
 			return;
236 236
 		}
237 237
 
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@
 block discarded – undo
239 239
         do_action( 'getpaid_checkout_invoice_exception', $invoice );
240 240
     }
241 241
 
242
-	// Do we have any errors?
242
+    // Do we have any errors?
243 243
     if ( wpinv_get_errors() ) {
244 244
         $response['data'] = getpaid_get_errors_html( true, false );
245 245
     } else {
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -1,155 +1,155 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_is_subscription_payment( $invoice = '' ) {
3
-    if ( empty( $invoice ) ) {
2
+function wpinv_is_subscription_payment($invoice = '') {
3
+    if (empty($invoice)) {
4 4
         return false;
5 5
     }
6 6
     
7
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
8
-        $invoice = wpinv_get_invoice( $invoice );
7
+    if (!is_object($invoice) && is_scalar($invoice)) {
8
+        $invoice = wpinv_get_invoice($invoice);
9 9
     }
10 10
     
11
-    if ( empty( $invoice ) ) {
11
+    if (empty($invoice)) {
12 12
         return false;
13 13
     }
14 14
         
15
-    if ( $invoice->is_renewal() ) {
15
+    if ($invoice->is_renewal()) {
16 16
         return true;
17 17
     }
18 18
 
19 19
     return false;
20 20
 }
21 21
 
22
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
23
-    if ( empty( $invoice ) ) {
22
+function wpinv_payment_link_transaction_id($invoice = '') {
23
+    if (empty($invoice)) {
24 24
         return false;
25 25
     }
26 26
     
27
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
28
-        $invoice = wpinv_get_invoice( $invoice );
27
+    if (!is_object($invoice) && is_scalar($invoice)) {
28
+        $invoice = wpinv_get_invoice($invoice);
29 29
     }
30 30
     
31
-    if ( empty( $invoice ) ) {
31
+    if (empty($invoice)) {
32 32
         return false;
33 33
     }
34 34
 
35
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
35
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
36 36
 }
37 37
 
38
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
39
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
38
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
39
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
40 40
     
41
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
42
-        $amount = __( 'Free', 'invoicing' );
41
+    if ($trial_interval > 0 && !empty($trial_period)) {
42
+        $amount = __('Free', 'invoicing');
43 43
         $interval = $trial_interval;
44 44
         $period = $trial_period;
45 45
     }
46 46
     
47 47
     $description = '';
48
-    switch ( $period ) {
48
+    switch ($period) {
49 49
         case 'D' :
50 50
         case 'day' :
51
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
51
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
52 52
             break;
53 53
         case 'W' :
54 54
         case 'week' :
55
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
55
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
56 56
             break;
57 57
         case 'M' :
58 58
         case 'month' :
59
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
59
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
60 60
             break;
61 61
         case 'Y' :
62 62
         case 'year' :
63
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
63
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
64 64
             break;
65 65
     }
66 66
 
67
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
67
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
68 68
 }
69 69
 
70
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
71
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
72
-    $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
70
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
71
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
72
+    $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0;
73 73
     
74 74
     $description = '';
75
-    switch ( $period ) {
75
+    switch ($period) {
76 76
         case 'D' :
77 77
         case 'day' :            
78
-            if ( (int)$bill_times > 0 ) {
79
-                if ( $interval > 1 ) {
80
-                    if ( $bill_times > 1 ) {
81
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
78
+            if ((int) $bill_times > 0) {
79
+                if ($interval > 1) {
80
+                    if ($bill_times > 1) {
81
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
82 82
                     } else {
83
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
83
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
84 84
                     }
85 85
                 } else {
86
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
86
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
87 87
                 }
88 88
             } else {
89
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
89
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
90 90
             }
91 91
             break;
92 92
         case 'W' :
93 93
         case 'week' :            
94
-            if ( (int)$bill_times > 0 ) {
95
-                if ( $interval > 1 ) {
96
-                    if ( $bill_times > 1 ) {
97
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
94
+            if ((int) $bill_times > 0) {
95
+                if ($interval > 1) {
96
+                    if ($bill_times > 1) {
97
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
98 98
                     } else {
99
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
99
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
100 100
                     }
101 101
                 } else {
102
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
102
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
103 103
                 }
104 104
             } else {
105
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
105
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
106 106
             }
107 107
             break;
108 108
         case 'M' :
109 109
         case 'month' :            
110
-            if ( (int)$bill_times > 0 ) {
111
-                if ( $interval > 1 ) {
112
-                    if ( $bill_times > 1 ) {
113
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
110
+            if ((int) $bill_times > 0) {
111
+                if ($interval > 1) {
112
+                    if ($bill_times > 1) {
113
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
114 114
                     } else {
115
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
115
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
116 116
                     }
117 117
                 } else {
118
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
118
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
119 119
                 }
120 120
             } else {
121
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
121
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
122 122
             }
123 123
             break;
124 124
         case 'Y' :
125 125
         case 'year' :            
126
-            if ( (int)$bill_times > 0 ) {
127
-                if ( $interval > 1 ) {
128
-                    if ( $bill_times > 1 ) {
129
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
126
+            if ((int) $bill_times > 0) {
127
+                if ($interval > 1) {
128
+                    if ($bill_times > 1) {
129
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
130 130
                     } else {
131
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
131
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
132 132
                     }
133 133
                 } else {
134
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
134
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
135 135
                 }
136 136
             } else {
137
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
137
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
138 138
             }
139 139
             break;
140 140
     }
141 141
 
142
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
142
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
143 143
 }
144 144
 
145
-function wpinv_subscription_payment_desc( $invoice ) {
146
-    if ( empty( $invoice ) ) {
145
+function wpinv_subscription_payment_desc($invoice) {
146
+    if (empty($invoice)) {
147 147
         return NULL;
148 148
     }
149 149
 
150 150
     $description = '';
151
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
-        if ( $item->has_free_trial() ) {
151
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
152
+        if ($item->has_free_trial()) {
153 153
             $trial_period = $item->get_trial_period();
154 154
             $trial_interval = $item->get_trial_interval();
155 155
         } else {
@@ -157,40 +157,40 @@  discard block
 block discarded – undo
157 157
             $trial_interval = 0;
158 158
         }
159 159
         
160
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
160
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
161 161
     }
162 162
     
163
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
163
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
164 164
 }
165 165
 
166
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
167
-    $initial_total      = wpinv_round_amount( $initial );
168
-    $recurring_total    = wpinv_round_amount( $recurring );
166
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
167
+    $initial_total      = wpinv_round_amount($initial);
168
+    $recurring_total    = wpinv_round_amount($recurring);
169 169
     
170
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
170
+    if ($trial_interval > 0 && !empty($trial_period)) {
171 171
         // Free trial
172 172
     } else {
173
-        if ( $bill_times == 1 ) {
173
+        if ($bill_times == 1) {
174 174
             $recurring_total = $initial_total;
175
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
175
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
176 176
             $bill_times--;
177 177
         }
178 178
     }
179 179
     
180
-    $initial_amount     = wpinv_price( $initial_total, $currency );
181
-    $recurring_amount   = wpinv_price( $recurring_total, $currency );
180
+    $initial_amount     = wpinv_price($initial_total, $currency);
181
+    $recurring_amount   = wpinv_price($recurring_total, $currency);
182 182
     
183
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
183
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
184 184
         
185
-    if ( $initial_total != $recurring_total ) {
186
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
185
+    if ($initial_total != $recurring_total) {
186
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
187 187
         
188
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
188
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
189 189
     } else {
190 190
         $description    = $recurring;
191 191
     }
192 192
     
193
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
193
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
194 194
 }
195 195
 
196 196
 /**
@@ -200,27 +200,27 @@  discard block
 block discarded – undo
200 200
  * @param string $card_number Card number.
201 201
  * @return string
202 202
  */
203
-function getpaid_get_card_name( $card_number ) {
203
+function getpaid_get_card_name($card_number) {
204 204
 
205 205
     // Known regexes.
206 206
     $regexes = array(
207
-        '/^4/'                     => __( 'Visa', 'invoicing' ),
208
-        '/^5[1-5]/'                => __( 'Mastercard', 'invoicing' ),
209
-        '/^3[47]/'                 => __( 'Amex', 'invoicing' ),
210
-        '/^3(?:0[0-5]|[68])/'      => __( 'Diners Club', 'invoicing' ),
211
-        '/^6(?:011|5)/'            => __( 'Discover', 'invoicing' ),
212
-        '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ),
207
+        '/^4/'                     => __('Visa', 'invoicing'),
208
+        '/^5[1-5]/'                => __('Mastercard', 'invoicing'),
209
+        '/^3[47]/'                 => __('Amex', 'invoicing'),
210
+        '/^3(?:0[0-5]|[68])/'      => __('Diners Club', 'invoicing'),
211
+        '/^6(?:011|5)/'            => __('Discover', 'invoicing'),
212
+        '/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'),
213 213
     );
214 214
 
215 215
     // Confirm if one matches.
216
-    foreach ( $regexes as $regex => $card ) {
217
-        if ( preg_match ( $regex, $card_number ) >= 1 ) {
216
+    foreach ($regexes as $regex => $card) {
217
+        if (preg_match($regex, $card_number) >= 1) {
218 218
             return $card;
219 219
         }
220 220
     }
221 221
 
222 222
     // None matched.
223
-    return __( 'Card', 'invoicing' );
223
+    return __('Card', 'invoicing');
224 224
 
225 225
 }
226 226
 
@@ -229,23 +229,23 @@  discard block
 block discarded – undo
229 229
  * 
230 230
  * @param WPInv_Invoice|int|null $invoice
231 231
  */
232
-function wpinv_send_back_to_checkout( $invoice = null ) {
233
-    $response = array( 'success' => false );
234
-    $invoice  = wpinv_get_invoice( $invoice );
232
+function wpinv_send_back_to_checkout($invoice = null) {
233
+    $response = array('success' => false);
234
+    $invoice  = wpinv_get_invoice($invoice);
235 235
 
236 236
     // Was an invoice created?
237
-    if ( ! empty( $invoice ) ) {
238
-        $invoice             = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice;
237
+    if (!empty($invoice)) {
238
+        $invoice             = is_scalar($invoice) ? new WPInv_Invoice($invoice) : $invoice;
239 239
         $response['invoice'] = $invoice->get_id();
240
-        do_action( 'getpaid_checkout_invoice_exception', $invoice );
240
+        do_action('getpaid_checkout_invoice_exception', $invoice);
241 241
     }
242 242
 
243 243
 	// Do we have any errors?
244
-    if ( wpinv_get_errors() ) {
245
-        $response['data'] = getpaid_get_errors_html( true, false );
244
+    if (wpinv_get_errors()) {
245
+        $response['data'] = getpaid_get_errors_html(true, false);
246 246
     } else {
247
-        $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' );
247
+        $response['data'] = __('An error occured while processing your payment. Please try again.', 'invoicing');
248 248
     }
249 249
 
250
-    wp_send_json( $response );
250
+    wp_send_json($response);
251 251
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -12,180 +12,180 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
133 117
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
138 125
 
139
-		return $invoice;
140
-	}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
141 131
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
132
+        $invoice = $submission->get_invoice();
150 133
 
151
-		$submission = $this->payment_form_submission;
152
-		$data       = $submission->get_data();
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
153 138
 
154
-		// Set-up the invoice details.
155
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
-		$invoice->set_user_id( $this->get_submission_customer() );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
139
+        return $invoice;
140
+    }
141
+
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+        $data       = $submission->get_data();
153
+
154
+        // Set-up the invoice details.
155
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
+        $invoice->set_user_id( $this->get_submission_customer() );
157
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158 158
         $invoice->set_items( $items );
159 159
         $invoice->set_fees( $submission->get_fees() );
160 160
         $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $data['wpi-gateway'] );
161
+        $invoice->set_discounts( $submission->get_discounts() );
162
+        $invoice->set_gateway( $data['wpi-gateway'] );
163 163
 
164
-		$address_confirmed = $submission->get_field( 'confirm-address' );
165
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
164
+        $address_confirmed = $submission->get_field( 'confirm-address' );
165
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
166 166
 
167
-		if ( $submission->has_discount_code() ) {
167
+        if ( $submission->has_discount_code() ) {
168 168
             $invoice->set_discount_code( $submission->get_discount_code() );
169
-		}
170
-
171
-		getpaid_maybe_add_default_address( $invoice );
172
-		return $invoice;
173
-	}
174
-
175
-	/**
176
-	 * Retrieves the submission's customer.
177
-	 *
178
-	 * @return int The customer id.
179
-	 */
180
-	protected function get_submission_customer() {
181
-		$submission = $this->payment_form_submission;
182
-
183
-		// If this is an existing invoice...
184
-		if ( $submission->has_invoice() ) {
185
-			return $submission->get_invoice()->get_user_id();
186
-		}
187
-
188
-		// (Maybe) create the user.
169
+        }
170
+
171
+        getpaid_maybe_add_default_address( $invoice );
172
+        return $invoice;
173
+    }
174
+
175
+    /**
176
+     * Retrieves the submission's customer.
177
+     *
178
+     * @return int The customer id.
179
+     */
180
+    protected function get_submission_customer() {
181
+        $submission = $this->payment_form_submission;
182
+
183
+        // If this is an existing invoice...
184
+        if ( $submission->has_invoice() ) {
185
+            return $submission->get_invoice()->get_user_id();
186
+        }
187
+
188
+        // (Maybe) create the user.
189 189
         $user = get_current_user_id();
190 190
 
191 191
         if ( empty( $user ) ) {
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
         if ( empty( $user ) ) {
196 196
             $user = wpinv_create_user( $submission->get_billing_email() );
197 197
 
198
-			// (Maybe) send new user notification.
199
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
200
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
201
-				wp_send_new_user_notifications( $user, 'user' );
202
-			}
198
+            // (Maybe) send new user notification.
199
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
200
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
201
+                wp_send_new_user_notifications( $user, 'user' );
202
+            }
203 203
 
204 204
         }
205 205
 
@@ -209,31 +209,31 @@  discard block
 block discarded – undo
209 209
 
210 210
         if ( is_numeric( $user ) ) {
211 211
             return $user;
212
-		}
212
+        }
213 213
 
214
-		return $user->ID;
214
+        return $user->ID;
215 215
 
216
-	}
216
+    }
217 217
 
218
-	/**
218
+    /**
219 219
      * Prepares submission data for saving to the database.
220 220
      *
221
-	 * @return array
221
+     * @return array
222 222
      */
223 223
     public function prepare_submission_data_for_saving() {
224 224
 
225
-		$submission = $this->payment_form_submission;
225
+        $submission = $this->payment_form_submission;
226 226
 
227
-		// Prepared submission details.
227
+        // Prepared submission details.
228 228
         $prepared = array();
229 229
 
230 230
         // Raw submission details.
231
-		$data     = $submission->get_data();
231
+        $data     = $submission->get_data();
232 232
 
233
-		// Loop through the submitted details.
233
+        // Loop through the submitted details.
234 234
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
235 235
 
236
-			// Skip premade fields.
236
+            // Skip premade fields.
237 237
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
238 238
                 continue;
239 239
             }
@@ -251,176 +251,176 @@  discard block
 block discarded – undo
251 251
                     $label = $field['label'];
252 252
                 }
253 253
 
254
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
254
+                $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
255 255
 
256 256
             }
257 257
 
258
-		}
258
+        }
259 259
 
260
-		return $prepared;
260
+        return $prepared;
261 261
 
262
-	}
262
+    }
263 263
 
264
-	/**
264
+    /**
265 265
      * Retrieves address details.
266 266
      *
267
-	 * @return array
268
-	 * @param WPInv_Invoice $invoice
269
-	 * @param string $type
267
+     * @return array
268
+     * @param WPInv_Invoice $invoice
269
+     * @param string $type
270 270
      */
271 271
     public function prepare_address_details( $invoice, $type = 'billing' ) {
272 272
 
273
-		$data     = $this->payment_form_submission->get_data();
274
-		$type     = sanitize_key( $type );
275
-		$address  = array();
276
-		$prepared = array();
273
+        $data     = $this->payment_form_submission->get_data();
274
+        $type     = sanitize_key( $type );
275
+        $address  = array();
276
+        $prepared = array();
277 277
 
278
-		if ( ! empty( $data[ $type ] ) ) {
279
-			$address = $data[ $type ];
280
-		}
278
+        if ( ! empty( $data[ $type ] ) ) {
279
+            $address = $data[ $type ];
280
+        }
281 281
 
282
-		// Clean address details.
283
-		foreach ( $address as $key => $value ) {
284
-			$key             = sanitize_key( $key );
285
-			$key             = str_replace( 'wpinv_', '', $key );
286
-			$value           = wpinv_clean( $value );
287
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
288
-		}
282
+        // Clean address details.
283
+        foreach ( $address as $key => $value ) {
284
+            $key             = sanitize_key( $key );
285
+            $key             = str_replace( 'wpinv_', '', $key );
286
+            $value           = wpinv_clean( $value );
287
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
288
+        }
289 289
 
290
-		// Filter address details.
291
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
290
+        // Filter address details.
291
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
292 292
 
293
-		// Remove non-whitelisted values.
294
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
293
+        // Remove non-whitelisted values.
294
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
295 295
 
296
-	}
296
+    }
297 297
 
298
-	/**
298
+    /**
299 299
      * Prepares the billing details.
300 300
      *
301
-	 * @return array
302
-	 * @param WPInv_Invoice $invoice
301
+     * @return array
302
+     * @param WPInv_Invoice $invoice
303 303
      */
304 304
     protected function prepare_billing_info( &$invoice ) {
305 305
 
306
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
306
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
307 307
 
308
-		// Update the invoice with the billing details.
309
-		$invoice->set_props( $billing_address );
308
+        // Update the invoice with the billing details.
309
+        $invoice->set_props( $billing_address );
310 310
 
311
-	}
311
+    }
312 312
 
313
-	/**
313
+    /**
314 314
      * Prepares the shipping details.
315 315
      *
316
-	 * @return array
317
-	 * @param WPInv_Invoice $invoice
316
+     * @return array
317
+     * @param WPInv_Invoice $invoice
318 318
      */
319 319
     protected function prepare_shipping_info( $invoice ) {
320 320
 
321
-		$data = $this->payment_form_submission->get_data();
321
+        $data = $this->payment_form_submission->get_data();
322 322
 
323
-		if ( empty( $data['same-shipping-address'] ) ) {
324
-			return $this->prepare_address_details( $invoice, 'shipping' );
325
-		}
323
+        if ( empty( $data['same-shipping-address'] ) ) {
324
+            return $this->prepare_address_details( $invoice, 'shipping' );
325
+        }
326 326
 
327
-		return $this->prepare_address_details( $invoice, 'billing' );
327
+        return $this->prepare_address_details( $invoice, 'billing' );
328 328
 
329
-	}
329
+    }
330 330
 
331
-	/**
332
-	 * Confirms the submission is valid and send users to the gateway.
333
-	 *
334
-	 * @param WPInv_Invoice $invoice
335
-	 * @param array $prepared_payment_form_data
336
-	 * @param array $shipping
337
-	 */
338
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
331
+    /**
332
+     * Confirms the submission is valid and send users to the gateway.
333
+     *
334
+     * @param WPInv_Invoice $invoice
335
+     * @param array $prepared_payment_form_data
336
+     * @param array $shipping
337
+     */
338
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
339 339
 
340
-		// Ensure the invoice exists.
340
+        // Ensure the invoice exists.
341 341
         if ( ! $invoice->exists() ) {
342 342
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
343 343
         }
344 344
 
345
-		// Save payment form data.
346
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
345
+        // Save payment form data.
346
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
347 347
         if ( ! empty( $prepared_payment_form_data ) ) {
348 348
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
349
-		}
349
+        }
350 350
 
351
-		// Save payment form data.
351
+        // Save payment form data.
352 352
         if ( ! empty( $shipping ) ) {
353 353
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
354
-		}
354
+        }
355 355
 
356
-		// Backwards compatibility.
356
+        // Backwards compatibility.
357 357
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
358 358
 
359
-		$this->process_payment( $invoice );
359
+        $this->process_payment( $invoice );
360 360
 
361 361
         // If we are here, there was an error.
362
-		wpinv_send_back_to_checkout( $invoice );
362
+        wpinv_send_back_to_checkout( $invoice );
363 363
 
364
-	}
364
+    }
365 365
 
366
-	/**
367
-	 * Processes the actual payment.
368
-	 *
369
-	 * @param WPInv_Invoice $invoice
370
-	 */
371
-	protected function process_payment( $invoice ) {
366
+    /**
367
+     * Processes the actual payment.
368
+     *
369
+     * @param WPInv_Invoice $invoice
370
+     */
371
+    protected function process_payment( $invoice ) {
372 372
 
373
-		// Clear any checkout errors.
374
-		wpinv_clear_errors();
373
+        // Clear any checkout errors.
374
+        wpinv_clear_errors();
375 375
 
376
-		// No need to send free invoices to the gateway.
377
-		if ( $invoice->is_free() ) {
378
-			$this->process_free_payment( $invoice );
379
-		}
376
+        // No need to send free invoices to the gateway.
377
+        if ( $invoice->is_free() ) {
378
+            $this->process_free_payment( $invoice );
379
+        }
380 380
 
381
-		$submission = $this->payment_form_submission;
381
+        $submission = $this->payment_form_submission;
382 382
 
383
-		// Fires before sending to the gateway.
384
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
383
+        // Fires before sending to the gateway.
384
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
385 385
 
386
-		// Allow the sumission data to be modified before it is sent to the gateway.
387
-		$submission_data    = $submission->get_data();
388
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
389
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
386
+        // Allow the sumission data to be modified before it is sent to the gateway.
387
+        $submission_data    = $submission->get_data();
388
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
389
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
390 390
 
391
-		// Validate the currency.
392
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
393
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
394
-		}
391
+        // Validate the currency.
392
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
393
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
394
+        }
395 395
 
396
-		// Check to see if we have any errors.
397
-		if ( wpinv_get_errors() ) {
398
-			wpinv_send_back_to_checkout( $invoice );
399
-		}
396
+        // Check to see if we have any errors.
397
+        if ( wpinv_get_errors() ) {
398
+            wpinv_send_back_to_checkout( $invoice );
399
+        }
400 400
 
401
-		// Send info to the gateway for payment processing
402
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
401
+        // Send info to the gateway for payment processing
402
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
403 403
 
404
-		// Backwards compatibility.
405
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
404
+        // Backwards compatibility.
405
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
406 406
 
407
-	}
407
+    }
408 408
 
409
-	/**
410
-	 * Marks the invoice as paid in case the checkout is free.
411
-	 *
412
-	 * @param WPInv_Invoice $invoice
413
-	 */
414
-	protected function process_free_payment( $invoice ) {
409
+    /**
410
+     * Marks the invoice as paid in case the checkout is free.
411
+     *
412
+     * @param WPInv_Invoice $invoice
413
+     */
414
+    protected function process_free_payment( $invoice ) {
415 415
 
416
-		$invoice->set_gateway( 'none' );
417
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
418
-		$invoice->mark_paid();
419
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
416
+        $invoice->set_gateway( 'none' );
417
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
418
+        $invoice->mark_paid();
419
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
420 420
 
421
-	}
421
+    }
422 422
 
423
-	/**
423
+    /**
424 424
      * Sends a redrect response to payment details.
425 425
      *
426 426
      */
Please login to merge, or discard this patch.
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,29 +146,29 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 		$data       = $submission->get_data();
153 153
 
154 154
 		// Set-up the invoice details.
155
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
-		$invoice->set_user_id( $this->get_submission_customer() );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158
-        $invoice->set_items( $items );
159
-        $invoice->set_fees( $submission->get_fees() );
160
-        $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $data['wpi-gateway'] );
163
-
164
-		$address_confirmed = $submission->get_field( 'confirm-address' );
165
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
166
-
167
-		if ( $submission->has_discount_code() ) {
168
-            $invoice->set_discount_code( $submission->get_discount_code() );
155
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
156
+		$invoice->set_user_id($this->get_submission_customer());
157
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
158
+        $invoice->set_items($items);
159
+        $invoice->set_fees($submission->get_fees());
160
+        $invoice->set_taxes($submission->get_taxes());
161
+		$invoice->set_discounts($submission->get_discounts());
162
+		$invoice->set_gateway($data['wpi-gateway']);
163
+
164
+		$address_confirmed = $submission->get_field('confirm-address');
165
+		$invoice->set_address_confirmed(!empty($address_confirmed));
166
+
167
+		if ($submission->has_discount_code()) {
168
+            $invoice->set_discount_code($submission->get_discount_code());
169 169
 		}
170 170
 
171
-		getpaid_maybe_add_default_address( $invoice );
171
+		getpaid_maybe_add_default_address($invoice);
172 172
 		return $invoice;
173 173
 	}
174 174
 
@@ -181,33 +181,33 @@  discard block
 block discarded – undo
181 181
 		$submission = $this->payment_form_submission;
182 182
 
183 183
 		// If this is an existing invoice...
184
-		if ( $submission->has_invoice() ) {
184
+		if ($submission->has_invoice()) {
185 185
 			return $submission->get_invoice()->get_user_id();
186 186
 		}
187 187
 
188 188
 		// (Maybe) create the user.
189 189
         $user = get_current_user_id();
190 190
 
191
-        if ( empty( $user ) ) {
192
-            $user = get_user_by( 'email', $submission->get_billing_email() );
191
+        if (empty($user)) {
192
+            $user = get_user_by('email', $submission->get_billing_email());
193 193
         }
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = wpinv_create_user( $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = wpinv_create_user($submission->get_billing_email());
197 197
 
198 198
 			// (Maybe) send new user notification.
199
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
200
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
201
-				wp_send_new_user_notifications( $user, 'user' );
199
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
200
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) {
201
+				wp_send_new_user_notifications($user, 'user');
202 202
 			}
203 203
 
204 204
         }
205 205
 
206
-        if ( is_wp_error( $user ) ) {
207
-            wp_send_json_error( $user->get_error_message() );
206
+        if (is_wp_error($user)) {
207
+            wp_send_json_error($user->get_error_message());
208 208
         }
209 209
 
210
-        if ( is_numeric( $user ) ) {
210
+        if (is_numeric($user)) {
211 211
             return $user;
212 212
 		}
213 213
 
@@ -228,30 +228,30 @@  discard block
 block discarded – undo
228 228
         $prepared = array();
229 229
 
230 230
         // Raw submission details.
231
-		$data     = $submission->get_data();
231
+		$data = $submission->get_data();
232 232
 
233 233
 		// Loop through the submitted details.
234
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
234
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
235 235
 
236 236
 			// Skip premade fields.
237
-            if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
237
+            if (!empty($field['premade']) || $field['type'] == 'address') {
238 238
                 continue;
239 239
             }
240 240
 
241 241
             // If it is required and not set, abort.
242
-            if ( ! $submission->is_required_field_set( $field ) ) {
243
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
242
+            if (!$submission->is_required_field_set($field)) {
243
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
244 244
             }
245 245
 
246 246
             // Handle misc fields.
247
-            if ( isset( $data[ $field['id'] ] ) ) {
247
+            if (isset($data[$field['id']])) {
248 248
                 $label = $field['id'];
249 249
 
250
-                if ( isset( $field['label'] ) ) {
250
+                if (isset($field['label'])) {
251 251
                     $label = $field['label'];
252 252
                 }
253 253
 
254
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
254
+				$prepared[wpinv_clean($label)] = wp_kses_post($data[$field['id']]);
255 255
 
256 256
             }
257 257
 
@@ -268,30 +268,30 @@  discard block
 block discarded – undo
268 268
 	 * @param WPInv_Invoice $invoice
269 269
 	 * @param string $type
270 270
      */
271
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
271
+    public function prepare_address_details($invoice, $type = 'billing') {
272 272
 
273 273
 		$data     = $this->payment_form_submission->get_data();
274
-		$type     = sanitize_key( $type );
274
+		$type     = sanitize_key($type);
275 275
 		$address  = array();
276 276
 		$prepared = array();
277 277
 
278
-		if ( ! empty( $data[ $type ] ) ) {
279
-			$address = $data[ $type ];
278
+		if (!empty($data[$type])) {
279
+			$address = $data[$type];
280 280
 		}
281 281
 
282 282
 		// Clean address details.
283
-		foreach ( $address as $key => $value ) {
284
-			$key             = sanitize_key( $key );
285
-			$key             = str_replace( 'wpinv_', '', $key );
286
-			$value           = wpinv_clean( $value );
287
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
283
+		foreach ($address as $key => $value) {
284
+			$key             = sanitize_key($key);
285
+			$key             = str_replace('wpinv_', '', $key);
286
+			$value           = wpinv_clean($value);
287
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
288 288
 		}
289 289
 
290 290
 		// Filter address details.
291
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
291
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
292 292
 
293 293
 		// Remove non-whitelisted values.
294
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
294
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
295 295
 
296 296
 	}
297 297
 
@@ -301,12 +301,12 @@  discard block
 block discarded – undo
301 301
 	 * @return array
302 302
 	 * @param WPInv_Invoice $invoice
303 303
      */
304
-    protected function prepare_billing_info( &$invoice ) {
304
+    protected function prepare_billing_info(&$invoice) {
305 305
 
306
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
306
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
307 307
 
308 308
 		// Update the invoice with the billing details.
309
-		$invoice->set_props( $billing_address );
309
+		$invoice->set_props($billing_address);
310 310
 
311 311
 	}
312 312
 
@@ -316,15 +316,15 @@  discard block
 block discarded – undo
316 316
 	 * @return array
317 317
 	 * @param WPInv_Invoice $invoice
318 318
      */
319
-    protected function prepare_shipping_info( $invoice ) {
319
+    protected function prepare_shipping_info($invoice) {
320 320
 
321 321
 		$data = $this->payment_form_submission->get_data();
322 322
 
323
-		if ( empty( $data['same-shipping-address'] ) ) {
324
-			return $this->prepare_address_details( $invoice, 'shipping' );
323
+		if (empty($data['same-shipping-address'])) {
324
+			return $this->prepare_address_details($invoice, 'shipping');
325 325
 		}
326 326
 
327
-		return $this->prepare_address_details( $invoice, 'billing' );
327
+		return $this->prepare_address_details($invoice, 'billing');
328 328
 
329 329
 	}
330 330
 
@@ -335,31 +335,31 @@  discard block
 block discarded – undo
335 335
 	 * @param array $prepared_payment_form_data
336 336
 	 * @param array $shipping
337 337
 	 */
338
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
338
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
339 339
 
340 340
 		// Ensure the invoice exists.
341
-        if ( ! $invoice->exists() ) {
342
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
341
+        if (!$invoice->exists()) {
342
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
343 343
         }
344 344
 
345 345
 		// Save payment form data.
346
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
347
-        if ( ! empty( $prepared_payment_form_data ) ) {
348
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
346
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
347
+        if (!empty($prepared_payment_form_data)) {
348
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
349 349
 		}
350 350
 
351 351
 		// Save payment form data.
352
-        if ( ! empty( $shipping ) ) {
353
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
352
+        if (!empty($shipping)) {
353
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
354 354
 		}
355 355
 
356 356
 		// Backwards compatibility.
357
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
357
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
358 358
 
359
-		$this->process_payment( $invoice );
359
+		$this->process_payment($invoice);
360 360
 
361 361
         // If we are here, there was an error.
362
-		wpinv_send_back_to_checkout( $invoice );
362
+		wpinv_send_back_to_checkout($invoice);
363 363
 
364 364
 	}
365 365
 
@@ -368,41 +368,41 @@  discard block
 block discarded – undo
368 368
 	 *
369 369
 	 * @param WPInv_Invoice $invoice
370 370
 	 */
371
-	protected function process_payment( $invoice ) {
371
+	protected function process_payment($invoice) {
372 372
 
373 373
 		// Clear any checkout errors.
374 374
 		wpinv_clear_errors();
375 375
 
376 376
 		// No need to send free invoices to the gateway.
377
-		if ( $invoice->is_free() ) {
378
-			$this->process_free_payment( $invoice );
377
+		if ($invoice->is_free()) {
378
+			$this->process_free_payment($invoice);
379 379
 		}
380 380
 
381 381
 		$submission = $this->payment_form_submission;
382 382
 
383 383
 		// Fires before sending to the gateway.
384
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
384
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
385 385
 
386 386
 		// Allow the sumission data to be modified before it is sent to the gateway.
387 387
 		$submission_data    = $submission->get_data();
388
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
389
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
388
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
389
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
390 390
 
391 391
 		// Validate the currency.
392
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
393
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
392
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
393
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
394 394
 		}
395 395
 
396 396
 		// Check to see if we have any errors.
397
-		if ( wpinv_get_errors() ) {
398
-			wpinv_send_back_to_checkout( $invoice );
397
+		if (wpinv_get_errors()) {
398
+			wpinv_send_back_to_checkout($invoice);
399 399
 		}
400 400
 
401 401
 		// Send info to the gateway for payment processing
402
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
402
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
403 403
 
404 404
 		// Backwards compatibility.
405
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
405
+		wpinv_send_to_gateway($submission_gateway, $invoice);
406 406
 
407 407
 	}
408 408
 
@@ -411,12 +411,12 @@  discard block
 block discarded – undo
411 411
 	 *
412 412
 	 * @param WPInv_Invoice $invoice
413 413
 	 */
414
-	protected function process_free_payment( $invoice ) {
414
+	protected function process_free_payment($invoice) {
415 415
 
416
-		$invoice->set_gateway( 'none' );
417
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
416
+		$invoice->set_gateway('none');
417
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
418 418
 		$invoice->mark_paid();
419
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
419
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
420 420
 
421 421
 	}
422 422
 
@@ -424,9 +424,9 @@  discard block
 block discarded – undo
424 424
      * Sends a redrect response to payment details.
425 425
      *
426 426
      */
427
-    public function send_redirect_response( $url ) {
428
-        $url = urlencode( $url );
429
-        wp_send_json_success( $url );
427
+    public function send_redirect_response($url) {
428
+        $url = urlencode($url);
429
+        wp_send_json_success($url);
430 430
     }
431 431
 
432 432
 }
Please login to merge, or discard this patch.
includes/data/admin-settings.php 1 patch
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -8,205 +8,205 @@  discard block
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13
-$pages = wpinv_get_pages( true );
13
+$pages = wpinv_get_pages(true);
14 14
     
15 15
 $currencies = wpinv_get_currencies();
16 16
     
17 17
 $currency_code_options = array();
18
-foreach ( $currencies as $code => $name ) {
19
-    $currency_code_options[ $code ] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol( $code ) . ')';
18
+foreach ($currencies as $code => $name) {
19
+    $currency_code_options[$code] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol($code) . ')';
20 20
 }
21 21
 
22 22
 $invoice_number_padd_options = array();
23
-for ( $i = 0; $i <= 20; $i++ ) {
23
+for ($i = 0; $i <= 20; $i++) {
24 24
     $invoice_number_padd_options[$i] = $i;
25 25
 }
26 26
     
27 27
 $currency_symbol = wpinv_currency_symbol();
28 28
     
29 29
 $last_number = $reset_number = '';
30
-if ( $last_invoice_number = get_option( 'wpinv_last_invoice_number' ) ) {
31
-    $last_invoice_number = preg_replace( '/[^0-9]/', '', $last_invoice_number );
30
+if ($last_invoice_number = get_option('wpinv_last_invoice_number')) {
31
+    $last_invoice_number = preg_replace('/[^0-9]/', '', $last_invoice_number);
32 32
 
33
-    if ( !empty( $last_invoice_number ) ) {
34
-        $last_number = ' ' . wp_sprintf( __( "( Last Invoice's sequential number: <b>%s</b> )", 'invoicing' ), $last_invoice_number );
33
+    if (!empty($last_invoice_number)) {
34
+        $last_number = ' ' . wp_sprintf(__("( Last Invoice's sequential number: <b>%s</b> )", 'invoicing'), $last_invoice_number);
35 35
     }
36 36
 
37 37
     $nonce = wp_create_nonce('reset_invoice_count');
38
-    $reset_number = '<a href="'.add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)).'" class="btn button">'.__('Force Reset Sequence', 'invoicing' ). '</a>';
38
+    $reset_number = '<a href="' . add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)) . '" class="btn button">' . __('Force Reset Sequence', 'invoicing') . '</a>';
39 39
 }
40 40
     
41 41
 $alert_wrapper_start = '<p style="color: #F00">';
42 42
 $alert_wrapper_close = '</p>';
43 43
 
44 44
 return array(
45
-    'general' => apply_filters( 'wpinv_settings_general',
45
+    'general' => apply_filters('wpinv_settings_general',
46 46
         array(
47 47
             'main' => array(
48 48
                 'location_settings' => array(
49 49
                     'id'   => 'location_settings',
50
-                    'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
50
+                    'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
51 51
                     'desc' => '',
52 52
                     'type' => 'header',
53 53
                 ),
54 54
                 'default_country' => array(
55 55
                     'id'      => 'default_country',
56
-                    'name'    => __( 'Default Country', 'invoicing' ),
57
-                    'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
56
+                    'name'    => __('Default Country', 'invoicing'),
57
+                    'desc'    => __('Where does your store operate from?', 'invoicing'),
58 58
                     'type'    => 'select',
59 59
                     'options' => wpinv_get_country_list(),
60 60
                     'std'     => 'GB',
61 61
                     'class'   => 'wpi_select2',
62
-                    'placeholder' => __( 'Select a country', 'invoicing' ),
62
+                    'placeholder' => __('Select a country', 'invoicing'),
63 63
                 ),
64 64
                 'default_state' => array(
65 65
                     'id'      => 'default_state',
66
-                    'name'    => __( 'Default State / Province', 'invoicing' ),
67
-                    'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
66
+                    'name'    => __('Default State / Province', 'invoicing'),
67
+                    'desc'    => __('What state / province does your store operate from?', 'invoicing'),
68 68
                     'type'    => 'country_states',
69 69
                     'class'   => 'wpi_select2',
70
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
70
+                    'placeholder' => __('Select a state', 'invoicing'),
71 71
                 ),
72 72
                 'store_name' => array(
73 73
                     'id'   => 'store_name',
74
-                    'name' => __( 'Store Name', 'invoicing' ),
75
-                    'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
74
+                    'name' => __('Store Name', 'invoicing'),
75
+                    'desc' => __('Store name to print on invoices.', 'invoicing'),
76 76
                     'std'     => get_option('blogname'),
77 77
                     'type' => 'text',
78 78
                 ),
79 79
                 'logo' => array(
80 80
                     'id'   => 'logo',
81
-                    'name' => __( 'Logo URL', 'invoicing' ),
82
-                    'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
81
+                    'name' => __('Logo URL', 'invoicing'),
82
+                    'desc' => __('Store logo to print on invoices.', 'invoicing'),
83 83
                     'type' => 'text',
84 84
                 ),
85 85
                 'logo_width'      => array(
86 86
                     'id'          => 'logo_width',
87
-                    'name'        => __( 'Logo width', 'invoicing' ),
88
-                    'desc'        => __( 'Logo width to use in invoice image.', 'invoicing' ),
87
+                    'name'        => __('Logo width', 'invoicing'),
88
+                    'desc'        => __('Logo width to use in invoice image.', 'invoicing'),
89 89
                     'type'        => 'number',
90
-                    'placeholder' => __( 'Auto', 'invoicing' ),
90
+                    'placeholder' => __('Auto', 'invoicing'),
91 91
                 ),
92 92
                 'logo_height'     => array(
93 93
                     'id'          => 'logo_height',
94
-                    'name'        => __( 'Logo height', 'invoicing' ),
95
-                    'desc'        => __( 'Logo height to use in invoice image.', 'invoicing' ),
94
+                    'name'        => __('Logo height', 'invoicing'),
95
+                    'desc'        => __('Logo height to use in invoice image.', 'invoicing'),
96 96
                     'type'        => 'number',
97
-                    'placeholder' => __( 'Auto', 'invoicing' ),
97
+                    'placeholder' => __('Auto', 'invoicing'),
98 98
                 ),
99 99
                 'store_address' => array(
100 100
                     'id'   => 'store_address',
101
-                    'name' => __( 'Store Address', 'invoicing' ),
102
-                    'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
101
+                    'name' => __('Store Address', 'invoicing'),
102
+                    'desc' => __('Enter the store address to display on invoice', 'invoicing'),
103 103
                     'type' => 'textarea',
104 104
                 ),
105 105
                 'page_settings' => array(
106 106
                     'id'   => 'page_settings',
107
-                    'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
107
+                    'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
108 108
                     'desc' => '',
109 109
                     'type' => 'header',
110 110
                 ),
111 111
                 'checkout_page' => array(
112 112
                     'id'          => 'checkout_page',
113
-                    'name'        => __( 'Checkout Page', 'invoicing' ),
114
-                    'desc'        => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ),
113
+                    'name'        => __('Checkout Page', 'invoicing'),
114
+                    'desc'        => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'),
115 115
                     'type'        => 'select',
116 116
                     'options'     => $pages,
117 117
                     'class'       => 'wpi_select2',
118
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
118
+                    'placeholder' => __('Select a page', 'invoicing'),
119 119
                     'help-tip'    => true,
120 120
                 ),
121 121
                 'success_page' => array(
122 122
                     'id'          => 'success_page',
123
-                    'name'        => __( 'Success Page', 'invoicing' ),
124
-                    'desc'        => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ),
123
+                    'name'        => __('Success Page', 'invoicing'),
124
+                    'desc'        => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'),
125 125
                     'type'        => 'select',
126 126
                     'options'     => $pages,
127 127
                     'class'       => 'wpi_select2',
128
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
128
+                    'placeholder' => __('Select a page', 'invoicing'),
129 129
                     'help-tip'    => true,
130 130
                 ),
131 131
                 'failure_page' => array(
132 132
                     'id'          => 'failure_page',
133
-                    'name'        => __( 'Failed Transaction Page', 'invoicing' ),
134
-                    'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing' ),
133
+                    'name'        => __('Failed Transaction Page', 'invoicing'),
134
+                    'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing'),
135 135
                     'type'        => 'select',
136 136
                     'options'     => $pages,
137 137
                     'class'       => 'wpi_select2',
138
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
138
+                    'placeholder' => __('Select a page', 'invoicing'),
139 139
                     'help-tip'    => true,
140 140
                 ),
141 141
                 'invoice_history_page' => array(
142 142
                     'id'          => 'invoice_history_page',
143
-                    'name'        => __( 'Invoice History Page', 'invoicing' ),
144
-                    'desc'        => __( 'This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing' ),
143
+                    'name'        => __('Invoice History Page', 'invoicing'),
144
+                    'desc'        => __('This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing'),
145 145
                     'type'        => 'select',
146 146
                     'options'     => $pages,
147 147
                     'class'       => 'wpi_select2',
148
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
148
+                    'placeholder' => __('Select a page', 'invoicing'),
149 149
                     'help-tip'    => true,
150 150
                 ),
151 151
                 'invoice_subscription_page' => array(
152 152
                     'id'          => 'invoice_subscription_page',
153
-                    'name'        => __( 'Invoice Subscriptions Page', 'invoicing' ),
154
-                    'desc'        => __( 'This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing' ),
153
+                    'name'        => __('Invoice Subscriptions Page', 'invoicing'),
154
+                    'desc'        => __('This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing'),
155 155
                     'type'        => 'select',
156 156
                     'options'     => $pages,
157 157
                     'class'       => 'wpi_select2',
158
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
158
+                    'placeholder' => __('Select a page', 'invoicing'),
159 159
                     'help-tip'    => true,
160 160
                 ),
161 161
             ),
162 162
             'currency_section' => array(
163 163
                 'currency_settings' => array(
164 164
                     'id'   => 'currency_settings',
165
-                    'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
165
+                    'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
166 166
                     'desc' => '',
167 167
                     'type' => 'header',
168 168
                 ),
169 169
                 'currency' => array(
170 170
                     'id'      => 'currency',
171
-                    'name'    => __( 'Currency', 'invoicing' ),
172
-                    'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
171
+                    'name'    => __('Currency', 'invoicing'),
172
+                    'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
173 173
                     'type'    => 'select',
174 174
                     'class'       => 'wpi_select2',
175 175
                     'options' => $currency_code_options,
176 176
                 ),
177 177
                 'currency_position' => array(
178 178
                     'id'      => 'currency_position',
179
-                    'name'    => __( 'Currency Position', 'invoicing' ),
180
-                    'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
179
+                    'name'    => __('Currency Position', 'invoicing'),
180
+                    'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
181 181
                     'type'    => 'select',
182 182
                     'class'   => 'wpi_select2',
183 183
                     'options'  => array(
184
-                        'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
185
-                        'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
186
-                        'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
187
-                        'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
184
+                        'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
185
+                        'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
186
+                        'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
187
+                        'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
188 188
                     )
189 189
                 ),
190 190
                 'thousands_separator' => array(
191 191
                     'id'   => 'thousands_separator',
192
-                    'name' => __( 'Thousands Separator', 'invoicing' ),
193
-                    'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
192
+                    'name' => __('Thousands Separator', 'invoicing'),
193
+                    'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
194 194
                     'type' => 'text',
195 195
                     'size' => 'small',
196 196
                     'std'  => ',',
197 197
                 ),
198 198
                 'decimal_separator' => array(
199 199
                     'id'   => 'decimal_separator',
200
-                    'name' => __( 'Decimal Separator', 'invoicing' ),
201
-                    'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
200
+                    'name' => __('Decimal Separator', 'invoicing'),
201
+                    'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
202 202
                     'type' => 'text',
203 203
                     'size' => 'small',
204 204
                     'std'  => '.',
205 205
                 ),
206 206
                 'decimals' => array(
207 207
                     'id'   => 'decimals',
208
-                    'name' => __( 'Number of Decimals', 'invoicing' ),
209
-                    'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
208
+                    'name' => __('Number of Decimals', 'invoicing'),
209
+                    'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => '2',
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
             'labels' => array(
219 219
                 'labels' => array(
220 220
                     'id'   => 'labels_settings',
221
-                    'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
221
+                    'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
222 222
                     'desc' => '',
223 223
                     'type' => 'header',
224 224
                 ),
225 225
                 'vat_invoice_notice_label' => array(
226 226
                     'id' => 'vat_invoice_notice_label',
227
-                    'name' => __( 'Invoice Notice Label', 'invoicing' ),
228
-                    'desc' => __( 'Use this to add an invoice notice section (label) to your invoices', 'invoicing' ),
227
+                    'name' => __('Invoice Notice Label', 'invoicing'),
228
+                    'desc' => __('Use this to add an invoice notice section (label) to your invoices', 'invoicing'),
229 229
                     'type' => 'text',
230 230
                     'size' => 'regular',
231 231
                 ),
232 232
                 'vat_invoice_notice' => array(
233 233
                     'id' => 'vat_invoice_notice',
234
-                    'name' => __( 'Invoice notice', 'invoicing' ),
235
-                    'desc' =>   __( 'Use this to add an invoice notice section (description) to your invoices', 'invoicing' ),
234
+                    'name' => __('Invoice notice', 'invoicing'),
235
+                    'desc' =>   __('Use this to add an invoice notice section (description) to your invoices', 'invoicing'),
236 236
                     'type' => 'text',
237 237
                     'size' => 'regular',
238 238
                 ),
@@ -244,22 +244,22 @@  discard block
 block discarded – undo
244 244
             'main' => array(
245 245
                 'gateway_settings' => array(
246 246
                     'id'   => 'api_header',
247
-                    'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
247
+                    'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
248 248
                     'desc' => '',
249 249
                     'type' => 'header',
250 250
                 ),
251 251
                 'gateways' => array(
252 252
                     'id'      => 'gateways',
253
-                    'name'    => __( 'Payment Gateways', 'invoicing' ),
254
-                    'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
253
+                    'name'    => __('Payment Gateways', 'invoicing'),
254
+                    'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
255 255
                     'type'    => 'gateways',
256
-                    'std'     => array( 'manual'=>1 ),
256
+                    'std'     => array('manual'=>1),
257 257
                     'options' => wpinv_get_payment_gateways(),
258 258
                 ),
259 259
                 'default_gateway' => array(
260 260
                     'id'      => 'default_gateway',
261
-                    'name'    => __( 'Default Gateway', 'invoicing' ),
262
-                    'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
261
+                    'name'    => __('Default Gateway', 'invoicing'),
262
+                    'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
263 263
                     'type'    => 'gateway_select',
264 264
                     'std'     => 'manual',
265 265
                     'class'   => 'wpi_select2',
@@ -274,32 +274,32 @@  discard block
 block discarded – undo
274 274
             'main' => array(
275 275
                 'tax_settings' => array(
276 276
                     'id'   => 'tax_settings',
277
-                    'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
277
+                    'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
278 278
                     'type' => 'header',
279 279
                 ),
280 280
 
281 281
                 'enable_taxes' => array(
282 282
                     'id'       => 'enable_taxes',
283
-                    'name'     => __( 'Enable Taxes', 'invoicing' ),
284
-                    'desc'     => __( 'Enable tax rates and calculations.', 'invoicing' ),
283
+                    'name'     => __('Enable Taxes', 'invoicing'),
284
+                    'desc'     => __('Enable tax rates and calculations.', 'invoicing'),
285 285
                     'type'     => 'checkbox',
286 286
                     'std'      => 0,
287 287
                 ),
288 288
 
289 289
                 'tax_subtotal_rounding' => array(
290 290
                     'id'                => 'tax_subtotal_rounding',
291
-                    'name'              => __( 'Rounding', 'invoicing' ),
292
-                    'desc'              => __( 'Round tax at subtotal level, instead of rounding per tax rate', 'invoicing' ),
291
+                    'name'              => __('Rounding', 'invoicing'),
292
+                    'desc'              => __('Round tax at subtotal level, instead of rounding per tax rate', 'invoicing'),
293 293
                     'type'              => 'checkbox',
294 294
                     'std'               => 1,
295 295
                 ),
296 296
 
297 297
                 'prices_include_tax' => array(
298 298
                     'id'      => 'prices_include_tax',
299
-                    'name'    => __( 'Prices entered with tax', 'invoicing' ),
299
+                    'name'    => __('Prices entered with tax', 'invoicing'),
300 300
                     'options' => array(
301
-                        'yes' => __( 'Yes, I will enter prices inclusive of tax', 'invoicing' ),
302
-                        'no'  => __( 'No, I will enter prices exclusive of tax', 'invoicing' ),
301
+                        'yes' => __('Yes, I will enter prices inclusive of tax', 'invoicing'),
302
+                        'no'  => __('No, I will enter prices exclusive of tax', 'invoicing'),
303 303
                     ),
304 304
                     'type'    => 'select',
305 305
                     'std'     => 'no',
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
 
308 308
                 'tax_base'              => array(
309 309
                     'id'                => 'tax_base',
310
-                    'name'              => __( 'Calculate tax based on', 'invoicing' ),
310
+                    'name'              => __('Calculate tax based on', 'invoicing'),
311 311
                     'options'           => array(
312
-                        'billing'       => __( 'Customer billing address', 'invoicing' ),
313
-                        'base'          => __( 'Shop base address', 'invoicing' ),
312
+                        'billing'       => __('Customer billing address', 'invoicing'),
313
+                        'base'          => __('Shop base address', 'invoicing'),
314 314
                     ),
315 315
                     'type'              => 'select',
316 316
                     'std'               => 'billing',
@@ -318,10 +318,10 @@  discard block
 block discarded – undo
318 318
 
319 319
                 'tax_display_totals'    => array(
320 320
                     'id'                => 'tax_display_totals',
321
-                    'name'              => __( 'Display tax totals', 'invoicing' ),
321
+                    'name'              => __('Display tax totals', 'invoicing'),
322 322
                     'options'           => array(
323
-                        'single'        => __( 'As a single total', 'invoicing' ),
324
-                        'individual'    => __( 'As individual tax rates', 'invoicing' ),
323
+                        'single'        => __('As a single total', 'invoicing'),
324
+                        'individual'    => __('As individual tax rates', 'invoicing'),
325 325
                     ),
326 326
                     'type'              => 'select',
327 327
                     'std'               => 'individual',
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 
330 330
                 'tax_rate' => array(
331 331
                     'id'   => 'tax_rate',
332
-                    'name' => __( 'Fallback Tax Rate', 'invoicing' ),
333
-                    'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
332
+                    'name' => __('Fallback Tax Rate', 'invoicing'),
333
+                    'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
334 334
                     'type' => 'number',
335 335
                     'size' => 'small',
336 336
                     'min'  => '0',
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
             'rates' => array(
343 343
                 'tax_rates' => array(
344 344
                     'id'   => 'tax_rates',
345
-                    'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
346
-                    'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
345
+                    'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
346
+                    'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
347 347
                     'type' => 'tax_rates',
348 348
                 ),
349 349
             ),
@@ -352,45 +352,45 @@  discard block
 block discarded – undo
352 352
 
353 353
                 'vat_company_name' => array(
354 354
                     'id' => 'vat_company_name',
355
-                    'name' => __( 'Company Name', 'invoicing' ),
356
-                    'desc' => wp_sprintf(__( 'Verify your company name and  VAT number on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
355
+                    'name' => __('Company Name', 'invoicing'),
356
+                    'desc' => wp_sprintf(__('Verify your company name and  VAT number on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
357 357
                     'type' => 'text',
358 358
                     'size' => 'regular',
359 359
                 ),
360 360
 
361 361
                 'vat_number' => array(
362 362
                     'id'   => 'vat_number',
363
-                    'name' => __( 'VAT Number', 'invoicing' ),
364
-                    'desc' => __( 'Enter your VAT number including the country identifier, eg: GB123456789', 'invoicing' ),
363
+                    'name' => __('VAT Number', 'invoicing'),
364
+                    'desc' => __('Enter your VAT number including the country identifier, eg: GB123456789', 'invoicing'),
365 365
                     'type' => 'text',
366 366
                     'size' => 'regular',
367 367
                 ),
368 368
 
369 369
                 'vat_prevent_b2c_purchase' => array(
370 370
                     'id' => 'vat_prevent_b2c_purchase',
371
-                    'name' => __( 'Prevent B2C Sales', 'invoicing' ),
372
-                    'desc' => __( 'Require everyone in the EU to provide a VAT number.', 'invoicing' ),
371
+                    'name' => __('Prevent B2C Sales', 'invoicing'),
372
+                    'desc' => __('Require everyone in the EU to provide a VAT number.', 'invoicing'),
373 373
                     'type' => 'checkbox'
374 374
                 ),
375 375
 
376 376
                 'validate_vat_number' => array(
377 377
                     'id'   => 'validate_vat_number',
378
-                    'name' => __( 'Validate VAT Number', 'invoicing' ),
379
-                    'desc' => __( 'Validate VAT numbers with VIES.', 'invoicing' ),
378
+                    'name' => __('Validate VAT Number', 'invoicing'),
379
+                    'desc' => __('Validate VAT numbers with VIES.', 'invoicing'),
380 380
                     'type' => 'checkbox'
381 381
                 ),
382 382
 
383 383
                 'vat_same_country_rule' => array(
384 384
                     'id'          => 'vat_same_country_rule',
385
-                    'name'        => __( 'Same Country Rule', 'invoicing' ),
386
-                    'desc'        => __( 'What should happen if a customer is from the same country as your business?', 'invoicing' ),
385
+                    'name'        => __('Same Country Rule', 'invoicing'),
386
+                    'desc'        => __('What should happen if a customer is from the same country as your business?', 'invoicing'),
387 387
                     'type'        => 'select',
388 388
                     'options'     => array(
389
-                        'no'        => __( 'Do not charge tax', 'invoicing' ),
390
-                        'always'    => __( 'Charge tax unless vat number is validated', 'invoicing' ),
391
-                        'vat_too'   => __( 'Charge tax even if vat number is validated', 'invoicing' )
389
+                        'no'        => __('Do not charge tax', 'invoicing'),
390
+                        'always'    => __('Charge tax unless vat number is validated', 'invoicing'),
391
+                        'vat_too'   => __('Charge tax even if vat number is validated', 'invoicing')
392 392
                     ),
393
-                    'placeholder' => __( 'Select an option', 'invoicing' ),
393
+                    'placeholder' => __('Select an option', 'invoicing'),
394 394
                     'std'         => 'vat_too',
395 395
                 ),
396 396
 
@@ -404,59 +404,59 @@  discard block
 block discarded – undo
404 404
             'main' => array(
405 405
                 'email_settings_header' => array(
406 406
                     'id'   => 'email_settings_header',
407
-                    'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
407
+                    'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
408 408
                     'type' => 'header',
409 409
                 ),
410 410
                 'email_from_name' => array(
411 411
                     'id'   => 'email_from_name',
412
-                    'name' => __( 'From Name', 'invoicing' ),
413
-                    'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
414
-                    'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
412
+                    'name' => __('From Name', 'invoicing'),
413
+                    'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
414
+                    'std' => esc_attr(get_bloginfo('name', 'display')),
415 415
                     'type' => 'text',
416 416
                 ),
417 417
                 'email_from' => array(
418 418
                     'id'   => 'email_from',
419
-                    'name' => __( 'From Email', 'invoicing' ),
420
-                    'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close),
421
-                    'std' => get_option( 'admin_email' ),
419
+                    'name' => __('From Email', 'invoicing'),
420
+                    'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close),
421
+                    'std' => get_option('admin_email'),
422 422
                     'type' => 'text',
423 423
                 ),
424 424
                 'admin_email' => array(
425 425
                     'id'   => 'admin_email',
426
-                    'name' => __( 'Admin Email', 'invoicing' ),
427
-                    'desc' => __( 'Where should we send admin notifications? This will is also act as the "reply-to" address for invoice emails', 'invoicing' ),
428
-                    'std' => get_option( 'admin_email' ),
426
+                    'name' => __('Admin Email', 'invoicing'),
427
+                    'desc' => __('Where should we send admin notifications? This will is also act as the "reply-to" address for invoice emails', 'invoicing'),
428
+                    'std' => get_option('admin_email'),
429 429
                     'type' => 'text',
430 430
                 ),
431 431
                 'overdue_settings_header' => array(
432 432
                     'id'   => 'overdue_settings_header',
433
-                    'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
433
+                    'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
434 434
                     'type' => 'header',
435 435
                 ),
436 436
                 'overdue_active' => array(
437 437
                     'id'   => 'overdue_active',
438
-                    'name' => __( 'Enable Due Date', 'invoicing' ),
439
-                    'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
438
+                    'name' => __('Enable Due Date', 'invoicing'),
439
+                    'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
440 440
                     'type' => 'checkbox',
441 441
                     'std'  => false,
442 442
                 ),
443 443
                 'email_template_header' => array(
444 444
                     'id'   => 'email_template_header',
445
-                    'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
445
+                    'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
446 446
                     'type' => 'header',
447 447
                 ),
448 448
                 'email_header_image' => array(
449 449
                     'id'   => 'email_header_image',
450
-                    'name' => __( 'Header Image', 'invoicing' ),
451
-                    'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
450
+                    'name' => __('Header Image', 'invoicing'),
451
+                    'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
452 452
                     'std' => '',
453 453
                     'type' => 'text',
454 454
                 ),
455 455
                 'email_footer_text' => array(
456 456
                     'id'   => 'email_footer_text',
457
-                    'name' => __( 'Footer Text', 'invoicing' ),
458
-                    'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
459
-                    'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GetPaid', 'invoicing' ),
457
+                    'name' => __('Footer Text', 'invoicing'),
458
+                    'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
459
+                    'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GetPaid', 'invoicing'),
460 460
                     'type' => 'textarea',
461 461
                     'class' => 'regular-text',
462 462
                     'rows' => 2,
@@ -464,29 +464,29 @@  discard block
 block discarded – undo
464 464
                 ),
465 465
                 'email_base_color' => array(
466 466
                     'id'   => 'email_base_color',
467
-                    'name' => __( 'Base Color', 'invoicing' ),
468
-                    'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
467
+                    'name' => __('Base Color', 'invoicing'),
468
+                    'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
469 469
                     'std' => '#557da2',
470 470
                     'type' => 'color',
471 471
                 ),
472 472
                 'email_background_color' => array(
473 473
                     'id'   => 'email_background_color',
474
-                    'name' => __( 'Background Color', 'invoicing' ),
475
-                    'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
474
+                    'name' => __('Background Color', 'invoicing'),
475
+                    'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
476 476
                     'std' => '#f5f5f5',
477 477
                     'type' => 'color',
478 478
                 ),
479 479
                 'email_body_background_color' => array(
480 480
                     'id'   => 'email_body_background_color',
481
-                    'name' => __( 'Body Background Color', 'invoicing' ),
482
-                    'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
481
+                    'name' => __('Body Background Color', 'invoicing'),
482
+                    'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
483 483
                     'std' => '#fdfdfd',
484 484
                     'type' => 'color',
485 485
                 ),
486 486
                 'email_text_color' => array(
487 487
                     'id'   => 'email_text_color',
488
-                    'name' => __( 'Body Text Color', 'invoicing' ),
489
-                    'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
488
+                    'name' => __('Body Text Color', 'invoicing'),
489
+                    'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
490 490
                     'std' => '#505050',
491 491
                     'type' => 'color',
492 492
                 ),
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
     ),
502 502
 
503 503
     // Integrations.
504
-    'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'settings', 'id' ),
504
+    'integrations' => wp_list_pluck(getpaid_get_integration_settings(), 'settings', 'id'),
505 505
 
506 506
     /** Privacy Settings */
507 507
     'privacy' => apply_filters('wpinv_settings_privacy',
@@ -509,17 +509,17 @@  discard block
 block discarded – undo
509 509
             'main' => array(
510 510
                 'invoicing_privacy_policy_settings' => array(
511 511
                     'id'   => 'invoicing_privacy_policy_settings',
512
-                    'name' => '<h3>' . __( 'Privacy Policy', 'invoicing' ) . '</h3>',
512
+                    'name' => '<h3>' . __('Privacy Policy', 'invoicing') . '</h3>',
513 513
                     'type' => 'header',
514 514
                 ),
515 515
                 'privacy_page' => array(
516 516
                     'id'          => 'privacy_page',
517
-                    'name'        => __( 'Privacy Page', 'invoicing' ),
518
-                    'desc'        => __( 'If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing' ),
517
+                    'name'        => __('Privacy Page', 'invoicing'),
518
+                    'desc'        => __('If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing'),
519 519
                     'type'        => 'select',
520
-                    'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
520
+                    'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
521 521
                     'class'       => 'wpi_select2',
522
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
522
+                    'placeholder' => __('Select a page', 'invoicing'),
523 523
                 ),
524 524
             ),
525 525
         )
@@ -530,19 +530,19 @@  discard block
 block discarded – undo
530 530
             'main' => array(
531 531
                 'invoice_number_format_settings' => array(
532 532
                     'id'   => 'invoice_number_format_settings',
533
-                    'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
533
+                    'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
534 534
                     'type' => 'header',
535 535
                 ),
536 536
                 'sequential_invoice_number' => array(
537 537
                     'id'   => 'sequential_invoice_number',
538
-                    'name' => __( 'Sequential Invoice Numbers', 'invoicing' ),
539
-                    'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing' ) . $reset_number,
538
+                    'name' => __('Sequential Invoice Numbers', 'invoicing'),
539
+                    'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing') . $reset_number,
540 540
                     'type' => 'checkbox',
541 541
                 ),
542 542
                 'invoice_sequence_start' => array(
543 543
                     'id'   => 'invoice_sequence_start',
544
-                    'name' => __( 'Sequential Starting Number', 'invoicing' ),
545
-                    'desc' => __( 'The number at which the invoice number sequence should begin.', 'invoicing' ) . $last_number,
544
+                    'name' => __('Sequential Starting Number', 'invoicing'),
545
+                    'desc' => __('The number at which the invoice number sequence should begin.', 'invoicing') . $last_number,
546 546
                     'type' => 'number',
547 547
                     'size' => 'small',
548 548
                     'std'  => '1',
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
                 ),
551 551
                 'invoice_number_padd' => array(
552 552
                     'id'      => 'invoice_number_padd',
553
-                    'name'    => __( 'Minimum Digits', 'invoicing' ),
554
-                    'desc'    => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ),
553
+                    'name'    => __('Minimum Digits', 'invoicing'),
554
+                    'desc'    => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'),
555 555
                     'type'    => 'select',
556 556
                     'options' => $invoice_number_padd_options,
557 557
                     'std'     => 5,
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
                 ),
560 560
                 'invoice_number_prefix' => array(
561 561
                     'id' => 'invoice_number_prefix',
562
-                    'name' => __( 'Invoice Number Prefix', 'invoicing' ),
563
-                    'desc' => __( 'Prefix for all invoice numbers. Ex: INV-', 'invoicing' ),
562
+                    'name' => __('Invoice Number Prefix', 'invoicing'),
563
+                    'desc' => __('Prefix for all invoice numbers. Ex: INV-', 'invoicing'),
564 564
                     'type' => 'text',
565 565
                     'size' => 'regular',
566 566
                     'std' => 'INV-',
@@ -568,46 +568,46 @@  discard block
 block discarded – undo
568 568
                 ),
569 569
                 'invoice_number_postfix' => array(
570 570
                     'id' => 'invoice_number_postfix',
571
-                    'name' => __( 'Invoice Number Postfix', 'invoicing' ),
572
-                    'desc' => __( 'Postfix for all invoice numbers.', 'invoicing' ),
571
+                    'name' => __('Invoice Number Postfix', 'invoicing'),
572
+                    'desc' => __('Postfix for all invoice numbers.', 'invoicing'),
573 573
                     'type' => 'text',
574 574
                     'size' => 'regular',
575 575
                     'std' => ''
576 576
                 ),
577 577
                 'checkout_settings' => array(
578 578
                     'id'   => 'checkout_settings',
579
-                    'name' => '<h3>' . __( 'Checkout Settings', 'invoicing' ) . '</h3>',
579
+                    'name' => '<h3>' . __('Checkout Settings', 'invoicing') . '</h3>',
580 580
                     'type' => 'header',
581 581
                 ),
582 582
                 'disable_new_user_emails' => array(
583 583
                     'id'   => 'disable_new_user_emails',
584
-                    'name' => __( 'Disable new user emails', 'invoicing' ),
585
-                    'desc' => __( 'Do not send an email to customers when a new user account is created for them.', 'invoicing' ),
584
+                    'name' => __('Disable new user emails', 'invoicing'),
585
+                    'desc' => __('Do not send an email to customers when a new user account is created for them.', 'invoicing'),
586 586
                     'type' => 'checkbox',
587 587
                 ),
588 588
                 'login_to_checkout' => array(
589 589
                     'id'   => 'login_to_checkout',
590
-                    'name' => __( 'Require Login To Checkout', 'invoicing' ),
591
-                    'desc' => __( 'If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing' ),
590
+                    'name' => __('Require Login To Checkout', 'invoicing'),
591
+                    'desc' => __('If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing'),
592 592
                     'type' => 'checkbox',
593 593
                 ),
594 594
                 'maxmind_license_key' => array(
595 595
                     'id'   => 'maxmind_license_key',
596
-                    'name' => __( 'MaxMind License Key', 'invoicing' ),
596
+                    'name' => __('MaxMind License Key', 'invoicing'),
597 597
                     'type' => 'text',
598 598
                     'size' => 'regular',
599
-                    'desc' => __( "Enter you license key if you would like to use MaxMind to automatically detect a customer's country.", 'invoicing' ) . ' <a href="https://support.maxmind.com/account-faq/license-keys/how-do-i-generate-a-license-key/">' . __( 'How to generate a free license key.', 'invoicing' ) . '</a>',
599
+                    'desc' => __("Enter you license key if you would like to use MaxMind to automatically detect a customer's country.", 'invoicing') . ' <a href="https://support.maxmind.com/account-faq/license-keys/how-do-i-generate-a-license-key/">' . __('How to generate a free license key.', 'invoicing') . '</a>',
600 600
                 ),
601 601
 
602 602
                 'uninstall_settings' => array(
603 603
                     'id'   => 'uninstall_settings',
604
-                    'name' => '<h3>' . __( 'Uninstall Settings', 'invoicing' ) . '</h3>',
604
+                    'name' => '<h3>' . __('Uninstall Settings', 'invoicing') . '</h3>',
605 605
                     'type' => 'header',
606 606
                 ),
607 607
                 'remove_data_on_unistall' => array(
608 608
                     'id'   => 'remove_data_on_unistall',
609
-                    'name' => __( 'Remove Data on Uninstall?', 'invoicing' ),
610
-                    'desc' => __( 'Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing' ),
609
+                    'name' => __('Remove Data on Uninstall?', 'invoicing'),
610
+                    'desc' => __('Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing'),
611 611
                     'type' => 'checkbox',
612 612
                     'std'  => ''
613 613
                 ),
@@ -616,13 +616,13 @@  discard block
 block discarded – undo
616 616
             'custom-css' => array(
617 617
                 'css_settings' => array(
618 618
                     'id'   => 'css_settings',
619
-                    'name' => '<h3>' . __( 'Custom CSS', 'invoicing' ) . '</h3>',
619
+                    'name' => '<h3>' . __('Custom CSS', 'invoicing') . '</h3>',
620 620
                     'type' => 'header',
621 621
                 ),
622 622
                 'template_custom_css' => array(
623 623
                     'id' => 'template_custom_css',
624
-                    'name' => __( 'Invoice Template CSS', 'invoicing' ),
625
-                    'desc' => __( 'Add CSS to modify appearance of the print invoice page.', 'invoicing' ),
624
+                    'name' => __('Invoice Template CSS', 'invoicing'),
625
+                    'desc' => __('Add CSS to modify appearance of the print invoice page.', 'invoicing'),
626 626
                     'type' => 'textarea',
627 627
                     'class'=> 'regular-text',
628 628
                     'rows' => 10,
@@ -636,8 +636,8 @@  discard block
 block discarded – undo
636 636
             'main' => array(
637 637
                 'tool_settings' => array(
638 638
                     'id'   => 'tool_settings',
639
-                    'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
640
-                    'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
639
+                    'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
640
+                    'desc' => __('Invoicing diagnostic tools', 'invoicing'),
641 641
                     'type' => 'tools',
642 642
                 ),
643 643
             ),
Please login to merge, or discard this patch.