← All changes
|
includes/core/rest-api/Controllers/class-wpfnl-rest-controller.php
+37
-5
2.8.16
→
3.13.3
View file →
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * WPFunnels rest api controllers |
| 4 | - * | |
| 4 | + * | |
| 5 | 5 | * @package WPFunnels\Rest\Controller |
| 6 | 6 | */ |
| 7 | 7 | namespace WPFunnels\Rest\Controllers; |
| 8 | 8 | |
| @@ -29,9 +29,9 @@ | ||
| 29 | 29 | * Prepare links for the request. |
| 30 | 30 | * |
| 31 | 31 | * @param string $setting_id Setting ID. |
| 32 | 32 | * @param string $group_id Group ID. |
| 33 | - * | |
| 33 | + * | |
| 34 | 34 | * @return array Links for the given setting. |
| 35 | 35 | * @since 3.0.0 |
| 36 | 36 | */ |
| 37 | 37 | protected function prepare_links( $setting_id ) { |
| @@ -54,9 +54,9 @@ | ||
| 54 | 54 | * @param string $error_message The error message. |
| 55 | 55 | * @param int $status The HTTP status code. |
| 56 | 56 | * |
| 57 | 57 | * @return WP_Error The created WP_Error object. |
| 58 | - * | |
| 58 | + * | |
| 59 | 59 | * @since 2.7.9 |
| 60 | 60 | */ |
| 61 | 61 | protected function prepare_wp_error_response( $error_code, $error_message, $data ) { |
| 62 | 62 | return new WP_Error( |
| @@ -61,9 +61,9 @@ | ||
| 61 | 61 | protected function prepare_wp_error_response( $error_code, $error_message, $data ) { |
| 62 | 62 | return new WP_Error( |
| 63 | 63 | $error_code, |
| 64 | 64 | $error_message, |
| 65 | - $data | |
| 65 | + $data | |
| 66 | 66 | ); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| @@ -72,9 +72,9 @@ | ||
| 72 | 72 | * @param string $message Success message. |
| 73 | 73 | * @param int $code Success coed. |
| 74 | 74 | * |
| 75 | 75 | * @return WP_Rest_Response The created WP_Rest_response object. |
| 76 | - * | |
| 76 | + * | |
| 77 | 77 | * @since 2.7.9 |
| 78 | 78 | */ |
| 79 | 79 | protected function prepare_wp_success_response( $message, $code ) { |
| 80 | 80 | $response = array( |
| @@ -83,5 +83,37 @@ | ||
| 83 | 83 | 'status' => $code |
| 84 | 84 | ); |
| 85 | 85 | return rest_ensure_response( $response ); |
| 86 | 86 | } |
| 87 | + | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Returns default 'before' parameter for the reports. | |
| 91 | + * | |
| 92 | + * @return \WC_DateTime | |
| 93 | + * @throws \Exception | |
| 94 | + * @since 3.1.7 | |
| 95 | + */ | |
| 96 | + public function default_before() { | |
| 97 | + $datetime = new \DateTime(); | |
| 98 | + $datetime->setTimezone( new \DateTimeZone( wpf_timezone_string() ) ); | |
| 99 | + return $datetime; | |
| 100 | + } | |
| 101 | + | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * Returns default 'after' parameter for the reports. | |
| 105 | + * | |
| 106 | + * @return \Wpfnl_DateTime | |
| 107 | + * @throws \Exception | |
| 108 | + * @since 3.1.7 | |
| 109 | + */ | |
| 110 | + public function default_after() { | |
| 111 | + $now = time(); | |
| 112 | + $week_back = $now - YEAR_IN_SECONDS; | |
| 113 | + | |
| 114 | + $datetime = new \DateTime(); | |
| 115 | + $datetime->setTimestamp( $week_back ); | |
| 116 | + $datetime->setTimezone( new \DateTimeZone( wpf_timezone_string() ) ); | |
| 117 | + return $datetime; | |
| 118 | + } | |
| 87 | 119 | } |