@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | - exit; // Exit if accessed directly |
|
| 9 | + exit; // Exit if accessed directly |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | class GetPaid_Meta_Box_Invoice_Subscription { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Output the subscription metabox. |
|
| 19 | - * |
|
| 20 | - * @param WP_Post $post |
|
| 21 | - */ |
|
| 18 | + * Output the subscription metabox. |
|
| 19 | + * |
|
| 20 | + * @param WP_Post $post |
|
| 21 | + */ |
|
| 22 | 22 | public static function output( $post ) { |
| 23 | 23 | |
| 24 | 24 | // Fetch the invoice. |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Output the subscription invoices. |
|
| 38 | - * |
|
| 39 | - * @param WP_Post $post |
|
| 40 | - */ |
|
| 37 | + * Output the subscription invoices. |
|
| 38 | + * |
|
| 39 | + * @param WP_Post $post |
|
| 40 | + */ |
|
| 41 | 41 | public static function output_invoices( $post ) { |
| 42 | 42 | |
| 43 | 43 | // Fetch the invoice. |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | - * Outputs related subscriptions. |
|
| 57 | - * |
|
| 58 | - * @param WP_Post $post |
|
| 59 | - */ |
|
| 56 | + * Outputs related subscriptions. |
|
| 57 | + * |
|
| 58 | + * @param WP_Post $post |
|
| 59 | + */ |
|
| 60 | 60 | public static function output_related( $post ) { |
| 61 | 61 | |
| 62 | 62 | // Fetch the invoice. |
@@ -16,165 +16,165 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class GetPaid_MaxMind_Geolocation { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The service responsible for interacting with the MaxMind database. |
|
| 21 | - * |
|
| 22 | - * @var GetPaid_MaxMind_Database_Service |
|
| 23 | - */ |
|
| 24 | - private $database_service; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Initialize the integration. |
|
| 28 | - */ |
|
| 29 | - public function __construct() { |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Supports overriding the database service to be used. |
|
| 33 | - * |
|
| 34 | - * @since 1.0.19 |
|
| 35 | - * @return mixed|null The geolocation database service. |
|
| 36 | - */ |
|
| 37 | - $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
| 38 | - if ( null === $this->database_service ) { |
|
| 39 | - $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - // Bind to the scheduled updater action. |
|
| 43 | - add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
| 44 | - |
|
| 45 | - // Bind to the geolocation filter for MaxMind database lookups. |
|
| 46 | - add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
| 47 | - |
|
| 48 | - // Handle maxmind key updates. |
|
| 49 | - add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Get database service. |
|
| 55 | - * |
|
| 56 | - * @return GetPaid_MaxMind_Database_Service|null |
|
| 57 | - */ |
|
| 58 | - public function get_database_service() { |
|
| 59 | - return $this->database_service; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Checks to make sure that the license key is valid. |
|
| 64 | - * |
|
| 65 | - * @param string $license_key The new license key. |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function handle_key_updates( $license_key ) { |
|
| 69 | - |
|
| 70 | - // Trim whitespaces and strip slashes. |
|
| 71 | - $license_key = trim( $license_key ); |
|
| 72 | - |
|
| 73 | - // Abort if the license key is empty or unchanged. |
|
| 74 | - if ( empty( $license_key ) ) { |
|
| 75 | - return $license_key; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // Abort if a database exists and the license key is unchaged. |
|
| 79 | - if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
| 80 | - return $license_key; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Check the license key by attempting to download the Geolocation database. |
|
| 84 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
| 85 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
| 86 | - getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
| 87 | - return $license_key; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
| 91 | - |
|
| 92 | - return $license_key; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Updates the database used for geolocation queries. |
|
| 97 | - * |
|
| 98 | - * @param string $tmp_database_path Temporary database path. |
|
| 99 | - */ |
|
| 100 | - public function update_database( $tmp_database_path = null ) { |
|
| 101 | - |
|
| 102 | - // Allow us to easily interact with the filesystem. |
|
| 103 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
| 104 | - WP_Filesystem(); |
|
| 105 | - global $wp_filesystem; |
|
| 106 | - |
|
| 107 | - // Remove any existing archives to comply with the MaxMind TOS. |
|
| 108 | - $target_database_path = $this->database_service->get_database_path(); |
|
| 109 | - |
|
| 110 | - // If there's no database path, we can't store the database. |
|
| 111 | - if ( empty( $target_database_path ) ) { |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
| 116 | - $wp_filesystem->delete( $target_database_path ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // We can't download a database if there's no license key configured. |
|
| 120 | - $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
| 121 | - if ( empty( $license_key ) ) { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if ( empty( $tmp_database_path ) ) { |
|
| 126 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
| 130 | - wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
| 131 | - return; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Move the new database into position. |
|
| 135 | - $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
| 136 | - $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
| 141 | - * |
|
| 142 | - * @param array $data Geolocation data. |
|
| 143 | - * @param string $ip_address The IP address to geolocate. |
|
| 144 | - * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
| 145 | - */ |
|
| 146 | - public function get_geolocation( $data, $ip_address ) { |
|
| 147 | - |
|
| 148 | - if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
| 149 | - return $data; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
| 153 | - |
|
| 154 | - return array( |
|
| 155 | - 'country' => $country_code, |
|
| 156 | - 'state' => '', |
|
| 157 | - 'city' => '', |
|
| 158 | - 'postcode' => '', |
|
| 159 | - ); |
|
| 160 | - |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Fetches the prefix for the MaxMind database file. |
|
| 165 | - * |
|
| 166 | - * @return string |
|
| 167 | - */ |
|
| 168 | - private function get_database_prefix() { |
|
| 169 | - |
|
| 170 | - $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
| 171 | - |
|
| 172 | - if ( empty( $prefix ) ) { |
|
| 173 | - $prefix = md5( uniqid( 'wpinv' ) ); |
|
| 174 | - update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $prefix; |
|
| 178 | - } |
|
| 19 | + /** |
|
| 20 | + * The service responsible for interacting with the MaxMind database. |
|
| 21 | + * |
|
| 22 | + * @var GetPaid_MaxMind_Database_Service |
|
| 23 | + */ |
|
| 24 | + private $database_service; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Initialize the integration. |
|
| 28 | + */ |
|
| 29 | + public function __construct() { |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Supports overriding the database service to be used. |
|
| 33 | + * |
|
| 34 | + * @since 1.0.19 |
|
| 35 | + * @return mixed|null The geolocation database service. |
|
| 36 | + */ |
|
| 37 | + $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
| 38 | + if ( null === $this->database_service ) { |
|
| 39 | + $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + // Bind to the scheduled updater action. |
|
| 43 | + add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
| 44 | + |
|
| 45 | + // Bind to the geolocation filter for MaxMind database lookups. |
|
| 46 | + add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
| 47 | + |
|
| 48 | + // Handle maxmind key updates. |
|
| 49 | + add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Get database service. |
|
| 55 | + * |
|
| 56 | + * @return GetPaid_MaxMind_Database_Service|null |
|
| 57 | + */ |
|
| 58 | + public function get_database_service() { |
|
| 59 | + return $this->database_service; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Checks to make sure that the license key is valid. |
|
| 64 | + * |
|
| 65 | + * @param string $license_key The new license key. |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function handle_key_updates( $license_key ) { |
|
| 69 | + |
|
| 70 | + // Trim whitespaces and strip slashes. |
|
| 71 | + $license_key = trim( $license_key ); |
|
| 72 | + |
|
| 73 | + // Abort if the license key is empty or unchanged. |
|
| 74 | + if ( empty( $license_key ) ) { |
|
| 75 | + return $license_key; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // Abort if a database exists and the license key is unchaged. |
|
| 79 | + if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
| 80 | + return $license_key; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Check the license key by attempting to download the Geolocation database. |
|
| 84 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
| 85 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
| 86 | + getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
| 87 | + return $license_key; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
| 91 | + |
|
| 92 | + return $license_key; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Updates the database used for geolocation queries. |
|
| 97 | + * |
|
| 98 | + * @param string $tmp_database_path Temporary database path. |
|
| 99 | + */ |
|
| 100 | + public function update_database( $tmp_database_path = null ) { |
|
| 101 | + |
|
| 102 | + // Allow us to easily interact with the filesystem. |
|
| 103 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
| 104 | + WP_Filesystem(); |
|
| 105 | + global $wp_filesystem; |
|
| 106 | + |
|
| 107 | + // Remove any existing archives to comply with the MaxMind TOS. |
|
| 108 | + $target_database_path = $this->database_service->get_database_path(); |
|
| 109 | + |
|
| 110 | + // If there's no database path, we can't store the database. |
|
| 111 | + if ( empty( $target_database_path ) ) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
| 116 | + $wp_filesystem->delete( $target_database_path ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // We can't download a database if there's no license key configured. |
|
| 120 | + $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
| 121 | + if ( empty( $license_key ) ) { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if ( empty( $tmp_database_path ) ) { |
|
| 126 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
| 130 | + wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
| 131 | + return; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Move the new database into position. |
|
| 135 | + $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
| 136 | + $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
| 141 | + * |
|
| 142 | + * @param array $data Geolocation data. |
|
| 143 | + * @param string $ip_address The IP address to geolocate. |
|
| 144 | + * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
| 145 | + */ |
|
| 146 | + public function get_geolocation( $data, $ip_address ) { |
|
| 147 | + |
|
| 148 | + if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
| 149 | + return $data; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
| 153 | + |
|
| 154 | + return array( |
|
| 155 | + 'country' => $country_code, |
|
| 156 | + 'state' => '', |
|
| 157 | + 'city' => '', |
|
| 158 | + 'postcode' => '', |
|
| 159 | + ); |
|
| 160 | + |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Fetches the prefix for the MaxMind database file. |
|
| 165 | + * |
|
| 166 | + * @return string |
|
| 167 | + */ |
|
| 168 | + private function get_database_prefix() { |
|
| 169 | + |
|
| 170 | + $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
| 171 | + |
|
| 172 | + if ( empty( $prefix ) ) { |
|
| 173 | + $prefix = md5( uniqid( 'wpinv' ) ); |
|
| 174 | + update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $prefix; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | } |
@@ -20,13 +20,13 @@ |
||
| 20 | 20 | <title><?php esc_html_e( 'GetPaid › Setup Wizard', 'invoicing' ); ?></title> |
| 21 | 21 | <?php |
| 22 | 22 | getpaid_admin()->enqeue_scripts(); |
| 23 | - wp_enqueue_style( 'font-awesome', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), 'v5.13.0' ); |
|
| 24 | - wp_print_styles( 'select2' ); |
|
| 23 | + wp_enqueue_style( 'font-awesome', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), 'v5.13.0' ); |
|
| 24 | + wp_print_styles( 'select2' ); |
|
| 25 | 25 | wp_print_scripts( 'select2' ); |
| 26 | - wp_print_scripts( 'wpinv-admin-script' ); |
|
| 26 | + wp_print_scripts( 'wpinv-admin-script' ); |
|
| 27 | 27 | do_action( 'admin_print_styles' ); |
| 28 | 28 | do_action( 'admin_head' ); |
| 29 | - ?> |
|
| 29 | + ?> |
|
| 30 | 30 | <style> |
| 31 | 31 | body, p{ |
| 32 | 32 | font-size: 16px; |
@@ -15,12 +15,12 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | - exit; |
|
| 18 | + exit; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) { |
| 22 | - // include the class if needed |
|
| 23 | - include_once( dirname( __FILE__ ) . "/wp-deactivation-survey.php" ); |
|
| 22 | + // include the class if needed |
|
| 23 | + include_once( dirname( __FILE__ ) . "/wp-deactivation-survey.php" ); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -36,6 +36,6 @@ discard block |
||
| 36 | 36 | //}); |
| 37 | 37 | |
| 38 | 38 | AyeCode_Deactivation_Survey::instance(array( |
| 39 | - 'slug' => 'ayecode-deactivation-survey-testing', |
|
| 40 | - 'version' => '1.0.0' |
|
| 39 | + 'slug' => 'ayecode-deactivation-survey-testing', |
|
| 40 | + 'version' => '1.0.0' |
|
| 41 | 41 | )); |
| 42 | 42 | \ No newline at end of file |
@@ -14,133 +14,133 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class GetPaid_WP_All_Import { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var RapidAddon[] |
|
| 19 | - */ |
|
| 20 | - protected $add_ons; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $datastores = array( |
|
| 26 | - 'item' =>'WPInv_Item', |
|
| 27 | - 'invoice' =>'WPInv_Invoice', |
|
| 28 | - 'discount' =>'WPInv_Discount', |
|
| 29 | - ); |
|
| 17 | + /** |
|
| 18 | + * @var RapidAddon[] |
|
| 19 | + */ |
|
| 20 | + protected $add_ons; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $datastores = array( |
|
| 26 | + 'item' =>'WPInv_Item', |
|
| 27 | + 'invoice' =>'WPInv_Invoice', |
|
| 28 | + 'discount' =>'WPInv_Discount', |
|
| 29 | + ); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * Class constructor. |
|
| 33 | - */ |
|
| 32 | + * Class constructor. |
|
| 33 | + */ |
|
| 34 | 34 | public function __construct() { |
| 35 | 35 | |
| 36 | - // Init each store separately. |
|
| 37 | - foreach ( array_keys( $this->datastores ) as $key ) { |
|
| 38 | - $this->init_store( $key ); |
|
| 39 | - } |
|
| 36 | + // Init each store separately. |
|
| 37 | + foreach ( array_keys( $this->datastores ) as $key ) { |
|
| 38 | + $this->init_store( $key ); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Inits a store. |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * Inits a store. |
|
| 45 | + */ |
|
| 46 | 46 | public function init_store( $key ) { |
| 47 | 47 | |
| 48 | - // Register the add-on. |
|
| 49 | - $this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key ); |
|
| 48 | + // Register the add-on. |
|
| 49 | + $this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key ); |
|
| 50 | 50 | |
| 51 | - // Create import function. |
|
| 52 | - $import_function = function ( $post_id, $data, $import_options, $_post ) use ( $key ) { |
|
| 53 | - $this->import_store( $key, $post_id, $data, $import_options, $_post ); |
|
| 51 | + // Create import function. |
|
| 52 | + $import_function = function ( $post_id, $data, $import_options, $_post ) use ( $key ) { |
|
| 53 | + $this->import_store( $key, $post_id, $data, $import_options, $_post ); |
|
| 54 | 54 | }; |
| 55 | 55 | |
| 56 | - $this->add_ons[ $key ]->set_import_function( $import_function ); |
|
| 56 | + $this->add_ons[ $key ]->set_import_function( $import_function ); |
|
| 57 | 57 | |
| 58 | - // Register store fields. |
|
| 59 | - $this->add_store_fields( $key ); |
|
| 58 | + // Register store fields. |
|
| 59 | + $this->add_store_fields( $key ); |
|
| 60 | 60 | |
| 61 | - // Only load on the correct post type. |
|
| 62 | - $this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) ); |
|
| 61 | + // Only load on the correct post type. |
|
| 62 | + $this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) ); |
|
| 63 | 63 | |
| 64 | - // Disable images. |
|
| 65 | - $this->add_ons[ $key ]->disable_default_images(); |
|
| 64 | + // Disable images. |
|
| 65 | + $this->add_ons[ $key ]->disable_default_images(); |
|
| 66 | 66 | |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Retrieves store fields. |
|
| 71 | - */ |
|
| 69 | + /** |
|
| 70 | + * Retrieves store fields. |
|
| 71 | + */ |
|
| 72 | 72 | public function get_store_fields( $key ) { |
| 73 | 73 | |
| 74 | - // Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php |
|
| 75 | - $fields = wpinv_get_data( $key . '-schema' ); |
|
| 74 | + // Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php |
|
| 75 | + $fields = wpinv_get_data( $key . '-schema' ); |
|
| 76 | 76 | |
| 77 | - if ( empty( $fields ) ) { |
|
| 78 | - return array(); |
|
| 79 | - } |
|
| 77 | + if ( empty( $fields ) ) { |
|
| 78 | + return array(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // Clean the fields. |
|
| 82 | - $prepared = array(); |
|
| 83 | - foreach ( $fields as $id => $field ) { |
|
| 81 | + // Clean the fields. |
|
| 82 | + $prepared = array(); |
|
| 83 | + foreach ( $fields as $id => $field ) { |
|
| 84 | 84 | |
| 85 | - // Skip read only fields. |
|
| 86 | - if ( ! empty( $field['readonly'] ) ) { |
|
| 87 | - continue; |
|
| 88 | - } |
|
| 85 | + // Skip read only fields. |
|
| 86 | + if ( ! empty( $field['readonly'] ) ) { |
|
| 87 | + continue; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $prepared[ $id ] = $field; |
|
| 90 | + $prepared[ $id ] = $field; |
|
| 91 | 91 | |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $prepared; |
|
| 94 | + return $prepared; |
|
| 95 | 95 | |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Registers store fields. |
|
| 100 | - */ |
|
| 98 | + /** |
|
| 99 | + * Registers store fields. |
|
| 100 | + */ |
|
| 101 | 101 | public function add_store_fields( $key ) { |
| 102 | 102 | |
| 103 | - foreach ( $this->get_store_fields( $key ) as $field_id => $data ) { |
|
| 104 | - $this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' ); |
|
| 105 | - } |
|
| 103 | + foreach ( $this->get_store_fields( $key ) as $field_id => $data ) { |
|
| 104 | + $this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' ); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Handles store imports. |
|
| 111 | - */ |
|
| 109 | + /** |
|
| 110 | + * Handles store imports. |
|
| 111 | + */ |
|
| 112 | 112 | public function import_store( $key, $post_id, $data, $import_options, $_post ) { |
| 113 | 113 | |
| 114 | - // Is the store class set? |
|
| 115 | - if ( ! isset( $this->datastores[ $key ] ) ) { |
|
| 116 | - return; |
|
| 117 | - } |
|
| 114 | + // Is the store class set? |
|
| 115 | + if ( ! isset( $this->datastores[ $key ] ) ) { |
|
| 116 | + return; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /**@var GetPaid_Data */ |
|
| 120 | - $data_store = new $this->datastores[ $key ]( $post_id ); |
|
| 119 | + /**@var GetPaid_Data */ |
|
| 120 | + $data_store = new $this->datastores[ $key ]( $post_id ); |
|
| 121 | 121 | |
| 122 | - // Abort if the invoice/item/discount does not exist. |
|
| 123 | - if ( ! $data_store->exists() ) { |
|
| 124 | - return; |
|
| 125 | - } |
|
| 122 | + // Abort if the invoice/item/discount does not exist. |
|
| 123 | + if ( ! $data_store->exists() ) { |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - // Prepare data props. |
|
| 128 | - $prepared = array(); |
|
| 127 | + // Prepare data props. |
|
| 128 | + $prepared = array(); |
|
| 129 | 129 | |
| 130 | - foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { |
|
| 131 | - // Make sure the user has allowed this field to be updated. |
|
| 132 | - if ( empty( $_post['ID'] ) || $this->add_ons[ $key ]->can_update_meta( $field, $import_options ) ) { |
|
| 130 | + foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { |
|
| 131 | + // Make sure the user has allowed this field to be updated. |
|
| 132 | + if ( empty( $_post['ID'] ) || $this->add_ons[ $key ]->can_update_meta( $field, $import_options ) ) { |
|
| 133 | 133 | |
| 134 | - // Update the custom field with the imported data. |
|
| 135 | - $prepared[ $field ] = $data[ $field ]; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // Only update if we have something to update. |
|
| 140 | - if ( ! empty( $prepared ) ) { |
|
| 141 | - $data_store->set_props( $prepared ); |
|
| 142 | - $data_store->save(); |
|
| 143 | - } |
|
| 134 | + // Update the custom field with the imported data. |
|
| 135 | + $prepared[ $field ] = $data[ $field ]; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // Only update if we have something to update. |
|
| 140 | + if ( ! empty( $prepared ) ) { |
|
| 141 | + $data_store->set_props( $prepared ); |
|
| 142 | + $data_store->save(); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | } |
| 146 | 146 | |
@@ -13,36 +13,36 @@ discard block |
||
| 13 | 13 | class GetPaid_Notification_Email { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Contains the type of this notification email. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Contains the type of this notification email. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Contains any object to use in filters. |
|
| 24 | - * |
|
| 25 | - * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
| 26 | - */ |
|
| 23 | + * Contains any object to use in filters. |
|
| 24 | + * |
|
| 25 | + * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
| 26 | + */ |
|
| 27 | 27 | public $object; |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Class constructor. |
|
| 31 | - * |
|
| 30 | + * Class constructor. |
|
| 31 | + * |
|
| 32 | 32 | * @param string $id Email Type. |
| 33 | 33 | * @param mixed $object Optional. Associated object. |
| 34 | - */ |
|
| 35 | - public function __construct( $id, $object = false ) { |
|
| 34 | + */ |
|
| 35 | + public function __construct( $id, $object = false ) { |
|
| 36 | 36 | $this->id = $id; |
| 37 | 37 | $this->object = $object; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * Retrieves an option |
|
| 42 | - * |
|
| 41 | + * Retrieves an option |
|
| 42 | + * |
|
| 43 | 43 | * @return mixed |
| 44 | - */ |
|
| 45 | - public function get_option( $key ) { |
|
| 44 | + */ |
|
| 45 | + public function get_option( $key ) { |
|
| 46 | 46 | |
| 47 | 47 | $key = "email_{$this->id}_$key"; |
| 48 | 48 | $value = wpinv_get_option( $key, null ); |
@@ -60,80 +60,80 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * Retrieves the email body. |
|
| 64 | - * |
|
| 63 | + * Retrieves the email body. |
|
| 64 | + * |
|
| 65 | 65 | * @return string |
| 66 | - */ |
|
| 67 | - public function get_body() { |
|
| 66 | + */ |
|
| 67 | + public function get_body() { |
|
| 68 | 68 | $body = $this->get_option( 'body' ); |
| 69 | 69 | return apply_filters( 'getpaid_get_email_body', $body, $this->id, $this->object ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | - * Retrieves the email subject. |
|
| 74 | - * |
|
| 73 | + * Retrieves the email subject. |
|
| 74 | + * |
|
| 75 | 75 | * @return string |
| 76 | - */ |
|
| 77 | - public function get_subject() { |
|
| 76 | + */ |
|
| 77 | + public function get_subject() { |
|
| 78 | 78 | $subject = $this->get_option( 'subject' ); |
| 79 | 79 | return apply_filters( 'getpaid_get_email_subject', $subject, $this->id, $this->object ); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | - * Retrieves the email heading. |
|
| 84 | - * |
|
| 83 | + * Retrieves the email heading. |
|
| 84 | + * |
|
| 85 | 85 | * @return string |
| 86 | - */ |
|
| 87 | - public function get_heading() { |
|
| 86 | + */ |
|
| 87 | + public function get_heading() { |
|
| 88 | 88 | $heading = $this->get_option( 'heading' ); |
| 89 | 89 | return apply_filters( 'getpaid_get_email_heading', $heading, $this->id, $this->object ); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | - * Checks if an email is active. |
|
| 94 | - * |
|
| 93 | + * Checks if an email is active. |
|
| 94 | + * |
|
| 95 | 95 | * @return bool |
| 96 | - */ |
|
| 97 | - public function is_active() { |
|
| 96 | + */ |
|
| 97 | + public function is_active() { |
|
| 98 | 98 | $is_active = ! empty( $this->get_option( 'active' ) ); |
| 99 | 99 | return apply_filters( 'getpaid_email_type_is_active', $is_active, $this->id, $this->object ); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | - * Checks if the site's admin should receive email notifications. |
|
| 104 | - * |
|
| 103 | + * Checks if the site's admin should receive email notifications. |
|
| 104 | + * |
|
| 105 | 105 | * @return bool |
| 106 | - */ |
|
| 107 | - public function include_admin_bcc() { |
|
| 106 | + */ |
|
| 107 | + public function include_admin_bcc() { |
|
| 108 | 108 | $include_admin_bcc = ! empty( $this->get_option( 'admin_bcc' ) ); |
| 109 | 109 | return apply_filters( 'getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object ); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | - * Checks whether this email should be sent to the customer or admin. |
|
| 114 | - * |
|
| 113 | + * Checks whether this email should be sent to the customer or admin. |
|
| 114 | + * |
|
| 115 | 115 | * @return bool |
| 116 | - */ |
|
| 117 | - public function is_admin_email() { |
|
| 116 | + */ |
|
| 117 | + public function is_admin_email() { |
|
| 118 | 118 | $is_admin_email = in_array( $this->id, array( 'new_invoice', 'failed_invoice' ) ); |
| 119 | 119 | return apply_filters( 'getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object ); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | - * Returns email attachments. |
|
| 124 | - * |
|
| 123 | + * Returns email attachments. |
|
| 124 | + * |
|
| 125 | 125 | * @return array |
| 126 | - */ |
|
| 127 | - public function get_attachments() { |
|
| 126 | + */ |
|
| 127 | + public function get_attachments() { |
|
| 128 | 128 | return apply_filters( 'getpaid_get_email_attachments', array(), $this->id, $this->object ); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | - * Returns an array of merge tags. |
|
| 133 | - * |
|
| 132 | + * Returns an array of merge tags. |
|
| 133 | + * |
|
| 134 | 134 | * @return array |
| 135 | - */ |
|
| 136 | - public function get_merge_tags() { |
|
| 135 | + */ |
|
| 136 | + public function get_merge_tags() { |
|
| 137 | 137 | |
| 138 | 138 | $merge_tags = array( |
| 139 | 139 | '{site_title}' => wpinv_get_blogname(), |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | - * Adds merge tags to a text. |
|
| 148 | - * |
|
| 147 | + * Adds merge tags to a text. |
|
| 148 | + * |
|
| 149 | 149 | * @param string string $text |
| 150 | 150 | * @param array $merge_tags |
| 151 | 151 | * @return string |
| 152 | - */ |
|
| 153 | - public function add_merge_tags( $text, $merge_tags = array() ) { |
|
| 152 | + */ |
|
| 153 | + public function add_merge_tags( $text, $merge_tags = array() ) { |
|
| 154 | 154 | |
| 155 | 155 | foreach ( $merge_tags as $key => $value ) { |
| 156 | 156 | $text = str_replace( $key, $value, $text ); |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | - * Returns the email content |
|
| 164 | - * |
|
| 163 | + * Returns the email content |
|
| 164 | + * |
|
| 165 | 165 | * @param array $merge_tags |
| 166 | 166 | * @param array $extra_args Extra template args |
| 167 | 167 | * @return string |
| 168 | - */ |
|
| 169 | - public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
| 168 | + */ |
|
| 169 | + public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
| 170 | 170 | |
| 171 | 171 | $content = wpinv_get_template_html( |
| 172 | 172 | "emails/wpinv-email-{$this->id}.php", |
@@ -37,29 +37,29 @@ discard block |
||
| 37 | 37 | 'advanced' => false, |
| 38 | 38 | ), |
| 39 | 39 | 'items' => array( |
| 40 | - 'title' => __( 'Items to buy', 'invoicing' ), |
|
| 41 | - 'desc' => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2 ', 'invoicing' ), |
|
| 42 | - 'type' => 'text', |
|
| 43 | - 'desc_tip' => true, |
|
| 44 | - 'default' => '', |
|
| 45 | - 'placeholder' => __( 'Items to buy', 'invoicing' ), |
|
| 46 | - 'advanced' => false, |
|
| 40 | + 'title' => __( 'Items to buy', 'invoicing' ), |
|
| 41 | + 'desc' => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2 ', 'invoicing' ), |
|
| 42 | + 'type' => 'text', |
|
| 43 | + 'desc_tip' => true, |
|
| 44 | + 'default' => '', |
|
| 45 | + 'placeholder' => __( 'Items to buy', 'invoicing' ), |
|
| 46 | + 'advanced' => false, |
|
| 47 | 47 | ), |
| 48 | 48 | 'label' => array( |
| 49 | - 'title' => __( 'Button Label', 'invoicing' ), |
|
| 50 | - 'desc' => __( 'Enter button label. Default "Buy Now".', 'invoicing' ), |
|
| 51 | - 'type' => 'text', |
|
| 52 | - 'desc_tip' => true, |
|
| 53 | - 'default' => __( 'Buy Now', 'invoicing' ), |
|
| 54 | - 'advanced' => false, |
|
| 49 | + 'title' => __( 'Button Label', 'invoicing' ), |
|
| 50 | + 'desc' => __( 'Enter button label. Default "Buy Now".', 'invoicing' ), |
|
| 51 | + 'type' => 'text', |
|
| 52 | + 'desc_tip' => true, |
|
| 53 | + 'default' => __( 'Buy Now', 'invoicing' ), |
|
| 54 | + 'advanced' => false, |
|
| 55 | 55 | ), |
| 56 | 56 | 'post_id' => array( |
| 57 | - 'title' => __( 'Post ID', 'invoicing' ), |
|
| 58 | - 'desc' => __( 'Enter related post ID. This is for 3rd party add ons and not mandatory field.', 'invoicing' ), |
|
| 59 | - 'type' => 'number', |
|
| 60 | - 'desc_tip' => true, |
|
| 61 | - 'default' => '', |
|
| 62 | - 'advanced' => true, |
|
| 57 | + 'title' => __( 'Post ID', 'invoicing' ), |
|
| 58 | + 'desc' => __( 'Enter related post ID. This is for 3rd party add ons and not mandatory field.', 'invoicing' ), |
|
| 59 | + 'type' => 'number', |
|
| 60 | + 'desc_tip' => true, |
|
| 61 | + 'default' => '', |
|
| 62 | + 'advanced' => true, |
|
| 63 | 63 | ), |
| 64 | 64 | ), |
| 65 | 65 | |
@@ -68,43 +68,43 @@ discard block |
||
| 68 | 68 | parent::__construct( $options ); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * The Super block output function. |
|
| 73 | - * |
|
| 74 | - * @param array $args |
|
| 75 | - * @param array $widget_args |
|
| 76 | - * @param string $content |
|
| 77 | - * |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 71 | + /** |
|
| 72 | + * The Super block output function. |
|
| 73 | + * |
|
| 74 | + * @param array $args |
|
| 75 | + * @param array $widget_args |
|
| 76 | + * @param string $content |
|
| 77 | + * |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | 80 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 81 | 81 | |
| 82 | - $defaults = array( |
|
| 83 | - 'items' => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity |
|
| 84 | - 'label' => __( 'Buy Now', 'invoicing' ), // the button title |
|
| 85 | - 'post_id' => '', // any related post_id |
|
| 86 | - ); |
|
| 82 | + $defaults = array( |
|
| 83 | + 'items' => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity |
|
| 84 | + 'label' => __( 'Buy Now', 'invoicing' ), // the button title |
|
| 85 | + 'post_id' => '', // any related post_id |
|
| 86 | + ); |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 90 | - */ |
|
| 91 | - $args = wp_parse_args( $args, $defaults ); |
|
| 88 | + /** |
|
| 89 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 90 | + */ |
|
| 91 | + $args = wp_parse_args( $args, $defaults ); |
|
| 92 | 92 | |
| 93 | - $html = '<div class="wpi-buy-button-wrapper wpi-g">'; |
|
| 93 | + $html = '<div class="wpi-buy-button-wrapper wpi-g">'; |
|
| 94 | 94 | |
| 95 | - if ( empty( $args['items'] ) ) { |
|
| 96 | - $html .= __( 'No items selected', 'invoicing' ); |
|
| 97 | - } else { |
|
| 98 | - $post_id = isset( $args['post_id'] ) && is_numeric( $args['post_id'] ) ? sanitize_text_field( $args['post_id'] ) : 0; |
|
| 99 | - $label = isset( $args['label'] ) ? sanitize_text_field( $args['label'] ) : __( 'Buy Now', 'invoicing' ); |
|
| 100 | - $items = esc_attr( $args['items'] ); |
|
| 101 | - $html .= "<button class='button button-primary wpi-buy-button' type='button' onclick=\"wpi_buy(this, '$items','$post_id');\">$label</button>"; |
|
| 102 | - } |
|
| 95 | + if ( empty( $args['items'] ) ) { |
|
| 96 | + $html .= __( 'No items selected', 'invoicing' ); |
|
| 97 | + } else { |
|
| 98 | + $post_id = isset( $args['post_id'] ) && is_numeric( $args['post_id'] ) ? sanitize_text_field( $args['post_id'] ) : 0; |
|
| 99 | + $label = isset( $args['label'] ) ? sanitize_text_field( $args['label'] ) : __( 'Buy Now', 'invoicing' ); |
|
| 100 | + $items = esc_attr( $args['items'] ); |
|
| 101 | + $html .= "<button class='button button-primary wpi-buy-button' type='button' onclick=\"wpi_buy(this, '$items','$post_id');\">$label</button>"; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false ); |
|
| 105 | - $html .= '</div>'; |
|
| 104 | + $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false ); |
|
| 105 | + $html .= '</div>'; |
|
| 106 | 106 | |
| 107 | - return $html; |
|
| 107 | + return $html; |
|
| 108 | 108 | |
| 109 | 109 | } |
| 110 | 110 | |
@@ -36,14 +36,14 @@ discard block |
||
| 36 | 36 | 'advanced' => false, |
| 37 | 37 | ), |
| 38 | 38 | 'id' => array( |
| 39 | - 'title' => __( 'Invoice', 'invoicing' ), |
|
| 40 | - 'desc' => __( 'Enter the invoice ID', 'invoicing' ), |
|
| 41 | - 'type' => 'text', |
|
| 42 | - 'desc_tip' => true, |
|
| 43 | - 'default' => '', |
|
| 44 | - 'placeholder' => __( '1', 'invoicing' ), |
|
| 45 | - 'advanced' => false, |
|
| 46 | - ), |
|
| 39 | + 'title' => __( 'Invoice', 'invoicing' ), |
|
| 40 | + 'desc' => __( 'Enter the invoice ID', 'invoicing' ), |
|
| 41 | + 'type' => 'text', |
|
| 42 | + 'desc_tip' => true, |
|
| 43 | + 'default' => '', |
|
| 44 | + 'placeholder' => __( '1', 'invoicing' ), |
|
| 45 | + 'advanced' => false, |
|
| 46 | + ), |
|
| 47 | 47 | ), |
| 48 | 48 | |
| 49 | 49 | ); |
@@ -51,26 +51,26 @@ discard block |
||
| 51 | 51 | parent::__construct( $options ); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * The Super block output function. |
|
| 56 | - * |
|
| 57 | - * @param array $args |
|
| 58 | - * @param array $widget_args |
|
| 59 | - * @param string $content |
|
| 60 | - * |
|
| 61 | - * @return mixed|string|bool |
|
| 62 | - */ |
|
| 54 | + /** |
|
| 55 | + * The Super block output function. |
|
| 56 | + * |
|
| 57 | + * @param array $args |
|
| 58 | + * @param array $widget_args |
|
| 59 | + * @param string $content |
|
| 60 | + * |
|
| 61 | + * @return mixed|string|bool |
|
| 62 | + */ |
|
| 63 | 63 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 64 | 64 | |
| 65 | 65 | // Is the shortcode set up correctly? |
| 66 | - if ( empty( $args['id'] ) ) { |
|
| 67 | - return aui()->alert( |
|
| 68 | - array( |
|
| 69 | - 'type' => 'warning', |
|
| 70 | - 'content' => __( 'Missing invoice ID', 'invoicing' ), |
|
| 71 | - ) |
|
| 72 | - ); |
|
| 73 | - } |
|
| 66 | + if ( empty( $args['id'] ) ) { |
|
| 67 | + return aui()->alert( |
|
| 68 | + array( |
|
| 69 | + 'type' => 'warning', |
|
| 70 | + 'content' => __( 'Missing invoice ID', 'invoicing' ), |
|
| 71 | + ) |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | $invoice = wpinv_get_invoice( (int) $args['id'] ); |
| 76 | 76 | |
@@ -36,36 +36,36 @@ discard block |
||
| 36 | 36 | 'desc_tip' => true, |
| 37 | 37 | 'default' => '', |
| 38 | 38 | 'advanced' => false, |
| 39 | - ), |
|
| 39 | + ), |
|
| 40 | 40 | |
| 41 | 41 | 'form' => array( |
| 42 | - 'title' => __( 'Form', 'invoicing' ), |
|
| 43 | - 'desc' => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ), |
|
| 44 | - 'type' => 'text', |
|
| 45 | - 'desc_tip' => true, |
|
| 46 | - 'default' => '', |
|
| 47 | - 'placeholder' => __( '1', 'invoicing' ), |
|
| 48 | - 'advanced' => false, |
|
| 49 | - ), |
|
| 50 | - |
|
| 51 | - 'item' => array( |
|
| 52 | - 'title' => __( 'Items', 'invoicing' ), |
|
| 53 | - 'desc' => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ), |
|
| 54 | - 'type' => 'text', |
|
| 55 | - 'desc_tip' => true, |
|
| 56 | - 'default' => '', |
|
| 57 | - 'placeholder' => __( '1', 'invoicing' ), |
|
| 58 | - 'advanced' => false, |
|
| 59 | - ), |
|
| 42 | + 'title' => __( 'Form', 'invoicing' ), |
|
| 43 | + 'desc' => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ), |
|
| 44 | + 'type' => 'text', |
|
| 45 | + 'desc_tip' => true, |
|
| 46 | + 'default' => '', |
|
| 47 | + 'placeholder' => __( '1', 'invoicing' ), |
|
| 48 | + 'advanced' => false, |
|
| 49 | + ), |
|
| 50 | + |
|
| 51 | + 'item' => array( |
|
| 52 | + 'title' => __( 'Items', 'invoicing' ), |
|
| 53 | + 'desc' => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ), |
|
| 54 | + 'type' => 'text', |
|
| 55 | + 'desc_tip' => true, |
|
| 56 | + 'default' => '', |
|
| 57 | + 'placeholder' => __( '1', 'invoicing' ), |
|
| 58 | + 'advanced' => false, |
|
| 59 | + ), |
|
| 60 | 60 | |
| 61 | 61 | 'button' => array( |
| 62 | - 'title' => __( 'Button', 'invoicing' ), |
|
| 63 | - 'desc' => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ), |
|
| 64 | - 'type' => 'text', |
|
| 65 | - 'desc_tip' => true, |
|
| 66 | - 'default' => '', |
|
| 67 | - 'advanced' => false, |
|
| 68 | - ), |
|
| 62 | + 'title' => __( 'Button', 'invoicing' ), |
|
| 63 | + 'desc' => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ), |
|
| 64 | + 'type' => 'text', |
|
| 65 | + 'desc_tip' => true, |
|
| 66 | + 'default' => '', |
|
| 67 | + 'advanced' => false, |
|
| 68 | + ), |
|
| 69 | 69 | |
| 70 | 70 | ), |
| 71 | 71 | |
@@ -74,96 +74,96 @@ discard block |
||
| 74 | 74 | parent::__construct( $options ); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * The Super block output function. |
|
| 79 | - * |
|
| 80 | - * @param array $args |
|
| 81 | - * @param array $widget_args |
|
| 82 | - * @param string $content |
|
| 83 | - * |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 77 | + /** |
|
| 78 | + * The Super block output function. |
|
| 79 | + * |
|
| 80 | + * @param array $args |
|
| 81 | + * @param array $widget_args |
|
| 82 | + * @param string $content |
|
| 83 | + * |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | 86 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 87 | 87 | |
| 88 | - // Is the shortcode set up correctly? |
|
| 89 | - if ( empty( $args['form'] ) && empty( $args['item'] ) ) { |
|
| 90 | - return aui()->alert( |
|
| 91 | - array( |
|
| 92 | - 'type' => 'warning', |
|
| 93 | - 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
| 94 | - ) |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // Payment form or button? |
|
| 99 | - if ( ! empty( $args['form'] ) ) { |
|
| 100 | - return $this->handle_payment_form( $args ); |
|
| 101 | - } else { |
|
| 102 | - return $this->handle_buy_item( $args ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Displaying a payment form |
|
| 109 | - * |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 88 | + // Is the shortcode set up correctly? |
|
| 89 | + if ( empty( $args['form'] ) && empty( $args['item'] ) ) { |
|
| 90 | + return aui()->alert( |
|
| 91 | + array( |
|
| 92 | + 'type' => 'warning', |
|
| 93 | + 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
| 94 | + ) |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // Payment form or button? |
|
| 99 | + if ( ! empty( $args['form'] ) ) { |
|
| 100 | + return $this->handle_payment_form( $args ); |
|
| 101 | + } else { |
|
| 102 | + return $this->handle_buy_item( $args ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Displaying a payment form |
|
| 109 | + * |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | 112 | protected function handle_payment_form( $args = array() ) { |
| 113 | 113 | |
| 114 | - if ( empty( $args['button'] ) ) { |
|
| 115 | - ob_start(); |
|
| 116 | - getpaid_display_payment_form( $args['form'] ); |
|
| 117 | - return ob_get_clean(); |
|
| 118 | - } |
|
| 114 | + if ( empty( $args['button'] ) ) { |
|
| 115 | + ob_start(); |
|
| 116 | + getpaid_display_payment_form( $args['form'] ); |
|
| 117 | + return ob_get_clean(); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return $this->payment_form_button( $args['form'], $args['button'] ); |
|
| 121 | - } |
|
| 120 | + return $this->payment_form_button( $args['form'], $args['button'] ); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Displays a payment form button. |
|
| 125 | - * |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 123 | + /** |
|
| 124 | + * Displays a payment form button. |
|
| 125 | + * |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | 128 | protected function payment_form_button( $form, $button ) { |
| 129 | - return getpaid_get_payment_button( $button, $form ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Selling an item |
|
| 134 | - * |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 129 | + return getpaid_get_payment_button( $button, $form ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Selling an item |
|
| 134 | + * |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | 137 | protected function handle_buy_item( $args = array() ) { |
| 138 | 138 | |
| 139 | - if ( empty( $args['button'] ) ) { |
|
| 140 | - return $this->buy_item_form( $args['item'] ); |
|
| 141 | - } |
|
| 139 | + if ( empty( $args['button'] ) ) { |
|
| 140 | + return $this->buy_item_form( $args['item'] ); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - return $this->buy_item_button( $args['item'], $args['button'] ); |
|
| 143 | + return $this->buy_item_button( $args['item'], $args['button'] ); |
|
| 144 | 144 | |
| 145 | - } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Displays a buy item form. |
|
| 149 | - * |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 147 | + /** |
|
| 148 | + * Displays a buy item form. |
|
| 149 | + * |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | 152 | protected function buy_item_form( $item ) { |
| 153 | - $items = getpaid_convert_items_to_array( $item ); |
|
| 154 | - ob_start(); |
|
| 155 | - getpaid_display_item_payment_form( $items ); |
|
| 156 | - return ob_get_clean(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Displays a buy item button. |
|
| 161 | - * |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 153 | + $items = getpaid_convert_items_to_array( $item ); |
|
| 154 | + ob_start(); |
|
| 155 | + getpaid_display_item_payment_form( $items ); |
|
| 156 | + return ob_get_clean(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Displays a buy item button. |
|
| 161 | + * |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | 164 | protected function buy_item_button( $item, $button ) { |
| 165 | - $button = getpaid_get_payment_button( $button, null, $item ); |
|
| 166 | - return apply_filters( 'getpaid_buy_item_button_widget', $button, $item ); |
|
| 165 | + $button = getpaid_get_payment_button( $button, null, $item ); |
|
| 166 | + return apply_filters( 'getpaid_buy_item_button_widget', $button, $item ); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | } |