wp-matchplay/matchplay.php

97 lines
2.4 KiB
PHP

<?php
/**
* Plugin Name: Matchplay
* Description: Custom block to show results of a Matchplay tournament
* Requires at least: 6.1
* Requires PHP: 7.0
* Version: 0.1.0
* Author: Ben Harris
* Author URI: https://tcpinball.org/matchplay-plugin/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: tcpinball
*
* @package create-block
*/
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
add_action( 'init', 'create_block_matchplay_block_init' );
function create_block_matchplay_block_init(): void {
register_block_type_from_metadata( __DIR__ . '/build' );
}
add_action( 'admin_init', 'matchplay_register_settings' );
function matchplay_register_settings(): void {
register_setting( 'matchplay', 'matchplay_options' );
add_settings_section(
'matchplay',
'',
'',
'matchplay'
);
add_settings_field(
'matchplay_field_api_key',
'API Key',
'matchplay_field_api_key_callback',
'matchplay',
'matchplay',
['label_for' => 'matchplay_field_api_key']
);
}
function matchplay_field_api_key_callback( $args ): void {
$options = get_option( 'matchplay_options' );
?>
<input
type="text"
name="matchplay_options[matchplay_field_api_key]"
value="<?= $options["matchplay_field_api_key"] ?? "" ?>" />
<?php
}
add_action( 'admin_menu', 'matchplay_options_page' );
function matchplay_options_page(): void {
add_options_page(
'Matchplay Settings',
'Matchplay Settings',
'manage_options',
'matchplay',
'matchplay_settings_page_html'
);
}
function matchplay_settings_page_html(): void {
// check user capabilities
if ( ! current_user_can( 'manage_options' ) ) return;
if ( isset( $_GET['settings-updated'] ) ) {
add_settings_error( 'matchplay_messages', 'matchplay_message', 'Settings saved', 'updated' );
}
settings_errors( 'matchplay_messages' );
?>
<div class="wrap">
<h1><?= esc_html( get_admin_page_title() ) ?></h1>
<form action="options.php" method="post">
<?php
settings_fields( 'matchplay' );
do_settings_sections( 'matchplay' );
submit_button( 'Save' );
?>
</form>
</div>
<?php
}