From c94a276a76484c3badd5deb617d24689372c414f Mon Sep 17 00:00:00 2001 From: Lemuel Smyth <36257395+lemsmyth@users.noreply.github.com> Date: Sun, 13 Feb 2022 10:57:41 -0600 Subject: [PATCH 1/2] Checkbox set default publish (#52) * checkbox to set default publish --- classes/LBRY_Admin.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 7cb8b03..72d672f 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -91,12 +91,23 @@ class LBRY_Admin ); 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', array( $this, 'default_channel_callback' ), LBRY_ADMIN_PAGE, LBRY_SETTINGS_SECTION_GENERAL ); + add_settings_field( LBRY_LICENSE, 'LBRY Publishing License', @@ -261,6 +272,24 @@ class LBRY_Admin ); } + /** + * 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( + '
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 */ From 992be8ca0ff14a1cdf808b035dd14ba8ee3ccea1 Mon Sep 17 00:00:00 2001 From: Lemuel Smyth <36257395+lemsmyth@users.noreply.github.com> Date: Sun, 13 Feb 2022 11:00:09 -0600 Subject: [PATCH 2/2] Sanitize options callback (#53) * sanitize option settings callbacks --- classes/LBRY_Admin.php | 48 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php index 72d672f..d72ab87 100644 --- a/classes/LBRY_Admin.php +++ b/classes/LBRY_Admin.php @@ -181,22 +181,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 ) @@ -230,13 +232,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 @@ -256,6 +251,15 @@ class LBRY_Admin options[LBRY_LBC_PUBLISH] ); - } + } /** * Channels Page