From f2e0c54e5eee0df75297c4ef79c28a2730e8beec Mon Sep 17 00:00:00 2001
From: Lemuel Smyth <36257395+lemsmyth@users.noreply.github.com>
Date: Sun, 13 Feb 2022 11:08:24 -0600
Subject: [PATCH] Meta box create (#54)
* creates and prints the meta box
---
classes/LBRYPress.php | 4 +--
classes/LBRY_Admin.php | 5 ++-
classes/LBRY_Network.php | 8 ++---
templates/meta-box.php | 69 ++++++++++++++++++++++++++++++++++++++++
templates/meta_box.php | 42 ------------------------
5 files changed, 77 insertions(+), 51 deletions(-)
create mode 100644 templates/meta-box.php
delete mode 100644 templates/meta_box.php
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 d72ab87..844072a 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 ),
@@ -91,7 +91,6 @@ class LBRY_Admin
);
add_settings_field(
-
'lbry_default_publish_setting',
'Always Publish to LBRY',
array( $this, 'lbry_always_pub_callback' ),
@@ -100,7 +99,6 @@ class LBRY_Admin
);
add_settings_field(
-
'default_lbry_channel',
'Default Publish Channel',
array( $this, 'default_channel_callback' ),
@@ -276,6 +274,7 @@ class LBRY_Admin
);
}
+
/**
* Checkbox to default to always allow publish on LBRY
*/
diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php
index 4b4de01..5d88d04 100644
--- a/classes/LBRY_Network.php
+++ b/classes/LBRY_Network.php
@@ -34,7 +34,7 @@ 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);
@@ -43,12 +43,12 @@ class LBRY_Network
/**
* 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
@@ -107,6 +107,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' ) );
+?>
+
+