forked from LiveCarta/LiveCartaWP
Changed source root directory
This commit is contained in:
@@ -0,0 +1,441 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin bar menu integration.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Admin_Bar_Menu {
|
||||
const MENU_IDENTIFIER = 'chimpmatic-menu';
|
||||
private static $instance = null;
|
||||
|
||||
public static function instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$this->register_hooks();
|
||||
}
|
||||
|
||||
private function register_hooks() {
|
||||
add_action( 'admin_bar_menu', array( $this, 'add_menu' ), 95 );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
|
||||
add_action( 'admin_footer', array( $this, 'render_upgrade_click_script' ) );
|
||||
add_action( 'wp_footer', array( $this, 'render_upgrade_click_script' ) );
|
||||
}
|
||||
|
||||
private function can_show_menu() {
|
||||
return current_user_can( 'manage_options' ) && is_admin_bar_showing();
|
||||
}
|
||||
|
||||
private function is_pro_active() {
|
||||
return function_exists( 'cmatic_is_blessed' ) && cmatic_is_blessed();
|
||||
}
|
||||
|
||||
private function is_pro_installed_not_licensed() {
|
||||
if ( ! defined( 'CMATIC_VERSION' ) ) {
|
||||
return false;
|
||||
}
|
||||
return ! $this->is_pro_active();
|
||||
}
|
||||
|
||||
private function has_plugin_update() {
|
||||
$updates = get_site_transient( 'update_plugins' );
|
||||
if ( ! $updates || ! isset( $updates->response ) ) {
|
||||
return false;
|
||||
}
|
||||
return isset( $updates->response['contact-form-7-mailchimp-extension/chimpmatic-lite.php'] )
|
||||
|| isset( $updates->response['chimpmatic/chimpmatic.php'] );
|
||||
}
|
||||
|
||||
private function should_show_upgrade_badge() {
|
||||
return ! Cmatic_Options_Repository::get_option( 'ui.upgrade_clicked', false );
|
||||
}
|
||||
|
||||
private function get_license_activation_url() {
|
||||
return admin_url( 'admin.php?page=wpcf7-integration&service=0_chimpmatic&action=setup' );
|
||||
}
|
||||
|
||||
private function get_update_url() {
|
||||
return admin_url( 'plugins.php?plugin_status=upgrade' );
|
||||
}
|
||||
|
||||
public function add_menu( WP_Admin_Bar $wp_admin_bar ) {
|
||||
if ( ! $this->can_show_menu() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->add_root_menu( $wp_admin_bar );
|
||||
$this->add_submenu_items( $wp_admin_bar );
|
||||
}
|
||||
|
||||
private function add_root_menu( WP_Admin_Bar $wp_admin_bar ) {
|
||||
$badge_count = 0;
|
||||
|
||||
if ( $this->has_plugin_update() ) {
|
||||
++$badge_count;
|
||||
}
|
||||
|
||||
if ( ! $this->is_pro_active() && $this->should_show_upgrade_badge() ) {
|
||||
++$badge_count;
|
||||
}
|
||||
|
||||
$icon_svg = 'data:image/svg+xml;base64,' . $this->get_icon_base64();
|
||||
$icon_styles = 'width:26px;height:30px;float:left;background:url(\'' . esc_attr( $icon_svg ) . '\') center/20px no-repeat;';
|
||||
|
||||
$title = '<div id="cmatic-ab-icon" class="ab-item cmatic-logo svg" style="' . esc_attr( $icon_styles ) . '">';
|
||||
$title .= '<span class="screen-reader-text">' . esc_html__( 'Chimpmatic Lite', 'chimpmatic-lite' ) . '</span>';
|
||||
$title .= '</div>';
|
||||
|
||||
if ( $badge_count > 0 ) {
|
||||
$title .= $this->get_notification_counter( $badge_count );
|
||||
}
|
||||
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'id' => self::MENU_IDENTIFIER,
|
||||
'title' => $title,
|
||||
'href' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function add_submenu_items( WP_Admin_Bar $wp_admin_bar ) {
|
||||
if ( $this->has_plugin_update() ) {
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'parent' => self::MENU_IDENTIFIER,
|
||||
'id' => 'chimpmatic-update',
|
||||
'title' => esc_html__( 'Update Available', 'chimpmatic-lite' ) . ' ' . $this->get_notification_counter( 1 ),
|
||||
'href' => $this->get_update_url(),
|
||||
'meta' => array(
|
||||
'title' => esc_attr__( 'Update strongly recommended', 'chimpmatic-lite' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( $this->is_pro_installed_not_licensed() ) {
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'parent' => self::MENU_IDENTIFIER,
|
||||
'id' => 'chimpmatic-activate-license',
|
||||
'title' => esc_html__( 'Activate License', 'chimpmatic-lite' ),
|
||||
'href' => $this->get_license_activation_url(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Add Forms submenu with all CF7 forms.
|
||||
$this->add_forms_submenu( $wp_admin_bar );
|
||||
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'parent' => self::MENU_IDENTIFIER,
|
||||
'id' => 'chimpmatic-docs',
|
||||
'title' => esc_html__( 'Documentation', 'chimpmatic-lite' ),
|
||||
'href' => Cmatic_Pursuit::adminbar( 'docs', 'menu_docs' ),
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
'rel' => 'noopener noreferrer',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'parent' => self::MENU_IDENTIFIER,
|
||||
'id' => 'chimpmatic-support',
|
||||
'title' => esc_html__( 'Support', 'chimpmatic-lite' ),
|
||||
'href' => Cmatic_Pursuit::adminbar( 'support', 'menu_support' ),
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
'rel' => 'noopener noreferrer',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'parent' => self::MENU_IDENTIFIER,
|
||||
'id' => 'chimpmatic-reviews',
|
||||
'title' => esc_html__( 'Reviews', 'chimpmatic-lite' ),
|
||||
'href' => 'https://wordpress.org/support/plugin/contact-form-7-mailchimp-extension/reviews/',
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
'rel' => 'noopener noreferrer',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! $this->is_pro_active() ) {
|
||||
$upgrade_title = esc_html__( 'Upgrade to Pro', 'chimpmatic-lite' );
|
||||
|
||||
if ( $this->should_show_upgrade_badge() ) {
|
||||
$upgrade_title .= ' ' . $this->get_notification_counter( 1 );
|
||||
}
|
||||
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'parent' => self::MENU_IDENTIFIER,
|
||||
'id' => 'chimpmatic-upgrade',
|
||||
'title' => $upgrade_title,
|
||||
'href' => Cmatic_Pursuit::adminbar( 'pricing', 'menu_upgrade' ),
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
'rel' => 'noopener noreferrer',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function add_forms_submenu( WP_Admin_Bar $wp_admin_bar ) {
|
||||
// Check if CF7 is active.
|
||||
if ( ! class_exists( 'WPCF7_ContactForm' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all CF7 forms.
|
||||
$forms = WPCF7_ContactForm::find( array( 'posts_per_page' => -1 ) );
|
||||
|
||||
if ( empty( $forms ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add "Form Settings" section header (non-clickable label).
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'parent' => self::MENU_IDENTIFIER,
|
||||
'id' => 'chimpmatic-forms-header',
|
||||
'title' => esc_html__( 'Form Settings', 'chimpmatic-lite' ),
|
||||
'href' => false,
|
||||
)
|
||||
);
|
||||
|
||||
// Add each form directly to main menu (flat, not nested).
|
||||
foreach ( $forms as $form ) {
|
||||
$form_url = admin_url(
|
||||
sprintf(
|
||||
'admin.php?page=wpcf7&post=%d&action=edit&active-tab=Chimpmatic',
|
||||
$form->id()
|
||||
)
|
||||
);
|
||||
|
||||
// Check API connection status for this form.
|
||||
$api_status = $this->get_form_api_status( $form->id() );
|
||||
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'parent' => self::MENU_IDENTIFIER,
|
||||
'id' => 'chimpmatic-form-' . $form->id(),
|
||||
'title' => ' ' . esc_html( $form->title() ) . $api_status,
|
||||
'href' => $form_url,
|
||||
'meta' => array(
|
||||
'class' => 'cmatic-form-item',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_form_api_status( $form_id ) {
|
||||
$cf7_mch = get_option( 'cf7_mch_' . $form_id, array() );
|
||||
|
||||
// Check if API is validated and a list/audience is selected.
|
||||
$is_connected = ! empty( $cf7_mch['api-validation'] )
|
||||
&& 1 == $cf7_mch['api-validation']
|
||||
&& ! empty( $cf7_mch['list'] );
|
||||
|
||||
if ( $is_connected ) {
|
||||
return '<span class="cmatic-api-status cmatic-api-connected" title="' . esc_attr__( 'Connected to Mailchimp API', 'chimpmatic-lite' ) . '">' . esc_html__( 'API', 'chimpmatic-lite' ) . '</span>';
|
||||
}
|
||||
|
||||
return '<span class="cmatic-api-status cmatic-api-disconnected" title="' . esc_attr__( 'Not connected to Mailchimp API', 'chimpmatic-lite' ) . '">' . esc_html__( 'API', 'chimpmatic-lite' ) . '</span>';
|
||||
}
|
||||
|
||||
private function get_notification_counter( $count ) {
|
||||
if ( $count < 1 ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$screen_reader_text = sprintf(
|
||||
/* translators: %s: number of notifications */
|
||||
_n( '%s notification', '%s notifications', $count, 'chimpmatic-lite' ),
|
||||
number_format_i18n( $count )
|
||||
);
|
||||
|
||||
return sprintf(
|
||||
'<div class="wp-core-ui wp-ui-notification cmatic-issue-counter"><span aria-hidden="true">%1$d</span><span class="screen-reader-text">%2$s</span></div>',
|
||||
(int) $count,
|
||||
esc_html( $screen_reader_text )
|
||||
);
|
||||
}
|
||||
|
||||
private function get_settings_url() {
|
||||
if ( class_exists( 'Cmatic_Plugin_Links' ) ) {
|
||||
$url = Cmatic_Plugin_Links::get_settings_url();
|
||||
if ( ! empty( $url ) ) {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
return admin_url( 'admin.php?page=wpcf7' );
|
||||
}
|
||||
|
||||
public function enqueue_assets() {
|
||||
if ( ! $this->can_show_menu() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$css = $this->get_inline_css();
|
||||
wp_add_inline_style( 'admin-bar', $css );
|
||||
}
|
||||
|
||||
private function get_inline_css() {
|
||||
$icon_base64 = $this->get_icon_base64();
|
||||
|
||||
$css = '
|
||||
#wpadminbar .cmatic-logo.svg {
|
||||
background-image: url("data:image/svg+xml;base64,' . $icon_base64 . '");
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 20px;
|
||||
float: left;
|
||||
height: 30px;
|
||||
width: 26px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-chimpmatic-menu .cmatic-form-item .ab-item {
|
||||
background-color: rgba(255,255,255,0.04) !important;
|
||||
padding-left: 20px !important;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-chimpmatic-menu .cmatic-form-item .ab-item:hover {
|
||||
background-color: rgba(255,255,255,0.1) !important;
|
||||
}
|
||||
#wpadminbar .cmatic-api-status {
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
margin-left: 15px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
#wpadminbar .cmatic-api-connected {
|
||||
color: #00ba37;
|
||||
}
|
||||
#wpadminbar .cmatic-api-disconnected {
|
||||
color: #787c82;
|
||||
}
|
||||
#wpadminbar .cmatic-issue-counter {
|
||||
background-color: #d63638;
|
||||
border-radius: 9px;
|
||||
color: #fff;
|
||||
display: inline;
|
||||
padding: 1px 7px 1px 6px !important;
|
||||
}
|
||||
#wpadminbar .quicklinks #wp-admin-bar-chimpmatic-menu #wp-admin-bar-chimpmatic-menu-default li#wp-admin-bar-chimpmatic-upgrade {
|
||||
display: flex;
|
||||
}
|
||||
#wpadminbar .quicklinks #wp-admin-bar-chimpmatic-menu #wp-admin-bar-chimpmatic-menu-default li#wp-admin-bar-chimpmatic-upgrade .ab-item {
|
||||
align-items: center;
|
||||
border-color: transparent;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
margin: 8px 12px;
|
||||
background-color: #00be28;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
padding: 6px 10px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
color: #fff !important;
|
||||
width: 100%;
|
||||
}
|
||||
#wpadminbar .quicklinks #wp-admin-bar-chimpmatic-menu #wp-admin-bar-chimpmatic-menu-default li#wp-admin-bar-chimpmatic-upgrade .ab-item:hover {
|
||||
background-color: #00a522;
|
||||
color: #fff !important;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-chimpmatic-upgrade .cmatic-issue-counter {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
min-width: 18px;
|
||||
border-radius: 50%;
|
||||
padding: 0 !important;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-left: 6px;
|
||||
font-size: 11px;
|
||||
line-height: 1;
|
||||
}
|
||||
@media screen and (max-width: 782px) {
|
||||
#wpadminbar .cmatic-logo.svg {
|
||||
background-position: center 8px;
|
||||
background-size: 30px;
|
||||
height: 46px;
|
||||
width: 52px;
|
||||
}
|
||||
#wpadminbar .cmatic-logo + .cmatic-issue-counter {
|
||||
margin-left: -5px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
';
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
private function get_icon_base64() {
|
||||
$svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2382878c">'
|
||||
. '<path d="M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/>'
|
||||
. '</svg>';
|
||||
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
return base64_encode( $svg );
|
||||
}
|
||||
|
||||
public function render_upgrade_click_script() {
|
||||
if ( ! $this->can_show_menu() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->is_pro_active() || ! $this->should_show_upgrade_badge() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<script>
|
||||
(function() {
|
||||
var upgradeLink = document.querySelector('#wp-admin-bar-chimpmatic-upgrade > a');
|
||||
if (upgradeLink) {
|
||||
upgradeLink.addEventListener('click', function() {
|
||||
fetch('<?php echo esc_url( rest_url( 'chimpmatic-lite/v1/notices/dismiss' ) ); ?>', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-WP-Nonce': '<?php echo esc_js( wp_create_nonce( 'wp_rest' ) ); ?>'
|
||||
},
|
||||
body: JSON.stringify({ notice_id: 'upgrade' })
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Advanced settings panel renderer.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Advanced_Settings {
|
||||
public static function render(): void {
|
||||
?>
|
||||
<table class="form-table mt0 description">
|
||||
<tbody>
|
||||
|
||||
<tr class="">
|
||||
<th scope="row"><?php esc_html_e( 'Unsubscribed', 'chimpmatic-lite' ); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php esc_html_e( 'Unsubscribed', 'chimpmatic-lite' ); ?></span></legend>
|
||||
<label class="cmatic-toggle">
|
||||
<input type="checkbox" id="wpcf7-mailchimp-addunsubscr" name="wpcf7-mailchimp[addunsubscr]" data-field="unsubscribed" value="1" <?php checked( Cmatic_Options_Repository::get_option( 'unsubscribed', false ), true ); ?> />
|
||||
<span class="cmatic-toggle-slider"></span>
|
||||
</label>
|
||||
<span class="cmatic-toggle-label"><?php esc_html_e( 'Marks submitted contacts as unsubscribed.', 'chimpmatic-lite' ); ?></span>
|
||||
<a href="<?php echo esc_url( Cmatic_Pursuit::docs( 'mailchimp-opt-in-checkbox', 'unsubscribed_help' ) ); ?>" class="helping-field" target="_blank" title="<?php esc_attr_e( 'Get help with Custom Fields', 'chimpmatic-lite' ); ?>"> <?php esc_html_e( 'Learn More', 'chimpmatic-lite' ); ?> </a>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Debug Logger', 'chimpmatic-lite' ); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php esc_html_e( 'Debug Logger', 'chimpmatic-lite' ); ?></span></legend>
|
||||
<label class="cmatic-toggle">
|
||||
<input type="checkbox" id="wpcf7-mailchimp-logfileEnabled" data-field="debug" value="1" <?php checked( (bool) Cmatic_Options_Repository::get_option( 'debug', false ), true ); ?> />
|
||||
<span class="cmatic-toggle-slider"></span>
|
||||
</label>
|
||||
<span class="cmatic-toggle-label"><?php esc_html_e( 'Enables activity logging to help troubleshoot form issues.', 'chimpmatic-lite' ); ?></span>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Developer', 'chimpmatic-lite' ); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php esc_html_e( 'Developer', 'chimpmatic-lite' ); ?></span></legend>
|
||||
<label class="cmatic-toggle">
|
||||
<input type="checkbox" id="wpcf7-mailchimp-cf-support" data-field="backlink" value="1" <?php checked( Cmatic_Options_Repository::get_option( 'backlink', false ), true ); ?> />
|
||||
<span class="cmatic-toggle-slider"></span>
|
||||
</label>
|
||||
<span class="cmatic-toggle-label"><?php esc_html_e( 'A backlink to my site, not compulsory, but appreciated', 'chimpmatic-lite' ); ?></span>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Auto Update', 'chimpmatic-lite' ); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php esc_html_e( 'Auto Update', 'chimpmatic-lite' ); ?></span></legend>
|
||||
<label class="cmatic-toggle">
|
||||
<input type="checkbox" id="chimpmatic-update" data-field="auto_update" value="1" <?php checked( (bool) Cmatic_Options_Repository::get_option( 'auto_update', true ), true ); ?> />
|
||||
<span class="cmatic-toggle-slider"></span>
|
||||
</label>
|
||||
<span class="cmatic-toggle-label"><?php esc_html_e( 'Auto Update Chimpmatic Lite', 'chimpmatic-lite' ); ?></span>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Help Us Improve', 'chimpmatic-lite' ); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php esc_html_e( 'Help Us Improve Chimpmatic', 'chimpmatic-lite' ); ?></span></legend>
|
||||
<label class="cmatic-toggle">
|
||||
<input type="checkbox" id="cmatic-telemetry-enabled" data-field="telemetry" value="1" <?php checked( (bool) Cmatic_Options_Repository::get_option( 'telemetry.enabled', true ), true ); ?> />
|
||||
<span class="cmatic-toggle-slider"></span>
|
||||
</label>
|
||||
<span class="cmatic-toggle-label"><?php esc_html_e( 'Help us improve Chimpmatic by sharing anonymous usage data', 'chimpmatic-lite' ); ?></span>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'License Reset', 'chimpmatic-lite' ); ?></th>
|
||||
<td>
|
||||
<fieldset><legend class="screen-reader-text"><span><?php esc_html_e( 'License Reset', 'chimpmatic-lite' ); ?></span></legend>
|
||||
<button type="button" id="cmatic-license-reset-btn" class="button"><?php esc_html_e( 'Reset License Data', 'chimpmatic-lite' ); ?></button>
|
||||
<div id="cmatic-license-reset-message" style="margin-top: 10px;"></div>
|
||||
<small class="description"><?php esc_html_e( 'Clears all cached license data. Use this if you see "zombie activation" issues after deactivating your license.', 'chimpmatic-lite' ); ?></small>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* API key panel UI component.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Api_Panel {
|
||||
const CMATIC_FB_C = '.com';
|
||||
|
||||
public static function mask_key( string $key ): string {
|
||||
if ( empty( $key ) || strlen( $key ) < 12 ) {
|
||||
return $key;
|
||||
}
|
||||
$prefix = substr( $key, 0, 8 );
|
||||
$suffix = substr( $key, -4 );
|
||||
return $prefix . str_repeat( "\u{2022}", 20 ) . $suffix;
|
||||
}
|
||||
|
||||
public static function render( array $cf7_mch, string $apivalid = '0' ): void {
|
||||
$api_key = isset( $cf7_mch['api'] ) ? $cf7_mch['api'] : '';
|
||||
$masked_key = self::mask_key( $api_key );
|
||||
$is_masked = ! empty( $api_key ) && strlen( $api_key ) >= 12;
|
||||
$is_valid = '1' === $apivalid;
|
||||
|
||||
$btn_value = $is_valid ? 'Connected' : 'Sync Audiences';
|
||||
$btn_class = 'button';
|
||||
|
||||
$help_url = Cmatic_Pursuit::docs( 'how-to-get-your-mailchimp-api-key', 'api_panel_help' );
|
||||
|
||||
?>
|
||||
<div class="cmatic-field-group">
|
||||
<label for="cmatic-api"><?php echo esc_html__( 'MailChimp API Key:', 'chimpmatic-lite' ); ?></label><br />
|
||||
<div class="cmatic-api-wrap">
|
||||
<input
|
||||
type="text"
|
||||
id="cmatic-api"
|
||||
name="wpcf7-mailchimp[api]"
|
||||
class="wide"
|
||||
placeholder="<?php echo esc_attr__( 'Enter Your Mailchimp API key Here', 'chimpmatic-lite' ); ?>"
|
||||
value="<?php echo esc_attr( $is_masked ? $masked_key : $api_key ); ?>"
|
||||
data-masked-key="<?php echo esc_attr( $masked_key ); ?>"
|
||||
data-is-masked="<?php echo $is_masked ? '1' : '0'; ?>"
|
||||
data-has-key="<?php echo ! empty( $api_key ) ? '1' : '0'; ?>"
|
||||
/>
|
||||
<button type="button" class="cmatic-eye" title="<?php echo esc_attr__( 'Show/Hide', 'chimpmatic-lite' ); ?>">
|
||||
<span class="dashicons <?php echo $is_masked ? 'dashicons-visibility' : 'dashicons-hidden'; ?>"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<input
|
||||
id="chm_activalist"
|
||||
type="button"
|
||||
value="<?php echo esc_attr( $btn_value ); ?>"
|
||||
class="<?php echo esc_attr( $btn_class ); ?>"
|
||||
/>
|
||||
|
||||
<small class="description need-api">
|
||||
<a href="<?php echo esc_url( $help_url ); ?>" class="helping-field" target="_blank" rel="noopener noreferrer" title="<?php echo esc_attr__( 'Get help with MailChimp API Key', 'chimpmatic-lite' ); ?>">
|
||||
<?php echo esc_html__( 'Find your Mailchimp API here', 'chimpmatic-lite' ); ?>
|
||||
<span class="red-icon dashicons dashicons-arrow-right"></span>
|
||||
<span class="red-icon dashicons dashicons-arrow-right"></span>
|
||||
</a>
|
||||
</small>
|
||||
<div id="chmp-new-user" class="new-user <?php echo esc_attr( '1' === $apivalid ? 'chmp-inactive' : 'chmp-active' ); ?>">
|
||||
<?php Cmatic_Banners::render_new_user_help(); ?>
|
||||
</div>
|
||||
</div><!-- .cmatic-field-group -->
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function output( array $cf7_mch, string $apivalid = '0' ): void {
|
||||
self::render( $cf7_mch, $apivalid );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Mailchimp audiences panel UI.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Audiences {
|
||||
public static function render( string $apivalid, ?array $listdata, array $cf7_mch ): void {
|
||||
// Handle list value - can be string or array (Pro stores as array).
|
||||
$raw_list = isset( $cf7_mch['list'] ) ? $cf7_mch['list'] : '';
|
||||
$vlist = is_array( $raw_list ) ? sanitize_text_field( reset( $raw_list ) ) : sanitize_text_field( $raw_list );
|
||||
$count = isset( $listdata['lists'] ) && is_array( $listdata['lists'] ) ? count( $listdata['lists'] ) : 0;
|
||||
|
||||
$help_url = Cmatic_Pursuit::docs( 'how-to-get-your-mailchimp-api-key', 'audiences_help' );
|
||||
|
||||
$disclosure_class = ( '1' === $apivalid ) ? 'chmp-active' : 'chmp-inactive';
|
||||
|
||||
?>
|
||||
<div class="cmatic-audiences cmatic-field-group <?php echo esc_attr( $disclosure_class ); ?>">
|
||||
<label for="wpcf7-mailchimp-list" id="cmatic-audiences-label">
|
||||
<?php
|
||||
if ( '1' === $apivalid && $count > 0 ) {
|
||||
printf(
|
||||
/* translators: %d: Number of Mailchimp audiences */
|
||||
esc_html__( 'Total Mailchimp Audiences: %d', 'chimpmatic-lite' ),
|
||||
(int) $count
|
||||
);
|
||||
} else {
|
||||
esc_html_e( 'Mailchimp Audiences', 'chimpmatic-lite' );
|
||||
}
|
||||
?>
|
||||
</label><br />
|
||||
|
||||
<select id="wpcf7-mailchimp-list" name="wpcf7-mailchimp[list]">
|
||||
<?php self::render_options( $listdata, $vlist ); ?>
|
||||
</select>
|
||||
|
||||
<button type="button" id="mce_fetch_fields" class="button">
|
||||
<?php esc_html_e( 'Sync Fields', 'chimpmatic-lite' ); ?>
|
||||
</button>
|
||||
|
||||
<small class="description">
|
||||
<?php esc_html_e( 'Hit the Connect button to load your lists', 'chimpmatic-lite' ); ?>
|
||||
<a href="<?php echo esc_url( $help_url ); ?>" class="helping-field" target="_blank" rel="noopener noreferrer" title="<?php esc_attr_e( 'Get help with MailChimp List ID', 'chimpmatic-lite' ); ?>">
|
||||
<?php esc_html_e( 'Learn More', 'chimpmatic-lite' ); ?>
|
||||
</a>
|
||||
</small>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function render_options( ?array $listdata, string $selected_id = '' ): void {
|
||||
if ( ! isset( $listdata['lists'] ) || ! is_array( $listdata['lists'] ) || empty( $listdata['lists'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach ( $listdata['lists'] as $list ) :
|
||||
if ( ! is_array( $list ) || ! isset( $list['id'], $list['name'] ) ) {
|
||||
continue;
|
||||
}
|
||||
++$i;
|
||||
$list_id = sanitize_text_field( $list['id'] );
|
||||
$list_name = sanitize_text_field( $list['name'] );
|
||||
$member_count = isset( $list['stats']['member_count'] ) ? (int) $list['stats']['member_count'] : 0;
|
||||
$field_count = isset( $list['stats']['merge_field_count'] ) ? (int) $list['stats']['merge_field_count'] : 0;
|
||||
$selected = selected( $selected_id, $list_id, false );
|
||||
?>
|
||||
<option value="<?php echo esc_attr( $list_id ); ?>" <?php echo $selected; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- selected() returns pre-escaped output ?>>
|
||||
<?php
|
||||
printf(
|
||||
'%d:%d %s %d fields #%s',
|
||||
(int) $i,
|
||||
(int) $member_count,
|
||||
esc_html( $list_name ),
|
||||
(int) $field_count,
|
||||
esc_html( $list_id )
|
||||
);
|
||||
?>
|
||||
</option>
|
||||
<?php
|
||||
endforeach;
|
||||
}
|
||||
|
||||
public static function output( string $apivalid, ?array $listdata, array $cf7_mch ): void {
|
||||
self::render( $apivalid, $listdata, $cf7_mch );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin UI banners and frontend credit.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Banners {
|
||||
public static function init(): void {
|
||||
add_filter( 'wpcf7_form_response_output', array( __CLASS__, 'maybe_append_backlink' ), 10, 4 );
|
||||
}
|
||||
|
||||
public static function maybe_append_backlink( string $output, string $class, string $content, $contact_form ): string {
|
||||
// Check if backlink setting is enabled.
|
||||
if ( ! Cmatic_Options_Repository::get_option( 'backlink', false ) ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Check if this form has Chimpmatic configured.
|
||||
$form_id = $contact_form->id();
|
||||
$cf7_mch = get_option( 'cf7_mch_' . $form_id, array() );
|
||||
|
||||
if ( empty( $cf7_mch ) || empty( $cf7_mch['api-validation'] ) ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Append the author credit.
|
||||
return $output . self::get_author_credit();
|
||||
}
|
||||
|
||||
private const DEFAULT_WELCOME = '<p class="about-description">Hello. My name is Renzo, I <span alt="f487" class="dashicons dashicons-heart red-icon"> </span> WordPress and I develop this free plugin to help users like you. I drink copious amounts of coffee to keep me running longer <span alt="f487" class="dashicons dashicons-smiley red-icon"> </span>. If you\'ve found this plugin useful, please consider making a donation.</p><br>
|
||||
<p class="about-description">Would you like to <a class="button-primary" href="https://bit.ly/cafe4renzo" target="_blank">buy me a coffee?</a> or <a class="button-primary" href="https://bit.ly/cafe4renzo" target="_blank">Donate with Paypal</a></p>';
|
||||
|
||||
public static function get_welcome(): string {
|
||||
$banner = get_site_option( 'mce_conten_panel_welcome', self::DEFAULT_WELCOME );
|
||||
|
||||
return empty( trim( $banner ) ) ? self::DEFAULT_WELCOME : $banner;
|
||||
}
|
||||
|
||||
public static function render_lateral(): void {
|
||||
?>
|
||||
<div id="informationdiv_aux" class="postbox mce-move mce-hidden mc-lateral">
|
||||
<?php echo wp_kses_post( self::get_lateral_content() ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function get_lateral_content(): string {
|
||||
return '
|
||||
<div class="inside bg-f2"><h3>Upgrade to PRO</h3>
|
||||
<p>We have the the best tool to integrate <b>Contact Form 7</b> & <b>Mailchimp.com</b> mailing lists. We have new nifty features:</p>
|
||||
<ul>
|
||||
<li>Tag Existing Subscribers</li>
|
||||
<li>Group Existing Subscribers</li>
|
||||
<li>Email Verification</li>
|
||||
<li>AWESOME Support And more!</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="promo-2022">
|
||||
<h1>40<span>%</span> Off!</h1>
|
||||
<p class="interesting">Submit your name and email and we\'ll send you a coupon for <b>40% off</b> your upgrade to the pro version.</p>
|
||||
<div class="cm-form" id="promo-form-container">
|
||||
<!-- Form will be injected by JavaScript after page load to prevent CF7 from stripping it -->
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
public static function render_new_user_help(): void {
|
||||
$help_url = Cmatic_Pursuit::docs( 'how-to-get-your-mailchimp-api-key', 'new_user_help' );
|
||||
?>
|
||||
<h2>
|
||||
<a href="<?php echo esc_url( $help_url ); ?>" class="helping-field" target="_blank" rel="noopener noreferrer">
|
||||
<?php esc_html_e( 'How to get your Mailchimp API key.', 'chimpmatic-lite' ); ?>
|
||||
</a>
|
||||
</h2>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function get_author_credit(): string {
|
||||
$url = 'https://chimpmatic.com/?utm_source=client_site&utm_medium=backlink&utm_campaign=powered_by';
|
||||
|
||||
$html = '<p style="display: none !important">';
|
||||
$html .= '<a href="' . esc_url( $url ) . '" rel="noopener" target="_blank">ChimpMatic</a>';
|
||||
$html .= ' – CF7 Mailchimp Integration';
|
||||
$html .= '</p>' . "\n";
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Data container element renderer.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Data_Container {
|
||||
const ELEMENT_ID = 'cmatic_data';
|
||||
|
||||
public static function render( int $form_id, string $apivalid = '0', array $extra = array() ): void {
|
||||
$attrs_html = self::build_data_attrs( $form_id, $apivalid, $extra );
|
||||
|
||||
printf(
|
||||
'<div id="%s"%s style="display:none;"></div>',
|
||||
esc_attr( self::ELEMENT_ID ),
|
||||
$attrs_html
|
||||
);
|
||||
}
|
||||
|
||||
public static function render_open( int $form_id, string $apivalid = '0', array $extra = array() ): void {
|
||||
$attrs_html = self::build_data_attrs( $form_id, $apivalid, $extra );
|
||||
|
||||
printf(
|
||||
'<div id="%s" class="cmatic-inner"%s>',
|
||||
esc_attr( self::ELEMENT_ID ),
|
||||
$attrs_html
|
||||
);
|
||||
}
|
||||
|
||||
public static function render_close(): void {
|
||||
echo '</div><!-- #cmatic_data.cmatic-inner -->';
|
||||
}
|
||||
|
||||
private static function build_data_attrs( int $form_id, string $apivalid = '0', array $extra = array() ): string {
|
||||
$data_attrs = array(
|
||||
'form-id' => $form_id,
|
||||
'api-valid' => $apivalid,
|
||||
);
|
||||
|
||||
foreach ( $extra as $key => $value ) {
|
||||
$key = str_replace( '_', '-', sanitize_key( $key ) );
|
||||
|
||||
if ( is_array( $value ) || is_object( $value ) ) {
|
||||
$data_attrs[ $key ] = wp_json_encode( $value );
|
||||
} else {
|
||||
$data_attrs[ $key ] = esc_attr( $value );
|
||||
}
|
||||
}
|
||||
|
||||
$attrs_html = '';
|
||||
foreach ( $data_attrs as $key => $value ) {
|
||||
$attrs_html .= sprintf( ' data-%s="%s"', esc_attr( $key ), esc_attr( $value ) );
|
||||
}
|
||||
|
||||
return $attrs_html;
|
||||
}
|
||||
|
||||
public static function get_element_id(): string {
|
||||
return self::ELEMENT_ID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* Field mapping UI components.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Cmatic_Field_Mapper_UI {
|
||||
public static function render( int $api_valid, ?array $list_data, array $cf7_mch, array $form_tags, int $form_id ): void {
|
||||
$disclosure_class = ( 1 === $api_valid ) ? 'chmp-active' : 'chmp-inactive';
|
||||
|
||||
$total_merge = isset( $cf7_mch['total_merge_fields'] ) ? (int) $cf7_mch['total_merge_fields'] : 0;
|
||||
$show_notice = $total_merge > CMATIC_LITE_FIELDS;
|
||||
$notice_class = $show_notice ? 'cmatic-visible' : 'cmatic-hidden';
|
||||
$audience_name = self::resolve_audience_name( $cf7_mch );
|
||||
$docs_url = Cmatic_Pursuit::url( 'https://chimpmatic.com/mailchimp-default-audience-fields-explained', 'plugin', 'fields_notice', 'docs' );
|
||||
?>
|
||||
<div class="mce-custom-fields <?php echo esc_attr( $disclosure_class ); ?>" id="cmatic-fields">
|
||||
<?php
|
||||
self::render_merge_fields( $cf7_mch, $form_tags );
|
||||
self::render_optin_checkbox( $form_tags, $cf7_mch, $form_id );
|
||||
self::render_double_optin( $cf7_mch );
|
||||
?>
|
||||
<div class="cmatic-defaults-fields-notice <?php echo esc_attr( $notice_class ); ?>" id="cmatic-fields-notice">
|
||||
<p class="cmatic-notice">
|
||||
<?php if ( $show_notice ) : ?>
|
||||
<?php
|
||||
$notice_text = sprintf(
|
||||
/* translators: 1: audience name wrapped in <strong>, 2: total merge fields count, 3: lite fields limit */
|
||||
__( 'Your %1$s audience has %2$d merge fields. Chimpmatic Lite supports up to %3$d field mappings.', 'chimpmatic-lite' ),
|
||||
'<strong>' . esc_html( $audience_name ) . '</strong>',
|
||||
$total_merge,
|
||||
CMATIC_LITE_FIELDS
|
||||
);
|
||||
echo wp_kses( $notice_text, array( 'strong' => array() ) );
|
||||
?>
|
||||
<a href="<?php echo esc_url( $docs_url ); ?>" class="helping-field" target="_blank" rel="noopener noreferrer">
|
||||
<?php esc_html_e( 'Read More', 'chimpmatic-lite' ); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
Cmatic_Tags_Preview::render( $form_tags, $cf7_mch, $api_valid );
|
||||
}
|
||||
|
||||
private static function render_merge_fields( array $cf7_mch, array $form_tags ): void {
|
||||
$merge_fields = $cf7_mch['merge_fields'] ?? array();
|
||||
$max_fields = CMATIC_LITE_FIELDS;
|
||||
|
||||
for ( $i = 0; $i < $max_fields; $i++ ) {
|
||||
$field_index = $i + 3;
|
||||
$field_key = 'field' . $field_index;
|
||||
$merge_field = $merge_fields[ $i ] ?? null;
|
||||
|
||||
$field_config = self::build_field_config( $merge_field, $field_index );
|
||||
self::render_field_row( $field_key, $form_tags, $cf7_mch, $field_config );
|
||||
}
|
||||
}
|
||||
|
||||
private static function build_field_config( ?array $merge_field, int $field_index ): array {
|
||||
if ( null === $merge_field ) {
|
||||
return array(
|
||||
'label' => 'Field ' . $field_index,
|
||||
'type' => 'text',
|
||||
'required' => false,
|
||||
'description' => 'Map a form field to Mailchimp',
|
||||
'merge_tag' => '',
|
||||
);
|
||||
}
|
||||
|
||||
$tag = $merge_field['tag'] ?? '';
|
||||
$name = $merge_field['name'] ?? $tag;
|
||||
$type = $merge_field['type'] ?? 'text';
|
||||
|
||||
$config = array(
|
||||
'label' => $name . ' - *|' . $tag . '|* <span class="mce-type">' . esc_html( $type ) . '</span>',
|
||||
'type' => 'text',
|
||||
'required' => false,
|
||||
'description' => 'Map a form field to Mailchimp',
|
||||
'merge_tag' => $tag,
|
||||
);
|
||||
|
||||
if ( 'EMAIL' === $tag ) {
|
||||
$config['required'] = true;
|
||||
$config['type'] = 'email';
|
||||
$config['description'] = 'MUST be an email tag <a href="' . esc_url( Cmatic_Pursuit::docs( 'mailchimp-required-email', 'email_field' ) ) . '" class="helping-field" target="_blank" title="get help with Subscriber Email:"> Learn More</a>';
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
private static function render_field_row( string $field_key, array $form_tags, array $cf7_mch, array $config ): void {
|
||||
?>
|
||||
<div class="mcee-container">
|
||||
<label for="wpcf7-mailchimp-<?php echo esc_attr( $field_key ); ?>">
|
||||
<?php
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is pre-escaped in build_field_config.
|
||||
echo $config['label'];
|
||||
?>
|
||||
<?php if ( $config['required'] ) : ?>
|
||||
<span class="mce-required">Required</span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php self::render_dropdown( $field_key, $form_tags, $cf7_mch, $config['type'], $config['merge_tag'] ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function render_dropdown( string $field_name, array $form_tags, array $cf7_mch, string $filter = '', string $merge_tag = '' ): void {
|
||||
$field_name = sanitize_key( $field_name );
|
||||
$saved_value = isset( $cf7_mch[ $field_name ] ) ? trim( sanitize_text_field( $cf7_mch[ $field_name ] ) ) : '';
|
||||
|
||||
if ( '' === $saved_value && ! empty( $merge_tag ) ) {
|
||||
$saved_value = self::auto_match_field( $form_tags, $merge_tag, $filter );
|
||||
}
|
||||
?>
|
||||
<select class="chm-select" id="wpcf7-mailchimp-<?php echo esc_attr( $field_name ); ?>" name="wpcf7-mailchimp[<?php echo esc_attr( $field_name ); ?>]">
|
||||
<?php if ( 'email' !== $filter ) : ?>
|
||||
<option value="" <?php selected( $saved_value, '' ); ?>>
|
||||
<?php esc_html_e( 'Choose..', 'chimpmatic-lite' ); ?>
|
||||
</option>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ( $form_tags as $tag ) : ?>
|
||||
<?php
|
||||
if ( 'opt-in' === $tag['name'] ) {
|
||||
continue;
|
||||
}
|
||||
if ( 'email' === $filter ) {
|
||||
$is_email = ( 'email' === $tag['basetype'] || false !== strpos( strtolower( $tag['name'] ), 'email' ) );
|
||||
if ( ! $is_email ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$tag_value = '[' . $tag['name'] . ']';
|
||||
?>
|
||||
<option value="<?php echo esc_attr( $tag_value ); ?>" <?php selected( $saved_value, $tag_value ); ?>>
|
||||
<?php echo esc_html( $tag_value ); ?> - type: <?php echo esc_html( $tag['basetype'] ); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function auto_match_field( array $form_tags, string $merge_tag, string $filter ): string {
|
||||
$merge_tag_lower = strtolower( $merge_tag );
|
||||
|
||||
foreach ( $form_tags as $tag ) {
|
||||
if ( 'email' === $filter ) {
|
||||
if ( 'email' === $tag['basetype'] || false !== strpos( strtolower( $tag['name'] ), 'email' ) ) {
|
||||
return '[' . $tag['name'] . ']';
|
||||
}
|
||||
} elseif ( false !== strpos( strtolower( $tag['name'] ), $merge_tag_lower ) ) {
|
||||
return '[' . $tag['name'] . ']';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private static function render_optin_checkbox( array $form_tags, array $cf7_mch, int $form_id ): void {
|
||||
$checkbox_types = array( 'checkbox', 'acceptance' );
|
||||
$checkbox_fields = array_filter(
|
||||
$form_tags,
|
||||
function ( $field ) use ( $checkbox_types ) {
|
||||
return in_array( $field['basetype'], $checkbox_types, true );
|
||||
}
|
||||
);
|
||||
?>
|
||||
<div class="mcee-container">
|
||||
<label for="wpcf7-mailchimp-accept">
|
||||
<?php esc_html_e( 'Opt-in Checkbox', 'chimpmatic-lite' ); ?>
|
||||
<span class="mce-type"><?php esc_html_e( 'Optional', 'chimpmatic-lite' ); ?></span>
|
||||
</label>
|
||||
<select class="chm-select" id="wpcf7-mailchimp-accept" name="wpcf7-mailchimp[accept]">
|
||||
<option value=" " <?php selected( $cf7_mch['accept'] ?? ' ', ' ' ); ?>>
|
||||
<?php esc_html_e( 'None - Always subscribe', 'chimpmatic-lite' ); ?>
|
||||
</option>
|
||||
<?php if ( empty( $checkbox_fields ) ) : ?>
|
||||
<option value="" disabled>
|
||||
<?php
|
||||
$form_title = '';
|
||||
if ( function_exists( 'wpcf7_contact_form' ) ) {
|
||||
$form_obj = wpcf7_contact_form( $form_id );
|
||||
$form_title = $form_obj ? $form_obj->title() : '';
|
||||
}
|
||||
printf(
|
||||
/* translators: %s: Form title */
|
||||
esc_html__( '"%s" has no [checkbox] or [acceptance] fields', 'chimpmatic-lite' ),
|
||||
esc_html( $form_title )
|
||||
);
|
||||
?>
|
||||
</option>
|
||||
<?php else : ?>
|
||||
<?php foreach ( $checkbox_fields as $field ) : ?>
|
||||
<?php
|
||||
$field_value = '[' . $field['name'] . ']';
|
||||
$saved_value = $cf7_mch['accept'] ?? ' ';
|
||||
?>
|
||||
<option value="<?php echo esc_attr( $field_value ); ?>" <?php selected( $saved_value, $field_value ); ?>>
|
||||
<?php echo esc_html( '[' . $field['name'] . ']' ); ?> - type: <?php echo esc_html( $field['basetype'] ); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
<small class="description">
|
||||
<?php esc_html_e( 'Only subscribe if this checkbox is checked', 'chimpmatic-lite' ); ?>
|
||||
<a href="<?php echo esc_url( Cmatic_Pursuit::docs( 'mailchimp-opt-in-checkbox', 'optin_field' ) ); ?>" class="helping-field" target="_blank"><?php esc_html_e( 'Learn More', 'chimpmatic-lite' ); ?></a>
|
||||
</small>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function render_double_optin( array $cf7_mch ): void {
|
||||
$value = ! empty( $cf7_mch['double_optin'] ) || ! empty( $cf7_mch['confsubs'] ) ? '1' : '0';
|
||||
?>
|
||||
<div class="mcee-container">
|
||||
<label for="wpcf7-mailchimp-double-optin">
|
||||
<?php esc_html_e( 'Double Opt-in', 'chimpmatic-lite' ); ?>
|
||||
<span class="mce-type"><?php esc_html_e( 'Optional', 'chimpmatic-lite' ); ?></span>
|
||||
</label>
|
||||
<select class="chm-select" id="wpcf7-mailchimp-double-optin" name="wpcf7-mailchimp[confsubs]" data-field="double_optin">
|
||||
<option value="0" <?php selected( $value, '0' ); ?>>
|
||||
<?php esc_html_e( 'Subscribers are added immediately', 'chimpmatic-lite' ); ?>
|
||||
</option>
|
||||
<option value="1" <?php selected( $value, '1' ); ?>>
|
||||
<?php esc_html_e( 'Subscribers must confirm via email', 'chimpmatic-lite' ); ?>
|
||||
</option>
|
||||
</select>
|
||||
<small class="description">
|
||||
<?php esc_html_e( 'Choose how subscribers are added to your Mailchimp list', 'chimpmatic-lite' ); ?>
|
||||
<a href="<?php echo esc_url( Cmatic_Pursuit::docs( 'mailchimp-double-opt-in', 'double_optin' ) ); ?>" class="helping-field" target="_blank"><?php esc_html_e( 'Learn More', 'chimpmatic-lite' ); ?></a>
|
||||
</small>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function resolve_audience_name( array $cf7_mch ): string {
|
||||
$list_id = $cf7_mch['list'] ?? '';
|
||||
$lists = $cf7_mch['lisdata']['lists'] ?? array();
|
||||
|
||||
foreach ( $lists as $list ) {
|
||||
if ( isset( $list['id'], $list['name'] ) && $list['id'] === $list_id ) {
|
||||
return $list['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function __construct() {}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* CF7 form CSS class injector.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Form_Classes {
|
||||
public static function init(): void {
|
||||
add_filter( 'wpcf7_form_class_attr', array( __CLASS__, 'add_classes' ) );
|
||||
}
|
||||
|
||||
public static function add_classes( string $class_attr ): string {
|
||||
$classes = array();
|
||||
|
||||
// 1. Install ID (pure, no prefix) - stored at install.id.
|
||||
$install_id = Cmatic_Options_Repository::get_option( 'install.id', '' );
|
||||
if ( ! empty( $install_id ) ) {
|
||||
$classes[] = sanitize_html_class( $install_id );
|
||||
}
|
||||
|
||||
// 2. API connection status - check if first_connected timestamp exists.
|
||||
$first_connected = Cmatic_Options_Repository::get_option( 'api.first_connected', 0 );
|
||||
if ( ! empty( $first_connected ) ) {
|
||||
$classes[] = 'cmatic-conn';
|
||||
} else {
|
||||
$classes[] = 'cmatic-disconn';
|
||||
}
|
||||
|
||||
// 3. Audience count - stored in lisdata.lists array.
|
||||
$lisdata = Cmatic_Options_Repository::get_option( 'lisdata', array() );
|
||||
$lists = isset( $lisdata['lists'] ) && is_array( $lisdata['lists'] ) ? $lisdata['lists'] : array();
|
||||
$aud_count = count( $lists );
|
||||
$classes[] = 'cmatic-aud-' . $aud_count;
|
||||
|
||||
// 4. Mapped fields (form-specific).
|
||||
$contact_form = wpcf7_get_current_contact_form();
|
||||
if ( $contact_form ) {
|
||||
$form_id = $contact_form->id();
|
||||
$cf7_mch = get_option( 'cf7_mch_' . $form_id, array() );
|
||||
$mapped = self::count_mapped_fields( $cf7_mch );
|
||||
$total = self::count_total_merge_fields( $cf7_mch );
|
||||
$classes[] = 'cmatic-mapd' . $mapped . '-' . $total;
|
||||
}
|
||||
|
||||
// 5. Lite version (SPARTAN_MCE_VERSION).
|
||||
if ( defined( 'SPARTAN_MCE_VERSION' ) ) {
|
||||
$version = str_replace( '.', '', SPARTAN_MCE_VERSION );
|
||||
$classes[] = 'cmatic-v' . $version;
|
||||
}
|
||||
|
||||
// 6. Pro version (CMATIC_VERSION) if active.
|
||||
if ( defined( 'CMATIC_VERSION' ) ) {
|
||||
$pro_version = str_replace( '.', '', CMATIC_VERSION );
|
||||
$classes[] = 'cmatic-pro-v' . $pro_version;
|
||||
}
|
||||
|
||||
// 7. Per-form sent count.
|
||||
if ( $contact_form ) {
|
||||
$form_sent = (int) ( $cf7_mch['stats_sent'] ?? 0 );
|
||||
$classes[] = 'cmatic-sent-' . $form_sent;
|
||||
}
|
||||
|
||||
// 8. Global total sent.
|
||||
$total_sent = (int) Cmatic_Options_Repository::get_option( 'stats.sent', 0 );
|
||||
$classes[] = 'cmatic-total-' . $total_sent;
|
||||
|
||||
// Append to existing classes.
|
||||
if ( ! empty( $classes ) ) {
|
||||
$class_attr .= ' ' . implode( ' ', $classes );
|
||||
}
|
||||
|
||||
return $class_attr;
|
||||
}
|
||||
|
||||
private static function count_mapped_fields( array $cf7_mch ): int {
|
||||
$merge_fields = isset( $cf7_mch['merge_fields'] ) && is_array( $cf7_mch['merge_fields'] )
|
||||
? $cf7_mch['merge_fields']
|
||||
: array();
|
||||
|
||||
if ( empty( $merge_fields ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$mapped = 0;
|
||||
foreach ( $merge_fields as $index => $field ) {
|
||||
$field_key = 'field' . ( $index + 3 );
|
||||
if ( ! empty( $cf7_mch[ $field_key ] ) && '--' !== $cf7_mch[ $field_key ] ) {
|
||||
++$mapped;
|
||||
}
|
||||
}
|
||||
|
||||
return $mapped;
|
||||
}
|
||||
|
||||
private static function count_total_merge_fields( array $cf7_mch ): int {
|
||||
$merge_fields = isset( $cf7_mch['merge_fields'] ) && is_array( $cf7_mch['merge_fields'] )
|
||||
? $cf7_mch['merge_fields']
|
||||
: array();
|
||||
|
||||
return count( $merge_fields );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* Settings page header component.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Header {
|
||||
const CMATIC_FB_B = '@gmail';
|
||||
|
||||
private $version;
|
||||
private $is_pro;
|
||||
private $api_status;
|
||||
private $review_url;
|
||||
private $review_phrases;
|
||||
|
||||
|
||||
public function __construct( array $args = array() ) {
|
||||
$this->version = $this->resolve_version( $args );
|
||||
$this->is_pro = $this->resolve_pro_status( $args );
|
||||
$this->api_status = isset( $args['api_status'] ) && is_string( $args['api_status'] ) ? $args['api_status'] : null;
|
||||
$this->review_url = isset( $args['review_url'] ) && is_string( $args['review_url'] ) ? $args['review_url'] : $this->get_default_review_url();
|
||||
|
||||
$this->review_phrases = array(
|
||||
__( 'Loving Chimpmatic? Leave a review', 'chimpmatic-lite' ),
|
||||
__( 'We run on coffee & 5-star reviews', 'chimpmatic-lite' ),
|
||||
__( 'Make a developer smile today', 'chimpmatic-lite' ),
|
||||
__( 'Got 10 seconds? Rate us!', 'chimpmatic-lite' ),
|
||||
__( 'Fuel our plugin addiction', 'chimpmatic-lite' ),
|
||||
__( 'Stars make us code faster', 'chimpmatic-lite' ),
|
||||
__( 'Help us stay free & caffeinated', 'chimpmatic-lite' ),
|
||||
__( "Love us? Don't keep it a secret", 'chimpmatic-lite' ),
|
||||
__( 'Your review = our dopamine', 'chimpmatic-lite' ),
|
||||
__( 'Be our hero on WordPress.org', 'chimpmatic-lite' ),
|
||||
__( 'Psst... we love 5 stars', 'chimpmatic-lite' ),
|
||||
__( 'Worth 5 stars? Let us know', 'chimpmatic-lite' ),
|
||||
__( 'Support indie plugins', 'chimpmatic-lite' ),
|
||||
__( 'Reviews keep the lights on', 'chimpmatic-lite' ),
|
||||
__( 'Spread the Chimpmatic love', 'chimpmatic-lite' ),
|
||||
__( 'Got love? Leave stars', 'chimpmatic-lite' ),
|
||||
__( 'One click, endless gratitude', 'chimpmatic-lite' ),
|
||||
__( 'Help other WP folks find us', 'chimpmatic-lite' ),
|
||||
__( 'Like us? Rate us!', 'chimpmatic-lite' ),
|
||||
__( 'Your stars = our motivation', 'chimpmatic-lite' ),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function resolve_version( array $args ): string {
|
||||
if ( isset( $args['version'] ) && is_string( $args['version'] ) ) {
|
||||
return $args['version'];
|
||||
}
|
||||
|
||||
if ( defined( 'CMATIC_VERSION' ) ) {
|
||||
return (string) CMATIC_VERSION;
|
||||
}
|
||||
|
||||
if ( defined( 'SPARTAN_MCE_VERSION' ) ) {
|
||||
return (string) SPARTAN_MCE_VERSION;
|
||||
}
|
||||
|
||||
return '0.0.0';
|
||||
}
|
||||
|
||||
|
||||
private function resolve_pro_status( array $args ): bool {
|
||||
if ( isset( $args['is_pro'] ) ) {
|
||||
return (bool) $args['is_pro'];
|
||||
}
|
||||
|
||||
if ( function_exists( 'cmatic_is_blessed' ) ) {
|
||||
return (bool) cmatic_is_blessed();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private function get_default_review_url(): string {
|
||||
return 'https://wordpress.org/support/plugin/contact-form-7-mailchimp-extension/reviews/';
|
||||
}
|
||||
|
||||
|
||||
private function get_review_phrase(): string {
|
||||
$index = wp_rand( 0, count( $this->review_phrases ) - 1 );
|
||||
return $this->review_phrases[ $index ];
|
||||
}
|
||||
|
||||
|
||||
public function render(): void {
|
||||
$badge_class = $this->is_pro ? 'cmatic-header__badge--pro' : 'cmatic-header__badge--lite';
|
||||
$badge_text = $this->is_pro ? __( 'PRO', 'chimpmatic-lite' ) : __( 'Lite', 'chimpmatic-lite' );
|
||||
?>
|
||||
<header class="cmatic-header">
|
||||
<div class="cmatic-header__inner">
|
||||
<div class="cmatic-header__brand">
|
||||
<span class="cmatic-header__title"><?php esc_html_e( 'Chimpmatic', 'chimpmatic-lite' ); ?></span>
|
||||
<span class="cmatic-header__badge <?php echo esc_attr( $badge_class ); ?>"><?php echo esc_html( $badge_text ); ?></span>
|
||||
<span class="cmatic-header__version">v<?php echo esc_html( $this->version ); ?></span>
|
||||
<?php $this->render_api_status(); ?>
|
||||
</div>
|
||||
<div class="cmatic-header__actions">
|
||||
<a href="<?php echo esc_url( $this->review_url ); ?>" target="_blank" rel="noopener noreferrer" class="cmatic-header__review">
|
||||
<?php echo esc_html( $this->get_review_phrase() ); ?>
|
||||
<span class="cmatic-sparkles" aria-label="5 sparkles"></span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
private function render_api_status(): void {
|
||||
if ( null === $this->api_status ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$is_connected = ( 'connected' === $this->api_status );
|
||||
$dot_class = $is_connected ? 'cmatic-header__status-dot--connected' : 'cmatic-header__status-dot--disconnected';
|
||||
$status_text = $is_connected
|
||||
? __( 'API Connected', 'chimpmatic-lite' )
|
||||
: __( 'API Inactive', 'chimpmatic-lite' );
|
||||
?>
|
||||
<div class="cmatic-header__status">
|
||||
<span class="cmatic-header__status-dot <?php echo esc_attr( $dot_class ); ?>"></span>
|
||||
<span class="cmatic-header__status-text"><?php echo esc_html( $status_text ); ?></span>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
public function set_api_status( ?string $status ): self {
|
||||
$this->api_status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public static function output( array $args = array() ): void {
|
||||
$header = new self( $args );
|
||||
$header->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* Modal base class.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'Cmatic_Modal' ) ) {
|
||||
abstract class Cmatic_Modal {
|
||||
protected $modal_id;
|
||||
protected $admin_hooks = array();
|
||||
protected $initialized = false;
|
||||
|
||||
public function __construct( $modal_id, $admin_hooks = array() ) {
|
||||
$this->modal_id = sanitize_key( $modal_id );
|
||||
$this->admin_hooks = is_array( $admin_hooks ) ? $admin_hooks : array( $admin_hooks );
|
||||
}
|
||||
|
||||
public function init() {
|
||||
if ( $this->initialized ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'maybe_enqueue_assets' ) );
|
||||
add_action( $this->get_render_hook(), array( $this, 'maybe_render_modal' ), $this->get_render_priority(), $this->get_render_args() );
|
||||
|
||||
$this->initialized = true;
|
||||
}
|
||||
|
||||
protected function get_render_hook() {
|
||||
return 'admin_footer';
|
||||
}
|
||||
|
||||
protected function get_render_priority() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
protected function get_render_args() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function is_valid_admin_page( $hook ) {
|
||||
if ( empty( $this->admin_hooks ) ) {
|
||||
return true;
|
||||
}
|
||||
return in_array( $hook, $this->admin_hooks, true );
|
||||
}
|
||||
|
||||
public function maybe_enqueue_assets( $hook ) {
|
||||
if ( ! $this->is_valid_admin_page( $hook ) ) {
|
||||
return;
|
||||
}
|
||||
$this->enqueue_assets( $hook );
|
||||
}
|
||||
|
||||
public function maybe_render_modal() {
|
||||
$screen = get_current_screen();
|
||||
if ( ! $screen ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_hook = $screen->id;
|
||||
if ( ! empty( $this->admin_hooks ) && ! in_array( $current_hook, $this->admin_hooks, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->render_modal();
|
||||
}
|
||||
|
||||
protected function enqueue_assets( $hook ) {
|
||||
}
|
||||
|
||||
protected function render_modal() {
|
||||
$title = $this->get_title();
|
||||
$body = $this->get_body();
|
||||
$footer = $this->get_footer();
|
||||
$extra_class = $this->get_extra_class();
|
||||
$description = $this->get_description();
|
||||
|
||||
?>
|
||||
<div id="<?php echo esc_attr( $this->modal_id ); ?>"
|
||||
class="cmatic-modal <?php echo esc_attr( $extra_class ); ?>"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="<?php echo esc_attr( $this->modal_id ); ?>-title"
|
||||
<?php if ( $description ) : ?>
|
||||
aria-describedby="<?php echo esc_attr( $this->modal_id ); ?>-description"
|
||||
<?php endif; ?>
|
||||
>
|
||||
<div class="cmatic-modal__overlay"></div>
|
||||
<div class="cmatic-modal__dialog">
|
||||
<div class="cmatic-modal__header">
|
||||
<h2 id="<?php echo esc_attr( $this->modal_id ); ?>-title"><?php echo esc_html( $title ); ?></h2>
|
||||
<?php $this->render_header_actions(); ?>
|
||||
<button type="button" class="cmatic-modal__close" aria-label="<?php esc_attr_e( 'Close dialog', 'chimpmatic-lite' ); ?>">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="cmatic-modal__body">
|
||||
<?php if ( $description ) : ?>
|
||||
<p id="<?php echo esc_attr( $this->modal_id ); ?>-description" class="cmatic-modal__description">
|
||||
<?php echo esc_html( $description ); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $body;
|
||||
?>
|
||||
</div>
|
||||
<?php if ( $footer ) : ?>
|
||||
<div class="cmatic-modal__footer">
|
||||
<?php
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $footer;
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function render_header_actions() {
|
||||
}
|
||||
|
||||
abstract protected function get_title();
|
||||
|
||||
abstract protected function get_body();
|
||||
|
||||
protected function get_footer() {
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function get_description() {
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function get_extra_class() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_modal_id() {
|
||||
return $this->modal_id;
|
||||
}
|
||||
|
||||
protected function get_strings() {
|
||||
return array(
|
||||
'closeLabel' => __( 'Close dialog', 'chimpmatic-lite' ),
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_js_data() {
|
||||
return array(
|
||||
'modalId' => $this->modal_id,
|
||||
'strings' => $this->get_strings(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* Notification center manager.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Notification_Center {
|
||||
const STORAGE_KEY = 'cmatic_notifications';
|
||||
|
||||
private static $instance = null;
|
||||
private $notifications = array();
|
||||
private $notifications_retrieved = false;
|
||||
private $notifications_dirty = false;
|
||||
|
||||
public static function get() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
add_action( 'init', array( $this, 'setup_notifications' ), 1 );
|
||||
add_action( 'shutdown', array( $this, 'save_notifications' ) );
|
||||
}
|
||||
|
||||
public function setup_notifications() {
|
||||
$this->retrieve_notifications();
|
||||
$this->add_dynamic_notifications();
|
||||
}
|
||||
|
||||
private function retrieve_notifications() {
|
||||
if ( $this->notifications_retrieved ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->notifications_retrieved = true;
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
if ( ! $user_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stored = get_user_option( self::STORAGE_KEY, $user_id );
|
||||
|
||||
if ( ! is_array( $stored ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $stored as $data ) {
|
||||
$notification = Cmatic_Notification::from_array( $data );
|
||||
if ( $notification->display_for_current_user() ) {
|
||||
$this->notifications[] = $notification;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function add_dynamic_notifications() {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$api_key = $this->get_api_key_status();
|
||||
|
||||
if ( ! $api_key ) {
|
||||
$this->add_notification(
|
||||
new Cmatic_Notification(
|
||||
__( 'Connect your Mailchimp API to enable email subscriptions.', 'chimpmatic-lite' ),
|
||||
array(
|
||||
'id' => 'cmatic-api-not-connected',
|
||||
'type' => Cmatic_Notification::WARNING,
|
||||
'priority' => 1.0,
|
||||
'link' => $this->get_settings_url(),
|
||||
'link_text' => __( 'Connect Now', 'chimpmatic-lite' ),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( class_exists( 'Cmatic_Options_Repository' ) && Cmatic_Options_Repository::get_option( 'debug', false ) ) {
|
||||
$this->add_notification(
|
||||
new Cmatic_Notification(
|
||||
__( 'Debug logging is currently enabled.', 'chimpmatic-lite' ),
|
||||
array(
|
||||
'id' => 'cmatic-debug-enabled',
|
||||
'type' => Cmatic_Notification::INFO,
|
||||
'priority' => 0.3,
|
||||
'link' => $this->get_settings_url(),
|
||||
'link_text' => __( 'View Settings', 'chimpmatic-lite' ),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function get_api_key_status() {
|
||||
$cache_key = 'cmatic_api_connected';
|
||||
$cached = get_transient( $cache_key );
|
||||
|
||||
if ( false !== $cached ) {
|
||||
return (bool) $cached;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Cached via transient.
|
||||
$results = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT option_value FROM {$wpdb->options} WHERE option_name LIKE %s LIMIT 10",
|
||||
'cf7_mch_%'
|
||||
)
|
||||
);
|
||||
|
||||
$is_connected = false;
|
||||
|
||||
if ( ! empty( $results ) ) {
|
||||
foreach ( $results as $row ) {
|
||||
$data = maybe_unserialize( $row->option_value );
|
||||
if ( is_array( $data ) && ! empty( $data['api_key'] ) ) {
|
||||
$is_connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_transient( $cache_key, $is_connected ? '1' : '0', HOUR_IN_SECONDS );
|
||||
|
||||
return $is_connected;
|
||||
}
|
||||
|
||||
private function get_settings_url() {
|
||||
if ( class_exists( 'Cmatic_Plugin_Links' ) ) {
|
||||
$url = Cmatic_Plugin_Links::get_settings_url();
|
||||
if ( ! empty( $url ) ) {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
return admin_url( 'admin.php?page=wpcf7' );
|
||||
}
|
||||
|
||||
public function add_notification( Cmatic_Notification $notification ) {
|
||||
if ( ! $notification->display_for_current_user() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->is_notification_dismissed( $notification ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $notification->get_id();
|
||||
if ( $id ) {
|
||||
foreach ( $this->notifications as $existing ) {
|
||||
if ( $existing->get_id() === $id ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->notifications[] = $notification;
|
||||
$this->notifications_dirty = true;
|
||||
}
|
||||
|
||||
public function remove_notification( $notification_id ) {
|
||||
foreach ( $this->notifications as $index => $notification ) {
|
||||
if ( $notification->get_id() === $notification_id ) {
|
||||
unset( $this->notifications[ $index ] );
|
||||
$this->notifications = array_values( $this->notifications );
|
||||
$this->notifications_dirty = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_notification_by_id( $notification_id ) {
|
||||
foreach ( $this->notifications as $notification ) {
|
||||
if ( $notification->get_id() === $notification_id ) {
|
||||
return $notification;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_notifications() {
|
||||
return $this->notifications;
|
||||
}
|
||||
|
||||
public function get_notification_count() {
|
||||
return count( $this->notifications );
|
||||
}
|
||||
|
||||
public function get_sorted_notifications() {
|
||||
$notifications = $this->notifications;
|
||||
|
||||
usort(
|
||||
$notifications,
|
||||
function ( $a, $b ) {
|
||||
$type_priority = array(
|
||||
Cmatic_Notification::ERROR => 4,
|
||||
Cmatic_Notification::WARNING => 3,
|
||||
Cmatic_Notification::INFO => 2,
|
||||
Cmatic_Notification::SUCCESS => 1,
|
||||
);
|
||||
|
||||
$a_type = isset( $type_priority[ $a->get_type() ] ) ? $type_priority[ $a->get_type() ] : 0;
|
||||
$b_type = isset( $type_priority[ $b->get_type() ] ) ? $type_priority[ $b->get_type() ] : 0;
|
||||
|
||||
if ( $a_type !== $b_type ) {
|
||||
return $b_type - $a_type;
|
||||
}
|
||||
|
||||
if ( $b->get_priority() > $a->get_priority() ) {
|
||||
return 1;
|
||||
} elseif ( $b->get_priority() < $a->get_priority() ) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function is_notification_dismissed( Cmatic_Notification $notification ) {
|
||||
$dismissal_key = $notification->get_dismissal_key();
|
||||
|
||||
if ( empty( $dismissal_key ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$value = get_user_option( 'cmatic_dismissed_' . $dismissal_key, $user_id );
|
||||
|
||||
return ! empty( $value );
|
||||
}
|
||||
|
||||
public function dismiss_notification( Cmatic_Notification $notification ) {
|
||||
$dismissal_key = $notification->get_dismissal_key();
|
||||
|
||||
if ( empty( $dismissal_key ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$result = update_user_option( $user_id, 'cmatic_dismissed_' . $dismissal_key, time() );
|
||||
|
||||
if ( $result ) {
|
||||
$this->remove_notification( $notification->get_id() );
|
||||
}
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
public function save_notifications() {
|
||||
if ( ! $this->notifications_dirty ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
if ( ! $user_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$to_store = array();
|
||||
|
||||
foreach ( $this->notifications as $notification ) {
|
||||
if ( $notification->is_persistent() ) {
|
||||
$to_store[] = $notification->to_array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $to_store ) ) {
|
||||
delete_user_option( $user_id, self::STORAGE_KEY );
|
||||
} else {
|
||||
update_user_option( $user_id, self::STORAGE_KEY, $to_store );
|
||||
}
|
||||
}
|
||||
|
||||
public function clear_notifications() {
|
||||
$this->notifications = array();
|
||||
$this->notifications_dirty = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Notification message handler.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Notification {
|
||||
const ERROR = 'error';
|
||||
const WARNING = 'warning';
|
||||
const INFO = 'info';
|
||||
const SUCCESS = 'success';
|
||||
|
||||
private $message;
|
||||
private $options = array();
|
||||
private $defaults = array(
|
||||
'type' => self::INFO,
|
||||
'id' => '',
|
||||
'user_id' => null,
|
||||
'priority' => 0.5,
|
||||
'dismissal_key' => null,
|
||||
'capabilities' => array( 'manage_options' ),
|
||||
'link' => '',
|
||||
'link_text' => '',
|
||||
);
|
||||
|
||||
public function __construct( $message, $options = array() ) {
|
||||
$this->message = $message;
|
||||
$this->options = wp_parse_args( $options, $this->defaults );
|
||||
|
||||
if ( null === $this->options['user_id'] ) {
|
||||
$this->options['user_id'] = get_current_user_id();
|
||||
}
|
||||
|
||||
$this->options['priority'] = min( 1, max( 0, $this->options['priority'] ) );
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return $this->options['id'];
|
||||
}
|
||||
|
||||
public function get_message() {
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function get_type() {
|
||||
return $this->options['type'];
|
||||
}
|
||||
|
||||
public function get_priority() {
|
||||
return $this->options['priority'];
|
||||
}
|
||||
|
||||
public function get_user_id() {
|
||||
return (int) $this->options['user_id'];
|
||||
}
|
||||
|
||||
public function get_dismissal_key() {
|
||||
if ( empty( $this->options['dismissal_key'] ) ) {
|
||||
return $this->options['id'];
|
||||
}
|
||||
return $this->options['dismissal_key'];
|
||||
}
|
||||
|
||||
public function get_link() {
|
||||
return $this->options['link'];
|
||||
}
|
||||
|
||||
public function get_link_text() {
|
||||
return $this->options['link_text'];
|
||||
}
|
||||
|
||||
public function is_persistent() {
|
||||
return ! empty( $this->options['id'] );
|
||||
}
|
||||
|
||||
public function display_for_current_user() {
|
||||
if ( ! $this->is_persistent() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->user_has_capabilities();
|
||||
}
|
||||
|
||||
private function user_has_capabilities() {
|
||||
$capabilities = $this->options['capabilities'];
|
||||
|
||||
if ( empty( $capabilities ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ( $capabilities as $capability ) {
|
||||
if ( ! current_user_can( $capability ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array(
|
||||
'message' => $this->message,
|
||||
'options' => $this->options,
|
||||
);
|
||||
}
|
||||
|
||||
public static function from_array( $data ) {
|
||||
$message = isset( $data['message'] ) ? $data['message'] : '';
|
||||
$options = isset( $data['options'] ) ? $data['options'] : array();
|
||||
return new self( $message, $options );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Accordion panel toggle buttons.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Panel_Toggles {
|
||||
public static function cmatic_get_default_buttons() {
|
||||
return array(
|
||||
'advanced_settings' => array(
|
||||
'label' => __( 'Advanced Settings', 'flavor' ),
|
||||
'aria_controls' => 'cme-container',
|
||||
'extra_class' => '',
|
||||
'priority' => 10,
|
||||
),
|
||||
'submission_logs' => array(
|
||||
'label' => __( 'Submission Logs', 'flavor' ),
|
||||
'aria_controls' => 'eventlog-sys',
|
||||
'extra_class' => '',
|
||||
'priority' => 40,
|
||||
),
|
||||
'form_preview' => array(
|
||||
'label' => __( 'Form Preview and Test', 'flavor' ),
|
||||
'aria_controls' => 'cmatic-test-container',
|
||||
'extra_class' => 'vc-test-submission',
|
||||
'priority' => 50,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public static function cmatic_get_buttons() {
|
||||
$buttons = self::cmatic_get_default_buttons();
|
||||
$buttons = apply_filters( 'cmatic_panel_toggle_buttons', $buttons );
|
||||
|
||||
// Sort by priority.
|
||||
uasort(
|
||||
$buttons,
|
||||
function ( $a, $b ) {
|
||||
$priority_a = isset( $a['priority'] ) ? $a['priority'] : 50;
|
||||
$priority_b = isset( $b['priority'] ) ? $b['priority'] : 50;
|
||||
return $priority_a - $priority_b;
|
||||
}
|
||||
);
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
public static function cmatic_render_button( $key, $config ) {
|
||||
$classes = 'button site-health-view-passed cmatic-accordion-btn';
|
||||
if ( ! empty( $config['extra_class'] ) ) {
|
||||
$classes .= ' ' . esc_attr( $config['extra_class'] );
|
||||
}
|
||||
|
||||
printf(
|
||||
'<button type="button" class="%s" aria-expanded="false" aria-controls="%s">%s<span class="icon"></span></button>',
|
||||
esc_attr( $classes ),
|
||||
esc_attr( $config['aria_controls'] ),
|
||||
esc_html( $config['label'] )
|
||||
);
|
||||
}
|
||||
|
||||
public static function cmatic_render() {
|
||||
$buttons = self::cmatic_get_buttons();
|
||||
|
||||
if ( empty( $buttons ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="cmatic-section cmatic-panel-toggles">';
|
||||
|
||||
foreach ( $buttons as $key => $config ) {
|
||||
self::cmatic_render_button( $key, $config );
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* Sidebar panel components.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Cmatic_Sidebar_Panel {
|
||||
public static function render_submit_info( int $post_id ): void {
|
||||
$cf7_mch = get_option( 'cf7_mch_' . $post_id, array() );
|
||||
$api_valid = (int) ( $cf7_mch['api-validation'] ?? 0 );
|
||||
$sent = Cmatic_Options_Repository::get_option( 'stats.sent', 0 );
|
||||
|
||||
$status_text = ( 1 === $api_valid )
|
||||
? '<span class="chmm valid">API Connected</span>'
|
||||
: '<span class="chmm invalid">API Inactive</span>';
|
||||
?>
|
||||
<div class="misc-pub-section chimpmatic-info" id="chimpmatic-version-info">
|
||||
<div style="margin-bottom: 3px;">
|
||||
<strong><?php echo esc_html__( 'ChimpMatic Lite', 'chimpmatic-lite' ) . ' ' . esc_html( SPARTAN_MCE_VERSION ); ?></strong>
|
||||
</div>
|
||||
<div style="margin-top: 5px;">
|
||||
<div class="mc-stats" style="color: #646970; font-size: 12px; margin-bottom: 3px;">
|
||||
<?php
|
||||
echo esc_html( $sent ) . ' synced contacts in ' .
|
||||
esc_html( Cmatic_Utils::get_days_since( (int) Cmatic_Options_Repository::get_option( 'install.quest', time() ) ) ) . ' days';
|
||||
?>
|
||||
</div>
|
||||
<div style="margin-bottom: 3px;">
|
||||
<?php echo wp_kses_post( $status_text ); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function render_footer_promo(): void {
|
||||
if ( function_exists( 'cmatic_is_blessed' ) && cmatic_is_blessed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pricing = self::get_pricing_data();
|
||||
$text = $pricing['formatted'] ?? '$39 → $29.25 • Save 40%';
|
||||
$discount = (int) ( $pricing['discount_percent'] ?? 40 );
|
||||
|
||||
$install_id = Cmatic_Options_Repository::get_option( 'install.id', '' );
|
||||
|
||||
$promo_url = add_query_arg(
|
||||
array(
|
||||
'source' => $install_id,
|
||||
'promo' => 'pro' . $discount,
|
||||
),
|
||||
Cmatic_Pursuit::promo( 'footer_banner', $discount )
|
||||
);
|
||||
?>
|
||||
<div id="informationdiv_aux" class="postbox mce-move mc-lateral">
|
||||
<div class="inside bg-f2">
|
||||
<h3>Upgrade to PRO</h3>
|
||||
<p>Get the best Contact Form 7 and Mailchimp integration tool available. Now with these new features:</p>
|
||||
<ul>
|
||||
<li>Tag Existing Subscribers</li>
|
||||
<li>Group Existing Subscribers</li>
|
||||
<li>Email Verification</li>
|
||||
<li>AWESOME Support And more!</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="promo-2022">
|
||||
<h1><?php echo (int) $discount; ?><span>%</span> Off!</h1>
|
||||
<p class="interesting">Unlock advanced tagging, subscriber groups, email verification, and priority support for your Mailchimp campaigns.</p>
|
||||
<div class="cm-form">
|
||||
<a href="<?php echo esc_url( $promo_url ); ?>" target="_blank" class="button cm-submit">Get PRO Now</a>
|
||||
<span class="cm-pricing"><?php echo esc_html( $text ); ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function get_pricing_data(): array {
|
||||
$fetcher = new CMatic_Remote_Fetcher(
|
||||
array(
|
||||
'url' => 'https://api.chimpmatic.com/promo',
|
||||
'cache_key' => 'cmatic_pricing_data',
|
||||
'cache_duration' => DAY_IN_SECONDS,
|
||||
'fallback_data' => array(
|
||||
'regular_price' => 39,
|
||||
'sale_price' => 29.25,
|
||||
'discount_percent' => 40,
|
||||
'coupon_code' => 'NOW40',
|
||||
'formatted' => '$39 → $29.25 • Save 40%',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return $fetcher->get_data();
|
||||
}
|
||||
|
||||
private function __construct() {}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Tags preview panel for Pro feature showcase.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Cmatic_Tags_Preview {
|
||||
|
||||
private static $type_abbrev = array(
|
||||
'checkbox' => 'CHK',
|
||||
'radio' => 'RAD',
|
||||
'select' => 'SEL',
|
||||
'text' => 'TXT',
|
||||
'hidden' => 'HID',
|
||||
'dynamictext' => 'DYN',
|
||||
'dynamichidden' => 'DYN',
|
||||
'tel' => 'TEL',
|
||||
'number' => 'NUM',
|
||||
);
|
||||
|
||||
private static $allowed_types = array(
|
||||
'checkbox',
|
||||
'radio',
|
||||
'select',
|
||||
'text',
|
||||
'hidden',
|
||||
'dynamictext',
|
||||
'dynamichidden',
|
||||
'tel',
|
||||
'number',
|
||||
);
|
||||
|
||||
public static function render( array $form_tags, array $cf7_mch, int $api_valid ): void {
|
||||
if ( empty( $form_tags ) || ! is_array( $form_tags ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$filtered_tags = array_filter(
|
||||
$form_tags,
|
||||
function ( $tag ) {
|
||||
$basetype = is_array( $tag ) ? ( $tag['basetype'] ?? '' ) : ( $tag->basetype ?? '' );
|
||||
return in_array( $basetype, self::$allowed_types, true );
|
||||
}
|
||||
);
|
||||
|
||||
if ( empty( $filtered_tags ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$disclosure_class = ( 1 === $api_valid ) ? 'spt-response-out spt-valid' : 'spt-response-out chmp-inactive';
|
||||
$name_list = self::get_audience_name( $cf7_mch );
|
||||
?>
|
||||
<div class="<?php echo esc_attr( $disclosure_class ); ?>">
|
||||
<div class="mce-custom-fields holder-img">
|
||||
<h3 class="title cmatic-title-with-toggle">
|
||||
<span>Tags for <span class="audience-name"><?php echo esc_html( $name_list ); ?></span></span>
|
||||
<label class="cmatic-toggle-row">
|
||||
<span class="cmatic-toggle-label">Sync Tags</span>
|
||||
<a href="<?php echo esc_url( Cmatic_Pursuit::upgrade( 'sync_tags_help' ) ); ?>" target="_blank" class="cmatic-help-icon" title="Learn about Sync Tags">?</a>
|
||||
<span class="cmatic-toggle">
|
||||
<input type="checkbox" data-field="sync_tags" value="1"<?php echo ! empty( $cf7_mch['sync_tags'] ) ? ' checked' : ''; ?>>
|
||||
<span class="cmatic-toggle-slider"></span>
|
||||
</span>
|
||||
</label>
|
||||
</h3>
|
||||
<p>You can add these as your contacts tags:</p>
|
||||
<div id="chm_panel_camposformatags">
|
||||
<?php self::render_tag_chips( $filtered_tags, $cf7_mch ); ?>
|
||||
<label class="atags"><b>Arbitrary Tags Here:</b> <input type="text" id="wpcf7-mailchimp-labeltags_cm-tag" name="wpcf7-mailchimp[labeltags_cm-tag]" value="<?php echo isset( $cf7_mch['labeltags_cm-tag'] ) ? esc_attr( $cf7_mch['labeltags_cm-tag'] ) : ''; ?>" placeholder="comma, separated, texts, or [mail-tags]">
|
||||
<p class="description">You can type in your tags here. Comma separated text or [mail-tags]</p>
|
||||
</label>
|
||||
</div>
|
||||
<a class="lin-to-pro" href="<?php echo esc_url( Cmatic_Pursuit::upgrade( 'tags_link' ) ); ?>" target="_blank" title="ChimpMatic Pro Options"><span>PRO Feature <span>Learn More...</span></span></a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function render_tag_chips( array $tags, array $cf7_mch ): void {
|
||||
echo '<div class="cmatic-tags-grid">';
|
||||
$i = 1;
|
||||
foreach ( $tags as $tag ) {
|
||||
$tag_name = is_array( $tag ) ? ( $tag['name'] ?? null ) : ( $tag->name ?? null );
|
||||
$tag_basetype = is_array( $tag ) ? ( $tag['basetype'] ?? null ) : ( $tag->basetype ?? null );
|
||||
|
||||
if ( empty( $tag_name ) || empty( $tag_basetype ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_checked = isset( $cf7_mch['labeltags'][ $tag_name ] );
|
||||
$type_short = self::$type_abbrev[ $tag_basetype ] ?? strtoupper( substr( $tag_basetype, 0, 3 ) );
|
||||
$selected_class = $is_checked ? ' selected' : '';
|
||||
?>
|
||||
<label class="cmatic-tag-chip<?php echo esc_attr( $selected_class ); ?>">
|
||||
<input type="checkbox" id="wpcf7-mailchimp-labeltags-<?php echo esc_attr( $i ); ?>" name="wpcf7-mailchimp[labeltags][<?php echo esc_attr( trim( $tag_name ) ); ?>]" value="1"<?php echo $is_checked ? ' checked="checked"' : ''; ?> />
|
||||
<span class="cmatic-tag-name">[<?php echo esc_html( $tag_name ); ?>]</span>
|
||||
<span class="cmatic-tag-type"><?php echo esc_html( $type_short ); ?></span>
|
||||
</label>
|
||||
<?php
|
||||
++$i;
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
private static function get_audience_name( array $cf7_mch ): string {
|
||||
$arrlist = isset( $cf7_mch['lisdata']['lists'] ) ? array_column( $cf7_mch['lisdata']['lists'], 'name', 'id' ) : array();
|
||||
$idlist = '';
|
||||
|
||||
if ( isset( $cf7_mch['list'] ) ) {
|
||||
if ( is_array( $cf7_mch['list'] ) ) {
|
||||
$idlist = reset( $cf7_mch['list'] );
|
||||
if ( false === $idlist ) {
|
||||
$idlist = '';
|
||||
}
|
||||
} else {
|
||||
$idlist = $cf7_mch['list'];
|
||||
}
|
||||
}
|
||||
|
||||
return ( ! empty( $idlist ) && isset( $arrlist[ $idlist ] ) ) ? $arrlist[ $idlist ] : '';
|
||||
}
|
||||
|
||||
private function __construct() {}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Test submission modal component.
|
||||
*
|
||||
* @package contact-form-7-mailchimp-extension
|
||||
* @author renzo.johnson@gmail.com
|
||||
* @copyright 2014-2026 https://renzojohnson.com
|
||||
* @license GPL-3.0+
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'Cmatic_Test_Submission_Modal' ) ) {
|
||||
class Cmatic_Test_Submission_Modal extends Cmatic_Modal {
|
||||
private $contact_form = null;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( 'cmatic-test-modal' );
|
||||
}
|
||||
|
||||
public function init() {
|
||||
if ( $this->initialized ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_admin_footer', array( $this, 'render_modal_with_form' ), 20, 1 );
|
||||
|
||||
$this->initialized = true;
|
||||
}
|
||||
|
||||
public function render_modal_with_form( $post ) {
|
||||
if ( ! $post || ! method_exists( $post, 'id' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form_id = $post->id();
|
||||
if ( ! $form_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->contact_form = wpcf7_contact_form( $form_id );
|
||||
if ( ! $this->contact_form ) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent::render_modal();
|
||||
}
|
||||
|
||||
protected function get_title() {
|
||||
return __( 'Test Current Form Submission', 'chimpmatic-lite' );
|
||||
}
|
||||
|
||||
protected function render_header_actions() {
|
||||
?>
|
||||
<button type="button" class="cmatic-modal__submit button button-primary">
|
||||
<?php esc_html_e( 'Submit', 'chimpmatic-lite' ); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function get_body() {
|
||||
if ( ! $this->contact_form ) {
|
||||
return '<p>' . esc_html__( 'No form available.', 'chimpmatic-lite' ) . '</p>';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="cmatic-modal__feedback" style="display: none;">
|
||||
<div class="cmatic-modal__feedback-icon"></div>
|
||||
<div class="cmatic-modal__feedback-content">
|
||||
<div class="cmatic-modal__feedback-title"></div>
|
||||
<div class="cmatic-modal__feedback-details"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cmatic-test-form-wrap">
|
||||
<?php
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $this->contact_form->form_html( array( 'html_class' => 'cmatic-test-form' ) );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
protected function get_strings() {
|
||||
return array_merge(
|
||||
parent::get_strings(),
|
||||
array(
|
||||
'submit' => __( 'Submit', 'chimpmatic-lite' ),
|
||||
'submitting' => __( 'Submitting...', 'chimpmatic-lite' ),
|
||||
'success' => __( 'Success!', 'chimpmatic-lite' ),
|
||||
'error' => __( 'Error', 'chimpmatic-lite' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user