diff --git a/classes/LBRYPress.php b/classes/LBRYPress.php
index 21706fd..89369d0 100644
--- a/classes/LBRYPress.php
+++ b/classes/LBRYPress.php
@@ -120,8 +120,8 @@ class LBRYPress
$this->define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish
$this->define('LBRY_WILL_PUBLISH', '_lbry_will_publish'); // The meta key for if to publish to LBRY Network or not
$this->define('LBRY_POST_CHANNEL', '_lbry_channel'); // The meta key for which channel to publish
- $this->define('LBRY_POST_PUB_CHANNEL', '_lbry_post_pub_channel'); // The meta key for which channel to publish
- $this->define('LBRY_POST_POST_LICENSE', '_lbry_post_pub_license'); // The meta key for which license to publish on
+ $this->define('LBRY_POST_PUB_CHANNEL', '_lbry_post_pub_channel'); // The meta key for which channel to publish on
+ $this->define('LBRY_POST_PUB_LICENSE', '_lbry_post_pub_license'); // The meta key for which license to publish on
$this->define('LBRY_CLAIM_ID', '_lbry_claim_id'); // The Claim ID for the post as it was published on LBRY
$this->define('LBRY_CANONICAL_URL', '_lbry_canonical_url'); // The canonical url for the published lbry post
$this->define('LBRY_SPEECH_ASSET_URL', 'speech_asset_url'); // The meta key for an asset's speech url
diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php
index 7cb8b03..0dc2565 100644
--- a/classes/LBRY_Admin.php
+++ b/classes/LBRY_Admin.php
@@ -37,7 +37,7 @@ class LBRY_Admin
// Admin stylesheet enqueue
function load_admin_stylesheet( $hook ) {
- if ( ( $_GET['page'] == 'lbrypress' ) ) {
+ if ( ( $hook == 'post.php' ) || ( $hook == 'post-new.php' ) || ( $_GET['page'] == 'lbrypress' ) ) {
wp_enqueue_style(
'lbry-admin',
plugins_url( '/admin/css/lbry-admin.css', LBRY_PLUGIN_FILE ),
@@ -90,6 +90,14 @@ class LBRY_Admin
LBRY_SETTINGS_SECTION_GENERAL
);
+ add_settings_field(
+ 'lbry_default_publish_setting',
+ 'Always Publish to LBRY',
+ array( $this, 'lbry_always_pub_callback' ),
+ LBRY_ADMIN_PAGE,
+ LBRY_SETTINGS_SECTION_GENERAL
+ );
+
add_settings_field(
'default_lbry_channel',
'Default Publish Channel',
@@ -97,6 +105,7 @@ class LBRY_Admin
LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL
);
+
add_settings_field(
LBRY_LICENSE,
'LBRY Publishing License',
@@ -108,7 +117,7 @@ class LBRY_Admin
add_settings_field(
LBRY_LBC_PUBLISH,
'LBC Per Publish',
- array( $this, 'lbc_publish_callback' ),
+ array( $this, 'lbc_per_publish_callback' ),
LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL
);
@@ -170,22 +179,24 @@ class LBRY_Admin
public function sanitize_general_settings( $input )
{
- if (!empty($input[LBRY_SPEECH_CHANNEL])) {
- $channel = $input[LBRY_SPEECH_CHANNEL];
- $channel = str_replace('@', '', $channel);
- $input[LBRY_SPEECH_CHANNEL] = $channel;
- }
+ $new_input = get_option( LBRY_SETTINGS ); // get saved data
- if (!empty($input[LBRY_SPEECH_PW])) {
- $encrypted = $this->encrypt($input['lbry_speech_pw']);
- $input[LBRY_SPEECH_PW] = $encrypted;
- } else {
- // If we have a password and its empty, keep orginal password
- if (!empty(get_option(LBRY_SETTINGS)[LBRY_SPEECH_PW])) {
- $input[LBRY_SPEECH_PW] = get_option(LBRY_SETTINGS)[LBRY_SPEECH_PW];
- }
+ if ( isset( $input[LBRY_WALLET] ) ) {
+ $new_input[LBRY_WALLET] = sanitize_text_field( $input[LBRY_WALLET] );
}
- return $input;
+ $new_input['lbry_default_publish_setting'] = $input['lbry_default_publish_setting'];
+
+ if ( isset( $input['default_lbry_channel'] ) ) {
+ $new_input['default_lbry_channel'] = sanitize_text_field( $input['default_lbry_channel'] );
+ }
+ $license_array = LBRY()->licenses;
+ if ( isset( $input[LBRY_LICENSE] ) && ( in_array( $input[LBRY_LICENSE], $license_array ) ) ) {
+ $new_input[LBRY_LICENSE] = sanitize_text_field( $input[LBRY_LICENSE] );
+ }
+ if ( isset( $input[LBRY_LBC_PUBLISH] ) ) {
+ $new_input[LBRY_LBC_PUBLISH] = number_format( floatval( $input[LBRY_LBC_PUBLISH] ), 3, '.', '' );
+ }
+ return $new_input;
}
public function sanitize_speech_settings( $input )
@@ -219,13 +230,6 @@ class LBRY_Admin
{
print 'This is where you can configure how LBRYPress will distribute your content:';
}
- /**
- * Section info for the Speech Channel Section
- */
- public function speech_section_callback()
- {
- print 'If you have a Spee.ch account, you can enter your account details here, if you don\'t already have a Spee.ch account, no need to enter anything here.';
- }
/**
* Section info for the Available Channel(s) Section
@@ -245,6 +249,15 @@ class LBRY_Admin
Set Default to always Publish to LBRY, this can be adjusted when publishing a New Post.
',
+ 'lbry_default_publish_setting',
+ LBRY_SETTINGS,
+
+ );
+ }
+
/**
* Prints select to choose a default to publish to channel
*/
@@ -323,16 +354,17 @@ class LBRY_Admin
/**
* Prints LBC per publish input
*/
- public function lbc_publish_callback()
+ public function lbc_per_publish_callback()
{
printf(
- '',
+ '
Current minimum bid 0.001
',
LBRY_LBC_PUBLISH,
LBRY_SETTINGS,
- $this->options[LBRY_LBC_PUBLISH]
+ $this->options[LBRY_LBC_PUBLISH],
+ plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbc.png'
);
- }
+ }
/**
* Channels Page
diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php
index 4b4de01..54564a2 100644
--- a/classes/LBRY_Network.php
+++ b/classes/LBRY_Network.php
@@ -34,21 +34,21 @@ class LBRY_Network
private function post_meta_setup()
{
// Add the meta boxes
- add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
+ add_action( 'add_meta_boxes', array( $this, 'lbry_meta_boxes' ) );
// Save the post meta on 'save_post' hook
- add_action('wp_insert_post', array($this, 'save_post_meta'), 11, 2);
+ add_action( 'wp_insert_post', array( $this, 'save_post_meta' ), 11, 2 );
}
/**
* Adds the meta boxes to the post editing backend
*/
- public function add_meta_boxes()
+ public function lbry_meta_boxes( $post )
{
// IDEA: Support post types based on user selection
add_meta_box(
'lbry-network-publishing', // Unique ID
- 'LBRY Network', // Title
+ __('LBRY Network', 'lbrypress'), // Title
array($this, 'meta_box_html'), // Callback function
'post', // Screen Options (or post type)
'side', // Context
@@ -64,20 +64,26 @@ class LBRY_Network
*/
public function save_post_meta( $post_id, $post )
{
- if ($post->post_type != 'post') {
- return;
+ if ( $post->post_type != 'post' ) {
+ return $post_id;
+ }
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
+ return $post_id;
}
-
// Verify the nonce before proceeding.
- if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) {
+ if ( ! isset( $_POST['_lbrynonce'] ) || ! wp_verify_nonce( $_POST['_lbrynonce'], 'lbry_publish_post_nonce' ) ) {
+ //LBRY()->notice->set_notice('error', 'Security check failed' );
return $post_id;
}
-
- // Check if the current user has permission to edit the post.
- $post_type = get_post_type_object($post->post_type);
- if (!current_user_can($post_type->cap->edit_post, $post_id)) {
+ $post_type = get_post_type_object( $post->post_type );
+ if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
return $post_id;
}
+ if ( ( $_POST[LBRY_WILL_PUBLISH] ) && $_POST[LBRY_WILL_PUBLISH] != get_post_meta( $post_id, LBRY_WILL_PUBLISH, true ) ) {
+ update_post_meta( $post_id, LBRY_WILL_PUBLISH, $_POST[LBRY_WILL_PUBLISH] );
+ } elseif ( ! isset( $_POST[LBRY_WILL_PUBLISH] ) ) {
+ update_post_meta( $post_id, LBRY_WILL_PUBLISH, 0 );
+ }
$channel = $_POST[LBRY_POST_PUB_CHANNEL];
$cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) );
@@ -86,18 +92,20 @@ class LBRY_Network
$will_publish = $_POST[LBRY_WILL_PUBLISH];
// Update meta acordingly
- if (!$will_publish) {
- update_post_meta($post_id, LBRY_WILL_PUBLISH, 'false');
- } else {
- update_post_meta($post_id, LBRY_WILL_PUBLISH, 'true');
+
+ if ( $channel !== $cur_channel ) {
+ update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $channel );
+ delete_post_meta( $post_id, '_lbry_channel'); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion
+ } elseif ( $channel === $cur_channel && ( $cur_channel === get_post_meta( $post_id, '_lbry_channel', true ) ) ) {
+ update_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, $channel );
+ delete_post_meta( $post_id, '_lbry_channel'); // remove the _lbry_channel if already set from the post and replaces with _lbry_post_pub_channel to avoid confusion
}
- if ($new_channel !== $cur_channel) {
- update_post_meta($post_id, LBRY_POST_CHANNEL, $new_channel);
+ if ( $license !== $cur_license ) {
+ update_post_meta( $post_id, LBRY_POST_PUB_LICENSE, $license );
}
-
- if ($will_publish && $post->post_status == 'publish') {
+ if ( ( $will_publish ) && ( $will_publish == 1 ) && $post->post_status == 'publish') {
// Publish the post on the LBRY Network
- $this->publisher->publish($post, get_post_meta($post_id, LBRY_POST_CHANNEL, true));
+ $this->publisher->publish( $post, $channel, $license );
}
}
@@ -107,6 +115,6 @@ class LBRY_Network
*/
public function meta_box_html( $post )
{
- require_once(LBRY_ABSPATH . 'templates/meta_box.php');
+ require_once( LBRY_ABSPATH . 'templates/meta-box.php' );
}
}
diff --git a/templates/meta-box.php b/templates/meta-box.php
new file mode 100644
index 0000000..68d51f1
--- /dev/null
+++ b/templates/meta-box.php
@@ -0,0 +1,69 @@
+ 'none (anonymous)',
+ 'claim_id' => 'null'
+);
+// Generate a custom nonce
+$lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' );
+
+$channels = LBRY()->daemon->channel_list();
+$channels[] = $unnatributed;
+$post_id = $post->ID;
+$cur_channel = ( get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) ? get_post_meta( $post_id, LBRY_POST_PUB_CHANNEL, true ) : get_post_meta( $post_id, '_lbry_channel', true ) );
+$default_channel = get_option( LBRY_SETTINGS )['default_lbry_channel'];
+
+// Sort the channels in a natural way
+usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
+?>
+
+
+
+$channel ) {
+ $options .= '';
+ }
+ printf(
+ '',
+ LBRY_POST_PUB_CHANNEL,
+ $options
+ );
+ } ?>
+licenses;
+ $options = '';
+ $default_license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
+ $cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
+
+ // Create options list, select current license
+ if ( $licenses ) {
+ foreach ( $licenses as $value => $name ) {
+ $options .= '
diff --git a/templates/meta_box.php b/templates/meta_box.php
deleted file mode 100644
index 336469f..0000000
--- a/templates/meta_box.php
+++ /dev/null
@@ -1,42 +0,0 @@
- 'none (anonymous)',
- 'claim_id' => 'null'
-);
-$channels = LBRY()->daemon->channel_list();
-$channels[] = $unnatributed;
-// Sort the channels in a natural way
-usort($channels, array('LBRYPress', 'channel_name_comp'));
-$cur_channel = get_post_meta($post->ID, LBRY_POST_CHANNEL, true);
-$will_publish = get_post_meta($post->ID, LBRY_WILL_PUBLISH, true);
-?>
-
-