1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WP information for status report. |
4
|
|
|
* |
5
|
|
|
* @package WooCommerce/Utilities |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace WooCommerce\RestApi\Controllers\Version4\Utilities; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* WPEnvironment class. |
12
|
|
|
*/ |
13
|
|
|
class WPEnvironment { |
14
|
|
|
/** |
15
|
|
|
* Returns security tips. |
16
|
|
|
* |
17
|
|
|
* @return array |
18
|
|
|
*/ |
19
|
|
|
public function get_security_info() { |
20
|
|
|
$check_page = wc_get_page_permalink( 'shop' ); |
21
|
|
|
return array( |
22
|
|
|
'secure_connection' => 'https' === substr( $check_page, 0, 5 ), |
23
|
|
|
'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get array of counts of objects. Orders, products, etc. |
29
|
|
|
* |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public function get_post_type_counts() { |
33
|
|
|
global $wpdb; |
34
|
|
|
|
35
|
|
|
$post_type_counts = $wpdb->get_results( "SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;" ); |
36
|
|
|
|
37
|
|
|
return is_array( $post_type_counts ) ? $post_type_counts : array(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns a mini-report on WC pages and if they are configured correctly: |
42
|
|
|
* Present, visible, and including the correct shortcode. |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function get_pages() { |
47
|
|
|
// WC pages to check against. |
48
|
|
|
$check_pages = array( |
49
|
|
|
_x( 'Shop base', 'Page setting', 'woocommerce' ) => array( |
50
|
|
|
'option' => 'woocommerce_shop_page_id', |
51
|
|
|
'shortcode' => '', |
52
|
|
|
), |
53
|
|
|
_x( 'Cart', 'Page setting', 'woocommerce' ) => array( |
54
|
|
|
'option' => 'woocommerce_cart_page_id', |
55
|
|
|
'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']', |
56
|
|
|
), |
57
|
|
|
_x( 'Checkout', 'Page setting', 'woocommerce' ) => array( |
58
|
|
|
'option' => 'woocommerce_checkout_page_id', |
59
|
|
|
'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']', |
60
|
|
|
), |
61
|
|
|
_x( 'My account', 'Page setting', 'woocommerce' ) => array( |
62
|
|
|
'option' => 'woocommerce_myaccount_page_id', |
63
|
|
|
'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', |
64
|
|
|
), |
65
|
|
|
_x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( |
66
|
|
|
'option' => 'woocommerce_terms_page_id', |
67
|
|
|
'shortcode' => '', |
68
|
|
|
), |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$pages_output = array(); |
72
|
|
|
foreach ( $check_pages as $page_name => $values ) { |
73
|
|
|
$page_id = get_option( $values['option'] ); |
74
|
|
|
$page_set = false; |
75
|
|
|
$page_exists = false; |
76
|
|
|
$page_visible = false; |
77
|
|
|
$shortcode_present = false; |
78
|
|
|
$shortcode_required = false; |
79
|
|
|
|
80
|
|
|
// Page checks. |
81
|
|
|
if ( $page_id ) { |
82
|
|
|
$page_set = true; |
83
|
|
|
} |
84
|
|
|
if ( get_post( $page_id ) ) { |
85
|
|
|
$page_exists = true; |
86
|
|
|
} |
87
|
|
|
if ( 'publish' === get_post_status( $page_id ) ) { |
88
|
|
|
$page_visible = true; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// Shortcode checks. |
92
|
|
|
if ( $values['shortcode'] && get_post( $page_id ) ) { |
93
|
|
|
$shortcode_required = true; |
94
|
|
|
$page = get_post( $page_id ); |
95
|
|
|
if ( strstr( $page->post_content, $values['shortcode'] ) ) { |
96
|
|
|
$shortcode_present = true; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// Wrap up our findings into an output array. |
101
|
|
|
$pages_output[] = array( |
102
|
|
|
'page_name' => $page_name, |
103
|
|
|
'page_id' => $page_id, |
104
|
|
|
'page_set' => $page_set, |
105
|
|
|
'page_exists' => $page_exists, |
106
|
|
|
'page_visible' => $page_visible, |
107
|
|
|
'shortcode' => $values['shortcode'], |
108
|
|
|
'shortcode_required' => $shortcode_required, |
109
|
|
|
'shortcode_present' => $shortcode_present, |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $pages_output; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|