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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Admin / WCAdminHelper.php
woocommerce / src / Admin Last commit date
API 5 days ago BlockTemplates 2 years ago Composer 2 years ago DateTimeProvider 4 years ago Features 4 weeks ago Marketing 1 year ago Notes 4 weeks ago Overrides 2 months ago PluginsInstallLoggers 1 year ago PluginsProvider 4 years ago RemoteInboxNotifications 4 weeks ago RemoteSpecs 2 months ago Schedulers 1 year ago Settings 2 weeks ago DataSourcePoller.php 2 years ago DeprecatedClassFacade.php 1 year ago FeaturePlugin.php 4 years ago Loader.php 2 years ago PageController.php 4 weeks ago PluginsHelper.php 4 weeks ago PluginsInstaller.php 4 years ago ReportCSVEmail.php 1 year ago ReportCSVExporter.php 1 year ago ReportExporter.php 3 years ago ReportsSync.php 4 months ago WCAdminHelper.php 4 weeks ago
WCAdminHelper.php
236 lines
1 <?php
2 /**
3 * WCAdminHelper
4 *
5 * Helper class for generic WCAdmin functions.
6 */
7
8 namespace Automattic\WooCommerce\Admin;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Class WCAdminHelper
14 */
15 class WCAdminHelper {
16 /**
17 * WC Admin timestamp option name.
18 */
19 const WC_ADMIN_TIMESTAMP_OPTION = 'woocommerce_admin_install_timestamp';
20
21 const WC_ADMIN_STORE_AGE_RANGES = array(
22 'week-1' => array(
23 'start' => 0,
24 'end' => WEEK_IN_SECONDS,
25 ),
26 'week-1-4' => array(
27 'start' => WEEK_IN_SECONDS,
28 'end' => WEEK_IN_SECONDS * 4,
29 ),
30 'month-1-3' => array(
31 'start' => MONTH_IN_SECONDS,
32 'end' => MONTH_IN_SECONDS * 3,
33 ),
34 'month-3-6' => array(
35 'start' => MONTH_IN_SECONDS * 3,
36 'end' => MONTH_IN_SECONDS * 6,
37 ),
38 'month-6+' => array(
39 'start' => MONTH_IN_SECONDS * 6,
40 ),
41 );
42
43 /**
44 * Get the number of seconds that the store has been active.
45 *
46 * @return number Number of seconds.
47 */
48 public static function get_wcadmin_active_for_in_seconds() {
49 $install_timestamp = get_option( self::WC_ADMIN_TIMESTAMP_OPTION );
50
51 if ( ! is_numeric( $install_timestamp ) ) {
52 $install_timestamp = time();
53 update_option( self::WC_ADMIN_TIMESTAMP_OPTION, $install_timestamp );
54 }
55
56 return time() - $install_timestamp;
57 }
58
59
60 /**
61 * Test how long WooCommerce Admin has been active.
62 *
63 * @param int $seconds Time in seconds to check.
64 * @return bool Whether or not WooCommerce admin has been active for $seconds.
65 */
66 public static function is_wc_admin_active_for( $seconds ) {
67 $wc_admin_active_for = self::get_wcadmin_active_for_in_seconds();
68
69 return ( $wc_admin_active_for >= $seconds );
70 }
71
72 /**
73 * Test if WooCommerce Admin has been active within a pre-defined range.
74 *
75 * @param string $range range available in WC_ADMIN_STORE_AGE_RANGES.
76 * @param int $custom_start custom start in range.
77 * @throws \InvalidArgumentException Throws exception when invalid $range is passed in.
78 * @return bool Whether or not WooCommerce admin has been active within the range.
79 */
80 public static function is_wc_admin_active_in_date_range( $range, $custom_start = null ) {
81 if ( ! array_key_exists( $range, self::WC_ADMIN_STORE_AGE_RANGES ) ) {
82 throw new \InvalidArgumentException(
83 sprintf(
84 '"%s" range is not supported, use one of: %s',
85 $range,
86 implode( ', ', array_keys( self::WC_ADMIN_STORE_AGE_RANGES ) )
87 )
88 );
89 }
90 $wc_admin_active_for = self::get_wcadmin_active_for_in_seconds();
91
92 $range_data = self::WC_ADMIN_STORE_AGE_RANGES[ $range ];
93 $start = null !== $custom_start ? $custom_start : $range_data['start'];
94 if ( $range_data && $wc_admin_active_for >= $start ) {
95 return isset( $range_data['end'] ) ? $wc_admin_active_for < $range_data['end'] : true;
96 }
97 return false;
98 }
99
100 /**
101 * Test if the site is fresh. A fresh site must meet the following requirements.
102 *
103 * - The current user was registered less than 1 month ago.
104 * - fresh_site option must be 1
105 *
106 * @return bool
107 */
108 public static function is_site_fresh() {
109 $fresh_site = get_option( 'fresh_site' );
110 if ( '1' !== $fresh_site ) {
111 return false;
112 }
113
114 $current_userdata = get_userdata( get_current_user_id() );
115 // Return false if we can't get user meta data for some reason.
116 if ( ! $current_userdata ) {
117 return false;
118 }
119
120 $date = new \DateTime( $current_userdata->user_registered );
121 $month_ago = new \DateTime( '-1 month' );
122
123 return $date > $month_ago;
124 }
125
126 /**
127 * Check if the current page is a store page.
128 *
129 * This should only be called when WP has has set up the query, typically during or after the parse_query or template_redirect action hooks.
130 *
131 * @return bool
132 */
133 public static function is_current_page_store_page() {
134 // WC store pages.
135 $store_pages = array(
136 'shop' => wc_get_page_id( 'shop' ),
137 'cart' => wc_get_page_id( 'cart' ),
138 'checkout' => wc_get_page_id( 'checkout' ),
139 'terms' => wc_terms_and_conditions_page_id(),
140 'coming_soon' => wc_get_page_id( 'coming_soon' ),
141 );
142
143 /**
144 * Filter the store pages array to check if a URL is a store page.
145 *
146 * @since 8.8.0
147 * @param array $store_pages The store pages array. The keys are the page slugs and the values are the page IDs.
148 */
149 $store_pages = apply_filters( 'woocommerce_store_pages', $store_pages );
150 _prime_post_caches( array_values( array_filter( $store_pages ) ), false, false );
151
152 foreach ( $store_pages as $page_slug => $page_id ) {
153 if ( $page_id > 0 && is_page( $page_id ) ) {
154 return true;
155 }
156 }
157
158 // Product archive page.
159 if ( is_post_type_archive( 'product' ) ) {
160 return true;
161 }
162
163 // Product page.
164 if ( is_singular( 'product' ) ) {
165 return true;
166 }
167
168 // Product taxonomy page (e.g. Product Category, Product Tag, etc.).
169 if ( is_product_taxonomy() ) {
170 return true;
171 }
172
173 global $wp;
174 $url = self::get_url_from_wp( $wp );
175
176 /**
177 * Filter if a URL is a store page.
178 *
179 * @since 9.3.0
180 * @param bool $is_store_page Whether or not the URL is a store page.
181 * @param string $url URL to check.
182 */
183 $is_store_page = apply_filters( 'woocommerce_is_extension_store_page', false, $url );
184
185 return filter_var( $is_store_page, FILTER_VALIDATE_BOOL );
186 }
187
188 /**
189 * Test if a URL is a store page.
190 *
191 * @param string $url URL to check. If not provided, the current URL will be used.
192 * @return bool Whether or not the URL is a store page.
193 * @deprecated 9.8.0 Use is_current_page_store_page instead.
194 */
195 public static function is_store_page( $url = '' ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
196 _deprecated_function( __METHOD__, '9.8.0', 'is_current_page_store_page' );
197 return self::is_current_page_store_page();
198 }
199
200 /**
201 * Get normalized URL path.
202 * 1. Only keep the path and query string (if any).
203 * 2. Remove wp home path from the URL path if WP is installed in a subdirectory.
204 * 3. Remove leading and trailing slashes.
205 *
206 * For example:
207 *
208 * - https://example.com/wordpress/shop/uncategorized/test/?add-to-cart=123 => shop/uncategorized/test/?add-to-cart=123
209 *
210 * @param string $url URL to normalize.
211 */
212 private static function get_normalized_url_path( $url ) {
213 $query = wp_parse_url( $url, PHP_URL_QUERY );
214 $path = wp_parse_url( $url, PHP_URL_PATH ) . ( $query ? '?' . $query : '' );
215 $home_path = wp_parse_url( site_url(), PHP_URL_PATH ) ?? '';
216 $normalized_path = trim( substr( $path, strlen( $home_path ) ), '/' );
217 return $normalized_path;
218 }
219
220 /**
221 * Builds the relative URL from the WP instance.
222 *
223 * @internal
224 * @link https://wordpress.stackexchange.com/a/274572
225 * @param \WP $wp WordPress environment instance.
226 */
227 private static function get_url_from_wp( \WP $wp ) {
228 // Initialize query vars if they haven't been set.
229 if ( empty( $wp->query_vars ) || empty( $wp->request ) ) {
230 $wp->parse_request();
231 }
232
233 return home_url( add_query_arg( $wp->query_vars, $wp->request ) );
234 }
235 }
236