ConvertKit in the WordPress Administration * interface, and handles saving its data. * * @package ConvertKit * @author ConvertKit */ class ConvertKit_Admin_Settings { /** * Settings sections * * @var array */ public $sections = array(); /** * Holds the Settings Page Slug * * @var string */ const SETTINGS_PAGE_SLUG = '_wp_convertkit_settings'; /** * Constructor */ public function __construct() { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); add_action( 'admin_menu', array( $this, 'add_settings_page' ) ); add_action( 'admin_init', array( $this, 'register_sections' ) ); add_filter( 'plugin_action_links_' . CONVERTKIT_PLUGIN_FILE, array( $this, 'add_settings_page_link' ) ); } /** * Enqueue JavaScript in Admin * * @since 1.9.6 * * @param string $hook Hook. */ public function enqueue_scripts( $hook ) { // Bail if we are not on the Settings screen. if ( $hook !== 'settings_page_' . self::SETTINGS_PAGE_SLUG ) { return; } // Enqueue Select2 JS. convertkit_select2_enqueue_scripts(); // Enqueue Preview Output JS. wp_enqueue_script( 'convertkit-admin-preview-output', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/preview-output.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true ); /** * Enqueue JavaScript for the Settings Screen at Settings > ConvertKit * * @since 1.9.6 */ do_action( 'convertkit_admin_settings_enqueue_scripts' ); } /** * Enqueue CSS for the Settings Screens at Settings > ConvertKit * * @since 1.9.6 * * @param string $hook Hook. */ public function enqueue_styles( $hook ) { // Bail if we are not on the Settings screen. if ( $hook !== 'settings_page_' . self::SETTINGS_PAGE_SLUG ) { return; } // Enqueue Select2 CSS. convertkit_select2_enqueue_styles(); // Enqueue Settings CSS. wp_enqueue_style( 'convertkit-admin-settings', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/settings.css', array(), CONVERTKIT_PLUGIN_VERSION ); /** * Enqueue CSS for the Settings Screen at Settings > ConvertKit * * @since 1.9.6 */ do_action( 'convertkit_admin_settings_enqueue_styles' ); } /** * Adds the options page * * @since 1.9.6 */ public function add_settings_page() { add_options_page( __( 'ConvertKit', 'convertkit' ), __( 'ConvertKit', 'convertkit' ), 'manage_options', self::SETTINGS_PAGE_SLUG, array( $this, 'display_settings_page' ) ); } /** * Outputs the settings screen. * * @since 1.9.6 */ public function display_settings_page() { $active_section = $this->get_active_section(); ?>

maybe_display_notices(); ?>
sections ) > 1 ) { $this->display_section_nav( $active_section ); } ?>
sections[ $active_section ] ) ) { $this->sections[ $active_section ]->render(); } ?>

', '' ); ?>

sections )->name; } /** * Display notice(s) immediately after the settings screen header. * * @since 1.9.6 */ private function maybe_display_notices() { $notices = array(); // Check the mbstring extension is loaded. if ( ! extension_loaded( 'mbstring' ) ) { $notices[] = array( 'type' => 'warning', 'message' => sprintf( /* translators: link to php.net manual */ __( 'Notice: Your server does not support the %s function - this is required for better character encoding. Please contact your webhost to have it installed.', 'convertkit' ), 'mbstring' ), ); } // Bail if no notices exist. if ( ! count( $notices ) ) { return; } ?>

sprintf( '%s', convertkit_get_settings_link(), __( 'Settings', 'convertkit' ) ), ), $links ); } /** * Output tabs, one for each registered settings section. * * @param string $active_section Currently displayed/selected section. */ public function display_section_nav( $active_section ) { ?> , whichever comes first. // As our

is inside our .metabox-holder, we output .wp-header-end first to control the notification // placement to be before the white background container/box. ?>
ConvertKit. * * Each section has its own tab. * * @since 1.9.6 */ public function register_sections() { // Register the General and Tools settings sections. $sections = array( 'general' => new ConvertKit_Settings_General(), 'tools' => new ConvertKit_Settings_Tools(), ); /** * Registers settings sections at Settings > ConvertKit. * * @since 1.9.6 * * @param array $sections Array of settings classes that handle individual tabs e.g. General, Tools etc. */ $sections = apply_filters( 'convertkit_admin_settings_register_sections', $sections ); // With our sections now registered, assign them to this class. $this->sections = $sections; } }