Plugin Directory

Changeset 3483107


Ignore:
Timestamp:
03/15/2026 01:18:49 PM (3 weeks ago)
Author:
reinventwp
Message:

Deploying version 2.6.9 - gutenberg block support

Location:
natural-text-to-speech/trunk
Files:
19 added
15 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • natural-text-to-speech/trunk/components/implement-plugin.php

    r3481905 r3483107  
    3434
    3535add_filter( 'the_content', 'natuteto_append_shortcode_to_content' );
     36
     37/**
     38 * Return the default shortcode attributes for the TTS player.
     39 *
     40 * @return array
     41 */
     42function natuteto_get_shortcode_default_attributes() {
     43    return array(
     44        'description'          => null,
     45        'lang'                 => null,
     46        'auto-embed'           => null,
     47        'target-tts-direction' => null,
     48        'target-tts-selector'  => null,
     49        'src'                  => null,
     50        'only-show'            => null,
     51        'trigger-play'         => null,
     52    );
     53}
     54
     55/**
     56 * Shared renderer for shortcode and Gutenberg block output.
     57 *
     58 * @param array       $atts Shortcode-compatible attributes.
     59 * @param string|null $content Optional JSON config payload.
     60 * @return string
     61 */
     62function natuteto_render_tts_embed_markup( $atts, $content = null ) {
     63    global $post;
     64
     65    $default_attribute = natuteto_get_shortcode_default_attributes();
     66    $atts              = shortcode_atts( $default_attribute, $atts );
     67
     68    $post_categories = array();
     69
     70    if ( $post instanceof WP_Post ) {
     71        $post_categories = wp_get_post_terms(
     72            $post->ID,
     73            'category',
     74            array( 'fields' => 'slugs' )
     75        );
     76    }
     77
     78    $attributes = '';
     79    foreach ( $default_attribute as $key => $default ) {
     80        if ( ! empty( $atts[ $key ] ) ) {
     81            $data_key    = esc_attr( "data-$key" );
     82            $data_val    = esc_attr( $atts[ $key ] );
     83            $attributes .= " {$data_key}=\"{$data_val}\"";
     84        }
     85    }
     86
     87    if ( $content ) {
     88        $config = json_decode( natuteto_normalize_json_string_for_decode( $content ), true );
     89
     90        if ( json_last_error() !== JSON_ERROR_NONE ) {
     91            return "<div class='natural-tts-error'>Invalid JSON in shortcode</div>";
     92        }
     93    } else {
     94        $config = natuteto_get_plugin_config();
     95    }
     96
     97    if ( $config && isset( $config['exclude_from_post_categories'] ) ) {
     98        $excluded = (array) $config['exclude_from_post_categories'];
     99
     100        if ( array_intersect( $excluded, $post_categories ) ) {
     101            return '';
     102        }
     103    }
     104
     105    if ( ! $content ) {
     106        return sprintf(
     107            '<div class="' . NATUTETO_SHORTCODE_CLASS . '"%s>🔊</div>',
     108            $attributes
     109        );
     110    }
     111
     112    $encoded = esc_attr( wp_json_encode( $config ) );
     113
     114    return sprintf(
     115        '<div class="' . NATUTETO_SHORTCODE_CLASS . '" %s data-config="%s">🔊</div>',
     116        $attributes,
     117        $encoded
     118    );
     119}
    36120
    37121/**
     
    78162    }
    79163
    80     // Read more about shortcode attributes: https://wordpress.org/plugins/natural-text-to-speech.
    81     $default_attribute = array(
    82         'description'          => null,
    83         'lang'                 => null,
    84         'auto-embed'           => null,
    85         'target-tts-direction' => null,
    86         'target-tts-selector'  => null,
    87         'src'                  => null,
    88         'only-show'            => null,
    89         'trigger-play'         => null,
    90     );
    91 
    92     $atts = shortcode_atts( $default_attribute, $atts );
    93 
    94     // Category exclusion logic.
    95     $post_categories = array();
    96 
    97     if ( $post instanceof WP_Post ) {
    98         $post_categories = wp_get_post_terms(
    99             $post->ID,
    100             'category',
    101             array( 'fields' => 'slugs' )
    102         );
    103     }
    104 
    105     // Build HTML attributes.
    106     $attributes = '';
    107     foreach ( $default_attribute as $key => $default ) {
    108         if ( ! empty( $atts[ $key ] ) ) {
    109             $data_key    = esc_attr( "data-$key" );
    110             $data_val    = esc_attr( $atts[ $key ] );
    111             $attributes .= " {$data_key}=\"{$data_val}\"";
    112         }
    113     }
    114 
    115     if ( $content ) {
    116         $config = json_decode( natuteto_normalize_json_string_for_decode( $content ), true );
    117 
    118         if ( json_last_error() !== JSON_ERROR_NONE ) {
    119             return "<div class='natural-tts-error'>Invalid JSON in shortcode</div>";
    120         }
    121     } else {
    122         $config = natuteto_get_plugin_config();
    123     }
    124 
    125     if ( $config ) {
    126         if ( isset( $config['exclude_from_post_categories'] ) ) {
    127             $excluded = (array) $config['exclude_from_post_categories'];
    128 
    129             // If any category matches, don't render the shortcode.
    130             if ( array_intersect( $excluded, $post_categories ) ) {
    131                 return ''; // skip rendering.
    132             }
    133         }
    134     }
    135 
    136     if ( ! $content ) {
    137         return sprintf(
    138             '<div class="' . NATUTETO_SHORTCODE_CLASS . '"%s>🔊</div>',
    139             $attributes
    140         );
    141     }
    142 
    143     $encoded = esc_attr( wp_json_encode( $config ) );
    144 
    145     return sprintf(
    146         '<div class="' . NATUTETO_SHORTCODE_CLASS . '" %s data-config="%s">🔊</div>',
    147         $attributes,
    148         $encoded
    149     );
     164    return natuteto_render_tts_embed_markup( $atts, $content );
    150165}
    151166
     
    192207    $auto_embed_types = isset( $config['auto_add_for_post_types'] ) ? (array) $config['auto_add_for_post_types'] : array();
    193208    if ( in_array( $post->post_type, $auto_embed_types, true ) ) {
     209        return true;
     210    }
     211
     212    if ( function_exists( 'has_block' ) && has_block( NATUTETO_BLOCK_NAME, $post ) ) {
    194213        return true;
    195214    }
  • natural-text-to-speech/trunk/constants.php

    r3481905 r3483107  
    6969
    7070const NATUTETO_SHORTCODE_CLASS = 'natural-tts';
     71
     72const NATUTETO_BLOCK_NAME = NATUTETO_PLUGIN_PREFIX . '/player';
    7173
    7274/**
  • natural-text-to-speech/trunk/natural-text-to-speech.php

    r3481905 r3483107  
    44 * Plugin URI:  https://wordpress.org/plugins/natural-text-to-speech
    55 * Description: Read aloud your posts using natural, human-like voices and highlights sentences and words as they are spoken. Available in Free and Pro versions! Start now with 20,000 free characters / month.
    6  * Version:     2.6.8
     6 * Version:     2.6.9
    77 * Author:      Reinvent WP
    88 * Author URI:  https://reinventwp.com
     
    2020 * serious issues with the options, so no if ( ! defined() ).}}
    2121 */
    22 define( 'NATUTETO_VERSION', '2.6.8' );
     22define( 'NATUTETO_VERSION', '2.6.9' );
    2323
    2424if ( ! defined( 'NATUTETO_PLUGIN_DIR' ) ) {
     
    109109require_once plugin_dir_path( __FILE__ ) . 'components/utils.php';
    110110
     111// Cache and optimizer compatibility hooks.
     112require_once plugin_dir_path( __FILE__ ) . 'components/cache-compat.php';
     113
     114// Gutenberg block integration.
     115require_once plugin_dir_path( __FILE__ ) . 'components/block.php';
     116
    111117// Implementation of the plugin to the post.
    112118require_once plugin_dir_path( __FILE__ ) . 'components/implement-plugin.php';
  • natural-text-to-speech/trunk/readme.txt

    r3481905 r3483107  
    44Requires at least: 5.0
    55Tested up to: 6.9
    6 Stable tag: 2.6.8
    7 Version: 2.6.8
     6Stable tag: 2.6.9
     7Version: 2.6.9
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    1818Designed as a flexible multi-provider TTS bridge, Reinvent WP Text to Speech (formerly Natural Text To Speech) allows you to switch voice engines without changing plugins. Generate audio automatically, export posts to MP3, and enable sentence-by-sentence playback with intelligent caching.
    1919
    20 Ideal for news sites, educational platforms, accessibility-focused websites, and agencies managing multiple client installations.
     20Ideal for news sites, educational platforms, accessibility-focused websites, agencies managing multiple client installations, and content-heavy WooCommerce stores.
    2121
    2222**Simple, Powerful Audio: Install now and see the play button on your posts in seconds!**
     
    6969* **Marketing** - Create compelling voice ads and audio clips from your written marketing copy.
    7070* **SEO Optimization** - Increase time-on-site by giving users the option to listen to audio.
     71* **WooCommerce Content** - Add listenable audio to product descriptions and other WooCommerce product content.
    7172
    7273=== Supported Languages ===
     
    313314
    314315Yes. The plugin inserts its player with a shortcode, so it will show on top of your posts. No template editing is required.
     316
     317= Does it work with WooCommerce? =
     318
     319Yes. You can use Reinvent WP Text To Speech with WooCommerce product content because the plugin supports custom post types, including products, alongside posts and pages.
    315320
    316321= Can I customise the player’s colors, size, or position? =
     
    420425  * Advanced Analytics: Completion Rate Metrics
    421426  * Audio Schema Markup (SEO)
     427  * Add the player with the Gutenberg block editor
    422428  * Any suggestion? [fill this form](https://reinventwp.com/feedback)
    423429
     
    485491== Changelog ==
    486492
     493= 2.6.9 =
     494* Add the player with the Gutenberg block editor
     495
    487496= 2.6.8 =
    488497* Audio Schema Markup (SEO)
Note: See TracChangeset for help on using the changeset viewer.