Default license selector (#51)

* default license select option

* default channel selector
This commit is contained in:
Lemuel Smyth 2022-02-13 10:39:42 -06:00 committed by GitHub
parent e66bc60c0e
commit 3e68befdc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 6 deletions

View file

@ -68,7 +68,7 @@ class LBRY_Admin
{
// Register the LBRY Setting array
register_setting(
LBRY_SETTINGS_GROUP,
'lbry_general_settings',
LBRY_SETTINGS,
array( $this, 'sanitize_general_settings' )
);
@ -90,6 +90,13 @@ class LBRY_Admin
LBRY_SETTINGS_SECTION_GENERAL
);
add_settings_field(
'default_lbry_channel',
'Default Publish Channel',
array( $this, 'default_channel_callback' ),
LBRY_ADMIN_PAGE,
LBRY_SETTINGS_SECTION_GENERAL
);
add_settings_field(
LBRY_LICENSE,
'LBRY Publishing License',
@ -115,7 +122,6 @@ class LBRY_Admin
/**
* Speech Admin Page settings
*/
@ -255,6 +261,37 @@ class LBRY_Admin
);
}
/**
* 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
*/
@ -275,13 +312,14 @@ class LBRY_Admin
}
printf(
'<select id="%1$s" name="%2$s[%1$s]">%3$s</select>',
'<select id="'.esc_attr('%1$s').'" name="'. esc_attr('%2$s[%1$s]') .'">' . esc_html('%3$s') . '</select>',
LBRY_LICENSE,
LBRY_SETTINGS,
$options
);
}
/**
* Prints LBC per publish input
*/

View file

@ -79,9 +79,11 @@ class LBRY_Network
return $post_id;
}
$will_publish = (isset($_POST[LBRY_WILL_PUBLISH]) ? $_POST[LBRY_WILL_PUBLISH] : false);
$new_channel = (isset($_POST[LBRY_POST_CHANNEL]) ? $_POST[LBRY_POST_CHANNEL] : null);
$cur_channel = get_post_meta($post_id, LBRY_POST_CHANNEL, true);
$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 ) );
$license = $_POST[LBRY_POST_PUB_LICENSE];
$cur_license = get_post_meta( $post_id, LBRY_POST_PUB_LICENSE, true );
$will_publish = $_POST[LBRY_WILL_PUBLISH];
// Update meta acordingly
if (!$will_publish) {