mirror of
https://github.com/discourse/wp-discourse.git
synced 2025-08-17 18:11:19 +08:00
* Add base log classes * Return maxFiles to normal level * Use protected class variables for folder names in folder-manager * Add unit tests for logger classes && various logger improvements * Add log viewer * Fix initialization sequence in LogViewer * Add wp-discourse settings to plugin meta * Remove metafile comments * Add partial coverage and annotate LogViewer * Add code coverage reporting and a tests readme * Tests readme xdebug section formatting * Add logging and tests to discourse-publish This abstracts remote post components to make it possible to add consistent error and log handling. Also adds basic tests coverage for discourse-publish. * Add successful publication test * Add working tests for publish_after_create and publish_after_update * Always remove test files and database upon install * Cleanup copy and assertions for existing tests * Final cleanup && verbose setting * Improve structure of publish test * Final tests, linting, security and cleanup * PHP 7.0 Compatibility * PHP 5.6 Compatibility * JSHint fixes * Update file-handler.php * Update log viewer title * Use older monolog and update file_handler function signatures * Add nonce to other view_log action * Namespace production composer packages and define build process * Update COMPOSER.md * Update FORMATTING.md * Log viewer style, naming and log-refresh improvements * Filter out all return type declarations during scoping * JsHint: Don't use default params * Update COMPOSER.md * Copy fix * Update scoper patchers notes * Address syntax issues - Remove >php7 syntax from non-required files - Add phpcs pattern exclusions to phpcs.xml - update formatting docs * discourse-publish: address all phpcs notices and add more tests Note: also added dealerdirect/phpcodesniffer-composer-installer to handle local requiring of codesniffer * Handle all phpcs warnings in lib/logs * Add todo: review phpcs exclusions to discourse-publish * Monolog cleanup - Remove unused monolog handlers, processors and formatters - Add vendor_namespaced to excluded phpcs patterns * Update CI versions to those used in composer * Switch to using composer directly in CI actions * Composer is packaged in shivammathur/setup-php * Setup PHPCS via shivammathur/setup-php * Incorrect tools key * Use vendor/bin version of phpcs * Install composer dependencies via ramsey/composer-install * Update composer.lock to composer 2 and --ignore-platform-reqs * Install lowest version of dependencies * Move dependency-versions key * Move composer-options key * Exclude vendor directory from syntax checker * Add vendor to jshintignore * Update phpcs.xml to properly exclude js css and config files * Address phpcs issues in log-viewer * Fix remaining whitespace issues created in this PR * Remove out of date sniffs and exclude specific code where necessary * Final cleanup * Properly escape html in log viewer * Remove unnecessary verbiage from documentation * Bump plugin's version to 2.2.4 Co-authored-by: Angus McLeod <angus@mcleod.org.au>
188 lines
8.1 KiB
PHP
188 lines
8.1 KiB
PHP
<?php
|
|
/**
|
|
* Options Page.
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
namespace WPDiscourse\Admin;
|
|
|
|
/**
|
|
* Class OptionsPage
|
|
*/
|
|
class OptionsPage {
|
|
|
|
/**
|
|
* Used for containing a single instance of the OptionsPage class throughout a request.
|
|
*
|
|
* @access protected
|
|
* @var null|OptionsPage
|
|
*/
|
|
protected static $instance;
|
|
|
|
/**
|
|
* Gets an instance of the OptionsPage class.
|
|
*
|
|
* @return OptionsPage
|
|
*/
|
|
public static function get_instance() {
|
|
if ( null === self::$instance ) {
|
|
self::$instance = new self();
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* OptionsPage constructor.
|
|
*/
|
|
protected function __construct() {
|
|
// Empty constructor.
|
|
}
|
|
|
|
/**
|
|
* Displays the options options page and options page tabs.
|
|
*
|
|
* @param string $active_tab The current tab, used if `$_GET['tab']` is not set.
|
|
* @param null|string $parent_tab An optional parent tab, useful for plugins that add a second-level menu.
|
|
* @param bool $form Whether or not to display the form on the page.
|
|
*/
|
|
public function display( $active_tab = '', $parent_tab = null, $form = true ) {
|
|
?>
|
|
<div class="wrap discourse-options-page-wrap">
|
|
<h2>
|
|
<img
|
|
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBD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gxym0kIhahYLCgPbDabGt/ayRPabJvf6cJRLS4bBI2mSCgk1SKTRkaCsdOoiDVy+QFwUYZr443Wvat6JImcXC6f+tGinfYT4rOdtsnqKSkMfWS0MIOGtEZ8g7jebMO/AgwANr2XXAf8LaoAAAAASUVORK5CYII="
|
|
alt="Discourse logo" class="discourse-logo">
|
|
<?php esc_html_e( 'WP Discourse', 'wp-discourse' ); ?>
|
|
</h2>
|
|
<?php settings_errors(); ?>
|
|
|
|
<?php
|
|
if ( isset( $_GET['tab'] ) ) { // Input var okay.
|
|
$tab = sanitize_key( wp_unslash( $_GET['tab'] ) ); // Input var okay.
|
|
} elseif ( $active_tab ) {
|
|
$tab = $active_tab;
|
|
} else {
|
|
$tab = 'connection_options';
|
|
}
|
|
|
|
if ( isset( $_GET['parent_tab'] ) ) { // Input var okay.
|
|
$parent = sanitize_key( wp_unslash( $_GET['parent_tab'] ) ); // Input var okay.
|
|
} else {
|
|
$parent = $parent_tab;
|
|
}
|
|
?>
|
|
|
|
<h2 class="nav-tab-wrapper nav-tab-first-level">
|
|
<a href="?page=wp_discourse_options&tab=connection_options"
|
|
class="nav-tab <?php echo 'connection_options' === $tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Connection', 'wp-discourse' ); ?>
|
|
</a>
|
|
<a href="?page=wp_discourse_options&tab=publishing_options"
|
|
class="nav-tab <?php echo 'publishing_options' === $tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Publishing', 'wp-discourse' ); ?>
|
|
</a>
|
|
<a href="?page=wp_discourse_options&tab=commenting_options"
|
|
class="nav-tab <?php echo 'commenting_options' === $tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Commenting', 'wp-discourse' ); ?>
|
|
</a>
|
|
<a href="?page=wp_discourse_options&tab=text_content_options"
|
|
class="nav-tab <?php echo 'text_content_options' === $tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Text Content', 'wp-discourse' ); ?>
|
|
</a>
|
|
<a href="?page=wp_discourse_options&tab=webhook_options"
|
|
class="nav-tab <?php echo 'webhook_options' === $tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Webhooks', 'wp-discourse' ); ?>
|
|
</a>
|
|
|
|
<?php $sso_active = 'sso_options' === $tab || 'sso_options' === $parent; ?>
|
|
|
|
<a href="?page=wp_discourse_options&tab=sso_options"
|
|
class="nav-tab <?php echo $sso_active ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'SSO', 'wp-discourse' ); ?>
|
|
</a>
|
|
|
|
<a href="?page=wp_discourse_options&tab=log_viewer"
|
|
class="nav-tab <?php echo 'log_viewer' === $tab ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Logs', 'wp-discourse' ); ?>
|
|
</a>
|
|
|
|
<?php
|
|
/**
|
|
* Can be used for adding tabs.
|
|
*
|
|
* @param string $tab The current tab.
|
|
* @param null|string The parent tab.
|
|
*/
|
|
do_action( 'wpdc_options_page_append_settings_tabs', $tab, $parent );
|
|
?>
|
|
|
|
</h2>
|
|
|
|
<?php
|
|
/**
|
|
* Called after the settings tabs.
|
|
*
|
|
* @param string $tab The current tab.
|
|
* @param null|string $parent The parent tab.
|
|
*/
|
|
do_action( 'wpdc_options_page_after_settings_tabs', $tab, $parent );
|
|
?>
|
|
|
|
<?php if ( $form ) : ?>
|
|
|
|
<form action="options.php" method="post" class="wp-discourse-options-form">
|
|
<?php
|
|
if ( 'connection_options' === $tab ) {
|
|
settings_fields( 'discourse_connect' );
|
|
do_settings_sections( 'discourse_connect' );
|
|
}
|
|
|
|
if ( 'publishing_options' === $tab ) {
|
|
settings_fields( 'discourse_publish' );
|
|
do_settings_sections( 'discourse_publish' );
|
|
}
|
|
|
|
if ( 'commenting_options' === $tab ) {
|
|
settings_fields( 'discourse_comment' );
|
|
do_settings_sections( 'discourse_comment' );
|
|
}
|
|
|
|
if ( 'text_content_options' === $tab ) {
|
|
settings_fields( 'discourse_configurable_text' );
|
|
do_settings_sections( 'discourse_configurable_text' );
|
|
}
|
|
|
|
if ( 'webhook_options' === $tab ) {
|
|
settings_fields( 'discourse_webhook' );
|
|
do_settings_sections( 'discourse_webhook' );
|
|
}
|
|
|
|
if ( 'log_viewer' === $tab ) {
|
|
settings_fields( 'discourse_logs' );
|
|
do_settings_sections( 'discourse_logs' );
|
|
}
|
|
|
|
do_action( 'wpdc_options_page_after_tab_switch', $tab );
|
|
|
|
$multisite_configuration = get_site_option( 'wpdc_multisite_configuration' );
|
|
$hide_submit_button = ( is_multisite() &&
|
|
( 'connection_options' === $tab || 'webhook_options' === $tab || 'sso_options' === $tab || 'sso_common' === $tab ) &&
|
|
! empty( $multisite_configuration ) ) ||
|
|
'log_viewer' === $tab;
|
|
|
|
if ( ! $hide_submit_button ) {
|
|
submit_button( 'Save Options', 'primary', 'discourse_save_options', false );
|
|
}
|
|
?>
|
|
</form>
|
|
<?php
|
|
/**
|
|
* Called after the setting-page form.
|
|
*
|
|
* @param string $tab The active tab.
|
|
*
|
|
* @hooked ConfigurableTextSettings::reset_options_form - 10
|
|
*/
|
|
do_action( 'wpdc_options_page_after_form', $tab );
|
|
?>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|