| 1 |
<?php |
| 2 |
|
| 3 |
class RabbitLoader_21_Util_WP{ |
| 4 |
|
| 5 |
private static $isSearch = false; |
| 6 |
private static $isPageAccount = false; |
| 7 |
|
| 8 |
public static function init(){ |
| 9 |
add_action( 'template_redirect', function(){ |
| 10 |
self::$isSearch = (is_search() || !empty($_GET["s"])); |
| 11 |
self::$isPageAccount = (function_exists("is_page") && is_page("account")); |
| 12 |
}); |
| 13 |
} |
| 14 |
|
| 15 |
public static function is_cli(){ |
| 16 |
return (defined("WP_CLI") && WP_CLI); |
| 17 |
} |
| 18 |
|
| 19 |
public static function is_user_logged_in(){ |
| 20 |
|
| 21 |
if(function_exists('is_user_logged_in')){ |
| 22 |
//if WP is not initialized, we may not get the function, so we have to do our own checks as well |
| 23 |
return is_user_logged_in(); |
| 24 |
} |
| 25 |
|
| 26 |
$cookies_keys = []; |
| 27 |
|
| 28 |
if(defined('RABBITLOADER_AC_LOGGED_IN_COOKIE')){ |
| 29 |
$cookies_keys[] = RABBITLOADER_AC_LOGGED_IN_COOKIE; |
| 30 |
} |
| 31 |
|
| 32 |
if(defined('LOGGED_IN_COOKIE')){ |
| 33 |
$cookies_keys[] = LOGGED_IN_COOKIE; |
| 34 |
} |
| 35 |
|
| 36 |
foreach ($cookies_keys as $key) { |
| 37 |
if (!empty($_COOKIE[$key])) { |
| 38 |
return true; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
public static function is_login_page() |
| 46 |
{ |
| 47 |
$is_login = function_exists('is_login') && function_exists('wp_login_url') && is_login(); |
| 48 |
|
| 49 |
$incl_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, ABSPATH); |
| 50 |
|
| 51 |
return $is_login || (in_array($incl_path . 'wp-login.php', get_included_files()) |
| 52 |
|| in_array($incl_path . 'wp-register.php', get_included_files())) |
| 53 |
|| (isset($_GLOBALS['pagenow']) && $GLOBALS['pagenow'] === 'wp-login.php') |
| 54 |
|| $_SERVER['PHP_SELF'] == '/wp-login.php' || self::$isPageAccount; |
| 55 |
} |
| 56 |
|
| 57 |
public static function is_ajax(){ |
| 58 |
|
| 59 |
$incl_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, ABSPATH); |
| 60 |
|
| 61 |
return (function_exists("wp_doing_ajax") && wp_doing_ajax()) || |
| 62 |
(defined('DOING_AJAX') && DOING_AJAX) || |
| 63 |
(!empty($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest") || |
| 64 |
(function_exists('get_included_files') && in_array($incl_path . 'wp-cron.php', get_included_files())) || |
| 65 |
(function_exists('get_included_files') && in_array($incl_path . 'admin-ajax.php', get_included_files())); |
| 66 |
} |
| 67 |
|
| 68 |
public static function is_cart(){ |
| 69 |
$isCart = (function_exists("is_cart") && is_cart()); |
| 70 |
if($isCart){ |
| 71 |
RabbitLoader_21_Core::getWpUserOption($user_options); |
| 72 |
$user_options['cart_uri'] = RabbitLoader_21_Util_Core::serverURINoGet(); |
| 73 |
RabbitLoader_21_Core::updateUserOption($user_options); |
| 74 |
} |
| 75 |
return $isCart; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public static function is_checkout(){ |
| 80 |
$isCheckout = (function_exists("is_checkout") && is_checkout()); |
| 81 |
if($isCheckout){ |
| 82 |
RabbitLoader_21_Core::getWpUserOption($user_options); |
| 83 |
$user_options['checkout_uri'] = RabbitLoader_21_Util_Core::serverURINoGet(); |
| 84 |
RabbitLoader_21_Core::updateUserOption($user_options); |
| 85 |
} |
| 86 |
return $isCheckout; |
| 87 |
} |
| 88 |
|
| 89 |
public static function is_search(){ |
| 90 |
return self::$isSearch; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* @return string directory path (without trailing slash) where cache files are stored |
| 95 |
*/ |
| 96 |
public static function &get_cache_dir($cache_type=''){ |
| 97 |
$cache_dir = ''; |
| 98 |
|
| 99 |
if(defined('RABBITLOADER_AC_CACHE_DIR')){ |
| 100 |
$cache_dir = RABBITLOADER_AC_CACHE_DIR; |
| 101 |
}else if(defined('RABBITLOADER_CACHE_DIR')){ |
| 102 |
$cache_dir = RABBITLOADER_CACHE_DIR; |
| 103 |
}else{ |
| 104 |
$cache_dir = WP_CONTENT_DIR.DIRECTORY_SEPARATOR."rabbitloader"; |
| 105 |
} |
| 106 |
if(!empty($cache_type)){ |
| 107 |
$cache_dir = $cache_dir.DIRECTORY_SEPARATOR.$cache_type; |
| 108 |
} |
| 109 |
return $cache_dir; |
| 110 |
} |
| 111 |
|
| 112 |
public static function get_wp_config(){ |
| 113 |
$wp_config_path = ''; |
| 114 |
if(file_exists( ABSPATH . 'wp-config.php')) { |
| 115 |
$wp_config_path = ABSPATH . 'wp-config.php'; |
| 116 |
} elseif(@file_exists(dirname( ABSPATH ).'/wp-config.php') && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) { |
| 117 |
// config file is not part of another installation |
| 118 |
$wp_config_path = dirname( ABSPATH ) . '/wp-config.php'; |
| 119 |
} else { |
| 120 |
$wp_config_path = false; |
| 121 |
} |
| 122 |
return $wp_config_path; |
| 123 |
} |
| 124 |
|
| 125 |
public static function _e($txt){ |
| 126 |
echo RabbitLoader_21_Util_WP::__($txt); |
| 127 |
} |
| 128 |
public static function __($txt){ |
| 129 |
return __($txt, RABBITLOADER_TEXT_DOMAIN); |
| 130 |
} |
| 131 |
public static function _n($txt_singular, $txt_plural, $count){ |
| 132 |
return _n($txt_singular, $txt_plural, $count, RABBITLOADER_TEXT_DOMAIN); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
?> |