Created
March 27, 2018 15:03
-
-
Save gagimilicevic/fdb9784669ac04cfe311887a72fbc2c0 to your computer and use it in GitHub Desktop.
Extending CF7 with new feature or option from backend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cf7_active_campaign_add_meta_boxes() { | |
add_meta_box( 'cf7-active-campaign-settings', 'Active Campaign', 'cf7_active_campaign_metaboxes', '', 'form', 'low'); | |
} | |
add_action( 'wpcf7_add_meta_boxes', 'cf7_active_campaign_add_meta_boxes' ); | |
function cf7_activecampaign_add_page_panels($panels) { | |
$panels['redirect-panel'] = array( 'title' => 'Active Campaign Settings', 'callback' => 'cf7_activecampaign_page_panel_meta' ); | |
return $panels; | |
} | |
add_action( 'wpcf7_editor_panels', 'cf7_activecampaign_add_page_panels' ); | |
function cf7_active_campaign_metaboxes( $post ) { | |
wp_nonce_field( 'cf7_active_campaign_metaboxes', 'cf7_active_campaign_metaboxes_nonce' ); | |
$cf7_activecampaing_page = get_post_meta( $post->id(), '_cf7_activecampaing_page_key', true ); | |
echo '<label>Test field</label>'; | |
echo '<input id="field1" type="text" name="field1" value="'.$cf7_activecampaing_page.'">'; | |
} | |
function cf7_activecampaign_page_panel_meta( $post ) { | |
wp_nonce_field( 'cf7_active_campaign_metaboxes', 'cf7_active_campaign_metaboxes_nonce' ); | |
$cf7_activecampaing_page = get_post_meta( $post->id(), '_cf7_activecampaing_page_key', true ); | |
echo '<label>Test field</label>'; | |
echo '<input id="field1" type="text" name="field1" value="'.$cf7_activecampaing_page.'">'; | |
} | |
function cf7_activecampaign_save_contact_form( $contact_form ) { | |
$contact_form_id = $contact_form->id(); | |
if ( !isset( $_POST ) || empty( $_POST ) || !isset( $_POST['field1'] ) ) { | |
return; | |
} | |
else { | |
if ( ! wp_verify_nonce( $_POST['cf7_active_campaign_metaboxes_nonce'], 'cf7_active_campaign_metaboxes' ) ) { | |
return; | |
} | |
update_post_meta( $contact_form_id, '_cf7_activecampaing_page_key', $_POST['field1'] ); | |
} | |
} | |
add_action( 'wpcf7_after_save', 'cf7_activecampaign_save_contact_form' ); | |
//Kada se submituje forma | |
function cf7_active_campaign_form_submitted( $contact_form ) { | |
$contact_form_id = $contact_form->id(); | |
$active_campaign = get_post_meta( $contact_form_id, '_cf7_activecampaing_page_key', true ); | |
if ( !empty($active_campaign) ) { | |
//Ovde stavi to sto treba da radi sa ActiveCampaing | |
} | |
} | |
add_action( 'wpcf7_mail_sent', 'cf7_active_campaign_form_submitted' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment