checkbox_input(
'multisite-configuration-enabled',
__( 'Configure the plugin for a WordPress multisite setup.', 'wp-discourse' ),
__(
"Enabling this setting will create a wpdc_topic_blog database table so that Discourse topics can be associated
with the blog they were posted from. This makes it possible to sync topic data between Discourse and WordPress with a single webhook.
When Multisite Configuration is enabled, the settings on this page will be used to configure their related settings on your network's subsites.",
'wp-discourse'
)
);
$this->next_setting_heading( __( 'Connection Settings', 'wp-discourse' ) );
}
/**
* ***************************
*
* Connection Settings Fields.
*****************************/
/**
* Outputs markup for the url input.
*/
public function url_input() {
$this->input( 'url', __( 'The base URL of your forum, for example http://discourse.example.com', 'wp-discourse' ), 'url' );
}
/**
* Outputs markup for the api-key input.
*/
public function api_key_input() {
$url = $this->get_site_option( 'url' );
if ( $url ) {
$this->input(
'api-key',
__( 'Found on your forum at ', 'wp-discourse' ) . '' . esc_url( $url ) . '/admin/api/keys. ' .
"If you haven't yet created an API key, Click 'New API Key', set User Level to 'Single User', set 'User' to an admin account, select 'Global Key' and click 'Save'. Copy and paste the API key here.",
'wp-discourse'
);
} else {
$this->input(
'api-key',
__(
"Found on your forum at /admin/api/keys.
If you haven't yet created an API key, Click 'New API Key', set User Level to 'Single User', set 'User' to an admin account, select 'Global Key' and click 'Save'. Copy and paste the API key here.",
'wp-discourse'
)
);
}
}
/**
* Outputs markup for the publish-username input.
*/
public function publish_username_input() {
$this->input(
'publish-username',
__(
'The default Discourse username under which WordPress posts will be published on your forum.
The Publishing Username is also used for making API calls to Discourse. It must be set to a Discourse admin username.',
'wp-discourse'
),
null,
null,
null,
'system'
);
}
/**
* Outputs markup for the discourse_connection_logs checkbox.
*/
public function connection_logs() {
$this->checkbox_input(
'connection-logs',
__(
'Enable connection logs.',
'wp-discourse'
),
__( 'Log attempts to check the connection with Discourse.', 'wp-discourse' )
);
$this->next_setting_heading( __( 'Webhook Settings', 'wp-discourse' ) );
}
/**
* ************************
*
* Webhook Settings Fields.
**************************/
/**
* Outputs markup for use-discourse-webhook checkbox.
*/
public function use_discourse_webhook_checkbox() {
$webhook_payload_url = network_site_url( '/wp-json/wp-discourse/v1/update-topic-content' );
$discourse_url = $this->get_site_option( 'url' );
if ( ! empty( $discourse_url ) ) {
$discourse_webhooks_url = '' .
esc_url( $discourse_url ) . '/admin/api/web_hooks';
} else {
$discourse_webhooks_url = 'http://forum.example.com/admin/api/web_hooks';
}
$description = sprintf(
// translators: Discourse webhook description. Placeholder: discourse_webhook_url, webhook_payload_url.
__(
'URL:%2$s
Events: "Post is created", "Post is updated".',
'wp-discourse'
),
$discourse_webhooks_url,
$webhook_payload_url
);
$this->checkbox_input(
'use-discourse-webhook',
__(
'Enable the Sync Comment Data webhook endpoint.',
'wp-discourse'
),
$description
);
}
/**
* Outputs markup for use-discourse-user-webhook checkbox.
*/
public function use_discourse_user_webhook_checkbox() {
$webhook_payload_url = network_site_url( '/wp-json/wp-discourse/v1/update-user' );
$url = $this->get_site_option( 'url' );
if ( ! empty( $url ) ) {
$discourse_webhooks_url = '' .
esc_url( $url ) . '/admin/api/web_hooks';
} else {
$discourse_webhooks_url = 'http://forum.example.com/admin/api/web_hooks';
}
$description = sprintf(
// translators: Discourse webhook description. Placeholder: discourse_webhook_url, webhook_payload_url.
__(
'URL:%2$s
Events: "User is created", "User is Updated".',
'wp-discourse'
),
$discourse_webhooks_url,
$webhook_payload_url
);
$this->checkbox_input( 'use-discourse-user-webhook', __( 'Enable the Update Userdata webhook endpoint.', 'wp-discourse' ), $description );
}
/**
* Outputs markup for the webhook-match-user-email-checkbox.
*/
public function webhook_match_user_email_checkbox() {
$this->checkbox_input(
'webhook-match-user-email',
__(
'Match WordPress users with Discourse users by email.',
'wp-discourse'
),
__(
'Update Userdata will attempt to match users by email if other methods of matching have not worked.',
'wp-discourse'
)
);
}
/**
* Outputs markup for webhook-secret input.
*/
public function webhook_secret_input() {
$description = __(
'String of text at least 12 characters long.',
'wp-discourse'
);
$this->input( 'webhook-secret', $description );
}
/**
* Outputs markup for the verbose-webhook-logs checkbox.
*/
public function verbose_webhook_logs() {
$this->checkbox_input(
'verbose-webhook-logs',
__(
'Enable verbose logs for webhooks.',
'wp-discourse'
),
__( 'Will log successful syncs as well as errors.', 'wp-discourse' )
);
$this->next_setting_heading( __( 'Publishing Settings', 'wp-discourse' ) );
}
/**
* ***********************
*
* Publish Settings Fields.
**************************/
/**
* Outputs markup for hide-discourse-name-field checkbox.
*/
public function hide_discourse_name_field_checkbox() {
$this->checkbox_input(
'hide-discourse-name-field',
__(
'Removes the Discourse Username field
from the WordPress user profile page.',
'wp-discourse'
),
__(
'If you enable this setting and also enable the Update
Userdata webhook, new users created on Discourse will have the their Discourse Username automatically filled in and be
uneditable on WordPress.',
'wp-discourse'
)
);
}
/**
* Outputs markup for the verbose-publication-logs checkbox.
*/
public function verbose_publication_logs() {
$this->checkbox_input(
'verbose-publication-logs',
__(
'Enable verbose logs for publication.',
'wp-discourse'
),
__( 'Will log successful publications as well as errors.', 'wp-discourse' )
);
$this->next_setting_heading( __( 'Comment Settings', 'wp-discourse' ) );
}
/**
* ***********************
*
* Comment Settings Fields.
**************************/
/**
* Outputs markup for the verbose-comment-logs checkbox.
*/
public function verbose_comment_logs() {
$this->checkbox_input(
'verbose-comment-logs',
__(
'Enable verbose logs for comments.',
'wp-discourse'
),
__( 'Will log successful operations as well as errors.', 'wp-discourse' )
);
$this->next_setting_heading( __( 'DiscourseConnect Settings', 'wp-discourse' ) );
}
/**
* *******************
*
* DiscourseConnect Settings Fields.
**********************/
/**
* Outputs markup for the enable-sso checkbox.
*/
public function enable_sso_provider_checkbox() {
$sso_documentation_url = get_admin_url( BLOG_ID_CURRENT_SITE, '/admin.php?page=wp_discourse_options&tab=sso_provider&parent_tab=sso_options' );
$sso_documentation_link = '' . __( 'DiscourseConnect Provider tab', 'wp-discourse' ) . '';
$description = __( 'Use this WordPress instance as the DiscourseConnect provider for your Discourse forum.', 'wp-discourse' );
$details = sprintf(
// translators: enable_sso_provider input. Placeholder: sso_documentation_link.
__( 'For details about using WordPress as the DiscourseConnect Provider, please visit the %1s of the main site in your network.', 'wp-discourse' ),
$sso_documentation_link
);
$this->checkbox_input( 'enable-sso', $description, $details );
}
/**
* Outputs markup for sso-client-enabled checkbox.
*/
public function enable_sso_client_checkbox() {
$sso_documentation_url = get_admin_url( BLOG_ID_CURRENT_SITE, '/admin.php?page=wp_discourse_options&tab=sso_client&parent_tab=sso_options' );
$sso_documentation_link = '' . __( 'DiscourseConnect Client tab', 'wp-discourse' ) . '';
$description = __( 'Allow your WordPress site to function as a DiscourseConnect client to Discourse.', 'wp-discourse' );
$details = sprintf(
// translators: enable_sso_client checkbox. Placeholder: sso_documentation_link.
__( 'For details about using WordPress as a DiscourseConnect Client for Discourse, please visit the %1s of the main site in your network.', 'wp-discourse' ),
$sso_documentation_link
);
$this->checkbox_input( 'sso-client-enabled', $description, $details );
}
/**
* Outputs markup for the sso-secret input.
*/
public function sso_secret_input() {
$url = $this->get_site_option( 'url' );
if ( ! empty( $url ) ) {
$discourse_sso_url = '' .
esc_url( $url ) . '/admin/site_settings/category/all_results?filter=sso';
} else {
$discourse_sso_url = 'http://forum.example.com/admin/site_settings/category/all_results?filter=sso';
}
$description = sprintf(
// translators: SSO secret input. Placeholder: discourse_sso_url.
__(
'The secret key used to verify Discourse DiscourseConnect requests. Set it to a string of text, at least 10
characters long. It needs to match the key set at %1$s.',
'wp-discourse'
),
$discourse_sso_url
);
$this->input( 'sso-secret', $description );
}
/**
* Outputs markup for the verbose-sso-logs checkbox.
*/
public function verbose_sso_logs() {
$this->checkbox_input(
'verbose-sso-logs',
__(
'Enable verbose logs for DiscourseConnect.',
'wp-discourse'
),
__( 'Will log successful operations as well as errors.', 'wp-discourse' )
);
}
/**
* Creates the network options page.
*/
public function network_options_page() {
if ( ! current_user_can( 'manage_network_options' ) ) {
exit;
}
$action_url = add_query_arg(
'action',
'discourse_network_options',
network_admin_url( 'edit.php' )
)
?>
' . __( 'To connect with Discourse, you need to supply the Discourse URL, API Key, and Publishing Username.', 'wp-discourse' ) . '
' . __( 'You are not connected to Discourse. Check that your connection settings are correct. If the issue persists, enable connection logs and check Logs.', 'wp-discourse' ) . '
' . __( 'You are connected to Discourse!', 'wp-discourse' ) . '
' . __( 'To use Discourse webhooks, you need to supply a webhook secret key.', 'wp-discourse' ) . '
' . __( 'The Webhook Secret Key must be at least 12 characters long.', 'wp-discourse' ) . '
' . __( 'To use WordPress as the DiscourseConnect Provider, you need to supply a DiscourseConnect Secret Key.', 'wp-discourse' ) . '
' . __( 'To use WordPress as the DiscourseConnect Client, you need to supply a DiscourseConnect Secret Key.', 'wp-discourse' ) . '
' . __( "You can't enable both the DiscourseConnect Client and DiscourseConnect Provider functionality.", 'wp-discourse' ) . '
' . __( 'The DiscourseConnect Secret Key must be at least 10 characters long.', 'wp-discourse' ) . '