2024-07-17 16:17:54 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2024-08-15 15:59:58 +02:00
|
|
|
* General settings class.
|
2024-07-17 16:17:54 +02:00
|
|
|
*
|
2024-08-15 15:59:58 +02:00
|
|
|
* This file contains the General class definition, which handles the "General" settings
|
2024-10-22 18:52:57 +02:00
|
|
|
* page for the Activitypub Event Bridge Plugin, providing options for configuring various general settings.
|
2024-07-17 16:17:54 +02:00
|
|
|
*
|
2024-10-02 21:54:03 +02:00
|
|
|
* @package ActivityPub_Event_Bridge
|
2024-07-17 16:17:54 +02:00
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
|
2024-10-02 21:54:03 +02:00
|
|
|
namespace ActivityPub_Event_Bridge\Admin;
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-08-15 15:59:58 +02:00
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-10-02 21:54:03 +02:00
|
|
|
use ActivityPub_Event_Bridge\Plugins\Event_Plugin;
|
|
|
|
use ActivityPub_Event_Bridge\Setup;
|
2024-09-28 13:14:10 +02:00
|
|
|
|
2024-07-17 16:17:54 +02:00
|
|
|
/**
|
2024-10-22 18:52:57 +02:00
|
|
|
* Class responsible for the Activitypub Event Bridge related Settings.
|
2024-07-17 16:17:54 +02:00
|
|
|
*
|
2024-10-22 18:52:57 +02:00
|
|
|
* Class which handles the "General" settings page for the Activitypub Event Bridge Plugin,
|
2024-09-11 07:59:53 +02:00
|
|
|
* providing options for configuring various general settings.
|
2024-07-17 16:17:54 +02:00
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
class Settings_Page {
|
2024-10-02 21:54:03 +02:00
|
|
|
const STATIC = 'ActivityPub_Event_Bridge\Admin\Settings_Page';
|
2024-08-15 15:59:58 +02:00
|
|
|
|
2024-10-02 21:54:03 +02:00
|
|
|
const SETTINGS_SLUG = 'activitypub-event-bridge';
|
2024-07-17 16:17:54 +02:00
|
|
|
/**
|
|
|
|
* Warning if the plugin is Active and the ActivityPub plugin is not.
|
2024-09-11 07:59:53 +02:00
|
|
|
*
|
|
|
|
* @return void
|
2024-07-17 16:17:54 +02:00
|
|
|
*/
|
2024-09-11 07:59:53 +02:00
|
|
|
public static function admin_menu(): void {
|
2024-07-17 16:17:54 +02:00
|
|
|
\add_options_page(
|
2024-10-22 18:52:57 +02:00
|
|
|
'Activitypub Event Bridge',
|
|
|
|
__( 'ActivityPub Event Bridge', 'activitypub-event-bridge' ),
|
2024-07-17 16:17:54 +02:00
|
|
|
'manage_options',
|
2024-08-15 15:59:58 +02:00
|
|
|
self::SETTINGS_SLUG,
|
2024-10-22 18:52:57 +02:00
|
|
|
array( self::STATIC, 'settings_page' ),
|
2024-07-17 16:17:54 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-18 16:24:05 +02:00
|
|
|
/**
|
|
|
|
* Adds Link to the settings page in the plugin page.
|
|
|
|
* It's called via apply_filter('plugin_action_links_' . PLUGIN_NAME).
|
|
|
|
*
|
2024-08-15 15:59:58 +02:00
|
|
|
* @param array $links Already added links.
|
2024-09-11 07:59:53 +02:00
|
|
|
*
|
2024-08-15 15:59:58 +02:00
|
|
|
* @return array Original links but with link to setting page added.
|
2024-07-18 16:24:05 +02:00
|
|
|
*/
|
2024-09-11 07:59:53 +02:00
|
|
|
public static function settings_link( $links ): array {
|
2024-07-18 16:24:05 +02:00
|
|
|
return array_merge(
|
|
|
|
$links,
|
|
|
|
array(
|
2024-08-15 15:59:58 +02:00
|
|
|
'<a href="' . admin_url( 'options-general.php?page=' . self::SETTINGS_SLUG ) . '">Settings</a>',
|
2024-07-18 16:24:05 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-08-27 21:23:33 +02:00
|
|
|
/**
|
|
|
|
* Receive the event categories (terms) used by the event plugin.
|
|
|
|
*
|
2024-09-11 00:38:21 +02:00
|
|
|
* @param Event_Plugin $event_plugin Contains info about a certain event plugin.
|
2024-08-27 21:23:33 +02:00
|
|
|
*
|
|
|
|
* @return array An array of Terms.
|
|
|
|
*/
|
2024-09-11 07:59:53 +02:00
|
|
|
private static function get_event_terms( $event_plugin ): array {
|
2024-09-18 21:26:53 +02:00
|
|
|
$taxonomy = $event_plugin::get_event_category_taxonomy();
|
2024-09-11 00:38:21 +02:00
|
|
|
if ( $taxonomy ) {
|
2024-08-27 21:23:33 +02:00
|
|
|
$event_terms = get_terms(
|
|
|
|
array(
|
2024-09-11 00:38:21 +02:00
|
|
|
'taxonomy' => $taxonomy,
|
2024-08-27 21:23:33 +02:00
|
|
|
'hide_empty' => true,
|
|
|
|
)
|
|
|
|
);
|
2024-09-11 00:38:21 +02:00
|
|
|
return ! is_wp_error( $event_terms ) ? $event_terms : array();
|
2024-07-17 16:17:54 +02:00
|
|
|
} else {
|
2024-08-27 21:23:33 +02:00
|
|
|
return array();
|
2024-07-17 16:17:54 +02:00
|
|
|
}
|
2024-08-27 21:23:33 +02:00
|
|
|
}
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-08-27 21:23:33 +02:00
|
|
|
/**
|
2024-09-11 07:59:53 +02:00
|
|
|
* Preparing the data and loading the template for the settings page.
|
|
|
|
*
|
|
|
|
* @return void
|
2024-08-27 21:23:33 +02:00
|
|
|
*/
|
2024-09-11 07:59:53 +02:00
|
|
|
public static function settings_page(): void {
|
2024-10-19 16:46:50 +02:00
|
|
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
|
|
if ( empty( $_GET['tab'] ) ) {
|
|
|
|
$tab = 'welcome';
|
|
|
|
} else {
|
|
|
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
|
|
$tab = sanitize_key( $_GET['tab'] );
|
|
|
|
}
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-10-19 16:46:50 +02:00
|
|
|
switch ( $tab ) {
|
|
|
|
case 'settings':
|
|
|
|
$plugin_setup = Setup::get_instance();
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-10-19 16:46:50 +02:00
|
|
|
$event_plugins = $plugin_setup->get_active_event_plugins();
|
2024-08-27 21:23:33 +02:00
|
|
|
|
2024-10-19 16:46:50 +02:00
|
|
|
$event_terms = array();
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-10-19 16:46:50 +02:00
|
|
|
foreach ( $event_plugins as $event_plugin ) {
|
|
|
|
$event_terms = array_merge( $event_terms, self::get_event_terms( $event_plugin ) );
|
|
|
|
}
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-10-19 16:46:50 +02:00
|
|
|
$args = array(
|
|
|
|
'slug' => self::SETTINGS_SLUG,
|
|
|
|
'event_terms' => $event_terms,
|
|
|
|
);
|
|
|
|
|
|
|
|
\load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/settings.php', true, $args );
|
|
|
|
break;
|
2024-11-18 16:07:09 +01:00
|
|
|
case 'event-sources':
|
|
|
|
wp_enqueue_script( 'thickbox' );
|
|
|
|
wp_enqueue_style( 'thickbox' );
|
|
|
|
\load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/event-sources.php', true );
|
|
|
|
break;
|
2024-10-19 16:46:50 +02:00
|
|
|
case 'welcome':
|
|
|
|
default:
|
|
|
|
wp_enqueue_script( 'plugin-install' );
|
|
|
|
add_thickbox();
|
|
|
|
wp_enqueue_script( 'updates' );
|
|
|
|
|
|
|
|
\load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/welcome.php', true );
|
|
|
|
break;
|
|
|
|
}
|
2024-07-17 16:17:54 +02:00
|
|
|
}
|
|
|
|
}
|