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
|
|
|
|
* page for the ActivityPub Event Extension Plugin, providing options for configuring various general settings.
|
2024-07-17 16:17:54 +02:00
|
|
|
*
|
|
|
|
* @package Activitypub_Event_Extensions
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Activitypub_Event_Extensions\Admin;
|
|
|
|
|
2024-08-27 19:26:54 +02:00
|
|
|
use Activitypub_Event_Extensions\Setup;
|
|
|
|
|
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-08-27 19:26:54 +02:00
|
|
|
* Class responsible for the ActivityPui Event Extension related Settings.
|
2024-07-17 16:17:54 +02:00
|
|
|
*
|
2024-08-27 19:26:54 +02:00
|
|
|
* Class responsible for the ActivityPui Event Extension related Settings.
|
2024-07-17 16:17:54 +02:00
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
class Settings_Page {
|
2024-08-15 15:59:58 +02:00
|
|
|
const STATIC = 'Activitypub_Event_Extensions\Admin\Settings_Page';
|
|
|
|
|
2024-08-27 19:26:54 +02:00
|
|
|
const SETTINGS_SLUG = 'activitypub-event-extensions';
|
2024-07-17 16:17:54 +02:00
|
|
|
/**
|
|
|
|
* Warning if the plugin is Active and the ActivityPub plugin is not.
|
|
|
|
*/
|
|
|
|
public static function admin_menu() {
|
|
|
|
\add_options_page(
|
|
|
|
'Activitypub Event Extension',
|
2024-08-27 19:26:54 +02:00
|
|
|
__( 'ActivityPub Events', 'activitypub_event_extensions' ),
|
2024-07-17 16:17:54 +02:00
|
|
|
'manage_options',
|
2024-08-15 15:59:58 +02:00
|
|
|
self::SETTINGS_SLUG,
|
|
|
|
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.
|
|
|
|
* @return array Original links but with link to setting page added.
|
2024-07-18 16:24:05 +02:00
|
|
|
*/
|
|
|
|
public static function settings_link( $links ) {
|
|
|
|
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 19:26:54 +02:00
|
|
|
/**
|
|
|
|
* Receive the event categories (terms) used by the event plugin.
|
|
|
|
*
|
|
|
|
* @param array $event_plugin Contains info about a certain event plugin.
|
|
|
|
*
|
|
|
|
* @return array An array of Terms.
|
|
|
|
*/
|
|
|
|
private static function get_event_terms( $event_plugin ) {
|
|
|
|
if ( isset( $event_plugin['taxonomy'] ) ) {
|
|
|
|
$event_terms = get_terms(
|
|
|
|
array(
|
|
|
|
'taxonomy' => $event_plugin['taxonomy'],
|
|
|
|
'hide_empty' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $event_terms;
|
2024-07-17 16:17:54 +02:00
|
|
|
} else {
|
2024-08-27 19:26:54 +02:00
|
|
|
return array();
|
2024-07-17 16:17:54 +02:00
|
|
|
}
|
2024-08-27 19:26:54 +02:00
|
|
|
}
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-08-27 19:26:54 +02:00
|
|
|
/**
|
|
|
|
* Settings page.
|
|
|
|
*/
|
|
|
|
public static function settings_page() {
|
|
|
|
$plugin_setup = Setup::get_instance();
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-08-27 19:26:54 +02:00
|
|
|
$event_plugins = $plugin_setup->get_active_event_plugins();
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-08-27 19:26:54 +02:00
|
|
|
$event_terms = array();
|
|
|
|
|
|
|
|
foreach ( $event_plugins as $event_plugin_name => $events_plugin_info ) {
|
|
|
|
$event_terms[ $event_plugin_name ] = self::get_event_terms( $events_plugin_info );
|
|
|
|
}
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-07-18 17:46:29 +02:00
|
|
|
$args = array(
|
2024-08-27 19:26:54 +02:00
|
|
|
'slug' => self::SETTINGS_SLUG,
|
|
|
|
'event_terms' => $event_terms,
|
2024-07-18 17:46:29 +02:00
|
|
|
);
|
2024-07-17 16:17:54 +02:00
|
|
|
|
2024-08-27 19:26:54 +02:00
|
|
|
\load_template( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . 'templates/settings.php', true, $args );
|
2024-07-17 16:17:54 +02:00
|
|
|
}
|
|
|
|
}
|