admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'f12_doi_details' )
) );
wp_enqueue_script( 'f12-cf7-doubleoptin-templateloader', plugins_url( 'assets/f12-cf7-templateloader.js', __FILE__ ), array( 'jquery' ) );
wp_localize_script( 'f12-cf7-doubleoptin-templateloader', 'templateloader', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'f12_doi_templateloader' ),
'label_placeholder' => __( 'Please wait while we load the template...', 'double-opt-in' )
) );
}
/**
* Add the hooks responsible to handle wordpress functions
*/
public function addHooks() {
add_filter( 'wpcf7_editor_panels', array( $this, 'addPanel' ), 10, 1 );
add_action( 'wpcf7_save_contact_form', array( $this, 'save' ), 10, 3 );
}
/**
* Add a custom panel to the contact form 7 options
*/
public function addPanel( array $panels ) {
$panels['optin'] = array(
'title' => __( 'Double-Opt-in', 'double-opt-in' ),
'callback' => array( $this, 'render' )
);
return $panels;
}
/**
* On Contact Form save store the information in the database
*
* @param \WPCF7_ContactForm $contact_form
* @param $args
* @param $context
*/
public function save( $contact_form, $args, $context ) {
$postID = $contact_form->id();
// Validate nonce
if ( ! isset( $_POST['f12_cf7_doubleoptin_save_form_nonce'] ) || ! wp_verify_nonce( $_POST['f12_cf7_doubleoptin_save_form_nonce'], 'f12_cf7_doubleoptin_save_form_action' ) ) {
return;
}
// Check if the double opt in settings is set
if ( ! $postID || ! isset( $_POST['doubleoptin'] ) ) {
update_post_meta( $postID, 'f12-cf7-doubleoptin', array() );
return;
}
$parameter = SanitizeHelper::sanitize_array( $_POST['doubleoptin'] );
// load the default parameter
$metadata = CF7DoubleOptIn::getInstance()->getParameter( $postID );
// validated all parameter defined in the default parameter options and sanitize them.
foreach ( $metadata as $key => $value ) {
if ( isset( $parameter[ $key ] ) ) {
if ( $key == 'body' ) {
$metadata[ $key ] = $parameter[ $key ];
} else if ( $key == 'enable' ) {
$metadata[ $key ] = (int) $parameter[ $key ];
} else if ( $key == 'sender' ) {
$metadata[ $key ] = $parameter[ $key ];
} else {
$metadata[ $key ] = $parameter[ $key ];
}
} else if ( $key == 'enable' ) {
$metadata[ $key ] = 0;
}
}
/**
* Adjust the Metadata before saving
*
* @param array $metadata
*/
$metadata = apply_filters( 'f12_cf7_doubleoptin_metadata_cf7', $metadata );
/**
* Adjust the Metadata before saving
*
* @param array $metadata
*/
$metadata = apply_filters( 'f12_cf7_doubleoptin_save_form', $metadata );
update_post_meta( $postID, 'f12-cf7-doubleoptin', $metadata );
}
/**
* Return an option list containing all tags for the condition and a default field to disable the condition.
*
* @param \WPCF7_ContactForm $post
*
* @return array
*/
private function getTags( $post ) {
$tags = array();
$arrayTags = $post->scan_form_tags();
foreach ( $arrayTags as $formTag /** @var \WPCF7_FormTag $formTag */ ) {
if ( ! empty( $formTag->name ) ) {
$tags[ $formTag->name ] = $formTag->name;
}
}
return $tags;
}
/**
* Show the backend double opt in options
*
* @param \WPCF7_ContactForm $post
*/
public function render( $post ) {
if ( ! $post ) {
return;
}
$metadata = CF7DoubleOptIn::getInstance()->getParameter( $post->id() );
$id = "doubleoptin";
?>
- 1,
'orderBy' => 'name',
'order' => 'ASC'
);
$list = Category::get_list( $atts, $numberOfPages );
$response = '';
foreach ( $list as $Category /** @var Category $Category */ ) {
$selected = "";
if ( $Category->get_id() == $metadata['category'] ) {
$selected = 'selected="selected"';
}
$response .= '';
}
?>
__( 'Disabled', 'double-opt-in' ) ), $this->getTags( $post ) ), array(
'id' => array( $id . '-conditions' ),
'class' => array(
'large-text',
'code'
)
) );
$ConditionList->setOptionSelectedByKey( $metadata['conditions'] );
echo wp_kses( $ConditionList->get(), array(
'select' => array( 'name' => array() ),
'option' => array(
'value' => array(),
'selected' => array()
)
) );
?>