$data ) { if ( 'Play.ht' === $data['Name'] && is_plugin_active( $file ) ) { return $file; } } return ''; } /** On the Dashboard, the Plugins page and Leelo's settings: switch Play.ht's plugin off. */ public static function playht_notice() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || ! in_array( $screen->id, array( 'dashboard', 'plugins', 'settings_page_' . self::PAGE ), true ) || ! current_user_can( 'activate_plugins' ) ) { return; } $file = self::playht_file(); if ( '' === $file ) { return; } echo '

' . esc_html__( 'Deactivate the Play.ht plugin to use Leelo.', 'leelo' ) . ' '; echo esc_html__( 'Play.ht\'s WordPress plugin was closed on WordPress.org in March 2024 for a security issue, and its player no longer plays. While it\'s on, its player shows on your posts instead of Leelo\'s. Your [playht_player] shortcodes stay where they are and play Leelo\'s audio once it\'s off.', 'leelo' ); echo '

'; if ( ! is_plugin_active_for_network( $file ) ) { $link = wp_nonce_url( admin_url( 'plugins.php?action=deactivate&plugin=' . rawurlencode( $file ) ), 'deactivate-plugin_' . $file ); echo '

' . esc_html__( 'Deactivate Play.ht', 'leelo' ) . '

'; } echo '
'; } public static function menu() { add_options_page( __( 'Leelo', 'leelo' ), __( 'Leelo', 'leelo' ), 'manage_options', self::PAGE, array( __CLASS__, 'page' ) ); } public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'leelo' ) . '' ); return $links; } private static function url( array $args = array() ) { return add_query_arg( array_merge( array( 'page' => self::PAGE ), $args ), admin_url( 'options-general.php' ) ); } private static function back( $notice, $type = 'success' ) { set_transient( 'leelo_notice_' . get_current_user_id(), array( $notice, $type ), 60 ); wp_safe_redirect( self::url() ); exit; } private static function guard( $action ) { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do that.', 'leelo' ) ); } check_admin_referer( $action ); } // ---------------------------------------------------------------- connecting /** Where "Connect to Leelo" goes: Leelo's page asks the person to confirm, then comes back here. */ private static function connect_link() { return add_query_arg( array( 'site' => rawurlencode( home_url( '/' ) ), 'return' => rawurlencode( self::url() ), 'state' => wp_create_nonce( 'leelo_connect' ), 'name' => rawurlencode( wp_strip_all_tags( get_bloginfo( 'name' ) ) ), ), LEELO_APP . '/app/connect/wordpress' ); } /** Back from Leelo with a one-time code: trade it for the site's key, server to server. */ public static function connect_return() { if ( ! isset( $_GET['page'] ) || self::PAGE !== $_GET['page'] || ( ! isset( $_GET['leelo_code'] ) && ! isset( $_GET['leelo_error'] ) ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } $state = isset( $_GET['state'] ) ? sanitize_text_field( wp_unslash( $_GET['state'] ) ) : ''; if ( ! wp_verify_nonce( $state, 'leelo_connect' ) ) { self::back( __( 'That connection link has expired. Please click Connect to Leelo again.', 'leelo' ), 'error' ); } if ( isset( $_GET['leelo_error'] ) ) { self::back( __( 'Connecting was cancelled.', 'leelo' ), 'warning' ); } $code = sanitize_text_field( wp_unslash( $_GET['leelo_code'] ) ); $result = Leelo_Api::request( 'POST', '/site/claim', array( 'code' => $code ), false ); if ( is_wp_error( $result ) || empty( $result['key'] ) ) { self::back( is_wp_error( $result ) ? $result->get_error_message() : __( 'Leelo did not send a key back. Please try again.', 'leelo' ), 'error' ); } Leelo_Narration::forget_pending(); self::forget_account(); Leelo_Settings::update( array( 'key' => sanitize_text_field( $result['key'] ), 'site_id' => sanitize_text_field( $result['site_id'] ?? '' ), 'plan' => 0, ) ); Leelo_Narration::ensure_schedule(); self::back( __( 'Connected to Leelo. Choose a voice below, and your posts will get audio.', 'leelo' ) ); } public static function disconnect() { self::guard( 'leelo_disconnect' ); Leelo_Narration::forget_pending(); self::forget_account(); Leelo_Settings::update( array( 'key' => '', 'site_id' => '', 'plan' => 0, ) ); self::back( __( 'Disconnected. Players already on your posts keep playing.', 'leelo' ) ); } /** What was kept about the last connected account (its credits, plan, cost estimate): gone. */ private static function forget_account() { delete_transient( 'leelo_site' ); delete_transient( 'leelo_estimate_' . get_current_user_id() ); } // ---------------------------------------------------------------- settings public static function save() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do that.', 'leelo' ) ); } check_admin_referer( 'leelo_save' ); $position = isset( $_POST['position'] ) ? sanitize_key( wp_unslash( $_POST['position'] ) ) : 'top'; $types = isset( $_POST['post_types'] ) ? array_map( 'sanitize_key', (array) wp_unslash( $_POST['post_types'] ) ) : array( 'post' ); Leelo_Settings::update( array( 'auto' => empty( $_POST['auto'] ) ? 0 : 1, 'position' => in_array( $position, array( 'top', 'bottom', 'none' ), true ) ? $position : 'top', 'post_types' => array_values( array_filter( $types, 'post_type_exists' ) ) ?: array( 'post' ), ) ); $site = array(); if ( ! empty( $_POST['voice_id'] ) ) { $site['voice_id'] = sanitize_text_field( wp_unslash( $_POST['voice_id'] ) ); } if ( isset( $_POST['theme'] ) ) { $site['theme'] = 'dark' === sanitize_key( wp_unslash( $_POST['theme'] ) ) ? 'dark' : 'light'; } if ( isset( $_POST['accent'] ) ) { $accent = sanitize_hex_color( wp_unslash( $_POST['accent'] ) ); if ( $accent ) { $site['accent'] = $accent; } } if ( $site ) { $result = Leelo_Api::post( '/site/settings', $site ); if ( is_wp_error( $result ) ) { self::back( $result->get_error_message(), 'error' ); } delete_transient( 'leelo_site' ); } self::back( __( 'Settings saved.', 'leelo' ) ); } // ---------------------------------------------------------------- older posts public static function estimate() { self::guard( 'leelo_estimate' ); $posts = array(); foreach ( Leelo_Narration::without_audio() as $post_id ) { $post = get_post( $post_id ); $paragraphs = Leelo_Text::paragraphs( $post ); if ( $paragraphs ) { $posts[] = array( 'post_id' => (string) $post_id, 'words' => Leelo_Text::words( get_the_title( $post ), $paragraphs ), ); } } if ( ! $posts ) { self::back( __( 'Every published post already has audio.', 'leelo' ) ); } $result = Leelo_Api::post( '/site/estimate', array( 'posts' => $posts ) ); if ( is_wp_error( $result ) ) { self::back( $result->get_error_message(), 'error' ); } set_transient( 'leelo_estimate_' . get_current_user_id(), array( 'ids' => wp_list_pluck( $posts, 'post_id' ), 'credits' => (int) $result['total_credits'], 'left' => (int) $result['credits_left'], 'enough' => ! empty( $result['enough'] ), 'can' => ! empty( $result['can_narrate'] ), ), HOUR_IN_SECONDS ); wp_safe_redirect( self::url() . '#leelo-older' ); exit; } public static function start_backlog() { self::guard( 'leelo_backlog' ); $estimate = get_transient( 'leelo_estimate_' . get_current_user_id() ); if ( ! is_array( $estimate ) || empty( $estimate['ids'] ) ) { self::back( __( 'Please check the cost first.', 'leelo' ), 'warning' ); } $queued = get_option( Leelo_Narration::BACKLOG, array() ); $ids = array_values( array_unique( array_map( 'intval', array_merge( is_array( $queued ) ? $queued : array(), $estimate['ids'] ) ) ) ); update_option( Leelo_Narration::BACKLOG, $ids, false ); delete_transient( 'leelo_estimate_' . get_current_user_id() ); self::back( sprintf( /* translators: %d: number of posts */ _n( '%d post will get audio over the next few minutes.', '%d posts will get audio, a few every five minutes.', count( $ids ), 'leelo' ), count( $ids ) ) ); } public static function create_one() { $post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0; if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( esc_html__( 'You are not allowed to do that.', 'leelo' ) ); } check_admin_referer( 'leelo_create_' . $post_id ); $result = Leelo_Narration::send( $post_id ); $back = wp_get_referer() ? wp_get_referer() : admin_url( 'edit.php' ); if ( is_wp_error( $result ) ) { set_transient( 'leelo_notice_' . get_current_user_id(), array( $result->get_error_message(), 'error' ), 60 ); } else { set_transient( 'leelo_notice_' . get_current_user_id(), array( __( 'Audio is being made for this post. It appears on the post in a few minutes.', 'leelo' ), 'success' ), 60 ); } wp_safe_redirect( $back ); exit; } /** Without a plan: one post, free, to hear it. The newest post without audio that the free post covers. */ public static function free_post() { self::guard( 'leelo_free_post' ); $posts = array(); // The newest posts that don't have audio yet. foreach ( Leelo_Narration::without_audio( 20 ) as $post_id ) { $paragraphs = Leelo_Text::paragraphs( get_post( $post_id ) ); if ( $paragraphs ) { $posts[] = array( 'post_id' => (string) $post_id, 'words' => Leelo_Text::words( get_the_title( $post_id ), $paragraphs ), ); } } if ( ! $posts ) { self::back( __( 'Every published post already has audio, or none has text yet.', 'leelo' ), 'warning' ); } $estimate = Leelo_Api::post( '/site/estimate', array( 'posts' => $posts ) ); if ( is_wp_error( $estimate ) ) { self::back( $estimate->get_error_message(), 'error' ); } $left = (int) $estimate['credits_left']; $pick = 0; foreach ( (array) $estimate['posts'] as $p ) { if ( (int) $p['credits'] <= $left ) { $pick = (int) $p['post_id']; break; } } if ( ! $pick ) { self::back( $left > 0 ? sprintf( /* translators: %s: credits */ __( 'Your recent posts are each longer than your free post covers (up to %s credits). Publish a shorter post for your free one, or choose a monthly plan to give all your posts audio.', 'leelo' ), number_format_i18n( $left ) ) : __( 'Your free post has already been used. Choose a monthly plan to give your posts audio.', 'leelo' ), 'warning' ); } $result = Leelo_Narration::send( $pick ); if ( is_wp_error( $result ) ) { self::back( $result->get_error_message(), 'error' ); } delete_transient( 'leelo_site' ); self::back( sprintf( /* translators: %s: post title */ __( '"%s" is getting its audio. Open the post in a minute or two to hear it.', 'leelo' ), wp_strip_all_tags( get_the_title( $pick ) ) ) ); } // ---------------------------------------------------------------- posts list public static function columns() { foreach ( Leelo_Settings::post_types() as $type ) { add_filter( "manage_{$type}_posts_columns", array( __CLASS__, 'column' ) ); add_action( "manage_{$type}_posts_custom_column", array( __CLASS__, 'column_value' ), 10, 2 ); } } public static function column( $columns ) { $columns['leelo'] = __( 'Audio', 'leelo' ); return $columns; } public static function column_value( $column, $post_id ) { if ( 'leelo' !== $column ) { return; } $status = (string) get_post_meta( $post_id, '_leelo_status', true ); $labels = array( 'ready' => __( 'Ready', 'leelo' ), 'queued' => __( 'Waiting', 'leelo' ), 'making' => __( 'Being made', 'leelo' ), 'failed' => __( 'Failed', 'leelo' ), 'needs_credits' => __( 'Needs credits', 'leelo' ), ); if ( isset( $labels[ $status ] ) ) { $error = (string) get_post_meta( $post_id, '_leelo_error', true ); printf( '%s', esc_attr( $error ), esc_html( $labels[ $status ] ) ); } else { echo ''; } } public static function row_action( $actions, $post ) { if ( Leelo_Settings::connected() && Leelo_Narration::eligible( $post ) && current_user_can( 'edit_post', $post->ID ) ) { $url = wp_nonce_url( admin_url( 'admin-post.php?action=leelo_create&post=' . $post->ID ), 'leelo_create_' . $post->ID ); $label = get_post_meta( $post->ID, '_leelo_embed_url', true ) ? __( 'Update audio', 'leelo' ) : __( 'Create audio', 'leelo' ); $actions['leelo_audio'] = '' . esc_html( $label ) . ''; } return $actions; } // ---------------------------------------------------------------- the post editor /** A small box beside each post: its audio, "No audio for this post", and making it now. */ public static function meta_box() { foreach ( Leelo_Settings::post_types() as $type ) { add_meta_box( 'leelo-audio', __( 'Leelo audio', 'leelo' ), array( __CLASS__, 'render_meta_box' ), $type, 'side' ); } } public static function render_meta_box( $post ) { wp_nonce_field( 'leelo_meta_' . $post->ID, 'leelo_meta_nonce' ); $skip = (bool) get_post_meta( $post->ID, '_leelo_skip', true ); $status = (string) get_post_meta( $post->ID, '_leelo_status', true ); $labels = array( 'ready' => __( 'This post has audio.', 'leelo' ), 'queued' => __( 'Audio is waiting to be made.', 'leelo' ), 'making' => __( 'Audio is being made.', 'leelo' ), 'failed' => __( 'Audio could not be made.', 'leelo' ), 'needs_credits' => __( 'Audio needs more credits.', 'leelo' ), ); echo '

