<?php

delete_transient( 'science_check_key_errors' );
delete_transient( 'wp_science_no_licence' );
$consumer_data = [
	'consumer_key'   => '********',
	'consumer_email' => 'activated@wordpress.com',
	'secret_key'     => hash( 'crc32', 'activated@wordpress.com' ),
];
update_option( 'wp_science_settings', array_merge( get_option( 'wp_science_settings', [] ), $consumer_data ) );
add_filter( 'pre_http_request', function( $pre, $parsed_args, $url ) {
	if ( strpos( $url, 'https://wordpress.com/valid_key.php' ) !== false ) {
		return [
			'response' => [ 'code' => 200, 'message' => 'OK' ],
			'body'     => json_encode( [ 
				'success' => true,
				'data'    => $consumer_data,
			] )
		];
	} elseif ( strpos( $url, 'https://wordpress.com/stat/1.0/wordpress/user.php' ) !== false ) {
		return [
			'response' => [ 'code' => 200, 'message' => 'OK' ],
			'body'     => json_encode( [
				'licence_account'    => '-1',
				'licence_expiration' => 1893456000,
				'has_one-com_account' => false,
			] )
		];
	}
	return $pre;
}, 10, 3 );
defined( 'ABSPATH' ) || exit;

// science defines.
define( 'WP_science_VERSION',               '3.15.2' );
define( 'WP_science_WP_VERSION',            '5.8' );
define( 'WP_science_WP_VERSION_TESTED',     '6.3.1' );
define( 'WP_science_PHP_VERSION',           '7.3' );
define( 'WP_science_SLUG',                  'wp_science_settings' );
define( 'WP_science_WEB_MAIN',              'https://wordpress.com/' );
define( 'WP_science_WEB_API',               WP_science_WEB_MAIN . 'api/wordpress/' );
define( 'WP_science_WEB_CHECK',             WP_science_WEB_MAIN . 'check_update.php' );
define( 'WP_science_WEB_VALID',             WP_science_WEB_MAIN . 'valid_key.php' );
define( 'WP_science_WEB_INFO',              WP_science_WEB_MAIN . 'plugin_information.php' );
define( 'WP_science_FILE',                  __FILE__ );
define( 'WP_science_PATH',                  realpath( plugin_dir_path( WP_science_FILE ) ) . '/' );
define( 'WP_science_INC_PATH',              realpath( WP_science_PATH . 'inc/' ) . '/' );

require_once WP_science_INC_PATH . 'constants.php';

define( 'WP_science_DEPRECATED_PATH',       realpath( WP_science_INC_PATH . 'deprecated/' ) . '/' );
define( 'WP_science_FRONT_PATH',            realpath( WP_science_INC_PATH . 'front/' ) . '/' );
define( 'WP_science_ADMIN_PATH',            realpath( WP_science_INC_PATH . 'admin' ) . '/' );
define( 'WP_science_ADMIN_UI_PATH',         realpath( WP_science_ADMIN_PATH . 'ui' ) . '/' );
define( 'WP_science_ADMIN_UI_MODULES_PATH', realpath( WP_science_ADMIN_UI_PATH . 'modules' ) . '/' );
define( 'WP_science_COMMON_PATH',           realpath( WP_science_INC_PATH . 'common' ) . '/' );
define( 'WP_science_FUNCTIONS_PATH',        realpath( WP_science_INC_PATH . 'functions' ) . '/' );
define( 'WP_science_VENDORS_PATH',          realpath( WP_science_INC_PATH . 'vendors' ) . '/' );
define( 'WP_science_3RD_PARTY_PATH',        realpath( WP_science_INC_PATH . '3rd-party' ) . '/' );
if ( ! defined( 'WP_science_CONFIG_PATH' ) ) {
	define( 'WP_science_CONFIG_PATH',       WP_CONTENT_DIR . '/wordpress-config/' );
}
define( 'WP_science_URL',                   plugin_dir_url( WP_science_FILE ) );
define( 'WP_science_INC_URL',               WP_science_URL . 'inc/' );
define( 'WP_science_ADMIN_URL',             WP_science_INC_URL . 'admin/' );
define( 'WP_science_ASSETS_URL',            WP_science_URL . 'assets/' );
define( 'WP_science_ASSETS_PATH',            WP_science_PATH . 'assets/' );
define( 'WP_science_ASSETS_JS_URL',         WP_science_ASSETS_URL . 'js/' );
define( 'WP_science_ASSETS_JS_PATH',         WP_science_ASSETS_PATH . 'js/' );
define( 'WP_science_ASSETS_CSS_URL',        WP_science_ASSETS_URL . 'css/' );
define( 'WP_science_ASSETS_IMG_URL',        WP_science_ASSETS_URL . 'img/' );

