* @since 3.0.0 */ namespace Beyondwords\Wordpress\Component\Settings; use Beyondwords\Wordpress\Component\Settings\ApiKey\ApiKey; use Beyondwords\Wordpress\Component\Settings\Languages\Languages; use Beyondwords\Wordpress\Component\Settings\Preselect\Preselect; use Beyondwords\Wordpress\Component\Settings\PrependExcerpt\PrependExcerpt; use Beyondwords\Wordpress\Component\Settings\PlayerUI\PlayerUI; use Beyondwords\Wordpress\Component\Settings\PlayerStyle\PlayerStyle; use Beyondwords\Wordpress\Component\Settings\PlayerVersion\PlayerVersion; use Beyondwords\Wordpress\Component\Settings\ProjectId\ProjectId; use Beyondwords\Wordpress\Component\Settings\SettingsUpdated\SettingsUpdated; use Beyondwords\Wordpress\Component\Settings\SettingsUtils; use Beyondwords\Wordpress\Core\Environment; /** * Settings setup * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * * @since 3.0.0 */ class Settings { /** * API Client. * * @since 3.0.0 */ private $apiClient; /** * Constructor. * * @since 3.0.0 */ public function __construct($apiClient) { $this->apiClient = $apiClient; } /** * Init */ public function init() { (new ApiKey())->init(); (new ProjectId())->init(); (new Preselect())->init(); (new PrependExcerpt())->init(); (new PlayerVersion($this->apiClient))->init(); (new PlayerUI())->init(); (new PlayerStyle($this->apiClient))->init(); (new Languages($this->apiClient))->init(); (new SettingsUpdated())->init(); add_action('admin_menu', array($this, 'addOptionsPage')); add_action('admin_init', array($this, 'addSettingsSections')); add_action('admin_notices', array($this, 'printPluginAdminNotices')); add_action('rest_api_init', array($this, 'restApiInit')); add_filter('plugin_action_links_speechkit/speechkit.php', array($this, 'addSettingsLinkToPluginPage')); add_action('updated_option', array($this, 'updatedOption'), 99); add_action('added_option', array($this, 'addedOption'), 99); } /** * Add items to the WordPress admin menu. * * @since 3.0.0 * * @return void */ public function addOptionsPage() { // Settings > BeyondWords add_options_page( __('BeyondWords', 'speechkit'), __('BeyondWords', 'speechkit'), 'manage_options', 'beyondwords', array($this, 'createAdminInterface') ); } /** * Add Settings sections. * * ===== * Basic * ===== * 'api_key' => '', * 'project_id' => '', * * ============== * Player * ============== * 'version' => '0', * * ============== * Generate audio * ============== * 'preselect' => array('post' => '1', 'page' => '1'), * * ======== * Advanced * ======== * 'merge_excerpt' => false, * * @since 3.0.0 */ public function addSettingsSections() { // Add Settings Section: Basic add_settings_section( 'basic', __('Basic settings', 'speechkit'), array($this, 'basicSectionCallback'), 'beyondwords' ); if (SettingsUtils::hasApiSettings()) { // Add Settings Section: Player add_settings_section( 'player', __('Player settings', 'speechkit'), array($this, 'playerSectionCallback'), 'beyondwords' ); // Add Settings Section: Content add_settings_section( 'content', __('Content settings', 'speechkit'), array($this, 'contentSectionCallback'), 'beyondwords' ); // Add Settings Section: Generate audio add_settings_section( 'generate-audio', __('‘Generate audio’ settings', 'speechkit'), array($this, 'generateAudioSectionCallback'), 'beyondwords' ); } } /** * "Basic section" callback * * @since 3.0.0 * * @return void **/ public function basicSectionCallback() { delete_transient('beyondwords_settings_errors'); ?>
' . __('Settings', 'speechkit') . ''; return $links; } public function createAdminInterface() { ?>
%s', esc_url(admin_url('options-general.php?page=beyondwords')), esc_html__('plugin settings', 'speechkit') ) ); ?>