settings_key = WP_ConvertKit::SETTINGS_PAGE_SLUG; $this->name = 'general'; $this->title = __( 'General Settings', 'convertkit' ); $this->tab_text = __( 'General', 'convertkit' ); parent::__construct(); } /** * Register and add settings */ public function register_fields() { add_settings_field( 'api_key', 'API Key', array($this, 'api_key_callback'), $this->settings_key, $this->name ); add_settings_field( 'api_secret', 'API Secret', array($this, 'api_secret_callback'), $this->settings_key, $this->name ); add_settings_field( 'default_form', 'Default Form', array($this, 'default_form_callback'), $this->settings_key, $this->name, $this->api->get_resources('forms') ); add_settings_field( 'debug', 'Debug', array($this, 'debug_callback'), $this->settings_key, $this->name ); } /** * Prints help info for this section */ public function print_section_info() { ?>
[convertkit] shortcode.', 'convertkit' ); ?>
', $this->settings_key, isset($this->options['api_key']) ? esc_attr($this->options['api_key']) : '' ); $html .= '' . __('Get your ConvertKit API Key', 'convertkit' ) . '
'; echo $html; } /** * Renders the input for api key entry */ public function api_secret_callback() { $html = sprintf( '', $this->settings_key, isset($this->options['api_secret']) ? esc_attr($this->options['api_secret']) : '' ); $html .= '' . __( 'Get your ConvertKit API Secret.', 'convertkit' ) . '' . ' ' . __( 'This setting is required to unsubscribe subscribers.', 'convertkit' ) . '
'; echo $html; } /** * Renders the form select list * * @param array $forms Form listing */ public function default_form_callback($forms) { // check for error in response if ( isset( $forms[0]['id'] ) && '-2' == $forms[0]['id'] ) { $html = '' . __('Error connecting to API. Please verify your site can connect to https://api.convertkit.com','convertkit') . '
' . __( 'Enter your API Key above to get your available forms.', 'convertkit' ) . '
'; } if (empty($forms)) { $html .= '' . __('There are no forms setup in your account. You can go here to create one.', 'convertkit' ) . '
'; } echo $html; } /** * Renders the input for debug setting */ public function debug_callback() { $debug = ''; if ( isset( $this->options['debug'] ) && 'on' == $this->options['debug'] ) { $debug = 'checked'; } $html = sprintf( '%s', $this->settings_key, $debug, __('Save connection data to a log file.','convertkit') ); echo $html; } /** * Sanitizes the settings * * @param array $settings The settings fields submitted * @return array Sanitized settings */ public function sanitize_settings($settings) { // clear api transient delete_transient( 'convertkit_get_api_response' ); return shortcode_atts(array( 'api_key' => '', 'api_secret' => '', 'default_form' => 0, 'debug' => '' ), $settings); } }