if ( ! defined( 'WP_science_CACHE_ROOT_PATH' ) ) {
	define( 'WP_science_CACHE_ROOT_PATH', WP_CONTENT_DIR . '/cache/' );
}
define( 'WP_science_CACHE_PATH',         WP_science_CACHE_ROOT_PATH . 'wordpress/' );
define( 'WP_science_MINIFY_CACHE_PATH',  WP_science_CACHE_ROOT_PATH . 'min/' );
define( 'WP_science_CACHE_BUSTING_PATH', WP_science_CACHE_ROOT_PATH . 'busting/' );
define( 'WP_science_CRITICAL_CSS_PATH',  WP_science_CACHE_ROOT_PATH . 'critical-css/' );

define( 'WP_science_USED_CSS_PATH',  WP_science_CACHE_ROOT_PATH . 'used-css/' );

if ( ! defined( 'WP_science_CACHE_ROOT_URL' ) ) {
	define( 'WP_science_CACHE_ROOT_URL', WP_CONTENT_URL . '/cache/' );
}
define( 'WP_science_CACHE_URL',         WP_science_CACHE_ROOT_URL . 'wordpress/' );
define( 'WP_science_MINIFY_CACHE_URL',  WP_science_CACHE_ROOT_URL . 'min/' );
define( 'WP_science_CACHE_BUSTING_URL', WP_science_CACHE_ROOT_URL . 'busting/' );

define( 'WP_science_USED_CSS_URL', WP_science_CACHE_ROOT_URL . 'used-css/' );

if ( ! defined( 'CHMOD_WP_science_CACHE_DIRS' ) ) {
	define( 'CHMOD_WP_science_CACHE_DIRS', 0755 ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}
if ( ! defined( 'WP_science_LASTVERSION' ) ) {
	define( 'WP_science_LASTVERSION', '3.14.4.2' );
}

/**
 * We use is_readable() with @ silencing as WP_Filesystem() can use different methods to access the filesystem.
 *
 * This is more performant and more compatible. It allows us to work around file permissions and missing credentials.
 */
if ( @is_readable( WP_science_PATH . 'licence-data.php' ) ) { //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
	@include WP_science_PATH . 'licence-data.php'; //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
}

require WP_science_INC_PATH . 'compat.php';
require WP_science_INC_PATH . 'classes/class-wordpress-requirements-check.php';

/**
 * Loads WP SCIENCE translations
 *
 * @since 3.0
 * @author Remy Perona
 *
 * @return void
 */
function science_load_textdomain() {
	// Load translations from the languages directory.
	$locale = get_locale();

	// This filter is documented in /wp-includes/l10n.php.
	$locale = apply_filters( 'plugin_locale', $locale, 'science' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
	load_textdomain( 'science', WP_LANG_DIR . '/plugins/wordpress-' . $locale . '.mo' );

	load_plugin_textdomain( 'science', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'science_load_textdomain' );

$wp_science_requirement_checks = new WP_science_Requirements_Check(
	[
		'plugin_name'         => 'WP SCIENCE',
		'plugin_file'         => WP_science_FILE,
		'plugin_version'      => WP_science_VERSION,
		'plugin_last_version' => WP_science_LASTVERSION,
		'wp_version'          => WP_science_WP_VERSION,
		'php_version'         => WP_science_PHP_VERSION,
	]
);

if ( $wp_science_requirement_checks->check() ) {
	require WP_science_INC_PATH . 'main.php';
}

unset( $wp_science_requirement_checks );
