[WIP] Start implementing admin page and settings

This commit is contained in:
Jeremy Dormitzer 2018-11-05 07:42:02 -05:00
parent bb88cdc030
commit 024c4809e2
4 changed files with 75 additions and 0 deletions

33
includes/admin/admin.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace pterotype\admin;
require_once plugin_dir_path( __FILE__ ) . 'icon.php';
function render_admin_html() {
if ( ! \current_user_can( 'manage_options' ) ) {
return;
}
?>
<div class="wrap">
<h1><?= \esc_html(\get_admin_page_title()); ?></h1>
<form action="options.php" method="post">
<?php
\settings_fields('pterotype_settings');
\do_settings_sections('pterotype');
\submit_button('Save Settings');
?>
</form>
</div>
<?php
}
function register_admin_page() {
\add_menu_page(
'Pterotype',
'Pterotype ',
'manage_options',
'pterotype',
'\pterotype\admin\render_admin_html',
\pterotype\admin\icon\icon_uri()
);
}

7
includes/admin/icon.php Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,27 @@
<?php
namespace pterotype\settings;
function register_settings_sections() {
\add_settings_section(
'pterotype_identity',
'Fediverse Identity',
'',
'pterotype'
);
}
function register_settings_fields() {
\add_settings_field(
'pterotype_blog_name',
'Site Name',
function() {
// TODO fill this with the existing option or the site default if not set
?>
<input type="text" name="pterotype_blog_name">
<?php
},
'pterotype',
'pterotype_identity'
);
}
?>

View File

@ -11,6 +11,8 @@ require_once plugin_dir_path( __FILE__ ) . 'client/comments.php';
require_once plugin_dir_path( __FILE__ ) . 'client/identity.php';
require_once plugin_dir_path( __FILE__ ) . 'server/async.php';
require_once plugin_dir_path( __FILE__ ) . 'pgp.php';
require_once plugin_dir_path( __FILE__ ) . 'admin/admin.php';
require_once plugin_dir_path( __FILE__ ) . 'admin/settings.php';
add_action( 'rest_api_init', function() {
\pterotype\api\register_routes();
@ -78,4 +80,10 @@ $theme = \get_option( 'stylesheet' );
add_action( "update_option_theme_mods_$theme", function() {
\pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG );
} );
add_action( 'admin_menu', function() {
\pterotype\admin\register_admin_page();
\pterotype\settings\register_settings_sections();
\pterotype\settings\register_settings_fields();
} );
?>