set_basename( false, __FILE__ ); } else { if ( !function_exists( 'aitts_fs' ) ) { // Create a helper function for easy SDK access. function aitts_fs() { global $aitts_fs; if ( !isset( $aitts_fs ) ) { // Include Freemius SDK. require_once __DIR__ . '/freemius/start.php'; $aitts_fs = fs_dynamic_init( array( 'id' => '14778', 'slug' => 'ai-text-to-speech', 'premium_slug' => 'ai-text-to-speech-pro', 'type' => 'plugin', 'public_key' => 'pk_29ce6983a9bad27c0fda5e4370067', 'is_premium' => false, 'premium_suffix' => 'Pro', 'has_addons' => false, 'has_paid_plans' => true, 'is_org_compliant' => true, 'menu' => array( 'slug' => 'ai-text-to-speech', 'first-path' => 'admin.php?page=ai-text-to-speech-settings', 'account' => true, 'support' => true, 'contact' => true, 'pricing' => true, 'addons' => false, ), 'is_live' => true, ) ); } return $aitts_fs; } // Init Freemius. aitts_fs(); // Signal that SDK was initiated. do_action( 'aitts_fs_loaded' ); } // Redirect the Freemius pricing page to the external pricing page add_action( 'admin_init', 'ai_tts_redirect_pricing_page' ); function ai_tts_redirect_pricing_page() { $page = ( isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '' ); if ( $page === 'ai-text-to-speech-pricing' ) { wp_safe_redirect( 'https://relywp.com/plugins/ai-text-to-speech/#pricing' ); exit; } } // Plugin version, used to bust the browser cache of scripts and styles define( 'AI_TTS_VERSION', '3.3.0' ); // Define the path for the uploads define( 'AI_TTS_UPLOAD_DIR', WP_CONTENT_DIR . '/uploads/ai-text-to-speech/' ); // Includes require_once plugin_dir_path( __FILE__ ) . 'inc/save.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/delete.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/attach.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/player.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/meta-box.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/options.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/admin-page.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/logs.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tts-files.php'; // Includes (Content Generation) require_once plugin_dir_path( __FILE__ ) . 'inc/content/generate.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/content/jobs.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/content/language.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/content/intro.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/content/replace/twitter.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/content/replace/numbers.php'; // Activation hook to create the upload directory register_activation_hook( __FILE__, 'ai_tts_create_upload_dir' ); function ai_tts_create_upload_dir() { if ( !file_exists( AI_TTS_UPLOAD_DIR ) ) { wp_mkdir_p( AI_TTS_UPLOAD_DIR ); } // Redirect to the settings page only once on activation update_option( 'ai_tts_do_activation_redirect', true ); } // Redirect to the settings page on activation add_action( 'admin_init', 'ai_tts_redirect' ); function ai_tts_redirect() { if ( get_option( 'ai_tts_do_activation_redirect', false ) ) { delete_option( 'ai_tts_do_activation_redirect' ); wp_safe_redirect( admin_url( 'admin.php?page=ai-text-to-speech-settings' ) ); exit; } } // Add settings link to plugins list add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'ai_tts_settings_link' ); function ai_tts_settings_link( $links ) { $settings_link = '' . esc_html__( 'Settings', 'ai-text-to-speech' ) . ''; array_unshift( $links, $settings_link ); $analytics_link = '' . esc_html__( 'Statistics', 'ai-text-to-speech' ) . ''; array_unshift( $links, $analytics_link ); return $links; } // Register the audio generation script (shared by the post editor and the Generator page) add_action( 'admin_enqueue_scripts', 'ai_tts_register_generate_script', 5 ); function ai_tts_register_generate_script() { wp_register_script( 'ai-tts-generate', plugin_dir_url( __FILE__ ) . 'js/generate.js', array('jquery'), AI_TTS_VERSION, true ); wp_localize_script( 'ai-tts-generate', 'aiTtsGenerateSettings', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'i18n' => array( 'generating' => __( 'Generating audio file...', 'ai-text-to-speech' ), 'progress' => __( 'Generating audio file (part %1$s of %2$s)...', 'ai-text-to-speech' ), 'saving' => __( 'Saving audio file...', 'ai-text-to-speech' ), 'timeout' => __( 'The server took too long to respond. Please ask your web host to increase the PHP max_execution_time and any server or proxy timeout limits (for example to 300 seconds), then try again.', 'ai-text-to-speech' ), 'serverError' => __( 'The server returned an error (HTTP %s). The Error Log on the plugin settings page may have more details.', 'ai-text-to-speech' ), 'invalid' => __( 'The server returned an invalid response.', 'ai-text-to-speech' ), 'network' => __( 'Could not connect to the server. Please check your internet connection and try again.', 'ai-text-to-speech' ), 'unknown' => __( 'Unknown error occurred.', 'ai-text-to-speech' ), ), ) ); } // Enqueue JavaScript Admin add_action( 'admin_enqueue_scripts', 'ai_tts_enqueue_scripts' ); function ai_tts_enqueue_scripts() { $screen = ( function_exists( 'get_current_screen' ) ? get_current_screen() : null ); // Only on post edit screens if ( !$screen || 'post' !== $screen->base ) { return; } // On all post type post edit screen global $post; $post_types_option = ai_tts_get_option( 'post_types' ); if ( 'all' !== $post_types_option ) { $the_types = ai_tts_get_option( 'post_types_to_enable' ); if ( !is_array( $the_types ) ) { $the_types = array(); } $post_type = ( isset( $post->post_type ) ? $post->post_type : '' ); if ( !$post_type ) { return; } if ( !in_array( $post_type, $the_types, true ) ) { return; } } // Ensure media modal is available for selecting/uploading audio if ( function_exists( 'wp_enqueue_media' ) ) { wp_enqueue_media(); } wp_enqueue_script( 'ai-tts-script', plugin_dir_url( __FILE__ ) . 'js/script.js', array('jquery', 'ai-tts-generate'), AI_TTS_VERSION, true ); // The cost estimate and automatic generation use the block editor's data store if ( !$screen->is_block_editor() ) { return; } wp_enqueue_script( 'ai-tts-post-script', plugin_dir_url( __FILE__ ) . 'js/post.js', array('wp-data'), AI_TTS_VERSION, true ); } // Enqueue JavaScript on Settings Page add_action( 'admin_enqueue_scripts', 'ai_tts_enqueue_scripts_settings' ); function ai_tts_enqueue_scripts_settings() { $page = ( isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '' ); // Only on the plugin settings page if ( !$page || !in_array( $page, array('ai-text-to-speech', 'ai-text-to-speech-settings'), true ) ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'ai-tts-settings-script', plugin_dir_url( __FILE__ ) . 'js/settings.js', array('jquery', 'wp-color-picker'), AI_TTS_VERSION, true ); } // Enqueue Admin Posts CSS add_action( 'admin_enqueue_scripts', 'ai_tts_enqueue_posts_styles' ); function ai_tts_enqueue_posts_styles() { // On all post type post edit screen global $post; $post_types_option = ai_tts_get_option( 'post_types' ); if ( 'all' !== $post_types_option ) { $the_types = ai_tts_get_option( 'post_types_to_enable' ); if ( !is_array( $the_types ) ) { $the_types = array(); } $post_type = ( isset( $post->post_type ) ? $post->post_type : '' ); if ( !$post_type ) { return; } if ( !in_array( $post_type, $the_types, true ) ) { return; } } if ( !is_object( $post ) ) { return; } wp_enqueue_style( 'ai-tts-style', plugin_dir_url( __FILE__ ) . 'css/post.css', array(), AI_TTS_VERSION ); } // Enqueue CSS admin settings page add_action( 'admin_enqueue_scripts', 'ai_tts_enqueue_styles_admin' ); function ai_tts_enqueue_styles_admin() { $page = ( isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '' ); // Only on the plugin admin pages if ( !$page || !in_array( $page, array( 'ai-text-to-speech', 'ai-text-to-speech-settings', 'ai-text-to-speech-api-logs', 'ai-text-to-speech-stats', 'ai-text-to-speech-files' ), true ) ) { return; } wp_enqueue_style( 'ai-tts-style-admin', plugin_dir_url( __FILE__ ) . 'css/settings.css', array(), AI_TTS_VERSION ); } }