@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -319,10 +319,10 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
322 | - * Output the metabox. |
|
323 | - * |
|
324 | - * @param WP_Post $post |
|
325 | - */ |
|
322 | + * Output the metabox. |
|
323 | + * |
|
324 | + * @param WP_Post $post |
|
325 | + */ |
|
326 | 326 | public static function output2( $post ) { |
327 | 327 | |
328 | 328 | // Prepare the invoice. |
@@ -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 |
@@ -1,103 +1,103 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; |
|
4 | + exit; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) { |
8 | 8 | |
9 | - class AyeCode_Deactivation_Survey { |
|
9 | + class AyeCode_Deactivation_Survey { |
|
10 | 10 | |
11 | - /** |
|
12 | - * AyeCode_Deactivation_Survey instance. |
|
13 | - * |
|
14 | - * @access private |
|
15 | - * @since 1.0.0 |
|
16 | - * @var AyeCode_Deactivation_Survey There can be only one! |
|
17 | - */ |
|
18 | - private static $instance = null; |
|
11 | + /** |
|
12 | + * AyeCode_Deactivation_Survey instance. |
|
13 | + * |
|
14 | + * @access private |
|
15 | + * @since 1.0.0 |
|
16 | + * @var AyeCode_Deactivation_Survey There can be only one! |
|
17 | + */ |
|
18 | + private static $instance = null; |
|
19 | 19 | |
20 | - public static $plugins; |
|
20 | + public static $plugins; |
|
21 | 21 | |
22 | - public $version = "1.0.4"; |
|
22 | + public $version = "1.0.4"; |
|
23 | 23 | |
24 | - public static function instance( $plugin = array() ) { |
|
25 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) { |
|
26 | - self::$instance = new AyeCode_Deactivation_Survey; |
|
27 | - self::$plugins = array(); |
|
24 | + public static function instance( $plugin = array() ) { |
|
25 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) { |
|
26 | + self::$instance = new AyeCode_Deactivation_Survey; |
|
27 | + self::$plugins = array(); |
|
28 | 28 | |
29 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) ); |
|
29 | + add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) ); |
|
30 | 30 | |
31 | - do_action( 'ayecode_deactivation_survey_loaded' ); |
|
32 | - } |
|
31 | + do_action( 'ayecode_deactivation_survey_loaded' ); |
|
32 | + } |
|
33 | 33 | |
34 | - if(!empty($plugin)){ |
|
35 | - self::$plugins[] = (object)$plugin; |
|
36 | - } |
|
34 | + if(!empty($plugin)){ |
|
35 | + self::$plugins[] = (object)$plugin; |
|
36 | + } |
|
37 | 37 | |
38 | - return self::$instance; |
|
39 | - } |
|
38 | + return self::$instance; |
|
39 | + } |
|
40 | 40 | |
41 | - public function scripts() { |
|
42 | - global $pagenow; |
|
41 | + public function scripts() { |
|
42 | + global $pagenow; |
|
43 | 43 | |
44 | - // Bail if we are not on the plugins page |
|
45 | - if ( $pagenow != "plugins.php" ) { |
|
46 | - return; |
|
47 | - } |
|
44 | + // Bail if we are not on the plugins page |
|
45 | + if ( $pagenow != "plugins.php" ) { |
|
46 | + return; |
|
47 | + } |
|
48 | 48 | |
49 | - // Enqueue scripts |
|
50 | - add_thickbox(); |
|
51 | - wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js'); |
|
49 | + // Enqueue scripts |
|
50 | + add_thickbox(); |
|
51 | + wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js'); |
|
52 | 52 | |
53 | - /* |
|
53 | + /* |
|
54 | 54 | * Localized strings. Strings can be localised by plugins using this class. |
55 | 55 | * We deliberately don't add textdomains here so that double textdomain warning is not given in theme review. |
56 | 56 | */ |
57 | - wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array( |
|
58 | - 'quick_feedback' => 'Quick Feedback', |
|
59 | - 'foreword' => 'If you would be kind enough, please tell us why you\'re deactivating?', |
|
60 | - 'better_plugins_name' => 'Please tell us which plugin?', |
|
61 | - 'please_tell_us' => 'Please tell us the reason so we can improve the plugin', |
|
62 | - 'do_not_attach_email' => 'Do not send my e-mail address with this feedback', |
|
63 | - 'brief_description' => 'Please give us any feedback that could help us improve', |
|
64 | - 'cancel' => 'Cancel', |
|
65 | - 'skip_and_deactivate' => 'Skip & Deactivate', |
|
66 | - 'submit_and_deactivate' => 'Submit & Deactivate', |
|
67 | - 'please_wait' => 'Please wait', |
|
68 | - 'get_support' => 'Get Support', |
|
69 | - 'documentation' => 'Documentation', |
|
70 | - 'thank_you' => 'Thank you!', |
|
71 | - )); |
|
72 | - |
|
73 | - // Plugins |
|
74 | - $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins); |
|
75 | - |
|
76 | - // Reasons |
|
77 | - $defaultReasons = array( |
|
78 | - 'suddenly-stopped-working' => 'The plugin suddenly stopped working', |
|
79 | - 'plugin-broke-site' => 'The plugin broke my site', |
|
80 | - 'plugin-setup-difficult' => 'Too difficult to setup', |
|
81 | - 'plugin-design-difficult' => 'Too difficult to get the design i want', |
|
82 | - 'no-longer-needed' => 'I don\'t need this plugin any more', |
|
83 | - 'found-better-plugin' => 'I found a better plugin', |
|
84 | - 'temporary-deactivation' => 'It\'s a temporary deactivation, I\'m troubleshooting', |
|
85 | - 'other' => 'Other', |
|
86 | - ); |
|
87 | - |
|
88 | - foreach($plugins as $plugin) |
|
89 | - { |
|
90 | - $plugin->reasons = apply_filters('ayecode_deactivation_survey_reasons', $defaultReasons, $plugin); |
|
91 | - $plugin->url = home_url(); |
|
92 | - $plugin->activated = 0; |
|
93 | - } |
|
94 | - |
|
95 | - // Send plugin data |
|
96 | - wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins); |
|
97 | - |
|
98 | - } |
|
57 | + wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array( |
|
58 | + 'quick_feedback' => 'Quick Feedback', |
|
59 | + 'foreword' => 'If you would be kind enough, please tell us why you\'re deactivating?', |
|
60 | + 'better_plugins_name' => 'Please tell us which plugin?', |
|
61 | + 'please_tell_us' => 'Please tell us the reason so we can improve the plugin', |
|
62 | + 'do_not_attach_email' => 'Do not send my e-mail address with this feedback', |
|
63 | + 'brief_description' => 'Please give us any feedback that could help us improve', |
|
64 | + 'cancel' => 'Cancel', |
|
65 | + 'skip_and_deactivate' => 'Skip & Deactivate', |
|
66 | + 'submit_and_deactivate' => 'Submit & Deactivate', |
|
67 | + 'please_wait' => 'Please wait', |
|
68 | + 'get_support' => 'Get Support', |
|
69 | + 'documentation' => 'Documentation', |
|
70 | + 'thank_you' => 'Thank you!', |
|
71 | + )); |
|
72 | + |
|
73 | + // Plugins |
|
74 | + $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins); |
|
75 | + |
|
76 | + // Reasons |
|
77 | + $defaultReasons = array( |
|
78 | + 'suddenly-stopped-working' => 'The plugin suddenly stopped working', |
|
79 | + 'plugin-broke-site' => 'The plugin broke my site', |
|
80 | + 'plugin-setup-difficult' => 'Too difficult to setup', |
|
81 | + 'plugin-design-difficult' => 'Too difficult to get the design i want', |
|
82 | + 'no-longer-needed' => 'I don\'t need this plugin any more', |
|
83 | + 'found-better-plugin' => 'I found a better plugin', |
|
84 | + 'temporary-deactivation' => 'It\'s a temporary deactivation, I\'m troubleshooting', |
|
85 | + 'other' => 'Other', |
|
86 | + ); |
|
87 | + |
|
88 | + foreach($plugins as $plugin) |
|
89 | + { |
|
90 | + $plugin->reasons = apply_filters('ayecode_deactivation_survey_reasons', $defaultReasons, $plugin); |
|
91 | + $plugin->url = home_url(); |
|
92 | + $plugin->activated = 0; |
|
93 | + } |
|
94 | + |
|
95 | + // Send plugin data |
|
96 | + wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins); |
|
97 | + |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | - } |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | \ 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", |
@@ -12,294 +12,294 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Helper { |
14 | 14 | |
15 | - /** |
|
16 | - * Get report totals such as invoice totals and discount amounts. |
|
17 | - * |
|
18 | - * Data example: |
|
19 | - * |
|
20 | - * 'subtotal' => array( |
|
21 | - * 'type' => 'invoice_data', |
|
22 | - * 'function' => 'SUM', |
|
23 | - * 'name' => 'subtotal' |
|
24 | - * ) |
|
25 | - * |
|
26 | - * @param array $args |
|
27 | - * @return mixed depending on query_type |
|
28 | - */ |
|
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $default_args = array( |
|
33 | - 'data' => array(), // The data to retrieve. |
|
34 | - 'where' => array(), // An array of where queries. |
|
35 | - 'query_type' => 'get_row', // wpdb query to run. |
|
36 | - 'group_by' => '', // What to group results by. |
|
37 | - 'order_by' => '', // What to order by. |
|
38 | - 'limit' => '', // Results limit. |
|
39 | - 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | - 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | - ); |
|
44 | - |
|
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
47 | - |
|
48 | - extract( $args ); |
|
49 | - |
|
50 | - if ( empty( $data ) ) { |
|
51 | - return ''; |
|
52 | - } |
|
53 | - |
|
54 | - $query = array(); |
|
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | - $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | - |
|
59 | - $query['where'] = " |
|
15 | + /** |
|
16 | + * Get report totals such as invoice totals and discount amounts. |
|
17 | + * |
|
18 | + * Data example: |
|
19 | + * |
|
20 | + * 'subtotal' => array( |
|
21 | + * 'type' => 'invoice_data', |
|
22 | + * 'function' => 'SUM', |
|
23 | + * 'name' => 'subtotal' |
|
24 | + * ) |
|
25 | + * |
|
26 | + * @param array $args |
|
27 | + * @return mixed depending on query_type |
|
28 | + */ |
|
29 | + public static function get_invoice_report_data( $args = array() ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $default_args = array( |
|
33 | + 'data' => array(), // The data to retrieve. |
|
34 | + 'where' => array(), // An array of where queries. |
|
35 | + 'query_type' => 'get_row', // wpdb query to run. |
|
36 | + 'group_by' => '', // What to group results by. |
|
37 | + 'order_by' => '', // What to order by. |
|
38 | + 'limit' => '', // Results limit. |
|
39 | + 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | + 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | + 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | + ); |
|
44 | + |
|
45 | + $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | + $args = wp_parse_args( $args, $default_args ); |
|
47 | + |
|
48 | + extract( $args ); |
|
49 | + |
|
50 | + if ( empty( $data ) ) { |
|
51 | + return ''; |
|
52 | + } |
|
53 | + |
|
54 | + $query = array(); |
|
55 | + $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | + $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | + $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | + |
|
59 | + $query['where'] = " |
|
60 | 60 | WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
64 | - $query['where'] .= " |
|
63 | + if ( ! empty( $invoice_status ) ) { |
|
64 | + $query['where'] .= " |
|
65 | 65 | AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
66 | 66 | "; |
67 | - } |
|
68 | - |
|
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | - } else { |
|
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
78 | - $query['where'] .= " |
|
67 | + } |
|
68 | + |
|
69 | + if ( ! empty( $parent_invoice_status ) ) { |
|
70 | + if ( ! empty( $invoice_status ) ) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | + } else { |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + if ( ! empty( $filter_range['before'] ) ) { |
|
78 | + $query['where'] .= " |
|
79 | 79 | AND posts.post_date < '" . date( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
80 | 80 | "; |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
84 | - $query['where'] .= " |
|
83 | + if ( ! empty( $filter_range['after'] ) ) { |
|
84 | + $query['where'] .= " |
|
85 | 85 | AND posts.post_date > '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['after'] ) ) . "' |
86 | 86 | "; |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if ( ! empty( $where ) ) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ( $where as $value ) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) { |
|
94 | - |
|
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
97 | - } |
|
98 | - |
|
99 | - if ( ! empty( $value['value'] ) ) { |
|
100 | - $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | - } |
|
102 | - } else { |
|
103 | - $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! empty( $where_value ) ) { |
|
107 | - $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - if ( $group_by ) { |
|
113 | - $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | - } |
|
115 | - |
|
116 | - if ( $order_by ) { |
|
117 | - $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | - } |
|
119 | - |
|
120 | - if ( $limit ) { |
|
121 | - $query['limit'] = "LIMIT {$limit}"; |
|
122 | - } |
|
123 | - |
|
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
126 | - |
|
127 | - return self::execute( $query_type, $query ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Prepares the data to select. |
|
133 | - * |
|
134 | - * |
|
135 | - * @param array $data |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public static function prepare_invoice_data( $data ) { |
|
139 | - |
|
140 | - $prepared = array(); |
|
141 | - |
|
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
144 | - $distinct = ''; |
|
145 | - |
|
146 | - if ( isset( $value['distinct'] ) ) { |
|
147 | - $distinct = 'DISTINCT'; |
|
148 | - } |
|
149 | - |
|
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | - |
|
152 | - if ( false === $get_key ) { |
|
153 | - // Skip to the next foreach iteration else the query will be invalid. |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if ( ! empty( $value['function'] ) ) { |
|
158 | - $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | - } else { |
|
160 | - $get = "{$distinct} {$get_key}"; |
|
161 | - } |
|
162 | - |
|
163 | - $prepared[] = "{$get} as {$value['name']}"; |
|
164 | - } |
|
165 | - |
|
166 | - return $prepared; |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Prepares the joins to use. |
|
172 | - * |
|
173 | - * |
|
174 | - * @param array $data |
|
175 | - * @param bool $with_parent |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | - global $wpdb; |
|
180 | - |
|
181 | - $prepared = array(); |
|
182 | - |
|
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
187 | - |
|
188 | - switch ( $type ) { |
|
189 | - case 'meta': |
|
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | - break; |
|
192 | - case 'parent_meta': |
|
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | - break; |
|
195 | - case 'invoice_data': |
|
196 | - $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | - break; |
|
198 | - case 'invoice_item': |
|
199 | - $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | - break; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - if ( $with_parent ) { |
|
205 | - $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | - } |
|
207 | - |
|
208 | - return $prepared; |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Retrieves the appropriate table key to use. |
|
214 | - * |
|
215 | - * |
|
216 | - * @param string $key |
|
217 | - * @param string $table |
|
218 | - * @return string|false |
|
219 | - */ |
|
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
221 | - |
|
222 | - $keys = array( |
|
223 | - 'meta' => "meta_{$key}.meta_value", |
|
224 | - 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | - 'post_data' => "posts.{$key}", |
|
226 | - 'invoice_data' => "invoices.{$key}", |
|
227 | - 'invoice_item' => "invoice_items.{$key}", |
|
228 | - ); |
|
229 | - |
|
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | - |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Executes a query and caches the result for a minute. |
|
236 | - * |
|
237 | - * |
|
238 | - * @param string $query_type |
|
239 | - * @param string $query |
|
240 | - * @return mixed depending on query_type |
|
241 | - */ |
|
242 | - public static function execute( $query_type, $query ) { |
|
243 | - global $wpdb; |
|
244 | - |
|
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
248 | - self::enable_big_selects(); |
|
249 | - |
|
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
252 | - } |
|
253 | - |
|
254 | - return $result; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Enables big mysql selects for reports, just once for this session. |
|
260 | - */ |
|
261 | - protected static function enable_big_selects() { |
|
262 | - static $big_selects = false; |
|
263 | - |
|
264 | - global $wpdb; |
|
265 | - |
|
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | - $big_selects = true; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Get the cached query result or null if it's not in the cache. |
|
274 | - * |
|
275 | - * @param string $query_hash The query hash. |
|
276 | - * |
|
277 | - * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | - */ |
|
279 | - protected static function get_cached_query( $query_hash ) { |
|
280 | - |
|
281 | - return wp_cache_get( |
|
282 | - $query_hash, |
|
283 | - strtolower( __CLASS__ ) |
|
284 | - ); |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Set the cached query result. |
|
290 | - * |
|
291 | - * @param string $query_hash The query hash. |
|
292 | - * @param mixed $data The data to cache. |
|
293 | - */ |
|
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
295 | - |
|
296 | - wp_cache_set( |
|
297 | - $query_hash, |
|
298 | - $data, |
|
299 | - strtolower( __CLASS__ ), |
|
300 | - MINUTE_IN_SECONDS |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
93 | + if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) { |
|
94 | + |
|
95 | + if ( is_array( $value['value'] ) ) { |
|
96 | + $value['value'] = implode( "','", $value['value'] ); |
|
97 | + } |
|
98 | + |
|
99 | + if ( ! empty( $value['value'] ) ) { |
|
100 | + $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | + } |
|
102 | + } else { |
|
103 | + $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! empty( $where_value ) ) { |
|
107 | + $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + if ( $group_by ) { |
|
113 | + $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | + } |
|
115 | + |
|
116 | + if ( $order_by ) { |
|
117 | + $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | + } |
|
119 | + |
|
120 | + if ( $limit ) { |
|
121 | + $query['limit'] = "LIMIT {$limit}"; |
|
122 | + } |
|
123 | + |
|
124 | + $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | + $query = implode( ' ', $query ); |
|
126 | + |
|
127 | + return self::execute( $query_type, $query ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Prepares the data to select. |
|
133 | + * |
|
134 | + * |
|
135 | + * @param array $data |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public static function prepare_invoice_data( $data ) { |
|
139 | + |
|
140 | + $prepared = array(); |
|
141 | + |
|
142 | + foreach ( $data as $raw_key => $value ) { |
|
143 | + $key = sanitize_key( $raw_key ); |
|
144 | + $distinct = ''; |
|
145 | + |
|
146 | + if ( isset( $value['distinct'] ) ) { |
|
147 | + $distinct = 'DISTINCT'; |
|
148 | + } |
|
149 | + |
|
150 | + $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | + |
|
152 | + if ( false === $get_key ) { |
|
153 | + // Skip to the next foreach iteration else the query will be invalid. |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if ( ! empty( $value['function'] ) ) { |
|
158 | + $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | + } else { |
|
160 | + $get = "{$distinct} {$get_key}"; |
|
161 | + } |
|
162 | + |
|
163 | + $prepared[] = "{$get} as {$value['name']}"; |
|
164 | + } |
|
165 | + |
|
166 | + return $prepared; |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Prepares the joins to use. |
|
172 | + * |
|
173 | + * |
|
174 | + * @param array $data |
|
175 | + * @param bool $with_parent |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | + global $wpdb; |
|
180 | + |
|
181 | + $prepared = array(); |
|
182 | + |
|
183 | + foreach ( $data as $raw_key => $value ) { |
|
184 | + $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | + $key = sanitize_key( $raw_key ); |
|
187 | + |
|
188 | + switch ( $type ) { |
|
189 | + case 'meta': |
|
190 | + $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | + break; |
|
192 | + case 'parent_meta': |
|
193 | + $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | + break; |
|
195 | + case 'invoice_data': |
|
196 | + $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | + break; |
|
198 | + case 'invoice_item': |
|
199 | + $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | + break; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + if ( $with_parent ) { |
|
205 | + $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | + } |
|
207 | + |
|
208 | + return $prepared; |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Retrieves the appropriate table key to use. |
|
214 | + * |
|
215 | + * |
|
216 | + * @param string $key |
|
217 | + * @param string $table |
|
218 | + * @return string|false |
|
219 | + */ |
|
220 | + public static function get_invoice_table_key( $key, $table ) { |
|
221 | + |
|
222 | + $keys = array( |
|
223 | + 'meta' => "meta_{$key}.meta_value", |
|
224 | + 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | + 'post_data' => "posts.{$key}", |
|
226 | + 'invoice_data' => "invoices.{$key}", |
|
227 | + 'invoice_item' => "invoice_items.{$key}", |
|
228 | + ); |
|
229 | + |
|
230 | + return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | + |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Executes a query and caches the result for a minute. |
|
236 | + * |
|
237 | + * |
|
238 | + * @param string $query_type |
|
239 | + * @param string $query |
|
240 | + * @return mixed depending on query_type |
|
241 | + */ |
|
242 | + public static function execute( $query_type, $query ) { |
|
243 | + global $wpdb; |
|
244 | + |
|
245 | + $query_hash = md5( $query_type . $query ); |
|
246 | + $result = self::get_cached_query( $query_hash ); |
|
247 | + if ( $result === false ) { |
|
248 | + self::enable_big_selects(); |
|
249 | + |
|
250 | + $result = $wpdb->$query_type( $query ); |
|
251 | + self::set_cached_query( $query_hash, $result ); |
|
252 | + } |
|
253 | + |
|
254 | + return $result; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Enables big mysql selects for reports, just once for this session. |
|
260 | + */ |
|
261 | + protected static function enable_big_selects() { |
|
262 | + static $big_selects = false; |
|
263 | + |
|
264 | + global $wpdb; |
|
265 | + |
|
266 | + if ( ! $big_selects ) { |
|
267 | + $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | + $big_selects = true; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Get the cached query result or null if it's not in the cache. |
|
274 | + * |
|
275 | + * @param string $query_hash The query hash. |
|
276 | + * |
|
277 | + * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | + */ |
|
279 | + protected static function get_cached_query( $query_hash ) { |
|
280 | + |
|
281 | + return wp_cache_get( |
|
282 | + $query_hash, |
|
283 | + strtolower( __CLASS__ ) |
|
284 | + ); |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Set the cached query result. |
|
290 | + * |
|
291 | + * @param string $query_hash The query hash. |
|
292 | + * @param mixed $data The data to cache. |
|
293 | + */ |
|
294 | + protected static function set_cached_query( $query_hash, $data ) { |
|
295 | + |
|
296 | + wp_cache_set( |
|
297 | + $query_hash, |
|
298 | + $data, |
|
299 | + strtolower( __CLASS__ ), |
|
300 | + MINUTE_IN_SECONDS |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | } |
@@ -1,271 +1,271 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; |
|
4 | + exit; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | if ( ! class_exists( "AyeCode_Connect_Helper" ) ) { |
8 | - /** |
|
9 | - * Allow the quick setup and connection of our AyeCode Connect plugin. |
|
10 | - * |
|
11 | - * Class AyeCode_Connect_Helper |
|
12 | - */ |
|
13 | - class AyeCode_Connect_Helper { |
|
14 | - |
|
15 | - // Hold the version number |
|
16 | - var $version = "1.0.3"; |
|
17 | - |
|
18 | - // Hold the default strings. |
|
19 | - var $strings = array(); |
|
20 | - |
|
21 | - // Hold the default pages. |
|
22 | - var $pages = array(); |
|
23 | - |
|
24 | - /** |
|
25 | - * The constructor. |
|
26 | - * |
|
27 | - * AyeCode_Connect_Helper constructor. |
|
28 | - * |
|
29 | - * @param array $strings |
|
30 | - * @param array $pages |
|
31 | - */ |
|
32 | - public function __construct( $strings = array(), $pages = array() ) { |
|
33 | - |
|
34 | - // Only fire if not localhost and the current user has the right permissions. |
|
35 | - if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
36 | - |
|
37 | - |
|
38 | - // set default strings |
|
39 | - $default_strings = array( |
|
40 | - 'connect_title' => __( "Thanks for choosing an AyeCode Product!" ), |
|
41 | - 'connect_external' => __( "Please confirm you wish to connect your site?" ), |
|
42 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
43 | - 'connect_button' => __( "Connect Site" ), |
|
44 | - 'connecting_button' => __( "Connecting..." ), |
|
45 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost." ), |
|
46 | - 'error' => __( "Something went wrong, please refresh and try again." ), |
|
47 | - ); |
|
48 | - $this->strings = array_merge( $default_strings, $strings ); |
|
49 | - |
|
50 | - |
|
51 | - // set default pages |
|
52 | - $default_pages = array(); |
|
53 | - $this->pages = array_merge( $default_pages, $pages ); |
|
54 | - |
|
55 | - // maybe show connect site notice |
|
56 | - add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
57 | - |
|
58 | - // add ajax action if not already added |
|
59 | - if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
60 | - add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - // add ajax action if not already added |
|
65 | - if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
66 | - add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
67 | - } |
|
68 | - |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Give a way to check we can connect via a external redirect. |
|
73 | - */ |
|
74 | - public function ayecode_connect_helper_installed(){ |
|
75 | - $active = array( |
|
76 | - 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
77 | - 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
78 | - 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
79 | - ); |
|
80 | - wp_send_json_success( $active ); |
|
81 | - wp_die(); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get slug from path |
|
86 | - * |
|
87 | - * @param string $key |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - private function format_plugin_slug( $key ) { |
|
92 | - $slug = explode( '/', $key ); |
|
93 | - $slug = explode( '.', end( $slug ) ); |
|
94 | - |
|
95 | - return $slug[0]; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Install and activate the AyeCode Connect Plugin |
|
100 | - */ |
|
101 | - public function ayecode_connect_install() { |
|
102 | - |
|
103 | - // bail if localhost |
|
104 | - if ( $this->is_localhost() ) { |
|
105 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
106 | - } |
|
107 | - |
|
108 | - // Explicitly clear the event. |
|
109 | - wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
110 | - |
|
111 | - $success = true; |
|
112 | - $plugin_slug = "ayecode-connect"; |
|
113 | - if ( ! empty( $plugin_slug ) ) { |
|
114 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
115 | - require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
116 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
117 | - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
118 | - |
|
119 | - WP_Filesystem(); |
|
120 | - |
|
121 | - $skin = new Automatic_Upgrader_Skin; |
|
122 | - $upgrader = new WP_Upgrader( $skin ); |
|
123 | - $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
124 | - $plugin_slug = $plugin_slug; |
|
125 | - $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
|
126 | - $installed = false; |
|
127 | - $activate = false; |
|
128 | - |
|
129 | - // See if the plugin is installed already |
|
130 | - if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
131 | - $installed = true; |
|
132 | - $activate = ! is_plugin_active( $plugin ); |
|
133 | - } |
|
134 | - |
|
135 | - // Install this thing! |
|
136 | - if ( ! $installed ) { |
|
137 | - |
|
138 | - // Suppress feedback |
|
139 | - ob_start(); |
|
140 | - |
|
141 | - try { |
|
142 | - $plugin_information = plugins_api( 'plugin_information', array( |
|
143 | - 'slug' => $plugin_slug, |
|
144 | - 'fields' => array( |
|
145 | - 'short_description' => false, |
|
146 | - 'sections' => false, |
|
147 | - 'requires' => false, |
|
148 | - 'rating' => false, |
|
149 | - 'ratings' => false, |
|
150 | - 'downloaded' => false, |
|
151 | - 'last_updated' => false, |
|
152 | - 'added' => false, |
|
153 | - 'tags' => false, |
|
154 | - 'homepage' => false, |
|
155 | - 'donate_link' => false, |
|
156 | - 'author_profile' => false, |
|
157 | - 'author' => false, |
|
158 | - ), |
|
159 | - ) ); |
|
160 | - |
|
161 | - if ( is_wp_error( $plugin_information ) ) { |
|
162 | - throw new Exception( $plugin_information->get_error_message() ); |
|
163 | - } |
|
164 | - |
|
165 | - $package = $plugin_information->download_link; |
|
166 | - $download = $upgrader->download_package( $package ); |
|
167 | - |
|
168 | - if ( is_wp_error( $download ) ) { |
|
169 | - throw new Exception( $download->get_error_message() ); |
|
170 | - } |
|
171 | - |
|
172 | - $working_dir = $upgrader->unpack_package( $download, true ); |
|
173 | - |
|
174 | - if ( is_wp_error( $working_dir ) ) { |
|
175 | - throw new Exception( $working_dir->get_error_message() ); |
|
176 | - } |
|
177 | - |
|
178 | - $result = $upgrader->install_package( array( |
|
179 | - 'source' => $working_dir, |
|
180 | - 'destination' => WP_PLUGIN_DIR, |
|
181 | - 'clear_destination' => false, |
|
182 | - 'abort_if_destination_exists' => false, |
|
183 | - 'clear_working' => true, |
|
184 | - 'hook_extra' => array( |
|
185 | - 'type' => 'plugin', |
|
186 | - 'action' => 'install', |
|
187 | - ), |
|
188 | - ) ); |
|
189 | - |
|
190 | - if ( is_wp_error( $result ) ) { |
|
191 | - throw new Exception( $result->get_error_message() ); |
|
192 | - } |
|
193 | - |
|
194 | - $activate = true; |
|
195 | - |
|
196 | - } catch ( Exception $e ) { |
|
197 | - $success = false; |
|
198 | - } |
|
199 | - |
|
200 | - // Discard feedback |
|
201 | - ob_end_clean(); |
|
202 | - } |
|
203 | - |
|
204 | - wp_clean_plugins_cache(); |
|
205 | - |
|
206 | - // Activate this thing |
|
207 | - if ( $activate ) { |
|
208 | - try { |
|
209 | - $result = activate_plugin( $plugin ); |
|
210 | - |
|
211 | - if ( is_wp_error( $result ) ) { |
|
212 | - $success = false; |
|
213 | - } else { |
|
214 | - $success = true; |
|
215 | - } |
|
216 | - } catch ( Exception $e ) { |
|
217 | - $success = false; |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
223 | - ayecode_connect();// init |
|
224 | - $args = ayecode_connect_args(); |
|
225 | - $client = new AyeCode_Connect( $args ); |
|
226 | - $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
227 | - $redirect = $client->build_connect_url( $redirect_to ); |
|
228 | - wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
229 | - } else { |
|
230 | - wp_send_json_error( $this->strings['error_localhost'] ); |
|
231 | - } |
|
232 | - wp_die(); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Check if maybe localhost. |
|
237 | - * |
|
238 | - * @return bool |
|
239 | - */ |
|
240 | - public function is_localhost() { |
|
241 | - $localhost = false; |
|
242 | - |
|
243 | - $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
244 | - $localhost_domains = array( |
|
245 | - 'localhost', |
|
246 | - 'localhost.localdomain', |
|
247 | - '127.0.0.1', |
|
248 | - '::1' |
|
249 | - ); |
|
250 | - |
|
251 | - if ( in_array( $host, $localhost_domains ) ) { |
|
252 | - $localhost = true; |
|
253 | - } |
|
254 | - |
|
255 | - return $localhost; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Show notice to connect site. |
|
260 | - */ |
|
261 | - public function ayecode_connect_install_notice() { |
|
262 | - if ( $this->maybe_show() ) { |
|
263 | - $connect_title_string = $this->strings['connect_title']; |
|
264 | - $connect_external_string = $this->strings['connect_external']; |
|
265 | - $connect_string = $this->strings['connect']; |
|
266 | - $connect_button_string = $this->strings['connect_button']; |
|
267 | - $connecting_button_string = $this->strings['connecting_button']; |
|
268 | - ?> |
|
8 | + /** |
|
9 | + * Allow the quick setup and connection of our AyeCode Connect plugin. |
|
10 | + * |
|
11 | + * Class AyeCode_Connect_Helper |
|
12 | + */ |
|
13 | + class AyeCode_Connect_Helper { |
|
14 | + |
|
15 | + // Hold the version number |
|
16 | + var $version = "1.0.3"; |
|
17 | + |
|
18 | + // Hold the default strings. |
|
19 | + var $strings = array(); |
|
20 | + |
|
21 | + // Hold the default pages. |
|
22 | + var $pages = array(); |
|
23 | + |
|
24 | + /** |
|
25 | + * The constructor. |
|
26 | + * |
|
27 | + * AyeCode_Connect_Helper constructor. |
|
28 | + * |
|
29 | + * @param array $strings |
|
30 | + * @param array $pages |
|
31 | + */ |
|
32 | + public function __construct( $strings = array(), $pages = array() ) { |
|
33 | + |
|
34 | + // Only fire if not localhost and the current user has the right permissions. |
|
35 | + if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) { |
|
36 | + |
|
37 | + |
|
38 | + // set default strings |
|
39 | + $default_strings = array( |
|
40 | + 'connect_title' => __( "Thanks for choosing an AyeCode Product!" ), |
|
41 | + 'connect_external' => __( "Please confirm you wish to connect your site?" ), |
|
42 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ), |
|
43 | + 'connect_button' => __( "Connect Site" ), |
|
44 | + 'connecting_button' => __( "Connecting..." ), |
|
45 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost." ), |
|
46 | + 'error' => __( "Something went wrong, please refresh and try again." ), |
|
47 | + ); |
|
48 | + $this->strings = array_merge( $default_strings, $strings ); |
|
49 | + |
|
50 | + |
|
51 | + // set default pages |
|
52 | + $default_pages = array(); |
|
53 | + $this->pages = array_merge( $default_pages, $pages ); |
|
54 | + |
|
55 | + // maybe show connect site notice |
|
56 | + add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) ); |
|
57 | + |
|
58 | + // add ajax action if not already added |
|
59 | + if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) { |
|
60 | + add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) ); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + // add ajax action if not already added |
|
65 | + if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) { |
|
66 | + add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) ); |
|
67 | + } |
|
68 | + |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Give a way to check we can connect via a external redirect. |
|
73 | + */ |
|
74 | + public function ayecode_connect_helper_installed(){ |
|
75 | + $active = array( |
|
76 | + 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0, |
|
77 | + 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0, |
|
78 | + 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0, |
|
79 | + ); |
|
80 | + wp_send_json_success( $active ); |
|
81 | + wp_die(); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get slug from path |
|
86 | + * |
|
87 | + * @param string $key |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + private function format_plugin_slug( $key ) { |
|
92 | + $slug = explode( '/', $key ); |
|
93 | + $slug = explode( '.', end( $slug ) ); |
|
94 | + |
|
95 | + return $slug[0]; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Install and activate the AyeCode Connect Plugin |
|
100 | + */ |
|
101 | + public function ayecode_connect_install() { |
|
102 | + |
|
103 | + // bail if localhost |
|
104 | + if ( $this->is_localhost() ) { |
|
105 | + wp_send_json_error( $this->strings['error_localhost'] ); |
|
106 | + } |
|
107 | + |
|
108 | + // Explicitly clear the event. |
|
109 | + wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() ); |
|
110 | + |
|
111 | + $success = true; |
|
112 | + $plugin_slug = "ayecode-connect"; |
|
113 | + if ( ! empty( $plugin_slug ) ) { |
|
114 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
115 | + require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
|
116 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
|
117 | + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
118 | + |
|
119 | + WP_Filesystem(); |
|
120 | + |
|
121 | + $skin = new Automatic_Upgrader_Skin; |
|
122 | + $upgrader = new WP_Upgrader( $skin ); |
|
123 | + $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) ); |
|
124 | + $plugin_slug = $plugin_slug; |
|
125 | + $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
|
126 | + $installed = false; |
|
127 | + $activate = false; |
|
128 | + |
|
129 | + // See if the plugin is installed already |
|
130 | + if ( in_array( $plugin_slug, $installed_plugins ) ) { |
|
131 | + $installed = true; |
|
132 | + $activate = ! is_plugin_active( $plugin ); |
|
133 | + } |
|
134 | + |
|
135 | + // Install this thing! |
|
136 | + if ( ! $installed ) { |
|
137 | + |
|
138 | + // Suppress feedback |
|
139 | + ob_start(); |
|
140 | + |
|
141 | + try { |
|
142 | + $plugin_information = plugins_api( 'plugin_information', array( |
|
143 | + 'slug' => $plugin_slug, |
|
144 | + 'fields' => array( |
|
145 | + 'short_description' => false, |
|
146 | + 'sections' => false, |
|
147 | + 'requires' => false, |
|
148 | + 'rating' => false, |
|
149 | + 'ratings' => false, |
|
150 | + 'downloaded' => false, |
|
151 | + 'last_updated' => false, |
|
152 | + 'added' => false, |
|
153 | + 'tags' => false, |
|
154 | + 'homepage' => false, |
|
155 | + 'donate_link' => false, |
|
156 | + 'author_profile' => false, |
|
157 | + 'author' => false, |
|
158 | + ), |
|
159 | + ) ); |
|
160 | + |
|
161 | + if ( is_wp_error( $plugin_information ) ) { |
|
162 | + throw new Exception( $plugin_information->get_error_message() ); |
|
163 | + } |
|
164 | + |
|
165 | + $package = $plugin_information->download_link; |
|
166 | + $download = $upgrader->download_package( $package ); |
|
167 | + |
|
168 | + if ( is_wp_error( $download ) ) { |
|
169 | + throw new Exception( $download->get_error_message() ); |
|
170 | + } |
|
171 | + |
|
172 | + $working_dir = $upgrader->unpack_package( $download, true ); |
|
173 | + |
|
174 | + if ( is_wp_error( $working_dir ) ) { |
|
175 | + throw new Exception( $working_dir->get_error_message() ); |
|
176 | + } |
|
177 | + |
|
178 | + $result = $upgrader->install_package( array( |
|
179 | + 'source' => $working_dir, |
|
180 | + 'destination' => WP_PLUGIN_DIR, |
|
181 | + 'clear_destination' => false, |
|
182 | + 'abort_if_destination_exists' => false, |
|
183 | + 'clear_working' => true, |
|
184 | + 'hook_extra' => array( |
|
185 | + 'type' => 'plugin', |
|
186 | + 'action' => 'install', |
|
187 | + ), |
|
188 | + ) ); |
|
189 | + |
|
190 | + if ( is_wp_error( $result ) ) { |
|
191 | + throw new Exception( $result->get_error_message() ); |
|
192 | + } |
|
193 | + |
|
194 | + $activate = true; |
|
195 | + |
|
196 | + } catch ( Exception $e ) { |
|
197 | + $success = false; |
|
198 | + } |
|
199 | + |
|
200 | + // Discard feedback |
|
201 | + ob_end_clean(); |
|
202 | + } |
|
203 | + |
|
204 | + wp_clean_plugins_cache(); |
|
205 | + |
|
206 | + // Activate this thing |
|
207 | + if ( $activate ) { |
|
208 | + try { |
|
209 | + $result = activate_plugin( $plugin ); |
|
210 | + |
|
211 | + if ( is_wp_error( $result ) ) { |
|
212 | + $success = false; |
|
213 | + } else { |
|
214 | + $success = true; |
|
215 | + } |
|
216 | + } catch ( Exception $e ) { |
|
217 | + $success = false; |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + if ( $success && function_exists( 'ayecode_connect_args' ) ) { |
|
223 | + ayecode_connect();// init |
|
224 | + $args = ayecode_connect_args(); |
|
225 | + $client = new AyeCode_Connect( $args ); |
|
226 | + $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : ''; |
|
227 | + $redirect = $client->build_connect_url( $redirect_to ); |
|
228 | + wp_send_json_success( array( 'connect_url' => $redirect ) ); |
|
229 | + } else { |
|
230 | + wp_send_json_error( $this->strings['error_localhost'] ); |
|
231 | + } |
|
232 | + wp_die(); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Check if maybe localhost. |
|
237 | + * |
|
238 | + * @return bool |
|
239 | + */ |
|
240 | + public function is_localhost() { |
|
241 | + $localhost = false; |
|
242 | + |
|
243 | + $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; |
|
244 | + $localhost_domains = array( |
|
245 | + 'localhost', |
|
246 | + 'localhost.localdomain', |
|
247 | + '127.0.0.1', |
|
248 | + '::1' |
|
249 | + ); |
|
250 | + |
|
251 | + if ( in_array( $host, $localhost_domains ) ) { |
|
252 | + $localhost = true; |
|
253 | + } |
|
254 | + |
|
255 | + return $localhost; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Show notice to connect site. |
|
260 | + */ |
|
261 | + public function ayecode_connect_install_notice() { |
|
262 | + if ( $this->maybe_show() ) { |
|
263 | + $connect_title_string = $this->strings['connect_title']; |
|
264 | + $connect_external_string = $this->strings['connect_external']; |
|
265 | + $connect_string = $this->strings['connect']; |
|
266 | + $connect_button_string = $this->strings['connect_button']; |
|
267 | + $connecting_button_string = $this->strings['connecting_button']; |
|
268 | + ?> |
|
269 | 269 | <div class="notice notice-info acch-notice"> |
270 | 270 | <span class="acch-float-left"> |
271 | 271 | <svg width="61px" height="61px" viewBox="0 0 61 61" version="1.1" |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | <h3 class="acch-title"><?php echo esc_html( $connect_title_string ); ?></h3> |
305 | 305 | <p> |
306 | 306 | <?php |
307 | - echo wp_kses_post( $connect_string ); |
|
308 | - ?> |
|
307 | + echo wp_kses_post( $connect_string ); |
|
308 | + ?> |
|
309 | 309 | </p> |
310 | 310 | </span> |
311 | 311 | |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | </div> |
319 | 319 | |
320 | 320 | <?php |
321 | - // only include the popup HTML if needed. |
|
322 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
323 | - ?> |
|
321 | + // only include the popup HTML if needed. |
|
322 | + if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
323 | + ?> |
|
324 | 324 | <div id="ayecode-connect-helper-external-confirm" style="display:none;"> |
325 | 325 | <div class="noticex notice-info acch-notice" style="border: none;"> |
326 | 326 | <span class="acch-float-left"> |
@@ -369,23 +369,23 @@ discard block |
||
369 | 369 | </div> |
370 | 370 | </div> |
371 | 371 | <?php |
372 | - } |
|
373 | - |
|
374 | - // add required scripts |
|
375 | - $this->script(); |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Get the JS Script. |
|
381 | - */ |
|
382 | - public function script() { |
|
383 | - |
|
384 | - // add thickbox if external request is requested |
|
385 | - if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
386 | - add_thickbox(); |
|
387 | - } |
|
388 | - ?> |
|
372 | + } |
|
373 | + |
|
374 | + // add required scripts |
|
375 | + $this->script(); |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Get the JS Script. |
|
381 | + */ |
|
382 | + public function script() { |
|
383 | + |
|
384 | + // add thickbox if external request is requested |
|
385 | + if ( ! empty( $_REQUEST['external-connect-request'] ) ) { |
|
386 | + add_thickbox(); |
|
387 | + } |
|
388 | + ?> |
|
389 | 389 | <style> |
390 | 390 | .acch-title { |
391 | 391 | margin: 0; |
@@ -454,43 +454,43 @@ discard block |
||
454 | 454 | |
455 | 455 | |
456 | 456 | <?php |
457 | - // add thickbox if external request is requested |
|
458 | - if(! empty( $_REQUEST['external-connect-request'] )) { |
|
459 | - ?> |
|
457 | + // add thickbox if external request is requested |
|
458 | + if(! empty( $_REQUEST['external-connect-request'] )) { |
|
459 | + ?> |
|
460 | 460 | jQuery(function () { |
461 | 461 | setTimeout(function () { |
462 | 462 | tb_show("AyeCode Connect", "?TB_inline?width=300&height=80&inlineId=ayecode-connect-helper-external-confirm"); |
463 | 463 | }, 200); |
464 | 464 | }); |
465 | 465 | <?php |
466 | - } |
|
467 | - ?> |
|
466 | + } |
|
467 | + ?> |
|
468 | 468 | |
469 | 469 | </script> |
470 | 470 | <?php |
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Decide what pages to show on. |
|
475 | - * |
|
476 | - * @return bool |
|
477 | - */ |
|
478 | - public function maybe_show() { |
|
479 | - $show = false; |
|
480 | - |
|
481 | - // check if on a page set to show |
|
482 | - if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
483 | - |
|
484 | - // check if not active and connected |
|
485 | - if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
486 | - $show = true; |
|
487 | - } |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Decide what pages to show on. |
|
475 | + * |
|
476 | + * @return bool |
|
477 | + */ |
|
478 | + public function maybe_show() { |
|
479 | + $show = false; |
|
480 | + |
|
481 | + // check if on a page set to show |
|
482 | + if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) { |
|
483 | + |
|
484 | + // check if not active and connected |
|
485 | + if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) { |
|
486 | + $show = true; |
|
487 | + } |
|
488 | 488 | |
489 | - } |
|
489 | + } |
|
490 | 490 | |
491 | - return $show; |
|
492 | - } |
|
491 | + return $show; |
|
492 | + } |
|
493 | 493 | |
494 | - } |
|
494 | + } |
|
495 | 495 | |
496 | 496 | } |
@@ -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 |