' . esc_html( $skip ? __( 'No audio for this post.', 'leelo' ) : ( $labels[ $status ] ?? __( 'No audio yet.', 'leelo' ) ) ) . '

'; $error = (string) get_post_meta( $post->ID, '_leelo_error', true ); if ( '' !== $error && ! $skip ) { echo '

' . esc_html( $error ) . '

'; } printf( '

', checked( $skip, true, false ), esc_html__( 'No audio for this post', 'leelo' ) ); if ( ! $skip && Leelo_Settings::connected() && Leelo_Narration::eligible( $post ) ) { $url = wp_nonce_url( admin_url( 'admin-post.php?action=leelo_create&post=' . $post->ID ), 'leelo_create_' . $post->ID ); printf( '

%s

', esc_url( $url ), esc_html( 'ready' === $status ? __( 'Update audio now', 'leelo' ) : __( 'Create audio now', 'leelo' ) ) ); } if ( ! Leelo_Settings::connected() ) { echo '

' . esc_html__( 'Connect to Leelo', 'leelo' ) . '

'; } } public static function save_meta_box( $post_id, $post ) { if ( ! isset( $_POST['leelo_meta_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['leelo_meta_nonce'] ) ), 'leelo_meta_' . $post_id ) ) { return; } if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { return; } if ( empty( $_POST['leelo_skip'] ) ) { delete_post_meta( $post_id, '_leelo_skip' ); } else { update_post_meta( $post_id, '_leelo_skip', 1 ); // Not sent, and not waiting either. wp_clear_scheduled_hook( Leelo_Narration::SEND, array( (int) $post_id ) ); } } // ---------------------------------------------------------------- the page private static function notice() { $notice = get_transient( 'leelo_notice_' . get_current_user_id() ); if ( is_array( $notice ) ) { delete_transient( 'leelo_notice_' . get_current_user_id() ); printf( '

%s

', esc_attr( $notice[1] ), esc_html( $notice[0] ) ); } } /** The site as Leelo has it (voice, look, credits), kept for five minutes; saving settings refreshes it. */ private static function site() { $site = get_transient( 'leelo_site' ); if ( false === $site ) { $site = Leelo_Api::get( '/site' ); if ( is_wp_error( $site ) ) { return $site; } set_transient( 'leelo_site', $site, 5 * MINUTE_IN_SECONDS ); Leelo_Settings::update( array( 'plan' => empty( $site['account']['website_plan'] ) ? 0 : 1 ) ); } return $site; } /** Voices in one language, from Leelo. */ private static function voices( $locale ) { $key = 'leelo_voices_v2_' . md5( $locale ); $voices = get_transient( $key ); if ( false !== $voices ) { return $voices; } $voices = array(); $after = ''; $complete = false; // A language has a few hundred voices, and Leelo sends them 200 at a time. for ( $page = 0; $page < 5; $page++ ) { $result = Leelo_Api::get( '/voices?locale=' . rawurlencode( $locale ) . '&limit=200' . ( '' !== $after ? '&after=' . rawurlencode( $after ) : '' ) ); if ( is_wp_error( $result ) ) { break; } if ( isset( $result['data'] ) && is_array( $result['data'] ) ) { $voices = array_merge( $voices, $result['data'] ); } $after = isset( $result['next'] ) && is_string( $result['next'] ) ? $result['next'] : ''; if ( '' === $after ) { $complete = true; break; } } // Website audio uses the catalogue's Core, Pro and Ultra voices (Leelo refuses the others). $voices = array_values( array_filter( $voices, function ( $v ) { return is_array( $v ) && ! empty( $v['id'] ) && empty( $v['own'] ) && (int) ( $v['credits_per_word'] ?? 0 ) <= 3; } ) ); // By name; the same name always in the same order, so "Emma (2)" stays the same voice. usort( $voices, function ( $a, $b ) { $by_name = strcasecmp( (string) ( $a['name'] ?? '' ), (string) ( $b['name'] ?? '' ) ); return $by_name ? $by_name : strcmp( (string) $a['id'], (string) $b['id'] ); } ); if ( $voices ) { // A list cut short (Leelo out of reach half-way) is asked for again sooner. set_transient( $key, $voices, $complete ? HOUR_IN_SECONDS : 5 * MINUTE_IN_SECONDS ); } return $voices; } /** * One part of the voice list, labelled so that no two voices read the same: name, gender, tier, * how it sounds where Leelo says, and for a voice from another language, that language. * * @param array $voices The voices, from voices(). * @param string $locale The language chosen. * @param array $locales Language names by code. * @param bool $native The language's own voices (true) or the others that also read it. * @return array[] Each with id, label and sample (an https address, or ''). */ private static function voice_options( $voices, $locale, $locales, $native ) { $tier = array( 'standard' => __( 'Core', 'leelo' ), 'premium' => __( 'Pro', 'leelo' ), 'hd' => __( 'Ultra', 'leelo' ), ); $out = array(); $seen = array(); foreach ( $voices as $v ) { $home = (string) ( $v['locale'] ?? '' ); if ( ( $home === $locale ) !== $native ) { continue; } $parts = array( (string) ( $v['name'] ?? '' ), ucfirst( (string) ( $v['gender'] ?? '' ) ), $tier[ $v['quality'] ?? '' ] ?? (string) ( $v['quality'] ?? '' ), (string) ( $v['description'] ?? '' ), $native ? '' : self::language_name( $home, $locales ), ); $label = implode( ' · ', array_filter( $parts, 'strlen' ) ); $seen[ $label ] = ( $seen[ $label ] ?? 0 ) + 1; if ( $seen[ $label ] > 1 ) { $label .= ' (' . $seen[ $label ] . ')'; } $sample = (string) ( $v['sample_url'] ?? '' ); $out[] = array( 'id' => (string) $v['id'], 'label' => $label, 'sample' => 0 === strpos( $sample, 'https://' ) ? $sample : '', ); } return $out; } /** A language's name from its code ("en-PH" → "English (Philippines)"), or the code. */ private static function language_name( $code, $locales ) { if ( isset( $locales[ $code ] ) ) { return $locales[ $code ]; } if ( function_exists( 'locale_get_display_name' ) ) { $name = locale_get_display_name( $code, 'en' ); if ( $name ) { return $name; } } return $code; } /** Languages to pick a voice in: the site's own first. */ private static function locales() { $list = array( 'en-US' => 'English (US)', 'en-GB' => 'English (UK)', 'en-AU' => 'English (Australia)', 'en-CA' => 'English (Canada)', 'es-ES' => 'Spanish (Spain)', 'es-MX' => 'Spanish (Mexico)', 'fr-FR' => 'French (France)', 'fr-CA' => 'French (Canada)', 'de-DE' => 'German', 'it-IT' => 'Italian', 'pt-BR' => 'Portuguese (Brazil)', 'pt-PT' => 'Portuguese (Portugal)', 'nl-NL' => 'Dutch', 'nl-BE' => 'Flemish', 'sv-SE' => 'Swedish', 'da-DK' => 'Danish', 'nb-NO' => 'Norwegian', 'fi-FI' => 'Finnish', 'pl-PL' => 'Polish', 'cs-CZ' => 'Czech', 'ro-RO' => 'Romanian', 'hu-HU' => 'Hungarian', 'el-GR' => 'Greek', 'tr-TR' => 'Turkish', 'ru-RU' => 'Russian', 'uk-UA' => 'Ukrainian', 'sr-Latn-RS' => 'Serbian', 'hr-HR' => 'Croatian', 'ar-SA' => 'Arabic (Saudi)', 'ar-EG' => 'Arabic (Egypt)', 'he-IL' => 'Hebrew', 'hi-IN' => 'Hindi', 'ja-JP' => 'Japanese', 'ko-KR' => 'Korean', 'zh-CN' => 'Chinese (Mandarin)', 'id-ID' => 'Indonesian', 'vi-VN' => 'Vietnamese', 'th-TH' => 'Thai', ); $own = str_replace( '_', '-', get_locale() ); if ( isset( $list[ $own ] ) ) { $list = array( $own => $list[ $own ] ) + $list; } return $list; } public static function page() { if ( ! current_user_can( 'manage_options' ) ) { return; } echo '

' . esc_html__( 'Leelo – Text to Speech & Listen to this Article', 'leelo' ) . '

'; self::notice(); if ( ! Leelo_Settings::connected() ) { echo '

' . esc_html__( 'Give every post a "listen to this article" player, read in a natural voice. Connect this site to your Leelo account to start. Automatic audio for your posts comes with a monthly plan, and you can give one post audio free to hear it first.', 'leelo' ) . '

'; echo '

' . esc_html__( 'Connect to Leelo', 'leelo' ) . '

'; echo '

' . esc_html__( 'No Leelo account yet? You can create one on the next page.', 'leelo' ) . '

'; return; } $site = self::site(); if ( is_wp_error( $site ) ) { echo '

' . esc_html( $site->get_error_message() ) . '

'; if ( ! Leelo_Settings::connected() ) { echo '

' . esc_html__( 'Connect to Leelo again', 'leelo' ) . '

'; } echo ''; return; } $s = isset( $site['site'] ) ? $site['site'] : array(); $account = isset( $site['account'] ) ? $site['account'] : array(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- which language's voices to list: it only changes the view. $locale = isset( $_GET['leelo_locale'] ) ? sanitize_text_field( wp_unslash( $_GET['leelo_locale'] ) ) : ( ! empty( $s['voice_locale'] ) ? $s['voice_locale'] : str_replace( '_', '-', get_locale() ) ); $locales = self::locales(); if ( ! isset( $locales[ $locale ] ) ) { $locale = 'en-US'; } // The account. $plan = ! empty( $account['website_plan'] ); echo '

' . esc_html__( 'Your account', 'leelo' ) . '

'; if ( $plan ) { printf( /* translators: 1: plan status, 2: credits left, 3: site name */ esc_html__( 'Website audio: %1$s · %2$s credits left · Connected as %3$s.', 'leelo' ), '' . esc_html__( 'on (monthly plan)', 'leelo' ) . '', esc_html( number_format_i18n( (int) ( $account['credits_left'] ?? 0 ) ) ), esc_html( $s['name'] ?? home_url() ) ); } else { // Without a plan there are no website credits to count: only the free post, said below. printf( /* translators: 1: plan status, 2: site name */ esc_html__( 'Website audio: %1$s · Connected as %2$s.', 'leelo' ), '' . esc_html__( 'needs a monthly plan', 'leelo' ) . '', esc_html( $s['name'] ?? home_url() ) ); } echo '

'; if ( ! $plan ) { echo '

' . esc_html( $account['why_not'] ?? __( 'Website audio comes with a monthly plan.', 'leelo' ) ) . '

'; if ( ! empty( $account['free_post_available'] ) && ! empty( $s['voice_id'] ) ) { echo '

'; wp_nonce_field( 'leelo_free_post' ); echo ''; submit_button( __( 'Hear one post free', 'leelo' ), 'secondary', 'submit', false ); echo '
'; } elseif ( ! empty( $account['free_post_available'] ) ) { echo esc_html__( 'Choose a voice below first, then you can hear one post free.', 'leelo' ) . '
'; } echo '' . esc_html__( 'Choose a monthly plan', 'leelo' ) . ''; echo '

' . esc_html__( 'After choosing a plan, come back to this page: new posts then get audio automatically.', 'leelo' ) . '

'; } // Settings. $voices = self::voices( $locale ); echo '
'; wp_nonce_field( 'leelo_save' ); echo ''; echo '

' . esc_html__( 'Voice and player', 'leelo' ) . '

'; echo ''; echo ''; $theme = $s['theme'] ?? 'light'; echo ''; echo ''; $position = Leelo_Settings::get( 'position' ); echo ''; echo ''; submit_button( __( 'Save settings', 'leelo' ) ); echo '
'; // Older posts: part of a monthly plan. echo '

' . esc_html__( 'Older posts', 'leelo' ) . '

'; if ( ! $plan ) { echo '

' . esc_html__( 'With a monthly plan, your published posts can get audio too. You see the cost before anything is spent.', 'leelo' ) . '

'; } else { $waiting = get_option( Leelo_Narration::BACKLOG, array() ); $estimate = get_transient( 'leelo_estimate_' . get_current_user_id() ); if ( is_array( $waiting ) && $waiting ) { /* translators: %d: number of posts */ echo '

' . esc_html( sprintf( _n( '%d older post is waiting for its audio.', '%d older posts are waiting for their audio, a few every five minutes.', count( $waiting ), 'leelo' ), count( $waiting ) ) ) . '

'; } elseif ( is_array( $estimate ) ) { echo '

'; printf( /* translators: 1: number of posts, 2: credits, 3: credits left */ esc_html__( '%1$s posts without audio would cost about %2$s credits. You have %3$s.', 'leelo' ), esc_html( number_format_i18n( count( $estimate['ids'] ) ) ), '' . esc_html( number_format_i18n( $estimate['credits'] ) ) . '', esc_html( number_format_i18n( $estimate['left'] ) ) ); echo '

'; if ( $estimate['can'] ) { echo '
'; wp_nonce_field( 'leelo_backlog' ); echo ''; submit_button( $estimate['enough'] ? __( 'Make audio for these posts', 'leelo' ) : __( 'Start, newest posts first (stops when credits run out)', 'leelo' ), 'primary', 'submit', false ); echo '
'; } } else { echo '

' . esc_html__( 'Give your published posts audio too. You see the cost before anything is spent.', 'leelo' ) . '

'; echo '
'; wp_nonce_field( 'leelo_estimate' ); echo ''; submit_button( __( 'Check the cost', 'leelo' ), 'secondary', 'submit', false ); echo '
'; } } // Disconnect. echo '

' . esc_html__( 'Connection', 'leelo' ) . '

'; echo '
'; wp_nonce_field( 'leelo_disconnect' ); echo ''; submit_button( __( 'Disconnect', 'leelo' ), 'delete', 'submit', false ); echo '
'; } }