This commit is contained in:
2026-01-11 19:39:55 +01:00
commit c1042c9cde
98 changed files with 9086 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
<?php
namespace RomhackPlaza\Extenders\Admin\Pages;
defined( '\ABSPATH' ) || exit;
abstract class Abstract_Page {
/**
* Page title at the tab.
* @var string
*/
final public string $page_title;
/**
* Short title in WP Admin menu
* @var string
*/
final public string $menu_title;
/**
* ?page slug.
* @var string
*/
final public string $page_slug;
/**
* Capability needed to see and access to this page.
* @var string
*/
final public string $capability;
/**
* ?page parent slug.
* @var string|null
*/
final public string|null $parent_slug;
/**
* Icon URL
* @var string|null
*/
final public string|null $icon;
/**
* Position in WP Admin menu
* @var int|null
*/
public int|null $position;
/**
* Setup page settings.
* @param string $page_title
* @param string $menu_title
* @param string $page_slug
* @param string $capability
* @param string|null $icon
* @param int|null $position
*/
public function __construct (
string $page_title,
string $menu_title,
string $page_slug,
string $capability,
string|null $parent_slug = null,
string|null $icon = null,
int|null $position = null
) {
$this->page_title = $page_title;
$this->menu_title = $menu_title;
$this->page_slug = $page_slug;
$this->capability = $capability;
$this->parent_slug = $parent_slug;
$this->icon = $icon;
$this->position = $position;
$this->prepare_filters();
add_action( 'admin_menu', [ $this, 'add_page' ] );
if( method_exists( $this, 'enqueue_scripts' ) )
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
/**
* Prepare filters "Before content" and "After content" if needed.
* @return void
*/
protected function prepare_filters (): void {
return;
}
/**
* Register page.
* @return void
*/
final public function add_page () {
if( !is_null( $this->parent_slug ) )
add_submenu_page(
$this->parent_slug,
$this->page_title,
$this->menu_title,
$this->capability,
$this->page_slug,
[ $this, 'pre_content' ],
$this->position
);
else
add_menu_page(
$this->page_title,
$this->menu_title,
$this->capability,
$this->page_slug,
[ $this, 'pre_content' ],
$this->icon,
$this->position
);
}
/**
* Prepare content and execute before content and after content hooks.
* @return void
*/
public function pre_content () {
$data = [];
$data = \apply_filters( "RomhackPlaza\\Extenders\\Admin\\Pages\\{$this->page_slug}\\Before_Content", $data );
$this->content( $data );
do_action( "RomhackPlaza\\Extenders\\Admin\\Pages\\{$this->page_slug}\\After_Content", $data );
}
/**
* The content. Can be done with Timber.
* /!\ Verify that Timber is available.
* @param array $data
* @return void
*/
abstract public function content( mixed $data = [] ): void;
}

View File

@@ -0,0 +1,58 @@
<?php
namespace RomhackPlaza\Extenders\Admin\Pages;
use RomhackPlaza\Format;
use RomhackPlaza\Script;
use RomhackPlaza\Script_Type;
use Timber\Timber;
defined( 'ABSPATH' ) || exit;
class Admin_Scripts extends Abstract_Page {
public function __construct() {
parent::__construct(
__( 'Admin Scripts', 'romhackplaza' ),
__( 'Admin Scripts', 'romhackplaza' ),
'romhackplaza-admin-scripts',
'manage_options',
'tools.php'
);
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
public function enqueue_scripts( $hook ) {
if( $hook !== 'tools_page_' . $this->page_slug )
return;
new Script(
Script_Type::JS,
'romhackplaza-admin-scripts',
ROMHACKPLAZA_PLUGIN_URI . '/assets/js/admin/admin-scripts.js',
[],
'20260105',
args: [ 'defer' => true, 'in_footer' => true ]
)
->enqueue()
->add_localize(
'_romhackplaza_admin_scripts',
[
'execute_url' => admin_url( 'admin-ajax.php' ),
'execute_nonce' => wp_create_nonce( Format::format_nonce_name( 'load_admin_script' ) )
]
);
}
public function content( mixed $data = [] ): void {
$context = Timber::context();
$context['scripts'] = \RomhackPlaza\Extenders\Admin_Scripts::get_scripts();
Timber::render( '@plugin/admin/pages/admin-scripts.twig', $context );
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace RomhackPlaza\Extenders\Admin\Pages;
use RomhackPlaza\Extenders\Admin\List_Table\Notifications_List as List_Table;
defined( '\ABSPATH' ) || exit;
class Notifications_List extends Abstract_Page {
public function __construct() {
parent::__construct(
__( 'Notifications', 'romhackplaza' ),
__( 'Notifications', 'romhackplaza' ),
'romhackplaza-notifications-list',
'edit_others_posts', // Only staff can see it
icon: "dashicons-bell",
position: 59
);
}
public function content( mixed $data = [] ): void {
$table = new List_Table();
?>
<style>.wp-list-table .column-id, .wp-list-table .column-auto, .wp-list-table .column-readed { width: 5%; } .wp-list-table .column-sender, .wp-list-table .column-recipient, .wp-list-table .column-type, .wp-list-table .column-date { width: 10%; }</style>
<div class="wrap"><h2><?php _e( 'Notifications', 'romhackplaza' ); ?></h2>
<form method="post">
<?php
$table->prepare_items();
$table->search_box( __( 'Search by ID, sender or recipient', 'romhackplaza' ), 'search_id' );
$table->display();
?>
</form>
</div>
<?php
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace RomhackPlaza\Extenders\Admin\Pages;
use \Timber\Timber;
defined( '\ABSPATH' ) || exit;
class RomhackPlaza_Main extends Abstract_Page {
public function __construct() {
parent::__construct(
__( 'RomhackPlaza - Admin', 'romhackplaza' ),
__( 'RomhackPlaza', 'romhackplaza' ),
'romhackplaza-wp',
'edit_posts', // Every member can see it.
position: 59
);
}
public function content( mixed $data = [] ): void {
$context = Timber::context();
Timber::render( '@plugin/admin/pages/main.twig', $context );
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace RomhackPlaza\Extenders\Admin\Pages;
use RomhackPlaza\Extenders\User_Notifications;
use RomhackPlaza\Format;
use RomhackPlaza\Modal;
use RomhackPlaza\Script;
use RomhackPlaza\Script_Type;
use \Timber\Timber;
defined( 'ABSPATH' ) || exit;
class Send_Notification extends Abstract_Page {
public function __construct() {
parent::__construct(
__( 'Send Notification', 'romhackplaza' ),
__( 'Send Notification', 'romhackplaza' ),
'romhackplaza-send-notification',
'edit_others_posts',
'romhackplaza-notifications-list'
);
add_action( "admin_head-notifications_page_{$this->page_slug}", array( $this, 'load_select2' ) );
add_action( "admin_enqueue_scripts", array( $this, 'enqueue_scripts' ) );
}
public function load_select2() {
// Load select2
?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css">
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<?php
}
public function enqueue_scripts( $hook ) {
if( $hook !== 'notifications_page_' . $this->page_slug )
return;
new Script(
Script_Type::JS,
'romhackplaza-send-notification',
ROMHACKPLAZA_PLUGIN_URI . '/assets/js/admin/send-notification.js',
[ 'jquery' ],
'20260101-4',
args: [ 'defer' => true, 'in_footer' => true ]
)
->enqueue()
->add_localize(
'_romhackplaza_send_notification',
[
'fetch_url' => admin_url( 'admin-ajax.php' ),
'fetch_nonce' => wp_create_nonce( Format::format_nonce_name( 'search_user' ) ),
'submit_nonce' => wp_create_nonce( Format::format_nonce_name( 'submit_notification' ) ),
],
);
}
public function content( mixed $data = [] ): void {
$context = Timber::context();
$context['type_list'] = User_Notifications::NOTIFICATIONS_TYPES;
new Modal( 'notifications', "", "" )->render();
Timber::render( '@plugin/admin/pages/send-notification.twig', $context );
}
}

View File

@@ -0,0 +1,209 @@
<?php
namespace RomhackPlaza\Extenders\Admin\Pages;
use Timber\Timber;
defined( '\ABSPATH' ) || exit;
class Settings extends Abstract_Page {
public function __construct() {
parent::__construct(
__( 'RomhackPlaza - Settings', 'romhackplaza' ),
__( 'Settings', 'romhackplaza' ),
'romhackplaza-config',
'manage_options', // Only admins.
'romhackplaza-wp',
position: 59
);
}
protected function prepare_filters(): void
{
add_action( 'admin_init', [ $this, 'register_settings_sections_fields'], 11 );
}
public function _generic_html_input_text( string $option_name ): void {
global $_romhackplaza;
$value = esc_attr( $_romhackplaza->settings->get( $option_name ) ?? "" );
echo sprintf( '<input type="text" name="%1$s[%2$s]" value="%3$s" />', 'romhackplaza_plugin_options', $option_name, $value );
}
/* ---
START SETTINGS REGISTRATION
--- */
public function register_settings_sections_fields () {
add_settings_section(
'nsfw',
__( 'NSFW', 'romhackplaza' ),
function(){}, // Change it to add style.
'romhackplaza-config'
);
add_settings_field(
'nsfw_tag_id',
__( 'Tag ID', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'nsfw_tag_id' ); },
'romhackplaza-config',
'nsfw',
);
add_settings_section(
'submissions',
__( 'Submissions', 'romhackplaza' ),
function(){ _e("All fields needs to be separated by a semi-colon WITHOUT SPACES !", 'romhackplaza' ); },
'romhackplaza-config'
);
add_settings_field(
'complete_submissions_form_page_ids',
__( 'Complete submissions page IDs', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'complete_submissions_form_page_ids' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'simple_submissions_form_page_ids',
__( 'Simple submissions page IDs (News)', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'simple_submissions_form_page_ids' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'translations_acf_group',
__( 'Translations ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'translations_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'romhacks_acf_group',
__( 'Romhacks ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'romhacks_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'homebrew_acf_group',
__( 'Homebrew ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'homebrew_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'utilities_acf_group',
__( 'Utilities ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'utilities_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'documents_acf_group',
__( 'Documents ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'documents_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'lua_scripts_acf_group',
__( 'LUA Scripts ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'lua_scripts_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'tutorials_acf_group',
__( 'Tutorials ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'tutorials_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'news_acf_group',
__( 'News ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'news_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'reviews_acf_group',
__( 'Reviews ACF Group', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'reviews_acf_group' ); },
'romhackplaza-config',
'submissions',
);
add_settings_field(
'public_edit_disabled_tag_id',
__( 'Public Edit Disabled Tag ID', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'public_edit_disabled_tag_id' ); },
'romhackplaza-config',
'submissions',
);
add_settings_section(
'discord',
__( 'Discord', 'romhackplaza' ),
function(){},
'romhackplaza-config'
);
add_settings_field(
'discord_webhook_romhacks_translations',
__( 'Discord webhook for Romhacks and Translations', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'discord_webhook_romhacks_translations' ); },
'romhackplaza-config',
'discord',
);
add_settings_field(
'discord_webhook_global',
__( 'Discord webhook for others submissions', 'romhackplaza' ),
function(){ $this->_generic_html_input_text( 'discord_webhook_global' ); },
'romhackplaza-config',
'discord',
);
}
/* ---
END SETTINGS REGISTRATION
--- */
public function content( mixed $data = [] ): void {
?>
<div class="wrap">
<h1><?php _e( 'RomhackPlaza - Configuration', 'romhackplaza' ); ?></h1>
<form method="post" action="options.php">
<?php
settings_fields( 'romhackplaza_plugin_options_group' );
do_settings_sections( 'romhackplaza-config' );
submit_button();
?>
</form>
</div>
<?php
}
}