Skip to content

Commit

Permalink
Merge pull request #132 from ConvertKit/release/1.6.3
Browse files Browse the repository at this point in the history
Release/1.6.3
  • Loading branch information
tnorthcutt authored Jan 7, 2019
2 parents c993646 + f73bbc0 commit 582786f
Show file tree
Hide file tree
Showing 8 changed files with 1,611 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/
inc/log.txt
log.txt
includes/log.txt
vendor
159 changes: 88 additions & 71 deletions admin/class-convertkit-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function __construct() {
add_action( 'admin_menu', array( $this, 'add_settings_page' ) );
add_action( 'admin_init', array( $this, 'register_sections' ) );

add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );

// AJAX callback for TinyMCE button to get list of tags
add_action( 'wp_ajax_convertkit_get_tags', array( $this, 'get_tags' ) );
// Function to output
Expand All @@ -59,6 +61,21 @@ public function __construct() {
}
}

/**
* Enqueue Scripts in Admin
*
* @param $hook
*/
public function enqueue_scripts( $hook ) {

if ( 'settings_page__wp_convertkit_settings' === $hook ) {
wp_enqueue_script( 'ck-admin-js', plugins_url( '../resources/backend/wp-convertkit.js', __FILE__ ), array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
wp_localize_script( 'ck-admin-js', 'ck_admin', array(
'option_none' => __( 'None', 'convertkit' ),
));
}
}

/**
* Add the options page
*/
Expand All @@ -85,35 +102,35 @@ public function display_settings_page() {
}

?>
<div class="wrap convertkit-settings-wrap">
<?php
if ( count( $this->sections ) > 1 ) {
$this->display_section_nav( $active_section );
} else {
?>
<h2><?php esc_html_e( 'ConvertKit', 'convertkit' ); ?></h2>
<div class="wrap convertkit-settings-wrap">
<?php
}
?>
if ( count( $this->sections ) > 1 ) {
$this->display_section_nav( $active_section );
} else {
?>
<h2><?php esc_html_e( 'ConvertKit', 'convertkit' ); ?></h2>
<?php
}
?>

<form method="post" action="options.php">
<?php
foreach ( $this->sections as $section ) :
if ( $active_section === $section->name ) :
$section->render();
endif;
endforeach;

// Check for Multibyte string PHP extension.
if ( ! extension_loaded( 'mbstring' ) ) {
?><p><strong><?php
echo sprintf( __( 'Note: Your server does not support the %s functions - this is required for better character encoding. Please contact your webhost to have it installed.', 'woocommerce' ), '<a href="https://php.net/manual/en/mbstring.installation.php">mbstring</a>' ) . '</mark>';
?></strong></p><?php
}
?><p class="description"><?php
printf( 'If you need help setting up the plugin please refer to the %s plugin documentation.</a>', '<a href="http://help.convertkit.com/article/99-the-convertkit-wordpress-plugin" target="_blank">' ); ?></p>
</form>
</div>
<form method="post" action="options.php">
<?php
foreach ( $this->sections as $section ) :
if ( $active_section === $section->name ) :
$section->render();
endif;
endforeach;

// Check for Multibyte string PHP extension.
if ( ! extension_loaded( 'mbstring' ) ) {
?><p><strong><?php
echo sprintf( __( 'Note: Your server does not support the %s functions - this is required for better character encoding. Please contact your webhost to have it installed.', 'woocommerce' ), '<a href="https://php.net/manual/en/mbstring.installation.php">mbstring</a>' ) . '</mark>';
?></strong></p><?php
}
?><p class="description"><?php
printf( 'If you need help setting up the plugin please refer to the %s plugin documentation.</a>', '<a href="http://help.convertkit.com/article/99-the-convertkit-wordpress-plugin" target="_blank">' ); ?></p>
</form>
</div>
<?php
}

