PluginProbe
WP Discourse / trunk
WP Discourse vtrunk
2.6.4 2.6.3 1.2.1 1.2.2 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.85 1.4.0 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 All 150 releases
wp-discourse / admin / connection-settings.php

connection-settings.php in WP Discourse trunk, at admin/connection-settings.php

263 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Connection Settings
4 *
5 * @package WPDiscourse
6 */
7
8 namespace WPDiscourse\Admin;
9
10 use WPDiscourse\Shared\PluginUtilities;
11
12 /**
13 * Class ConnectionSettings
14 */
15 class ConnectionSettings {
16 use PluginUtilities;
17
18 /**
19 * An instance of the FormHelper class.
20 *
21 * @access protected
22 * @var \WPDiscourse\Admin\FormHelper
23 */
24 protected $form_helper;
25
26 /**
27 * Gives access to the plugin options.
28 *
29 * @access protected
30 * @var mixed|void
31 */
32 protected $options;
33
34 /**
35 * Whether or not to display the connection_options fields.
36 *
37 * @access protected
38 * @var bool
39 */
40 protected $display_connection_options;
41
42 /**
43 * ConnectionSettings constructor.
44 *
45 * @param \WPDiscourse\Admin\FormHelper $form_helper An instance of the FormHelper class.
46 */
47 public function __construct( $form_helper ) {
48 $this->form_helper = $form_helper;
49
50 add_action( 'admin_init', array( $this, 'register_connection_settings' ) );
51 }
52
53 /**
54 * Add settings section, settings fields, and register the setting.
55 */
56 public function register_connection_settings() {
57 $this->options = $this->get_options();
58 $this->display_connection_options = ! is_multisite() || empty( $this->options['multisite-configuration-enabled'] );
59
60 add_settings_section(
61 'discourse_connection_settings_section',
62 __( 'Connecting With Discourse', 'wp-discourse' ),
63 array(
64 $this,
65 'connection_settings_tab_details',
66 ),
67 'discourse_connect'
68 );
69
70 if ( $this->display_connection_options ) {
71 add_settings_field(
72 'discourse_url',
73 __( 'Discourse URL', 'wp-discourse' ),
74 array(
75 $this,
76 'url_input',
77 ),
78 'discourse_connect',
79 'discourse_connection_settings_section'
80 );
81
82 add_settings_field(
83 'discourse_api_key',
84 __( 'API Key', 'wp-discourse' ),
85 array(
86 $this,
87 'api_key_input',
88 ),
89 'discourse_connect',
90 'discourse_connection_settings_section'
91 );
92
93 add_settings_field(
94 'discourse_publish_username',
95 __( 'Publishing Username', 'wp-discourse' ),
96 array(
97 $this,
98 'publish_username_input',
99 ),
100 'discourse_connect',
101 'discourse_connection_settings_section'
102 );
103
104 add_settings_field(
105 'discourse_connection_logs',
106 __( 'Connection Logs', 'wp-discourse' ),
107 array(
108 $this,
109 'connection_logs',
110 ),
111 'discourse_connect',
112 'discourse_connection_settings_section'
113 );
114 }// End if().
115
116 register_setting(
117 'discourse_connect',
118 'discourse_connect',
119 array(
120 $this->form_helper,
121 'validate_options',
122 )
123 );
124 }
125
126 /**
127 * Outputs markup for the Discourse-url input.
128 */
129 public function url_input() {
130 $this->form_helper->input( 'url', 'discourse_connect', __( 'The base URL of your forum, for example http://discourse.example.com', 'wp-discourse' ), 'url' );
131 }
132
133 /**
134 * Outputs markup for the api-key input.
135 */
136 public function api_key_input() {
137 $discourse_options = $this->options;
138 if ( ! empty( $discourse_options['url'] ) ) {
139 $this->form_helper->input(
140 'api-key',
141 'discourse_connect',
142 __( 'Found on your forum at ', 'wp-discourse' ) . '<a href="' . esc_url( $discourse_options['url'] ) .
143 '/admin/api/keys" target="_blank" rel="norefferer noopener">' . esc_url( $discourse_options['url'] ) . '/admin/api/keys</a>. ' .
144 "If you haven't yet created an API key, Click 'New API Key', set User Level to 'All Users', set 'User' to an admin account, select 'Global Key' and click 'Save'. Copy and paste the API key here.",
145 'wp-discourse'
146 );
147 } else {
148 $this->form_helper->input(
149 'api-key',
150 'discourse_connect',
151 __(
152 "Found on your forum at /admin/api/keys.
153 If you haven't yet created an API key, Click 'New API Key', set User Level to 'All Users', set 'User' to an admin account, select 'Global Key' and click 'Save'. Copy and paste the API key here.",
154 'wp-discourse'
155 )
156 );
157 }
158 }
159
160 /**
161 * Outputs markup for the publish-username input.
162 */
163 public function publish_username_input() {
164 $this->form_helper->input(
165 'publish-username',
166 'discourse_connect',
167 __(
168 'The default Discourse username under which WordPress posts will be published on your forum.
169 The Publishing Username is also used for making API calls to Discourse. It must be set to a Discourse admin username.',
170 'wp-discourse'
171 )
172 );
173 }
174
175 /**
176 * Outputs markup for the discourse_verbose_connection_logs checkbox.
177 */
178 public function connection_logs() {
179 $this->form_helper->checkbox_input(
180 'connection-logs',
181 'discourse_connect',
182 __(
183 'Enable connection logs.',
184 'wp-discourse'
185 ),
186 __( 'Log attempts to check the connection with Discourse.', 'wp-discourse' ) . ' View logs in the <a href="?page=wp_discourse_options&tab=log_viewer">' . __( 'Log Viewer', 'wp-discourse' ) . '</a>.'
187 );
188 }
189
190 /**
191 * Details for the connection_options tab.
192 */
193 public function connection_settings_tab_details() {
194 $self_install_url = 'https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md';
195 $community_install_url = 'https://www.literatecomputing.com/product/discourse-install/';
196 $discourse_org_install_url = 'https://discourse.org/pricing/';
197 $setup_howto_url = 'https://meta.discourse.org/t/wp-discourse-plugin-installation-and-setup/50752';
198 $discourse_meta_url = 'https://meta.discourse.org/';
199 ?>
200 <p class="wpdc-options-documentation">
201 <em>
202 <?php
203 esc_html_e(
204 "The WP Discourse plugin is used to connect an existing Discourse forum with your WordPress site.
205 If you don't already have a Discourse forum, here are some options for setting one up:",
206 'wp-discourse'
207 );
208 ?>
209 </em>
210 </p>
211 <ul class="wpdc-documentation-list">
212 <em>
213 <li>
214 <a href="<?php echo esc_url( $self_install_url ); ?>" target="_blank" rel="noreferrer noopener">install it yourself for
215 free</a>
216 </li>
217 <li>
218 <a href="<?php echo esc_url( $community_install_url ); ?>" target="_blank" rel="noreferrer noopener">self-supported community
219 installation</a>
220 </li>
221 <li>
222 <a href="<?php echo esc_url( $discourse_org_install_url ); ?>" target="_blank" rel="noreferrer noopener">discourse.org
223 hosting</a>
224 </li>
225 </em>
226 </ul>
227 <p class="wpdc-options-documentation">
228 <em>
229 <?php esc_html_e( 'For detailed instructions on setting up the plugin, please see the ', 'wp-discourse' ); ?>
230 <a href="<?php echo esc_url( $setup_howto_url ); ?>"
231 target="_blank" rel="noreferrer noopener"><?php esc_html_e( 'WP Discourse plugin installation and setup', 'wp-discourse' ); ?></a>
232 <?php esc_html_e( 'topic on the ', 'wp-discourse' ); ?>
233 <a href="<?php echo esc_url( $discourse_meta_url ); ?>" target="_blank" rel="noreferrer noopener">Discourse Meta</a>
234 <?php esc_html_e( 'forum.', 'wp-discourse' ); ?>
235 </em>
236 </p>
237 <?php if ( $this->display_connection_options ) : ?>
238 <p class="wpdc-options-documentation">
239 <em>
240 <strong><?php esc_html_e( 'The following settings are used to establish a connection between your site and your forum:', 'wp-discourse' ); ?></strong>
241 </em>
242 </p>
243 <?php else : ?>
244 <p class="wpdc-options-documentation wpdc-subsite-documentation">
245 <em>
246 <strong>
247 <?php
248 esc_html_e(
249 "You are using the WP Discourse plugin in a subsite of a multisite installation.
250 The plugin's API credentials are being managed through the installation's main site. If you have difficulty
251 connecting to the Discourse forum. Please contact the network administrator.",
252 'wp-discourse'
253 );
254 ?>
255 </strong>
256 </em>
257 </p>
258 <?php endif; ?>
259
260 <?php
261 }
262 }
263