meta-box-change-after-post-published
This commit is contained in:
parent
e54b3034d2
commit
b9117fc749
4 changed files with 203 additions and 94 deletions
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Stylesheet for the admin options page
|
* Stylesheet for the admin pages LBRYPress uses
|
||||||
* @package LBRYPress
|
* @package LBRYPress
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -27,12 +27,15 @@
|
||||||
padding: .5em .8em .6em;
|
padding: .5em .8em .6em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lbry-meta-checkbox-wrapper-last {
|
.lbry-meta-wrapper-last {
|
||||||
padding: .5em .8em 1.5em;
|
padding: 0em .8em 1.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lbry-meta-label {
|
.lbry-meta-label {
|
||||||
padding-left: .3em;
|
padding: .3em .6em .6em .1em;
|
||||||
|
/* padding-left: .3em;
|
||||||
padding-right: .6em;
|
padding-right: .6em;
|
||||||
|
padding-bottom: .5em; */
|
||||||
}
|
}
|
||||||
|
|
||||||
.lbry-meta-bx-label {
|
.lbry-meta-bx-label {
|
||||||
|
@ -42,6 +45,38 @@
|
||||||
.lbry-meta-bx-option {
|
.lbry-meta-bx-option {
|
||||||
padding: .5em .8em .6em;
|
padding: .5em .8em .6em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lbry-meta-bx-option-last {
|
.lbry-meta-bx-option-last {
|
||||||
padding: .5em .8em 1.5em;
|
padding: .5em .8em 1.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lbry-hr-meta {
|
||||||
|
margin-left: 1em;
|
||||||
|
margin-right: 1em;
|
||||||
|
}
|
||||||
|
.post-lbry-display-before {
|
||||||
|
color: darkgreen;
|
||||||
|
}
|
||||||
|
.post-lbry-display {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lbry-pub-metabox {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lbry-claim-id-metabox {
|
||||||
|
margin: 0;
|
||||||
|
padding-top: .3em;
|
||||||
|
font-size: .85em;
|
||||||
|
line-height: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lbry-meta-bx-content {
|
||||||
|
padding: .2em .8em .6em .1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lbry-meta-bx-content-last {
|
||||||
|
padding: .2em .8em 1em .1em;
|
||||||
|
}
|
|
@ -120,11 +120,27 @@ class LBRY_Network
|
||||||
|
|
||||||
public function publish_to_lbry_checkbox( $post )
|
public function publish_to_lbry_checkbox( $post )
|
||||||
{
|
{
|
||||||
$post_id = $post->ID;
|
|
||||||
|
|
||||||
if ( get_post_type( $post_id ) != 'post' ) {
|
if ( get_post_type( $post_id ) != 'post' ) {
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
$post_id = $post->ID;
|
||||||
|
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
|
||||||
|
if ( $_GET['action'] === 'edit' ) {
|
||||||
|
if ( get_post_meta( $post_id, '_lbry_canonical_url', true ) == null || empty( get_post_meta( $post_id, '_lbry_canonical_url', true ) ) ) {
|
||||||
|
$canonical_url = LBRY()->daemon->canonical_url( $lbry_claim_id );
|
||||||
|
update_post_meta( $post_id, '_lbry_canonical_url', $canonical_url );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ( get_post_meta( $post_id, '_lbry_will_publish', true ) == true ) && (isset( $lbry_claim_id ) ) ) {
|
||||||
|
update_post_meta( $post_id, '_lbry_is_published', true );
|
||||||
|
}
|
||||||
|
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
|
||||||
|
$lbry_url = ( get_post_meta( $post_id, '_lbry_canonical_url', true ) );
|
||||||
|
|
||||||
|
if ($lbry_url) {
|
||||||
|
$open_url = str_replace('lbry://', 'open.lbry.com/', $lbry_url );
|
||||||
|
}
|
||||||
|
|
||||||
$default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'];
|
$default_value = get_option( LBRY_SETTINGS )['lbry_default_publish_setting'];
|
||||||
$new_value = get_post_meta( $post_id, LBRY_WILL_PUBLISH, true );
|
$new_value = get_post_meta( $post_id, LBRY_WILL_PUBLISH, true );
|
||||||
if ( ( $new_value ) ? $new_value : $new_value = $default_value );
|
if ( ( $new_value ) ? $new_value : $new_value = $default_value );
|
||||||
|
@ -132,17 +148,38 @@ class LBRY_Network
|
||||||
if ( ( $value ) ? $value : 0 );
|
if ( ( $value ) ? $value : 0 );
|
||||||
|
|
||||||
// nonce set on page meta-box.php
|
// nonce set on page meta-box.php
|
||||||
|
if ( ( $lbry_published ) && ( ( $lbry_url) || ( $lbry_claim_id ) ) ) {
|
||||||
printf(
|
printf(
|
||||||
'<div class="lbry-meta-checkbox-wrapper lbry-meta-checkbox-wrapper-last">
|
'<hr class="lbry-hr-meta">
|
||||||
<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 class="misc-pub-section lbry-meta-published-lbry-wrapper">
|
||||||
|
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span> <span class="post-lbry-display-before">Published on:</span> <span class="post-lbry-display"><strong> LBRY</strong></span>
|
||||||
|
</div>
|
||||||
|
<div class="misc-pub-section lbry-url-meta-wrapper">
|
||||||
|
<span class="lbry-meta-label"><strong> LBRY URL: </strong></span><a href="' . esc_url( '%2$s', 'lbrypress' ) . '" target="_blank">' . esc_html__( '%3$s', 'lbrypress' ) . '</a>
|
||||||
|
</div>
|
||||||
|
<div class="misc-pub-section lbry-claim-id-meta-wrapper">
|
||||||
|
<span class="lbry-meta-label"><strong> LBRY claim ID: </strong></span><span class="lbry-pub-metabox"><p class="lbry-claim-id-metabox">' . esc_html__( '%4$s', 'lbrypress' ) . '</p></span>
|
||||||
|
</div>
|
||||||
|
<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last">
|
||||||
|
<span class="lbry-meta-label"> Update Post on: <span><strong>' . esc_html__('LBRY', 'lbrypress') . '</strong></span> <input type="checkbox" class="lbry-meta-checkbox" value="1"' . esc_attr('%5$s') . ' name="' . esc_attr('%6$s') . '">
|
||||||
</div>',
|
</div>',
|
||||||
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
|
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
|
||||||
'Publish to',
|
$open_url,
|
||||||
'LBRY',
|
$lbry_url,
|
||||||
'lbrypress',
|
$lbry_claim_id,
|
||||||
checked( $value, true, false ),
|
checked( $value, true, false ),
|
||||||
LBRY_WILL_PUBLISH
|
LBRY_WILL_PUBLISH
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
printf (
|
||||||
|
'<div class="misc-pub-section lbry-meta-checkbox-wrapper lbry-meta-wrapper-last">
|
||||||
|
<span class="lbry-pub-metabox"><img src="' . __( '%1$s', 'lbrypress' ) . '" class="icon icon-lbry meta-icon-lbry"></span><span class="lbry-meta-label"> Publish to: <strong>' . esc_html__('LBRY', 'lbrypress') . '</strong></span><input type="checkbox" class="lbry-meta-checkbox" value="1"' . esc_attr('%2$s') . ' name="' . esc_attr('%3$s') . '">
|
||||||
|
</div>',
|
||||||
|
plugin_dir_url( LBRY_PLUGIN_FILE ) . 'admin/images/lbry.png',
|
||||||
|
checked( $value, true, false ),
|
||||||
|
LBRY_WILL_PUBLISH
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -84,9 +84,24 @@ class LBRY_Network_Publisher
|
||||||
// Set Claim ID
|
// Set Claim ID
|
||||||
update_post_meta( $post->ID, LBRY_CLAIM_ID, $claim_id );
|
update_post_meta( $post->ID, LBRY_CLAIM_ID, $claim_id );
|
||||||
|
|
||||||
|
// Set Channel Name Published under
|
||||||
|
$published_channel = $output->signing_channel->name;
|
||||||
|
$channel_claim_id = $output->signing_channel->claim_id;
|
||||||
|
update_post_meta( $post->ID, '_lbry_post_published_channel', $published_channel );
|
||||||
|
update_post_meta( $post->ID, '_lbry_post_pub_channel_claim_id', $channel_claim_id );
|
||||||
|
|
||||||
|
// Set License Published under
|
||||||
|
$published_license = $output->value->license;
|
||||||
|
if ( isset( $published_license ) && ( $published_license !== null ) ) {
|
||||||
|
update_post_meta( $post->ID, '_lbry_post_published_license', $published_license );
|
||||||
|
}
|
||||||
|
|
||||||
// Set Canonical URL
|
// Set Canonical URL
|
||||||
$canonical_url = LBRY()->daemon->canonical_url( $claim_id );
|
$canonical_url = LBRY()->daemon->canonical_url( $claim_id );
|
||||||
update_post_meta( $post->ID, LBRY_CANONICAL_URL, $canonical_url );
|
update_post_meta( $post->ID, LBRY_CANONICAL_URL, $canonical_url );
|
||||||
|
|
||||||
|
// Set _lbry_is_published to true
|
||||||
|
update_post_meta( $post->ID, '_lbry_is_published', true );
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
error_log( 'Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage() );
|
error_log( 'Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage() );
|
||||||
|
|
|
@ -12,28 +12,50 @@ $unnatributed = (object) array(
|
||||||
'name' => 'none (anonymous)',
|
'name' => 'none (anonymous)',
|
||||||
'claim_id' => 'null'
|
'claim_id' => 'null'
|
||||||
);
|
);
|
||||||
|
$post_id = $post->ID;
|
||||||
// Generate a custom nonce
|
// Generate a custom nonce
|
||||||
$lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' );
|
$lbrynonce = wp_create_nonce( 'lbry_publish_post_nonce' );
|
||||||
|
|
||||||
|
$lbry_published = get_post_meta( $post_id, '_lbry_is_published', true );
|
||||||
|
$lbry_claim_id = get_post_meta( $post_id, '_lbry_claim_id', true );
|
||||||
|
// $lbry_url = get_post_meta( $post_id, '_lbry_canonical_url', true );
|
||||||
|
$lbry_published_channel = get_post_meta( $post_id, '_lbry_post_published_channel', true );
|
||||||
|
if ( ! ( $lbry_published_channel ) ) {
|
||||||
|
LBRY()->daemon->claim_search( $lbry_claim_id );
|
||||||
|
}
|
||||||
|
$lbry_channel_claim_id = get_post_meta( $post_id, '_lbry_post_pub_channel', true );
|
||||||
|
//if ( $lbry_channel_claim_id === null ? 'Anonymously' : $lbry_channel_claim_id);
|
||||||
|
$lbry_published_license = get_post_meta( $post_id, '_lbry_post_pub_license', true );
|
||||||
|
|
||||||
$channels = LBRY()->daemon->channel_list();
|
$channels = LBRY()->daemon->channel_list();
|
||||||
$channels[] = $unnatributed;
|
$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 ) );
|
$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'];
|
$default_channel = get_option( LBRY_SETTINGS )['default_lbry_channel'];
|
||||||
|
$chan_open_url = ( 'open.lbry.com/'. $lbry_published_channel .'#' . $lbry_channel_claim_id . '');
|
||||||
|
|
||||||
// Sort the channels in a natural way
|
// Sort the channels in a natural way
|
||||||
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
|
usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<section>
|
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>"><?php
|
||||||
<input type="hidden" id="_lbrynonce" name="_lbrynonce" value="<?php echo $lbrynonce ?>">
|
|
||||||
<div><label for="LBRY_POST_PUB_CHANNEL" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php esc_html_e( 'Channel to Publish: ', 'lbrypress' ); ?></label></div><?php
|
if ( ( ( $lbry_published == true ) || ( $lbry_published_channel ) ) && ( $lbry_published_license != null) ) {
|
||||||
|
printf(
|
||||||
|
'<div class="lbry-meta-label lbry-meta-bx-channel"><strong>' . __( 'LBRY channel published at:', 'lbrypress' ) . '</strong> <div class="lbry-meta-bx-content lbry-meta-bx-channel"><a href="' . esc_url( '%2$s', 'lbrypress' ) . '">' . esc_html__( '%1$s', 'lbrypress' ) . '</a></div><div class="lbry-meta-label lbry-meta-bx-license"><strong>' . __( 'License published under:', 'lbrypress' ) .'</strong> </div><div class="lbry-meta-bx-content lbry-meta-bx-license lbry-meta-bx-content-last">' . esc_html__( '%3$s', 'lbrypress' ) . '</div></div>',
|
||||||
|
$lbry_published_channel,
|
||||||
|
$chan_open_url,
|
||||||
|
$lbry_published_license,
|
||||||
|
);
|
||||||
|
} else { ?>
|
||||||
|
<div><label for="LBRY_POST_PUB_CHANNEL" class="lbry-meta-bx-label lbry-meta-bx-channel"><?php
|
||||||
|
|
||||||
|
esc_html_e( 'Channel to Publish:', 'lbrypress' ); ?> </label></div><?php
|
||||||
|
|
||||||
$options = '';
|
$options = '';
|
||||||
if ( $channels ) {
|
if ( $channels ) {
|
||||||
foreach ( $channels as $index=>$channel ) {
|
foreach ( $channels as $index=>$channel ) {
|
||||||
$options .= '<option class="lbry-meta-bx-option lbry-meta-option-channel" value="' . esc_attr( $channel->claim_id ) . '"';
|
$options .= '<option class="lbry-meta-bx-option lbry-meta-option-channel" value="' . esc_attr( $channel->claim_id ) . '"';
|
||||||
if ( isset( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) {
|
if ( ( $cur_channel ) ? $cur_channel : $cur_channel = $default_channel ) {
|
||||||
$options .= selected( $cur_channel, $channel->claim_id, false );
|
$options .= selected( $cur_channel, $channel->claim_id, false );
|
||||||
}
|
}
|
||||||
$options .= '>' . esc_html__( $channel->name, 'lbrypress' ) . '</option>';
|
$options .= '>' . esc_html__( $channel->name, 'lbrypress' ) . '</option>';
|
||||||
|
@ -43,7 +65,8 @@ usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
|
||||||
LBRY_POST_PUB_CHANNEL,
|
LBRY_POST_PUB_CHANNEL,
|
||||||
$options
|
$options
|
||||||
);
|
);
|
||||||
} ?>
|
}
|
||||||
|
?>
|
||||||
<div><label for="LBRY_POST_PUB_LICENSE" class="lbry-meta-bx-label lbry-meta-bx-license"><?php esc_html_e( 'Publish License:', 'lbrypress' ); ?> </label></div><?php
|
<div><label for="LBRY_POST_PUB_LICENSE" class="lbry-meta-bx-label lbry-meta-bx-license"><?php esc_html_e( 'Publish License:', 'lbrypress' ); ?> </label></div><?php
|
||||||
$licenses = LBRY()->licenses;
|
$licenses = LBRY()->licenses;
|
||||||
$options = '';
|
$options = '';
|
||||||
|
@ -54,7 +77,7 @@ usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
|
||||||
if ( $licenses ) {
|
if ( $licenses ) {
|
||||||
foreach ( $licenses as $value => $name ) {
|
foreach ( $licenses as $value => $name ) {
|
||||||
$options .= '<option class="lbry-meta-bx-option lbry-meta-bx-option-last lbry-meta-option-license" value="' . esc_attr( $value ) . '"';
|
$options .= '<option class="lbry-meta-bx-option lbry-meta-bx-option-last lbry-meta-option-license" value="' . esc_attr( $value ) . '"';
|
||||||
if ( isset( $cur_license ) ? $cur_license : $cur_license = $default_license ) {
|
if ( ( $cur_license ) ? $cur_license : $cur_license = $default_license ) {
|
||||||
$options .= selected( $cur_license, $value, false );
|
$options .= selected( $cur_license, $value, false );
|
||||||
}
|
}
|
||||||
$options .= '>'. esc_html__( $name, 'lbrypress' ) . '</option>';
|
$options .= '>'. esc_html__( $name, 'lbrypress' ) . '</option>';
|
||||||
|
@ -65,5 +88,4 @@ usort( $channels, array( 'LBRYPress', 'channel_name_comp' ) );
|
||||||
LBRY_POST_PUB_LICENSE,
|
LBRY_POST_PUB_LICENSE,
|
||||||
$options
|
$options
|
||||||
);
|
);
|
||||||
?>
|
}
|
||||||
</section>
|
|
Loading…
Reference in a new issue