Skip to content

Commit

Permalink
Merge pull request #16 from ConvertKit/1.4.0
Browse files Browse the repository at this point in the history
Version 1.4.0 of plugin
  • Loading branch information
growdev committed May 16, 2016
2 parents 9e22e12 + a1bb2ea commit 5cf64a4
Show file tree
Hide file tree
Showing 12 changed files with 764 additions and 573 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# ConvertKit

Wordpress plugin for [ConvertKit](https://convertkit.com). Visit https://wordpress.org/plugins/convertkit/ for more information.
WordPress plugin for [ConvertKit](https://convertkit.com). Visit https://wordpress.org/plugins/convertkit/ for more information.
6 changes: 6 additions & 0 deletions admin/section/base.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* Class ConvertKitSettingsSection
*/
abstract class ConvertKitSettingsSection {
public $is_registerable = true;
public $name;
Expand All @@ -10,6 +13,9 @@ abstract class ConvertKitSettingsSection {
public $api;
public $options;

/**
* Constructor
*/
public function __construct() {
global $convertkit_settings;

Expand Down
232 changes: 131 additions & 101 deletions admin/section/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,137 @@

require_once "base.php";

/**
* Class ConvertKitSettingsGeneral
*/
class ConvertKitSettingsGeneral extends ConvertKitSettingsSection {

public function __construct() {
$this->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(
'default_form',
'Default Form',
array($this, 'default_form_callback'),
$this->settings_key,
$this->name,
$this->api->get_resources('forms')
);
}

/**
* Prints help info for this section
*/
public function print_section_info() {
?>
<p>
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.
</p>
<p>
The default form can be inserted into the middle of post or page content
by using the <code>[convertkit]</code> shortcode.
</p>
<?php
}

/**
* Renders the input for api key entry
*/
public function api_key_callback() {
$html = sprintf(
'<input type="text" class="regular-text code" id="api_key" name="%s[api_key]" value="%s" />',
$this->settings_key,
isset($this->options['api_key']) ? esc_attr($this->options['api_key']) : ''
);

$html .= '<p class="description"><a href="https://app.convertkit.com/account/edit" target="_blank">Get your ConvertKit API Key</a></p>';

echo $html;
}

/**
* Renders the form select list
*
* @param array $forms Form listing
*/
public function default_form_callback($forms) {
$html = sprintf('<select id="default_form" name="%s[default_form]">', $this->settings_key);
$html .= '<option value="default">None</option>';
foreach($forms as $form) {
$html .= sprintf(
'<option value="%s" %s>%s</option>',
esc_attr($form['id']),
selected($this->options['default_form'], $form['id'], false),
esc_html($form['name'])
);
}
$html .= '</select>';

if (empty($forms)) {
$html .= '<p class="description">Enter your API Key above to get your available forms.</p>';
}

echo $html;
}

/**
* Sanitizes the settings
*
* @param array $settings The settings fields submitted
* @return array Sanitized settings
*/
public function sanitize_settings($settings) {
return shortcode_atts(array(
'api_key' => '',
'default_form' => 0
), $settings);
}
/**
* Constructor
*/
public function __construct() {
$this->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')
);
}

/**
* Prints help info for this section
*/
public function print_section_info() {
?>
<p>
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.
</p>
<p>
The default form can be inserted into the middle of post or page content
by using the <code>[convertkit]</code> shortcode.
</p>
<?php
}

/**
* Renders the input for api key entry
*/
public function api_key_callback() {
$html = sprintf(
'<input type="text" class="regular-text code" id="api_key" name="%s[api_key]" value="%s" />',
$this->settings_key,
isset($this->options['api_key']) ? esc_attr($this->options['api_key']) : ''
);

$html .= '<p class="description"><a href="https://app.convertkit.com/account/edit" target="_blank">Get your ConvertKit API Key</a></p>';

echo $html;
}

/**
* Renders the input for api key entry
*/
public function api_secret_callback() {
$html = sprintf(
'<input type="password" class="regular-text code" id="api_key" name="%s[api_secret]" value="%s" />',
$this->settings_key,
isset($this->options['api_secret']) ? esc_attr($this->options['api_secret']) : ''
);

$html .= '<p class="description"><a href="https://app.convertkit.com/account/edit" target="_blank">Get your ConvertKit API Secret.</a> This setting is required to unsubscribe subscribers.</p>';

echo $html;
}

/**
* Renders the form select list
*
* @param array $forms Form listing
*/
public function default_form_callback($forms) {
$html = sprintf('<select id="default_form" name="%s[default_form]">', $this->settings_key);
$html .= '<option value="default">None</option>';
foreach ( $forms as $form ) {
$html .= sprintf(
'<option value="%s" %s>%s</option>',
esc_attr( $form['id'] ),
selected( $this->options['default_form'], $form['id'], false ),
esc_html( $form['name'] )
);
}
$html .= '</select>';

if (empty($forms)) {
$html .= '<p class="description">Enter your API Key above to get your available forms.</p>';
}

echo $html;
}

/**
* Sanitizes the settings
*
* @param array $settings The settings fields submitted
* @return array Sanitized settings
*/
public function sanitize_settings($settings) {
return shortcode_atts(array(
'api_key' => '',
'api_secret' => '',
'default_form' => 0
), $settings);
}
}
6 changes: 6 additions & 0 deletions admin/section/wishlist_member.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require_once "base.php";
require_once plugin_dir_path( __FILE__ ) . "../../lib/multi_value_field_table.php";

/**
* Class ConvertKitSettingsWishlistMember
*/
class ConvertKitSettingsWishlistMember extends ConvertKitSettingsSection {

/**
Expand All @@ -11,6 +14,9 @@ class ConvertKitSettingsWishlistMember extends ConvertKitSettingsSection {
*/
private $wlm_levels;

/**
* Cont
*/
public function __construct() {
if (!function_exists('wlmapi_get_levels')) {
return $this->is_registerable = false;
Expand Down
Loading

0 comments on commit 5cf64a4

Please sign in to comment.