Skip to content

Commit c8908e4

Browse files
authored
Merge pull request #71 from WebDevStudios/fix/cc-75-auth-notice
Fix: Add Server Config Information in Settings
2 parents 109d9c2 + 60a00b0 commit c8908e4

File tree

6 files changed

+237
-5
lines changed

6 files changed

+237
-5
lines changed

app/admin.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
#cc_woo_abandoned_carts_secret_key {
22
width: 90%;
3+
}
4+
5+
#cc_woo_abandoned_carts_rest_endpoints {
6+
display: none !important; /* !important is unfortunately required here to override inline styles. */
7+
}
8+
9+
#cc_woo_abandoned_carts_server_info {
10+
display: none !important; /* !important is unfortunately required here to override inline styles. */
11+
}
12+
13+
#cc_woo_abandoned_carts_rest_endpoints + .description * {
14+
font-style: normal;
15+
}
16+
17+
#cc_woo_abandoned_carts_server_info + .description * {
18+
font-style: normal;
19+
}
20+
21+
.forminp code {
22+
background: none;
23+
white-space: pre-line;
324
}

app/admin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ window.ccWooAdmin = {};
6767
*
6868
* @author George Gecewicz <[email protected]>
6969
* @since 2019-10-24
70+
*
71+
* @param {object} data The AJAX response data from wp.ajax's success callback.
7072
*/
7173
app.handleGenerateKeySuccess = function( data ) {
7274
app.els.input.value = data.key;

src/View/Admin/Field/AbandonedCartsApiSecretKey.php renamed to src/View/Admin/Field/AbandonedCarts/ApiSecretKey.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
* @package cc-woo-view-admin-field
88
*/
99

10-
namespace WebDevStudios\CCForWoo\View\Admin\Field;
10+
namespace WebDevStudios\CCForWoo\View\Admin\Field\AbandonedCarts;
1111

1212
/**
13-
* AbandonedCartsApiSecretKey clss
13+
* ApiSecretKey field class
1414
*
1515
* @since 2019-10-24
1616
* @author George Gecewicz <[email protected]>
1717
* @package cc-woo-view-admin-field
1818
*/
19-
class AbandonedCartsApiSecretKey {
19+
class ApiSecretKey {
2020

2121
/**
2222
* Secret Key field.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Field for showing the REST Endpoints for the Abandoned Carts API.
4+
*
5+
* @since 2019-10-28
6+
* @author George Gecewicz <[email protected]>
7+
* @package cc-woo-view-admin-field
8+
*/
9+
10+
namespace WebDevStudios\CCForWoo\View\Admin\Field\AbandonedCarts;
11+
12+
/**
13+
* RestEndpoints field class
14+
*
15+
* @since 2019-10-28
16+
* @author George Gecewicz <[email protected]>
17+
* @package cc-woo-view-admin-field
18+
*/
19+
class RestEndpoints {
20+
21+
/**
22+
* Rest Endpoints field.
23+
*
24+
* @since 2019-10-28
25+
*
26+
* @var string
27+
*/
28+
const OPTION_FIELD_NAME = 'cc_woo_abandoned_carts_rest_endpoints';
29+
30+
/**
31+
* Returns the form field configuration.
32+
*
33+
* @since 2019-10-28
34+
* @author George Gecewicz <[email protected]>
35+
*
36+
* @return array.
37+
*/
38+
public function get_form_field() : array {
39+
return [
40+
'title' => esc_html__( 'REST Endpoints', 'cc-woo' ),
41+
'desc' => $this->get_description(),
42+
'type' => 'text',
43+
'id' => self::OPTION_FIELD_NAME,
44+
'default' => '',
45+
'custom_attributes' => [
46+
'readonly' => 'true',
47+
],
48+
];
49+
}
50+
51+
/**
52+
* Field description, where we actually just show the Generate Key button.
53+
*
54+
* @since 2019-10-24
55+
* @author George Gecewicz <[email protected]>
56+
*
57+
* @return string
58+
*/
59+
private function get_description() : string {
60+
ob_start();
61+
?>
62+
<div>
63+
<p>
64+
<strong><?php esc_html_e( 'REST Endpoint: Abandoned Carts', 'cc-woo' ); ?></strong><br />
65+
<?php echo esc_html( $this->get_abandoned_carts_endpoint_url() ); ?>
66+
</p>
67+
<p>
68+
<strong><?php esc_html_e( 'REST Endpoint: Get Token', 'cc-woo' ); ?></strong><br />
69+
<?php echo esc_html( $this->get_get_token_endpoint_url() ); ?>
70+
</p>
71+
</div>
72+
<?php
73+
return ob_get_clean();
74+
}
75+
76+
/**
77+
* Get URL to abandoned cart endpoint.
78+
*
79+
* @since 2019-10-28
80+
* @author George Gecewicz <[email protected]>
81+
*
82+
* @return string
83+
*/
84+
private function get_abandoned_carts_endpoint_url() : string {
85+
return sprintf( '%1$s/wp-json/cc-woo/v1/abandoned-carts', get_home_url() );
86+
}
87+
88+
/**
89+
* Get URL to getToken endpoint.
90+
*
91+
* @since 2019-10-28
92+
* @author George Gecewicz <[email protected]>
93+
*
94+
* @return string
95+
*/
96+
private function get_get_token_endpoint_url() : string {
97+
return sprintf( '%1$s/wp-json/cc-woo/v1/get-token', get_home_url() );
98+
}
99+
100+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Field for showing tips on server configuration for REST API to work.
4+
*
5+
* @since 2019-10-28
6+
* @author George Gecewicz <[email protected]>
7+
* @package cc-woo-view-admin-field
8+
*/
9+
10+
namespace WebDevStudios\CCForWoo\View\Admin\Field\AbandonedCarts;
11+
12+
/**
13+
* AbandonedCarts\ServerInfo field class
14+
*
15+
* @since 2019-10-28
16+
* @author George Gecewicz <[email protected]>
17+
* @package cc-woo-view-admin-field
18+
*/
19+
class ServerInfo {
20+
21+
/**
22+
* Server Info field.
23+
*
24+
* @since 2019-10-28
25+
*
26+
* @var string
27+
*/
28+
const OPTION_FIELD_NAME = 'cc_woo_abandoned_carts_server_info';
29+
30+
/**
31+
* Returns the form field configuration.
32+
*
33+
* @since 2019-10-28
34+
* @author George Gecewicz <[email protected]>
35+
*
36+
* @return array.
37+
*/
38+
public function get_form_field() : array {
39+
return [
40+
'title' => esc_html__( 'Server Information', 'cc-woo' ),
41+
'desc' => $this->get_description(),
42+
'type' => 'text',
43+
'id' => self::OPTION_FIELD_NAME,
44+
'default' => '',
45+
'custom_attributes' => [
46+
'readonly' => 'true',
47+
],
48+
];
49+
}
50+
51+
/**
52+
* Field description.
53+
*
54+
* @since 2019-10-28
55+
* @author George Gecewicz <[email protected]>
56+
*
57+
* @return string
58+
*/
59+
private function get_description() : string {
60+
ob_start();
61+
?>
62+
<div>
63+
<p><?php esc_html_e( 'For the Abandoned Carts REST API endpoint to work, you need to make sure your web server allows HTTP authorization headers. If you\'re not familiar with checking or enabling this, please contact your web host for assistance.', 'cc-woo' ); ?></p>
64+
<p><?php esc_html_e( 'If you are comfortable tweaking files on your server, then in most cases one of the following methods will enable that functionality.', 'cc-woo' ); ?></p>
65+
<h3>.htaccess</h3>
66+
<p>
67+
<?php
68+
printf(
69+
/* Translators: Placeholder is a string of HTML referencing file names. */
70+
esc_html__( 'Add the following code to your server\'s %1$s file:', 'cc-woo' ),
71+
'<kbd>.htaccess</kbd>'
72+
);
73+
?>
74+
</p>
75+
<code>
76+
RewriteEngine on
77+
RewriteCond %{HTTP:Authorization} ^(.*)
78+
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
79+
</code>
80+
<h3>apache.conf</h3>
81+
<p>
82+
<?php
83+
printf(
84+
/* Translators: Placeholders are strings of HTML referencing file names. */
85+
esc_html__( 'Add the following code to your server\'s %1$s or %2$s file:', 'cc-woo' ),
86+
'<kbd>apache.conf</kbd>',
87+
'<kbd>apache2.conf</kbd>'
88+
);
89+
?>
90+
</p>
91+
<code>
92+
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
93+
</code>
94+
</div>
95+
<?php
96+
return ob_get_clean();
97+
}
98+
}

src/View/Admin/WooTab.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,25 @@ private function get_abandoned_carts_settings() {
564564
[
565565
'title' => '',
566566
'type' => 'title',
567+
'desc' => esc_html__( 'Settings for the Abandoned Carts functionality, namely its REST API endpoint.', 'cc-woo' ),
567568
],
568569
];
569570

570-
$secret_key_field = new \WebDevStudios\CCForWoo\View\Admin\Field\AbandonedCartsApiSecretKey();
571+
$rest_endpoints_field = new \WebDevStudios\CCForWoo\View\Admin\Field\AbandonedCarts\RestEndpoints();
572+
$secret_key_field = new \WebDevStudios\CCForWoo\View\Admin\Field\AbandonedCarts\ApiSecretKey();
573+
$server_info_field = new \WebDevStudios\CCForWoo\View\Admin\Field\AbandonedCarts\ServerInfo();
574+
575+
$settings[] = array_merge( $settings,
576+
$rest_endpoints_field->get_form_field()
577+
);
578+
579+
$settings[] = array_merge( $settings,
580+
$secret_key_field->get_form_field()
581+
);
571582

572583
$settings[] = array_merge(
573584
$settings,
574-
$secret_key_field->get_form_field()
585+
$server_info_field->get_form_field()
575586
);
576587

577588
return $settings;

0 commit comments

Comments
 (0)