Expand All @@ -131,20 +148,20 @@ public function admin_styles() {
*/
public function display_section_nav( $active_section ) {
?>
<h1><?php esc_html_e( 'ConvertKit', 'convertkit' ); ?></h1>
<h2 class="nav-tab-wrapper">
<?php
foreach ( $this->sections as $section ) :
printf(
'<a href="?page=%s&tab=%s" class="nav-tab right %s">%s</a>',
esc_html( $this->settings_key ),
esc_html( $section->name ),
$active_section === $section->name ? 'nav-tab-active' : '',
esc_html( $section->tab_text )
);
endforeach;
?>
</h2>
<h1><?php esc_html_e( 'ConvertKit', 'convertkit' ); ?></h1>
<h2 class="nav-tab-wrapper">
<?php
foreach ( $this->sections as $section ) :
printf(
'<a href="?page=%s&tab=%s" class="nav-tab right %s">%s</a>',
esc_html( $this->settings_key ),
esc_html( $section->name ),
$active_section === $section->name ? 'nav-tab-active' : '',
esc_html( $section->tab_text )
);
endforeach;
?>
</h2>
<?php
}

Expand Down Expand Up @@ -201,25 +218,25 @@ public function add_tags_footer() {
if ( $pagenow !== 'admin.php' ) {
$nonce = wp_create_nonce( 'convertkit-tinymce' );
?><script type="text/javascript">
jQuery( document ).ready( function( $ ) {
var data = {
'action' : 'convertkit_get_tags', // wp ajax action
'security' : '<?php echo $nonce; ?>' // nonce value created earlier
};
jQuery.post( ajaxurl, data, function( response ) {
if( response === '-1' ){
console.log( 'error convertkit_get_tags' );
} else {
if ( typeof( tinyMCE ) != 'undefined' ) {
if (tinyMCE.activeEditor != null) {
tinyMCE.activeEditor.settings.ckTags = response;
console.log('added tags');
}
}
}
});
});
</script>
jQuery( document ).ready( function( $ ) {
var data = {
'action' : 'convertkit_get_tags', // wp ajax action
'security' : '<?php echo $nonce; ?>' // nonce value created earlier
};
jQuery.post( ajaxurl, data, function( response ) {
if( response === '-1' ){
console.log( 'error convertkit_get_tags' );
} else {
if ( typeof( tinyMCE ) != 'undefined' ) {
if (tinyMCE.activeEditor != null) {
tinyMCE.activeEditor.settings.ckTags = response;
console.log('added tags');
}
}
}
});
});
</script>
<?php
}
}
Expand All @@ -232,13 +249,13 @@ public function add_customer_meta_fields( $user ) {

$tags = get_user_meta( $user->ID, 'convertkit_tags', true );
?>
<h2><?php esc_attr_e( 'ConvertKit Tags', 'convertkit' ) ?></h2>
<table class="form-table" id="<?php echo esc_attr( 'fieldset-convertkit' ); ?>">
<h2><?php esc_attr_e( 'ConvertKit Tags', 'convertkit' ) ?></h2>
<table class="form-table" id="<?php echo esc_attr( 'fieldset-convertkit' ); ?>">
<?php
?>
<tr>
<th><label for="tags"><?php esc_attr_e( 'Tags', 'convertkit' ) ?></label></th>
<td><textarea id="tags" name="tags" disabled="disabled">
?>
<tr>
<th><label for="tags"><?php esc_attr_e( 'Tags', 'convertkit' ) ?></label></th>
<td><textarea id="tags" name="tags" disabled="disabled">
<?php
if ( empty( $tags ) ) {
esc_html_e( 'No ConvertKit Tags assigned to this user.' ,'convertkit' );
Expand All @@ -249,11 +266,11 @@ public function add_customer_meta_fields( $user ) {
}
}
?></textarea>
</td>
</tr>
<?php
</td>
</tr>
<?php
?>
</table>
</table>
<?php
}

Expand All @@ -268,7 +285,7 @@ public function category_form_fields( $tag ) {
$forms = get_option( 'convertkit_forms' );
$default_form = get_term_meta( $tag->term_id, 'ck_default_form', true );

echo '<tr class="form-field term-description-wrap"><th scope="row"><label for="description">ConvertKit Form</label></th><td>';
echo '<tr class="form-field ck-term-description-wrap"><th scope="row"><label for="description">ConvertKit Form</label></th><td>';

// Check for error in response.
if ( isset( $forms[0]['id'] ) && '-2' === $forms[0]['id'] ) {
Expand Down
8 changes: 5 additions & 3 deletions admin/section/class-convertkit-settings-contactform7.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function cf7_form_callback( $args ) {
$cf7_form_id = $args['cf7_form_id'];
$forms = $args['forms'];

$html = sprintf( '<select id="%1$s_%2$s" name="%1$s[%2$s]">', $this->settings_key, $cf7_form_id );
$html = sprintf( '<select id="%1$s_%2$s" class="widefat" name="%1$s[%2$s]">', $this->settings_key, $cf7_form_id );
$html .= '<option value="default">' . esc_html__( 'None', 'convertkit' ) . '</option>';
foreach ( $forms as $form ) {
$selected = '';
Expand Down Expand Up @@ -271,12 +271,14 @@ public function cf7_name_callback( $args ) {
*/
public function sanitize_settings( $input ) {
// Settings page can be paginated; combine input with existing options.
$output = $this->options;
// If saved options are not an array, start fresh. Fixes rogue saved options
$output = is_array( $this->options ) ? $this->options : array();

foreach ( $input as $key => $value ) {
$output[ $key ] = stripslashes( $input[ $key ] );
$output[ $key ] = sanitize_text_field( $value );
}
$sanitize_hook = 'sanitize' . $this->settings_key;

return apply_filters( $sanitize_hook, $output, $input );
}
}
Loading

0 comments on commit 582786f

Please sign in to comment.