settings_key ); $api_key = $general_options && array_key_exists( 'api_key', $general_options ) ? $general_options['api_key'] : null; $api_secret = $general_options && array_key_exists( 'api_secret', $general_options ) ? $general_options['api_secret'] : null; $debug = $general_options && array_key_exists( 'debug', $general_options ) ? $general_options['debug'] : null; $this->api = new ConvertKit_API( $api_key, $api_secret, $debug ); 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 add_action( 'admin_footer', array( $this, 'add_tags_footer' ) ); // Category default forms add_action( 'edit_category_form_fields', array( $this, 'category_form_fields' ), 20 ); add_action( 'edited_category', array( $this, 'save_category_fields' ), 20 ); if ( WP_DEBUG ) { add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ) ); add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ) ); } } /** * 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 */ public function add_settings_page() { add_options_page( __( 'ConvertKit', 'convertkit' ), __( 'ConvertKit', 'convertkit' ), 'manage_options', $this->settings_key, array( $this, 'display_settings_page' ) ); add_action( 'admin_print_styles', array( $this, 'admin_styles' ) ); } /** * Options page callback */ public function display_settings_page() { if ( isset( $_GET['tab'] ) ) { // WPCS: CSRF ok. $active_section = sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // WPCS: CSRF ok. } else { $active_section = $this->sections[0]->name; } ?>
sections ) > 1 ) { $this->display_section_nav( $active_section ); } else { ?>

sections as $section ) : if ( $active_section === $section->name ) : $section->render(); endif; endforeach; // Check for Multibyte string PHP extension. if ( ! extension_loaded( 'mbstring' ) ) { ?>

mbstring' ) . ''; ?>

', '' ); ?>

is_registerable ) { array_push( $this->sections, $section_instance ); } } /** * Register each 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_Wishlist' ); $this->register_section( 'ConvertKit_Settings_ContactForm7' ); } /** * Ajax callback to return formatted list of available tags * * Since 1.5.0 */ public function get_tags() { check_ajax_referer( 'convertkit-tinymce', 'security' ); $tags = get_option( 'convertkit_tags' ); $values = array(); foreach ( $tags as $tag ) { $values[] = array( 'value' => $tag['id'], 'text' => $tag['name'], ); } wp_send_json( $values ); } /** * Add tags to the footer * * @since 1.5.0 */ public function add_tags_footer() { // create nonce global $pagenow; if ( $pagenow !== 'admin.php' ) { $nonce = wp_create_nonce( 'convertkit-tinymce' ); ?> ID, 'convertkit_tags', true ); ?>

term_id, 'ck_default_form', true ); echo ''; // 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 = ''; } if ( empty( $forms ) ) { $html .= '

' . __( 'There are no forms setup in your account. You can go here to create one.', 'convertkit' ) . '

'; } $html .= '

' . __( 'This form will be automatically added to posts in this category.', 'convertkit' ) . '

'; echo $html; // WPCS: XSS ok. } /** * Set the default ConvertKit form for * * @param int $tag_id */ public function save_category_fields( $tag_id ) { $ck_default_form = isset( $_POST['ck_default_form'] ) ? intval( $_POST['ck_default_form'] ) : 0; if ( $ck_default_form ) { update_term_meta( $tag_id, 'ck_default_form', $ck_default_form ); } } }