|
| 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 | +} |
0 commit comments