basic outline for add supports
This commit is contained in:
parent
a1c0ac76a3
commit
83874b5331
3 changed files with 78 additions and 2 deletions
|
@ -19,6 +19,7 @@ class LBRY_Admin
|
|||
add_action('admin_init', array($this, 'page_init'));
|
||||
add_action('admin_init', array($this, 'wallet_balance_warning'));
|
||||
add_action('admin_post_lbry_add_channel', array($this, 'add_channel'));
|
||||
add_action('admin_post_lbry_supports_add', array($this, 'supports_add'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -487,6 +488,43 @@ class LBRY_Admin
|
|||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles adding supports form submission
|
||||
*/
|
||||
public function supports_add()
|
||||
{
|
||||
$redirect_url = admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) );
|
||||
|
||||
// Check that nonce
|
||||
if ( isset( $_POST['_lbrynonce'] ) && wp_verify_nonce( $_POST['_lbrynonce'], 'add_supports_nonce' ) ) {
|
||||
if ( empty( $_POST['lbry_supports_add_claim_id'] ) || empty( $_POST['lbry_supports_add_amount'] ) ) {
|
||||
LBRY()->notice->set_notice( 'error', 'Must supply both channel name and bid amount' );
|
||||
} elseif ( isset( $_POST['lbry_supports_add_claim_id'] ) && isset( $_POST['lbry_supports_add_amount'] ) ) {
|
||||
$claim_id = $_POST['lbry_supports_add_claim_id']; // TODO: sanitize key() only allows for lowercase chars, dashes, and underscores. maybe remove to allow more characters? and use something else for better control?
|
||||
|
||||
$bid = $_POST['lbry_supports_add_amount'];
|
||||
$support_bid = number_format( floatval( $bid ), 3, '.', '' );
|
||||
|
||||
// Try to add the new channel
|
||||
try {
|
||||
// $result = LBRY()->daemon->channel_new( $claim_id, $supports_bid );
|
||||
// Tell the user it takes some time to go through
|
||||
LBRY()->notice->set_notice(
|
||||
'success', 'Successfully added supports for: @' . esc_html( $claim_name ) . '! Please allow a few minutes for the bid to process.', true );
|
||||
|
||||
} catch ( \Exception $e ) {
|
||||
LBRY()->notice->set_notice( 'error', $e->getMessage(), false );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LBRY()->notice->set_notice('error', 'Security check failed' );
|
||||
die( __( 'Security check failed', 'lbrypress' ) );
|
||||
}
|
||||
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks at most once an hour to see if the wallet balance is too low
|
||||
*/
|
||||
|
|
|
@ -19,9 +19,19 @@ $lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
|
|||
<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>
|
||||
<?php
|
||||
if ( $lbry_active_tab == 'supports' ) {
|
||||
$admin_url = admin_url( 'options.php?page=lbrypress&tab=supports' );
|
||||
printf(
|
||||
'<a href="' . esc_url( $admin_url ) . '" class="nav-tab nav-tab-active">' . esc_html__( 'Supports', 'lbrypress') . '</a>',
|
||||
$admin_url,
|
||||
);
|
||||
} ?>
|
||||
</nav>
|
||||
<?php if ( $lbry_active_tab == 'channels' ) {
|
||||
include_once( 'channels-page.php' );
|
||||
} elseif ( $lbry_active_tab == 'supports' ) {
|
||||
include_once( 'supports-add-form.php' );
|
||||
} else {
|
||||
?>
|
||||
<form class="form-table" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post">
|
||||
|
@ -32,7 +42,9 @@ $lbry_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
|
|||
do_settings_sections( LBRY_ADMIN_PAGE );
|
||||
submit_button();
|
||||
} elseif ( $lbry_active_tab == 'channels' ) {
|
||||
include_once( 'channels-page.php' );
|
||||
//include_once( 'channels-page.php' );
|
||||
} elseif ( $lbry_active_tab == 'supports' ) {
|
||||
// include_once( 'supports-add-form.php' );
|
||||
} elseif ( $lbry_active_tab == 'speech' ) {
|
||||
settings_fields( LBRY_SPEECH_SETTINGS );
|
||||
do_settings_sections( 'lbrypress-speech' );
|
||||
|
|
26
templates/supports-add-form.php
Normal file
26
templates/supports-add-form.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* ============================
|
||||
* ADD SUPPORTS FORM ADMIN PAGE
|
||||
* Uses the post-admin action and the $_POST global variable to build our cURL request
|
||||
* @package LBRYPress
|
||||
* ============================
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
|
||||
// Generate a custom nonce
|
||||
$lbrynonce = wp_create_nonce( 'add_supports_nonce' );
|
||||
|
||||
// Build the page ?>
|
||||
<h3><?php _e( 'Add Supports to a Claim', 'lbrypress' ); ?></h3>
|
||||
|
||||
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="lbry_supports_add_form">
|
||||
|
||||
<input type="hidden" name="action" value="lbry_supports_add">
|
||||
<input type="hidden" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
|
||||
|
||||
</form>
|
||||
<?php
|
||||
}
|
Loading…
Reference in a new issue