Checkbox for always publish to LBRY inside main publish meta box (#58)
* hook publish to LBRY into main publish metabox * style metaboxes
This commit is contained in:
parent
557dd888fa
commit
d04668ee91
5 changed files with 118 additions and 1 deletions
|
@ -13,3 +13,35 @@
|
|||
height: 1.2em;
|
||||
margin-bottom: -.2em;
|
||||
}
|
||||
|
||||
.lbry-pub-metabox {
|
||||
margin: 0 0 0 -.2em;
|
||||
padding: 0 .2em 0 0 ;
|
||||
}
|
||||
.meta-icon-lbry {
|
||||
height: 1.55em;
|
||||
margin-bottom: -.4em;
|
||||
padding-left: .1em;
|
||||
}
|
||||
.lbry-meta-checkbox-wrapper {
|
||||
padding: .5em .8em .6em;
|
||||
}
|
||||
|
||||
.lbry-meta-checkbox-wrapper-last {
|
||||
padding: .5em .8em 1.5em;
|
||||
}
|
||||
.lbry-meta-label {
|
||||
padding-left: .3em;
|
||||
padding-right: .6em;
|
||||
}
|
||||
|
||||
.lbry-meta-bx-label {
|
||||
margin: .5em .8em .6em;
|
||||
}
|
||||
|
||||
.lbry-meta-bx-option {
|
||||
padding: .5em .8em .6em;
|
||||
}
|
||||
.lbry-meta-bx-option-last {
|
||||
padding: .5em .8em 1.5em;
|
||||
}
|
||||
|
|
BIN
admin/images/lbry-icon.png
Normal file
BIN
admin/images/lbry-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 654 B |
BIN
admin/images/lbry.png
Normal file
BIN
admin/images/lbry.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Admin
|
||||
{
|
||||
|
@ -32,7 +33,7 @@ class LBRY_Admin
|
|||
'manage_options',
|
||||
LBRY_ADMIN_PAGE,
|
||||
array( $this, 'options_page_html' ),
|
||||
plugin_dir_url(LBRY_PLUGIN_FILE) . '/admin/images/lbry-logo.svg'
|
||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . '/admin/images/lbry-icon.png'
|
||||
);
|
||||
|
||||
// Admin stylesheet enqueue
|
||||
|
@ -338,6 +339,55 @@ class LBRY_Admin
|
|||
<?php }
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox to default to always allow publish on LBRY
|
||||
*/
|
||||
public function lbry_always_pub_callback()
|
||||
{
|
||||
$options = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'];
|
||||
if ( ! isset( $options ) ) {
|
||||
$options = 0;
|
||||
}
|
||||
$checked = checked( $options, 1, false );
|
||||
printf(
|
||||
'<input type="checkbox" id="lbry_default_publish_setting" name="' . esc_attr('%2$s[%1$s]') . '" value="1" ' . esc_attr( $checked ) . '><p>Set Default to always Publish to <strong>LBRY</strong>, this can be adjusted when publishing a New Post.</p>',
|
||||
'lbry_default_publish_setting',
|
||||
LBRY_SETTINGS,
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints select to choose a default to publish to channel
|
||||
*/
|
||||
public function default_channel_callback()
|
||||
{
|
||||
$options = '';
|
||||
$channel_list = LBRY()->daemon->channel_list();
|
||||
|
||||
if ( $channel_list ) {
|
||||
foreach ( $channel_list as $channel ) {
|
||||
$selected = $this->options['default_lbry_channel'] === $channel->claim_id;
|
||||
|
||||
$options .= '<option value="' . esc_attr( $channel->claim_id ) . '"';
|
||||
if ( $selected ) {
|
||||
$options .= ' selected';
|
||||
}
|
||||
$options .= '>' . esc_html( $channel->name ) . '</option>';
|
||||
}
|
||||
|
||||
printf(
|
||||
'<select id="' . esc_attr('%1$s') . '" name="' . esc_attr('%2$s[%1$s]') . '">' . esc_html('%3$s') . '</select>',
|
||||
'default_lbry_channel',
|
||||
LBRY_SETTINGS,
|
||||
$options
|
||||
);
|
||||
} else { ?>
|
||||
<p>Looks like you haven't added any channels yet, you can do that now on the <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'lbrypress', 'tab' => 'channels' ), 'options.php' ) ) ); ?>" class="">Channels Tab</a></p>
|
||||
<?php }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints License input
|
||||
*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*
|
||||
* @package LBRYPress
|
||||
*/
|
||||
defined('ABSPATH') || die(); // Exit if accessed directly
|
||||
|
||||
class LBRY_Network
|
||||
{
|
||||
|
@ -38,6 +39,8 @@ class LBRY_Network
|
|||
|
||||
// Save the post meta on 'save_post' hook
|
||||
add_action( 'wp_insert_post', array( $this, 'save_post_meta' ), 11, 2 );
|
||||
// Checkbox inside the WordPres meta box near "Publish" button
|
||||
add_action( 'post_submitbox_misc_actions', array( $this, 'publish_to_lbry_checkbox' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,6 +112,38 @@ class LBRY_Network
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a checkbox that changes the default setting to always publish to LBRY,
|
||||
* can be reverted individually to not publish on a per post basis. Saves to options table.
|
||||
*/
|
||||
|
||||
public function publish_to_lbry_checkbox( $post )
|
||||
{
|
||||
$post_id = $post->ID;
|
||||
|
||||
if ( get_post_type( $post_id ) != 'post' ) {
|
||||
return $post;
|
||||
}
|
||||
$default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'];
|
||||
$new_value = get_post_meta( $post_id, LBRY_WILL_PUBLISH, true );
|
||||
if ( ( $new_value ) ? $new_value : $new_value = $default_value );
|
||||
$value = $new_value;
|
||||
if ( ( $value ) ? $value : 0 );
|
||||
|
||||
// nonce set on page meta-box.php
|
||||
printf (
|
||||
'<div class="lbry-meta-checkbox-wrapper lbry-meta-checkbox-wrapper-last">
|
||||
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', '%4$s' ) . '" class="icon icon-lbry meta-icon-lbry"></span><label class="lbry-meta-label">' . esc_html__('%2$s', '%4$s' ) . ' <strong>' . esc_html__('%3$s', '%4$s') . '</strong></label><input type="checkbox" class="lbry-meta-checkbox" value="1"' . esc_attr('%5$s') . ' name="' . esc_attr('%6$s') . '">
|
||||
</div>',
|
||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
|
||||
'Publish to',
|
||||
'LBRY',
|
||||
'lbrypress',
|
||||
checked( $value, true, false ),
|
||||
LBRY_WILL_PUBLISH
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML for the LBRY Meta Box
|
||||
* @param WP_POST $post
|
||||
|
|
Loading…
Reference in a new issue