settings_key = WP_ConvertKit::SETTINGS_PAGE_SLUG; $this->name = 'general'; $this->title = 'General Settings'; $this->tab_text = 'General'; 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() { ?>

Choosing a default form will embed it at the bottom of every post or page (in single view only) across your site. If you wish to turn off form embedding or select a different form for an individual post or page, you can do so within the ConvertKit meta box on the editing form.

The default form can be inserted into the middle of post or page content by using the [convertkit] shortcode.

', $this->settings_key, isset($this->options['api_key']) ? esc_attr($this->options['api_key']) : '' ); $html .= '

Get your ConvertKit API Key

'; 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. This setting is required to unsubscribe subscribers.

'; 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') . '

'; } else { $html = sprintf( ''; } if ( empty( $this->options['api_key'] ) ) { $html .= '

Enter your API Key above to get your available forms.

'; } if (empty($forms)) { $html .= '

There are no forms setup in your account. You can go here to create one.

'; } 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); } }