/var/www/html/wp-content/plugins/woocommerce/vendor/automattic/jetpack-status/src/class-paths.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
 * A Path & URL utility class for Jetpack.
 *
 * @package automattic/jetpack-status
 */

namespace Automattic\Jetpack;

/**
 * Class Automattic\Jetpack\Paths
 *
 * Used to retrieve information about files.
 */
class Paths {
    
/**
     * Jetpack Admin URL.
     *
     * @param array $args Query string args.
     *
     * @return string Jetpack admin URL.
     */
    
public function admin_url$args null ) {
        
$args wp_parse_args$args, array( 'page' => 'jetpack' ) );
        
$url  add_query_arg$argsadmin_url'admin.php' ) );
        return 
$url;
    }

    
/**
     * Determine if the current request is activating a plugin from the plugins page.
     *
     * @param string $plugin Plugin file path to check.
     * @return bool
     */
    
public function is_current_request_activating_plugin_from_plugins_screen$plugin ) {
        
// Filter out common async request contexts
        
if (
            
wp_doing_ajax() ||
            ( 
defined'REST_REQUEST' ) && REST_REQUEST ) ||
            ( 
defined'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
            ( 
defined'WP_CLI' ) && WP_CLI )
        ) {
            return 
false;
        }

        if ( isset( 
$_SERVER['SCRIPT_NAME'] ) ) {
            
$request_file esc_url_rawwp_unslash$_SERVER['SCRIPT_NAME'] ) );
        } elseif ( isset( 
$_SERVER['REQUEST_URI'] ) ) {
            list( 
$request_file ) = explode'?'esc_url_rawwp_unslash$_SERVER['REQUEST_URI'] ) ) );
        } else {
            return 
false;
        }

        
// Not the plugins page
        
if ( strpos$request_file'wp-admin/plugins.php' ) === false ) {
            return 
false;
        }

        
// Same method to get the action as used by plugins.php
        
$wp_list_table _get_list_table'WP_Plugins_List_Table' );
        
$action        $wp_list_table->current_action();

        
// Not a singular activation
        // This also means that if the plugin is activated as part of a group ( bulk activation ), this function will return false here.
        
if ( 'activate' !== $action ) {
            return 
false;
        }

        
// Check the nonce associated with the plugin activation
        // We are not changing any data here, so this is not super necessary, it's just a best practice before using the form data from $_REQUEST.
        
check_admin_referer'activate-plugin_' $plugin );

        
// Not the right plugin
        
$requested_plugin = isset( $_REQUEST['plugin'] ) ? sanitize_text_fieldwp_unslash$_REQUEST['plugin'] ) ) : null;
        if ( 
$requested_plugin !== $plugin ) {
            return 
false;
        }

        return 
true;
    }
}