Basic tabbed structure (#45)

* gitignore rm vscode

* structure for tabbed admin

* options-page rewrite

* comment out unused include

* define LBRY_SPEECH_SETTINGS

* amend commit to rm style enqueue
This commit is contained in:
Lemuel Smyth 2022-02-12 09:56:59 -06:00 committed by GitHub
parent 4b0e17bcf4
commit e49670732c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 57 deletions

1
.gitignore vendored
View file

@ -4,6 +4,7 @@
!*.* !*.*
.DS_Store .DS_Store
.vscode/*
tmp/* tmp/*
logs/* logs/*

View file

@ -112,6 +112,7 @@ class LBRYPress
$this->define('LBRY_SETTINGS_SECTION_GENERAL', 'lbry_settings_section_general'); $this->define('LBRY_SETTINGS_SECTION_GENERAL', 'lbry_settings_section_general');
$this->define('LBRY_ADMIN_PAGE', 'lbrypress'); $this->define('LBRY_ADMIN_PAGE', 'lbrypress');
$this->define('LBRY_WALLET', 'lbry_wallet'); // the wallet address $this->define('LBRY_WALLET', 'lbry_wallet'); // the wallet address
$this->define('LBRY_SPEECH_SETTINGS', 'lbry_speech_settings');
$this->define('LBRY_SPEECH', 'lbry_speech'); // the spee.ch address $this->define('LBRY_SPEECH', 'lbry_speech'); // the spee.ch address
$this->define('LBRY_SPEECH_CHANNEL', 'lbry_speech_channel'); // The spee.ch channel $this->define('LBRY_SPEECH_CHANNEL', 'lbry_speech_channel'); // The spee.ch channel
$this->define('LBRY_SPEECH_PW', 'lbry_speech_pw'); // The password for the spee.ch channel $this->define('LBRY_SPEECH_PW', 'lbry_speech_pw'); // The password for the spee.ch channel

View file

@ -41,13 +41,17 @@ class LBRY_Admin
public function page_init() public function page_init()
{ {
// Register the LBRY Setting array // Register the LBRY Setting array
register_setting(LBRY_SETTINGS_GROUP, LBRY_SETTINGS, array('sanitize_callback' => array($this, 'sanitize'))); register_setting(
LBRY_SETTINGS_GROUP,
LBRY_SETTINGS,
array( $this, 'sanitize_general_settings' )
);
// Add Required Settings Sections // Add Required Settings Sections
add_settings_section( add_settings_section(
LBRY_SETTINGS_SECTION_GENERAL, // ID LBRY_SETTINGS_SECTION_GENERAL, // ID
'General Settings', // Title 'General Settings', // Title
array( $this, 'general_section_info' ), // Callback array( $this, 'general_section_callback' ), // Callback
LBRY_ADMIN_PAGE // Page LBRY_ADMIN_PAGE // Page
); );
@ -108,14 +112,16 @@ class LBRY_Admin
{ {
// Set class property to be referenced in callbacks // Set class property to be referenced in callbacks
$this->options = get_option(LBRY_SETTINGS); $this->options = get_option(LBRY_SETTINGS);
require_once(LBRY_ABSPATH . 'templates/options_page.php'); require_once( LBRY_ABSPATH . 'templates/options-page.php' );
} }
/** /**
* Sanitizes setting input * Sanitizes setting input
* // COMBAK Potentially sanitize more * // COMBAK Potentially sanitize more
*/ */
public function sanitize($input)
public function sanitize_general_settings( $input )
{ {
if (!empty($input[LBRY_SPEECH_CHANNEL])) { if (!empty($input[LBRY_SPEECH_CHANNEL])) {
$channel = $input[LBRY_SPEECH_CHANNEL]; $channel = $input[LBRY_SPEECH_CHANNEL];
@ -139,7 +145,7 @@ class LBRY_Admin
/** /**
* Section info for the General Section * Section info for the General Section
*/ */
public function general_section_info() public function general_section_callback()
{ {
print 'This is where you can configure how LBRYPress will distribute your content:'; print 'This is where you can configure how LBRYPress will distribute your content:';
} }

View file

@ -0,0 +1,50 @@
<?php
/**
* The Options Page with tabs
* @package LBRYPress
*/
defined('ABSPATH') || die(); // Exit if accessed directly
$LBRY = LBRY();
$wallet_balance = $LBRY->daemon->wallet_balance();
$available_balance = $wallet_balance->result->available;
$lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
$channel_list = $LBRY->daemon->channel_list();
// TODO: Make this page look cleaner
?>
<div class="wrap">
<h1><?php esc_html_e( get_admin_page_title(), 'lbrypress' ); ?></h1>
<h2 title="<?php echo esc_attr( number_format( $total_balance, 3, '.', ',' ) ); ?> Wallet Total Balance"><img src="<?php echo esc_url( plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png' ) ?>" class="icon icon-lbc wallet-icon-lbc" style="height: 1.8em; margin-right: .5em; margin-bottom: -.5em;"><code><?php esc_html_e( number_format( $available_balance, 3, '.', ',' ) ); ?></code> Wallet Available Balance</h2>
<nav class="nav-tab-wrapper">
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=general' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'general' || '' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Settings' ); ?></a>
<a href="<?php echo esc_url( admin_url( 'admin.php?page=lbrypress&tab=channels' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'channels' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Channels' ); ?></a>
<a href="<?php echo esc_url( admin_url( 'options.php?page=lbrypress&tab=speech' ) ); ?>" class="nav-tab <?php echo $lbry_active_tab == 'speech' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Spee.ch' ); ?></a>
</nav>
<?php if ( $lbry_active_tab == 'channels' ) {
// include_once( 'partials/channel-page.php' );
} else {
?>
<form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post">
<?php
}
if ( $lbry_active_tab == 'general' ) {
settings_fields( 'lbry_general_settings' );
do_settings_sections( LBRY_ADMIN_PAGE );
submit_button();
} elseif ( $lbry_active_tab == 'channels' ) {
/// include_once( 'partials/channel-page.php' );
} elseif ( $lbry_active_tab == 'speech' ) {
settings_fields( LBRY_SPEECH_SETTINGS );
do_settings_sections( 'lbrypress-speech' );
submit_button();
} else {
settings_fields( 'lbry_general_settings' );
do_settings_sections( LBRY_ADMIN_PAGE );
submit_button();
}
?>
</form>
</div><!-- wrap -->

View file

@ -1,52 +0,0 @@
<?php
$LBRY = LBRY();
$wallet_balance = $LBRY->daemon->wallet_balance();
$available_balance = $wallet_balance->result->available;
$channel_list = $LBRY->daemon->channel_list();
// TODO: Make this page look cleaner
?>
<div class="wrap">
<h1><?= esc_html(get_admin_page_title()); ?></h1>
<h2>Your wallet amount:</h2>
<img src="<?php echo esc_url( plugin_dir_url(LBRY_PLUGIN_FILE) . 'admin/images/lbc.png') ?>" class="icon icon-lbc wallet-icon-lbc" style="height: 1.8em; margin-right: .5em; margin-bottom: -.5em;"><code><?= number_format($available_balance, 2, '.', ','); ?></code>
<form action="options.php" method="post">
<?php
settings_fields(LBRY_SETTINGS_GROUP);
do_settings_sections(LBRY_ADMIN_PAGE);
submit_button('Save Settings');
?>
</form>
<h2>Your Publishable Channels</h2>
<?php if ($channel_list): ?>
<ul class="lbry-channel-list">
<?php foreach ($channel_list as $channel): ?>
<li><?= $channel->name ?></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>Looks like you haven't added any channels yet, feel free to do so below:</p>
<?php endif; ?>
<h2>Add a new channel to publish to:</h2>
<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
<?php wp_nonce_field('lbry_add_channel', '_lbrynonce'); ?>
<input type="hidden" name="action" value="lbry_add_channel">
<table class="form-table">
<tbody>
<tr>
<th scope="row">New Channel Name</th>
<td>
<span>@</span>
<input type="text" name="new_channel" value="" placeholder="your-new-channel" required>
</td>
</tr>
<tr>
<th scope="row">Amount of LBC to Bid</th>
<td>
<input type="number" step="0.1" min="0.1" name="bid_amount" value="10" required>
</td>
</tr>
</tbody>
</table>
<?php submit_button('Add New Channel'); ?>
</form>
</div>