@@ -8,20 +8,20 @@ |
||
| 8 | 8 | * @var GetPaid_Payment_Form $form The current payment form |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | -$placeholder = esc_attr( $input_label ); |
|
| 14 | -$label = sanitize_text_field( $button_label ); |
|
| 13 | +$placeholder = esc_attr($input_label); |
|
| 14 | +$label = sanitize_text_field($button_label); |
|
| 15 | 15 | |
| 16 | -if ( ! empty( $description ) ) { |
|
| 16 | +if (!empty($description)) { |
|
| 17 | 17 | $description = "<small class='form-text text-muted'>$description</small>"; |
| 18 | 18 | } else { |
| 19 | 19 | $description = ''; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | $discount_code = ''; |
| 23 | -if ( ! empty( $form->invoice ) ) { |
|
| 24 | - $discount_code = esc_attr( $form->invoice->get_discount_code() ); |
|
| 23 | +if (!empty($form->invoice)) { |
|
| 24 | + $discount_code = esc_attr($form->invoice->get_discount_code()); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | ?> |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -20,29 +20,29 @@ discard block |
||
| 20 | 20 | public $templates_url; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Class constructor. |
|
| 24 | - * |
|
| 25 | - * @since 1.0.19 |
|
| 26 | - */ |
|
| 27 | - public function __construct() { |
|
| 23 | + * Class constructor. |
|
| 24 | + * |
|
| 25 | + * @since 1.0.19 |
|
| 26 | + */ |
|
| 27 | + public function __construct() { |
|
| 28 | 28 | |
| 29 | 29 | $this->templates_dir = apply_filters( 'getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates' ); |
| 30 | 30 | $this->templates_url = apply_filters( 'getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates' ); |
| 31 | 31 | |
| 32 | 32 | // Oxygen plugin |
| 33 | - if ( defined( 'CT_VERSION' ) ) { |
|
| 34 | - add_filter( 'wpinv_locate_template', array( $this, 'oxygen_override_template' ), 11, 4 ); |
|
| 35 | - } |
|
| 33 | + if ( defined( 'CT_VERSION' ) ) { |
|
| 34 | + add_filter( 'wpinv_locate_template', array( $this, 'oxygen_override_template' ), 11, 4 ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | - * Checks if this is a preview page |
|
| 41 | - * |
|
| 42 | - * @since 1.0.19 |
|
| 43 | - * @return bool |
|
| 44 | - */ |
|
| 45 | - public function is_preview() { |
|
| 40 | + * Checks if this is a preview page |
|
| 41 | + * |
|
| 42 | + * @since 1.0.19 |
|
| 43 | + * @return bool |
|
| 44 | + */ |
|
| 45 | + public function is_preview() { |
|
| 46 | 46 | return |
| 47 | 47 | $this->is_divi_preview() || |
| 48 | 48 | $this->is_elementor_preview() || |
@@ -54,73 +54,73 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * Checks if this is an elementor preview page |
|
| 58 | - * |
|
| 59 | - * @since 1.0.19 |
|
| 60 | - * @return bool |
|
| 61 | - */ |
|
| 62 | - public function is_elementor_preview() { |
|
| 63 | - return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Checks if this is a DIVI preview page |
|
| 68 | - * |
|
| 69 | - * @since 1.0.19 |
|
| 70 | - * @return bool |
|
| 71 | - */ |
|
| 72 | - public function is_divi_preview() { |
|
| 73 | - return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' ); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Checks if this is a beaver builder preview page |
|
| 78 | - * |
|
| 79 | - * @since 1.0.19 |
|
| 80 | - * @return bool |
|
| 81 | - */ |
|
| 82 | - public function is_beaver_preview() { |
|
| 83 | - return isset( $_REQUEST['fl_builder'] ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Checks if this is a siteorigin builder preview page |
|
| 88 | - * |
|
| 89 | - * @since 1.0.19 |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function is_siteorigin_preview() { |
|
| 93 | - return ! empty( $_REQUEST['siteorigin_panels_live_editor'] ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Checks if this is a cornerstone builder preview page |
|
| 98 | - * |
|
| 99 | - * @since 1.0.19 |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - public function is_cornerstone_preview() { |
|
| 103 | - return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Checks if this is a fusion builder preview page |
|
| 108 | - * |
|
| 109 | - * @since 1.0.19 |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function is_fusion_preview() { |
|
| 113 | - return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Checks if this is an oxygen builder preview page |
|
| 118 | - * |
|
| 119 | - * @since 1.0.19 |
|
| 120 | - * @return bool |
|
| 121 | - */ |
|
| 122 | - public function is_oxygen_preview() { |
|
| 123 | - return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ); |
|
| 57 | + * Checks if this is an elementor preview page |
|
| 58 | + * |
|
| 59 | + * @since 1.0.19 |
|
| 60 | + * @return bool |
|
| 61 | + */ |
|
| 62 | + public function is_elementor_preview() { |
|
| 63 | + return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Checks if this is a DIVI preview page |
|
| 68 | + * |
|
| 69 | + * @since 1.0.19 |
|
| 70 | + * @return bool |
|
| 71 | + */ |
|
| 72 | + public function is_divi_preview() { |
|
| 73 | + return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' ); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Checks if this is a beaver builder preview page |
|
| 78 | + * |
|
| 79 | + * @since 1.0.19 |
|
| 80 | + * @return bool |
|
| 81 | + */ |
|
| 82 | + public function is_beaver_preview() { |
|
| 83 | + return isset( $_REQUEST['fl_builder'] ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Checks if this is a siteorigin builder preview page |
|
| 88 | + * |
|
| 89 | + * @since 1.0.19 |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function is_siteorigin_preview() { |
|
| 93 | + return ! empty( $_REQUEST['siteorigin_panels_live_editor'] ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Checks if this is a cornerstone builder preview page |
|
| 98 | + * |
|
| 99 | + * @since 1.0.19 |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + public function is_cornerstone_preview() { |
|
| 103 | + return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Checks if this is a fusion builder preview page |
|
| 108 | + * |
|
| 109 | + * @since 1.0.19 |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function is_fusion_preview() { |
|
| 113 | + return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Checks if this is an oxygen builder preview page |
|
| 118 | + * |
|
| 119 | + * @since 1.0.19 |
|
| 120 | + * @return bool |
|
| 121 | + */ |
|
| 122 | + public function is_oxygen_preview() { |
|
| 123 | + return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
| 131 | 131 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 132 | 132 | */ |
| 133 | - public function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 133 | + public function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 134 | 134 | |
| 135 | 135 | // Load the defaults for the template path and default path. |
| 136 | 136 | $template_path = empty( $template_path ) ? 'invoicing' : $template_path; |
@@ -151,22 +151,22 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | - * Loads a template |
|
| 155 | - * |
|
| 156 | - * @since 1.0.19 |
|
| 157 | - * @return bool |
|
| 158 | - */ |
|
| 159 | - protected function load_template( $template_name, $template_path, $args ) { |
|
| 154 | + * Loads a template |
|
| 155 | + * |
|
| 156 | + * @since 1.0.19 |
|
| 157 | + * @return bool |
|
| 158 | + */ |
|
| 159 | + protected function load_template( $template_name, $template_path, $args ) { |
|
| 160 | 160 | |
| 161 | 161 | if ( is_array( $args ) ){ |
| 162 | 162 | extract( $args ); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Fires before loading a template. |
| 166 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $args ); |
|
| 166 | + do_action( 'wpinv_before_template_part', $template_name, $template_path, $args ); |
|
| 167 | 167 | |
| 168 | 168 | // Load the template. |
| 169 | - include( $template_path ); |
|
| 169 | + include( $template_path ); |
|
| 170 | 170 | |
| 171 | 171 | // Fires after loading a template. |
| 172 | 172 | do_action( 'wpinv_after_template_part', $template_name, $template_path, $args ); |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
| 184 | 184 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 185 | 185 | */ |
| 186 | - public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 186 | + public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 187 | 187 | |
| 188 | 188 | // Locate the template. |
| 189 | 189 | $located = $this->locate_template( $template_name, $template_path, $default_path ); |
@@ -208,74 +208,74 @@ discard block |
||
| 208 | 208 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
| 209 | 209 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 210 | 210 | */ |
| 211 | - public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 211 | + public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 212 | 212 | ob_start(); |
| 213 | 213 | $this->display_template( $template_name, $args, $template_path, $default_path ); |
| 214 | 214 | return ob_get_clean(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
| 218 | - * Get the geodirectory templates theme path. |
|
| 219 | - * |
|
| 220 | - * |
|
| 221 | - * @return string Template path. |
|
| 222 | - */ |
|
| 223 | - public static function get_theme_template_path() { |
|
| 224 | - $template = get_template(); |
|
| 225 | - $theme_root = get_theme_root( $template ); |
|
| 226 | - |
|
| 227 | - return $theme_root . '/' . $template . '/' . untrailingslashit( wpinv_get_theme_template_dir_name() ); |
|
| 228 | - |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Oxygen locate theme template. |
|
| 233 | - * |
|
| 234 | - * @param string $template The template. |
|
| 235 | - * @return string The theme template. |
|
| 236 | - */ |
|
| 237 | - public static function oxygen_locate_template( $template ) { |
|
| 238 | - |
|
| 239 | - if ( empty( $template ) ) { |
|
| 240 | - return ''; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $has_filter = has_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 244 | - |
|
| 245 | - // Remove template filter |
|
| 246 | - if ( $has_filter ) { |
|
| 247 | - remove_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $template = self::get_theme_template_path() . '/' . $template; |
|
| 251 | - |
|
| 252 | - if ( ! file_exists( $template ) ) { |
|
| 253 | - $template = ''; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Add template filter |
|
| 257 | - if ( $has_filter ) { |
|
| 258 | - add_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - return $template; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Oxygen override theme template. |
|
| 266 | - * |
|
| 267 | - * @param string $located Located template. |
|
| 268 | - * @param string $template_name Template name. |
|
| 269 | - * @return string Located template. |
|
| 270 | - */ |
|
| 271 | - public function oxygen_override_template( $located, $template_name ) { |
|
| 218 | + * Get the geodirectory templates theme path. |
|
| 219 | + * |
|
| 220 | + * |
|
| 221 | + * @return string Template path. |
|
| 222 | + */ |
|
| 223 | + public static function get_theme_template_path() { |
|
| 224 | + $template = get_template(); |
|
| 225 | + $theme_root = get_theme_root( $template ); |
|
| 226 | + |
|
| 227 | + return $theme_root . '/' . $template . '/' . untrailingslashit( wpinv_get_theme_template_dir_name() ); |
|
| 228 | + |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Oxygen locate theme template. |
|
| 233 | + * |
|
| 234 | + * @param string $template The template. |
|
| 235 | + * @return string The theme template. |
|
| 236 | + */ |
|
| 237 | + public static function oxygen_locate_template( $template ) { |
|
| 238 | + |
|
| 239 | + if ( empty( $template ) ) { |
|
| 240 | + return ''; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $has_filter = has_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 244 | + |
|
| 245 | + // Remove template filter |
|
| 246 | + if ( $has_filter ) { |
|
| 247 | + remove_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $template = self::get_theme_template_path() . '/' . $template; |
|
| 251 | + |
|
| 252 | + if ( ! file_exists( $template ) ) { |
|
| 253 | + $template = ''; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Add template filter |
|
| 257 | + if ( $has_filter ) { |
|
| 258 | + add_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + return $template; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Oxygen override theme template. |
|
| 266 | + * |
|
| 267 | + * @param string $located Located template. |
|
| 268 | + * @param string $template_name Template name. |
|
| 269 | + * @return string Located template. |
|
| 270 | + */ |
|
| 271 | + public function oxygen_override_template( $located, $template_name ) { |
|
| 272 | 272 | |
| 273 | 273 | $oxygen_overide = self::oxygen_locate_template( $template_name ); |
| 274 | - if ( ! empty( $oxygen_overide ) ) { |
|
| 275 | - return $oxygen_overide; |
|
| 276 | - } |
|
| 274 | + if ( ! empty( $oxygen_overide ) ) { |
|
| 275 | + return $oxygen_overide; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - return $located; |
|
| 279 | - } |
|
| 278 | + return $located; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | 281 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -26,12 +26,12 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function __construct() { |
| 28 | 28 | |
| 29 | - $this->templates_dir = apply_filters( 'getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates' ); |
|
| 30 | - $this->templates_url = apply_filters( 'getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates' ); |
|
| 29 | + $this->templates_dir = apply_filters('getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates'); |
|
| 30 | + $this->templates_url = apply_filters('getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates'); |
|
| 31 | 31 | |
| 32 | 32 | // Oxygen plugin |
| 33 | - if ( defined( 'CT_VERSION' ) ) { |
|
| 34 | - add_filter( 'wpinv_locate_template', array( $this, 'oxygen_override_template' ), 11, 4 ); |
|
| 33 | + if (defined('CT_VERSION')) { |
|
| 34 | + add_filter('wpinv_locate_template', array($this, 'oxygen_override_template'), 11, 4); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @return bool |
| 61 | 61 | */ |
| 62 | 62 | public function is_elementor_preview() { |
| 63 | - return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ); |
|
| 63 | + return isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax'); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @return bool |
| 71 | 71 | */ |
| 72 | 72 | public function is_divi_preview() { |
| 73 | - return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' ); |
|
| 73 | + return isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'et_pb'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @return bool |
| 81 | 81 | */ |
| 82 | 82 | public function is_beaver_preview() { |
| 83 | - return isset( $_REQUEST['fl_builder'] ); |
|
| 83 | + return isset($_REQUEST['fl_builder']); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return bool |
| 91 | 91 | */ |
| 92 | 92 | public function is_siteorigin_preview() { |
| 93 | - return ! empty( $_REQUEST['siteorigin_panels_live_editor'] ); |
|
| 93 | + return !empty($_REQUEST['siteorigin_panels_live_editor']); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @return bool |
| 101 | 101 | */ |
| 102 | 102 | public function is_cornerstone_preview() { |
| 103 | - return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint'; |
|
| 103 | + return !empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint'; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return bool |
| 111 | 111 | */ |
| 112 | 112 | public function is_fusion_preview() { |
| 113 | - return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ); |
|
| 113 | + return !empty($_REQUEST['fb-edit']) || !empty($_REQUEST['fusion_load_nonce']); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @return bool |
| 121 | 121 | */ |
| 122 | 122 | public function is_oxygen_preview() { |
| 123 | - return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ); |
|
| 123 | + return !empty($_REQUEST['ct_builder']) || (!empty($_REQUEST['action']) && (substr($_REQUEST['action'], 0, 11) === "oxy_render_" || substr($_REQUEST['action'], 0, 10) === "ct_render_")); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -130,24 +130,24 @@ discard block |
||
| 130 | 130 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
| 131 | 131 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 132 | 132 | */ |
| 133 | - public function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 133 | + public function locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 134 | 134 | |
| 135 | 135 | // Load the defaults for the template path and default path. |
| 136 | - $template_path = empty( $template_path ) ? 'invoicing' : $template_path; |
|
| 137 | - $default_path = empty( $default_path ) ? $this->templates_dir : $default_path; |
|
| 138 | - $default_path = apply_filters( 'getpaid_template_default_template_path', $default_path, $template_name ); |
|
| 136 | + $template_path = empty($template_path) ? 'invoicing' : $template_path; |
|
| 137 | + $default_path = empty($default_path) ? $this->templates_dir : $default_path; |
|
| 138 | + $default_path = apply_filters('getpaid_template_default_template_path', $default_path, $template_name); |
|
| 139 | 139 | |
| 140 | 140 | // Is it overidden? |
| 141 | 141 | $template = locate_template( |
| 142 | - array( trailingslashit( $template_path ) . $template_name, 'wpinv-' . $template_name ) |
|
| 142 | + array(trailingslashit($template_path) . $template_name, 'wpinv-' . $template_name) |
|
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | 145 | // If not, load the default template. |
| 146 | - if ( empty( $template ) ) { |
|
| 147 | - $template = trailingslashit( $default_path ) . $template_name; |
|
| 146 | + if (empty($template)) { |
|
| 147 | + $template = trailingslashit($default_path) . $template_name; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path, $default_path ); |
|
| 150 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path, $default_path); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -156,20 +156,20 @@ discard block |
||
| 156 | 156 | * @since 1.0.19 |
| 157 | 157 | * @return bool |
| 158 | 158 | */ |
| 159 | - protected function load_template( $template_name, $template_path, $args ) { |
|
| 159 | + protected function load_template($template_name, $template_path, $args) { |
|
| 160 | 160 | |
| 161 | - if ( is_array( $args ) ){ |
|
| 162 | - extract( $args ); |
|
| 161 | + if (is_array($args)) { |
|
| 162 | + extract($args); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Fires before loading a template. |
| 166 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $args ); |
|
| 166 | + do_action('wpinv_before_template_part', $template_name, $template_path, $args); |
|
| 167 | 167 | |
| 168 | 168 | // Load the template. |
| 169 | - include( $template_path ); |
|
| 169 | + include($template_path); |
|
| 170 | 170 | |
| 171 | 171 | // Fires after loading a template. |
| 172 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $args ); |
|
| 172 | + do_action('wpinv_after_template_part', $template_name, $template_path, $args); |
|
| 173 | 173 | |
| 174 | 174 | } |
| 175 | 175 | |
@@ -183,18 +183,18 @@ discard block |
||
| 183 | 183 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
| 184 | 184 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 185 | 185 | */ |
| 186 | - public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 186 | + public function display_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 187 | 187 | |
| 188 | 188 | // Locate the template. |
| 189 | - $located = $this->locate_template( $template_name, $template_path, $default_path ); |
|
| 189 | + $located = $this->locate_template($template_name, $template_path, $default_path); |
|
| 190 | 190 | |
| 191 | 191 | // Abort if the file does not exist. |
| 192 | - if ( ! file_exists( $located ) ) { |
|
| 193 | - getpaid_doing_it_wrong( __METHOD__, sprintf( '<code>%s</code> does not exist.', $located ), '2.0.0' ); |
|
| 192 | + if (!file_exists($located)) { |
|
| 193 | + getpaid_doing_it_wrong(__METHOD__, sprintf('<code>%s</code> does not exist.', $located), '2.0.0'); |
|
| 194 | 194 | return; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - $this->load_template( $template_name, $located, $args ); |
|
| 197 | + $this->load_template($template_name, $located, $args); |
|
| 198 | 198 | |
| 199 | 199 | } |
| 200 | 200 | |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
| 209 | 209 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 210 | 210 | */ |
| 211 | - public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 211 | + public function get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 212 | 212 | ob_start(); |
| 213 | - $this->display_template( $template_name, $args, $template_path, $default_path ); |
|
| 213 | + $this->display_template($template_name, $args, $template_path, $default_path); |
|
| 214 | 214 | return ob_get_clean(); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -222,9 +222,9 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public static function get_theme_template_path() { |
| 224 | 224 | $template = get_template(); |
| 225 | - $theme_root = get_theme_root( $template ); |
|
| 225 | + $theme_root = get_theme_root($template); |
|
| 226 | 226 | |
| 227 | - return $theme_root . '/' . $template . '/' . untrailingslashit( wpinv_get_theme_template_dir_name() ); |
|
| 227 | + return $theme_root . '/' . $template . '/' . untrailingslashit(wpinv_get_theme_template_dir_name()); |
|
| 228 | 228 | |
| 229 | 229 | } |
| 230 | 230 | |
@@ -234,28 +234,28 @@ discard block |
||
| 234 | 234 | * @param string $template The template. |
| 235 | 235 | * @return string The theme template. |
| 236 | 236 | */ |
| 237 | - public static function oxygen_locate_template( $template ) { |
|
| 237 | + public static function oxygen_locate_template($template) { |
|
| 238 | 238 | |
| 239 | - if ( empty( $template ) ) { |
|
| 239 | + if (empty($template)) { |
|
| 240 | 240 | return ''; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - $has_filter = has_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 243 | + $has_filter = has_filter('template', 'ct_oxygen_template_name'); |
|
| 244 | 244 | |
| 245 | 245 | // Remove template filter |
| 246 | - if ( $has_filter ) { |
|
| 247 | - remove_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 246 | + if ($has_filter) { |
|
| 247 | + remove_filter('template', 'ct_oxygen_template_name'); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | $template = self::get_theme_template_path() . '/' . $template; |
| 251 | 251 | |
| 252 | - if ( ! file_exists( $template ) ) { |
|
| 252 | + if (!file_exists($template)) { |
|
| 253 | 253 | $template = ''; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // Add template filter |
| 257 | - if ( $has_filter ) { |
|
| 258 | - add_filter( 'template', 'ct_oxygen_template_name' ); |
|
| 257 | + if ($has_filter) { |
|
| 258 | + add_filter('template', 'ct_oxygen_template_name'); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | return $template; |
@@ -268,10 +268,10 @@ discard block |
||
| 268 | 268 | * @param string $template_name Template name. |
| 269 | 269 | * @return string Located template. |
| 270 | 270 | */ |
| 271 | - public function oxygen_override_template( $located, $template_name ) { |
|
| 271 | + public function oxygen_override_template($located, $template_name) { |
|
| 272 | 272 | |
| 273 | - $oxygen_overide = self::oxygen_locate_template( $template_name ); |
|
| 274 | - if ( ! empty( $oxygen_overide ) ) { |
|
| 273 | + $oxygen_overide = self::oxygen_locate_template($template_name); |
|
| 274 | + if (!empty($oxygen_overide)) { |
|
| 275 | 275 | return $oxygen_overide; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -8,205 +8,205 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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" and "reply-to" 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" and "reply-to" 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?', 'invoicing' ), |
|
| 428 | - 'std' => get_option( 'admin_email' ), |
|
| 426 | + 'name' => __('Admin Email', 'invoicing'), |
|
| 427 | + 'desc' => __('Where should we send admin notifications?', '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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,41 +568,41 @@ discard block |
||
| 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 | 'login_to_checkout' => array( |
| 583 | 583 | 'id' => 'login_to_checkout', |
| 584 | - 'name' => __( 'Require Login To Checkout', 'invoicing' ), |
|
| 585 | - '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' ), |
|
| 584 | + 'name' => __('Require Login To Checkout', 'invoicing'), |
|
| 585 | + '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'), |
|
| 586 | 586 | 'type' => 'checkbox', |
| 587 | 587 | ), |
| 588 | 588 | |
| 589 | 589 | 'maxmind_license_key' => array( |
| 590 | 590 | 'id' => 'maxmind_license_key', |
| 591 | - 'name' => __( 'MaxMind License Key', 'invoicing' ), |
|
| 591 | + 'name' => __('MaxMind License Key', 'invoicing'), |
|
| 592 | 592 | 'type' => 'text', |
| 593 | 593 | 'size' => 'regular', |
| 594 | - '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>', |
|
| 594 | + '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>', |
|
| 595 | 595 | ), |
| 596 | 596 | |
| 597 | 597 | 'uninstall_settings' => array( |
| 598 | 598 | 'id' => 'uninstall_settings', |
| 599 | - 'name' => '<h3>' . __( 'Uninstall Settings', 'invoicing' ) . '</h3>', |
|
| 599 | + 'name' => '<h3>' . __('Uninstall Settings', 'invoicing') . '</h3>', |
|
| 600 | 600 | 'type' => 'header', |
| 601 | 601 | ), |
| 602 | 602 | 'remove_data_on_unistall' => array( |
| 603 | 603 | 'id' => 'remove_data_on_unistall', |
| 604 | - 'name' => __( 'Remove Data on Uninstall?', 'invoicing' ), |
|
| 605 | - 'desc' => __( 'Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing' ), |
|
| 604 | + 'name' => __('Remove Data on Uninstall?', 'invoicing'), |
|
| 605 | + 'desc' => __('Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing'), |
|
| 606 | 606 | 'type' => 'checkbox', |
| 607 | 607 | 'std' => '' |
| 608 | 608 | ), |
@@ -611,13 +611,13 @@ discard block |
||
| 611 | 611 | 'custom-css' => array( |
| 612 | 612 | 'css_settings' => array( |
| 613 | 613 | 'id' => 'css_settings', |
| 614 | - 'name' => '<h3>' . __( 'Custom CSS', 'invoicing' ) . '</h3>', |
|
| 614 | + 'name' => '<h3>' . __('Custom CSS', 'invoicing') . '</h3>', |
|
| 615 | 615 | 'type' => 'header', |
| 616 | 616 | ), |
| 617 | 617 | 'template_custom_css' => array( |
| 618 | 618 | 'id' => 'template_custom_css', |
| 619 | - 'name' => __( 'Invoice Template CSS', 'invoicing' ), |
|
| 620 | - 'desc' => __( 'Add CSS to modify appearance of the print invoice page.', 'invoicing' ), |
|
| 619 | + 'name' => __('Invoice Template CSS', 'invoicing'), |
|
| 620 | + 'desc' => __('Add CSS to modify appearance of the print invoice page.', 'invoicing'), |
|
| 621 | 621 | 'type' => 'textarea', |
| 622 | 622 | 'class'=> 'regular-text', |
| 623 | 623 | 'rows' => 10, |
@@ -631,8 +631,8 @@ discard block |
||
| 631 | 631 | 'main' => array( |
| 632 | 632 | 'tool_settings' => array( |
| 633 | 633 | 'id' => 'tool_settings', |
| 634 | - 'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>', |
|
| 635 | - 'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ), |
|
| 634 | + 'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>', |
|
| 635 | + 'desc' => __('Invoicing diagnostic tools', 'invoicing'), |
|
| 636 | 636 | 'type' => 'tools', |
| 637 | 637 | ), |
| 638 | 638 | ), |
@@ -7,24 +7,24 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | -$logo_width = wpinv_get_option( 'logo_width' ); |
|
| 13 | -$logo_height = wpinv_get_option( 'logo_height' ); |
|
| 12 | +$logo_width = wpinv_get_option('logo_width'); |
|
| 13 | +$logo_height = wpinv_get_option('logo_height'); |
|
| 14 | 14 | |
| 15 | 15 | ?> |
| 16 | -<a target="_blank" class="logo-link text-dark" href="<?php echo esc_url( wpinv_get_business_website() ); ?>"> |
|
| 16 | +<a target="_blank" class="logo-link text-dark" href="<?php echo esc_url(wpinv_get_business_website()); ?>"> |
|
| 17 | 17 | |
| 18 | - <?php if ( $logo = wpinv_get_business_logo() ) : ?> |
|
| 18 | + <?php if ($logo = wpinv_get_business_logo()) : ?> |
|
| 19 | 19 | |
| 20 | - <?php if ( ! empty( $logo_width ) && ! empty( $logo_height ) ) : ?> |
|
| 21 | - <img class="logo" style="max-width:100%; width:<?php echo absint( $logo_width ); ?>px; height:<?php echo absint( $logo_height ); ?>px;" src="<?php echo esc_url( $logo ); ?>"> |
|
| 20 | + <?php if (!empty($logo_width) && !empty($logo_height)) : ?> |
|
| 21 | + <img class="logo" style="max-width:100%; width:<?php echo absint($logo_width); ?>px; height:<?php echo absint($logo_height); ?>px;" src="<?php echo esc_url($logo); ?>"> |
|
| 22 | 22 | <?php else: ?> |
| 23 | - <img class="logo" style="max-width:100%;" src="<?php echo esc_url( $logo ); ?>"> |
|
| 23 | + <img class="logo" style="max-width:100%;" src="<?php echo esc_url($logo); ?>"> |
|
| 24 | 24 | <?php endif; ?> |
| 25 | 25 | |
| 26 | 26 | <?php else: ?> |
| 27 | - <h1 class="h3"><?php echo esc_html( wpinv_get_business_name() ); ?></h1> |
|
| 27 | + <h1 class="h3"><?php echo esc_html(wpinv_get_business_name()); ?></h1> |
|
| 28 | 28 | <?php endif; ?> |
| 29 | 29 | |
| 30 | 30 | </a> |
@@ -19,12 +19,18 @@ |
||
| 19 | 19 | |
| 20 | 20 | <?php if ( ! empty( $logo_width ) && ! empty( $logo_height ) ) : ?> |
| 21 | 21 | <img class="logo" style="max-width:100%; width:<?php echo absint( $logo_width ); ?>px; height:<?php echo absint( $logo_height ); ?>px;" src="<?php echo esc_url( $logo ); ?>"> |
| 22 | - <?php else: ?> |
|
| 23 | - <img class="logo" style="max-width:100%;" src="<?php echo esc_url( $logo ); ?>"> |
|
| 22 | + <?php else { |
|
| 23 | + : ?> |
|
| 24 | + <img class="logo" style="max-width:100%;" src="<?php echo esc_url( $logo ); |
|
| 25 | +} |
|
| 26 | +?>"> |
|
| 24 | 27 | <?php endif; ?> |
| 25 | 28 | |
| 26 | - <?php else: ?> |
|
| 27 | - <h1 class="h3"><?php echo esc_html( wpinv_get_business_name() ); ?></h1> |
|
| 29 | + <?php else { |
|
| 30 | + : ?> |
|
| 31 | + <h1 class="h3"><?php echo esc_html( wpinv_get_business_name() ); |
|
| 32 | +} |
|
| 33 | +?></h1> |
|
| 28 | 34 | <?php endif; ?> |
| 29 | 35 | |
| 30 | 36 | </a> |
@@ -160,50 +160,50 @@ |
||
| 160 | 160 | */ |
| 161 | 161 | function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
| 162 | 162 | |
| 163 | - $initial_discount = 0; |
|
| 164 | - $recurring_discount = 0; |
|
| 163 | + $initial_discount = 0; |
|
| 164 | + $recurring_discount = 0; |
|
| 165 | 165 | |
| 166 | - foreach ( $invoice->get_items() as $item ) { |
|
| 166 | + foreach ( $invoice->get_items() as $item ) { |
|
| 167 | 167 | |
| 168 | - // Abort if it is not valid for this item. |
|
| 169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 170 | - continue; |
|
| 171 | - } |
|
| 168 | + // Abort if it is not valid for this item. |
|
| 169 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 170 | + continue; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - // Calculate the initial amount... |
|
| 174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 175 | - $recurring_item_discount = 0; |
|
| 173 | + // Calculate the initial amount... |
|
| 174 | + $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 175 | + $recurring_item_discount = 0; |
|
| 176 | 176 | |
| 177 | - // ... and maybe the recurring amount. |
|
| 178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 180 | - } |
|
| 177 | + // ... and maybe the recurring amount. |
|
| 178 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | + $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - // Discount should not exceed discounted amount. |
|
| 183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
| 182 | + // Discount should not exceed discounted amount. |
|
| 183 | + if ( ! $discount->is_type( 'percent' ) ) { |
|
| 184 | 184 | |
| 185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 186 | - $item_discount = $discount->get_amount() - $initial_discount; |
|
| 187 | - } |
|
| 185 | + if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 186 | + $item_discount = $discount->get_amount() - $initial_discount; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 190 | - $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
| 191 | - } |
|
| 189 | + if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 190 | + $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - $initial_discount += $item_discount; |
|
| 196 | - $recurring_discount += $recurring_discount; |
|
| 197 | - $item->item_discount = $item_discount; |
|
| 198 | - $item->recurring_item_discount = $recurring_item_discount; |
|
| 195 | + $initial_discount += $item_discount; |
|
| 196 | + $recurring_discount += $recurring_discount; |
|
| 197 | + $item->item_discount = $item_discount; |
|
| 198 | + $item->recurring_item_discount = $recurring_item_discount; |
|
| 199 | 199 | |
| 200 | - } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return array( |
|
| 203 | - 'name' => 'discount_code', |
|
| 204 | - 'discount_code' => $discount->get_code(), |
|
| 205 | - 'initial_discount' => $initial_discount, |
|
| 206 | - 'recurring_discount' => $recurring_discount, |
|
| 207 | - ); |
|
| 202 | + return array( |
|
| 203 | + 'name' => 'discount_code', |
|
| 204 | + 'discount_code' => $discount->get_code(), |
|
| 205 | + 'initial_discount' => $initial_discount, |
|
| 206 | + 'recurring_discount' => $recurring_discount, |
|
| 207 | + ); |
|
| 208 | 208 | |
| 209 | 209 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | return apply_filters( |
| 18 | 18 | 'wpinv_discount_types', |
| 19 | 19 | array( |
| 20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
| 21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
| 20 | + 'percent' => __('Percentage', 'invoicing'), |
|
| 21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
| 22 | 22 | ) |
| 23 | 23 | ); |
| 24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
| 31 | +function wpinv_get_discount_type_name($type = '') { |
|
| 32 | 32 | $types = wpinv_get_discount_types(); |
| 33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
| 33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Deletes a discount via the admin page. |
| 38 | 38 | * |
| 39 | 39 | */ |
| 40 | -function wpinv_delete_discount( $data ) { |
|
| 40 | +function wpinv_delete_discount($data) { |
|
| 41 | 41 | |
| 42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
| 43 | - $discount->delete( true ); |
|
| 42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
| 43 | + $discount->delete(true); |
|
| 44 | 44 | |
| 45 | 45 | } |
| 46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
| 46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Deactivates a discount via the admin page. |
| 50 | 50 | */ |
| 51 | -function wpinv_activate_discount( $data ) { |
|
| 51 | +function wpinv_activate_discount($data) { |
|
| 52 | 52 | |
| 53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
| 54 | - $discount->set_status( 'publish' ); |
|
| 53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
| 54 | + $discount->set_status('publish'); |
|
| 55 | 55 | $discount->save(); |
| 56 | 56 | |
| 57 | 57 | } |
| 58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
| 58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Activates a discount via the admin page. |
| 62 | 62 | */ |
| 63 | -function wpinv_deactivate_discount( $data ) { |
|
| 63 | +function wpinv_deactivate_discount($data) { |
|
| 64 | 64 | |
| 65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
| 66 | - $discount->set_status( 'pending' ); |
|
| 65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
| 66 | + $discount->set_status('pending'); |
|
| 67 | 67 | $discount->save(); |
| 68 | 68 | |
| 69 | 69 | } |
| 70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
| 70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | * @since 1.0.15 |
| 77 | 77 | * @return WPInv_Discount |
| 78 | 78 | */ |
| 79 | -function wpinv_get_discount( $discount ) { |
|
| 80 | - return new WPInv_Discount( $discount ); |
|
| 79 | +function wpinv_get_discount($discount) { |
|
| 80 | + return new WPInv_Discount($discount); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | * @since 1.0.15 |
| 88 | 88 | * @return WPInv_Discount |
| 89 | 89 | */ |
| 90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
| 91 | - return new WPInv_Discount( $discount ); |
|
| 90 | +function wpinv_get_discount_obj($discount = 0) { |
|
| 91 | + return new WPInv_Discount($discount); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
| 98 | 98 | * @param string|int $value The field value |
| 99 | 99 | * @return bool|WPInv_Discount |
| 100 | 100 | */ |
| 101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
| 102 | - $discount = new WPInv_Discount( $value ); |
|
| 101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
| 102 | + $discount = new WPInv_Discount($value); |
|
| 103 | 103 | |
| 104 | - if ( $discount->get_id() != 0 ) { |
|
| 104 | + if ($discount->get_id() != 0) { |
|
| 105 | 105 | return $discount; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | function wpinv_get_discount_statuses() { |
| 117 | 117 | |
| 118 | 118 | return array( |
| 119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
| 121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
| 119 | + 'expired' => __('Expired', 'invoicing'), |
|
| 120 | + 'publish' => __('Active', 'invoicing'), |
|
| 121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
| 122 | 122 | ); |
| 123 | 123 | |
| 124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | /** |
| 127 | 127 | * Retrieves an invoice status label. |
| 128 | 128 | */ |
| 129 | -function wpinv_discount_status( $status ) { |
|
| 129 | +function wpinv_discount_status($status) { |
|
| 130 | 130 | $statuses = wpinv_get_discount_statuses(); |
| 131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
| 131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
| 139 | 139 | * @return bool |
| 140 | 140 | */ |
| 141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
| 141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
| 142 | 142 | |
| 143 | - if( ! empty( $discount ) ) { |
|
| 144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 143 | + if (!empty($discount)) { |
|
| 144 | + $discount = wpinv_get_discount_obj($discount); |
|
| 145 | 145 | } else { |
| 146 | - $discount = wpinv_get_discount_obj( $code ); |
|
| 146 | + $discount = wpinv_get_discount_obj($code); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | return $discount->get_is_recurring(); |
@@ -158,35 +158,35 @@ discard block |
||
| 158 | 158 | * @param WPInv_Discount $discount |
| 159 | 159 | * @return array |
| 160 | 160 | */ |
| 161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
|
| 161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { |
|
| 162 | 162 | |
| 163 | 163 | $initial_discount = 0; |
| 164 | 164 | $recurring_discount = 0; |
| 165 | 165 | |
| 166 | - foreach ( $invoice->get_items() as $item ) { |
|
| 166 | + foreach ($invoice->get_items() as $item) { |
|
| 167 | 167 | |
| 168 | 168 | // Abort if it is not valid for this item. |
| 169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 169 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
| 170 | 170 | continue; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Calculate the initial amount... |
| 174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total()); |
|
| 175 | 175 | $recurring_item_discount = 0; |
| 176 | 176 | |
| 177 | 177 | // ... and maybe the recurring amount. |
| 178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 178 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
| 179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // Discount should not exceed discounted amount. |
| 183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
| 183 | + if (!$discount->is_type('percent')) { |
|
| 184 | 184 | |
| 185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 185 | + if (($initial_discount + $item_discount) > $discount->get_amount()) { |
|
| 186 | 186 | $item_discount = $discount->get_amount() - $initial_discount; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 189 | + if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { |
|
| 190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -12,228 +12,228 @@ |
||
| 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 | + |
|
| 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 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | + $this->taxes[ $name ] = $tax; |
|
| 72 | + continue; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Checks if the submission has a digital item. |
|
| 84 | + * |
|
| 85 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | + * @since 1.0.19 |
|
| 87 | + * @return bool |
|
| 88 | + */ |
|
| 89 | + public function has_digital_item( $submission ) { |
|
| 90 | + |
|
| 91 | + foreach ( $submission->get_items() as $item ) { |
|
| 92 | + |
|
| 93 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Checks if this is an eu store. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public static function is_eu_store() { |
|
| 109 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
| 110 | + } |
|
| 26 | 111 | |
| 27 | 112 | /** |
| 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 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | - $this->taxes[ $name ] = $tax; |
|
| 72 | - continue; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Checks if the submission has a digital item. |
|
| 84 | - * |
|
| 85 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | - * @since 1.0.19 |
|
| 87 | - * @return bool |
|
| 88 | - */ |
|
| 89 | - public function has_digital_item( $submission ) { |
|
| 90 | - |
|
| 91 | - foreach ( $submission->get_items() as $item ) { |
|
| 92 | - |
|
| 93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Checks if this is an eu store. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public static function is_eu_store() { |
|
| 109 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Checks if this is an eu country. |
|
| 114 | - * |
|
| 115 | - * @param string $country |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 119 | - public static function is_eu_country( $country ) { |
|
| 120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Checks if this is an eu purchase. |
|
| 125 | - * |
|
| 126 | - * @param string $customer_country |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @return bool |
|
| 129 | - */ |
|
| 130 | - public static function is_eu_transaction( $customer_country ) { |
|
| 131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Retrieves the vat number. |
|
| 136 | - * |
|
| 137 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function get_vat_number( $submission ) { |
|
| 142 | - |
|
| 143 | - // Retrieve from the posted number. |
|
| 144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | - if ( ! is_null( $vat_number ) ) { |
|
| 146 | - return wpinv_clean( $vat_number ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Retrieves the company. |
|
| 154 | - * |
|
| 155 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 156 | - * @since 1.0.19 |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - public function get_company( $submission ) { |
|
| 160 | - |
|
| 161 | - // Retrieve from the posted data. |
|
| 162 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 163 | - if ( ! empty( $company ) ) { |
|
| 164 | - return wpinv_clean( $company ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // Retrieve from the invoice. |
|
| 168 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Checks if we require a VAT number. |
|
| 173 | - * |
|
| 174 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 175 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 176 | - * @since 1.0.19 |
|
| 177 | - * @return string |
|
| 178 | - */ |
|
| 179 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 180 | - |
|
| 181 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 182 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 183 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 184 | - |
|
| 185 | - return $prevent_b2c && $is_eu; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Validate VAT data. |
|
| 190 | - * |
|
| 191 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 192 | - * @since 1.0.19 |
|
| 193 | - */ |
|
| 194 | - public function validate_vat( $submission ) { |
|
| 195 | - |
|
| 196 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 197 | - |
|
| 198 | - // Abort if we are not validating vat numbers. |
|
| 199 | - if ( ! $in_eu ) { |
|
| 113 | + * Checks if this is an eu country. |
|
| 114 | + * |
|
| 115 | + * @param string $country |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | + public static function is_eu_country( $country ) { |
|
| 120 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Checks if this is an eu purchase. |
|
| 125 | + * |
|
| 126 | + * @param string $customer_country |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @return bool |
|
| 129 | + */ |
|
| 130 | + public static function is_eu_transaction( $customer_country ) { |
|
| 131 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Retrieves the vat number. |
|
| 136 | + * |
|
| 137 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function get_vat_number( $submission ) { |
|
| 142 | + |
|
| 143 | + // Retrieve from the posted number. |
|
| 144 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | + if ( ! is_null( $vat_number ) ) { |
|
| 146 | + return wpinv_clean( $vat_number ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Retrieves the company. |
|
| 154 | + * |
|
| 155 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 156 | + * @since 1.0.19 |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + public function get_company( $submission ) { |
|
| 160 | + |
|
| 161 | + // Retrieve from the posted data. |
|
| 162 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 163 | + if ( ! empty( $company ) ) { |
|
| 164 | + return wpinv_clean( $company ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // Retrieve from the invoice. |
|
| 168 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Checks if we require a VAT number. |
|
| 173 | + * |
|
| 174 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 175 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 176 | + * @since 1.0.19 |
|
| 177 | + * @return string |
|
| 178 | + */ |
|
| 179 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 180 | + |
|
| 181 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 182 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 183 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 184 | + |
|
| 185 | + return $prevent_b2c && $is_eu; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Validate VAT data. |
|
| 190 | + * |
|
| 191 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 192 | + * @since 1.0.19 |
|
| 193 | + */ |
|
| 194 | + public function validate_vat( $submission ) { |
|
| 195 | + |
|
| 196 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 197 | + |
|
| 198 | + // Abort if we are not validating vat numbers. |
|
| 199 | + if ( ! $in_eu ) { |
|
| 200 | 200 | return; |
| 201 | - } |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - // Prepare variables. |
|
| 204 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 205 | - $ip_country = getpaid_get_ip_country(); |
|
| 203 | + // Prepare variables. |
|
| 204 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 205 | + $ip_country = getpaid_get_ip_country(); |
|
| 206 | 206 | $is_eu = $this->is_eu_country( $submission->country ); |
| 207 | 207 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 208 | 208 | |
| 209 | - // Maybe abort early for initial fetches. |
|
| 210 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 211 | - return; |
|
| 212 | - } |
|
| 209 | + // Maybe abort early for initial fetches. |
|
| 210 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 211 | + return; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // If we're preventing business to consumer purchases, |
|
| 215 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 214 | + // If we're preventing business to consumer purchases, |
|
| 215 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 216 | 216 | |
| 217 | - // Ensure that a vat number has been specified. |
|
| 218 | - throw new Exception( |
|
| 219 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 220 | - ); |
|
| 217 | + // Ensure that a vat number has been specified. |
|
| 218 | + throw new Exception( |
|
| 219 | + __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 220 | + ); |
|
| 221 | 221 | |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - if ( empty( $vat_number ) ) { |
|
| 225 | - return; |
|
| 226 | - } |
|
| 224 | + if ( empty( $vat_number ) ) { |
|
| 225 | + return; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 229 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 230 | - } |
|
| 228 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 229 | + throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 233 | - return; |
|
| 234 | - } |
|
| 232 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 233 | + return; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - $this->skip_taxes = true; |
|
| 237 | - } |
|
| 236 | + $this->skip_taxes = true; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission taxes class |
@@ -29,22 +29,22 @@ discard block |
||
| 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,24 +56,24 @@ discard block |
||
| 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 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | - $this->taxes[ $name ] = $tax; |
|
| 70 | + if (!isset($this->taxes[$name])) { |
|
| 71 | + $this->taxes[$name] = $tax; |
|
| 72 | 72 | continue; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 75 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | * @since 1.0.19 |
| 87 | 87 | * @return bool |
| 88 | 88 | */ |
| 89 | - public function has_digital_item( $submission ) { |
|
| 89 | + public function has_digital_item($submission) { |
|
| 90 | 90 | |
| 91 | - foreach ( $submission->get_items() as $item ) { |
|
| 91 | + foreach ($submission->get_items() as $item) { |
|
| 92 | 92 | |
| 93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 93 | + if ('digital' == $item->get_vat_rule()) { |
|
| 94 | 94 | return true; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @return bool |
| 107 | 107 | */ |
| 108 | 108 | public static function is_eu_store() { |
| 109 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 109 | + return self::is_eu_country(wpinv_get_default_country()); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | * @since 1.0.19 |
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | - public static function is_eu_country( $country ) { |
|
| 120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 119 | + public static function is_eu_country($country) { |
|
| 120 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | * @since 1.0.19 |
| 128 | 128 | * @return bool |
| 129 | 129 | */ |
| 130 | - public static function is_eu_transaction( $customer_country ) { |
|
| 131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 130 | + public static function is_eu_transaction($customer_country) { |
|
| 131 | + return self::is_eu_country($customer_country) && self::is_eu_store(); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | * @since 1.0.19 |
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | - public function get_vat_number( $submission ) { |
|
| 141 | + public function get_vat_number($submission) { |
|
| 142 | 142 | |
| 143 | 143 | // Retrieve from the posted number. |
| 144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | - if ( ! is_null( $vat_number ) ) { |
|
| 146 | - return wpinv_clean( $vat_number ); |
|
| 144 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
| 145 | + if (!is_null($vat_number)) { |
|
| 146 | + return wpinv_clean($vat_number); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
@@ -156,12 +156,12 @@ discard block |
||
| 156 | 156 | * @since 1.0.19 |
| 157 | 157 | * @return string |
| 158 | 158 | */ |
| 159 | - public function get_company( $submission ) { |
|
| 159 | + public function get_company($submission) { |
|
| 160 | 160 | |
| 161 | 161 | // Retrieve from the posted data. |
| 162 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 163 | - if ( ! empty( $company ) ) { |
|
| 164 | - return wpinv_clean( $company ); |
|
| 162 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
| 163 | + if (!empty($company)) { |
|
| 164 | + return wpinv_clean($company); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Retrieve from the invoice. |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | * @since 1.0.19 |
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 179 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
| 180 | 180 | |
| 181 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 182 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 181 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
| 182 | + $prevent_b2c = !empty($prevent_b2c); |
|
| 183 | 183 | $is_eu = $ip_in_eu || $country_in_eu; |
| 184 | 184 | |
| 185 | 185 | return $prevent_b2c && $is_eu; |
@@ -191,45 +191,45 @@ discard block |
||
| 191 | 191 | * @param GetPaid_Payment_Form_Submission $submission |
| 192 | 192 | * @since 1.0.19 |
| 193 | 193 | */ |
| 194 | - public function validate_vat( $submission ) { |
|
| 194 | + public function validate_vat($submission) { |
|
| 195 | 195 | |
| 196 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 196 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
| 197 | 197 | |
| 198 | 198 | // Abort if we are not validating vat numbers. |
| 199 | - if ( ! $in_eu ) { |
|
| 199 | + if (!$in_eu) { |
|
| 200 | 200 | return; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // Prepare variables. |
| 204 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 204 | + $vat_number = $this->get_vat_number($submission); |
|
| 205 | 205 | $ip_country = getpaid_get_ip_country(); |
| 206 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
| 207 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
| 206 | + $is_eu = $this->is_eu_country($submission->country); |
|
| 207 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
| 208 | 208 | |
| 209 | 209 | // Maybe abort early for initial fetches. |
| 210 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 210 | + if ($submission->is_initial_fetch() && empty($vat_number)) { |
|
| 211 | 211 | return; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // If we're preventing business to consumer purchases, |
| 215 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 215 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
| 216 | 216 | |
| 217 | 217 | // Ensure that a vat number has been specified. |
| 218 | 218 | throw new Exception( |
| 219 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 219 | + __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing') |
|
| 220 | 220 | ); |
| 221 | 221 | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if ( empty( $vat_number ) ) { |
|
| 224 | + if (empty($vat_number)) { |
|
| 225 | 225 | return; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 229 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 228 | + if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
| 229 | + throw new Exception(__('Your VAT number is invalid', 'invoicing')); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 232 | + if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) { |
|
| 233 | 233 | return; |
| 234 | 234 | } |
| 235 | 235 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | - exit; |
|
| 12 | + exit; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -21,356 +21,356 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class GetPaid_Data { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * ID for this object. |
|
| 26 | - * |
|
| 27 | - * @since 1.0.19 |
|
| 28 | - * @var int |
|
| 29 | - */ |
|
| 30 | - protected $id = 0; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Core data for this object. Name value pairs (name + default value). |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Core data changes for this object. |
|
| 42 | - * |
|
| 43 | - * @since 1.0.19 |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $changes = array(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * This is false until the object is read from the DB. |
|
| 50 | - * |
|
| 51 | - * @since 1.0.19 |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 54 | - protected $object_read = false; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * This is the name of this object type. |
|
| 58 | - * |
|
| 59 | - * @since 1.0.19 |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - protected $object_type = 'data'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Extra data for this object. Name value pairs (name + default value). |
|
| 66 | - * Used as a standard way for sub classes (like item types) to add |
|
| 67 | - * additional information to an inherited class. |
|
| 68 | - * |
|
| 69 | - * @since 1.0.19 |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - protected $extra_data = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Set to _data on construct so we can track and reset data if needed. |
|
| 76 | - * |
|
| 77 | - * @since 1.0.19 |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - protected $default_data = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Contains a reference to the data store for this class. |
|
| 84 | - * |
|
| 85 | - * @since 1.0.19 |
|
| 86 | - * @var GetPaid_Data_Store |
|
| 87 | - */ |
|
| 88 | - protected $data_store; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Stores meta in cache for future reads. |
|
| 92 | - * A group must be set to to enable caching. |
|
| 93 | - * |
|
| 94 | - * @since 1.0.19 |
|
| 95 | - * @var string |
|
| 96 | - */ |
|
| 97 | - protected $cache_group = ''; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Stores the last error. |
|
| 101 | - * |
|
| 102 | - * @since 1.0.19 |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $last_error = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Stores additional meta data. |
|
| 109 | - * |
|
| 110 | - * @since 1.0.19 |
|
| 111 | - * @var array |
|
| 112 | - */ |
|
| 113 | - protected $meta_data = null; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Default constructor. |
|
| 117 | - * |
|
| 118 | - * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
| 119 | - */ |
|
| 120 | - public function __construct( $read = 0 ) { |
|
| 121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
| 122 | - $this->default_data = $this->data; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Only store the object ID to avoid serializing the data object instance. |
|
| 127 | - * |
|
| 128 | - * @return array |
|
| 129 | - */ |
|
| 130 | - public function __sleep() { |
|
| 131 | - return array( 'id' ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Re-run the constructor with the object ID. |
|
| 136 | - * |
|
| 137 | - * If the object no longer exists, remove the ID. |
|
| 138 | - */ |
|
| 139 | - public function __wakeup() { |
|
| 140 | - $this->__construct( absint( $this->id ) ); |
|
| 141 | - |
|
| 142 | - if ( ! empty( $this->last_error ) ) { |
|
| 143 | - $this->set_id( 0 ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * When the object is cloned, make sure meta is duplicated correctly. |
|
| 150 | - * |
|
| 151 | - * @since 1.0.19 |
|
| 152 | - */ |
|
| 153 | - public function __clone() { |
|
| 154 | - $this->maybe_read_meta_data(); |
|
| 155 | - if ( ! empty( $this->meta_data ) ) { |
|
| 156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
| 158 | - if ( ! empty( $meta->id ) ) { |
|
| 159 | - $this->meta_data[ $array_key ]->id = null; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Get the data store. |
|
| 167 | - * |
|
| 168 | - * @since 1.0.19 |
|
| 169 | - * @return object |
|
| 170 | - */ |
|
| 171 | - public function get_data_store() { |
|
| 172 | - return $this->data_store; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Get the object type. |
|
| 177 | - * |
|
| 178 | - * @since 1.0.19 |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function get_object_type() { |
|
| 182 | - return $this->object_type; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Returns the unique ID for this object. |
|
| 187 | - * |
|
| 188 | - * @since 1.0.19 |
|
| 189 | - * @return int |
|
| 190 | - */ |
|
| 191 | - public function get_id() { |
|
| 192 | - return $this->id; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Get form status. |
|
| 197 | - * |
|
| 198 | - * @since 1.0.19 |
|
| 199 | - * @param string $context View or edit context. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function get_status( $context = 'view' ) { |
|
| 203 | - return $this->get_prop( 'status', $context ); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Delete an object, set the ID to 0, and return result. |
|
| 208 | - * |
|
| 209 | - * @since 1.0.19 |
|
| 210 | - * @param bool $force_delete Should the data be deleted permanently. |
|
| 211 | - * @return bool result |
|
| 212 | - */ |
|
| 213 | - public function delete( $force_delete = false ) { |
|
| 214 | - if ( $this->data_store && $this->exists() ) { |
|
| 215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
| 216 | - $this->set_id( 0 ); |
|
| 217 | - return true; |
|
| 218 | - } |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Save should create or update based on object existence. |
|
| 224 | - * |
|
| 225 | - * @since 1.0.19 |
|
| 226 | - * @return int |
|
| 227 | - */ |
|
| 228 | - public function save() { |
|
| 229 | - if ( ! $this->data_store ) { |
|
| 230 | - return $this->get_id(); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
| 235 | - * |
|
| 236 | - * @param GetPaid_Data $this The object being saved. |
|
| 237 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 238 | - */ |
|
| 239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 240 | - |
|
| 241 | - if ( $this->get_id() ) { |
|
| 242 | - $this->data_store->update( $this ); |
|
| 243 | - } else { |
|
| 244 | - $this->data_store->create( $this ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Trigger action after saving to the DB. |
|
| 249 | - * |
|
| 250 | - * @param GetPaid_Data $this The object being saved. |
|
| 251 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 252 | - */ |
|
| 253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 254 | - |
|
| 255 | - return $this->get_id(); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Change data to JSON format. |
|
| 260 | - * |
|
| 261 | - * @since 1.0.19 |
|
| 262 | - * @return string Data in JSON format. |
|
| 263 | - */ |
|
| 264 | - public function __toString() { |
|
| 265 | - return wp_json_encode( $this->get_data() ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Returns all data for this object. |
|
| 270 | - * |
|
| 271 | - * @since 1.0.19 |
|
| 272 | - * @return array |
|
| 273 | - */ |
|
| 274 | - public function get_data() { |
|
| 275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Returns array of expected data keys for this object. |
|
| 280 | - * |
|
| 281 | - * @since 1.0.19 |
|
| 282 | - * @return array |
|
| 283 | - */ |
|
| 284 | - public function get_data_keys() { |
|
| 285 | - return array_keys( $this->data ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Returns all "extra" data keys for an object (for sub objects like item types). |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @return array |
|
| 293 | - */ |
|
| 294 | - public function get_extra_data_keys() { |
|
| 295 | - return array_keys( $this->extra_data ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Filter null meta values from array. |
|
| 300 | - * |
|
| 301 | - * @since 1.0.19 |
|
| 302 | - * @param mixed $meta Meta value to check. |
|
| 303 | - * @return bool |
|
| 304 | - */ |
|
| 305 | - protected function filter_null_meta( $meta ) { |
|
| 306 | - return ! is_null( $meta->value ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Get All Meta Data. |
|
| 311 | - * |
|
| 312 | - * @since 1.0.19 |
|
| 313 | - * @return array of objects. |
|
| 314 | - */ |
|
| 315 | - public function get_meta_data() { |
|
| 316 | - $this->maybe_read_meta_data(); |
|
| 317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Check if the key is an internal one. |
|
| 322 | - * |
|
| 323 | - * @since 1.0.19 |
|
| 324 | - * @param string $key Key to check. |
|
| 325 | - * @return bool true if it's an internal key, false otherwise |
|
| 326 | - */ |
|
| 327 | - protected function is_internal_meta_key( $key ) { |
|
| 328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
| 329 | - |
|
| 330 | - if ( ! $internal_meta_key ) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
| 335 | - |
|
| 336 | - if ( ! $has_setter_or_getter ) { |
|
| 337 | - return false; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /* translators: %s: $key Key to check */ |
|
| 341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 342 | - |
|
| 343 | - return true; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Magic method for setting data fields. |
|
| 348 | - * |
|
| 349 | - * This method does not update custom fields in the database. |
|
| 350 | - * |
|
| 351 | - * @since 1.0.19 |
|
| 352 | - * @access public |
|
| 353 | - * |
|
| 354 | - */ |
|
| 355 | - public function __set( $key, $value ) { |
|
| 356 | - |
|
| 357 | - if ( 'id' == strtolower( $key ) ) { |
|
| 358 | - return $this->set_id( $value ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if ( method_exists( $this, "set_$key") ) { |
|
| 362 | - |
|
| 363 | - /* translators: %s: $key Key to set */ |
|
| 364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 365 | - |
|
| 366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
| 367 | - } else { |
|
| 368 | - $this->set_prop( $key, $value ); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 24 | + /** |
|
| 25 | + * ID for this object. |
|
| 26 | + * |
|
| 27 | + * @since 1.0.19 |
|
| 28 | + * @var int |
|
| 29 | + */ |
|
| 30 | + protected $id = 0; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Core data for this object. Name value pairs (name + default value). |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Core data changes for this object. |
|
| 42 | + * |
|
| 43 | + * @since 1.0.19 |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $changes = array(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * This is false until the object is read from the DB. |
|
| 50 | + * |
|
| 51 | + * @since 1.0.19 |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | + protected $object_read = false; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * This is the name of this object type. |
|
| 58 | + * |
|
| 59 | + * @since 1.0.19 |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + protected $object_type = 'data'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Extra data for this object. Name value pairs (name + default value). |
|
| 66 | + * Used as a standard way for sub classes (like item types) to add |
|
| 67 | + * additional information to an inherited class. |
|
| 68 | + * |
|
| 69 | + * @since 1.0.19 |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + protected $extra_data = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Set to _data on construct so we can track and reset data if needed. |
|
| 76 | + * |
|
| 77 | + * @since 1.0.19 |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + protected $default_data = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Contains a reference to the data store for this class. |
|
| 84 | + * |
|
| 85 | + * @since 1.0.19 |
|
| 86 | + * @var GetPaid_Data_Store |
|
| 87 | + */ |
|
| 88 | + protected $data_store; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Stores meta in cache for future reads. |
|
| 92 | + * A group must be set to to enable caching. |
|
| 93 | + * |
|
| 94 | + * @since 1.0.19 |
|
| 95 | + * @var string |
|
| 96 | + */ |
|
| 97 | + protected $cache_group = ''; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Stores the last error. |
|
| 101 | + * |
|
| 102 | + * @since 1.0.19 |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $last_error = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Stores additional meta data. |
|
| 109 | + * |
|
| 110 | + * @since 1.0.19 |
|
| 111 | + * @var array |
|
| 112 | + */ |
|
| 113 | + protected $meta_data = null; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Default constructor. |
|
| 117 | + * |
|
| 118 | + * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
| 119 | + */ |
|
| 120 | + public function __construct( $read = 0 ) { |
|
| 121 | + $this->data = array_merge( $this->data, $this->extra_data ); |
|
| 122 | + $this->default_data = $this->data; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Only store the object ID to avoid serializing the data object instance. |
|
| 127 | + * |
|
| 128 | + * @return array |
|
| 129 | + */ |
|
| 130 | + public function __sleep() { |
|
| 131 | + return array( 'id' ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Re-run the constructor with the object ID. |
|
| 136 | + * |
|
| 137 | + * If the object no longer exists, remove the ID. |
|
| 138 | + */ |
|
| 139 | + public function __wakeup() { |
|
| 140 | + $this->__construct( absint( $this->id ) ); |
|
| 141 | + |
|
| 142 | + if ( ! empty( $this->last_error ) ) { |
|
| 143 | + $this->set_id( 0 ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * When the object is cloned, make sure meta is duplicated correctly. |
|
| 150 | + * |
|
| 151 | + * @since 1.0.19 |
|
| 152 | + */ |
|
| 153 | + public function __clone() { |
|
| 154 | + $this->maybe_read_meta_data(); |
|
| 155 | + if ( ! empty( $this->meta_data ) ) { |
|
| 156 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 157 | + $this->meta_data[ $array_key ] = clone $meta; |
|
| 158 | + if ( ! empty( $meta->id ) ) { |
|
| 159 | + $this->meta_data[ $array_key ]->id = null; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Get the data store. |
|
| 167 | + * |
|
| 168 | + * @since 1.0.19 |
|
| 169 | + * @return object |
|
| 170 | + */ |
|
| 171 | + public function get_data_store() { |
|
| 172 | + return $this->data_store; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Get the object type. |
|
| 177 | + * |
|
| 178 | + * @since 1.0.19 |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function get_object_type() { |
|
| 182 | + return $this->object_type; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Returns the unique ID for this object. |
|
| 187 | + * |
|
| 188 | + * @since 1.0.19 |
|
| 189 | + * @return int |
|
| 190 | + */ |
|
| 191 | + public function get_id() { |
|
| 192 | + return $this->id; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Get form status. |
|
| 197 | + * |
|
| 198 | + * @since 1.0.19 |
|
| 199 | + * @param string $context View or edit context. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function get_status( $context = 'view' ) { |
|
| 203 | + return $this->get_prop( 'status', $context ); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Delete an object, set the ID to 0, and return result. |
|
| 208 | + * |
|
| 209 | + * @since 1.0.19 |
|
| 210 | + * @param bool $force_delete Should the data be deleted permanently. |
|
| 211 | + * @return bool result |
|
| 212 | + */ |
|
| 213 | + public function delete( $force_delete = false ) { |
|
| 214 | + if ( $this->data_store && $this->exists() ) { |
|
| 215 | + $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
| 216 | + $this->set_id( 0 ); |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Save should create or update based on object existence. |
|
| 224 | + * |
|
| 225 | + * @since 1.0.19 |
|
| 226 | + * @return int |
|
| 227 | + */ |
|
| 228 | + public function save() { |
|
| 229 | + if ( ! $this->data_store ) { |
|
| 230 | + return $this->get_id(); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
| 235 | + * |
|
| 236 | + * @param GetPaid_Data $this The object being saved. |
|
| 237 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 238 | + */ |
|
| 239 | + do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 240 | + |
|
| 241 | + if ( $this->get_id() ) { |
|
| 242 | + $this->data_store->update( $this ); |
|
| 243 | + } else { |
|
| 244 | + $this->data_store->create( $this ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Trigger action after saving to the DB. |
|
| 249 | + * |
|
| 250 | + * @param GetPaid_Data $this The object being saved. |
|
| 251 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 252 | + */ |
|
| 253 | + do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 254 | + |
|
| 255 | + return $this->get_id(); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Change data to JSON format. |
|
| 260 | + * |
|
| 261 | + * @since 1.0.19 |
|
| 262 | + * @return string Data in JSON format. |
|
| 263 | + */ |
|
| 264 | + public function __toString() { |
|
| 265 | + return wp_json_encode( $this->get_data() ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Returns all data for this object. |
|
| 270 | + * |
|
| 271 | + * @since 1.0.19 |
|
| 272 | + * @return array |
|
| 273 | + */ |
|
| 274 | + public function get_data() { |
|
| 275 | + return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Returns array of expected data keys for this object. |
|
| 280 | + * |
|
| 281 | + * @since 1.0.19 |
|
| 282 | + * @return array |
|
| 283 | + */ |
|
| 284 | + public function get_data_keys() { |
|
| 285 | + return array_keys( $this->data ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Returns all "extra" data keys for an object (for sub objects like item types). |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @return array |
|
| 293 | + */ |
|
| 294 | + public function get_extra_data_keys() { |
|
| 295 | + return array_keys( $this->extra_data ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Filter null meta values from array. |
|
| 300 | + * |
|
| 301 | + * @since 1.0.19 |
|
| 302 | + * @param mixed $meta Meta value to check. |
|
| 303 | + * @return bool |
|
| 304 | + */ |
|
| 305 | + protected function filter_null_meta( $meta ) { |
|
| 306 | + return ! is_null( $meta->value ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Get All Meta Data. |
|
| 311 | + * |
|
| 312 | + * @since 1.0.19 |
|
| 313 | + * @return array of objects. |
|
| 314 | + */ |
|
| 315 | + public function get_meta_data() { |
|
| 316 | + $this->maybe_read_meta_data(); |
|
| 317 | + return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Check if the key is an internal one. |
|
| 322 | + * |
|
| 323 | + * @since 1.0.19 |
|
| 324 | + * @param string $key Key to check. |
|
| 325 | + * @return bool true if it's an internal key, false otherwise |
|
| 326 | + */ |
|
| 327 | + protected function is_internal_meta_key( $key ) { |
|
| 328 | + $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
| 329 | + |
|
| 330 | + if ( ! $internal_meta_key ) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
| 335 | + |
|
| 336 | + if ( ! $has_setter_or_getter ) { |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /* translators: %s: $key Key to check */ |
|
| 341 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 342 | + |
|
| 343 | + return true; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Magic method for setting data fields. |
|
| 348 | + * |
|
| 349 | + * This method does not update custom fields in the database. |
|
| 350 | + * |
|
| 351 | + * @since 1.0.19 |
|
| 352 | + * @access public |
|
| 353 | + * |
|
| 354 | + */ |
|
| 355 | + public function __set( $key, $value ) { |
|
| 356 | + |
|
| 357 | + if ( 'id' == strtolower( $key ) ) { |
|
| 358 | + return $this->set_id( $value ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if ( method_exists( $this, "set_$key") ) { |
|
| 362 | + |
|
| 363 | + /* translators: %s: $key Key to set */ |
|
| 364 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 365 | + |
|
| 366 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
| 367 | + } else { |
|
| 368 | + $this->set_prop( $key, $value ); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | 374 | * Margic method for retrieving a property. |
| 375 | 375 | */ |
| 376 | 376 | public function __get( $key ) { |
@@ -378,10 +378,10 @@ discard block |
||
| 378 | 378 | // Check if we have a helper method for that. |
| 379 | 379 | if ( method_exists( $this, 'get_' . $key ) ) { |
| 380 | 380 | |
| 381 | - if ( 'post_type' != $key ) { |
|
| 382 | - /* translators: %s: $key Key to set */ |
|
| 383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 384 | - } |
|
| 381 | + if ( 'post_type' != $key ) { |
|
| 382 | + /* translators: %s: $key Key to set */ |
|
| 383 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | 386 | return call_user_func( array( $this, 'get_' . $key ) ); |
| 387 | 387 | } |
@@ -391,514 +391,514 @@ discard block |
||
| 391 | 391 | return $this->post->$key; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - return $this->get_prop( $key ); |
|
| 395 | - |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Get Meta Data by Key. |
|
| 400 | - * |
|
| 401 | - * @since 1.0.19 |
|
| 402 | - * @param string $key Meta Key. |
|
| 403 | - * @param bool $single return first found meta with key, or all with $key. |
|
| 404 | - * @param string $context What the value is for. Valid values are view and edit. |
|
| 405 | - * @return mixed |
|
| 406 | - */ |
|
| 407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
| 408 | - |
|
| 409 | - // Check if this is an internal meta key. |
|
| 410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
| 411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
| 412 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 413 | - $function = 'get_' . $_key; |
|
| 414 | - |
|
| 415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 416 | - return $this->{$function}(); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - // Read the meta data if not yet read. |
|
| 421 | - $this->maybe_read_meta_data(); |
|
| 422 | - $meta_data = $this->get_meta_data(); |
|
| 423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
| 424 | - $value = $single ? '' : array(); |
|
| 425 | - |
|
| 426 | - if ( ! empty( $array_keys ) ) { |
|
| 427 | - // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
| 428 | - if ( $single ) { |
|
| 429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
| 430 | - } else { |
|
| 431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - if ( 'view' === $context ) { |
|
| 436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - return $value; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
| 444 | - * |
|
| 445 | - * @since 1.0.19 |
|
| 446 | - * @param string $key Meta Key. |
|
| 447 | - * @return boolean |
|
| 448 | - */ |
|
| 449 | - public function meta_exists( $key = '' ) { |
|
| 450 | - $this->maybe_read_meta_data(); |
|
| 451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
| 452 | - return in_array( $key, $array_keys, true ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Set all meta data from array. |
|
| 457 | - * |
|
| 458 | - * @since 1.0.19 |
|
| 459 | - * @param array $data Key/Value pairs. |
|
| 460 | - */ |
|
| 461 | - public function set_meta_data( $data ) { |
|
| 462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
| 463 | - $this->maybe_read_meta_data(); |
|
| 464 | - foreach ( $data as $meta ) { |
|
| 465 | - $meta = (array) $meta; |
|
| 466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
| 467 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 468 | - array( |
|
| 469 | - 'id' => $meta['id'], |
|
| 470 | - 'key' => $meta['key'], |
|
| 471 | - 'value' => $meta['value'], |
|
| 472 | - ) |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Add meta data. |
|
| 481 | - * |
|
| 482 | - * @since 1.0.19 |
|
| 483 | - * |
|
| 484 | - * @param string $key Meta key. |
|
| 485 | - * @param string|array $value Meta value. |
|
| 486 | - * @param bool $unique Should this be a unique key?. |
|
| 487 | - */ |
|
| 488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
| 489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 490 | - $function = 'set_' . $key; |
|
| 491 | - |
|
| 492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 493 | - return $this->{$function}( $value ); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - $this->maybe_read_meta_data(); |
|
| 498 | - if ( $unique ) { |
|
| 499 | - $this->delete_meta_data( $key ); |
|
| 500 | - } |
|
| 501 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 502 | - array( |
|
| 503 | - 'key' => $key, |
|
| 504 | - 'value' => $value, |
|
| 505 | - ) |
|
| 506 | - ); |
|
| 507 | - |
|
| 508 | - $this->save(); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Update meta data by key or ID, if provided. |
|
| 513 | - * |
|
| 514 | - * @since 1.0.19 |
|
| 515 | - * |
|
| 516 | - * @param string $key Meta key. |
|
| 517 | - * @param string|array $value Meta value. |
|
| 518 | - * @param int $meta_id Meta ID. |
|
| 519 | - */ |
|
| 520 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
| 521 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 522 | - $function = 'set_' . $key; |
|
| 523 | - |
|
| 524 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 525 | - return $this->{$function}( $value ); |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - $this->maybe_read_meta_data(); |
|
| 530 | - |
|
| 531 | - $array_key = false; |
|
| 532 | - |
|
| 533 | - if ( $meta_id ) { |
|
| 534 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
| 535 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
| 536 | - } else { |
|
| 537 | - // Find matches by key. |
|
| 538 | - $matches = array(); |
|
| 539 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
| 540 | - if ( $meta->key === $key ) { |
|
| 541 | - $matches[] = $meta_data_array_key; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if ( ! empty( $matches ) ) { |
|
| 546 | - // Set matches to null so only one key gets the new value. |
|
| 547 | - foreach ( $matches as $meta_data_array_key ) { |
|
| 548 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
| 549 | - } |
|
| 550 | - $array_key = current( $matches ); |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - if ( false !== $array_key ) { |
|
| 555 | - $meta = $this->meta_data[ $array_key ]; |
|
| 556 | - $meta->key = $key; |
|
| 557 | - $meta->value = $value; |
|
| 558 | - } else { |
|
| 559 | - $this->add_meta_data( $key, $value, true ); |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Delete meta data. |
|
| 565 | - * |
|
| 566 | - * @since 1.0.19 |
|
| 567 | - * @param string $key Meta key. |
|
| 568 | - */ |
|
| 569 | - public function delete_meta_data( $key ) { |
|
| 570 | - $this->maybe_read_meta_data(); |
|
| 571 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
| 572 | - |
|
| 573 | - if ( $array_keys ) { |
|
| 574 | - foreach ( $array_keys as $array_key ) { |
|
| 575 | - $this->meta_data[ $array_key ]->value = null; |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Delete meta data. |
|
| 582 | - * |
|
| 583 | - * @since 1.0.19 |
|
| 584 | - * @param int $mid Meta ID. |
|
| 585 | - */ |
|
| 586 | - public function delete_meta_data_by_mid( $mid ) { |
|
| 587 | - $this->maybe_read_meta_data(); |
|
| 588 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
| 589 | - |
|
| 590 | - if ( $array_keys ) { |
|
| 591 | - foreach ( $array_keys as $array_key ) { |
|
| 592 | - $this->meta_data[ $array_key ]->value = null; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Read meta data if null. |
|
| 599 | - * |
|
| 600 | - * @since 1.0.19 |
|
| 601 | - */ |
|
| 602 | - protected function maybe_read_meta_data() { |
|
| 603 | - if ( is_null( $this->meta_data ) ) { |
|
| 604 | - $this->read_meta_data(); |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Read Meta Data from the database. Ignore any internal properties. |
|
| 610 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
| 611 | - * |
|
| 612 | - * @since 1.0.19 |
|
| 613 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
| 614 | - */ |
|
| 615 | - public function read_meta_data( $force_read = false ) { |
|
| 616 | - |
|
| 617 | - // Reset meta data. |
|
| 618 | - $this->meta_data = array(); |
|
| 619 | - |
|
| 620 | - // Maybe abort early. |
|
| 621 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
| 622 | - return; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - // Only read from cache if the cache key is set. |
|
| 626 | - $cache_key = null; |
|
| 627 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
| 628 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 629 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - // Should we force read? |
|
| 633 | - if ( empty( $raw_meta_data ) ) { |
|
| 634 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
| 635 | - |
|
| 636 | - if ( ! empty( $cache_key ) ) { |
|
| 637 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - // Set meta data. |
|
| 643 | - if ( is_array( $raw_meta_data ) ) { |
|
| 644 | - |
|
| 645 | - foreach ( $raw_meta_data as $meta ) { |
|
| 646 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 647 | - array( |
|
| 648 | - 'id' => (int) $meta->meta_id, |
|
| 649 | - 'key' => $meta->meta_key, |
|
| 650 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
| 651 | - ) |
|
| 652 | - ); |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Update Meta Data in the database. |
|
| 661 | - * |
|
| 662 | - * @since 1.0.19 |
|
| 663 | - */ |
|
| 664 | - public function save_meta_data() { |
|
| 665 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
| 666 | - return; |
|
| 667 | - } |
|
| 668 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 669 | - if ( is_null( $meta->value ) ) { |
|
| 670 | - if ( ! empty( $meta->id ) ) { |
|
| 671 | - $this->data_store->delete_meta( $this, $meta ); |
|
| 672 | - unset( $this->meta_data[ $array_key ] ); |
|
| 673 | - } |
|
| 674 | - } elseif ( empty( $meta->id ) ) { |
|
| 675 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
| 676 | - $meta->apply_changes(); |
|
| 677 | - } else { |
|
| 678 | - if ( $meta->get_changes() ) { |
|
| 679 | - $this->data_store->update_meta( $this, $meta ); |
|
| 680 | - $meta->apply_changes(); |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - if ( ! empty( $this->cache_group ) ) { |
|
| 685 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 686 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * Set ID. |
|
| 692 | - * |
|
| 693 | - * @since 1.0.19 |
|
| 694 | - * @param int $id ID. |
|
| 695 | - */ |
|
| 696 | - public function set_id( $id ) { |
|
| 697 | - $this->id = absint( $id ); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Sets item status. |
|
| 702 | - * |
|
| 703 | - * @since 1.0.19 |
|
| 704 | - * @param string $status New status. |
|
| 705 | - * @return array details of change. |
|
| 706 | - */ |
|
| 707 | - public function set_status( $status ) { |
|
| 394 | + return $this->get_prop( $key ); |
|
| 395 | + |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Get Meta Data by Key. |
|
| 400 | + * |
|
| 401 | + * @since 1.0.19 |
|
| 402 | + * @param string $key Meta Key. |
|
| 403 | + * @param bool $single return first found meta with key, or all with $key. |
|
| 404 | + * @param string $context What the value is for. Valid values are view and edit. |
|
| 405 | + * @return mixed |
|
| 406 | + */ |
|
| 407 | + public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
| 408 | + |
|
| 409 | + // Check if this is an internal meta key. |
|
| 410 | + $_key = str_replace( '_wpinv', '', $key ); |
|
| 411 | + $_key = str_replace( 'wpinv', '', $_key ); |
|
| 412 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
| 413 | + $function = 'get_' . $_key; |
|
| 414 | + |
|
| 415 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 416 | + return $this->{$function}(); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + // Read the meta data if not yet read. |
|
| 421 | + $this->maybe_read_meta_data(); |
|
| 422 | + $meta_data = $this->get_meta_data(); |
|
| 423 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
| 424 | + $value = $single ? '' : array(); |
|
| 425 | + |
|
| 426 | + if ( ! empty( $array_keys ) ) { |
|
| 427 | + // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
| 428 | + if ( $single ) { |
|
| 429 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
| 430 | + } else { |
|
| 431 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + if ( 'view' === $context ) { |
|
| 436 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + return $value; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
| 444 | + * |
|
| 445 | + * @since 1.0.19 |
|
| 446 | + * @param string $key Meta Key. |
|
| 447 | + * @return boolean |
|
| 448 | + */ |
|
| 449 | + public function meta_exists( $key = '' ) { |
|
| 450 | + $this->maybe_read_meta_data(); |
|
| 451 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
| 452 | + return in_array( $key, $array_keys, true ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Set all meta data from array. |
|
| 457 | + * |
|
| 458 | + * @since 1.0.19 |
|
| 459 | + * @param array $data Key/Value pairs. |
|
| 460 | + */ |
|
| 461 | + public function set_meta_data( $data ) { |
|
| 462 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
| 463 | + $this->maybe_read_meta_data(); |
|
| 464 | + foreach ( $data as $meta ) { |
|
| 465 | + $meta = (array) $meta; |
|
| 466 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
| 467 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 468 | + array( |
|
| 469 | + 'id' => $meta['id'], |
|
| 470 | + 'key' => $meta['key'], |
|
| 471 | + 'value' => $meta['value'], |
|
| 472 | + ) |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Add meta data. |
|
| 481 | + * |
|
| 482 | + * @since 1.0.19 |
|
| 483 | + * |
|
| 484 | + * @param string $key Meta key. |
|
| 485 | + * @param string|array $value Meta value. |
|
| 486 | + * @param bool $unique Should this be a unique key?. |
|
| 487 | + */ |
|
| 488 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
| 489 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
| 490 | + $function = 'set_' . $key; |
|
| 491 | + |
|
| 492 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 493 | + return $this->{$function}( $value ); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + $this->maybe_read_meta_data(); |
|
| 498 | + if ( $unique ) { |
|
| 499 | + $this->delete_meta_data( $key ); |
|
| 500 | + } |
|
| 501 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 502 | + array( |
|
| 503 | + 'key' => $key, |
|
| 504 | + 'value' => $value, |
|
| 505 | + ) |
|
| 506 | + ); |
|
| 507 | + |
|
| 508 | + $this->save(); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Update meta data by key or ID, if provided. |
|
| 513 | + * |
|
| 514 | + * @since 1.0.19 |
|
| 515 | + * |
|
| 516 | + * @param string $key Meta key. |
|
| 517 | + * @param string|array $value Meta value. |
|
| 518 | + * @param int $meta_id Meta ID. |
|
| 519 | + */ |
|
| 520 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
| 521 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
| 522 | + $function = 'set_' . $key; |
|
| 523 | + |
|
| 524 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 525 | + return $this->{$function}( $value ); |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + $this->maybe_read_meta_data(); |
|
| 530 | + |
|
| 531 | + $array_key = false; |
|
| 532 | + |
|
| 533 | + if ( $meta_id ) { |
|
| 534 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
| 535 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
| 536 | + } else { |
|
| 537 | + // Find matches by key. |
|
| 538 | + $matches = array(); |
|
| 539 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
| 540 | + if ( $meta->key === $key ) { |
|
| 541 | + $matches[] = $meta_data_array_key; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + if ( ! empty( $matches ) ) { |
|
| 546 | + // Set matches to null so only one key gets the new value. |
|
| 547 | + foreach ( $matches as $meta_data_array_key ) { |
|
| 548 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
| 549 | + } |
|
| 550 | + $array_key = current( $matches ); |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + if ( false !== $array_key ) { |
|
| 555 | + $meta = $this->meta_data[ $array_key ]; |
|
| 556 | + $meta->key = $key; |
|
| 557 | + $meta->value = $value; |
|
| 558 | + } else { |
|
| 559 | + $this->add_meta_data( $key, $value, true ); |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Delete meta data. |
|
| 565 | + * |
|
| 566 | + * @since 1.0.19 |
|
| 567 | + * @param string $key Meta key. |
|
| 568 | + */ |
|
| 569 | + public function delete_meta_data( $key ) { |
|
| 570 | + $this->maybe_read_meta_data(); |
|
| 571 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
| 572 | + |
|
| 573 | + if ( $array_keys ) { |
|
| 574 | + foreach ( $array_keys as $array_key ) { |
|
| 575 | + $this->meta_data[ $array_key ]->value = null; |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Delete meta data. |
|
| 582 | + * |
|
| 583 | + * @since 1.0.19 |
|
| 584 | + * @param int $mid Meta ID. |
|
| 585 | + */ |
|
| 586 | + public function delete_meta_data_by_mid( $mid ) { |
|
| 587 | + $this->maybe_read_meta_data(); |
|
| 588 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
| 589 | + |
|
| 590 | + if ( $array_keys ) { |
|
| 591 | + foreach ( $array_keys as $array_key ) { |
|
| 592 | + $this->meta_data[ $array_key ]->value = null; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Read meta data if null. |
|
| 599 | + * |
|
| 600 | + * @since 1.0.19 |
|
| 601 | + */ |
|
| 602 | + protected function maybe_read_meta_data() { |
|
| 603 | + if ( is_null( $this->meta_data ) ) { |
|
| 604 | + $this->read_meta_data(); |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Read Meta Data from the database. Ignore any internal properties. |
|
| 610 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
| 611 | + * |
|
| 612 | + * @since 1.0.19 |
|
| 613 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
| 614 | + */ |
|
| 615 | + public function read_meta_data( $force_read = false ) { |
|
| 616 | + |
|
| 617 | + // Reset meta data. |
|
| 618 | + $this->meta_data = array(); |
|
| 619 | + |
|
| 620 | + // Maybe abort early. |
|
| 621 | + if ( ! $this->get_id() || ! $this->data_store ) { |
|
| 622 | + return; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + // Only read from cache if the cache key is set. |
|
| 626 | + $cache_key = null; |
|
| 627 | + if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
| 628 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 629 | + $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + // Should we force read? |
|
| 633 | + if ( empty( $raw_meta_data ) ) { |
|
| 634 | + $raw_meta_data = $this->data_store->read_meta( $this ); |
|
| 635 | + |
|
| 636 | + if ( ! empty( $cache_key ) ) { |
|
| 637 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + // Set meta data. |
|
| 643 | + if ( is_array( $raw_meta_data ) ) { |
|
| 644 | + |
|
| 645 | + foreach ( $raw_meta_data as $meta ) { |
|
| 646 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 647 | + array( |
|
| 648 | + 'id' => (int) $meta->meta_id, |
|
| 649 | + 'key' => $meta->meta_key, |
|
| 650 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
| 651 | + ) |
|
| 652 | + ); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Update Meta Data in the database. |
|
| 661 | + * |
|
| 662 | + * @since 1.0.19 |
|
| 663 | + */ |
|
| 664 | + public function save_meta_data() { |
|
| 665 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
| 666 | + return; |
|
| 667 | + } |
|
| 668 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 669 | + if ( is_null( $meta->value ) ) { |
|
| 670 | + if ( ! empty( $meta->id ) ) { |
|
| 671 | + $this->data_store->delete_meta( $this, $meta ); |
|
| 672 | + unset( $this->meta_data[ $array_key ] ); |
|
| 673 | + } |
|
| 674 | + } elseif ( empty( $meta->id ) ) { |
|
| 675 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
| 676 | + $meta->apply_changes(); |
|
| 677 | + } else { |
|
| 678 | + if ( $meta->get_changes() ) { |
|
| 679 | + $this->data_store->update_meta( $this, $meta ); |
|
| 680 | + $meta->apply_changes(); |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + if ( ! empty( $this->cache_group ) ) { |
|
| 685 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 686 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * Set ID. |
|
| 692 | + * |
|
| 693 | + * @since 1.0.19 |
|
| 694 | + * @param int $id ID. |
|
| 695 | + */ |
|
| 696 | + public function set_id( $id ) { |
|
| 697 | + $this->id = absint( $id ); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Sets item status. |
|
| 702 | + * |
|
| 703 | + * @since 1.0.19 |
|
| 704 | + * @param string $status New status. |
|
| 705 | + * @return array details of change. |
|
| 706 | + */ |
|
| 707 | + public function set_status( $status ) { |
|
| 708 | 708 | $old_status = $this->get_status(); |
| 709 | 709 | |
| 710 | - $this->set_prop( 'status', $status ); |
|
| 711 | - |
|
| 712 | - return array( |
|
| 713 | - 'from' => $old_status, |
|
| 714 | - 'to' => $status, |
|
| 715 | - ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Set all props to default values. |
|
| 720 | - * |
|
| 721 | - * @since 1.0.19 |
|
| 722 | - */ |
|
| 723 | - public function set_defaults() { |
|
| 724 | - $this->data = $this->default_data; |
|
| 725 | - $this->changes = array(); |
|
| 726 | - $this->set_object_read( false ); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Set object read property. |
|
| 731 | - * |
|
| 732 | - * @since 1.0.19 |
|
| 733 | - * @param boolean $read Should read?. |
|
| 734 | - */ |
|
| 735 | - public function set_object_read( $read = true ) { |
|
| 736 | - $this->object_read = (bool) $read; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * Get object read property. |
|
| 741 | - * |
|
| 742 | - * @since 1.0.19 |
|
| 743 | - * @return boolean |
|
| 744 | - */ |
|
| 745 | - public function get_object_read() { |
|
| 746 | - return (bool) $this->object_read; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
| 751 | - * Only sets using public methods. |
|
| 752 | - * |
|
| 753 | - * @since 1.0.19 |
|
| 754 | - * |
|
| 755 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
| 756 | - * @param string $context In what context to run this. |
|
| 757 | - * |
|
| 758 | - * @return bool|WP_Error |
|
| 759 | - */ |
|
| 760 | - public function set_props( $props, $context = 'set' ) { |
|
| 761 | - $errors = false; |
|
| 762 | - |
|
| 763 | - foreach ( $props as $prop => $value ) { |
|
| 764 | - try { |
|
| 765 | - /** |
|
| 766 | - * Checks if the prop being set is allowed, and the value is not null. |
|
| 767 | - */ |
|
| 768 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
| 769 | - continue; |
|
| 770 | - } |
|
| 771 | - $setter = "set_$prop"; |
|
| 772 | - |
|
| 773 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
| 774 | - $this->{$setter}( $value ); |
|
| 775 | - } |
|
| 776 | - } catch ( Exception $e ) { |
|
| 777 | - if ( ! $errors ) { |
|
| 778 | - $errors = new WP_Error(); |
|
| 779 | - } |
|
| 780 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
| 781 | - $this->last_error = $e->getMessage(); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * Sets a prop for a setter method. |
|
| 790 | - * |
|
| 791 | - * This stores changes in a special array so we can track what needs saving |
|
| 792 | - * the the DB later. |
|
| 793 | - * |
|
| 794 | - * @since 1.0.19 |
|
| 795 | - * @param string $prop Name of prop to set. |
|
| 796 | - * @param mixed $value Value of the prop. |
|
| 797 | - */ |
|
| 798 | - protected function set_prop( $prop, $value ) { |
|
| 799 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 800 | - if ( true === $this->object_read ) { |
|
| 801 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
| 802 | - $this->changes[ $prop ] = $value; |
|
| 803 | - } |
|
| 804 | - } else { |
|
| 805 | - $this->data[ $prop ] = $value; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - /** |
|
| 811 | - * Return data changes only. |
|
| 812 | - * |
|
| 813 | - * @since 1.0.19 |
|
| 814 | - * @return array |
|
| 815 | - */ |
|
| 816 | - public function get_changes() { |
|
| 817 | - return $this->changes; |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Merge changes with data and clear. |
|
| 822 | - * |
|
| 823 | - * @since 1.0.19 |
|
| 824 | - */ |
|
| 825 | - public function apply_changes() { |
|
| 826 | - $this->data = array_replace( $this->data, $this->changes ); |
|
| 827 | - $this->changes = array(); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * Prefix for action and filter hooks on data. |
|
| 832 | - * |
|
| 833 | - * @since 1.0.19 |
|
| 834 | - * @return string |
|
| 835 | - */ |
|
| 836 | - protected function get_hook_prefix() { |
|
| 837 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Gets a prop for a getter method. |
|
| 842 | - * |
|
| 843 | - * Gets the value from either current pending changes, or the data itself. |
|
| 844 | - * Context controls what happens to the value before it's returned. |
|
| 845 | - * |
|
| 846 | - * @since 1.0.19 |
|
| 847 | - * @param string $prop Name of prop to get. |
|
| 848 | - * @param string $context What the value is for. Valid values are view and edit. |
|
| 849 | - * @return mixed |
|
| 850 | - */ |
|
| 851 | - protected function get_prop( $prop, $context = 'view' ) { |
|
| 852 | - $value = null; |
|
| 853 | - |
|
| 854 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 855 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
| 856 | - |
|
| 857 | - if ( 'view' === $context ) { |
|
| 858 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - return $value; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
| 867 | - * |
|
| 868 | - * @since 1.0.19 |
|
| 869 | - * @param string $prop Name of prop to set. |
|
| 870 | - * @param string|integer $value Value of the prop. |
|
| 871 | - */ |
|
| 872 | - protected function set_date_prop( $prop, $value ) { |
|
| 873 | - |
|
| 874 | - if ( empty( $value ) ) { |
|
| 875 | - $this->set_prop( $prop, null ); |
|
| 876 | - return; |
|
| 877 | - } |
|
| 878 | - $this->set_prop( $prop, $value ); |
|
| 879 | - |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
| 884 | - * |
|
| 885 | - * @since 1.0.19 |
|
| 886 | - * @param string $code Error code. |
|
| 887 | - * @param string $message Error message. |
|
| 888 | - */ |
|
| 889 | - protected function error( $code, $message ) { |
|
| 890 | - $this->last_error = $message; |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - /** |
|
| 894 | - * Checks if the object is saved in the database |
|
| 895 | - * |
|
| 896 | - * @since 1.0.19 |
|
| 897 | - * @return bool |
|
| 898 | - */ |
|
| 899 | - public function exists() { |
|
| 900 | - $id = $this->get_id(); |
|
| 901 | - return ! empty( $id ); |
|
| 902 | - } |
|
| 710 | + $this->set_prop( 'status', $status ); |
|
| 711 | + |
|
| 712 | + return array( |
|
| 713 | + 'from' => $old_status, |
|
| 714 | + 'to' => $status, |
|
| 715 | + ); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Set all props to default values. |
|
| 720 | + * |
|
| 721 | + * @since 1.0.19 |
|
| 722 | + */ |
|
| 723 | + public function set_defaults() { |
|
| 724 | + $this->data = $this->default_data; |
|
| 725 | + $this->changes = array(); |
|
| 726 | + $this->set_object_read( false ); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * Set object read property. |
|
| 731 | + * |
|
| 732 | + * @since 1.0.19 |
|
| 733 | + * @param boolean $read Should read?. |
|
| 734 | + */ |
|
| 735 | + public function set_object_read( $read = true ) { |
|
| 736 | + $this->object_read = (bool) $read; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * Get object read property. |
|
| 741 | + * |
|
| 742 | + * @since 1.0.19 |
|
| 743 | + * @return boolean |
|
| 744 | + */ |
|
| 745 | + public function get_object_read() { |
|
| 746 | + return (bool) $this->object_read; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
| 751 | + * Only sets using public methods. |
|
| 752 | + * |
|
| 753 | + * @since 1.0.19 |
|
| 754 | + * |
|
| 755 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
| 756 | + * @param string $context In what context to run this. |
|
| 757 | + * |
|
| 758 | + * @return bool|WP_Error |
|
| 759 | + */ |
|
| 760 | + public function set_props( $props, $context = 'set' ) { |
|
| 761 | + $errors = false; |
|
| 762 | + |
|
| 763 | + foreach ( $props as $prop => $value ) { |
|
| 764 | + try { |
|
| 765 | + /** |
|
| 766 | + * Checks if the prop being set is allowed, and the value is not null. |
|
| 767 | + */ |
|
| 768 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
| 769 | + continue; |
|
| 770 | + } |
|
| 771 | + $setter = "set_$prop"; |
|
| 772 | + |
|
| 773 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
| 774 | + $this->{$setter}( $value ); |
|
| 775 | + } |
|
| 776 | + } catch ( Exception $e ) { |
|
| 777 | + if ( ! $errors ) { |
|
| 778 | + $errors = new WP_Error(); |
|
| 779 | + } |
|
| 780 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
| 781 | + $this->last_error = $e->getMessage(); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * Sets a prop for a setter method. |
|
| 790 | + * |
|
| 791 | + * This stores changes in a special array so we can track what needs saving |
|
| 792 | + * the the DB later. |
|
| 793 | + * |
|
| 794 | + * @since 1.0.19 |
|
| 795 | + * @param string $prop Name of prop to set. |
|
| 796 | + * @param mixed $value Value of the prop. |
|
| 797 | + */ |
|
| 798 | + protected function set_prop( $prop, $value ) { |
|
| 799 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
| 800 | + if ( true === $this->object_read ) { |
|
| 801 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
| 802 | + $this->changes[ $prop ] = $value; |
|
| 803 | + } |
|
| 804 | + } else { |
|
| 805 | + $this->data[ $prop ] = $value; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + /** |
|
| 811 | + * Return data changes only. |
|
| 812 | + * |
|
| 813 | + * @since 1.0.19 |
|
| 814 | + * @return array |
|
| 815 | + */ |
|
| 816 | + public function get_changes() { |
|
| 817 | + return $this->changes; |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Merge changes with data and clear. |
|
| 822 | + * |
|
| 823 | + * @since 1.0.19 |
|
| 824 | + */ |
|
| 825 | + public function apply_changes() { |
|
| 826 | + $this->data = array_replace( $this->data, $this->changes ); |
|
| 827 | + $this->changes = array(); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * Prefix for action and filter hooks on data. |
|
| 832 | + * |
|
| 833 | + * @since 1.0.19 |
|
| 834 | + * @return string |
|
| 835 | + */ |
|
| 836 | + protected function get_hook_prefix() { |
|
| 837 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Gets a prop for a getter method. |
|
| 842 | + * |
|
| 843 | + * Gets the value from either current pending changes, or the data itself. |
|
| 844 | + * Context controls what happens to the value before it's returned. |
|
| 845 | + * |
|
| 846 | + * @since 1.0.19 |
|
| 847 | + * @param string $prop Name of prop to get. |
|
| 848 | + * @param string $context What the value is for. Valid values are view and edit. |
|
| 849 | + * @return mixed |
|
| 850 | + */ |
|
| 851 | + protected function get_prop( $prop, $context = 'view' ) { |
|
| 852 | + $value = null; |
|
| 853 | + |
|
| 854 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
| 855 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
| 856 | + |
|
| 857 | + if ( 'view' === $context ) { |
|
| 858 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + return $value; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
| 867 | + * |
|
| 868 | + * @since 1.0.19 |
|
| 869 | + * @param string $prop Name of prop to set. |
|
| 870 | + * @param string|integer $value Value of the prop. |
|
| 871 | + */ |
|
| 872 | + protected function set_date_prop( $prop, $value ) { |
|
| 873 | + |
|
| 874 | + if ( empty( $value ) ) { |
|
| 875 | + $this->set_prop( $prop, null ); |
|
| 876 | + return; |
|
| 877 | + } |
|
| 878 | + $this->set_prop( $prop, $value ); |
|
| 879 | + |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
| 884 | + * |
|
| 885 | + * @since 1.0.19 |
|
| 886 | + * @param string $code Error code. |
|
| 887 | + * @param string $message Error message. |
|
| 888 | + */ |
|
| 889 | + protected function error( $code, $message ) { |
|
| 890 | + $this->last_error = $message; |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + /** |
|
| 894 | + * Checks if the object is saved in the database |
|
| 895 | + * |
|
| 896 | + * @since 1.0.19 |
|
| 897 | + * @return bool |
|
| 898 | + */ |
|
| 899 | + public function exists() { |
|
| 900 | + $id = $this->get_id(); |
|
| 901 | + return ! empty( $id ); |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | 904 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if (!defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
| 119 | 119 | */ |
| 120 | - public function __construct( $read = 0 ) { |
|
| 121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
| 120 | + public function __construct($read = 0) { |
|
| 121 | + $this->data = array_merge($this->data, $this->extra_data); |
|
| 122 | 122 | $this->default_data = $this->data; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @return array |
| 129 | 129 | */ |
| 130 | 130 | public function __sleep() { |
| 131 | - return array( 'id' ); |
|
| 131 | + return array('id'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | * If the object no longer exists, remove the ID. |
| 138 | 138 | */ |
| 139 | 139 | public function __wakeup() { |
| 140 | - $this->__construct( absint( $this->id ) ); |
|
| 140 | + $this->__construct(absint($this->id)); |
|
| 141 | 141 | |
| 142 | - if ( ! empty( $this->last_error ) ) { |
|
| 143 | - $this->set_id( 0 ); |
|
| 142 | + if (!empty($this->last_error)) { |
|
| 143 | + $this->set_id(0); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | } |
@@ -152,11 +152,11 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function __clone() { |
| 154 | 154 | $this->maybe_read_meta_data(); |
| 155 | - if ( ! empty( $this->meta_data ) ) { |
|
| 156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
| 158 | - if ( ! empty( $meta->id ) ) { |
|
| 159 | - $this->meta_data[ $array_key ]->id = null; |
|
| 155 | + if (!empty($this->meta_data)) { |
|
| 156 | + foreach ($this->meta_data as $array_key => $meta) { |
|
| 157 | + $this->meta_data[$array_key] = clone $meta; |
|
| 158 | + if (!empty($meta->id)) { |
|
| 159 | + $this->meta_data[$array_key]->id = null; |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -199,8 +199,8 @@ discard block |
||
| 199 | 199 | * @param string $context View or edit context. |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public function get_status( $context = 'view' ) { |
|
| 203 | - return $this->get_prop( 'status', $context ); |
|
| 202 | + public function get_status($context = 'view') { |
|
| 203 | + return $this->get_prop('status', $context); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | * @param bool $force_delete Should the data be deleted permanently. |
| 211 | 211 | * @return bool result |
| 212 | 212 | */ |
| 213 | - public function delete( $force_delete = false ) { |
|
| 214 | - if ( $this->data_store && $this->exists() ) { |
|
| 215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
| 216 | - $this->set_id( 0 ); |
|
| 213 | + public function delete($force_delete = false) { |
|
| 214 | + if ($this->data_store && $this->exists()) { |
|
| 215 | + $this->data_store->delete($this, array('force_delete' => $force_delete)); |
|
| 216 | + $this->set_id(0); |
|
| 217 | 217 | return true; |
| 218 | 218 | } |
| 219 | 219 | return false; |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @return int |
| 227 | 227 | */ |
| 228 | 228 | public function save() { |
| 229 | - if ( ! $this->data_store ) { |
|
| 229 | + if (!$this->data_store) { |
|
| 230 | 230 | return $this->get_id(); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | * @param GetPaid_Data $this The object being saved. |
| 237 | 237 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
| 238 | 238 | */ |
| 239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 239 | + do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
| 240 | 240 | |
| 241 | - if ( $this->get_id() ) { |
|
| 242 | - $this->data_store->update( $this ); |
|
| 241 | + if ($this->get_id()) { |
|
| 242 | + $this->data_store->update($this); |
|
| 243 | 243 | } else { |
| 244 | - $this->data_store->create( $this ); |
|
| 244 | + $this->data_store->create($this); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @param GetPaid_Data $this The object being saved. |
| 251 | 251 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
| 252 | 252 | */ |
| 253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 253 | + do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
| 254 | 254 | |
| 255 | 255 | return $this->get_id(); |
| 256 | 256 | } |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * @return string Data in JSON format. |
| 263 | 263 | */ |
| 264 | 264 | public function __toString() { |
| 265 | - return wp_json_encode( $this->get_data() ); |
|
| 265 | + return wp_json_encode($this->get_data()); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @return array |
| 273 | 273 | */ |
| 274 | 274 | public function get_data() { |
| 275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
| 275 | + return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data())); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @return array |
| 283 | 283 | */ |
| 284 | 284 | public function get_data_keys() { |
| 285 | - return array_keys( $this->data ); |
|
| 285 | + return array_keys($this->data); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | * @return array |
| 293 | 293 | */ |
| 294 | 294 | public function get_extra_data_keys() { |
| 295 | - return array_keys( $this->extra_data ); |
|
| 295 | + return array_keys($this->extra_data); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -302,8 +302,8 @@ discard block |
||
| 302 | 302 | * @param mixed $meta Meta value to check. |
| 303 | 303 | * @return bool |
| 304 | 304 | */ |
| 305 | - protected function filter_null_meta( $meta ) { |
|
| 306 | - return ! is_null( $meta->value ); |
|
| 305 | + protected function filter_null_meta($meta) { |
|
| 306 | + return !is_null($meta->value); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | public function get_meta_data() { |
| 316 | 316 | $this->maybe_read_meta_data(); |
| 317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
| 317 | + return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta'))); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -324,21 +324,21 @@ discard block |
||
| 324 | 324 | * @param string $key Key to check. |
| 325 | 325 | * @return bool true if it's an internal key, false otherwise |
| 326 | 326 | */ |
| 327 | - protected function is_internal_meta_key( $key ) { |
|
| 328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
| 327 | + protected function is_internal_meta_key($key) { |
|
| 328 | + $internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true); |
|
| 329 | 329 | |
| 330 | - if ( ! $internal_meta_key ) { |
|
| 330 | + if (!$internal_meta_key) { |
|
| 331 | 331 | return false; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
| 334 | + $has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key)); |
|
| 335 | 335 | |
| 336 | - if ( ! $has_setter_or_getter ) { |
|
| 336 | + if (!$has_setter_or_getter) { |
|
| 337 | 337 | return false; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /* translators: %s: $key Key to check */ |
| 341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 341 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
| 342 | 342 | |
| 343 | 343 | return true; |
| 344 | 344 | } |
@@ -352,20 +352,20 @@ discard block |
||
| 352 | 352 | * @access public |
| 353 | 353 | * |
| 354 | 354 | */ |
| 355 | - public function __set( $key, $value ) { |
|
| 355 | + public function __set($key, $value) { |
|
| 356 | 356 | |
| 357 | - if ( 'id' == strtolower( $key ) ) { |
|
| 358 | - return $this->set_id( $value ); |
|
| 357 | + if ('id' == strtolower($key)) { |
|
| 358 | + return $this->set_id($value); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( method_exists( $this, "set_$key") ) { |
|
| 361 | + if (method_exists($this, "set_$key")) { |
|
| 362 | 362 | |
| 363 | 363 | /* translators: %s: $key Key to set */ |
| 364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 364 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
| 365 | 365 | |
| 366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
| 366 | + call_user_func(array($this, "set_$key"), $value); |
|
| 367 | 367 | } else { |
| 368 | - $this->set_prop( $key, $value ); |
|
| 368 | + $this->set_prop($key, $value); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | } |
@@ -373,25 +373,25 @@ discard block |
||
| 373 | 373 | /** |
| 374 | 374 | * Margic method for retrieving a property. |
| 375 | 375 | */ |
| 376 | - public function __get( $key ) { |
|
| 376 | + public function __get($key) { |
|
| 377 | 377 | |
| 378 | 378 | // Check if we have a helper method for that. |
| 379 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 379 | + if (method_exists($this, 'get_' . $key)) { |
|
| 380 | 380 | |
| 381 | - if ( 'post_type' != $key ) { |
|
| 381 | + if ('post_type' != $key) { |
|
| 382 | 382 | /* translators: %s: $key Key to set */ |
| 383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
| 383 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 386 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | // Check if the key is in the associated $post object. |
| 390 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
| 390 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
| 391 | 391 | return $this->post->$key; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - return $this->get_prop( $key ); |
|
| 394 | + return $this->get_prop($key); |
|
| 395 | 395 | |
| 396 | 396 | } |
| 397 | 397 | |
@@ -404,15 +404,15 @@ discard block |
||
| 404 | 404 | * @param string $context What the value is for. Valid values are view and edit. |
| 405 | 405 | * @return mixed |
| 406 | 406 | */ |
| 407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
| 407 | + public function get_meta($key = '', $single = true, $context = 'view') { |
|
| 408 | 408 | |
| 409 | 409 | // Check if this is an internal meta key. |
| 410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
| 411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
| 412 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 410 | + $_key = str_replace('_wpinv', '', $key); |
|
| 411 | + $_key = str_replace('wpinv', '', $_key); |
|
| 412 | + if ($this->is_internal_meta_key($key)) { |
|
| 413 | 413 | $function = 'get_' . $_key; |
| 414 | 414 | |
| 415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 415 | + if (is_callable(array($this, $function))) { |
|
| 416 | 416 | return $this->{$function}(); |
| 417 | 417 | } |
| 418 | 418 | } |
@@ -420,20 +420,20 @@ discard block |
||
| 420 | 420 | // Read the meta data if not yet read. |
| 421 | 421 | $this->maybe_read_meta_data(); |
| 422 | 422 | $meta_data = $this->get_meta_data(); |
| 423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
| 423 | + $array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true); |
|
| 424 | 424 | $value = $single ? '' : array(); |
| 425 | 425 | |
| 426 | - if ( ! empty( $array_keys ) ) { |
|
| 426 | + if (!empty($array_keys)) { |
|
| 427 | 427 | // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
| 428 | - if ( $single ) { |
|
| 429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
| 428 | + if ($single) { |
|
| 429 | + $value = $meta_data[current($array_keys)]->value; |
|
| 430 | 430 | } else { |
| 431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
| 431 | + $value = array_intersect_key($meta_data, array_flip($array_keys)); |
|
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if ( 'view' === $context ) { |
|
| 436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
| 435 | + if ('view' === $context) { |
|
| 436 | + $value = apply_filters($this->get_hook_prefix() . $key, $value, $this); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | return $value; |
@@ -446,10 +446,10 @@ discard block |
||
| 446 | 446 | * @param string $key Meta Key. |
| 447 | 447 | * @return boolean |
| 448 | 448 | */ |
| 449 | - public function meta_exists( $key = '' ) { |
|
| 449 | + public function meta_exists($key = '') { |
|
| 450 | 450 | $this->maybe_read_meta_data(); |
| 451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
| 452 | - return in_array( $key, $array_keys, true ); |
|
| 451 | + $array_keys = wp_list_pluck($this->get_meta_data(), 'key'); |
|
| 452 | + return in_array($key, $array_keys, true); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -458,12 +458,12 @@ discard block |
||
| 458 | 458 | * @since 1.0.19 |
| 459 | 459 | * @param array $data Key/Value pairs. |
| 460 | 460 | */ |
| 461 | - public function set_meta_data( $data ) { |
|
| 462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
| 461 | + public function set_meta_data($data) { |
|
| 462 | + if (!empty($data) && is_array($data)) { |
|
| 463 | 463 | $this->maybe_read_meta_data(); |
| 464 | - foreach ( $data as $meta ) { |
|
| 464 | + foreach ($data as $meta) { |
|
| 465 | 465 | $meta = (array) $meta; |
| 466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
| 466 | + if (isset($meta['key'], $meta['value'], $meta['id'])) { |
|
| 467 | 467 | $this->meta_data[] = new GetPaid_Meta_Data( |
| 468 | 468 | array( |
| 469 | 469 | 'id' => $meta['id'], |
@@ -485,18 +485,18 @@ discard block |
||
| 485 | 485 | * @param string|array $value Meta value. |
| 486 | 486 | * @param bool $unique Should this be a unique key?. |
| 487 | 487 | */ |
| 488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
| 489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 488 | + public function add_meta_data($key, $value, $unique = false) { |
|
| 489 | + if ($this->is_internal_meta_key($key)) { |
|
| 490 | 490 | $function = 'set_' . $key; |
| 491 | 491 | |
| 492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 493 | - return $this->{$function}( $value ); |
|
| 492 | + if (is_callable(array($this, $function))) { |
|
| 493 | + return $this->{$function}($value); |
|
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | $this->maybe_read_meta_data(); |
| 498 | - if ( $unique ) { |
|
| 499 | - $this->delete_meta_data( $key ); |
|
| 498 | + if ($unique) { |
|
| 499 | + $this->delete_meta_data($key); |
|
| 500 | 500 | } |
| 501 | 501 | $this->meta_data[] = new GetPaid_Meta_Data( |
| 502 | 502 | array( |
@@ -517,12 +517,12 @@ discard block |
||
| 517 | 517 | * @param string|array $value Meta value. |
| 518 | 518 | * @param int $meta_id Meta ID. |
| 519 | 519 | */ |
| 520 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
| 521 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 520 | + public function update_meta_data($key, $value, $meta_id = 0) { |
|
| 521 | + if ($this->is_internal_meta_key($key)) { |
|
| 522 | 522 | $function = 'set_' . $key; |
| 523 | 523 | |
| 524 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 525 | - return $this->{$function}( $value ); |
|
| 524 | + if (is_callable(array($this, $function))) { |
|
| 525 | + return $this->{$function}($value); |
|
| 526 | 526 | } |
| 527 | 527 | } |
| 528 | 528 | |
@@ -530,33 +530,33 @@ discard block |
||
| 530 | 530 | |
| 531 | 531 | $array_key = false; |
| 532 | 532 | |
| 533 | - if ( $meta_id ) { |
|
| 534 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
| 535 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
| 533 | + if ($meta_id) { |
|
| 534 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true); |
|
| 535 | + $array_key = $array_keys ? current($array_keys) : false; |
|
| 536 | 536 | } else { |
| 537 | 537 | // Find matches by key. |
| 538 | 538 | $matches = array(); |
| 539 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
| 540 | - if ( $meta->key === $key ) { |
|
| 539 | + foreach ($this->meta_data as $meta_data_array_key => $meta) { |
|
| 540 | + if ($meta->key === $key) { |
|
| 541 | 541 | $matches[] = $meta_data_array_key; |
| 542 | 542 | } |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - if ( ! empty( $matches ) ) { |
|
| 545 | + if (!empty($matches)) { |
|
| 546 | 546 | // Set matches to null so only one key gets the new value. |
| 547 | - foreach ( $matches as $meta_data_array_key ) { |
|
| 548 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
| 547 | + foreach ($matches as $meta_data_array_key) { |
|
| 548 | + $this->meta_data[$meta_data_array_key]->value = null; |
|
| 549 | 549 | } |
| 550 | - $array_key = current( $matches ); |
|
| 550 | + $array_key = current($matches); |
|
| 551 | 551 | } |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - if ( false !== $array_key ) { |
|
| 555 | - $meta = $this->meta_data[ $array_key ]; |
|
| 554 | + if (false !== $array_key) { |
|
| 555 | + $meta = $this->meta_data[$array_key]; |
|
| 556 | 556 | $meta->key = $key; |
| 557 | 557 | $meta->value = $value; |
| 558 | 558 | } else { |
| 559 | - $this->add_meta_data( $key, $value, true ); |
|
| 559 | + $this->add_meta_data($key, $value, true); |
|
| 560 | 560 | } |
| 561 | 561 | } |
| 562 | 562 | |
@@ -566,13 +566,13 @@ discard block |
||
| 566 | 566 | * @since 1.0.19 |
| 567 | 567 | * @param string $key Meta key. |
| 568 | 568 | */ |
| 569 | - public function delete_meta_data( $key ) { |
|
| 569 | + public function delete_meta_data($key) { |
|
| 570 | 570 | $this->maybe_read_meta_data(); |
| 571 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
| 571 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true); |
|
| 572 | 572 | |
| 573 | - if ( $array_keys ) { |
|
| 574 | - foreach ( $array_keys as $array_key ) { |
|
| 575 | - $this->meta_data[ $array_key ]->value = null; |
|
| 573 | + if ($array_keys) { |
|
| 574 | + foreach ($array_keys as $array_key) { |
|
| 575 | + $this->meta_data[$array_key]->value = null; |
|
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | 578 | } |
@@ -583,13 +583,13 @@ discard block |
||
| 583 | 583 | * @since 1.0.19 |
| 584 | 584 | * @param int $mid Meta ID. |
| 585 | 585 | */ |
| 586 | - public function delete_meta_data_by_mid( $mid ) { |
|
| 586 | + public function delete_meta_data_by_mid($mid) { |
|
| 587 | 587 | $this->maybe_read_meta_data(); |
| 588 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
| 588 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true); |
|
| 589 | 589 | |
| 590 | - if ( $array_keys ) { |
|
| 591 | - foreach ( $array_keys as $array_key ) { |
|
| 592 | - $this->meta_data[ $array_key ]->value = null; |
|
| 590 | + if ($array_keys) { |
|
| 591 | + foreach ($array_keys as $array_key) { |
|
| 592 | + $this->meta_data[$array_key]->value = null; |
|
| 593 | 593 | } |
| 594 | 594 | } |
| 595 | 595 | } |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | * @since 1.0.19 |
| 601 | 601 | */ |
| 602 | 602 | protected function maybe_read_meta_data() { |
| 603 | - if ( is_null( $this->meta_data ) ) { |
|
| 603 | + if (is_null($this->meta_data)) { |
|
| 604 | 604 | $this->read_meta_data(); |
| 605 | 605 | } |
| 606 | 606 | } |
@@ -612,42 +612,42 @@ discard block |
||
| 612 | 612 | * @since 1.0.19 |
| 613 | 613 | * @param bool $force_read True to force a new DB read (and update cache). |
| 614 | 614 | */ |
| 615 | - public function read_meta_data( $force_read = false ) { |
|
| 615 | + public function read_meta_data($force_read = false) { |
|
| 616 | 616 | |
| 617 | 617 | // Reset meta data. |
| 618 | 618 | $this->meta_data = array(); |
| 619 | 619 | |
| 620 | 620 | // Maybe abort early. |
| 621 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
| 621 | + if (!$this->get_id() || !$this->data_store) { |
|
| 622 | 622 | return; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | // Only read from cache if the cache key is set. |
| 626 | 626 | $cache_key = null; |
| 627 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
| 628 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 629 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
| 627 | + if (!$force_read && !empty($this->cache_group)) { |
|
| 628 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
| 629 | + $raw_meta_data = wp_cache_get($cache_key, $this->cache_group); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | // Should we force read? |
| 633 | - if ( empty( $raw_meta_data ) ) { |
|
| 634 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
| 633 | + if (empty($raw_meta_data)) { |
|
| 634 | + $raw_meta_data = $this->data_store->read_meta($this); |
|
| 635 | 635 | |
| 636 | - if ( ! empty( $cache_key ) ) { |
|
| 637 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
| 636 | + if (!empty($cache_key)) { |
|
| 637 | + wp_cache_set($cache_key, $raw_meta_data, $this->cache_group); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | // Set meta data. |
| 643 | - if ( is_array( $raw_meta_data ) ) { |
|
| 643 | + if (is_array($raw_meta_data)) { |
|
| 644 | 644 | |
| 645 | - foreach ( $raw_meta_data as $meta ) { |
|
| 645 | + foreach ($raw_meta_data as $meta) { |
|
| 646 | 646 | $this->meta_data[] = new GetPaid_Meta_Data( |
| 647 | 647 | array( |
| 648 | 648 | 'id' => (int) $meta->meta_id, |
| 649 | 649 | 'key' => $meta->meta_key, |
| 650 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
| 650 | + 'value' => maybe_unserialize($meta->meta_value), |
|
| 651 | 651 | ) |
| 652 | 652 | ); |
| 653 | 653 | } |
@@ -662,28 +662,28 @@ discard block |
||
| 662 | 662 | * @since 1.0.19 |
| 663 | 663 | */ |
| 664 | 664 | public function save_meta_data() { |
| 665 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
| 665 | + if (!$this->data_store || is_null($this->meta_data)) { |
|
| 666 | 666 | return; |
| 667 | 667 | } |
| 668 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 669 | - if ( is_null( $meta->value ) ) { |
|
| 670 | - if ( ! empty( $meta->id ) ) { |
|
| 671 | - $this->data_store->delete_meta( $this, $meta ); |
|
| 672 | - unset( $this->meta_data[ $array_key ] ); |
|
| 668 | + foreach ($this->meta_data as $array_key => $meta) { |
|
| 669 | + if (is_null($meta->value)) { |
|
| 670 | + if (!empty($meta->id)) { |
|
| 671 | + $this->data_store->delete_meta($this, $meta); |
|
| 672 | + unset($this->meta_data[$array_key]); |
|
| 673 | 673 | } |
| 674 | - } elseif ( empty( $meta->id ) ) { |
|
| 675 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
| 674 | + } elseif (empty($meta->id)) { |
|
| 675 | + $meta->id = $this->data_store->add_meta($this, $meta); |
|
| 676 | 676 | $meta->apply_changes(); |
| 677 | 677 | } else { |
| 678 | - if ( $meta->get_changes() ) { |
|
| 679 | - $this->data_store->update_meta( $this, $meta ); |
|
| 678 | + if ($meta->get_changes()) { |
|
| 679 | + $this->data_store->update_meta($this, $meta); |
|
| 680 | 680 | $meta->apply_changes(); |
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | - if ( ! empty( $this->cache_group ) ) { |
|
| 685 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 686 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
| 684 | + if (!empty($this->cache_group)) { |
|
| 685 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
| 686 | + wp_cache_delete($cache_key, $this->cache_group); |
|
| 687 | 687 | } |
| 688 | 688 | } |
| 689 | 689 | |
@@ -693,8 +693,8 @@ discard block |
||
| 693 | 693 | * @since 1.0.19 |
| 694 | 694 | * @param int $id ID. |
| 695 | 695 | */ |
| 696 | - public function set_id( $id ) { |
|
| 697 | - $this->id = absint( $id ); |
|
| 696 | + public function set_id($id) { |
|
| 697 | + $this->id = absint($id); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -704,10 +704,10 @@ discard block |
||
| 704 | 704 | * @param string $status New status. |
| 705 | 705 | * @return array details of change. |
| 706 | 706 | */ |
| 707 | - public function set_status( $status ) { |
|
| 707 | + public function set_status($status) { |
|
| 708 | 708 | $old_status = $this->get_status(); |
| 709 | 709 | |
| 710 | - $this->set_prop( 'status', $status ); |
|
| 710 | + $this->set_prop('status', $status); |
|
| 711 | 711 | |
| 712 | 712 | return array( |
| 713 | 713 | 'from' => $old_status, |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | public function set_defaults() { |
| 724 | 724 | $this->data = $this->default_data; |
| 725 | 725 | $this->changes = array(); |
| 726 | - $this->set_object_read( false ); |
|
| 726 | + $this->set_object_read(false); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | /** |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | * @since 1.0.19 |
| 733 | 733 | * @param boolean $read Should read?. |
| 734 | 734 | */ |
| 735 | - public function set_object_read( $read = true ) { |
|
| 735 | + public function set_object_read($read = true) { |
|
| 736 | 736 | $this->object_read = (bool) $read; |
| 737 | 737 | } |
| 738 | 738 | |
@@ -757,32 +757,32 @@ discard block |
||
| 757 | 757 | * |
| 758 | 758 | * @return bool|WP_Error |
| 759 | 759 | */ |
| 760 | - public function set_props( $props, $context = 'set' ) { |
|
| 760 | + public function set_props($props, $context = 'set') { |
|
| 761 | 761 | $errors = false; |
| 762 | 762 | |
| 763 | - foreach ( $props as $prop => $value ) { |
|
| 763 | + foreach ($props as $prop => $value) { |
|
| 764 | 764 | try { |
| 765 | 765 | /** |
| 766 | 766 | * Checks if the prop being set is allowed, and the value is not null. |
| 767 | 767 | */ |
| 768 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
| 768 | + if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) { |
|
| 769 | 769 | continue; |
| 770 | 770 | } |
| 771 | 771 | $setter = "set_$prop"; |
| 772 | 772 | |
| 773 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
| 774 | - $this->{$setter}( $value ); |
|
| 773 | + if (is_callable(array($this, $setter))) { |
|
| 774 | + $this->{$setter}($value); |
|
| 775 | 775 | } |
| 776 | - } catch ( Exception $e ) { |
|
| 777 | - if ( ! $errors ) { |
|
| 776 | + } catch (Exception $e) { |
|
| 777 | + if (!$errors) { |
|
| 778 | 778 | $errors = new WP_Error(); |
| 779 | 779 | } |
| 780 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
| 780 | + $errors->add($e->getCode(), $e->getMessage()); |
|
| 781 | 781 | $this->last_error = $e->getMessage(); |
| 782 | 782 | } |
| 783 | 783 | } |
| 784 | 784 | |
| 785 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
| 785 | + return $errors && count($errors->get_error_codes()) ? $errors : true; |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | /** |
@@ -795,14 +795,14 @@ discard block |
||
| 795 | 795 | * @param string $prop Name of prop to set. |
| 796 | 796 | * @param mixed $value Value of the prop. |
| 797 | 797 | */ |
| 798 | - protected function set_prop( $prop, $value ) { |
|
| 799 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 800 | - if ( true === $this->object_read ) { |
|
| 801 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
| 802 | - $this->changes[ $prop ] = $value; |
|
| 798 | + protected function set_prop($prop, $value) { |
|
| 799 | + if (array_key_exists($prop, $this->data)) { |
|
| 800 | + if (true === $this->object_read) { |
|
| 801 | + if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) { |
|
| 802 | + $this->changes[$prop] = $value; |
|
| 803 | 803 | } |
| 804 | 804 | } else { |
| 805 | - $this->data[ $prop ] = $value; |
|
| 805 | + $this->data[$prop] = $value; |
|
| 806 | 806 | } |
| 807 | 807 | } |
| 808 | 808 | } |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | * @since 1.0.19 |
| 824 | 824 | */ |
| 825 | 825 | public function apply_changes() { |
| 826 | - $this->data = array_replace( $this->data, $this->changes ); |
|
| 826 | + $this->data = array_replace($this->data, $this->changes); |
|
| 827 | 827 | $this->changes = array(); |
| 828 | 828 | } |
| 829 | 829 | |
@@ -848,14 +848,14 @@ discard block |
||
| 848 | 848 | * @param string $context What the value is for. Valid values are view and edit. |
| 849 | 849 | * @return mixed |
| 850 | 850 | */ |
| 851 | - protected function get_prop( $prop, $context = 'view' ) { |
|
| 851 | + protected function get_prop($prop, $context = 'view') { |
|
| 852 | 852 | $value = null; |
| 853 | 853 | |
| 854 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 855 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
| 854 | + if (array_key_exists($prop, $this->data)) { |
|
| 855 | + $value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop]; |
|
| 856 | 856 | |
| 857 | - if ( 'view' === $context ) { |
|
| 858 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
| 857 | + if ('view' === $context) { |
|
| 858 | + $value = apply_filters($this->get_hook_prefix() . $prop, $value, $this); |
|
| 859 | 859 | } |
| 860 | 860 | } |
| 861 | 861 | |
@@ -869,13 +869,13 @@ discard block |
||
| 869 | 869 | * @param string $prop Name of prop to set. |
| 870 | 870 | * @param string|integer $value Value of the prop. |
| 871 | 871 | */ |
| 872 | - protected function set_date_prop( $prop, $value ) { |
|
| 872 | + protected function set_date_prop($prop, $value) { |
|
| 873 | 873 | |
| 874 | - if ( empty( $value ) ) { |
|
| 875 | - $this->set_prop( $prop, null ); |
|
| 874 | + if (empty($value)) { |
|
| 875 | + $this->set_prop($prop, null); |
|
| 876 | 876 | return; |
| 877 | 877 | } |
| 878 | - $this->set_prop( $prop, $value ); |
|
| 878 | + $this->set_prop($prop, $value); |
|
| 879 | 879 | |
| 880 | 880 | } |
| 881 | 881 | |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | * @param string $code Error code. |
| 887 | 887 | * @param string $message Error message. |
| 888 | 888 | */ |
| 889 | - protected function error( $code, $message ) { |
|
| 889 | + protected function error($code, $message) { |
|
| 890 | 890 | $this->last_error = $message; |
| 891 | 891 | } |
| 892 | 892 | |
@@ -898,7 +898,7 @@ discard block |
||
| 898 | 898 | */ |
| 899 | 899 | public function exists() { |
| 900 | 900 | $id = $this->get_id(); |
| 901 | - return ! empty( $id ); |
|
| 901 | + return !empty($id); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | } |
@@ -12,455 +12,455 @@ |
||
| 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 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Helper function to send an email. |
|
| 155 | - * |
|
| 156 | - * @param WPInv_Invoice $invoice |
|
| 157 | - * @param GetPaid_Notification_Email $email |
|
| 158 | - * @param string $type |
|
| 159 | - * @param string|array $recipients |
|
| 160 | - * @param array $extra_args Extra template args. |
|
| 161 | - */ |
|
| 162 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 163 | - |
|
| 164 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 165 | - |
|
| 166 | - if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) { |
|
| 167 | - return; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 171 | - $merge_tags = $email->get_merge_tags(); |
|
| 172 | - |
|
| 173 | - $result = $mailer->send( |
|
| 174 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 175 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 176 | - $email->get_content( $merge_tags, $extra_args ), |
|
| 177 | - $email->get_attachments() |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - // Maybe send a copy to the admin. |
|
| 181 | - if ( $email->include_admin_bcc() ) { |
|
| 182 | - $mailer->send( |
|
| 183 | - wpinv_get_admin_email(), |
|
| 184 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 185 | - $email->get_content( $merge_tags ), |
|
| 186 | - $email->get_attachments() |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if ( $result ) { |
|
| 191 | - $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 192 | - } else { |
|
| 193 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
| 197 | - |
|
| 198 | - return $result; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Also send emails to any cc users. |
|
| 203 | - * |
|
| 204 | - * @param array $recipients |
|
| 205 | - * @param GetPaid_Notification_Email $email |
|
| 206 | - */ |
|
| 207 | - public function filter_email_recipients( $recipients, $email ) { |
|
| 208 | - |
|
| 209 | - if ( ! $email->is_admin_email() ) { |
|
| 210 | - $cc = $email->object->get_email_cc(); |
|
| 211 | - |
|
| 212 | - if ( ! empty( $cc ) ) { |
|
| 213 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 214 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - return $recipients; |
|
| 220 | - |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Sends a new invoice notification. |
|
| 225 | - * |
|
| 226 | - * @param WPInv_Invoice $invoice |
|
| 227 | - */ |
|
| 228 | - public function new_invoice( $invoice ) { |
|
| 229 | - |
|
| 230 | - // Only send this email for invoices created via the admin page. |
|
| 231 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 232 | - return; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 236 | - $recipient = wpinv_get_admin_email(); |
|
| 237 | - |
|
| 238 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Sends a cancelled invoice notification. |
|
| 244 | - * |
|
| 245 | - * @param WPInv_Invoice $invoice |
|
| 246 | - */ |
|
| 247 | - public function cancelled_invoice( $invoice ) { |
|
| 15 | + /** |
|
| 16 | + * The array of invoice email actions. |
|
| 17 | + * |
|
| 18 | + * @param array |
|
| 19 | + */ |
|
| 20 | + public $invoice_actions; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Class constructor |
|
| 24 | + * |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + |
|
| 28 | + $this->invoice_actions = apply_filters( |
|
| 29 | + 'getpaid_notification_email_invoice_triggers', |
|
| 30 | + array( |
|
| 31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
| 32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
| 33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
| 34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
| 35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
| 36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
| 37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
| 38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
| 39 | + 'getpaid_new_customer_note' => 'user_note', |
|
| 40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
| 41 | + ) |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + $this->init_hooks(); |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Registers email hooks. |
|
| 50 | + */ |
|
| 51 | + public function init_hooks() { |
|
| 52 | + |
|
| 53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
| 54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
| 55 | + |
|
| 56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
| 57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Registers an email hook for an invoice action. |
|
| 63 | + * |
|
| 64 | + * @param string $hook |
|
| 65 | + * @param string|array $email_type |
|
| 66 | + */ |
|
| 67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
| 68 | + |
|
| 69 | + $email_type = wpinv_parse_list( $email_type ); |
|
| 70 | + |
|
| 71 | + foreach ( $email_type as $type ) { |
|
| 72 | + |
|
| 73 | + $email = new GetPaid_Notification_Email( $type ); |
|
| 74 | + |
|
| 75 | + // Abort if it is not active. |
|
| 76 | + if ( ! $email->is_active() ) { |
|
| 77 | + continue; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ( method_exists( $this, $type ) ) { |
|
| 81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Filters invoice merge tags. |
|
| 92 | + * |
|
| 93 | + * @param array $merge_tags |
|
| 94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 95 | + */ |
|
| 96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
| 97 | + |
|
| 98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
| 99 | + return array_merge( |
|
| 100 | + $merge_tags, |
|
| 101 | + $this->get_invoice_merge_tags( $object ) |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 106 | + return array_merge( |
|
| 107 | + $merge_tags, |
|
| 108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
| 109 | + ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return $merge_tags; |
|
| 113 | + |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Generates invoice merge tags. |
|
| 118 | + * |
|
| 119 | + * @param WPInv_Invoice $invoice |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function get_invoice_merge_tags( $invoice ) { |
|
| 123 | + |
|
| 124 | + // Abort if it does not exist. |
|
| 125 | + if ( ! $invoice->get_id() ) { |
|
| 126 | + return array(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $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 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Helper function to send an email. |
|
| 155 | + * |
|
| 156 | + * @param WPInv_Invoice $invoice |
|
| 157 | + * @param GetPaid_Notification_Email $email |
|
| 158 | + * @param string $type |
|
| 159 | + * @param string|array $recipients |
|
| 160 | + * @param array $extra_args Extra template args. |
|
| 161 | + */ |
|
| 162 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 163 | + |
|
| 164 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 165 | + |
|
| 166 | + if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 171 | + $merge_tags = $email->get_merge_tags(); |
|
| 172 | + |
|
| 173 | + $result = $mailer->send( |
|
| 174 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 175 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 176 | + $email->get_content( $merge_tags, $extra_args ), |
|
| 177 | + $email->get_attachments() |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + // Maybe send a copy to the admin. |
|
| 181 | + if ( $email->include_admin_bcc() ) { |
|
| 182 | + $mailer->send( |
|
| 183 | + wpinv_get_admin_email(), |
|
| 184 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 185 | + $email->get_content( $merge_tags ), |
|
| 186 | + $email->get_attachments() |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if ( $result ) { |
|
| 191 | + $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 192 | + } else { |
|
| 193 | + $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
| 197 | + |
|
| 198 | + return $result; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Also send emails to any cc users. |
|
| 203 | + * |
|
| 204 | + * @param array $recipients |
|
| 205 | + * @param GetPaid_Notification_Email $email |
|
| 206 | + */ |
|
| 207 | + public function filter_email_recipients( $recipients, $email ) { |
|
| 208 | + |
|
| 209 | + if ( ! $email->is_admin_email() ) { |
|
| 210 | + $cc = $email->object->get_email_cc(); |
|
| 211 | + |
|
| 212 | + if ( ! empty( $cc ) ) { |
|
| 213 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 214 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + return $recipients; |
|
| 220 | + |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Sends a new invoice notification. |
|
| 225 | + * |
|
| 226 | + * @param WPInv_Invoice $invoice |
|
| 227 | + */ |
|
| 228 | + public function new_invoice( $invoice ) { |
|
| 229 | + |
|
| 230 | + // Only send this email for invoices created via the admin page. |
|
| 231 | + if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 232 | + return; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 236 | + $recipient = wpinv_get_admin_email(); |
|
| 237 | + |
|
| 238 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Sends a cancelled invoice notification. |
|
| 244 | + * |
|
| 245 | + * @param WPInv_Invoice $invoice |
|
| 246 | + */ |
|
| 247 | + public function cancelled_invoice( $invoice ) { |
|
| 248 | 248 | |
| 249 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 250 | - $recipient = wpinv_get_admin_email(); |
|
| 249 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 250 | + $recipient = wpinv_get_admin_email(); |
|
| 251 | 251 | |
| 252 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 252 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 253 | 253 | |
| 254 | - } |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Sends a failed invoice notification. |
|
| 258 | - * |
|
| 259 | - * @param WPInv_Invoice $invoice |
|
| 260 | - */ |
|
| 261 | - public function failed_invoice( $invoice ) { |
|
| 256 | + /** |
|
| 257 | + * Sends a failed invoice notification. |
|
| 258 | + * |
|
| 259 | + * @param WPInv_Invoice $invoice |
|
| 260 | + */ |
|
| 261 | + public function failed_invoice( $invoice ) { |
|
| 262 | 262 | |
| 263 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 264 | - $recipient = wpinv_get_admin_email(); |
|
| 263 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 264 | + $recipient = wpinv_get_admin_email(); |
|
| 265 | 265 | |
| 266 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 266 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 267 | 267 | |
| 268 | - } |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Sends a notification whenever an invoice is put on hold. |
|
| 272 | - * |
|
| 273 | - * @param WPInv_Invoice $invoice |
|
| 274 | - */ |
|
| 275 | - public function onhold_invoice( $invoice ) { |
|
| 270 | + /** |
|
| 271 | + * Sends a notification whenever an invoice is put on hold. |
|
| 272 | + * |
|
| 273 | + * @param WPInv_Invoice $invoice |
|
| 274 | + */ |
|
| 275 | + public function onhold_invoice( $invoice ) { |
|
| 276 | 276 | |
| 277 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 278 | - $recipient = $invoice->get_email(); |
|
| 277 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 278 | + $recipient = $invoice->get_email(); |
|
| 279 | 279 | |
| 280 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 280 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 281 | 281 | |
| 282 | - } |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
| 286 | - * |
|
| 287 | - * @param WPInv_Invoice $invoice |
|
| 288 | - */ |
|
| 289 | - public function processing_invoice( $invoice ) { |
|
| 284 | + /** |
|
| 285 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
| 286 | + * |
|
| 287 | + * @param WPInv_Invoice $invoice |
|
| 288 | + */ |
|
| 289 | + public function processing_invoice( $invoice ) { |
|
| 290 | 290 | |
| 291 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 292 | - $recipient = $invoice->get_email(); |
|
| 291 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 292 | + $recipient = $invoice->get_email(); |
|
| 293 | 293 | |
| 294 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 294 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 295 | 295 | |
| 296 | - } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Sends a notification whenever an invoice is paid. |
|
| 300 | - * |
|
| 301 | - * @param WPInv_Invoice $invoice |
|
| 302 | - */ |
|
| 303 | - public function completed_invoice( $invoice ) { |
|
| 298 | + /** |
|
| 299 | + * Sends a notification whenever an invoice is paid. |
|
| 300 | + * |
|
| 301 | + * @param WPInv_Invoice $invoice |
|
| 302 | + */ |
|
| 303 | + public function completed_invoice( $invoice ) { |
|
| 304 | 304 | |
| 305 | - // (Maybe) abort if it is a renewal invoice. |
|
| 306 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 307 | - return; |
|
| 308 | - } |
|
| 305 | + // (Maybe) abort if it is a renewal invoice. |
|
| 306 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 311 | - $recipient = $invoice->get_email(); |
|
| 310 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 311 | + $recipient = $invoice->get_email(); |
|
| 312 | 312 | |
| 313 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 313 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 314 | 314 | |
| 315 | - } |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - /** |
|
| 318 | - * Sends a notification whenever an invoice is refunded. |
|
| 319 | - * |
|
| 320 | - * @param WPInv_Invoice $invoice |
|
| 321 | - */ |
|
| 322 | - public function refunded_invoice( $invoice ) { |
|
| 317 | + /** |
|
| 318 | + * Sends a notification whenever an invoice is refunded. |
|
| 319 | + * |
|
| 320 | + * @param WPInv_Invoice $invoice |
|
| 321 | + */ |
|
| 322 | + public function refunded_invoice( $invoice ) { |
|
| 323 | 323 | |
| 324 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 325 | - $recipient = $invoice->get_email(); |
|
| 324 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 325 | + $recipient = $invoice->get_email(); |
|
| 326 | 326 | |
| 327 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 327 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 328 | 328 | |
| 329 | - } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * Notifies a user about new invoices |
|
| 333 | - * |
|
| 334 | - * @param WPInv_Invoice $invoice |
|
| 335 | - * @param bool $force |
|
| 336 | - */ |
|
| 337 | - public function user_invoice( $invoice, $force = false ) { |
|
| 331 | + /** |
|
| 332 | + * Notifies a user about new invoices |
|
| 333 | + * |
|
| 334 | + * @param WPInv_Invoice $invoice |
|
| 335 | + * @param bool $force |
|
| 336 | + */ |
|
| 337 | + public function user_invoice( $invoice, $force = false ) { |
|
| 338 | 338 | |
| 339 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 340 | - return; |
|
| 341 | - } |
|
| 339 | + if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 340 | + return; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - // Only send this email for invoices created via the admin page. |
|
| 344 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 345 | - return; |
|
| 346 | - } |
|
| 343 | + // Only send this email for invoices created via the admin page. |
|
| 344 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 345 | + return; |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 349 | - $recipient = $invoice->get_email(); |
|
| 348 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 349 | + $recipient = $invoice->get_email(); |
|
| 350 | 350 | |
| 351 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 351 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 352 | 352 | |
| 353 | - } |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * Checks if an invoice is a payment form invoice. |
|
| 357 | - * |
|
| 358 | - * @param int $invoice |
|
| 359 | - * @return bool |
|
| 360 | - */ |
|
| 361 | - public function is_payment_form_invoice( $invoice ) { |
|
| 362 | - return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
| 363 | - } |
|
| 355 | + /** |
|
| 356 | + * Checks if an invoice is a payment form invoice. |
|
| 357 | + * |
|
| 358 | + * @param int $invoice |
|
| 359 | + * @return bool |
|
| 360 | + */ |
|
| 361 | + public function is_payment_form_invoice( $invoice ) { |
|
| 362 | + return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * Notifies admin about new invoice notes |
|
| 367 | - * |
|
| 368 | - * @param WPInv_Invoice $invoice |
|
| 369 | - * @param string $note |
|
| 370 | - */ |
|
| 371 | - public function user_note( $invoice, $note ) { |
|
| 372 | - |
|
| 373 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 374 | - $recipient = $invoice->get_email(); |
|
| 365 | + /** |
|
| 366 | + * Notifies admin about new invoice notes |
|
| 367 | + * |
|
| 368 | + * @param WPInv_Invoice $invoice |
|
| 369 | + * @param string $note |
|
| 370 | + */ |
|
| 371 | + public function user_note( $invoice, $note ) { |
|
| 372 | + |
|
| 373 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 374 | + $recipient = $invoice->get_email(); |
|
| 375 | 375 | |
| 376 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 377 | - |
|
| 378 | - } |
|
| 376 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 377 | + |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * (Force) Sends overdue notices. |
|
| 382 | - * |
|
| 383 | - * @param WPInv_Invoice $invoice |
|
| 384 | - */ |
|
| 385 | - public function force_send_overdue_notice( $invoice ) { |
|
| 386 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 387 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Sends overdue notices. |
|
| 392 | - * |
|
| 393 | - * @TODO: Create an invoices query class. |
|
| 394 | - */ |
|
| 395 | - public function overdue() { |
|
| 396 | - global $wpdb; |
|
| 397 | - |
|
| 398 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 399 | - |
|
| 400 | - // Fetch reminder days. |
|
| 401 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 402 | - |
|
| 403 | - // Abort if non is set. |
|
| 404 | - if ( empty( $reminder_days ) ) { |
|
| 405 | - return; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - // Retrieve date query. |
|
| 409 | - $date_query = $this->get_date_query( $reminder_days ); |
|
| 410 | - |
|
| 411 | - // Invoices table. |
|
| 412 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 413 | - |
|
| 414 | - // Fetch invoices. |
|
| 415 | - $invoices = $wpdb->get_col( |
|
| 416 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
| 380 | + /** |
|
| 381 | + * (Force) Sends overdue notices. |
|
| 382 | + * |
|
| 383 | + * @param WPInv_Invoice $invoice |
|
| 384 | + */ |
|
| 385 | + public function force_send_overdue_notice( $invoice ) { |
|
| 386 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 387 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Sends overdue notices. |
|
| 392 | + * |
|
| 393 | + * @TODO: Create an invoices query class. |
|
| 394 | + */ |
|
| 395 | + public function overdue() { |
|
| 396 | + global $wpdb; |
|
| 397 | + |
|
| 398 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 399 | + |
|
| 400 | + // Fetch reminder days. |
|
| 401 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 402 | + |
|
| 403 | + // Abort if non is set. |
|
| 404 | + if ( empty( $reminder_days ) ) { |
|
| 405 | + return; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + // Retrieve date query. |
|
| 409 | + $date_query = $this->get_date_query( $reminder_days ); |
|
| 410 | + |
|
| 411 | + // Invoices table. |
|
| 412 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 413 | + |
|
| 414 | + // Fetch invoices. |
|
| 415 | + $invoices = $wpdb->get_col( |
|
| 416 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
| 417 | 417 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
| 418 | 418 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
| 419 | 419 | |
| 420 | - foreach ( $invoices as $invoice ) { |
|
| 420 | + foreach ( $invoices as $invoice ) { |
|
| 421 | 421 | |
| 422 | - // Only send this email for invoices created via the admin page. |
|
| 423 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 424 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 425 | - $email->object = $invoice; |
|
| 422 | + // Only send this email for invoices created via the admin page. |
|
| 423 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 424 | + $invoice = new WPInv_Invoice( $invoice ); |
|
| 425 | + $email->object = $invoice; |
|
| 426 | 426 | |
| 427 | - if ( $invoice->needs_payment() ) { |
|
| 428 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 429 | - } |
|
| 427 | + if ( $invoice->needs_payment() ) { |
|
| 428 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - } |
|
| 431 | + } |
|
| 432 | 432 | |
| 433 | - } |
|
| 433 | + } |
|
| 434 | 434 | |
| 435 | - } |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - /** |
|
| 438 | - * Calculates the date query for an invoices query |
|
| 439 | - * |
|
| 440 | - * @param array $reminder_days |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - public function get_date_query( $reminder_days ) { |
|
| 437 | + /** |
|
| 438 | + * Calculates the date query for an invoices query |
|
| 439 | + * |
|
| 440 | + * @param array $reminder_days |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + public function get_date_query( $reminder_days ) { |
|
| 444 | 444 | |
| 445 | - $date_query = array( |
|
| 446 | - 'relation' => 'OR' |
|
| 447 | - ); |
|
| 445 | + $date_query = array( |
|
| 446 | + 'relation' => 'OR' |
|
| 447 | + ); |
|
| 448 | 448 | |
| 449 | - foreach ( $reminder_days as $days ) { |
|
| 450 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 449 | + foreach ( $reminder_days as $days ) { |
|
| 450 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 451 | 451 | |
| 452 | - $date_query[] = array( |
|
| 453 | - 'year' => $date['year'], |
|
| 454 | - 'month' => $date['month'], |
|
| 455 | - 'day' => $date['day'], |
|
| 456 | - ); |
|
| 452 | + $date_query[] = array( |
|
| 453 | + 'year' => $date['year'], |
|
| 454 | + 'month' => $date['month'], |
|
| 455 | + 'day' => $date['day'], |
|
| 456 | + ); |
|
| 457 | 457 | |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 460 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 461 | 461 | |
| 462 | - return $date_query->get_sql(); |
|
| 462 | + return $date_query->get_sql(); |
|
| 463 | 463 | |
| 464 | - } |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | 466 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * This class handles invoice notificaiton emails. |
@@ -28,7 +28,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,35 +119,35 @@ discard block |
||
| 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 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 150 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -159,11 +159,11 @@ discard block |
||
| 159 | 159 | * @param string|array $recipients |
| 160 | 160 | * @param array $extra_args Extra template args. |
| 161 | 161 | */ |
| 162 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 162 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
| 163 | 163 | |
| 164 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 164 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
| 165 | 165 | |
| 166 | - if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) { |
|
| 166 | + if (apply_filters('getpaid_skip_invoice_email', false, $type, $invoice)) { |
|
| 167 | 167 | return; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -171,29 +171,29 @@ discard block |
||
| 171 | 171 | $merge_tags = $email->get_merge_tags(); |
| 172 | 172 | |
| 173 | 173 | $result = $mailer->send( |
| 174 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 175 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 176 | - $email->get_content( $merge_tags, $extra_args ), |
|
| 174 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
| 175 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
| 176 | + $email->get_content($merge_tags, $extra_args), |
|
| 177 | 177 | $email->get_attachments() |
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | 180 | // Maybe send a copy to the admin. |
| 181 | - if ( $email->include_admin_bcc() ) { |
|
| 181 | + if ($email->include_admin_bcc()) { |
|
| 182 | 182 | $mailer->send( |
| 183 | 183 | wpinv_get_admin_email(), |
| 184 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 185 | - $email->get_content( $merge_tags ), |
|
| 184 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
| 185 | + $email->get_content($merge_tags), |
|
| 186 | 186 | $email->get_attachments() |
| 187 | 187 | ); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ( $result ) { |
|
| 191 | - $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 190 | + if ($result) { |
|
| 191 | + $invoice->add_note(sprintf(__('Successfully sent %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
| 192 | 192 | } else { |
| 193 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 193 | + $invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
| 196 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
| 197 | 197 | |
| 198 | 198 | return $result; |
| 199 | 199 | } |
@@ -204,14 +204,14 @@ discard block |
||
| 204 | 204 | * @param array $recipients |
| 205 | 205 | * @param GetPaid_Notification_Email $email |
| 206 | 206 | */ |
| 207 | - public function filter_email_recipients( $recipients, $email ) { |
|
| 207 | + public function filter_email_recipients($recipients, $email) { |
|
| 208 | 208 | |
| 209 | - if ( ! $email->is_admin_email() ) { |
|
| 209 | + if (!$email->is_admin_email()) { |
|
| 210 | 210 | $cc = $email->object->get_email_cc(); |
| 211 | 211 | |
| 212 | - if ( ! empty( $cc ) ) { |
|
| 213 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 214 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 212 | + if (!empty($cc)) { |
|
| 213 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
| 214 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | } |
@@ -225,17 +225,17 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @param WPInv_Invoice $invoice |
| 227 | 227 | */ |
| 228 | - public function new_invoice( $invoice ) { |
|
| 228 | + public function new_invoice($invoice) { |
|
| 229 | 229 | |
| 230 | 230 | // Only send this email for invoices created via the admin page. |
| 231 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 231 | + if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) { |
|
| 232 | 232 | return; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 235 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 236 | 236 | $recipient = wpinv_get_admin_email(); |
| 237 | 237 | |
| 238 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 238 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
@@ -244,12 +244,12 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @param WPInv_Invoice $invoice |
| 246 | 246 | */ |
| 247 | - public function cancelled_invoice( $invoice ) { |
|
| 247 | + public function cancelled_invoice($invoice) { |
|
| 248 | 248 | |
| 249 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 249 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 250 | 250 | $recipient = wpinv_get_admin_email(); |
| 251 | 251 | |
| 252 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 252 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
| 253 | 253 | |
| 254 | 254 | } |
| 255 | 255 | |
@@ -258,12 +258,12 @@ discard block |
||
| 258 | 258 | * |
| 259 | 259 | * @param WPInv_Invoice $invoice |
| 260 | 260 | */ |
| 261 | - public function failed_invoice( $invoice ) { |
|
| 261 | + public function failed_invoice($invoice) { |
|
| 262 | 262 | |
| 263 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 263 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 264 | 264 | $recipient = wpinv_get_admin_email(); |
| 265 | 265 | |
| 266 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 266 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
| 267 | 267 | |
| 268 | 268 | } |
| 269 | 269 | |
@@ -272,12 +272,12 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @param WPInv_Invoice $invoice |
| 274 | 274 | */ |
| 275 | - public function onhold_invoice( $invoice ) { |
|
| 275 | + public function onhold_invoice($invoice) { |
|
| 276 | 276 | |
| 277 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 277 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 278 | 278 | $recipient = $invoice->get_email(); |
| 279 | 279 | |
| 280 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 280 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
| 281 | 281 | |
| 282 | 282 | } |
| 283 | 283 | |
@@ -286,12 +286,12 @@ discard block |
||
| 286 | 286 | * |
| 287 | 287 | * @param WPInv_Invoice $invoice |
| 288 | 288 | */ |
| 289 | - public function processing_invoice( $invoice ) { |
|
| 289 | + public function processing_invoice($invoice) { |
|
| 290 | 290 | |
| 291 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 291 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 292 | 292 | $recipient = $invoice->get_email(); |
| 293 | 293 | |
| 294 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 294 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
| 295 | 295 | |
| 296 | 296 | } |
| 297 | 297 | |
@@ -300,17 +300,17 @@ discard block |
||
| 300 | 300 | * |
| 301 | 301 | * @param WPInv_Invoice $invoice |
| 302 | 302 | */ |
| 303 | - public function completed_invoice( $invoice ) { |
|
| 303 | + public function completed_invoice($invoice) { |
|
| 304 | 304 | |
| 305 | 305 | // (Maybe) abort if it is a renewal invoice. |
| 306 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 306 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
| 307 | 307 | return; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 310 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 311 | 311 | $recipient = $invoice->get_email(); |
| 312 | 312 | |
| 313 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 313 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
| 314 | 314 | |
| 315 | 315 | } |
| 316 | 316 | |
@@ -319,12 +319,12 @@ discard block |
||
| 319 | 319 | * |
| 320 | 320 | * @param WPInv_Invoice $invoice |
| 321 | 321 | */ |
| 322 | - public function refunded_invoice( $invoice ) { |
|
| 322 | + public function refunded_invoice($invoice) { |
|
| 323 | 323 | |
| 324 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 324 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 325 | 325 | $recipient = $invoice->get_email(); |
| 326 | 326 | |
| 327 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 327 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
| 328 | 328 | |
| 329 | 329 | } |
| 330 | 330 | |
@@ -334,21 +334,21 @@ discard block |
||
| 334 | 334 | * @param WPInv_Invoice $invoice |
| 335 | 335 | * @param bool $force |
| 336 | 336 | */ |
| 337 | - public function user_invoice( $invoice, $force = false ) { |
|
| 337 | + public function user_invoice($invoice, $force = false) { |
|
| 338 | 338 | |
| 339 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 339 | + if (!empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | // Only send this email for invoices created via the admin page. |
| 344 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 344 | + if (!$invoice->is_type('invoice') || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
| 345 | 345 | return; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 348 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 349 | 349 | $recipient = $invoice->get_email(); |
| 350 | 350 | |
| 351 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 351 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
| 352 | 352 | |
| 353 | 353 | } |
| 354 | 354 | |
@@ -358,8 +358,8 @@ discard block |
||
| 358 | 358 | * @param int $invoice |
| 359 | 359 | * @return bool |
| 360 | 360 | */ |
| 361 | - public function is_payment_form_invoice( $invoice ) { |
|
| 362 | - return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
| 361 | + public function is_payment_form_invoice($invoice) { |
|
| 362 | + return empty($_GET['getpaid-admin-action']) && ('payment_form' == get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' == get_post_meta($invoice, 'wpinv_created_via', true)); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -368,12 +368,12 @@ discard block |
||
| 368 | 368 | * @param WPInv_Invoice $invoice |
| 369 | 369 | * @param string $note |
| 370 | 370 | */ |
| 371 | - public function user_note( $invoice, $note ) { |
|
| 371 | + public function user_note($invoice, $note) { |
|
| 372 | 372 | |
| 373 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 373 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
| 374 | 374 | $recipient = $invoice->get_email(); |
| 375 | 375 | |
| 376 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 376 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
| 377 | 377 | |
| 378 | 378 | } |
| 379 | 379 | |
@@ -382,9 +382,9 @@ discard block |
||
| 382 | 382 | * |
| 383 | 383 | * @param WPInv_Invoice $invoice |
| 384 | 384 | */ |
| 385 | - public function force_send_overdue_notice( $invoice ) { |
|
| 386 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 387 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 385 | + public function force_send_overdue_notice($invoice) { |
|
| 386 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
| 387 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /** |
@@ -395,37 +395,37 @@ discard block |
||
| 395 | 395 | public function overdue() { |
| 396 | 396 | global $wpdb; |
| 397 | 397 | |
| 398 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 398 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
| 399 | 399 | |
| 400 | 400 | // Fetch reminder days. |
| 401 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 401 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
| 402 | 402 | |
| 403 | 403 | // Abort if non is set. |
| 404 | - if ( empty( $reminder_days ) ) { |
|
| 404 | + if (empty($reminder_days)) { |
|
| 405 | 405 | return; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | // Retrieve date query. |
| 409 | - $date_query = $this->get_date_query( $reminder_days ); |
|
| 409 | + $date_query = $this->get_date_query($reminder_days); |
|
| 410 | 410 | |
| 411 | 411 | // Invoices table. |
| 412 | 412 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 413 | 413 | |
| 414 | 414 | // Fetch invoices. |
| 415 | - $invoices = $wpdb->get_col( |
|
| 415 | + $invoices = $wpdb->get_col( |
|
| 416 | 416 | "SELECT posts.ID FROM $wpdb->posts as posts |
| 417 | 417 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
| 418 | 418 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
| 419 | 419 | |
| 420 | - foreach ( $invoices as $invoice ) { |
|
| 420 | + foreach ($invoices as $invoice) { |
|
| 421 | 421 | |
| 422 | 422 | // Only send this email for invoices created via the admin page. |
| 423 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 424 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 423 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
| 424 | + $invoice = new WPInv_Invoice($invoice); |
|
| 425 | 425 | $email->object = $invoice; |
| 426 | 426 | |
| 427 | - if ( $invoice->needs_payment() ) { |
|
| 428 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 427 | + if ($invoice->needs_payment()) { |
|
| 428 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | } |
@@ -440,14 +440,14 @@ discard block |
||
| 440 | 440 | * @param array $reminder_days |
| 441 | 441 | * @return string |
| 442 | 442 | */ |
| 443 | - public function get_date_query( $reminder_days ) { |
|
| 443 | + public function get_date_query($reminder_days) { |
|
| 444 | 444 | |
| 445 | 445 | $date_query = array( |
| 446 | 446 | 'relation' => 'OR' |
| 447 | 447 | ); |
| 448 | 448 | |
| 449 | - foreach ( $reminder_days as $days ) { |
|
| 450 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 449 | + foreach ($reminder_days as $days) { |
|
| 450 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
| 451 | 451 | |
| 452 | 452 | $date_query[] = array( |
| 453 | 453 | 'year' => $date['year'], |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 460 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
| 461 | 461 | |
| 462 | 462 | return $date_query->get_sql(); |
| 463 | 463 | |
@@ -13,288 +13,288 @@ |
||
| 13 | 13 | class GetPaid_Subscription_Notification_Emails { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * The array of subscription email actions. |
|
| 17 | - * |
|
| 18 | - * @param array |
|
| 19 | - */ |
|
| 20 | - public $subscription_actions; |
|
| 16 | + * The array of subscription email actions. |
|
| 17 | + * |
|
| 18 | + * @param array |
|
| 19 | + */ |
|
| 20 | + public $subscription_actions; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Class constructor |
|
| 23 | + * Class constructor |
|
| 24 | 24 | * |
| 25 | - */ |
|
| 26 | - public function __construct() { |
|
| 27 | - |
|
| 28 | - $this->subscription_actions = apply_filters( |
|
| 29 | - 'getpaid_notification_email_subscription_triggers', |
|
| 30 | - array( |
|
| 31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
| 32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
| 33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
| 34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
| 35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
| 36 | - ) |
|
| 37 | - ); |
|
| 38 | - |
|
| 39 | - $this->init_hooks(); |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + |
|
| 28 | + $this->subscription_actions = apply_filters( |
|
| 29 | + 'getpaid_notification_email_subscription_triggers', |
|
| 30 | + array( |
|
| 31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
| 32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
| 33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
| 34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
| 35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
| 36 | + ) |
|
| 37 | + ); |
|
| 38 | + |
|
| 39 | + $this->init_hooks(); |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Registers email hooks. |
|
| 45 | - */ |
|
| 46 | - public function init_hooks() { |
|
| 47 | - |
|
| 48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 50 | - |
|
| 51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
| 52 | - |
|
| 53 | - if ( ! $email->is_active() ) { |
|
| 54 | - continue; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( method_exists( $this, $email_type ) ) { |
|
| 58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 59 | - continue; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 63 | - |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Filters subscription merge tags. |
|
| 70 | - * |
|
| 71 | - * @param array $merge_tags |
|
| 72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 73 | - */ |
|
| 74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 75 | - |
|
| 76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 77 | - $merge_tags = array_merge( |
|
| 78 | - $merge_tags, |
|
| 79 | - $this->get_subscription_merge_tags( $object ) |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return $merge_tags; |
|
| 84 | - |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Generates subscription merge tags. |
|
| 89 | - * |
|
| 90 | - * @param WPInv_Subscription $subscription |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function get_subscription_merge_tags( $subscription ) { |
|
| 94 | - |
|
| 95 | - // Abort if it does not exist. |
|
| 96 | - if ( ! $subscription->get_id() ) { |
|
| 97 | - return array(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $invoice = $subscription->get_parent_invoice(); |
|
| 101 | - return array( |
|
| 102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
| 111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Checks if we should send a notification for a subscription. |
|
| 118 | - * |
|
| 119 | - * @param WPInv_Invoice $invoice |
|
| 120 | - * @return bool |
|
| 121 | - */ |
|
| 122 | - public function should_send_notification( $invoice ) { |
|
| 123 | - return 0 != $invoice->get_id(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Returns notification recipients. |
|
| 128 | - * |
|
| 129 | - * @param WPInv_Invoice $invoice |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - public function get_recipients( $invoice ) { |
|
| 133 | - $recipients = array( $invoice->get_email() ); |
|
| 134 | - |
|
| 135 | - $cc = $invoice->get_email_cc(); |
|
| 136 | - |
|
| 137 | - if ( ! empty( $cc ) ) { |
|
| 138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $recipients; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Helper function to send an email. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Subscription $subscription |
|
| 149 | - * @param GetPaid_Notification_Email $email |
|
| 150 | - * @param string $type |
|
| 151 | - * @param array $extra_args Extra template args. |
|
| 152 | - */ |
|
| 153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 154 | - |
|
| 155 | - // Abort in case the parent invoice does not exist. |
|
| 156 | - $invoice = $subscription->get_parent_invoice(); |
|
| 157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 162 | - return; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 166 | - |
|
| 167 | - $recipients = $this->get_recipients( $invoice ); |
|
| 168 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 169 | - $merge_tags = $email->get_merge_tags(); |
|
| 170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 172 | - $attachments = $email->get_attachments(); |
|
| 173 | - |
|
| 174 | - $result = $mailer->send( |
|
| 175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 176 | - $subject, |
|
| 177 | - $content, |
|
| 178 | - $attachments |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - // Maybe send a copy to the admin. |
|
| 182 | - if ( $email->include_admin_bcc() ) { |
|
| 183 | - $mailer->send( |
|
| 184 | - wpinv_get_admin_email(), |
|
| 185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 186 | - $content, |
|
| 187 | - $attachments |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if ( $result ) { |
|
| 192 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 193 | - } else { |
|
| 194 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 198 | - |
|
| 199 | - } |
|
| 44 | + * Registers email hooks. |
|
| 45 | + */ |
|
| 46 | + public function init_hooks() { |
|
| 47 | + |
|
| 48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 50 | + |
|
| 51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
| 52 | + |
|
| 53 | + if ( ! $email->is_active() ) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( method_exists( $this, $email_type ) ) { |
|
| 58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 59 | + continue; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 63 | + |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + } |
|
| 200 | 67 | |
| 201 | 68 | /** |
| 202 | - * Sends a new trial notification. |
|
| 203 | - * |
|
| 204 | - * @param WPInv_Subscription $subscription |
|
| 205 | - */ |
|
| 206 | - public function subscription_trial( $subscription ) { |
|
| 69 | + * Filters subscription merge tags. |
|
| 70 | + * |
|
| 71 | + * @param array $merge_tags |
|
| 72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 73 | + */ |
|
| 74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 207 | 75 | |
| 208 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 209 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 77 | + $merge_tags = array_merge( |
|
| 78 | + $merge_tags, |
|
| 79 | + $this->get_subscription_merge_tags( $object ) |
|
| 80 | + ); |
|
| 81 | + } |
|
| 210 | 82 | |
| 211 | - } |
|
| 83 | + return $merge_tags; |
|
| 212 | 84 | |
| 213 | - /** |
|
| 214 | - * Sends a cancelled subscription notification. |
|
| 215 | - * |
|
| 216 | - * @param WPInv_Subscription $subscription |
|
| 217 | - */ |
|
| 218 | - public function subscription_cancelled( $subscription ) { |
|
| 85 | + } |
|
| 219 | 86 | |
| 220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 87 | + /** |
|
| 88 | + * Generates subscription merge tags. |
|
| 89 | + * |
|
| 90 | + * @param WPInv_Subscription $subscription |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function get_subscription_merge_tags( $subscription ) { |
|
| 94 | + |
|
| 95 | + // Abort if it does not exist. |
|
| 96 | + if ( ! $subscription->get_id() ) { |
|
| 97 | + return array(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $invoice = $subscription->get_parent_invoice(); |
|
| 101 | + return array( |
|
| 102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
| 111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 112 | + ); |
|
| 222 | 113 | |
| 223 | - } |
|
| 114 | + } |
|
| 224 | 115 | |
| 225 | - /** |
|
| 226 | - * Sends a subscription expired notification. |
|
| 227 | - * |
|
| 228 | - * @param WPInv_Subscription $subscription |
|
| 229 | - */ |
|
| 230 | - public function subscription_expired( $subscription ) { |
|
| 116 | + /** |
|
| 117 | + * Checks if we should send a notification for a subscription. |
|
| 118 | + * |
|
| 119 | + * @param WPInv_Invoice $invoice |
|
| 120 | + * @return bool |
|
| 121 | + */ |
|
| 122 | + public function should_send_notification( $invoice ) { |
|
| 123 | + return 0 != $invoice->get_id(); |
|
| 124 | + } |
|
| 231 | 125 | |
| 232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 126 | + /** |
|
| 127 | + * Returns notification recipients. |
|
| 128 | + * |
|
| 129 | + * @param WPInv_Invoice $invoice |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + public function get_recipients( $invoice ) { |
|
| 133 | + $recipients = array( $invoice->get_email() ); |
|
| 234 | 134 | |
| 235 | - } |
|
| 135 | + $cc = $invoice->get_email_cc(); |
|
| 236 | 136 | |
| 237 | - /** |
|
| 238 | - * Sends a completed subscription notification. |
|
| 239 | - * |
|
| 240 | - * @param WPInv_Subscription $subscription |
|
| 241 | - */ |
|
| 242 | - public function subscription_complete( $subscription ) { |
|
| 137 | + if ( ! empty( $cc ) ) { |
|
| 138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 140 | + } |
|
| 243 | 141 | |
| 244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 142 | + return $recipients; |
|
| 143 | + } |
|
| 246 | 144 | |
| 247 | - } |
|
| 145 | + /** |
|
| 146 | + * Helper function to send an email. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Subscription $subscription |
|
| 149 | + * @param GetPaid_Notification_Email $email |
|
| 150 | + * @param string $type |
|
| 151 | + * @param array $extra_args Extra template args. |
|
| 152 | + */ |
|
| 153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 154 | + |
|
| 155 | + // Abort in case the parent invoice does not exist. |
|
| 156 | + $invoice = $subscription->get_parent_invoice(); |
|
| 157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 162 | + return; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 166 | + |
|
| 167 | + $recipients = $this->get_recipients( $invoice ); |
|
| 168 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 169 | + $merge_tags = $email->get_merge_tags(); |
|
| 170 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 171 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 172 | + $attachments = $email->get_attachments(); |
|
| 173 | + |
|
| 174 | + $result = $mailer->send( |
|
| 175 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 176 | + $subject, |
|
| 177 | + $content, |
|
| 178 | + $attachments |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + // Maybe send a copy to the admin. |
|
| 182 | + if ( $email->include_admin_bcc() ) { |
|
| 183 | + $mailer->send( |
|
| 184 | + wpinv_get_admin_email(), |
|
| 185 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 186 | + $content, |
|
| 187 | + $attachments |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if ( $result ) { |
|
| 192 | + $subscription->get_parent_invoice()->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 193 | + } else { |
|
| 194 | + $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 248 | 198 | |
| 249 | - /** |
|
| 250 | - * Sends a subscription renewal reminder notification. |
|
| 251 | - * |
|
| 252 | - */ |
|
| 253 | - public function renewal_reminder() { |
|
| 199 | + } |
|
| 254 | 200 | |
| 255 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 201 | + /** |
|
| 202 | + * Sends a new trial notification. |
|
| 203 | + * |
|
| 204 | + * @param WPInv_Subscription $subscription |
|
| 205 | + */ |
|
| 206 | + public function subscription_trial( $subscription ) { |
|
| 256 | 207 | |
| 257 | - // Fetch reminder days. |
|
| 258 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 208 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 209 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 259 | 210 | |
| 260 | - // Abort if non is set. |
|
| 261 | - if ( empty( $reminder_days ) ) { |
|
| 262 | - return; |
|
| 263 | - } |
|
| 211 | + } |
|
| 264 | 212 | |
| 265 | - // Fetch matching subscriptions. |
|
| 213 | + /** |
|
| 214 | + * Sends a cancelled subscription notification. |
|
| 215 | + * |
|
| 216 | + * @param WPInv_Subscription $subscription |
|
| 217 | + */ |
|
| 218 | + public function subscription_cancelled( $subscription ) { |
|
| 219 | + |
|
| 220 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 221 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 222 | + |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Sends a subscription expired notification. |
|
| 227 | + * |
|
| 228 | + * @param WPInv_Subscription $subscription |
|
| 229 | + */ |
|
| 230 | + public function subscription_expired( $subscription ) { |
|
| 231 | + |
|
| 232 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 234 | + |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Sends a completed subscription notification. |
|
| 239 | + * |
|
| 240 | + * @param WPInv_Subscription $subscription |
|
| 241 | + */ |
|
| 242 | + public function subscription_complete( $subscription ) { |
|
| 243 | + |
|
| 244 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Sends a subscription renewal reminder notification. |
|
| 251 | + * |
|
| 252 | + */ |
|
| 253 | + public function renewal_reminder() { |
|
| 254 | + |
|
| 255 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 256 | + |
|
| 257 | + // Fetch reminder days. |
|
| 258 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 259 | + |
|
| 260 | + // Abort if non is set. |
|
| 261 | + if ( empty( $reminder_days ) ) { |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + // Fetch matching subscriptions. |
|
| 266 | 266 | $args = array( |
| 267 | 267 | 'number' => -1, |
| 268 | - 'count_total' => false, |
|
| 269 | - 'status' => 'trialling active', |
|
| 268 | + 'count_total' => false, |
|
| 269 | + 'status' => 'trialling active', |
|
| 270 | 270 | 'date_expires_query' => array( |
| 271 | - 'relation' => 'OR' |
|
| 271 | + 'relation' => 'OR' |
|
| 272 | 272 | ), |
| 273 | - ); |
|
| 273 | + ); |
|
| 274 | 274 | |
| 275 | - foreach ( $reminder_days as $days ) { |
|
| 276 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 275 | + foreach ( $reminder_days as $days ) { |
|
| 276 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 277 | 277 | |
| 278 | - $args['date_expires_query'][] = array( |
|
| 279 | - 'year' => $date['year'], |
|
| 280 | - 'month' => $date['month'], |
|
| 281 | - 'day' => $date['day'], |
|
| 282 | - ); |
|
| 278 | + $args['date_expires_query'][] = array( |
|
| 279 | + 'year' => $date['year'], |
|
| 280 | + 'month' => $date['month'], |
|
| 281 | + 'day' => $date['day'], |
|
| 282 | + ); |
|
| 283 | 283 | |
| 284 | - } |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 286 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 287 | 287 | |
| 288 | 288 | foreach ( $subscriptions as $subscription ) { |
| 289 | 289 | |
| 290 | - // Skip packages. |
|
| 291 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
| 292 | - $email->object = $subscription; |
|
| 293 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 294 | - } |
|
| 290 | + // Skip packages. |
|
| 291 | + if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
| 292 | + $email->object = $subscription; |
|
| 293 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - } |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | 300 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * This class handles subscription notificaiton emails. |
@@ -45,21 +45,21 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function init_hooks() { |
| 47 | 47 | |
| 48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 48 | + add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2); |
|
| 49 | + foreach ($this->subscription_actions as $hook => $email_type) { |
|
| 50 | 50 | |
| 51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
| 51 | + $email = new GetPaid_Notification_Email($email_type); |
|
| 52 | 52 | |
| 53 | - if ( ! $email->is_active() ) { |
|
| 53 | + if (!$email->is_active()) { |
|
| 54 | 54 | continue; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( method_exists( $this, $email_type ) ) { |
|
| 58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 57 | + if (method_exists($this, $email_type)) { |
|
| 58 | + add_action($hook, array($this, $email_type), 100, 2); |
|
| 59 | 59 | continue; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 62 | + do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook); |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | * @param array $merge_tags |
| 72 | 72 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
| 73 | 73 | */ |
| 74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 74 | + public function subscription_merge_tags($merge_tags, $object) { |
|
| 75 | 75 | |
| 76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 76 | + if (is_a($object, 'WPInv_Subscription')) { |
|
| 77 | 77 | $merge_tags = array_merge( |
| 78 | 78 | $merge_tags, |
| 79 | - $this->get_subscription_merge_tags( $object ) |
|
| 79 | + $this->get_subscription_merge_tags($object) |
|
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -90,25 +90,25 @@ discard block |
||
| 90 | 90 | * @param WPInv_Subscription $subscription |
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | - public function get_subscription_merge_tags( $subscription ) { |
|
| 93 | + public function get_subscription_merge_tags($subscription) { |
|
| 94 | 94 | |
| 95 | 95 | // Abort if it does not exist. |
| 96 | - if ( ! $subscription->get_id() ) { |
|
| 96 | + if (!$subscription->get_id()) { |
|
| 97 | 97 | return array(); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $invoice = $subscription->get_parent_invoice(); |
|
| 100 | + $invoice = $subscription->get_parent_invoice(); |
|
| 101 | 101 | return array( |
| 102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 102 | + '{subscription_renewal_date}' => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')), |
|
| 103 | + '{subscription_created}' => getpaid_format_date_value($subscription->get_date_created()), |
|
| 104 | + '{subscription_status}' => sanitize_text_field($subscription->get_status_label()), |
|
| 105 | + '{subscription_profile_id}' => sanitize_text_field($subscription->get_profile_id()), |
|
| 106 | + '{subscription_id}' => absint($subscription->get_id()), |
|
| 107 | + '{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())), |
|
| 108 | + '{subscription_initial_amount}' => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())), |
|
| 109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''), |
|
| 110 | 110 | '{subscription_bill_times}' => $subscription->get_bill_times(), |
| 111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 111 | + '{subscription_url}' => esc_url($subscription->get_view_url()), |
|
| 112 | 112 | ); |
| 113 | 113 | |
| 114 | 114 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param WPInv_Invoice $invoice |
| 120 | 120 | * @return bool |
| 121 | 121 | */ |
| 122 | - public function should_send_notification( $invoice ) { |
|
| 122 | + public function should_send_notification($invoice) { |
|
| 123 | 123 | return 0 != $invoice->get_id(); |
| 124 | 124 | } |
| 125 | 125 | |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * @param WPInv_Invoice $invoice |
| 130 | 130 | * @return array |
| 131 | 131 | */ |
| 132 | - public function get_recipients( $invoice ) { |
|
| 133 | - $recipients = array( $invoice->get_email() ); |
|
| 132 | + public function get_recipients($invoice) { |
|
| 133 | + $recipients = array($invoice->get_email()); |
|
| 134 | 134 | |
| 135 | 135 | $cc = $invoice->get_email_cc(); |
| 136 | 136 | |
| 137 | - if ( ! empty( $cc ) ) { |
|
| 138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 137 | + if (!empty($cc)) { |
|
| 138 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
| 139 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | return $recipients; |
@@ -150,51 +150,51 @@ discard block |
||
| 150 | 150 | * @param string $type |
| 151 | 151 | * @param array $extra_args Extra template args. |
| 152 | 152 | */ |
| 153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 153 | + public function send_email($subscription, $email, $type, $extra_args = array()) { |
|
| 154 | 154 | |
| 155 | 155 | // Abort in case the parent invoice does not exist. |
| 156 | 156 | $invoice = $subscription->get_parent_invoice(); |
| 157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 157 | + if (!$this->should_send_notification($invoice)) { |
|
| 158 | 158 | return; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 161 | + if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) { |
|
| 162 | 162 | return; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 165 | + do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email); |
|
| 166 | 166 | |
| 167 | - $recipients = $this->get_recipients( $invoice ); |
|
| 167 | + $recipients = $this->get_recipients($invoice); |
|
| 168 | 168 | $mailer = new GetPaid_Notification_Email_Sender(); |
| 169 | 169 | $merge_tags = $email->get_merge_tags(); |
| 170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 170 | + $content = $email->get_content($merge_tags, $extra_args); |
|
| 171 | + $subject = $email->add_merge_tags($email->get_subject(), $merge_tags); |
|
| 172 | 172 | $attachments = $email->get_attachments(); |
| 173 | 173 | |
| 174 | 174 | $result = $mailer->send( |
| 175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 175 | + apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email), |
|
| 176 | 176 | $subject, |
| 177 | 177 | $content, |
| 178 | 178 | $attachments |
| 179 | 179 | ); |
| 180 | 180 | |
| 181 | 181 | // Maybe send a copy to the admin. |
| 182 | - if ( $email->include_admin_bcc() ) { |
|
| 182 | + if ($email->include_admin_bcc()) { |
|
| 183 | 183 | $mailer->send( |
| 184 | 184 | wpinv_get_admin_email(), |
| 185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 185 | + $subject . __(' - ADMIN BCC COPY', 'invoicing'), |
|
| 186 | 186 | $content, |
| 187 | 187 | $attachments |
| 188 | 188 | ); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( $result ) { |
|
| 192 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 191 | + if ($result) { |
|
| 192 | + $subscription->get_parent_invoice()->add_note(sprintf(__('Successfully sent %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
| 193 | 193 | } else { |
| 194 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
| 194 | + $subscription->get_parent_invoice()->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 197 | + do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email); |
|
| 198 | 198 | |
| 199 | 199 | } |
| 200 | 200 | |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @param WPInv_Subscription $subscription |
| 205 | 205 | */ |
| 206 | - public function subscription_trial( $subscription ) { |
|
| 206 | + public function subscription_trial($subscription) { |
|
| 207 | 207 | |
| 208 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 209 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 208 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
| 209 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 210 | 210 | |
| 211 | 211 | } |
| 212 | 212 | |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | * |
| 216 | 216 | * @param WPInv_Subscription $subscription |
| 217 | 217 | */ |
| 218 | - public function subscription_cancelled( $subscription ) { |
|
| 218 | + public function subscription_cancelled($subscription) { |
|
| 219 | 219 | |
| 220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 220 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
| 221 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | * |
| 228 | 228 | * @param WPInv_Subscription $subscription |
| 229 | 229 | */ |
| 230 | - public function subscription_expired( $subscription ) { |
|
| 230 | + public function subscription_expired($subscription) { |
|
| 231 | 231 | |
| 232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 232 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
| 233 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
@@ -239,10 +239,10 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @param WPInv_Subscription $subscription |
| 241 | 241 | */ |
| 242 | - public function subscription_complete( $subscription ) { |
|
| 242 | + public function subscription_complete($subscription) { |
|
| 243 | 243 | |
| 244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 244 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
| 245 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 246 | 246 | |
| 247 | 247 | } |
| 248 | 248 | |
@@ -252,18 +252,18 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | public function renewal_reminder() { |
| 254 | 254 | |
| 255 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 255 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
| 256 | 256 | |
| 257 | 257 | // Fetch reminder days. |
| 258 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 258 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
| 259 | 259 | |
| 260 | 260 | // Abort if non is set. |
| 261 | - if ( empty( $reminder_days ) ) { |
|
| 261 | + if (empty($reminder_days)) { |
|
| 262 | 262 | return; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | // Fetch matching subscriptions. |
| 266 | - $args = array( |
|
| 266 | + $args = array( |
|
| 267 | 267 | 'number' => -1, |
| 268 | 268 | 'count_total' => false, |
| 269 | 269 | 'status' => 'trialling active', |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | ), |
| 273 | 273 | ); |
| 274 | 274 | |
| 275 | - foreach ( $reminder_days as $days ) { |
|
| 276 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 275 | + foreach ($reminder_days as $days) { |
|
| 276 | + $date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp')))); |
|
| 277 | 277 | |
| 278 | 278 | $args['date_expires_query'][] = array( |
| 279 | 279 | 'year' => $date['year'], |
@@ -283,14 +283,14 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 286 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
| 287 | 287 | |
| 288 | - foreach ( $subscriptions as $subscription ) { |
|
| 288 | + foreach ($subscriptions as $subscription) { |
|
| 289 | 289 | |
| 290 | 290 | // Skip packages. |
| 291 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
| 291 | + if (get_post_meta($subscription->get_product_id(), '_wpinv_type', true) != 'package') { |
|
| 292 | 292 | $email->object = $subscription; |
| 293 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 293 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | } |