HEX
Server: Apache/2.4.29 (Ubuntu)
System: Linux instance-1 5.4.0-1092-gcp #101~18.04.1-Ubuntu SMP Mon Oct 17 18:29:06 UTC 2022 x86_64
User: web202 (5061)
PHP: 8.1.14
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, exec, shell_exec, system, passthru, proc_open, proc_close, popen, parse_ini_file, show_source
Upload Files
File: /data0/www/clients/client33/web202/web/wp-content/plugins/woocommerce-services/src/Utils.php
<?php
/**
 * General Automattic\WCServices utils.
 *
 * Provides utility functions useful for multiple parts of WCServices.
 *
 * @package Automattic\WCServices
 */

namespace Automattic\WCServices;

use WC_Connect_Loader;

/**
 * Automattic\WCServices utils class.
 */
class Utils {
	/**
	 * Get WooCommerce Services plugin version.
	 *
	 * @return string
	 */
	public static function get_wcservices_version() {
		return WC_Connect_Loader::get_wcs_version();
	}

	/**
	 * Get the base URL for enqueuing assets.
	 *
	 * @return string
	 */
	public static function get_enqueue_base_url(): string {
		return trailingslashit( defined( 'WOOCOMMERCE_CONNECT_DEV_SERVER_URL' ) ? WOOCOMMERCE_CONNECT_DEV_SERVER_URL : WCSERVICES_PLUGIN_DIST_URL );
	}

	/**
	 * Get the plugin directory path.
	 * This is a helper function to get the plugin directory path for either the main plugin or the WooCommerce plugin.
	 *
	 * @param bool $for_woocommerce Whether to get the path for the WooCommerce plugin.
	 * @return string The plugin directory path.
	 */
	public static function get_plugin_path( $for_woocommerce = false ) {
		return $for_woocommerce ? plugin_dir_path( WC_PLUGIN_FILE ) : plugin_dir_path( WCSERVICES_PLUGIN_FILE );
	}

	/**
	 * Get the file modified time as a cache buster if we're in dev mode.
	 *
	 * @param string $file Local path to the file.
	 *
	 * @return string The cache buster value to use for the given file.
	 */
	public static function get_file_version( string $file ): string {
		if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && file_exists( $file ) ) {
			return (string) filemtime( $file );
		}

		return self::get_wcservices_version();
	}

	/**
	 * Get sanitized request data.
	 *
	 * @param string $key     The key to get the data for.
	 * @param string $default The default value to return if the key is not set.
	 * @return string The sanitized data as a string.
	 */
	public static function get_sanitized_request_data( string $key, string $default = '' ): string {
		return sanitize_text_field( wp_unslash( $_REQUEST[ $key ] ?? $default ) );
	}
}