PluginProbe
RabbitLoader / 2.18.2
RabbitLoader v2.18.2
4.0.2 4.0.1 4.0 3.2.0 3.1.1 3.1.0 3.0.5 3.0.3 3.0.4 2.17.1 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.7 2.18.0 2.18.1 2.18.2 2.18.3 2.18.4 2.18.5 2.18.6 2.18.7 2.18.8 All 129 releases
rabbit-loader / inc / util_wp.php

util_wp.php in RabbitLoader 2.18.2, at inc/util_wp.php

136 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ?>