Skip to content

Commit

Permalink
Merge pull request #150 from ConvertKit/tools-tab
Browse files Browse the repository at this point in the history
Adding tools tab.
  • Loading branch information
tnorthcutt authored Jan 18, 2019
2 parents b6a525c + b12b95b commit 38ca6e8
Show file tree
Hide file tree
Showing 6 changed files with 1,627 additions and 74 deletions.
144 changes: 72 additions & 72 deletions admin/class-convertkit-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function __construct() {
* @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(
Expand Down Expand Up @@ -102,35 +101,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>
<?php
}
<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 @@ -148,20 +147,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 All @@ -184,6 +183,7 @@ public function register_section( $section ) {
public function register_sections() {
wp_register_style( 'wp-convertkit-admin', plugins_url( '../resources/backend/wp-convertkit.css', __FILE__ ) );
$this->register_section( 'ConvertKit_Settings_General' );
$this->register_section( 'ConvertKit_Settings_Tools' );
$this->register_section( 'ConvertKit_Settings_Wishlist' );
$this->register_section( 'ConvertKit_Settings_ContactForm7' );
}
Expand Down Expand Up @@ -218,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 @@ -249,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 @@ -266,11 +266,11 @@ public function add_customer_meta_fields( $user ) {
}
}
?></textarea>
</td>
</tr>
<?php
</td>
</tr>
<?php
?>
</table>
</table>
<?php
}

Expand All @@ -285,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 ck-term-description-wrap"><th scope="row"><label for="description">ConvertKit Form</label></th><td>';
echo '<tr class="form-field 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
11 changes: 10 additions & 1 deletion admin/section/class-convertkit-settings-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ abstract class ConvertKit_Settings_Base {
*/
public $options;

/**
* If false, we will hide the submit button.
*
* @var bool
*/
protected $show_submit = true;

/**
* Constructor
*/
Expand Down Expand Up @@ -105,7 +112,9 @@ public function register_section() {
public function render() {
do_settings_sections( $this->settings_key );
settings_fields( $this->settings_key );
submit_button();
if ( $this->show_submit ) {
submit_button();
}
}

/**
Expand Down
Loading

0 comments on commit 38ca6e8

Please sign in to comment.