| Server IP : 172.67.201.108 / Your IP : 216.73.216.68 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/home2/mommybites/wp-content/plugins/amp-cf7/ |
Upload File : |
<?php
/*
* Plugin Name: Contact Form 7 for AMP
* Plugin URI: https://ampforwp.com/contact-form-7/
* Description: Add CF7 integration with AMP
* Author: Mohammed Kaludi
* Version: 1.50
* Author URI: https://www.ampforwp.com/
* License: GPL2+
* Text Domain: ampforwp
*
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
define('AMP_CF7_PLUGIN_URI', plugin_dir_url(__FILE__));
define('AMP_CF7_PLUGIN_PATH', plugin_dir_path(__FILE__));
if ( ! defined( 'AMP_CF7_VERSION' ) ) {
define( 'AMP_CF7_VERSION', '1.50' );
}
// this is the URL our updater / license checker pings. This should be the URL of the site with EDD installed
define( 'AMP_CF7_STORE_URL', 'https://accounts.ampforwp.com/' ); // you should use your own CONSTANT name, and be sure to replace it throughout this file
// the name of your product. This should match the download name in EDD exactly
define( 'AMP_CF7_ITEM_NAME', 'Contact Form 7 for AMP' );
// the download ID. This is the ID of your product in EDD and should match the download ID visible in your Downloads list (see example below)
//define( 'AMPFORWP_ITEM_ID', 2502 );
// the name of the settings page for the license input to be displayed
define( 'AMP_CF7_LICENSE_PAGE', 'contact-form-7-for-amp' );
if(! defined('AMP_CF7_ITEM_FOLDER_NAME')){
$folderName = basename(__DIR__);
define( 'AMP_CF7_ITEM_FOLDER_NAME', $folderName );
}
// CODE TO ADD LICENSE ACTIVATION FATURE FOR NON AMPFORWP
if(!defined('AMPFORWP_PLUGIN_DIR')){
$redux_builder_amp = get_option('redux_builder_amp',true);
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'ampforwp_ext_plugin_activation_link' );
function ampforwp_ext_plugin_activation_link( $links ) {
$_link = '<a href="admin.php?page=license-activation" target="_blank">License Activation</a>';
$links[] = $_link;
return $links;
}
add_action('init', 'ampforwp_set_extension_license_key_page');
function ampforwp_set_extension_license_key_page(){
require_once('license-activation.php');
add_submenu_page(
'',
'License Activation',
'License Activation',
'manage_options',
'license-activation',
'ampforwp_license_activation'
);
}
function ampforwp_license_activation(){
require_once('license-activation-view.php');
}
}
add_action('init', 'amp_cf7_plugin_init');
function amp_cf7_plugin_init() {
if(!defined('AMPFORWP_AMP__DIR__')){
if ( defined('AMP__DIR__') ){
define( 'AMPFORWP_AMP__DIR__', AMP__DIR__);
require_once AMP_CF7_PLUGIN_PATH .'/class-amp-cf7-blacklist.php';
}elseif( defined('AMP__VENDOR__DIR__')){
define( 'AMPFORWP_AMP__DIR__', AMP__VENDOR__DIR__);
require_once AMP_CF7_PLUGIN_PATH .'/class-amp-cf7-blacklist.php';
}
}
}
add_action('wp', 'ampforwp_start_generating_code', 100);
function ampforwp_start_generating_code() {
if ( (function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint()) || (function_exists( 'is_wp_amp' ) && is_wp_amp()) || (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) ) {
global $cf7data;
global $shortcode_tags;
// store current handler
$cf7data = ampforwp_get_array( $shortcode_tags, 'contact-form-7' );
// replace original handler with our
add_shortcode(
'contact-form-7','ampforwp_generate_amp_cf7_form'
);
add_shortcode(
'contact-form', 'ampforwp_generate_amp_cf7_form' );
}
}
include_once(ABSPATH. 'wp-admin/includes/plugin.php');
if ( is_plugin_active('contact-form-7/wp-contact-form-7.php')){
function ampforwp_generate_amp_cf7_form($atts, $content = null, $code = '') {
global $cf7data;
$post_id = '';
$redirect_attr = '';
$post_id = (int) $atts['id'];
$handler = $cf7data;
$cf7Content = $handler( $atts, $content, $code );
$redirect_field = '';
if(isset($atts['amp_redirect']) && !empty($atts['amp_redirect'])){
$redirect_attr = $atts['amp_redirect'];
}
//$submit_url = AMP_CF7_PLUGIN_URI . "/class-amp-cf7-form.php?action=submit";
$submit_url = admin_url('admin-ajax.php?action=contact_form_submission');
$actionXhrUrl = preg_replace('#^https?:#', '', $submit_url)."&submit=1";
$wp_get_canonical_url = wp_get_canonical_url();
$url_creator = get_site_url();
global $wpcf7,$redux_builder_amp;
$current_form = wpcf7_get_current_contact_form();
if(!empty($current_form)){
$current_form_id = $current_form->id();
}
$post_id = get_the_ID();
$url_creator = get_site_url();
$form_url_build = $url_creator.'/wp-json/contact-form-7-for-amp/v1/contact-forms/'.$current_form_id.'/feedback';
if(isset($redux_builder_amp['ampforwp_cf7_POST_method']) && $redux_builder_amp['ampforwp_cf7_POST_method'] == 'restapiendpoint' ){
$cf7Content = preg_replace( '/<form\saction=(.*?)class="(.*?)">/', '<form action-xhr='.$form_url_build.' class="$2" method="POST">', $cf7Content );
}else {
$cf7Content = preg_replace( '#action="([^"]+)"#ius', 'action-xhr="' . $actionXhrUrl . '" target="_top"', $cf7Content );
}
$cf7Content = preg_replace( '#(\[recaptcha(.*)])#iu', ' ', $cf7Content );
$cf7formallow = preg_match('#(<form\saction-xhr=(.*?)class="(.*?)")#iu', $cf7Content);
$cf7Content = preg_replace( '/<b>Upload Images \(Max 3mb per image\)<\/b>/', '<span class="wpcf7-form-control-wrap your-file"><b>Upload Images (Max 3mb per image)</b></span>', $cf7Content );
if($cf7formallow){
$cf7Content = preg_replace( '/<form\saction-xhr=(.*?)class="(.*?)"/', '<form action-xhr=$1class="$2 ampforwp-form-allow saswp-review-submission-form"', $cf7Content );
}
if( !empty($redirect_attr)){
$redirect_field = '<input type="hidden" name="amp_redirect_url" value="'.$redirect_attr.'">';
}
// Generate Submit Button
$submit_button = $redirect_field.''.ampforwp_after_submit_notice();
$checker = preg_match('#(<p><input\s+type="submit")#iu', $cf7Content);
/*
global $redux_builder_amp;
$sitetkey = $redux_builder_amp['ampforwp-cf7-recaptcha-site'];
$formchck = preg_match('/<input\stype="submit"\svalue="(.*?)"\sclass="wpcf7-form-control\swpcf7-submit/', $cf7Content);
if($formchck == 1 && (isset($redux_builder_amp['ampforwp-cf7-recaptcha']) && $redux_builder_amp['ampforwp-cf7-recaptcha'] == 1 ) ) {
$cf7Content = preg_replace('/<input\stype="submit"\svalue="(.*?)"\sclass="wpcf7-form-control\swpcf7-submit/', '<p><amp-recaptcha-input layout="nodisplay" name="cf7-recaptcha-response" data-sitekey="'.$sitetkey.'" data-action="cf7_recaptcha_response">
</amp-recaptcha-input></p><input type="submit" value="$1" class="wpcf7-form-control wpcf7-submit', $cf7Content);
}
*/
if(isset($_SERVER['HTTP_REFERER'])) {
$amp_prvs_url = $_SERVER['HTTP_REFERER'];
}
if(preg_match('/<p><input\stype="button"\svalue="(.*?)"\sclass="wpcf7-form-control\swpcf7-previous"\s\/>/', $cf7Content )){
$cf7Content = preg_replace('/<p><input\stype="button"\svalue="(.*?)"\sclass="wpcf7-form-control\swpcf7-previous"\s\/>/','<a href="'.$amp_prvs_url.'" class="ampforwp-cf7-prvs">$1</a>', $cf7Content);
}
if(1 == $checker){
$cf7Content = preg_replace( '#(<p><input([^>]+)?type="submit"([^>]+)?>)#iu', $submit_button . '$1', $cf7Content );
$tags = array("<center>", "</center>","<ul class=\"conatctus-form\">","</ul>","<li>","</li>", "<div class=\"submit-button\">", "<div class=\"submit-btn\">" );
$cf7Content = str_replace($tags, "", $cf7Content);
}
else{
$div_checker = preg_match('#(<div\sclass=(.*?)>\n.*<input\stype="submit".*class=".*wpcf7-submit.*?")#iu', $cf7Content);
$div2_checker = preg_match('#(<div\sclass=(.*?)>(.*?)<input\stype="submit"(.*?)class="(.*)wpcf7-submit(.*?)")#iu', $cf7Content);
if(1 == $div_checker || 1 == $div2_checker) {
$cf7Content = preg_replace( '#(<div\sclass=(.*?)>\n.*<input\stype="submit".*class=".*wpcf7-submit.*?")#iu', $submit_button . '$1', $cf7Content );
$cf7Content = preg_replace( '#(<div\sclass=(.*?)>(.*?)<input\stype="submit"(.*?)class="(.*)wpcf7-submit(.*?)")#iu', $submit_button . '$1', $cf7Content );
$tags = array("<center>", "</center>","<ul class=\"conatctus-form\">","</ul>","<li>","</li>", "<div class=\"banner-form\">", "<div class=\"inner-form\">" );
$cf7Content = str_replace($tags,"", $cf7Content);
}
else {
$cf7Content = preg_replace( '#(<input([^>]+)?type="submit"([^>]+)?>)#iu', $submit_button . '$1', $cf7Content );
if(preg_match('/<button(.*?)type="submit"(.*?)<\/button>/s', $cf7Content)){
$cf7Content = preg_replace( '/<button(.*?)type="submit"(.*?)<\/button>/s', $submit_button . '<p><input type="submit" value="Submit" class="wpcf7-form-control wpcf7-submit user-valid valid"></p>', $cf7Content );
}
$tags = array("<center>", "</center>","<ul class=\"conatctus-form\">","</ul>","<li>","</li>", "<div class=\"submit-button\">", "<div class=\"submit-btn\">" );
$cf7Content = str_replace($tags,"", $cf7Content);
}
}
$content = $cf7Content ;
if(preg_match('/<input(.*?)aria-required="true"(.*?)>/s', $content)){
$content = preg_replace('/<input(.*?)aria-required="true"(.*?)>/s', '<input$1aria-required="true"$2><span class = "required_field"></span>', $content) ;
}
if(preg_match('/<textarea (.*?)aria-required="true" (.*?) placeholder="(.*?)">(.*?)><\/span><\/textarea>/', $content)){
$content = preg_replace('/<textarea (.*?)aria-required="true" (.*?) placeholder="(.*?)">(.*?)><\/span><\/textarea>/','<textarea $1aria-required="true" $2 placeholder="$3"></textarea><span class = "required_field"></span>', $content) ;
}
if(preg_match('/<textarea (.*?) class="wpcf7-form-control wpcf7-textarea(.*?)" aria-required="true" (.*?)>(.*?)<\/textarea>/', $content)){
$content = preg_replace('/<textarea (.*?) class="wpcf7-form-control wpcf7-textarea(.*?)" aria-required="true" (.*?)>(.*?)<\/textarea>/','<textarea $1 class="wpcf7-form-control wpcf7-textarea$2" aria-required="true" $3></textarea><span class="required_field"></span>', $content);
}
# recaptcha v3 added.
global $redux_builder_amp;
$sitetkey = $redux_builder_amp['ampforwp-cf7-recaptcha-site'];
if( isset($redux_builder_amp['ampforwp-cf7-recaptcha']) && $redux_builder_amp['ampforwp-cf7-recaptcha'] == 1 ) {
$content = preg_replace('/<input type="hidden" name="amp_cf7_nonce" value="(.*?)">/', '<input type="hidden" name="amp_cf7_nonce" value="$1"><amp-recaptcha-input layout="nodisplay" name="cf7-recaptcha-response" data-sitekey="'.$sitetkey.'" data-action="cf7_recaptcha_response">
</amp-recaptcha-input>', $content);
}
//cf7 honeypot hidden field.
if(function_exists('wpcf7_honeypot_formtag_handler') && class_exists('WPCF7_ContactForm')){
$wpcf7 = WPCF7_ContactForm::get_current();
$contact_form = $wpcf7->scan_form_tags();
foreach ($contact_form as $key => $value) {
if($value->type == "honeypot"){
foreach ($value->options as $key => $options) {
$word = 'move-inline-css:true';
if(strpos($options, $word) !== false){
$content = preg_replace('/<span id="(.*?)" class="wpcf7-form-control-wrap honeypot-(.*?)-wrap" >/', '<span id="$1" class="wpcf7-form-control-wrap honeypot-$2-wrap cf7-hp-hidden" >', $content);
}
}
}
}
}
$html = '<input type="hidden" name="action" value="contact_form_submission">';
add_filter('amp_post_template_data','ampforwp_add_required_scripts', 20);
if( false == has_action('amp_post_template_css','amp_cf7_form_styling') ){
add_action('amp_post_template_css', 'amp_cf7_form_styling',10);
}
if(class_exists('CF7CF')){
$current_form = wpcf7_get_current_contact_form();
if(!empty($current_form)){
$current_form_id = $current_form->id();
}
$conditions = CF7CF::getConditions($current_form_id);
$group_fields = array();
if(!empty($conditions)){
foreach ($conditions as $key => $value) {
$group_fields[] = $value['then_field'];
}
$unique_grp = array_unique($group_fields);
$grouping = array();
foreach ($conditions as $key => $value) {
if(in_array($value['then_field'], $unique_grp )){
$grouping[$value['then_field']][] = $value;
}
}
foreach ($grouping as $group => $rules) {
$i =1;
$orCondition = '';
if(count($rules)>1){
$orCondition .= '(';
}
foreach ($rules as $orKey => $orVal) {
$j = 1;
$andCondition = '';
if(count($orVal['and_rules']) > 1){
$andCondition .= '(';
}
if($i>1){
$orCondition .= ' || ';
}
$group_name = $orVal['then_field'];
foreach ($orVal['and_rules'] as $andKey => $andVal) {
if($andVal['operator'] == 'equals'){
$operand = '==';
}else{
$operand = '!=';
}
if($j>1){
$andCondition .= ' && ';
preg_match('/<input\stype="checkbox"\sname="'.$andVal['if_field'].'\[\]"(.*?)>/', $content, $matches);
if(!empty($matches)){
$andCondition .= 'option_'.$andVal['if_field'].'_'.$group.' '.$operand.' \''.$andVal['if_value'].'\'';
}else{
$andCondition .= 'option_'.$andVal['if_field'].' '.$operand.' \''.$andVal['if_value'].'\'';
}
}else{
preg_match('/<input\stype="checkbox"\sname="'.$andVal['if_field'].'\[\]"(.*?)>/', $content, $matches);
if(!empty($matches)){
$andCondition .= 'option_'.$andVal['if_field'].'_'.$group.' '.$operand.' \''.$andVal['if_value'].'\'';
}else{
$andCondition .= 'option_'.$andVal['if_field'].' '.$operand.' \''.$andVal['if_value'].'\'';
}
}
if($j==count($orVal['and_rules']) && $j>1){
$andCondition .= ')';
}
$j++;
}
$orCondition .= $andCondition;
if($i==count($rules) && $i>1){
$orCondition .= ')';
}
$i++;
}
if(preg_match('/<div\sdata-id="'.$group.'"\sdata-orig_data_id="'.$group.'"(.*?)>(.*?)<select\sname="(.*?)"\sclass="(.*?)"\saria-required="true"(.*?)>/s', $content)){
$content = preg_replace('/<div\sdata-id="'.$group.'"\sdata-orig_data_id="'.$group.'"(.*?)>(.*?)<select\sname="(.*?)"\sclass="(.*?)"\saria-required="true"(.*?)>/s', '<div data-id="'.$group.'" data-orig_data_id="'.$group.'"$1 class="wpcf7cf-hidden" [class]="'.$orCondition.'? \'wpcf7cf-show\' : \'wpcf7cf-hidden\'">$2<select name="$3" class="$4" aria-required="true" required="" data-amp-bind-required="'.$orCondition.'? true : false"$5>', $content);
}else{
$content = preg_replace('/<(.*?)data-id="'.$group.'"\sdata-orig_data_id="'.$group.'"(.*?)>/', '<$1data-id="'.$group.'" data-orig_data_id="'.$group.'"$2 class="wpcf7cf-hidden" [class]="'.$orCondition.'? \'wpcf7cf-show\' : \'wpcf7cf-hidden\'">', $content);
}
}
$operand = '';
$group_name = '';
foreach ($conditions as $key => $rules) {
$group_name = $rules['then_field'];
foreach ($rules['and_rules'] as $key => $value) {
if($value['operator'] == 'equals'){
$operand = '!=';
}else{
$operand = '==';
}
$content = preg_replace('/<select\sname="'.$value['if_field'].'"(.*?)>/', '<select name="'.$value['if_field'].'"$1 on="change:AMP.setState({ option_'.$value['if_field'].': event.value })">', $content);
$content = preg_replace('/<input\stype="radio"\sname="'.$value['if_field'].'"(.*?)>/', '<input type="radio" name="'.$value['if_field'].'"$1 on="change:AMP.setState({ option_'.$value['if_field'].': event.value })">', $content);
$content = preg_replace('/<input\stype="checkbox"\sname="'.$value['if_field'].'\[\]"\svalue="'.$value['if_value'].'"(.*?)>/', '<input type="checkbox" name="'.$value['if_field'].'[]" value="'.$value['if_value'].'"$1 on="change:AMP.setState({ option_'.$value['if_field'].'_'.$group_name.': (event.checked == true ? event.value: \'\') })">', $content);
}
}
}
}
add_action('amphtml_template_css', 'amp_cf7_form_styling'); // compatibility with WP AMP for WordPress and WooCommerce
return $content;
}
}
// example to create the shortcode in contact form 7
/*add_action( 'wpcf7_init', 'ampforwp_cf7_add_form_tag_url' );
function ampforwp_cf7_add_form_tag_url(){
wpcf7_add_form_tag('sourceurl', 'wpcf7_ampforwp_sourceurl_shortcode_handler', true);
}
function wpcf7_ampforwp_sourceurl_shortcode_handler($tag) {
if (!is_object($tag)) return '';
$name = $tag->name;
if (empty($name)) return '';
$html = '<input type="hidden" name="' . $name . '" value="http://' . $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] . '" />';
return $html;
}
*/
//Add the mustache script for singular & archive
// add_action('amp_post_template_head','amp_cf7_add_mustache_singular',11);
function amp_cf7_add_mustache_singular(){
global $redux_builder_amp;
$post_id = get_the_ID();
$cf7_form_checker = '';
if( is_singular() || is_archive() ) {
$cf7_form_checker = get_post_meta($post_id, 'amp-cf7-form-checker', true);
if ( ! empty( $cf7_form_checker )) { ?>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-latest.js"></script>
<?php }
}
}
//Add the mustache script for home & front page
// add_action('amp_post_template_head','amp_cf7_add_mustache');
function amp_cf7_add_mustache(){
global $redux_builder_amp;
$post_id = '';
$cf7_form_checker = '';
if( is_home() && $redux_builder_amp['amp-frontpage-select-option'] ) {
$post_id = $redux_builder_amp['amp-frontpage-select-option-pages'] ;
$cf7_form_checker = get_post_meta($post_id, 'amp-cf7-form-checker', true);
if ( ! empty( $cf7_form_checker )) { ?>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-latest.js"></script>
<?php }
}
}
add_action('amphtml_template_head','ampforwp_with_wp_amp');
function ampforwp_with_wp_amp() {
$post_id = get_the_ID();
$cf7_form_checker = '';
if ( is_singular() || is_home() || is_archive() || is_front_page() ) {
$cf7_form_checker = get_post_meta($post_id, 'amp-cf7-form-checker', true);
if ( ! empty( $cf7_form_checker )) { ?>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-latest.js"></script>
<?php } ?>
<?php }
}
function ampforwp_add_required_scripts($data) {
global $redux_builder_amp;
if ( is_singular() || is_home() || ( is_home() && $redux_builder_amp['amp-frontpage-select-option'] ) || is_archive()) {
// Adding Form Script
if ( empty( $data['amp_component_scripts']['amp-form'] ) ) {
$data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js';
}
if(empty($data['amp_component_scripts']['amp-mustache'])){
$data['amp_component_scripts']['amp-mustache']='https://cdn.ampproject.org/v0/amp-mustache-latest.js';
}
if(class_exists('CF7CF')){
if(empty($data['amp_component_scripts']['amp-bind'])){
$data['amp_component_scripts']['amp-bind']='https://cdn.ampproject.org/v0/amp-bind-0.1.js';
}
}
}
return $data;
}
add_filter('amp_content_sanitizers','ampforwp_add_custom_blacklist', 85,1);
add_filter('ampforwp_content_sanitizers','ampforwp_add_custom_blacklist', 85,1);
function ampforwp_add_custom_blacklist($data){
global $redux_builder_amp;
$post_id = '';
$cf7_form_checker = '';
$post_id = get_the_ID();
if( is_home() && $redux_builder_amp['amp-frontpage-select-option'] ) {
$post_id = $redux_builder_amp['amp-frontpage-select-option-pages'] ;
}
$cf7_form_checker = 1;
// This will make sure the sanitizer will only run
// When post has CF7 form
// print_r($cf7_form_checker); die;
if ( ! empty( $cf7_form_checker )) {
$ampforwp_pagebuilder_enable = get_post_meta($post_id,'ampforwp_page_builder_enable', true);
unset($data['AMP_Blacklist_Sanitizer']);
unset($data['AMPFORWP_Blacklist_Sanitizer']);
if(!function_exists('amp_activate') && $ampforwp_pagebuilder_enable !=='yes'){
unset($data['AMP_Tag_And_Attribute_Sanitizer']);
}
if( $ampforwp_pagebuilder_enable == 'yes' ){
require_once AMP_CF7_PLUGIN_PATH .'/amp-cf7-tag-attr-sanitizer.php';
unset($data['AMP_Tag_And_Attribute_Sanitizer']);
$data[ 'AMP_CF7_Tag_And_Attribute_Sanitizer' ] = array();
return $data;
}
$data[ 'AMPFORWP_CF7_Blacklist' ] = array();
if(function_exists('amp_activate')){
$getOption = get_option('amp-options');
if ($getOption['theme_support'] == 'standard' || $getOption['theme_support'] == 'transitional'){
unset($data[ 'AMPFORWP_CF7_Blacklist' ]);
}
}
if(is_plugin_active('wp-tab-widget/wp-tab-widget.php')){
$data[ 'AMP_Blacklist_Sanitizer' ] = array();
}
if(get_post_meta($post_id, 'amp-cf7-form-checker', true)!=1){
update_post_meta($post_id, 'amp-cf7-form-checker', 1);
}
}
return $data;
}
add_filter('ampforwp_tree_shaking_white_list_selector','amp_cf7_tree_shaking_whitelists',20);
function amp_cf7_tree_shaking_whitelists($white_list){
$white_list[] = '.amp-form-submit-error span.required_field:before';
$white_list[] = '.typeMismatch';
return $white_list;
}
add_action('ampforwp_modify_the_content','skip_invalid_content');
function skip_invalid_content($content){
$content = str_replace('caption=""', '', $content);
return $content;
}
add_filter('amp_post_template_data','inc_amp_script');
function inc_amp_script( $data ){
if ( empty( $data['amp_component_scripts']['amp-carousel'] ) ) {
$data['amp_component_scripts']['amp-carousel'] =
'https://cdn.ampproject.org/v0/amp-carousel-0.1.js';
}
return $data;
}
add_filter('the_content','ampforwp_check_cf7_shortcode');
add_filter('widget_text', 'ampforwp_check_cf7_shortcode', 9);
function ampforwp_check_cf7_shortcode($content){
global $redux_builder_amp;
$post_id = '';
$cf7_form_checker = '';
$post_id = get_the_ID();
if( is_home() && $redux_builder_amp['amp-frontpage-select-option'] ) {
$post_id = $redux_builder_amp['amp-frontpage-select-option-pages'] ;
}
$cf7_form_checker = get_post_meta($post_id, 'amp-cf7-form-checker', true);
if ( has_shortcode($content, 'contact-form-7' ) && empty($cf7_form_checker) ) {
update_post_meta($post_id, 'amp-cf7-form-checker', 1);
}
if ( has_shortcode($content, 'contact-form-7' )){
add_filter( 'amp_post_template_data', 'ampforwp_cf7_recaptcha_scripts', 100,1 );
add_action('amp_post_template_css', 'amp_cf7_form_styling',10);
}
return $content;
}
function ampforwp_cf7_recaptcha_scripts( $data ) {
global $redux_builder_amp;
if ( empty( $data['amp_component_scripts']['amp-recaptcha-input'] ) && (isset($redux_builder_amp['ampforwp-cf7-recaptcha']) && $redux_builder_amp['ampforwp-cf7-recaptcha'] == 1 ) ) {
$data['amp_component_scripts']['amp-recaptcha-input'] = 'https://cdn.ampproject.org/v0/amp-recaptcha-input-0.1.js';
}
return $data;
}
function ampforwp_after_submit_notice(){
$cf7_nonce = wp_create_nonce( 'amp_cf7_nonce' );
$output = '';
$output = '<input type="hidden" name="amp_cf7_nonce" value="'.$cf7_nonce.'">
<div submitting><div class="ampforwp-cf7-loading"></div></div>
<div submit-success class="ampforwp-form-status-success-new">
<template type="amp-mustache">
<div class="ampforwp-form-status amp_cf7_success">
{{message}}
</div>
</template>
</div>
<div submit-error>
<template type="amp-mustache">
<div class="ampforwp-form-status amp_cf7_error">
{{message}}
</div>
</template>
</div>';
return $output;
}
if ( ! function_exists( 'ampforwp_get_array' ) ) {
function ampforwp_get_array( $array, $keys, $default = null ) {
if ( empty( $keys ) && $keys !== 0 ) {
return $array;
}
if ( ! is_array( $array ) ) {
return $default;
}
if ( ! is_array( $keys ) && isset( $array[ $keys ] ) ) {
return $array[ $keys ];
}
if ( is_array( $keys ) ) {
$current = $array;
foreach ( $keys as $key ) {
if ( ! array_key_exists( $key, $current ) ) {
return $default;
}
$current = $current[ $key ];
}
return $current;
}
return $default;
}
}
function amp_cf7_sticky_form_styling(){
global $redux_builder_amp;
if( isset($redux_builder_amp['ampforwp-cf7-sticky-form']) && $redux_builder_amp['ampforwp-cf7-sticky-form'] == 1){
?>
#sticky-form{
position: fixed;
top: auto;
bottom: 3px;
right: 20px;
background: #fff;
border-radius: 10px 20px 0px 0px;
width:300px;
font-family: 'Arial', sans-serif;
z-index: 9999;
box-shadow: 0 20px 40px 8px rgba(0, 0, 0, 0.25);
font-size: 15px;
}
#content {
display: none;
}
#sticky-form:target #content {
display: inline-block;
width:100%;
height: min-content;
}
#sticky-form:target #open {
display: none;
}
#content .msg{
font-size:14px;
line-height:1.4;
display: block;
color:#222;
margin: 0px 0px 20px;
}
#content textarea{
border: 1px solid #ccc;
background: #fff;
border-radius: 3px;
padding: 10px;
resize:none;
}
.wpcf7 label{
font-size:14px;
}
#content form .wpcf7-form-control-wrap{
margin-bottom:12px;
display: inline-block;
margin-top:5px;
}
#content form span input{
border: 1px solid #ccc;
background: #fff;
border-radius: 3px;
padding: 10px;
box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}
#sticky-form #content .wpcf7{
height:495px;
overflow-y:scroll;
}
<?php if(function_exists('ampforwp_get_setting') && (1 == ampforwp_get_setting('amp-design-selector') || 4 == ampforwp_get_setting('amp-design-selector'))) { ?>
#sticky-form #content .wpcf7-form{
margin: 0;
}
<?php }else{ ?>
#sticky-form #content .wpcf7-form{
margin:-15px 0;
}
<?php }?>
<?php if(4 != ampforwp_get_setting('amp-design-selector')) { ?>
#sticky-form #content .wpcf7-textarea{
height:65px;
}
#sticky-form #content .wpcf7-form span,
#sticky-form #content .wpcf7-form p{
margin-bottom:0;
}
#sticky-form #content .ampforwp-form-status.amp_cf7_error{
font-size:13px;}
<?php }?>
<?php
if(isset($redux_builder_amp['amp-design-selector']) && $redux_builder_amp['amp-design-selector'] == 4 ){?>
#content form span input{
width: 100%;
}
#sticky-form:target #content {
display: inline-block;
width:100%;
height: min-content;
}
#content textarea{
width: 100%;
}
<?php }else{?>
#content form span input{
width: 90%;
}
#sticky-form:target #content {
display: inline-block;
width:100%;
height: min-content;
}
#content textarea{
width: 90%;
}
<?php } ?>
#sticky-form #open{
background: #414765;
display: flex;
align-items: center;
padding: 15px 20px;
color: #fff;
text-decoration:none;
border-radius: 2px 2px 0px 0px;
}
#sticky-form #close span{
font-size: 18px;
position: relative;
left: -38px;
z-index: 99999;
color: #000;
top: 0px;
border-radius: 100%;
background: #d6d6d6;
padding: 6px 10px 6px 10px;
}
#sticky-form #close{
width: 100%;
background: #414765;
display: inline-block;
padding: 10px 0px;
color: #fff;
text-decoration: none;
border-radius: 2px 2px 0px 0px;
}
<?php if(4 != ampforwp_get_setting('amp-design-selector')) { ?>
#sticky-form #close{
padding: 10px 0px;
}
#sticky-form .wpcf7-form-control.wpcf7-submit{
margin-bottom:20px;
}
<?php }?>
.fm-txt{
padding:15px;
}
#sticky-form .wpcf7-form-control.wpcf7-submit, #sticky-form .wpcf7-form-control.wpcf7-submit:active, #sticky-form .wpcf7-form-control.wpcf7-submit:hover{
background: #0faf0f;
color: #fff;
font-size: 15px;
padding: 12px 20px;
display: inline-block;
border-radius: 3px;
border: none;
width: 100%;
cursor: pointer;
position: relative;}
.ampforwp-form-status.amp_cf7_success{
color: green;
font-weight: bold;
margin-bottom: 10px;
font-size: 15px;
line-height: 1.2;
}
.ampforwp-form-status.amp_cf7_error{
font-size: 16px;
font-weight: bold;
color: red;
margin-bottom: 10px;
font-size: 15px;
line-height: 1.2;
}
@media(max-width:375px){
#sticky-form{
right:0;
}
#sticky-form #close span{left:-20px;}
}
<?php } // Sticky Form Ends
}
/*remmoving this function because scripts are already added above
add_action( 'amp_post_template_head', 'ampforwp_add_post_template_scripts' );
function ampforwp_add_post_template_scripts( $amp_template ) {
$scripts = $amp_template->get( 'amp_component_template', array() );
if ( $scripts) {
foreach ( $scripts as $template => $script ) : ?>
<script custom-template="<?php echo esc_attr( $template ); ?>" src="<?php echo esc_url( $script ); ?>" async></script>
<?php endforeach;
}
}
*/
// show required filed message with amp plugin.
$getOption = get_option('amp-options');
if ( $getOption['theme_support'] == 'standard' || $getOption['theme_support'] == 'transitional'){
add_action('wp_head', 'field_required_css_for_amp');
}
function field_required_css_for_amp(){
if(function_exists('amp_activate')){
$required_msg = '';
if(!function_exists('ampforwp_add_custom_post_support')){
$required_msg = '.amp-form-submit-error span.required_field:before {content: "The field is required.";color: #f00;display: block;top: 6px;position: relative;font-weight: 700;}';
}
echo'<style>'.$required_msg.'
.ampforwp-form-status {
background: #FFF9C4;
padding: 10px 17px;
margin: 20px 0;
font-size: 15px;
border: 1px solid rgba(0,0,0,0.14);
}
.amp_cf7_success {
background: #DCEDC8;
}
form.amp-form-submit-success label, form.amp-form-submit-success .wpcf7-submit,form.amp-form-submit-success .captcha-section, form.amp-form-submit-success .wpcf7-form-control-wrap{display: none;}
.ampforwp-cf7-loading {
animation: ampforwpspinColor 1s ease-in-out infinite;
margin: 20px;
border: 5px solid #f0eff5;
border-radius: 50%;
width: 40px;
height: 40px;
}
@keyframes ampforwpspinColor {
0% {
border-top:5px solid #387eff;
border-bottom:5px solid #387eff;
}
100% {
transform: rotate(360deg);
border-top:5px solid #387eff;
border-bottom:5px solid #387eff;
}
}.valueMissing,.typeMismatch{border: 1px solid red;}</style>';
}
}
function amp_cf7_form_styling(){ global $redux_builder_amp;
if($redux_builder_amp['amp-cf7-translator-The field is required'] !== ""){
$text = $redux_builder_amp['amp-cf7-translator-The field is required'];
}else{$text = 'The field is required.';}
?>
<?php if(function_exists('wpcf7_honeypot_formtag_handler')){?>
.cf7-hp-hidden {
display: none;
visibility: hidden;
}
<?php } ?>
.valueMissing{border: 1px red solid;}
#anythingChecked {
display: none;
}
.wpcf7cf-hidden{display:none;}.wpcf7cf-show{display:block;}
.wpcf7 label{font-size:11px;color:#555;letter-spacing:.5px;text-transform:uppercase;line-height:1}.wpcf7-form-control{padding:10px 9px;border-radius:2px;border:1px solid #ccc;font-size:14px}.wpcf7 form{margin-bottom:40px;font-family:sans-serif}.wpcf7 p{margin-bottom:15px}.wpcf7-text{color:#111;width:240px}.wpcf7 .wpcf7-form-control:focus{outline:none}.wpcf7-submit,a.ampforwp-cf7-prvs{background:#333;border:0;font-size:11px;padding:15px 30px;text-transform:uppercase;letter-spacing:2px;font-weight:700;color:#fff;box-shadow:2px 3px 6px rgba(102,102,102,0.33)}.ampforwp-form-status{background:#FFF9C4;padding:10px 17px;margin:20px 0;font-size:15px;border:1px solid rgba(0,0,0,0.14)}.amp_cf7_error{background:#FFF9C4}.amp_cf7_success{background:#DCEDC8}
.wpcf7-form-control-wrap.honeypot-Darren-wrap{display:none;}
.wpcf7-form-control-wrap { display: inline-block; width: 100%;}
.amp-form-submit-error span.required_field:before {content: "<?php //echo $text;?>";color: #f00;display: block;top: 6px;position: relative;font-weight: 700;}
@keyframes Pop-up-delay {
to {
visibility: visible;
}
}
form.amp-form-submit-success label, form.amp-form-submit-success .wpcf7-submit, form.amp-form-submit-success .wpcf7-form-control-wrap{display: none;}
.ampforwp-cf7-loading {
animation: ampforwpspinColor 1s ease-in-out infinite;
margin: 20px;
border: 5px solid #f0eff5;
border-radius: 50%;
width: 40px;
height: 40px;
}
@keyframes ampforwpspinColor {
0% {
border-top:5px solid #387eff;
border-bottom:5px solid #387eff;
}
100% {
transform: rotate(360deg);
border-top:5px solid #387eff;
border-bottom:5px solid #387eff;
}
}
.amp_dp {
padding: 10px 9px;
border-radius: 2px;
border: 1px solid #ccc;
font-size: 14px;
}
body #cf7-notification.amp-active { background: hsla(0, 2%, 14%, 0.7); border-color: #242323b3; z-index: 10000; height: -webkit-fill-available; height: -moz-fill-available; top:0; visibility: hidden; animation: 0s linear <?php if( isset($redux_builder_amp['ampforwp-cf7-popup-sec']) && $redux_builder_amp['ampforwp-cf7-popup-sec'] == true) { echo $redux_builder_amp['ampforwp-cf7-popup-sec']; } else {?> 3s <?php } ?> forwards Pop-up-delay;
}
span.wpcf7-form-control.wpcf7-acceptance
{
display: block;
border: 1px solid #ccc;
}
.ampforwp-cf7-popup { position: fixed; -webkit-overflow-scrolling: touch; top: 0; right: 0; bottom: 0; left: 0; padding: 1rem; display: flex; justify-content: center; }
.cf7-pop-up-form { position: relative;background: <?php if(isset($redux_builder_amp['ampforwp-cf7-pop-up-background-color']) && true == $redux_builder_amp['ampforwp-cf7-pop-up-background-color']){
echo $redux_builder_amp['ampforwp-cf7-pop-up-background-color']['color'];
} ?>; padding: 20px 20px 0px 20px;overflow-y:scroll; }
.ampforwp-cf7-pop-up-close-btn { background-color: #525252; border: 1px solid #525252; top: 0; position: absolute; font-size: 12px; padding: 7px 13px; right: 0; }
.cf7-pop-up-headline { text-align: center; padding-bottom: 12px; color:<?php echo $redux_builder_amp['ampforwp-cf7-pop-up-label-color']['color'] ?>; }
<?php if(isset($redux_builder_amp['ampforwp-cf7-pop-up']) && 1 == $redux_builder_amp['ampforwp-cf7-pop-up']){ ?>
.cf7-pop-up-form .wpcf7 label { color:<?php echo $redux_builder_amp['ampforwp-cf7-pop-up-label-color']['color']; ?>; }
.cf7-pop-up-form .wpcf7-submit { background: <?php echo $redux_builder_amp['ampforwp-cf7-pop-up-btn-color']['color'] ?>;
color:<?php echo $redux_builder_amp['ampforwp-cf7-pop-up-btn-label-color']['color']; ?>; }
.cf7-pop-up-form .wpcf7 textarea{ width:100%; height: 100px;}
@media(min-width:375px){
.ampforwp-cf7-popup{
align-items: center;
}
}
amp-user-notification button { color: #fff; }
<?php if(isset($redux_builder_amp['amp-design-selector']) && $redux_builder_amp['amp-design-selector'] != 4){ ?>
.cf7-pop-up-form { height: 488px; }
.cf7-pop-up-form .wpcf7 textarea{ width: 92%; }
.cf7-pop-up-form .wpcf7-text { width: 228px; height: 10px; }
.cf7-pop-up-form h3{ padding: 0; margin-top: 0px;}
#cf7-notification{ text-align: unset; }
<?php }
}
// Sticky Form CSS
}
//rest api endpoint submission.
add_action('pre_amp_render_post','remove_non_endpoint_api');
function remove_non_endpoint_api(){
remove_action( 'rest_api_init', 'wpcf7_rest_api_init', 10, 0 );
}
add_action( 'rest_api_init', 'wpcf7_rest_api_init_amp', 10, 0 );
function wpcf7_rest_api_init_amp() {
global $redux_builder_amp;
if(isset($redux_builder_amp['ampforwp_cf7_POST_method']) && $redux_builder_amp['ampforwp_cf7_POST_method'] == 'restapiendpoint' ){
$namespace = 'contact-form-7-for-amp/v1';
register_rest_route( $namespace,
'/contact-forms/(?P<id>\d+)/feedback',
array(
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'wpcf7_rest_create_feedback_response_amp',
'permission_callback' => '__return_true',
),
)
);
}
}
function wpcf7_rest_create_feedback_response_amp( WP_REST_Request $request ) {
$url_params = $request->get_url_params();
$item = null;
if ( ! empty( $url_params['id'] ) ) {
$item = wpcf7_contact_form( $url_params['id'] );
}
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( "The requested contact form was not found.", 'contact-form-7-for-amp' ),
array( 'status' => 404 )
);
}
$result = $item->submit();
$unit_tag = $request->get_param( '_wpcf7_unit_tag' );
$response = array(
'into' => '#' . wpcf7_sanitize_unit_tag( $unit_tag ),
'status' => $result['status'],
'message' => $result['message'],
'posted_data_hash' => $result['posted_data_hash'],
);
if ( 'validation_failed' == $result['status'] ) {
$invalid_fields = array();
foreach ( (array) $result['invalid_fields'] as $name => $field ) {
$invalid_fields[] = array(
'into' => 'span.wpcf7-form-control-wrap.'
. sanitize_html_class( $name ),
'message' => $field['reason'],
'idref' => $field['idref'],
'error_id' => sprintf(
'%1$s-ve-%2$s',
$unit_tag,
$name
),
);
}
$response['invalid_fields'] = $invalid_fields;
}
$response = wpcf7_apply_filters_deprecated(
'wpcf7_ajax_json_echo',
array( $response, $result ),
'5.2',
'wpcf7_feedback_response'
);
$response = apply_filters( 'wpcf7_feedback_response', $response, $result );
return rest_ensure_response( $response );
}
add_action('wp_ajax_contact_form_submission','contact_form_submission');
add_action('wp_ajax_nopriv_contact_form_submission','contact_form_submission');
if(isset($_GET['ampsubmit']) && $_GET['ampsubmit'] ==1){
add_action("plugins_loaded",function(){
remove_action( 'wpcf7_mail_sent', 'cf7_success_page_form_submitted');
});
}
function contact_form_submission (){
$form_id = $_POST['_wpcf7'];
if(class_exists('CF7CF')){
$conditions = CF7CF::getConditions($form_id);
}
if(class_exists('CF7CF') && !empty($conditions)){
remove_filter('wpcf7_validate_select*', 'wpcf7_select_validation_filter', 10, 2 );
}
add_filter( 'wpcf7_spam', 'wpcf7_recaptcha_check_with_google_amp', 10 );
//checking nonce
if(!wp_verify_nonce($_POST['amp_cf7_nonce'],'amp_cf7_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
header('HTTP/1.1 500 FORBIDDEN');
echo wp_json_encode( 'Sorry, your nonce did not verify.' );
die;
}
else{
require_once AMP_CF7_PLUGIN_PATH .'/class-amp-cf7-form.php';
}
}
// CF7 Settings
add_filter("redux/options/redux_builder_amp/sections", 'ampforwp_cf7_settings');
if( ! function_exists('ampforwp_cf7_settings') ){
function ampforwp_cf7_settings( $sections ){
$ssl_notify_cf7 = '';
if((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) != 1)
{
$ssl_notify_cf7 = array(
'id' => 'amp-cf7-SSL-info',
'type' => 'info',
'desc' =>"<div style='background: #FFF9C4;padding: 12px;line-height: 1.6;margin:-30px -14px -18px -17px;'><span style='color:#303F9F;'> Note: </span> We've noticed that your site doesn't have the SSL (https) certificate, don't worry forms will work perfectly but it is recommended to have the SSL certificate to make forms work smoothly & fully functional.</div>"
);
}
$sections[] = array(
'title' => __( 'AMP CF7', 'redux-framework-demo' ),
'icon' => 'el el-envelope ',
'id' => 'ampforwp-cf7-subsection',
'desc' => " ",
'subsection' => false,
'fields' => array(
$ssl_notify_cf7,
// for pages
array(
'id' => 'amp-cf7-pages',
'type' => 'section',
'title' => __('Pages', 'accelerated-mobile-pages'),
'indent' => true,
'layout_type' => 'accordion',
'accordion-open'=> 1,
),
array(
'id' => 'ampforwp-cf7-pages',
'type' => 'switch',
'title' => 'Show CF7 On All Pages',
'default' => 0,
),
array(
'id' => 'ampforwp-cf7-shortcode',
'type' => 'text',
'title' => __('CF7 ID', 'accelerated-mobile-pages'),
'required' => array(array('ampforwp-cf7-pages','=','1')),
'default' => '',
),
array(
'id' => 'ampforwp-cf7-content-top',
'type' => 'switch',
'title' => 'Above Content',
'default' => 0,
'required' => array('ampforwp-cf7-pages','=','1'),
),
array(
'id' => 'ampforwp-cf7-content-bottom',
'type' => 'switch',
'title' => 'Below Content',
'default' => 0,
'required' => array('ampforwp-cf7-pages','=','1'),
),
// for posts
array(
'id' => 'amp-cf7-post',
'type' => 'section',
'title' => __('Posts', 'accelerated-mobile-pages'),
'indent' => true,
'layout_type' => 'accordion',
'accordion-open'=> 1,
),
array(
'id' => 'ampforwp-cf7-posts',
'type' => 'switch',
'title' => 'Show CF7 On All Posts',
'default' => 0,
),
array(
'id' => 'ampforwp-cf7-posts-shortcode',
'type' => 'text',
'title' => __('CF7 ID', 'accelerated-mobile-pages'),
'required' => array(array('ampforwp-cf7-posts','=','1')),
'default' => '',
),
array(
'id' => 'ampforwp-cf7-posts-content-top',
'type' => 'switch',
'title' => 'Above Content',
'default' => 0,
'required' => array('ampforwp-cf7-posts','=','1'),
),
array(
'id' => 'ampforwp-cf7-posts-content-bottom',
'type' => 'switch',
'title' => 'Below Content',
'default' => 0,
'required' => array('ampforwp-cf7-posts','=','1'),
),
array(
'id' => 'amp-cf7-recaptcha',
'type' => 'section',
'title' => __('ReCAPTCHA', 'accelerated-mobile-pages'),
'indent' => true,
'layout_type' => 'accordion',
'accordion-open'=> 1,
),
array(
'id' => 'ampforwp-cf7-recaptcha',
'type' => 'switch',
'title' => __(' ReCAPTCHA v3 ', 'accelerated-mobile-pages'),
'desc' => __('Enable or disable the Recaptcha v3 feature','accelerated-mobile-pages'),
'default' => 0,
),
array(
'id' =>'ampforwp-cf7-recaptcha-site',
'type' => 'text',
'title' => esc_html__('Site Key','accelerated-mobile-pages'),
'tooltip-subtitle' => esc_html__('You can get the site key from here ','accelerated-mobile-pages').'<a target="_blank" href="https://www.google.com/recaptcha/admin/create">'.esc_html__('form here','accelerated-mobile-pages').'</a>',
'default' => '',
'required' => array(
array('ampforwp-cf7-recaptcha', '=' , '1')),
),
array(
'id' =>'ampforwp-cf7-recaptcha-secerete',
'type' => 'text',
'title' => esc_html__('Secret Key','accelerated-mobile-pages'),
'tooltip-subtitle' => esc_html__('You can get the Secret Key from here ','accelerated-mobile-pages').'<a target="_blank" href="https://www.google.com/recaptcha/admin/create">'.esc_html__('form here','accelerated-mobile-pages').'</a>',
'default' => '',
'required' => array(
array('ampforwp-cf7-recaptcha', '=' , '1')),
),
array(
'title' => __('Redirection Settings', 'accelerated-mobile-pages'),
'id' => 'amp-cf7-redirection-settings',
'type' => 'section',
'indent'=> true,
'layout_type' => 'accordion',
'accordion-open'=> 1,
),
array(
'id' =>'amp-cf7-redirection-main-switch',
'type' => 'switch',
'title' => esc_html__('Redirection on Submit', 'accelerated-mobile-pages'),
'default' => 0,
'tooltip-subtitle' => esc_html__('Enable or disable on submit redirection for your AMP', 'accelerated-mobile-pages'),
'true' => 'true',
'false' => 'false',
),
array(
'id' =>'amp-cf7-redirection-int-switch',
'type' => 'switch',
'class' => 'child_opt child_opt_arrow',
'title' => esc_html__('Set landing page for AMP', 'accelerated-mobile-pages'),
'default' => 0,
'tooltip-subtitle' => esc_html__('This option will override contact form redirection setting (in case if you are using) only for your AMP', 'accelerated-mobile-pages'),
'desc' => __('Note: For Form specific redirection you can add \'amp_redirect\' attribute in the shortcode. Example: [contact-form-7 id=”20″ title=”Contact form 1″ amp_redirect="URL"]
','accelerated-mobile-pages'),
'true' => 'true',
'false' => 'false',
'required' => array('amp-cf7-redirection-main-switch','=','1'),
),
array(
'id' => 'amp-cf7-redirection-select-option',
'type' => 'select',
'class' => 'child_opt child_opt_arrow',
'title' => esc_html__('Select page', 'accelerated-mobile-pages'),
'required' => array(array('amp-cf7-redirection-main-switch', '=' , '1'),array('amp-cf7-redirection-int-switch', '=', '1')),
'data' => 'page',
'args' => array(
'post_type' => 'page',
'posts_per_page' => 500
),
'default' => '2',
),
array(
'id' =>'amp-cf7-redirection-ext-switch',
'type' => 'switch',
'class' => 'child_opt child_opt_arrow',
'title' => esc_html__('Want to use external Url?', 'accelerated-mobile-pages'),
'default' => 0,
'tooltip-subtitle' => esc_html__('This option will override contact form redirection setting (in case if you are using) only for your AMP', 'accelerated-mobile-pages'),
'true' => 'true',
'false' => 'false',
'required' => array('amp-cf7-redirection-main-switch','=','1'),
),
array(
'id' => 'amp-cf7-redirection-ext-url',
'type' => 'text',
'class' => 'child_opt child_opt_arrow',
'title' => esc_html__('Add Url', 'accelerated-mobile-pages'),
'required' => array(array('amp-cf7-redirection-main-switch', '=' , '1'),array('amp-cf7-redirection-ext-switch', '=', '1')),
'default' => '',
),
array(
'title' => __('Designs of Form', 'accelerated-mobile-pages'),
'id' => 'ampforwp-cf7-popup-feature',
'type' => 'section',
'indent'=> true,
'layout_type' => 'accordion',
'accordion-open'=> 1,
),
array(
'id' => 'ampforwp-cf7-pop-up',
'type' => 'switch',
'title' => 'Light Box',
'default' => 0,
),
array(
'id' => 'ampforwp-cf7-pop-up-shortcode',
'type' => 'text',
'title' => __('Contact form ID', 'accelerated-mobile-pages'),
'required' => array(array('ampforwp-cf7-pop-up','=','1')),
'default' => '',
),
array(
'id' => 'ampforwp-cf7-pop-up-headline-text',
'type' => 'text',
'title' => __('Form Title', 'accelerated-mobile-pages'),
'required' => array(array('ampforwp-cf7-pop-up','=','1')),
'default' => 'Headline Title',
),
array(
'id' => 'ampforwp-cf7-popup-sec',
'type' => 'text',
'default' => '3s',
'required' => array('ampforwp-cf7-pop-up','=','1'),
'title' => 'Seconds to delay the Pop-up',
'desc' => 'When a user visits the site, It takes some seconds to pop-up the form( eg: 5s ).',
),
array(
'id' => 'ampforwp-cf7-pop-up-background-color',
'type' => 'color_rgba',
'title' => 'Form Background',
'default' => array(
'color' => '#fff',
),
'required' => array( 'ampforwp-cf7-pop-up', '=','1')
),
array(
'id' => 'ampforwp-cf7-pop-up-label-color',
'type' => 'color_rgba',
'title' => 'Label',
'default' => array(
'color' => '#555',
),
'required' => array( 'ampforwp-cf7-pop-up', '=','1')
),
array(
'id' => 'ampforwp-cf7-pop-up-btn-color',
'type' => 'color_rgba',
'title' => 'Submit Button',
'default' => array(
'color' => '#333',
),
'required' => array( 'ampforwp-cf7-pop-up', '=','1')
),
array(
'id' => 'ampforwp-cf7-pop-up-btn-label-color',
'type' => 'color_rgba',
'title' => 'Submit Button Label',
'default' => array(
'color' => '#fff',
),
'required' => array( 'ampforwp-cf7-pop-up', '=','1')
),
// Sticky Form Fields
array(
'id' => 'ampforwp-cf7-sticky-form',
'type' => 'switch',
'title' => 'Sticky Form',
'default' => 0,
),
array(
'id' => 'ampforwp-cf7-sticky-form-shortcode',
'type' => 'text',
'title' => __('Contact form ID', 'accelerated-mobile-pages'),
'required' => array(array('ampforwp-cf7-sticky-form','=','1')),
'default' => '',
),
array(
'id' => 'ampforwp-cf7-sticky-form-headline-text',
'type' => 'text',
'title' => __('Form Headline', 'accelerated-mobile-pages'),
'required' => array(array('ampforwp-cf7-sticky-form','=','1')),
'default' => 'Send us a message',
),
array(
'title' => __('POST Method', 'accelerated-mobile-pages'),
'id' => 'ampforwp-cf7-POST_method',
'type' => 'section',
'indent'=> true,
'layout_type' => 'accordion',
'accordion-open'=> 0,
),
array(
'id' => 'ampforwp_cf7_POST_method',
'type' => 'select',
'title' => esc_html__('Select Post Method', 'accelerated-mobile-pages'),
'options' => array(
'adminajax' => 'Admin Ajax',
'restapiendpoint'=> 'Rest API',
),
'default' => 'adminajax',
)
),
);
$sections[] = array(
'title' => __( 'Translation Panel', 'accelerated-mobile-pages' ),
'id' => 'ampforwp-cf7-translation-panel',
'subsection' => true,
'type' => 'section',
'fields' => array(
// Translation Panel
array(
'id' => 'translation',
'type' => 'section',
'title' => __('Translation', 'accelerated-mobile-pages'),
'indent' => true,
),
array(
'id' => 'amp-cf7-translator-The field is required',
'type' => 'text',
'title' => __('The field is required', 'accelerated-mobile-pages'),
'default' => __('The field is required.','accelerated-mobile-pages'),
'required' => array( 'amp-use-pot', '=' , 0 )
),
array(
'id' => 'amp-cf7-translator-invalid-email-format',
'type' => 'text',
'title' => __('Invalid Email Format', 'accelerated-mobile-pages'),
'default' => __('Invalid Email Format','accelerated-mobile-pages'),
'required' => array( 'amp-use-pot', '=' , 0 )
),
array(
'id' => 'amp-cf7-translator-invalid-phone-format',
'type' => 'text',
'title' => __('Invalid Phone Format', 'accelerated-mobile-pages'),
'default' => __('The telephone number is invalid.','accelerated-mobile-pages'),
'required' => array( 'amp-use-pot', '=' , 0 )
),
array(
'id' =>'amp-cf7-fill-the-fields',
'type' =>'text',
'title' => __('Please fill all the required Fields','accelerated-mobile-pages'),
'default' => __('Please fill all the required Fields','accelerated-mobile-pages'),
'required' => array('amp-use-pot', '=', 0)
),
array(
'id' => 'amp-cf7-Please-fill-all-the',
'type' => 'text',
'title' => __('Please fill all the required Fields with Valid Email Format', 'accelerated-mobile-pages'),
'default' => __('Please fill all the required Fields with Valid Email Format','accelerated-mobile-pages'),
'required' => array( 'amp-use-pot', '=' , 0 )
),
array(
'id' =>'amp-cf7-success-msg',
'type' =>'text',
'title' => __('Success message','accelerated-mobile-pages'),
'default' => __('Thank you, your form has been submitted','accelerated-mobile-pages'),
'required' => array('amp-use-pot', '=', 0)
),
), );
return $sections;
}
}
// CF7 for All Pages & Posts
add_action('pre_amp_render_post', 'ampforwp_cf7_all_pages_and_posts_enabler');
if( ! function_exists(' ampforwp_cf7_all_pages_and_posts_enabler ') ){
function ampforwp_cf7_all_pages_and_posts_enabler(){
global $post, $redux_builder_amp;
if( (is_page() && 1 == $redux_builder_amp['ampforwp-cf7-pages']) || ( is_single() && 1 == $redux_builder_amp['ampforwp-cf7-posts']) ){
add_filter('amp_post_template_data','ampforwp_add_required_scripts', 20);
add_action('amp_post_template_css', 'amp_cf7_form_styling');
update_post_meta($post->ID, 'amp-cf7-form-checker', 1);
add_filter( 'amp_post_template_data', 'ampforwp_cf7_recaptcha_scripts', 10,1 );
if( (true == $redux_builder_amp['ampforwp-cf7-content-top']) || (true == $redux_builder_amp['ampforwp-cf7-posts-content-top']) ){
add_action('ampforwp_before_post_content', 'ampforwp_cf7_all_pages_and_posts');
add_action('ampforwp_inside_post_content_before', 'ampforwp_cf7_all_pages_and_posts');
}
if( (true == $redux_builder_amp['ampforwp-cf7-content-bottom']) || (true == $redux_builder_amp['ampforwp-cf7-posts-content-bottom']) ){
add_action('ampforwp_after_post_content', 'ampforwp_cf7_all_pages_and_posts');
}
}
}
}
add_action('pre_amp_render_post','amp_cf7_front_page');
function amp_cf7_front_page(){
global $redux_builder_amp;
if( function_exists('ampforwp_is_front_page') && ampforwp_is_front_page() && ( true == $redux_builder_amp['ampforwp-cf7-content-top']) )
{
add_action('ampforwp_before_post_content', 'ampforwp_cf7_all_pages_and_posts');
add_action('amp_post_template_css', 'amp_cf7_form_styling');
}
if( function_exists('ampforwp_is_front_page') && ampforwp_is_front_page() && ( true == $redux_builder_amp['ampforwp-cf7-content-bottom']) )
{
add_action('ampforwp_after_post_content', 'ampforwp_cf7_all_pages_and_posts');
add_action('amp_post_template_css', 'amp_cf7_form_styling');
}
}
if( ! function_exists( ' ampforwp_cf7_all_pages_and_posts ' ) ){
function ampforwp_cf7_all_pages_and_posts(){
global $redux_builder_amp;
if( is_page() || ampforwp_is_front_page() && 1 == $redux_builder_amp['ampforwp-cf7-pages'] ) {
$cf7_shortcode = $redux_builder_amp['ampforwp-cf7-shortcode'];
$cf7_form_data = do_shortcode('[contact-form-7 id=" '. $cf7_shortcode . ' "]');
$sanitized_form_data = new AMPFORWP_Content( $cf7_form_data,
apply_filters( 'amp_content_embed_handlers', array() ),
apply_filters( 'amp_content_sanitizers', array('AMP_Style_Sanitizer' => array() ) )
);
$form_content = $sanitized_form_data->get_amp_content();
echo $form_content;
}
else {
if( is_single() && 1 == $redux_builder_amp['ampforwp-cf7-posts'] ) {
$cf7_posts_shortcode = $redux_builder_amp['ampforwp-cf7-posts-shortcode'];
$cf7_posts_form_data = do_shortcode('[contact-form-7 id=" '. $cf7_posts_shortcode . ' "]');
$posts_sanitized_form_data = new AMPFORWP_Content( $cf7_posts_form_data,
apply_filters( 'amp_content_embed_handlers', array() ),
apply_filters( 'amp_content_sanitizers', array('AMP_Style_Sanitizer' => array() ) )
);
$posts_form_content = $posts_sanitized_form_data->get_amp_content();
echo $posts_form_content;
}
}
}
}
if( shortcode_exists( 'contact-form-7' ) ){
add_filter('widget_text', 'ampforwp_widget_text_cf7',12);
if( ! function_exists('ampforwp_widget_text_cf7') ){
function ampforwp_widget_text_cf7($content){
if( function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint() ) {
$dom = '';
$nodes = '';
$num_nodes = '';
if( !empty( $content ) ){
// Create a new document
$dom = new DOMDocument();
if( function_exists( 'mb_convert_encoding' ) ){
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
}
libxml_use_internal_errors(true);
$dom->loadHTML($content);
libxml_clear_errors();
$nodes = $dom->getElementsByTagName( 'form' );
$num_nodes = $nodes->length;
if( $num_nodes != 0 ) {
add_filter('amp_content_sanitizers','ampforwp_add_custom_blacklist2');
add_filter('amp_post_template_data','ampforwp_add_required_scripts', 9);
add_action('amp_post_template_css', 'amp_cf7_form_styling',99);
}
$content = $dom->saveHTML();
}
return $content;
}
}
}
}
function ampforwp_add_custom_blacklist2($data){
require_once AMP_CF7_PLUGIN_PATH .'/class-amp-cf7-blacklist.php';
unset($data['AMP_Blacklist_Sanitizer']);
unset($data['AMPFORWP_Blacklist_Sanitizer']);
$data[ 'AMPFORWP_CF7_Blacklist' ] = array();
return $data;
}
function ampforwp_shortcode_exists() {
global $shortcode_tags;
return array_key_exists( '["contact-form-7"]', $shortcode_tags );
}
function amp_do_shortcode( $do_amp_content, $ignore_html = false ) {
global $shortcode_tags;
if ( false === strpos( $do_amp_content, '[' ) ) {
return $do_amp_content;
}
if (empty($shortcode_tags) || !is_array($shortcode_tags))
return $do_amp_content;
// Find all registered tag names in $content.
preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $do_amp_content, $matches );
$tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );
if ( empty( $tagnames ) ) {
return $do_amp_content;
}
$do_amp_content = do_shortcodes_in_html_tags( $do_amp_content, $ignore_html, $tagnames );
$pattern = get_shortcode_regex( $tagnames );
$do_amp_content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $do_amp_content );
// Always restore square braces so we don't break things like <!--[if IE ]>
$do_amp_content = unescape_invalid_shortcodes( $do_amp_content );
$posts_sanitized_form_data_amp = new AMPFORWP_Content( $do_amp_content,
apply_filters( 'amp_content_embed_handlers', array() ),
apply_filters( 'amp_content_sanitizers', array('AMP_Style_Sanitizer' => array() ) )
);
$amp_posts_form_content = $posts_sanitized_form_data_amp->get_amp_content();
return $amp_posts_form_content;
}
function ampforwp_do_shortcode_script_runner(){
global $shortcode_tags;
if ( (!isset( $shortcode_tags["contact-form-7"] ))|| (!isset( $shortcode_tags["contact-form"] ))) {
return ;
}
add_filter('amp_post_template_data','ampforwp_add_required_scripts', 20);
add_action('amp_post_template_css', 'amp_cf7_form_styling');
/* $amp_do_cf7_form_checker = get_post_meta($post_id, 'amp-cf7-form-checker', true);
/// var_dump($amp_do_cf7_form_checker); die;
if ( $amp_do_cf7_form_checker == 0 ) {
add_filter('amp_post_template_data','ampforwp_add_required_scripts', 20);
add_action('amp_post_template_css', 'amp_cf7_form_styling',1);
update_post_meta($post_id, 'amp-cf7-form-checker', 1);
} */
}
// Eliminate Validation Error when Sticky Form is used
add_action('pre_amp_render_post', 'elim_val_err');
function elim_val_err(){
remove_filter('wpcf7_form_elements', 'apbct_form__contactForm7__addField');
}
//remove send-pdf-cf7 hook.
add_action('plugins_loaded','remove_send_pdf_cf7',9);
function remove_send_pdf_cf7(){
if(function_exists( 'ampforwp_is_amp_endpoint' )){
remove_action( 'plugins_loaded', '_cf7_sendpdf_load' );
}
}
if(is_plugin_active('cf7-phone-mask-field/cf7-phone-mask-field.php')){
add_action('amp_init','amp_cf7_mask_field_html');
}
function amp_cf7_mask_field_html(){
if ( ! function_exists( 'wpcf7_add_form_tag' ) ) {
return;
}
add_filter('amp_post_template_data','amp_input_masking_scripts', 20);
wpcf7_add_form_tag(array( 'mask', 'mask*' ),'amp_wpcf7mf_mask_shortcode_handler',true);
}
function amp_input_masking_scripts($data){
if ( empty( $data['amp_component_scripts']['amp-inputmask'] ) ) {
$data['amp_component_scripts']['amp-inputmask'] = 'https://cdn.ampproject.org/v0/amp-inputmask-0.1.js';
}
return $data;
}
function amp_wpcf7mf_mask_shortcode_handler( $tag ) {
if ( ! class_exists( 'WPCF7_FormTag' ) ) {
return;
}
$tag = new WPCF7_FormTag( $tag );
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type, 'wpcf7mf-mask' );
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
// the attributes of the tag
$atts = array(
'type' => 'text',
'value' => '',
'name' => $tag->name,
'id' => $tag->get_id_option(),
'class' => $tag->get_class_option( $class ),
'size' => $tag->get_size_option( '40' ),
'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
'maxlength' => $tag->get_maxlength_option(),
'minlength' => $tag->get_minlength_option(),
'aria-required' => (string)$tag->is_required(),
'aria-invalid' => (string)$validation_error,
'data-autoclear' => $tag->has_option( 'autoclear' ),
'data-readonly' => $tag->has_option( 'readonly' ),
);
if ( $atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength'] ) {
unset( $atts['maxlength'], $atts['minlength'] );
}
// extract mask and placeholder from $tag->values
extract( wpcf7mf_get_markers( $tag->values ) );
// set tag type
if ( $tag->has_option( 'type' ) ) {
$atts['type'] = $tag->get_option( 'type', '[-0-9a-zA-Z]+', true );
} elseif ( $mask && ! strrpos( $mask, WPCF7MF_MASK_ANY, 1 ) ) { // $mask is numeric type?
$atts['type'] = 'tel';
}
$atts['placeholder'] = $placeholder ? $placeholder : $mask;
if ( (function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint()) || (function_exists( 'is_wp_amp' ) && is_wp_amp()) || (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) ) {
$atts['mask'] = str_replace('_', '0', $mask);
$atts['mask-output'] = "alphanumeric";
}else{
$atts['data-mask'] = $mask;
}
$atts = wpcf7_format_atts( $atts );
$html = sprintf(
'<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
sanitize_html_class( $tag->name ), $atts, $validation_error
);
return $html;
}
global $redux_builder_amp;
$url_path = $_SERVER['REQUEST_URI'];
$explode_url = explode('/', $url_path);
if(in_array('amp', $explode_url) || in_array('?amp', $explode_url) || isset($redux_builder_amp['ampforwp-amp-takeover']) && ($redux_builder_amp['ampforwp-amp-takeover'])){
add_action('amp_init','amp_cf7_checkbox_field_html');
}
function amp_cf7_checkbox_field_html(){
if(function_exists('wpcf7_add_form_tag')){
wpcf7_add_form_tag( array( 'checkbox', 'checkbox*', 'radio' ),
'amp_wpcf7_checkbox_form_tag_handler',
array(
'name-attr' => true,
'selectable-values' => true,
'multiple-controls-container' => true,
)
);
}
}
function amp_wpcf7_checkbox_form_tag_handler( $tag ) {
if ( empty( $tag->name ) ) {
return '';
}
$req_class = '';
foreach ($tag as $key => $value) {
if($value == "checkbox*"){
$req_class .= 'on="change:AMP.setState({pageStatus: {choiceChecked:event.checked==true ? pageStatus.choiceChecked + 1 :pageStatus.choiceChecked - 1}})"';
}
}
if(function_exists('wpcf7_get_validation_error')){
$validation_error = wpcf7_get_validation_error( $tag->name );
}
if(function_exists('wpcf7_form_controls_class')){
$class = wpcf7_form_controls_class( $tag->type );
}
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
$label_first = $tag->has_option( 'label_first' );
$use_label_element = $tag->has_option( 'use_label_element' );
$exclusive = $tag->has_option( 'exclusive' );
$free_text = $tag->has_option( 'free_text' );
$multiple = false;
if ( 'checkbox' == $tag->basetype ) {
$multiple = ! $exclusive;
} else { // radio
$exclusive = false;
}
if ( $exclusive ) {
$class .= ' wpcf7-exclusive-checkbox';
}
$atts = array();
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
if ( $validation_error ) {
$atts['aria-describedby'] = wpcf7_get_validation_error_reference(
$tag->name
);
}
$tabindex = $tag->get_option( 'tabindex', 'signed_int', true );
if ( false !== $tabindex ) {
$tabindex = (int) $tabindex;
}
$html = '';
$count = 0;
if ( $data = (array) $tag->get_data_option() ) {
if ( $free_text ) {
$tag->values = array_merge(
array_slice( $tag->values, 0, -1 ),
array_values( $data ),
array_slice( $tag->values, -1 ) );
$tag->labels = array_merge(
array_slice( $tag->labels, 0, -1 ),
array_values( $data ),
array_slice( $tag->labels, -1 ) );
} else {
$tag->values = array_merge( $tag->values, array_values( $data ) );
$tag->labels = array_merge( $tag->labels, array_values( $data ) );
}
}
$values = $tag->values;
$labels = $tag->labels;
$default_choice = $tag->get_default_option( null, array(
'multiple' => $multiple,
) );
$hangover = wpcf7_get_hangover( $tag->name, $multiple ? array() : '' );
foreach ( $values as $key => $value ) {
if ( $hangover ) {
$checked = in_array( $value, (array) $hangover, true );
} else {
$checked = in_array( $value, (array) $default_choice, true );
}
if ( isset( $labels[$key] ) ) {
$label = $labels[$key];
} else {
$label = $value;
}
$item_atts = array(
'type' => $tag->basetype,
'name' => $tag->name . ( $multiple ? '[]' : '' ),
'value' => $value,
'class' => $req_class,
'checked' => $checked ? 'checked' : '',
'tabindex' => false !== $tabindex ? $tabindex : '',
);
$item_atts = wpcf7_format_atts( $item_atts );
if ( $label_first ) { // put label first, input last
$item = sprintf(
'<span class="wpcf7-list-item-label">%1$s</span><input %2$s />',
esc_html( $label ), $item_atts
);
} else {
$item = sprintf(
'<input %2$s /><span class="wpcf7-list-item-label">%1$s</span>',
esc_html( $label ), $item_atts
);
}
if ( $use_label_element ) {
$item = '<label>' . $item . '</label>';
}
if ( false !== $tabindex
and 0 < $tabindex ) {
$tabindex += 1;
}
$class = 'wpcf7-list-item';
$count += 1;
if ( 1 == $count ) {
$class .= ' first';
}
if ( count( $values ) == $count ) { // last round
$class .= ' last';
if ( $free_text ) {
$free_text_name = $tag->name . '_free_text';
$free_text_atts = array(
'name' => $free_text_name,
'class' => 'wpcf7-free-text',
'tabindex' => false !== $tabindex ? $tabindex : '',
);
if ( wpcf7_is_posted()
and isset( $_POST[$free_text_name] ) ) {
$free_text_atts['value'] = wp_unslash(
$_POST[$free_text_name] );
}
$free_text_atts = wpcf7_format_atts( $free_text_atts );
$item .= sprintf( ' <input type="text" %s />', $free_text_atts );
$class .= ' has-free-text';
}
}
$item = '<span class="' . esc_attr( $class ) . '">' . $item . '</span>';
$html .= $item;
}
$atts = wpcf7_format_atts( $atts );
$html = sprintf(
'<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>',
sanitize_html_class( $tag->name ), $atts, $html, $validation_error
);
return $html;
}
add_action('amp_init', 'ampforwp_cf7_recaptcha_removed');
function ampforwp_cf7_recaptcha_removed(){
$url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH),'/' );
$explode_path = explode('/', $url_path);
if ( 'amp' === end( $explode_path) || ( isset($_GET['action']) && $_GET['action'] == 'contact_form_submission' ) ) {
remove_action( 'wpcf7_init', 'wpcf7_recaptcha_add_form_tag_recaptcha',10 );
}
}
// Pop-up feature
add_action('pre_amp_render_post', 'ampforwp_cf7_popup_enabler');
if( ! function_exists(' ampforwp_cf7_popup_enabler ') ){
function ampforwp_cf7_popup_enabler(){
global $post, $redux_builder_amp;
if( isset($redux_builder_amp['ampforwp-cf7-pop-up']) && 1 == $redux_builder_amp['ampforwp-cf7-pop-up'] ){
add_filter('amp_post_template_data','ampforwp_add_required_scripts', 20);
add_action('amp_post_template_css', 'amp_cf7_form_styling');
update_post_meta($post->ID, 'amp-cf7-form-checker', 1);
}
}
}
if( isset($redux_builder_amp['ampforwp-cf7-sticky-form']) && $redux_builder_amp['ampforwp-cf7-sticky-form'] == 1){
add_action('amp_post_template_footer','ampforwp_cf7_sticky_form');
add_action('amp_post_template_css', 'amp_cf7_sticky_form_styling');
add_filter('amp_post_template_data','ampforwp_add_required_scripts', 20);
if( !function_exists('ampforwp_cf7_sticky_form')){
function ampforwp_cf7_sticky_form(){
global $redux_builder_amp;
$cf7_shortcode = $redux_builder_amp['ampforwp-cf7-sticky-form-shortcode'];
?>
<div id="sticky-form">
<a href="#sticky-form" id="open" class="btn btn-default btn-sm">
<?php if(isset($redux_builder_amp['ampforwp-cf7-sticky-form-headline-text']) && $redux_builder_amp['ampforwp-cf7-sticky-form-headline-text']){
$sticky_form_title = $redux_builder_amp['ampforwp-cf7-sticky-form-headline-text'];
echo $sticky_form_title;
} ?>
</a>
<div id="content">
<a href="#hide" id="close" class="btn btn-default btn-sm"><span>X</span>
<?php if(isset($redux_builder_amp['ampforwp-cf7-sticky-form-headline-text']) && $redux_builder_amp['ampforwp-cf7-sticky-form-headline-text']){
$sticky_form_title = $redux_builder_amp['ampforwp-cf7-sticky-form-headline-text'];
echo $sticky_form_title;
} ?>
</a>
<div class="fm-txt">
<?php $cf7StickyFormData = do_shortcode('[contact-form-7 id="'.$cf7_shortcode.'" title="Footer Sticky Form"]');
$sanitized_form_data = new AMPFORWP_Content($cf7StickyFormData,
apply_filters( 'amp_content_embed_handlers', array() ),
apply_filters( 'amp_content_sanitizers', array('AMP_Style_Sanitizer' => array() ) )
);
$cf7StickyFormOutput = $sanitized_form_data->get_amp_content();
echo $cf7StickyFormOutput;
?>
</div>
</div>
</div>
<?php
}
}
}
if( isset($redux_builder_amp['ampforwp-cf7-pop-up']) && $redux_builder_amp['ampforwp-cf7-pop-up'] == 1){
add_action('ampforwp_body_beginning','ampforwp_cf7_popup');
if( ! function_exists('ampforwp_cf7_popup') ){
function ampforwp_cf7_popup() {
global $redux_builder_amp; ?>
<amp-user-notification id="cf7-notification"
layout="nodisplay">
<div class="ampforwp-cf7-popup">
<?php
$cf7_shortcode = $redux_builder_amp['ampforwp-cf7-pop-up-shortcode'];
$cf7_form_data = do_shortcode('[contact-form-7 id=" '. $cf7_shortcode . ' "]'); ?>
<div class ="cf7-pop-up-form">
<?php if(isset($redux_builder_amp['amp-design-selector']) && $redux_builder_amp['amp-design-selector'] == 4){ ?>
<h1 class="cf7-pop-up-headline">
<?php if(isset($redux_builder_amp['ampforwp-cf7-pop-up-headline-text']) && $redux_builder_amp['ampforwp-cf7-pop-up-headline-text']){
$pop_up_title = $redux_builder_amp['ampforwp-cf7-pop-up-headline-text'];
echo $pop_up_title;
} ?>
</h1> <?php }
else{ ?>
<h3 class="cf7-pop-up-headline">
<?php if(isset($redux_builder_amp['ampforwp-cf7-pop-up-headline-text']) && $redux_builder_amp['ampforwp-cf7-pop-up-headline-text']){
$pop_up_title = $redux_builder_amp['ampforwp-cf7-pop-up-headline-text'];
echo $pop_up_title;
} ?>
</h3>
<?php }
$sanitized_form_data = new AMPFORWP_Content( $cf7_form_data,
apply_filters( 'amp_content_embed_handlers', array() ),
apply_filters( 'amp_content_sanitizers', array('AMP_Style_Sanitizer' => array() ) )
);
$form_content = $sanitized_form_data->get_amp_content();
echo $form_content;
?>
<button on="tap:cf7-notification.dismiss"
class="ampforwp-cf7-pop-up-close-btn">X</button>
</div>
</div>
</amp-user-notification>
<?php }
}
}
// adding amp-user-notification script for pop-up feature
add_filter( 'amp_post_template_data', 'ampforwp_cf7_pop_up_notification_scripts', 75 );
function ampforwp_cf7_pop_up_notification_scripts( $data ) {
global $redux_builder_amp;
if ( isset($redux_builder_amp['ampforwp-cf7-pop-up']) && $redux_builder_amp['ampforwp-cf7-pop-up'] == true ) {
if ( empty( $data['amp_component_scripts']['amp-user-notification'] ) ) {
$data['amp_component_scripts']['amp-user-notification'] = 'https://cdn.ampproject.org/v0/amp-user-notification-0.1.js';
}
}
return $data;
}
// pop-up code end here
add_filter('ampforwp_the_content_last_filter','ampforwp_fields_valn');
function ampforwp_fields_valn($content_buffer){
$content_buffer = preg_replace( '/<amp-img class="wpcf7-form-control wpcf7-captchac wpcf7-captcha-captcha(.*?)>(.*?)<\/amp-img><\/amp-img>/', '<span class="wpcf7-form-control-wrap your-captcha"><amp-img class="wpcf7-form-control wpcf7-captchac wpcf7-captcha-captcha$1>$2</amp-img></amp-img></span>', $content_buffer );
$content_buffer = preg_replace( '/<amp-img class="wpcf7-form-control wpcf7-captchac wpcf7-captcha-captcha(.*?)>(.*?)<\/amp-img>/', '<span class="wpcf7-form-control-wrap your-captcha"><amp-img class="wpcf7-form-control wpcf7-captchac wpcf7-captcha-captcha$1>$2</amp-img></span>', $content_buffer );
$content_buffer = preg_replace( '/<form action-xhr="(.*?)">/', '<form custom-validation-reporting="show-all-on-submit" action-xhr="$1">', $content_buffer );
$content_buffer = preg_replace( '/novalidate="novalidate"/', '', $content_buffer );
global $F_is_required, $redux_builder_amp;
$F_is_required = $redux_builder_amp['amp-cf7-translator-The field is required'];
if(preg_match('/<input\s+type="(.*?)"\s+name="(.*?)"\s+(.*?)\s+aria-required="true"(.*?)>/', $content_buffer)) {
$content_buffer = preg_replace( '/<input\s+type="(.*?)"\s+name="(.*?)"\s+(.*?)\s+aria-required="true"(.*?)>/', '<input required type="$1" name="$2" $3 id="show-all-on-submit-$1-$2" aria-required="true" $4><span visible-when-invalid="valueMissing" validation-for="show-all-on-submit-$1-$2">'.$F_is_required.'</span>', $content_buffer );
}
if(preg_match('/<select\sname="(.*?)"(.*?)aria-required="true"(.*?)>(.*?)<\/select>/s', $content_buffer)){
$content_buffer = preg_replace('/<select\sname="(.*?)"(.*?)aria-required="true"(.*?)>(.*?)<\/select>/s', '<select name="$1"$2aria-required="true"$3 required id="show-all-on-submit-select-$1">$4</select><span visible-when-invalid="valueMissing" validation-for="show-all-on-submit-select-$1">'.$F_is_required.'</span>', $content_buffer) ;
}
if(class_exists('CF7CF')){
$current_form = wpcf7_get_current_contact_form();
if(!empty($current_form)){
$current_form_id = $current_form->id();
}
$conditions = CF7CF::getConditions($current_form_id);
}
if(class_exists('CF7CF') && !empty($conditions)){
$re = '/<div data-id="(.*?)" data-orig_data_id="(.*?)"(.*?)>\s+(.*?)\s+<span(.*?)><select(.*?) class="(.*?)" required(.*?)>/';
if(preg_match($re, $content_buffer)){
$content_buffer = preg_replace($re, '<div data-id="$1" data-orig_data_id="$2"$3>$4<span$5><select$6 class="$7" $8>', $content_buffer);
}
}
// cf7 checkbox client side required validation.
if(preg_match('/<span class="wpcf7-form-control wpcf7-checkbox wpcf7-validates-as-required">/', $content_buffer)){
$amp_state = '<amp-state id="pageStatus"><script type="application/json">{"choiceChecked": 0}</script></amp-state>';
$content_buffer = preg_replace('/<span class="wpcf7-form-control wpcf7-checkbox wpcf7-validates-as-required">/', ''.$amp_state.'<span class="wpcf7-form-control wpcf7-checkbox wpcf7-validates-as-required">', $content_buffer );
$content_buffer = preg_replace('/<span\s+class="(.*?)wpcf7-checkbox\s+wpcf7-validates-as-required">(.*?)<input\s+type="(.*?)"(.*?)><\/span><\/span><\/span>/', '<span class="$1wpcf7-checkbox wpcf7-validates-as-required">$2<input type="$3"$4></span></span></span><input required type="checkbox" id="anythingChecked" [checked]="pageStatus.choiceChecked > 0 ? \'checked\' : \'\'"><span visible-when-invalid="valueMissing" validation-for="anythingChecked">'.$F_is_required.'</span>', $content_buffer );
$content_buffer = preg_replace('/class=\'on="change:(.*?)\'/','on="change:$1', $content_buffer );
}
global $Inv_format;
$Inv_format = $redux_builder_amp['amp-cf7-translator-invalid-email-format'];
$content_buffer = preg_replace( '/<input required type="email" name="(.*?)"(.*?)>/', '<input required type="email" name="$1"$2 pattern="[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,5})$"> <span visible-when-invalid="patternMismatch" validation-for="show-all-on-submit-email-$1">'.$Inv_format.'</span><span visible-when-invalid="typeMismatch" validation-for="show-all-on-submit-email-$1">'.$Inv_format.'</span>', $content_buffer );
$Inv_phone_format = $redux_builder_amp['amp-cf7-translator-invalid-phone-format'];
$content_buffer = preg_replace( '/<input required type="tel"\s+name="(.*?)"(.*?)>/', '<input required type="tel" name="$1"$2 pattern="[+,0-9]{3,18}"> <span visible-when-invalid="patternMismatch" validation-for="show-all-on-submit-tel-$1">'.$Inv_phone_format.'</span>', $content_buffer );
$content_buffer = preg_replace( '/<textarea(.*?)name="(.*?)"(.*?)aria-required="true"(.*?)>(.*?)<\/textarea>/', '<textarea required $1 name="$2" $3 id="show-all-on-submit-$2" aria-required="true"$4>$5</textarea><span visible-when-invalid="valueMissing" validation-for="show-all-on-submit-$2">'.$F_is_required.'</span>', $content_buffer );
if ( class_exists( 'CMoreira\\Plugins\\DateTimePicker\\Init' ) ) {
if(preg_match_all('/<span class="wpcf7-form-control-wrap date-(.*?)">/', $content_buffer, $matches)){
$date_val = $matches[1][0];
$content_buffer = preg_replace( '/<span class="wpcf7-form-control-wrap date-(.*?)">/', '<span class="wpcf7-form-control-wrap date-'.$date_val.'">', $content_buffer );
}
$cur_date = date("Y-m-d");
$content_buffer = preg_replace( '/<input required\s+type="date"(.*?)>/', '<amp-date-picker id="src-picker" type="single" mode="overlay" layout="container" format="YYYY-MM-DD" input-selector="#src-input" on=" select:AMP.setState({date-'.$date_val.': event.date,product:{dateType1:{from:event.date}}});"> <input id="src-input" name="date-'.$date_val.'" placeholder="'.$cur_date.'" value="'.$cur_date.'" class="amp_dp"></amp-date-picker>', $content_buffer );
}
return $content_buffer;
}
require_once dirname( __FILE__ ) . '/updater/EDD_SL_Plugin_Updater.php';
// Check for updates
function amp_cf7_plugin_updater() {
// retrieve our license key from the DB
//$license_key = trim( get_option( 'amp_ads_license_key' ) );
$selectedOption = get_option('redux_builder_amp',true);
$license_key = '';//trim( get_option( 'amp_ads_license_key' ) );
$pluginItemName = '';
$pluginItemStoreUrl = '';
$pluginstatus = '';
if( isset($selectedOption['amp-license']) && "" != $selectedOption['amp-license'] && isset($selectedOption['amp-license'][AMP_CF7_ITEM_FOLDER_NAME])){
$pluginsDetail = $selectedOption['amp-license'][AMP_CF7_ITEM_FOLDER_NAME];
$license_key = $pluginsDetail['license'];
// $pluginItemName = $pluginsDetail['item_name'];
$pluginItemStoreUrl = $pluginsDetail['store_url'];
$pluginstatus = $pluginsDetail['status'];
}
// setup the updater
$edd_updater = new AMP_CF7_EDD_SL_Plugin_Updater( AMP_CF7_STORE_URL, __FILE__, array(
'version' => AMP_CF7_VERSION, // current version number
'license' => $license_key, // license key (used get_option above to retrieve from DB)
'license_status'=>$pluginstatus,
'item_name' => AMP_CF7_ITEM_NAME, // name of this plugin
'author' => 'Mohammed Kaludi', // author of this plugin
'beta' => false,
)
);
}
add_action( 'admin_init', 'amp_cf7_plugin_updater', 0 );
// Notice to enter license key once activate the plugin
$path = plugin_basename( __FILE__ );
add_action("after_plugin_row_{$path}", function( $plugin_file, $plugin_data, $status ) {
global $redux_builder_amp;
if(! defined('AMP_CF7_ITEM_FOLDER_NAME')){
$folderName = basename(__DIR__);
define( 'AMP_CF7_ITEM_FOLDER_NAME', $folderName );
}
$pluginstatus = '';
if(isset($redux_builder_amp['amp-license'][AMP_CF7_ITEM_FOLDER_NAME])){
$pluginsDetail = $redux_builder_amp['amp-license'][AMP_CF7_ITEM_FOLDER_NAME];
$pluginstatus = $pluginsDetail['status'];
}
$activation_link = 'amp_options&tabid=opt-go-premium';
if(!defined('AMPFORWP_PLUGIN_DIR')){
$activation_link = 'license-activation';
}
if(empty($redux_builder_amp['amp-license'][AMP_CF7_ITEM_FOLDER_NAME]['license'])){
echo "<tr class='active'><td> </td><td colspan='2'><a href='".esc_url( self_admin_url( 'admin.php?page='.$activation_link ) )."'>Please enter the license key</a> to get the <strong>latest features</strong> and <strong>stable updates</strong></td></tr>";
}elseif($pluginstatus=="valid"){
$update_cache = get_site_transient( 'update_plugins' );
$update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
if(isset($update_cache->response[ AMP_CF7_ITEM_FOLDER_NAME ])
&& empty($update_cache->response[ AMP_CF7_ITEM_FOLDER_NAME ]->download_link)
){
unset($update_cache->response[ AMP_CF7_ITEM_FOLDER_NAME ]);
set_site_transient( 'update_plugins', $update_cache );
}
}
}, 10, 3 );