diff --git a/assets/js/settings.js b/assets/js/settings.js index 8dffb72b..b26e80ad 100644 --- a/assets/js/settings.js +++ b/assets/js/settings.js @@ -52,8 +52,8 @@ jQuery(document).ready(function($) { }); }, /** - * Validate the api credentials - */ + * Validate the api credentials + */ initConnect = function () { $connectBtn.on('click', function (e) { e.preventDefault(); diff --git a/php/classes/controllers/class-settings-controller.php b/php/classes/controllers/class-settings-controller.php index 61560d3d..080fa651 100644 --- a/php/classes/controllers/class-settings-controller.php +++ b/php/classes/controllers/class-settings-controller.php @@ -143,6 +143,20 @@ public function register_hooks_and_filters() { add_filter( 'ssp_field_data', array( $this, 'provide_podcasts_sync_status' ), 10, 2 ); $this->generate_dynamic_color_scheme(); + + add_shortcode( 'castos_email', array( $this, 'castos_email' ) ); + } + + /** + * Gets castos email to show in the Hosting tab. + * + * @since 3.5.0 + * + * @return string + * @throws \Exception + */ + public function castos_email() { + return $this->castos_handler->get_email(); } /** diff --git a/php/classes/handlers/class-castos-handler.php b/php/classes/handlers/class-castos-handler.php index f2698bbd..5040dca7 100644 --- a/php/classes/handlers/class-castos-handler.php +++ b/php/classes/handlers/class-castos-handler.php @@ -80,6 +80,7 @@ public function __construct( $feed_handler, $log_helper ) { add_filter( 'http_request_args', array( $this, 'authorization_headers' ), 10, 2 ); } + /** * Adds authorization headers * @@ -181,6 +182,34 @@ public function connect( $account_api_token ) { return $response; } + /** + * Gets connected user email. + * + * @since 3.5.0 + * + * @return string + * @throws Exception + */ + public function get_email() { + $this->logger->log( __METHOD__ ); + + $cache_key = 'ssp_castos_api_email'; + + $email = wp_cache_get( $cache_key ); + + if ( $email ) { + return $email; + } + + $res = $this->send_request( 'api/v2/' ); + + $email = isset( $res['email'] ) ? $res['email'] : ''; + + wp_cache_add( $cache_key, $email, '', MINUTE_IN_SECONDS ); + + return $email; + } + public function set_token( $token ) { update_option( self::API_TOKEN_OPTION, $token ); } diff --git a/php/config/settings/hosting.php b/php/config/settings/hosting.php index d40d489d..a347540e 100644 --- a/php/config/settings/hosting.php +++ b/php/config/settings/hosting.php @@ -4,66 +4,72 @@ * @var array $podcast_options * */ return array( - 'title' => __('Hosting', 'seriously-simple-podcasting'), - 'button_text' => __('Connect', 'seriously-simple-podcasting'), + 'title' => __( 'Hosting', 'seriously-simple-podcasting' ), + 'button_text' => __( 'Connect', 'seriously-simple-podcasting' ), 'button_class' => 'castos-connect disabled hidden', 'sections' => array( 'credentials' => array( 'condition_callback' => function () { - return !ssp_is_connected_to_castos(); + return ! ssp_is_connected_to_castos(); }, - 'title' => __('Podcast Hosting', 'seriously-simple-podcasting'), - 'description' => sprintf(__('Connect your WordPress site to your %s account.', 'seriously-simple-podcasting'), 'Castos'), - 'fields' => array( + 'title' => __( 'Podcast Hosting', 'seriously-simple-podcasting' ), + 'description' => sprintf( __( 'Connect your WordPress site to your %s account.', 'seriously-simple-podcasting' ), 'Castos' ), + 'fields' => array( array( - 'id' => 'podmotor_account_api_token', - 'type' => 'text', - 'label' => __('Castos API token', 'seriously-simple-podcasting'), - 'description' => sprintf(__('Your Castos API token. Available from your %s.', 'seriously-simple-podcasting'), 'Castos dashboard'), - 'default' => '', - 'placeholder' => __('Enter your API token', 'seriously-simple-podcasting'), - 'callback' => 'sanitize_text_field', - 'class' => 'regular-text', + 'id' => 'podmotor_account_api_token', + 'type' => 'text', + 'label' => __( 'Castos API token', 'seriously-simple-podcasting' ), + 'description' => sprintf( __( 'Your Castos API token. Available from your %s.', 'seriously-simple-podcasting' ), 'Castos dashboard' ), + 'default' => '', + 'placeholder' => __( 'Enter your API token', 'seriously-simple-podcasting' ), + 'callback' => 'sanitize_text_field', + 'class' => 'regular-text', ), ), ), - 'sync' => array( + 'sync' => array( 'condition_callback' => 'ssp_is_connected_to_castos', - 'title' => __('Sync to Castos', 'seriously-simple-podcasting'), - 'no_store' => true, - 'description' => sprintf( - __('Use this option for a one time sync of your existing WordPress podcast to your Castos account. If you encounter any problems with it, please contact support at hello@castos.com.', 'seriously-simple-podcasting'), - 'Castos' - ), - 'fields' => array( + 'title' => __( 'Sync to Castos', 'seriously-simple-podcasting' ), + 'no_store' => true, + 'fields' => array( + array( + 'id' => 'castos_sync_info', + 'label' => __( 'Castos Account', 'seriously-simple-podcasting' ), + 'description' => do_shortcode( '[castos_email]' ), + 'type' => 'info', + ), array( - 'id' => 'podcasts_sync', - 'label' => __('Podcast', 'seriously-simple-podcasting'), - 'description' => __('Select the podcast you want to sync to your Castos hosting account.', 'seriously-simple-podcasting'), - 'type' => 'podcasts_sync', - 'options' => $podcast_options, + 'id' => 'podcasts_sync', + 'label' => __( 'Podcast', 'seriously-simple-podcasting' ), + 'description' => __( 'Select the podcast you want to sync to your Castos hosting account.', 'seriously-simple-podcasting' ), + 'type' => 'podcasts_sync', + 'options' => $podcast_options, ), array( - 'id' => 'trigger_sync', - 'type' => 'button', - 'label' => esc_attr(__('Trigger Sync', 'seriously-simple-podcasting')), + 'id' => 'trigger_sync', + 'type' => 'button', + 'label' => esc_attr( __( 'Trigger Sync', 'seriously-simple-podcasting' ) ), + 'description' => '

' . sprintf( + __( 'Use this option for a one time sync of your existing WordPress podcast to your %s. If you encounter any problems with it, please contact support at hello@castos.com.', 'seriously-simple-podcasting' ), + '' . __( 'Castos account', 'seriously-simple-podcasting' ) . '' + ), 'class' => 'button-primary', ), ), ), - 'disconnect' => array( + 'disconnect' => array( 'condition_callback' => 'ssp_is_connected_to_castos', - 'title' => __('Danger Zone', 'seriously-simple-podcasting'), - 'no_store' => true, - 'fields' => array( + 'title' => __( 'Danger Zone', 'seriously-simple-podcasting' ), + 'no_store' => true, + 'fields' => array( array( - 'id' => 'disconnect_castos', - 'label' => __('Disconnect', 'seriously-simple-podcasting'), - 'description' => __('Select this if you wish to disconnect your Castos account.', 'seriously-simple-podcasting'), - 'type' => 'button', - 'default' => '', - 'callback' => 'wp_strip_all_tags', - 'class' => 'disconnect-castos button', + 'id' => 'disconnect_castos', + 'label' => __( 'Disconnect', 'seriously-simple-podcasting' ), + 'description' => __( 'Select this if you wish to disconnect your Castos account.', 'seriously-simple-podcasting' ), + 'type' => 'button', + 'default' => '', + 'callback' => 'wp_strip_all_tags', + 'class' => 'disconnect-castos button', ), ), ), diff --git a/tests/acceptance/3_main-feed.feature b/tests/acceptance/3_main-feed.feature index 5be30df2..d8a8c124 100644 --- a/tests/acceptance/3_main-feed.feature +++ b/tests/acceptance/3_main-feed.feature @@ -35,7 +35,7 @@ Feature: Login And I can see in source "xmlns:podcast=\"https://podcastindex.org/namespace/1.0\"" And I can see in source "" And I can see in source "Automated test show" - And I can see in source "" + And I can see in source "" And I can see in source "{{base_url}}/podcasts/automated-test-show/" And I can see in source "This show is to test some SSP functionality" And I can see in source ""