plugin_name = $plugin_name;
$this->version = $version;
}
/**
* WordPress filter, responsible for adding audio play functionality for posts.
*
* @since 1.0.0
* @param string $content The content of the new post.
*/
public function amazon_polly_filter( $content ) {
if ( get_post_meta( $GLOBALS['post']->ID, 'amazon_polly_enable', true ) === '1' ) {
$audio_location = get_post_meta( $GLOBALS['post']->ID, 'amazon_polly_audio_link_location', true );
$selected_autoplay = get_option( 'amazon_polly_autoplay' );
$player_label = get_option( 'amazon_polly_player_label' );
// Checks if this is single post view and if there is autoplay options selected.
if ( is_singular() && ! empty( $selected_autoplay ) ) {
$autoplay = 'autoplay';
} else {
$autoplay = '';
}
if ( is_singular() ) {
$image = plugin_dir_url( __FILE__ ) . 'images/Voiced_by_Amazon_Polly_EN.png';
$voice_by_part = '
';
} else {
$voice_by_part = '';
}
$original_content = $content;
// Removing Amazon Polly special tags.
$original_content = preg_replace("/-AMAZONPOLLY-ONLYAUDIO-START-[\S\s]*?-AMAZONPOLLY-ONLYAUDIO-END-/", "", $original_content);
$original_content = str_replace( '-AMAZONPOLLY-ONLYWORDS-START-', '', $original_content );
$original_content = str_replace( '-AMAZONPOLLY-ONLYWORDS-END-', '', $original_content );
$new_content = '
|
' . $player_label . '
' . $voice_by_part . '
|
';
$selected_position = get_option( 'amazon_polly_position' );
if ( strcmp( $selected_position, 'Do not show' ) === 0 ) {
$content = $original_content;
} elseif ( strcmp( $selected_position, 'After post' ) === 0 ) {
$content = $original_content . $new_content;
} else {
$content = $new_content . $original_content;
}
}//end if
// Returns the content.
return $content;
}
/**
* Register the stylesheets for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Amazonpolly_Loader as all of the hooks are defined
* in that particular class.
*
* The Amazonpolly_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/amazonpolly-public.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Amazonpolly_Loader as all of the hooks are defined
* in that particular class.
*
* The Amazonpolly_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/amazonpolly-public.js', array( 'jquery' ), $this->version, false );
}
/**
* Adds customizer controls for the Podcast Feature.
*
* @since 1.0.0
* @param object $wp_customize Instance of the WP Customize Manager.
*/
public function customize_register( $wp_customize ) {
$wp_customize->add_section(
'amazonpolly', array(
'title' => __( 'Amazon Polly', 'amazonpolly' ),
'priority' => 30,
)
);
$wp_customize->add_setting(
'amazon_polly_podcast_icon', array(
'default' => 'image.jpg',
'capability' => 'edit_theme_options',
'type' => 'option',
)
);
$wp_customize->add_setting(
'amazon_polly_podcast_email', array(
'default' => '',
'capability' => 'edit_theme_options',
'type' => 'option',
)
);
$wp_customize->add_setting(
'amazon_polly_podcast_category', array(
'default' => 'News & Politics',
'capability' => 'edit_theme_options',
'type' => 'option',
)
);
$wp_customize->add_setting(
'amazon_polly_podcast_explicit', array(
'default' => 'no',
'capability' => 'edit_theme_options',
'type' => 'option',
)
);
$wp_customize->add_control(
new WP_Customize_Cropped_Image_Control(
$wp_customize, 'podcast_icon', array(
'settings' => 'amazon_polly_podcast_icon',
'section' => 'amazonpolly',
'label' => __( 'iTunes image' ),
'flex_width' => false,
'flex_height' => false,
'width' => 1400,
'height' => 1400,
)
)
);
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize, 'podcast_email', array(
'settings' => 'amazon_polly_podcast_email',
'section' => 'amazonpolly',
'label' => __( 'iTunes contact email' ),
'flex_width' => false,
'flex_height' => false,
'width' => 1400,
'height' => 1400,
)
)
);
$wp_customize->add_control(
'amazon_polly_podcast_category', array(
'type' => 'select',
'priority' => 10,
'section' => 'amazonpolly',
'label' => __( 'iTunes category' ),
'choices' => array(
'Arts' => 'Arts',
'Business' => 'Business',
'Comedy' => 'Comedy',
'Education' => 'Education',
'Games & Hobbies' => 'Games & Hobbies',
'Government & Organizations' => 'Government & Organizations',
'Health' => 'Health',
'Kids' => 'Kids',
'Music' => 'Music',
'News & Politics' => 'News & Politics',
'Religion' => 'Religion',
'Science & Medicine' => 'Science & Medicine',
'Society & Culture' => 'Society & Culture',
'Sports & Recreation' => 'Sports & Recreation',
'Technology' => 'Technology',
'TV & Film' => 'TV & Film',
),
)
);
$wp_customize->add_control(
'amazon_polly_podcast_explicit', array(
'type' => 'select',
'priority' => 10,
'section' => 'amazonpolly',
'label' => __( 'iTunes explicit content' ),
'choices' => array(
'yes' => 'Yes',
'no' => 'No',
),
)
);
}
}