Plugin Directory

Changeset 2364671


Ignore:
Timestamp:
08/19/2020 08:27:13 AM (6 years ago)
Author:
edge226
Message:

add the option to put the widget after the title

Location:
audiate-me/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • audiate-me/trunk/audiate.php

    r2335625 r2364671  
    88 * Plugin URI: https://www.audiate.me
    99 * Description: Transform your content into audio to reach a larger audience with our Text-to-Speech widget.
    10  * Version: 1.1.1
     10 * Version: 1.2
    1111 * Author: Audiate.Me
    1212 * License: GPLv2 or later
  • audiate-me/trunk/includes/audiate-admin.php

    r2335625 r2364671  
    8080
    8181        add_settings_field(
    82             'widget_id_0', // id
    83             'Widget id (Deprecated)', // title
    84             array( $this, 'widget_id_0_callback' ), // callback
     82            'position_4', // id
     83            'Widget Placement', // title
     84            array( $this, 'position_4_callback' ), // callback
    8585            'audiate-admin', // page
    8686            'audiate_setting_section' // section
    8787        );
     88
    8889    }
    8990
    9091    public function audiate_sanitize($input) {
    9192        $sanitary_values = array();
    92         if ( isset( $input['widget_id_0'] ) ) {
    93             $sanitary_values['widget_id_0'] = sanitize_text_field( $input['widget_id_0'] );
    94         }
    9593
    9694        if ( isset( $input['show_on_all_posts_1'] ) ) {
    97             $sanitary_values['show_on_all_posts_1'] = $input['show_on_all_posts_1'];
     95            $sanitary_values['show_on_all_posts_1'] = sanitize_text_field($input['show_on_all_posts_1']);
    9896        }
    9997
     
    104102
    105103        if ( isset( $input['show_on_all_pages_3'] ) ) {
    106             $sanitary_values['show_on_all_pages_3'] = $input['show_on_all_pages_3'];
     104            $sanitary_values['show_on_all_pages_3'] = sanitize_text_field($input['show_on_all_pages_3']);
     105        }
     106
     107        if ( isset( $input['position_4'] ) ) {
     108            $sanitary_values['position_4'] = sanitize_text_field($input['position_4']);
    107109        }
    108110
     
    112114    public function audiate_section_info() {
    113115
    114     }
    115 
    116     public function widget_id_0_callback() {
    117         printf(
    118             '<input class="regular-text" type="text" name="audiate_option_name[widget_id_0]" id="widget_id_0" value="%s">',
    119             isset( $this->audiate_options['widget_id_0'] ) ? esc_attr( $this->audiate_options['widget_id_0']) : ''
    120         );
    121116    }
    122117
     
    139134    }
    140135
     136    public function position_4_callback() {
     137        ?> <select name="audiate_option_name[position_4]" id="position_4">
     138            <?php $selected = (isset( $this->audiate_options['position_4'] ) && $this->audiate_options['position_4'] === 'before_content') ? 'selected' : '' ; ?>
     139            <option value="before_content" <?php echo $selected; ?>>Before Content</option>
     140            <?php $selected = (isset( $this->audiate_options['position_4'] ) && $this->audiate_options['position_4'] === 'after_title') ? 'selected' : '' ; ?>
     141            <option value="after_title" <?php echo $selected; ?>>After Title</option>
     142        </select> <?php
     143    }
     144
    141145    public function widget_code_2_callback() {
    142146        printf(
  • audiate-me/trunk/includes/audiate-widget.php

    r2335603 r2364671  
    9999    public function add_widget()
    100100    {
    101         if(isset($this->options['widget_code_2']) || isset($this->options['widget_id_0'])) {
    102             add_filter('the_content', array($this, 'add_code_to_post_title'), 0 );
     101        if(isset($this->options['widget_code_2'])) {
     102            if(!isset($this->options['position_4']) || $this->options['position_4'] === 'before_content') {
     103                add_filter('the_content', function( $content )  {
     104                    return $this->add_code_to_post_content( $content, false );
     105                }, 0 );
     106            }
     107            else if ($this->options['position_4'] === 'after_title') {
     108                add_filter('the_title', function( $content )  {
     109                    return $this->add_code_to_post_content( $content, true );
     110                }, 0 );
     111            }
     112
     113
    103114            add_shortcode('audiate-widget', 'getShortCode');
    104115        }
     
    108119        if($this->options['widget_code_2']) {
    109120            $ret =  '<div class="audiate-widget">' . $this->options['widget_code_2'] . '</div>';
    110         } else {
    111             $ret = '<div class="audiate-widget"><ins data-ea data-ea-id="'.$this->options['widget_id_0'].'"></ins>
    112 <script async src=\'https://cdn.audiate.me/audio/widgets/Loader.js\'></script></div>';
    113121        }
    114122        return $ret;
    115123    }
    116124
     125
    117126    /*
    118127    * Add the widget to posts before the post content
    119128    */
    120     public function add_code_to_post_title($content) {
     129    public function add_code_to_post_content($content, $isAfterContent) {
    121130
    122131        $allowedPostTypes = array('post', 'page');
     
    131140
    132141            ) {
    133                     return $widget . $content;
     142                    return AudiateWidget::stitchWidget($content , $widget, $isAfterContent);
    134143            }
    135144
     
    139148
    140149            if (isset($showOnPost) && $showOnPost === 'on') {
    141                 return $widget . $content;
     150                return AudiateWidget::stitchWidget($content , $widget, $isAfterContent);
    142151            }
    143152
     
    147156    }
    148157
     158    /**
     159     * @param string $content
     160     * @param boolean $isAfterContent
     161     */
     162    static function stitchWidget(  $content, $widget, $isAfterContent ) {
     163        if($isAfterContent) {
     164            return $content . $widget;
     165        } else {
     166            return $widget . $content;
     167        }
     168    }
     169
    149170}
  • audiate-me/trunk/readme.txt

    r2337868 r2364671  
    66License URI: http://www.gnu.org/licenses/gpl-2.0.html
    77Tested up to: 5.4
    8 Stable tag: 1.1.1
     8Stable tag: 1.2
    99
    1010Elevate Your Content with Audio. Transform your content into audio to reach a larger audience with our Text-to-Speech widget.
     
    2323HOW DOES IT WORK?
    24241. Create a free account at: https://audiate.me
    25 2. Edit your user profile and add your site\'s URL.
     252. Edit your user profile and add your site\'s domain.
    26263. Create a new widget
    2727
     
    30302. Go to https://Audiate.me website, login, navigate to 'Create Widgets' page and generate a widget code.
    31313. Copy the widget code and paste it in your WordPress in settings -> audiate
    32 4. Choose whether to show the widget on all posts or only on selected ones.
     324. Choose whether to show the widget on all posts/pages or only on selected ones.
     335. Select the widget position, before the content or after the title
    3334
    3435SHORT CODE
    3536Another way to implement the widget in your posts and pages is to use Wordpress shortcode.
    36 Simply paste [audiate-widget] in your text.
     37Simply paste [audiate-widget] in your text or use it in your templates.
Note: See TracChangeset for help on using the changeset viewer.