public function amazon_polly_register_settings()

in admin/class-amazonpolly-admin.php [308:463]


	public function amazon_polly_register_settings() {

		// ************************************************* *
		// ***************** GENERAL SECTION **************** *
		add_settings_section( 'amazon_polly_general', __( 'General', 'amazonpolly' ), array( $this, 'amazon_polly_general_cb' ), $this->plugin_name );
		add_settings_field( 'amazon_polly_access_key', __( 'AWS access key:', 'amazonpolly' ), array( $this, 'amazon_polly_access_key_cb' ), $this->plugin_name, 'amazon_polly_general', array( 'label_for' => 'amazon_polly_access_key' ) );
		add_settings_field( 'amazon_polly_secret_key', __( 'AWS secret key:', 'amazonpolly' ), array( $this, 'amazon_polly_secret_key_cb' ), $this->plugin_name, 'amazon_polly_general', array( 'label_for' => 'amazon_polly_secret_key' ) );
		add_settings_field( 'amazon_polly_region', __( 'AWS Region:', 'amazonpolly' ), array( $this, 'amazon_polly_region_cb' ), $this->plugin_name, 'amazon_polly_general', array( 'label_for' => 'amazon_polly_region' ) );

		// ************************************************* *
		// ***************** PLAYER SECTION **************** *
		add_settings_section( 'amazon_polly_playersettings', __( 'Player settings', 'amazonpolly' ), array( $this, 'amazon_polly_playersettings_cb' ), $this->plugin_name );
		add_settings_field( 'amazon_polly_position', __( 'Player position:', 'amazonpolly' ), array( $this, 'amazon_polly_position_cb' ), $this->plugin_name, 'amazon_polly_playersettings', array( 'label_for' => 'amazon_polly_position' ) );
		add_settings_field( 'amazon_polly_player_label', __( 'Player label:', 'amazonpolly' ), array( $this, 'amazon_polly_player_label_cb' ), $this->plugin_name, 'amazon_polly_playersettings', array( 'label_for' => 'amazon_polly_player_label' ) );
		add_settings_field( 'amazon_polly_defconf', __( 'New post default:', 'amazonpolly' ), array( $this, 'amazon_polly_defconf_cb' ), $this->plugin_name, 'amazon_polly_playersettings', array( '' => 'amazon_polly_defconf' ) );
		add_settings_field( 'amazon_polly_autoplay', __( 'Autoplay:', 'amazonpolly' ), array( $this, 'amazon_polly_autoplay_cb' ), $this->plugin_name, 'amazon_polly_playersettings', array( 'label_for' => 'amazon_polly_autoplay' ) );

		// ************************************************* *
		// ************* POLLY SETTINGS SECTION ************ *
		add_settings_section( 'amazon_polly_pollysettings', __( 'Amazon Polly settings', 'amazonpolly' ), array( $this, 'amazon_polly_pollysettings_cb' ), $this->plugin_name );
		add_settings_field( 'amazon_polly_sample_rate', __( 'Sample rate:', 'amazonpolly' ), array( $this, 'amazon_polly_sample_rate_cb' ), $this->plugin_name, 'amazon_polly_pollysettings', array( 'label_for' => 'amazon_polly_sample_rate' ) );
		add_settings_field( 'amazon_polly_voice_id', __( 'Voice name:', 'amazonpolly' ), array( $this, 'amazon_polly_voice_id_cb' ), $this->plugin_name, 'amazon_polly_pollysettings', array( 'label_for' => 'amazon_polly_voice_id' ) );
		add_settings_field( 'amazon_polly_auto_breaths', __( 'Automated breaths:', 'amazonpolly' ), array( $this, 'amazon_polly_auto_breaths_cb' ), $this->plugin_name, 'amazon_polly_pollysettings', array( 'label_for' => 'amazon_polly_auto_breaths_id' ) );
		add_settings_field( 'amazon_polly_ssml', __( 'Enable SSML support:', 'amazonpolly' ), array( $this, 'amazon_polly_ssml_cb' ), $this->plugin_name, 'amazon_polly_pollysettings', array( 'label_for' => 'amazon_polly_ssml' ) );
		add_settings_field( 'amazon_polly_lexicons', __( 'Lexicons:', 'amazonpolly' ), array( $this, 'amazon_polly_lexicons_cb' ), $this->plugin_name, 'amazon_polly_pollysettings', array( 'label_for' => 'amazon_polly_lexicons' ) );
		add_settings_field( 'amazon_polly_speed', __( 'Audio speed [%]:', 'amazonpolly' ), array( $this, 'amazon_polly_speed_cb' ), $this->plugin_name, 'amazon_polly_pollysettings', array( 'label_for' => 'amazon_polly_speed' ) );

		// ************************************************* *
		// ************** STORAGE SECTION ************** *
		add_settings_section( 'amazon_polly_storage', __( 'Cloud storage', 'amazonpolly' ), array( $this, 'amazon_polly_storage_cb' ), $this->plugin_name );
		add_settings_field( 'amazon_polly_s3', __( 'Store audio in Amazon S3:', 'amazonpolly' ), array( $this, 'amazon_polly_s3_cb' ), $this->plugin_name, 'amazon_polly_storage', array( 'label_for' => 'amazon_polly_s3' ) );
		add_settings_field( 'amazon_polly_cloudfront', __( 'Amazon CloudFront (CDN) domain name:', 'amazonpolly' ), array( $this, 'amazon_polly_cloudfront_cb' ), $this->plugin_name, 'amazon_polly_storage', array( 'label_for' => 'amazon_polly_cloudfront' ) );

		// ************************************************* *
		// ************** PODCAST SECTION ************** *
		add_settings_section( 'amazon_polly_podcast', __( 'Amazon Pollycast', 'amazonpolly' ), array( $this, 'amazon_pollycast_cb' ), $this->plugin_name );
		add_settings_field( 'amazon_polly_podcast_enabled', __( 'Pollycast enabled:', 'amazonpolly' ), array( $this, 'amazon_polly_podcast_enabled_cb' ), $this->plugin_name, 'amazon_polly_podcast', array( 'label_for' => 'amazon_polly_podcast_enabled' ) );
		add_settings_field( 'amazon_polly_podcast_email', __( 'iTunes contact email:', 'amazonpolly' ), array( $this, 'amazon_polly_podcast_email_cb' ), $this->plugin_name, 'amazon_polly_podcast', array( 'label_for' => 'amazon_polly_podcast_email' ) );
		add_settings_field( 'amazon_polly_podcast_category', __( 'iTunes category:', 'amazonpolly' ), array( $this, 'amazon_polly_podcast_category_cb' ), $this->plugin_name, 'amazon_polly_podcast', array( 'label_for' => 'amazon_polly_podcast_category' ) );
		add_settings_field( 'amazon_polly_podcast_explicit', __( 'iTunes explicit content:', 'amazonpolly' ), array( $this, 'amazon_polly_podcast_explicit_cb' ), $this->plugin_name, 'amazon_polly_podcast', array( 'label_for' => 'amazon_polly_podcast_explicit' ) );
		add_settings_field( 'amazon_polly_podcast_icon', __( 'iTunes image:', 'amazonpolly' ), array( $this, 'amazon_polly_podcast_icon_cb' ), $this->plugin_name, 'amazon_polly_podcast', array( 'label_for' => 'amazon_polly_podcast_icon' ) );
		add_settings_field( 'amazon_polly_podcast_feedsize', __( 'Feed size:', 'amazonpolly' ), array( $this, 'amazon_polly_podcast_feedsize_cb' ), $this->plugin_name, 'amazon_polly_podcast', array( 'label_for' => 'amazon_polly_podcast_feedsize' ) );
		add_settings_field( 'amazon_polly_podcast_post_cat', __( 'Post categories:', 'amazonpolly' ), array( $this, 'amazon_polly_podcast_post_cat_cb' ), $this->plugin_name, 'amazon_polly_podcast', array( 'label_for' => 'amazon_polly_podcast_post_cat' ) );
		add_settings_field( 'amazon_polly_podcast_https', __( 'Use HTTPS for audio files:', 'amazonpolly' ), array( $this, 'amazon_polly_podcast_https_cb' ), $this->plugin_name, 'amazon_polly_podcast', array( 'label_for' => 'amazon_polly_podcast_https' ) );

		// ************************************************* *
		// ************** ADDITIONAL SECTION ************** *
		add_settings_section( 'amazon_polly_additional', __( 'Additional configuration', 'amazonpolly' ), array( $this, 'amazon_polly_additional_cb' ), $this->plugin_name );
		add_settings_field( 'amazon_polly_update_all', __( 'Bulk update all posts:', 'amazonpolly' ), array( $this, 'amazon_polly_update_all_cb' ), $this->plugin_name, 'amazon_polly_additional', array( 'label_for' => 'amazon_polly_update_all' ) );
		add_settings_field( 'amazon_polly_add_post_title', __( 'Add post title to audio:', 'amazonpolly' ), array( $this, 'amazon_polly_add_post_title_cb' ), $this->plugin_name, 'amazon_polly_additional', array( 'label_for' => 'amazon_polly_add_post_title' ) );
		add_settings_field( 'amazon_polly_add_post_excerpt', __( 'Add post excerpt to audio:', 'amazonpolly' ), array( $this, 'amazon_polly_add_post_excerpt_cb' ), $this->plugin_name, 'amazon_polly_additional', array( 'label_for' => 'amazon_polly_add_post_excerpt' ) );
		add_settings_field( 'amazon_polly_posttypes', __( 'Post types:', 'amazonpolly' ), array( $this, 'amazon_polly_posttypes_cb' ), $this->plugin_name, 'amazon_polly_additional', array( 'label_for' => 'amazon_polly_posttypes' ) );

		// ************************************************* *
		// ************** TRANSLATION SECTION ************** *
		add_settings_section( 'amazon_polly_trans', __( 'Amazon Translate configuration', 'amazonpolly' ), array( $this, 'amazon_polly_trans_cb' ), $this->plugin_name );
		add_settings_field( 'amazon_polly_trans_enabled', __( 'Enable translation support:', 'amazonpolly' ), array( $this, 'amazon_polly_trans_enabled_cb' ), $this->plugin_name, 'amazon_polly_trans', array( 'label_for' => 'amazon_polly_trans_enabled' ) );
		add_settings_field( 'amazon_polly_transcript_enabled', __( 'Show transcript:', 'amazonpolly' ), array( $this, 'amazon_polly_transcript_enabled_cb' ), $this->plugin_name, 'amazon_polly_trans', array( 'label_for' => 'amazon_polly_transcript_enabled' ) );
		add_settings_field( 'amazon_polly_trans_src_lang', __( 'Source language:', 'amazonpolly' ), array( $this, 'amazon_polly_trans_src_lang_cb' ), $this->plugin_name, 'amazon_polly_trans', array( 'label_for' => 'amazon_polly_trans_src_lang' ) );
		add_settings_field( 'amazon_polly_trans_langs_src_label', __( 'Source language label:', 'amazonpolly' ), array( $this, 'amazon_polly_trans_langs_src_label_cb' ), $this->plugin_name, 'amazon_polly_trans', array( 'label_for' => 'amazon_polly_trans_langs_src_label' ) );
		add_settings_field( 'amazon_polly_trans_langs_label', __( 'Translations label:', 'amazonpolly' ), array( $this, 'amazon_polly_trans_langs_label_cb' ), $this->plugin_name, 'amazon_polly_trans', array( 'label_for' => 'amazon_polly_trans_langs_label' ) );
		add_settings_field( 'amazon_polly_trans_langs', __( 'Target languages:', 'amazonpolly' ), array( $this, 'amazon_polly_trans_langs_cb' ), $this->plugin_name, 'amazon_polly_trans', array( 'label_for' => 'amazon_polly_trans_langs' ) );

		add_option( 'amazon_polly_trans_validated' );


		// ************************************************* *
		$selected_region = get_option( 'amazon_polly_region' );

		if ( empty( $selected_region ) ) {
			update_option( 'amazon_polly_region', 'us-east-1' );
			$selected_region = 'us-east-1';
		}

		if ( empty( get_option( 'amazon_polly_access_key' ) ) ) {

			// Set AWS SDK settings.
			$aws_sdk_config = array(
				'region'  => $selected_region,
				'version' => 'latest',
			);

		} else {

			// Set AWS SDK settings.
			$aws_sdk_config = array(
				'region'      => $selected_region,
				'version'     => 'latest',
				'credentials' => array(
					'key'    => get_option( 'amazon_polly_access_key' ),
					'secret' => get_option( 'amazon_polly_secret_key' ),
				),
			);

		}//end if

		// Create an SDK class to use config.
		$sdk = new Aws\Sdk( $aws_sdk_config );

		$this->s3_file_handler->set_s3_client( $sdk->createS3() );
		$this->translate_client = $sdk->createTranslate();
		$this->polly_client = $sdk->createPolly();

		register_setting( $this->plugin_name, 'amazon_polly_access_key', 'strval' );
		register_setting( $this->plugin_name, 'amazon_polly_secret_key', 'strval' );
		register_setting( $this->plugin_name, 'amazon_polly_s3', 'strval' );

		if ( $this->amazon_polly_is_ok() ) {
			register_setting( $this->plugin_name, 'amazon_polly_podcast_enabled', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_cloudfront', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_region', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_sample_rate', 'intval' );
			register_setting( $this->plugin_name, 'amazon_polly_voice_id', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_ssml', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_auto_breaths', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_position', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_player_label', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_defconf', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_autoplay', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_speed', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_podcast_feedsize', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_podcast_email', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_podcast_category', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_podcast_explicit', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_podcast_post_cat', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_podcast_https', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_settings_hash', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_podcast_explicit', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_add_post_title', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_add_post_excerpt', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_posttypes', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_lexicons', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_trans', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_trans_enabled', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_transcript_enabled', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_trans_src_lang', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_trans_langs_src_label', 'strval' );
			register_setting( $this->plugin_name, 'amazon_polly_trans_langs_label', 'strval' );

			foreach ( $this->translate_langs as $lan ) {
				register_setting( $this->plugin_name, 'amazon_polly_trans_langs_' . $lan, 'strval' );
				register_setting( $this->plugin_name, 'amazon_polly_trans_langs_' . $lan . '_voice', 'strval' );
				register_setting( $this->plugin_name, 'amazon_polly_trans_langs_' . $lan . '_label', 'strval' );
			}
		}//end if

		$this->amazon_polly_validate_credentials();

		$is_s3_enabled = $this->amazon_polly_is_s3_enabled();
		if ( $this->amazon_polly_is_ok() ) {
			if ( $is_s3_enabled ) {
				$this->getFileHandler()->prepare_s3_bucket();
			}
		}

	}