Commit 2b4e7e7e by Pham Huy

add theme ahoadon

parent 1d7c2298
...@@ -546,6 +546,44 @@ table.comments td.comment p a:after { ...@@ -546,6 +546,44 @@ table.comments td.comment p a:after {
margin-top: 1.5rem; margin-top: 1.5rem;
} }
.akismet-box-header {
max-width: 700px;
margin: 0 auto 40px auto;
line-height: 1.5;
}
.akismet-box-header h2 {
margin: 1.5rem 10% 0;
font-size: 1.375rem;
font-weight: 700;
color: #000;
}
.akismet-box .centered {
text-align: center;
}
.akismet-enter-api-key-box {
margin: 1.5rem 0;
}
.akismet-box .enter-api-key {
display: none;
margin-top: 1.5rem;
}
.akismet-box .akismet-toggles {
margin: 3rem 0;
}
.akismet-box .akismet-ak-connect, .akismet-box .toggle-jp-connect {
display: none;
}
.akismet-box .enter-api-key p {
padding: 0 1.5rem;
}
.akismet-button, .akismet-button:hover, .akismet-button:visited { .akismet-button, .akismet-button:hover, .akismet-button:visited {
background: white; background: white;
border-color: #c8d7e1; border-color: #c8d7e1;
......
...@@ -169,6 +169,8 @@ jQuery( function ( $ ) { ...@@ -169,6 +169,8 @@ jQuery( function ( $ ) {
function akismet_check_for_spam(offset, limit) { function akismet_check_for_spam(offset, limit) {
var check_for_spam_buttons = $( '.checkforspam' ); var check_for_spam_buttons = $( '.checkforspam' );
var nonce = check_for_spam_buttons.data( 'nonce' );
// We show the percentage complete down to one decimal point so even queues with 100k // We show the percentage complete down to one decimal point so even queues with 100k
// pending comments will show some progress pretty quickly. // pending comments will show some progress pretty quickly.
var percentage_complete = Math.round( ( recheck_count / check_for_spam_buttons.data( 'pending-comment-count' ) ) * 1000 ) / 10; var percentage_complete = Math.round( ( recheck_count / check_for_spam_buttons.data( 'pending-comment-count' ) ) * 1000 ) / 10;
...@@ -181,9 +183,16 @@ jQuery( function ( $ ) { ...@@ -181,9 +183,16 @@ jQuery( function ( $ ) {
{ {
'action': 'akismet_recheck_queue', 'action': 'akismet_recheck_queue',
'offset': offset, 'offset': offset,
'limit': limit 'limit': limit,
'nonce': nonce
}, },
function(result) { function(result) {
if ( 'error' in result ) {
// An error is only returned in the case of a missing nonce, so we don't need the actual error message.
window.location.href = check_for_spam_buttons.data( 'failure-url' );
return;
}
recheck_count += result.counts.processed; recheck_count += result.counts.processed;
spam_count += result.counts.spam; spam_count += result.counts.spam;
...@@ -282,27 +291,64 @@ jQuery( function ( $ ) { ...@@ -282,27 +291,64 @@ jQuery( function ( $ ) {
/** /**
* Sets the comment form privacy notice display to hide when one clicks Core's dismiss button on the related admin notice. * Sets the comment form privacy notice display to hide when one clicks Core's dismiss button on the related admin notice.
*/ */
$( '#akismet-privacy-notice-admin-notice' ).on( 'click', '.notice-dismiss', function(){ $( '#akismet-privacy-notice-admin-notice' ).on( 'click', '.notice-dismiss', function () {
$.ajax({ $.ajax( {
url: './options-general.php?page=akismet-key-config&akismet_comment_form_privacy_notice=hide', url: './options-general.php?page=akismet-key-config&akismet_comment_form_privacy_notice=hide',
}); } );
}); });
$( ".akismet-could-be-primary" ).each( function () { $( '.akismet-could-be-primary' ).each( function () {
var form = $( this ).closest( 'form' ); var form = $( this ).closest( 'form' );
form.data( 'initial-state', form.serialize() ); form.data( 'initial-state', form.serialize() );
form.on( 'change keyup', function () { form.on( 'change keyup', function () {
var self = $( this ); var self = $( this );
var submit_button = self.find( ".akismet-could-be-primary" ); var submit_button = self.find( '.akismet-could-be-primary' );
if ( self.serialize() != self.data( 'initial-state' ) ) { if ( self.serialize() != self.data( 'initial-state' ) ) {
submit_button.addClass( "akismet-is-primary" ); submit_button.addClass( 'akismet-is-primary' );
} }
else { else {
submit_button.removeClass( "akismet-is-primary" ); submit_button.removeClass( 'akismet-is-primary' );
} }
} ); } );
} ); } );
/**
* Shows the Enter API key form
*/
$( '.akismet-enter-api-key-box a' ).on( 'click', function ( e ) {
e.preventDefault();
var div = $( '.enter-api-key' );
div.show( 500 );
div.find( 'input[name=key]' ).focus();
$( this ).hide();
} );
/**
* Hides the Connect with Jetpack form | Shows the Activate Akismet Account form
*/
$( 'a.toggle-ak-connect' ).on( 'click', function ( e ) {
e.preventDefault();
$( '.akismet-ak-connect' ).slideToggle('slow');
$( 'a.toggle-ak-connect' ).hide();
$( '.akismet-jp-connect' ).hide();
$( 'a.toggle-jp-connect' ).show();
} );
/**
* Shows the Connect with Jetpack form | Hides the Activate Akismet Account form
*/
$( 'a.toggle-jp-connect' ).on( 'click', function ( e ) {
e.preventDefault();
$( '.akismet-jp-connect' ).slideToggle('slow');
$( 'a.toggle-jp-connect' ).hide();
$( '.akismet-ak-connect' ).hide();
$( 'a.toggle-ak-connect' ).show();
} );
}); });
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
Plugin Name: Akismet Anti-Spam Plugin Name: Akismet Anti-Spam
Plugin URI: https://akismet.com/ Plugin URI: https://akismet.com/
Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key. Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key.
Version: 4.1.2 Version: 4.1.3
Author: Automattic Author: Automattic
Author URI: https://automattic.com/wordpress-plugins/ Author URI: https://automattic.com/wordpress-plugins/
License: GPLv2 or later License: GPLv2 or later
...@@ -37,7 +37,7 @@ if ( !function_exists( 'add_action' ) ) { ...@@ -37,7 +37,7 @@ if ( !function_exists( 'add_action' ) ) {
exit; exit;
} }
define( 'AKISMET_VERSION', '4.1.2' ); define( 'AKISMET_VERSION', '4.1.3' );
define( 'AKISMET__MINIMUM_WP_VERSION', '4.0' ); define( 'AKISMET__MINIMUM_WP_VERSION', '4.0' );
define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'AKISMET_DELETE_LIMIT', 100000 ); define( 'AKISMET_DELETE_LIMIT', 100000 );
......
...@@ -80,6 +80,13 @@ class Akismet_Admin { ...@@ -80,6 +80,13 @@ class Akismet_Admin {
} }
public static function admin_init() { public static function admin_init() {
if ( get_option( 'Activated_Akismet' ) ) {
delete_option( 'Activated_Akismet' );
if ( ! headers_sent() ) {
wp_redirect( add_query_arg( array( 'page' => 'akismet-key-config', 'view' => 'start' ), class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'options-general.php' ) ) );
}
}
load_plugin_textdomain( 'akismet' ); load_plugin_textdomain( 'akismet' );
add_meta_box( 'akismet-status', __('Comment History', 'akismet'), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' ); add_meta_box( 'akismet-status', __('Comment History', 'akismet'), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' );
...@@ -396,8 +403,10 @@ class Akismet_Admin { ...@@ -396,8 +403,10 @@ class Akismet_Admin {
href="' . esc_url( $link ) . '" href="' . esc_url( $link ) . '"
data-active-label="' . esc_attr( __( 'Checking for Spam', 'akismet' ) ) . '" data-active-label="' . esc_attr( __( 'Checking for Spam', 'akismet' ) ) . '"
data-progress-label-format="' . esc_attr( __( '(%1$s%)', 'akismet' ) ) . '" data-progress-label-format="' . esc_attr( __( '(%1$s%)', 'akismet' ) ) . '"
data-success-url="' . esc_attr( remove_query_arg( 'akismet_recheck', add_query_arg( array( 'akismet_recheck_complete' => 1, 'recheck_count' => urlencode( '__recheck_count__' ), 'spam_count' => urlencode( '__spam_count__' ) ) ) ) ) . '" data-success-url="' . esc_attr( remove_query_arg( array( 'akismet_recheck', 'akismet_recheck_error' ), add_query_arg( array( 'akismet_recheck_complete' => 1, 'recheck_count' => urlencode( '__recheck_count__' ), 'spam_count' => urlencode( '__spam_count__' ) ) ) ) ) . '"
data-failure-url="' . esc_attr( remove_query_arg( array( 'akismet_recheck', 'akismet_recheck_complete' ), add_query_arg( array( 'akismet_recheck_error' => 1 ) ) ) ) . '"
data-pending-comment-count="' . esc_attr( $comments_count->moderated ) . '" data-pending-comment-count="' . esc_attr( $comments_count->moderated ) . '"
data-nonce="' . esc_attr( wp_create_nonce( 'akismet_check_for_spam' ) ) . '"
>'; >';
echo '<span class="akismet-label">' . esc_html__('Check for Spam', 'akismet') . '</span>'; echo '<span class="akismet-label">' . esc_html__('Check for Spam', 'akismet') . '</span>';
echo '<span class="checkforspam-progress"></span>'; echo '<span class="checkforspam-progress"></span>';
...@@ -414,6 +423,13 @@ class Akismet_Admin { ...@@ -414,6 +423,13 @@ class Akismet_Admin {
if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) ) { if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) ) {
return; return;
} }
if ( ! wp_verify_nonce( $_POST['nonce'], 'akismet_check_for_spam' ) ) {
wp_send_json( array(
'error' => __( "You don't have permission to do that."),
));
return;
}
$result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] ); $result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] );
...@@ -1061,6 +1077,9 @@ class Akismet_Admin { ...@@ -1061,6 +1077,9 @@ class Akismet_Admin {
echo '<div class="notice notice-success"><p>' . esc_html( $message ) . '</p></div>'; echo '<div class="notice notice-success"><p>' . esc_html( $message ) . '</p></div>';
} }
else if ( isset( $_GET['akismet_recheck_error'] ) ) {
echo '<div class="notice notice-error"><p>' . esc_html( __( 'Akismet could not recheck your comments for spam.', 'akismet' ) ) . '</p></div>';
}
$akismet_comment_form_privacy_notice_option = get_option( 'akismet_comment_form_privacy_notice' ); $akismet_comment_form_privacy_notice_option = get_option( 'akismet_comment_form_privacy_notice' );
if ( ! in_array( $akismet_comment_form_privacy_notice_option, array( 'hide', 'display' ) ) ) { if ( ! in_array( $akismet_comment_form_privacy_notice_option, array( 'hide', 'display' ) ) ) {
...@@ -1108,7 +1127,11 @@ class Akismet_Admin { ...@@ -1108,7 +1127,11 @@ class Akismet_Admin {
if ( !class_exists('Jetpack') ) if ( !class_exists('Jetpack') )
return false; return false;
Jetpack::load_xml_rpc_client(); if ( defined( 'JETPACK__VERSION' ) && version_compare( JETPACK__VERSION, '7.7', '<' ) ) {
// For version of Jetpack prior to 7.7.
Jetpack::load_xml_rpc_client();
}
$xml = new Jetpack_IXR_ClientMulticall( array( 'user_id' => get_current_user_id() ) ); $xml = new Jetpack_IXR_ClientMulticall( array( 'user_id' => get_current_user_id() ) );
$xml->addCall( 'wpcom.getUserID' ); $xml->addCall( 'wpcom.getUserID' );
......
...@@ -1277,6 +1277,8 @@ p { ...@@ -1277,6 +1277,8 @@ p {
$message = '<strong>'.sprintf(esc_html__( 'Akismet %s requires WordPress %s or higher.' , 'akismet'), AKISMET_VERSION, AKISMET__MINIMUM_WP_VERSION ).'</strong> '.sprintf(__('Please <a href="%1$s">upgrade WordPress</a> to a current version, or <a href="%2$s">downgrade to version 2.4 of the Akismet plugin</a>.', 'akismet'), 'https://codex.wordpress.org/Upgrading_WordPress', 'https://wordpress.org/extend/plugins/akismet/download/'); $message = '<strong>'.sprintf(esc_html__( 'Akismet %s requires WordPress %s or higher.' , 'akismet'), AKISMET_VERSION, AKISMET__MINIMUM_WP_VERSION ).'</strong> '.sprintf(__('Please <a href="%1$s">upgrade WordPress</a> to a current version, or <a href="%2$s">downgrade to version 2.4 of the Akismet plugin</a>.', 'akismet'), 'https://codex.wordpress.org/Upgrading_WordPress', 'https://wordpress.org/extend/plugins/akismet/download/');
Akismet::bail_on_activation( $message ); Akismet::bail_on_activation( $message );
} else {
add_option( 'Activated_Akismet', true );
} }
} }
......
...@@ -3,7 +3,7 @@ Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, eo ...@@ -3,7 +3,7 @@ Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, eo
Tags: akismet, comments, spam, antispam, anti-spam, anti spam, comment moderation, comment spam, contact form spam, spam comments Tags: akismet, comments, spam, antispam, anti-spam, anti spam, comment moderation, comment spam, contact form spam, spam comments
Requires at least: 4.0 Requires at least: 4.0
Tested up to: 5.2 Tested up to: 5.2
Stable tag: 4.1.2 Stable tag: 4.1.3
License: GPLv2 or later License: GPLv2 or later
Akismet checks your comments and contact form submissions against our global database of spam to protect you and your site from malicious content. Akismet checks your comments and contact form submissions against our global database of spam to protect you and your site from malicious content.
...@@ -20,16 +20,24 @@ Major features in Akismet include: ...@@ -20,16 +20,24 @@ Major features in Akismet include:
* Moderators can see the number of approved comments for each user. * Moderators can see the number of approved comments for each user.
* A discard feature that outright blocks the worst spam, saving you disk space and speeding up your site. * A discard feature that outright blocks the worst spam, saving you disk space and speeding up your site.
PS: You'll need an [Akismet.com API key](https://akismet.com/get/) to use it. Keys are free for personal blogs; paid subscriptions are available for businesses and commercial sites. PS: You'll be prompted to get an Akismet.com API key to use it, once activated. Keys are free for personal blogs; paid subscriptions are available for businesses and commercial sites.
== Installation == == Installation ==
Upload the Akismet plugin to your blog, Activate it, then enter your [Akismet.com API key](https://akismet.com/get/). Upload the Akismet plugin to your blog, activate it, and then enter your Akismet.com API key.
1, 2, 3: You're done! 1, 2, 3: You're done!
== Changelog == == Changelog ==
= 4.1.3 =
*Release Date - 31 October 2019*
* Prevented an attacker from being able to cause a user to unknowingly recheck their Pending comments for spam.
* Improved compatibility with Jetpack 7.7+.
* Updated the plugin activation page to use consistent language and markup.
* Redirecting users to the Akismet connnection/settings screen upon plugin activation, in an effort to make it easier for people to get setup.
= 4.1.2 = = 4.1.2 =
*Release Date - 14 May 2019* *Release Date - 14 May 2019*
......
<div class="akismet-box">
<?php Akismet::view( 'title' ); ?>
<?php Akismet::view( 'setup' );?>
</div>
<br/>
<div class="akismet-box">
<?php Akismet::view( 'enter' );?>
</div>
\ No newline at end of file
<?php
//phpcs:disable VariableAnalysis
// There are "undefined" variables here because they're defined in the code that includes this file as a template.
?>
<div class="akismet-box">
<?php Akismet::view( 'title' ); ?>
<div class="akismet-jp-connect">
<h3><?php esc_html_e( 'Connect with Jetpack', 'akismet' ); ?></h3><?php
if ( in_array( $akismet_user->status, array( 'no-sub', 'missing' ) ) ) {?>
<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
<form name="akismet_activate" id="akismet_activate" action="https://akismet.com/get/" method="post" class="akismet-right" target="_blank">
<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/>
<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/>
<input type="hidden" name="auto-connect" value="<?php echo esc_attr( $akismet_user->ID ); ?>"/>
<input type="hidden" name="redirect" value="plugin-signup"/>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack' , 'akismet' ); ?>"/>
</form>
<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
<p><?php
/* translators: %s is the WordPress.com username */
echo sprintf( esc_html( __( 'You are connected as %s.', 'akismet' ) ), '<b>' . esc_html( $akismet_user->user_login ) . '</b>' ); ?><br /><span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span></p>
<?php } elseif ( $akismet_user->status == 'cancelled' ) { ?>
<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
<form name="akismet_activate" id="akismet_activate" action="https://akismet.com/get/" method="post" class="akismet-right" target="_blank">
<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/>
<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/>
<input type="hidden" name="user_id" value="<?php echo esc_attr( $akismet_user->ID ); ?>"/>
<input type="hidden" name="redirect" value="upgrade"/>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack' , 'akismet' ); ?>"/>
</form>
<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
<p><?php
/* translators: %s is the WordPress.com email address */
echo esc_html( sprintf( __( 'Your subscription for %s is cancelled.' , 'akismet' ), $akismet_user->user_email ) ); ?><br /><span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span></p>
<?php } elseif ( $akismet_user->status == 'suspended' ) { ?>
<div class="akismet-right">
<p><a href="https://akismet.com/contact" class="akismet-button akismet-is-primary"><?php esc_html_e( 'Contact Akismet support' , 'akismet' ); ?></a></p>
</div>
<p>
<span class="akismet-alert-text"><?php
/* translators: %s is the WordPress.com email address */
echo esc_html( sprintf( __( 'Your subscription for %s is suspended.' , 'akismet' ), $akismet_user->user_email ) ); ?></span>
<?php esc_html_e( 'No worries! Get in touch and we&#8217;ll sort this out.', 'akismet' ); ?>
</p>
<?php } else { // ask do they want to use akismet account found using jetpack wpcom connection ?>
<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
<form name="akismet_use_wpcom_key" action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post" id="akismet-activate" class="akismet-right">
<input type="hidden" name="key" value="<?php echo esc_attr( $akismet_user->api_key );?>"/>
<input type="hidden" name="action" value="enter-key">
<?php wp_nonce_field( Akismet_Admin::NONCE ) ?>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack' , 'akismet' ); ?>"/>
</form>
<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
<p><?php
/* translators: %s is the WordPress.com username */
echo sprintf( esc_html( __( 'You are connected as %s.', 'akismet' ) ), '<b>' . esc_html( $akismet_user->user_login ) . '</b>' ); ?><br /><span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span></p>
<?php } ?>
</div>
<div class="akismet-ak-connect">
<?php Akismet::view( 'setup' );?>
</div>
<div class="centered akismet-toggles">
<a href="#" class="toggle-jp-connect"><?php esc_html_e( 'Connect with Jetpack' ); ?></a>
<a href="#" class="toggle-ak-connect"><?php esc_html_e( 'Set up a different account' ); ?></a>
</div>
</div>
<br/>
<div class="akismet-box">
<?php Akismet::view( 'enter' );?>
</div>
\ No newline at end of file
<div class="akismet-enter-api-key-box centered">
<a href="#"><?php esc_html_e( 'Manually enter an API key' ); ?></a>
<div class="enter-api-key">
<form action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post">
<?php wp_nonce_field( Akismet_Admin::NONCE ) ?>
<input type="hidden" name="action" value="enter-key">
<p style="width: 100%; display: flex; flex-wrap: nowrap; box-sizing: border-box;">
<input id="key" name="key" type="text" size="15" value="" placeholder="<?php esc_attr_e( 'Enter your API key' , 'akismet' ); ?>" class="regular-text code" style="flex-grow: 1; margin-right: 1rem;">
<input type="submit" name="submit" id="submit" class="akismet-button" value="<?php esc_attr_e( 'Connect with API key', 'akismet' );?>">
</p>
</form>
</div>
</div>
\ No newline at end of file
<?php
//phpcs:disable VariableAnalysis
// There are "undefined" variables here because they're defined in the code that includes this file as a template.
?>
<?php if ( $type == 'plugin' ) :?> <?php if ( $type == 'plugin' ) :?>
<div class="updated" id="akismet_setup_prompt"> <div class="updated" id="akismet_setup_prompt">
<form name="akismet_activate" action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="POST"> <form name="akismet_activate" action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="POST">
...@@ -138,4 +144,4 @@ ...@@ -138,4 +144,4 @@
<p><?php esc_html_e( 'To help your site with transparency under privacy laws like the GDPR, Akismet can display a notice to your users under your comment forms. This feature is disabled by default, however, you can turn it on below.', 'akismet' ); ?></p> <p><?php esc_html_e( 'To help your site with transparency under privacy laws like the GDPR, Akismet can display a notice to your users under your comment forms. This feature is disabled by default, however, you can turn it on below.', 'akismet' ); ?></p>
<p><?php printf( __(' Please <a href="%s">enable</a> or <a href="%s">disable</a> this feature. <a href="%s" id="akismet-privacy-notice-control-notice-info-link" target="_blank">More information</a>.', 'akismet' ), admin_url( apply_filters( 'akismet_comment_form_privacy_notice_url_display', 'options-general.php?page=akismet-key-config&akismet_comment_form_privacy_notice=display' ) ), admin_url( apply_filters( 'akismet_comment_form_privacy_notice_url_hide', 'options-general.php?page=akismet-key-config&akismet_comment_form_privacy_notice=hide' ) ), 'https://akismet.com/privacy/' ); ?></p> <p><?php printf( __(' Please <a href="%s">enable</a> or <a href="%s">disable</a> this feature. <a href="%s" id="akismet-privacy-notice-control-notice-info-link" target="_blank">More information</a>.', 'akismet' ), admin_url( apply_filters( 'akismet_comment_form_privacy_notice_url_display', 'options-general.php?page=akismet-key-config&akismet_comment_form_privacy_notice=display' ) ), admin_url( apply_filters( 'akismet_comment_form_privacy_notice_url_hide', 'options-general.php?page=akismet-key-config&akismet_comment_form_privacy_notice=hide' ) ), 'https://akismet.com/privacy/' ); ?></p>
</div> </div>
<?php endif;?> <?php endif;?>
\ No newline at end of file
<div class="akismet-box">
<h2><?php esc_html_e( 'Manual Configuration', 'akismet' ); ?></h2>
<p>
<?php
/* translators: %s is the wp-config.php file */
echo sprintf( esc_html__( 'An Akismet API key has been defined in the %s file for this site.', 'akismet' ), '<code>wp-config.php</code>' );
?>
</p>
</div>
\ No newline at end of file
<h3><?php esc_html_e( 'Set Up Akismet' , 'akismet' );?></h3>
<div class="akismet-right">
<?php Akismet::view( 'get', array( 'text' => __( 'Set up your Akismet account' , 'akismet' ), 'classes' => array( 'akismet-button', 'akismet-is-primary' ) ) ); ?>
</div>
<p><?php esc_html_e( 'Set up your Akismet account to enable spam filtering on this site.', 'akismet' ); ?></p>
\ No newline at end of file
<?php
//phpcs:disable VariableAnalysis
// There are "undefined" variables here because they're defined in the code that includes this file as a template.
?>
<div id="akismet-plugin-container"> <div id="akismet-plugin-container">
<div class="akismet-masthead"> <div class="akismet-masthead">
<div class="akismet-masthead__inside-container"> <div class="akismet-masthead__inside-container">
...@@ -7,96 +13,19 @@ ...@@ -7,96 +13,19 @@
</div> </div>
</div> </div>
<div class="akismet-lower"> <div class="akismet-lower">
<?php Akismet_Admin::display_status(); ?> <?php Akismet_Admin::display_status();?>
<div class="akismet-box">
<h2><?php esc_html_e( 'Eliminate spam from your site', 'akismet' ); ?></h2>
<p><?php esc_html_e( 'Select one of the options below to get started.', 'akismet' ); ?></p>
</div>
<div class="akismet-boxes"> <div class="akismet-boxes">
<?php if ( ! Akismet::predefined_api_key() ) { ?> <?php
<?php if ( $akismet_user && in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub', 'missing', 'cancelled', 'suspended' ) ) ) { ?>
<?php if ( in_array( $akismet_user->status, array( 'no-sub', 'missing' ) ) ) { ?> if ( Akismet::predefined_api_key() ) {
<div class="akismet-box"> Akismet::view( 'predefined' );
<h3><?php esc_html_e( 'Connect via Jetpack', 'akismet' ); ?></h3> } elseif ( $akismet_user && in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub', 'missing', 'cancelled', 'suspended' ) ) ) {
<p><?php esc_html_e( 'Use your Jetpack connection to activate Akismet.', 'akismet' ); ?></p> Akismet::view( 'connect-jp', compact( 'akismet_user' ) );
<form name="akismet_activate" id="akismet_activate" action="https://akismet.com/get/" method="post" class="akismet-right" target="_blank"> } else {
<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/> Akismet::view( 'activate' );
<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/> }
<input type="hidden" name="auto-connect" value="<?php echo esc_attr( $akismet_user->ID ); ?>"/>
<input type="hidden" name="redirect" value="plugin-signup"/> ?>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack' , 'akismet' ); ?>"/>
</form>
<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
<p><?php echo sprintf( esc_html( __( 'You are connected as %s.', 'akismet' ) ), '<b>' . esc_html( $akismet_user->user_login ) . '</b>' ); ?><br /><span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span></p>
</div>
<?php } elseif ( $akismet_user->status == 'cancelled' ) { ?>
<div class="akismet-box">
<h3><?php esc_html_e( 'Connect via Jetpack', 'akismet' ); ?></h3>
<form name="akismet_activate" id="akismet_activate" action="https://akismet.com/get/" method="post" class="akismet-right" target="_blank">
<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/>
<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/>
<input type="hidden" name="user_id" value="<?php echo esc_attr( $akismet_user->ID ); ?>"/>
<input type="hidden" name="redirect" value="upgrade"/>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Reactivate Akismet' , 'akismet' ); ?>"/>
</form>
<p><?php echo esc_html( sprintf( __( 'Your subscription for %s is cancelled.' , 'akismet' ), $akismet_user->user_email ) ); ?></p>
</div>
<?php } elseif ( $akismet_user->status == 'suspended' ) { ?>
<div class="centered akismet-box">
<h3><?php esc_html_e( 'Connected via Jetpack' , 'akismet' ); ?></h3>
<p class="akismet-alert-text"><?php echo esc_html( sprintf( __( 'Your subscription for %s is suspended.' , 'akismet' ), $akismet_user->user_email ) ); ?></p>
<p><?php esc_html_e( 'No worries! Get in touch and we&#8217;ll sort this out.', 'akismet' ); ?></p>
<p><a href="https://akismet.com/contact" class="akismet-button akismet-is-primary"><?php esc_html_e( 'Contact Akismet support' , 'akismet' ); ?></a></p>
</div>
<?php } else { // ask do they want to use akismet account found using jetpack wpcom connection ?>
<div class="akismet-box">
<h3><?php esc_html_e( 'Connect via Jetpack', 'akismet' ); ?></h3>
<p><?php esc_html_e( 'Use your Jetpack connection to activate Akismet.', 'akismet' ); ?></p>
<form name="akismet_use_wpcom_key" action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post" id="akismet-activate" class="akismet-right">
<input type="hidden" name="key" value="<?php echo esc_attr( $akismet_user->api_key );?>"/>
<input type="hidden" name="action" value="enter-key">
<?php wp_nonce_field( Akismet_Admin::NONCE ) ?>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack' , 'akismet' ); ?>"/>
</form>
<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
<p><?php echo sprintf( esc_html( __( 'You are connected as %s.', 'akismet' ) ), '<b>' . esc_html( $akismet_user->user_login ) . '</b>' ); ?><br /><span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span></p>
</div>
<?php } ?>
<div class="akismet-box">
<h3><?php esc_html_e( 'Or sign up with a different email address', 'akismet' ); ?></h3>
<div class="akismet-right">
<?php Akismet::view( 'get', array( 'text' => __( 'Sign up with a different email address' , 'akismet' ), 'classes' => array( 'akismet-button' ) ) ); ?>
</div>
<p><?php esc_html_e( 'Choose this option to use Akismet independently of your Jetpack connection.', 'akismet' ); ?></p>
</div>
<?php } else { ?>
<div class="akismet-box">
<h3><?php esc_html_e( 'Activate Akismet' , 'akismet' );?></h3>
<div class="akismet-right">
<?php Akismet::view( 'get', array( 'text' => __( 'Get your API key' , 'akismet' ), 'classes' => array( 'akismet-button', 'akismet-is-primary' ) ) ); ?>
</div>
<p><?php esc_html_e( 'Log in or sign up now.', 'akismet' ); ?></p>
</div>
<?php } ?>
<div class="akismet-box">
<h3><?php esc_html_e( 'Or enter an API key', 'akismet' ); ?></h3>
<p><?php esc_html_e( 'Already have your key? Enter it here.', 'akismet' ); ?> <a href="https://docs.akismet.com/getting-started/api-key/" target="_blank"><?php esc_html_e( '(What is an API key?)', 'akismet' ); ?></a></p>
<form action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post">
<?php wp_nonce_field( Akismet_Admin::NONCE ) ?>
<input type="hidden" name="action" value="enter-key">
<p style="width: 100%; display: flex; flex-wrap: nowrap; box-sizing: border-box;">
<input id="key" name="key" type="text" size="15" value="" class="regular-text code" style="flex-grow: 1; margin-right: 1rem;">
<input type="submit" name="submit" id="submit" class="akismet-button" value="<?php esc_attr_e( 'Connect with API key', 'akismet' );?>">
</p>
</form>
</div>
<?php } else { ?>
<div class="akismet-box">
<h2><?php esc_html_e( 'Manual Configuration', 'akismet' ); ?></h2>
<p><?php echo sprintf( esc_html__( 'An Akismet API key has been defined in the %s file for this site.', 'akismet' ), '<code>wp-config.php</code>' ); ?></p>
</div>
<?php } ?>
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
<div class="centered akismet-box-header">
<h2><?php esc_html_e( 'Eliminate spam from your site', 'akismet' ); ?></h2>
</div>
\ No newline at end of file
#wpcf7-contact-form-list-table span.shortcode input,
#wpcf7-contact-form-editor span.shortcode input {
color: #fff;
}
div.config-error, span.config-error, ul.config-error {
color: #bbc8d4;
}
.keyboard-interaction {
color: #bbc8d4;
}
#contact-form-editor .contact-form-editor-panel {
background-color: #32373c;
}
#contact-form-editor-tabs {
border-bottom: 1px solid #aaa;
}
#contact-form-editor-tabs li {
border: 1px solid #ccc;
border-bottom: 1px solid #aaa;
background-color: #37444c;
}
#contact-form-editor-tabs li:hover {
background-color: #000;
}
#contact-form-editor-tabs li.ui-tabs-active,
#contact-form-editor-tabs li.ui-tabs-active:hover {
border-top: 1px solid #aaa;
border-right: 1px solid #aaa;
border-left: 1px solid #aaa;
border-bottom: 1px solid #32373c;
background-color: #32373c;
}
#contact-form-editor-tabs li a {
color: #bbc8d4;
}
#contact-form-editor-tabs li.ui-tabs-active a {
color: #fff;
}
#contact-form-editor-tabs li a:hover {
color: #fff;
}
.contact-form-editor-box-mail span.mailtag {
color: #ddd;
}
.contact-form-editor-box-mail span.mailtag.used {
color: #999;
}
#mail-panel .contact-form-editor-box-mail table.form-table tr th,
#mail-panel .contact-form-editor-box-mail table.form-table tr td {
background-color: #32373c;
}
div.wrap#wpcf7-integration .card.active {
border-color: #00a0d2;
}
div.wrap#wpcf7-integration .card .infobox {
color: #aaa;
}
/*
* Tabs
*/
#contact-form-editor-tabs {
padding: 9px 10px 0 15px;
}
/*
* Form Tab
*/
.tag-generator-panel {
text-align: right;
}
.tag-generator-panel .control-box > fieldset legend {
border: 1px solid #dfdfdf;
border-right: 4px solid #00a0d2;
}
.tag-generator-panel .insert-box input.tag {
float: right;
}
.tag-generator-panel .insert-box .submitbox input[type="button"] {
float: left;
}
/*
* Mail Tab
*/
.contact-form-editor-box-mail span.mailtag {
margin: 0 4px 0 0;
}
/*
* Welcome Panel
*/
.welcome-panel .welcome-panel-column,
.welcome-panel .welcome-panel-column:first-child {
padding: 0 0 0 2%;
}
/*
* Integration
*/
.card {
border-left: 1px solid #e5e5e5;
border-right: 4px solid #e5e5e5;
}
.card img.icon {
float: right;
margin: 8px -8px 8px 8px;
}
.card h2.title {
float: right;
}
.card .infobox {
float: left;
}
#titlediv .inside p.description {
margin: 8px 2px 0;
}
#titlediv .inside p.description label {
cursor: pointer;
}
span.shortcode {
display: block;
margin: 2px 0;
}
span.shortcode.old {
background: #777;
color: #fff;
}
span.shortcode input {
font-size: 12px;
border: none;
box-shadow: none;
padding: 4px 8px;
margin: 0;
}
#wpcf7-contact-form-list-table span.shortcode input,
#wpcf7-contact-form-editor span.shortcode input {
background: transparent;
}
#wpcf7-contact-form-list-table span.shortcode input {
color: #444;
}
#wpcf7-contact-form-editor span.shortcode input {
color: #fff;
}
#submitpost input.copy {
margin-bottom: 10px;
}
#submitpost input.delete {
padding: 0;
margin: 0;
border: none;
cursor: pointer;
background: inherit;
color: #a00;
}
#submitpost input.delete:hover {
color: #f00;
}
#submitpost input.delete:focus {
outline: thin dotted;
}
.postbox-container .postbox h3 {
border-bottom: 1px solid transparent;
}
.keyboard-interaction {
visibility: hidden;
color: #23282d;
}
div.config-error, span.config-error, ul.config-error {
color: #444;
font-style: normal;
font-size: 13px;
}
ul.config-error {
margin: 2px 0;
}
ul.config-error li {
list-style: none;
padding: 2px 2px;
margin: 0;
}
[data-config-field][aria-invalid="true"] {
border-color: #d00;
}
#contact-form-editor-tabs li a .icon-in-circle,
#contact-form-editor .config-error .icon-in-circle,
.wp-list-table .config-error .icon-in-circle,
.icon-in-circle {
display: inline-block;
vertical-align: text-top;
margin: 1px 6px 0;
padding: 0 5px;
min-width: 7px;
height: 17px;
border-radius: 11px;
background-color: #ca4a1f;
color: #fff;
font-size: 12px;
font-weight: bold;
line-height: 17px;
text-align: center;
z-index: 26;
}
/*
* Tabs
*/
#contact-form-editor-tabs {
border-bottom: 1px solid #aaa;
padding: 9px 15px 0 10px;
margin: 0;
}
#contact-form-editor-tabs li {
display: inline-block;
list-style: none;
border: 1px solid #ccc;
border-bottom: 1px solid #aaa;
padding: 0;
margin: 0 4px -1px;
background-color: #e4e4e4;
}
#contact-form-editor-tabs li:hover {
background-color: #fff;
}
#contact-form-editor-tabs li.ui-tabs-active,
#contact-form-editor-tabs li.ui-tabs-active:hover {
border-top: 1px solid #aaa;
border-right: 1px solid #aaa;
border-left: 1px solid #aaa;
border-bottom: 1px solid #f5f5f5;
background-color: #f5f5f5;
}
#contact-form-editor-tabs li a {
padding: 6px 10px;
font-size: 14px;
font-weight: normal;
line-height: 30px;
color: #333;
text-decoration: none;
}
#contact-form-editor-tabs li.ui-tabs-active a {
color: #000;
font-size: 14px;
font-weight: bold;
}
#contact-form-editor-tabs li a:hover {
color: #000;
}
#contact-form-editor .contact-form-editor-panel > div.config-error {
margin-bottom: 1.4em;
}
#contact-form-editor-tabs li.ui-tabs-active a .icon-in-circle {
display: none;
}
#contact-form-editor .contact-form-editor-panel h2 {
font-size: 18px;
font-weight: 400;
line-height: 24px;
margin: 8px 0;
padding: 0;
}
#contact-form-editor .contact-form-editor-panel {
background-color: #f5f5f5;
border: 1px solid #aaa;
border-top: none;
padding: 16px;
}
#contact-form-editor .form-table th {
width: 100px;
}
#contact-form-editor .contact-form-editor-panel fieldset legend {
line-height: 1.5;
margin: .6em 0 .4em;
}
/*
* Form Tab
*/
#tag-generator-list a.button {
font-size: 12px;
height: 26px;
line-height: 24px;
margin: 2px;
padding: 0 8px 1px;
}
.tag-generator-panel {
position: relative;
height: 495px;
}
.tag-generator-panel .control-box {
padding: 0;
margin: 0;
height: 380px;
overflow: auto;
}
.tag-generator-panel .control-box > fieldset legend {
border: 1px solid #dfdfdf;
border-left: 4px solid #00a0d2;
background: #f7fcfe;
padding: 4px 12px;
margin: 4px 0;
line-height: 1.4em;
width: 95%;
}
.tag-generator-panel table {
width: 100%;
}
.tag-generator-panel table.form-table th {
width: 120px;
padding: 4px 10px 4px 0;
font-size: 13px;
}
.tag-generator-panel table.form-table td {
padding: 4px 10px;
font-size: 13px;
}
.tag-generator-panel .control-box input.oneline {
width: 200px;
}
.tag-generator-panel .control-box input.large-text {
width: 400px;
}
.tag-generator-panel .control-box textarea.values {
width: 200px;
height: 6em;
}
.tag-generator-panel .control-box input[type="number"],
.tag-generator-panel .control-box input[type="date"] {
width: 88px;
}
.tag-generator-panel .control-box table caption {
text-align: left;
font-size: 110%;
font-weight: bold;
color: #777;
margin: 10px 0 5px;
}
.tag-generator-panel .control-box table.form-table td label {
line-height: 1.1em;
}
.tag-generator-panel .control-box table.form-table td label .description {
line-height: 1.4em;
}
.tag-generator-panel .insert-box {
position: absolute;
left: -15px;
right: -15px;
bottom: -15px;
width: 100%;
height: 84px;
margin: 0;
padding: 8px 16px;
background-color: #fcfcfc;
border-top: 1px solid #dfdfdf;
overflow: auto;
}
.tag-generator-panel .insert-box input.tag {
width: 480px;
float: left;
background-color: transparent;
box-shadow: none;
}
.tag-generator-panel .insert-box .submitbox {
padding: 2px 4px;
}
.tag-generator-panel .insert-box .submitbox input[type="button"] {
float: right;
}
.tag-generator-panel .insert-box .description label {
cursor: text;
}
/*
* Mail Tab
*/
.contact-form-editor-box-mail span.mailtag {
display: inline-block;
margin: 0 0 0 4px;
padding: 1px 2px;
cursor: pointer;
color: #000;
}
.contact-form-editor-box-mail span.mailtag.used {
color: #666;
}
.contact-form-editor-box-mail span.mailtag.unused {
font-weight: bold;
}
/*
* Messages Tab
*/
#messages-panel p.description {
margin: 5px 0 10px;
}
/*
* List Table
*/
.fixed .column-title {
width: 38%;
}
.fixed .column-shortcode {
width: 38%;
}
/*
* Welcome Panel
*/
.welcome-panel .welcome-panel-column,
.welcome-panel .welcome-panel-column:first-child {
width: 48%;
padding: 0 2% 0 0;
margin: 0 0 1em 0;
}
@media screen and (max-width: 870px) {
.welcome-panel .welcome-panel-column,
.welcome-panel .welcome-panel-column:first-child {
display: block;
float: none;
width: 100%;
}
}
.welcome-panel h3 {
font-size: 16px;
font-weight: 600;
line-height: 2.1em;
margin: 1em 0 1.2em;
}
.welcome-panel h3 .dashicons {
position: relative;
top: -2px;
display: inline-block;
width: 60px;
color: #575757;
font-size: 40px;
}
.welcome-panel p a {
font-weight: bold;
}
.welcome-panel-close {
z-index: 2;
}
/*
* Integration
*/
.card {
background: #fff none repeat scroll 0 0;
border: 1px solid #e5e5e5;
border-left: 4px solid #e5e5e5;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
margin-top: 20px;
max-width: 520px;
min-width: 255px;
padding: 0.7em 2em 1em;
position: relative;
}
.card.active {
border-color: #00a0d2;
}
.card img.icon {
float: left;
margin: 8px 8px 8px -8px;
}
.card h2.title {
float: left;
max-width: 240px;
font-size: 1.3em;
font-weight: 600;
}
.card .infobox {
float: right;
font-size: 13px;
color: #666;
margin: 2px 0 5px;
line-height: 1.5;
max-width: 240px;
}
.card .inside .form-table th {
padding: 15px 10px 15px 0;
width: 160px;
}
.card .inside .form-table td {
padding: 10px 10px;
}
.card .checkboxes li {
margin: 0;
}
<?php
// don't load directly
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
function wpcf7_admin_save_button( $post_id ) {
static $button = '';
if ( ! empty( $button ) ) {
echo $button;
return;
}
$nonce = wp_create_nonce( 'wpcf7-save-contact-form_' . $post_id );
$onclick = sprintf(
"this.form._wpnonce.value = '%s';"
. " this.form.action.value = 'save';"
. " return true;",
$nonce );
$button = sprintf(
'<input type="submit" class="button-primary" name="wpcf7-save" value="%1$s" onclick="%2$s" />',
esc_attr( __( 'Save', 'contact-form-7' ) ),
$onclick );
echo $button;
}
?><div class="wrap" id="wpcf7-contact-form-editor">
<h1 class="wp-heading-inline"><?php
if ( $post->initial() ) {
echo esc_html( __( 'Add New Contact Form', 'contact-form-7' ) );
} else {
echo esc_html( __( 'Edit Contact Form', 'contact-form-7' ) );
}
?></h1>
<?php
if ( ! $post->initial()
and current_user_can( 'wpcf7_edit_contact_forms' ) ) {
echo wpcf7_link(
menu_page_url( 'wpcf7-new', false ),
__( 'Add New', 'contact-form-7' ),
array( 'class' => 'page-title-action' )
);
}
?>
<hr class="wp-header-end">
<?php
do_action( 'wpcf7_admin_warnings',
$post->initial() ? 'wpcf7-new' : 'wpcf7',
wpcf7_current_action(),
$post
);
do_action( 'wpcf7_admin_notices',
$post->initial() ? 'wpcf7-new' : 'wpcf7',
wpcf7_current_action(),
$post
);
?>
<?php
if ( $post ) :
if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) {
$disabled = '';
} else {
$disabled = ' disabled="disabled"';
}
?>
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'post' => $post_id ), menu_page_url( 'wpcf7', false ) ) ); ?>" id="wpcf7-admin-form-element"<?php do_action( 'wpcf7_post_edit_form_tag' ); ?>>
<?php
if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) {
wp_nonce_field( 'wpcf7-save-contact-form_' . $post_id );
}
?>
<input type="hidden" id="post_ID" name="post_ID" value="<?php echo (int) $post_id; ?>" />
<input type="hidden" id="wpcf7-locale" name="wpcf7-locale" value="<?php echo esc_attr( $post->locale() ); ?>" />
<input type="hidden" id="hiddenaction" name="action" value="save" />
<input type="hidden" id="active-tab" name="active-tab" value="<?php echo isset( $_GET['active-tab'] ) ? (int) $_GET['active-tab'] : '0'; ?>" />
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
<div id="titlediv">
<div id="titlewrap">
<label class="screen-reader-text" id="title-prompt-text" for="title"><?php echo esc_html( __( 'Enter title here', 'contact-form-7' ) ); ?></label>
<?php
$posttitle_atts = array(
'type' => 'text',
'name' => 'post_title',
'size' => 30,
'value' => $post->initial() ? '' : $post->title(),
'id' => 'title',
'spellcheck' => 'true',
'autocomplete' => 'off',
'disabled' =>
current_user_can( 'wpcf7_edit_contact_form', $post_id ) ? '' : 'disabled',
);
echo sprintf( '<input %s />', wpcf7_format_atts( $posttitle_atts ) );
?>
</div><!-- #titlewrap -->
<div class="inside">
<?php
if ( ! $post->initial() ) :
?>
<p class="description">
<label for="wpcf7-shortcode"><?php echo esc_html( __( "Copy this shortcode and paste it into your post, page, or text widget content:", 'contact-form-7' ) ); ?></label>
<span class="shortcode wp-ui-highlight"><input type="text" id="wpcf7-shortcode" onfocus="this.select();" readonly="readonly" class="large-text code" value="<?php echo esc_attr( $post->shortcode() ); ?>" /></span>
</p>
<?php
if ( $old_shortcode = $post->shortcode( array( 'use_old_format' => true ) ) ) :
?>
<p class="description">
<label for="wpcf7-shortcode-old"><?php echo esc_html( __( "You can also use this old-style shortcode:", 'contact-form-7' ) ); ?></label>
<span class="shortcode old"><input type="text" id="wpcf7-shortcode-old" onfocus="this.select();" readonly="readonly" class="large-text code" value="<?php echo esc_attr( $old_shortcode ); ?>" /></span>
</p>
<?php
endif;
endif;
?>
</div>
</div><!-- #titlediv -->
</div><!-- #post-body-content -->
<div id="postbox-container-1" class="postbox-container">
<?php if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) : ?>
<div id="submitdiv" class="postbox">
<h3><?php echo esc_html( __( 'Status', 'contact-form-7' ) ); ?></h3>
<div class="inside">
<div class="submitbox" id="submitpost">
<div id="minor-publishing-actions">
<div class="hidden">
<input type="submit" class="button-primary" name="wpcf7-save" value="<?php echo esc_attr( __( 'Save', 'contact-form-7' ) ); ?>" />
</div>
<?php
if ( ! $post->initial() ) :
$copy_nonce = wp_create_nonce( 'wpcf7-copy-contact-form_' . $post_id );
?>
<input type="submit" name="wpcf7-copy" class="copy button" value="<?php echo esc_attr( __( 'Duplicate', 'contact-form-7' ) ); ?>" <?php echo "onclick=\"this.form._wpnonce.value = '$copy_nonce'; this.form.action.value = 'copy'; return true;\""; ?> />
<?php endif; ?>
</div><!-- #minor-publishing-actions -->
<div id="misc-publishing-actions">
<?php do_action( 'wpcf7_admin_misc_pub_section', $post_id ); ?>
</div><!-- #misc-publishing-actions -->
<div id="major-publishing-actions">
<?php
if ( ! $post->initial() ) :
$delete_nonce = wp_create_nonce( 'wpcf7-delete-contact-form_' . $post_id );
?>
<div id="delete-action">
<input type="submit" name="wpcf7-delete" class="delete submitdelete" value="<?php echo esc_attr( __( 'Delete', 'contact-form-7' ) ); ?>" <?php echo "onclick=\"if (confirm('" . esc_js( __( "You are about to delete this contact form.\n 'Cancel' to stop, 'OK' to delete.", 'contact-form-7' ) ) . "')) {this.form._wpnonce.value = '$delete_nonce'; this.form.action.value = 'delete'; return true;} return false;\""; ?> />
</div><!-- #delete-action -->
<?php endif; ?>
<div id="publishing-action">
<span class="spinner"></span>
<?php wpcf7_admin_save_button( $post_id ); ?>
</div>
<div class="clear"></div>
</div><!-- #major-publishing-actions -->
</div><!-- #submitpost -->
</div>
</div><!-- #submitdiv -->
<?php endif; ?>
<div id="informationdiv" class="postbox">
<h3><?php echo esc_html( __( "Do you need help?", 'contact-form-7' ) ); ?></h3>
<div class="inside">
<p><?php echo esc_html( __( "Here are some available options to help solve your problems.", 'contact-form-7' ) ); ?></p>
<ol>
<li><?php echo sprintf(
/* translators: 1: FAQ, 2: Docs ("FAQ & Docs") */
__( '%1$s &#38; %2$s', 'contact-form-7' ),
wpcf7_link(
__( 'https://contactform7.com/faq/', 'contact-form-7' ),
__( 'FAQ', 'contact-form-7' )
),
wpcf7_link(
__( 'https://contactform7.com/docs/', 'contact-form-7' ),
__( 'Docs', 'contact-form-7' )
)
); ?></li>
<li><?php echo wpcf7_link(
__( 'https://wordpress.org/support/plugin/contact-form-7/', 'contact-form-7' ),
__( 'Support Forums', 'contact-form-7' )
); ?></li>
<li><?php echo wpcf7_link(
__( 'https://contactform7.com/custom-development/', 'contact-form-7' ),
__( 'Professional Services', 'contact-form-7' )
); ?></li>
</ol>
</div>
</div><!-- #informationdiv -->
</div><!-- #postbox-container-1 -->
<div id="postbox-container-2" class="postbox-container">
<div id="contact-form-editor">
<div class="keyboard-interaction"><?php
echo sprintf(
/* translators: 1: ◀ ▶ dashicon, 2: screen reader text for the dashicon */
esc_html( __( '%1$s %2$s keys switch panels', 'contact-form-7' ) ),
'<span class="dashicons dashicons-leftright" aria-hidden="true"></span>',
sprintf(
'<span class="screen-reader-text">%s</span>',
/* translators: screen reader text */
esc_html( __( '(left and right arrow)', 'contact-form-7' ) )
)
);
?></div>
<?php
$editor = new WPCF7_Editor( $post );
$panels = array();
if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) {
$panels = array(
'form-panel' => array(
'title' => __( 'Form', 'contact-form-7' ),
'callback' => 'wpcf7_editor_panel_form',
),
'mail-panel' => array(
'title' => __( 'Mail', 'contact-form-7' ),
'callback' => 'wpcf7_editor_panel_mail',
),
'messages-panel' => array(
'title' => __( 'Messages', 'contact-form-7' ),
'callback' => 'wpcf7_editor_panel_messages',
),
);
$additional_settings = trim( $post->prop( 'additional_settings' ) );
$additional_settings = explode( "\n", $additional_settings );
$additional_settings = array_filter( $additional_settings );
$additional_settings = count( $additional_settings );
$panels['additional-settings-panel'] = array(
'title' => $additional_settings
/* translators: %d: number of additional settings */
? sprintf(
__( 'Additional Settings (%d)', 'contact-form-7' ),
$additional_settings )
: __( 'Additional Settings', 'contact-form-7' ),
'callback' => 'wpcf7_editor_panel_additional_settings',
);
}
$panels = apply_filters( 'wpcf7_editor_panels', $panels );
foreach ( $panels as $id => $panel ) {
$editor->add_panel( $id, $panel['title'], $panel['callback'] );
}
$editor->display();
?>
</div><!-- #contact-form-editor -->
<?php if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) : ?>
<p class="submit"><?php wpcf7_admin_save_button( $post_id ); ?></p>
<?php endif; ?>
</div><!-- #postbox-container-2 -->
</div><!-- #post-body -->
<br class="clear" />
</div><!-- #poststuff -->
</form>
<?php endif; ?>
</div><!-- .wrap -->
<?php
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->print_panels( $post );
do_action( 'wpcf7_admin_footer', $post );
<?php
function wpcf7_current_action() {
if ( isset( $_REQUEST['action'] ) and -1 != $_REQUEST['action'] ) {
return $_REQUEST['action'];
}
if ( isset( $_REQUEST['action2'] ) and -1 != $_REQUEST['action2'] ) {
return $_REQUEST['action2'];
}
return false;
}
function wpcf7_admin_has_edit_cap() {
return current_user_can( 'wpcf7_edit_contact_forms' );
}
function wpcf7_add_tag_generator( $name, $title, $elm_id, $callback, $options = array() ) {
$tag_generator = WPCF7_TagGenerator::get_instance();
return $tag_generator->add( $name, $title, $callback, $options );
}
<?php
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class WPCF7_Contact_Form_List_Table extends WP_List_Table {
public static function define_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'contact-form-7' ),
'shortcode' => __( 'Shortcode', 'contact-form-7' ),
'author' => __( 'Author', 'contact-form-7' ),
'date' => __( 'Date', 'contact-form-7' ),
);
return $columns;
}
public function __construct() {
parent::__construct( array(
'singular' => 'post',
'plural' => 'posts',
'ajax' => false,
) );
}
public function prepare_items() {
$current_screen = get_current_screen();
$per_page = $this->get_items_per_page( 'cfseven_contact_forms_per_page' );
$args = array(
'posts_per_page' => $per_page,
'orderby' => 'title',
'order' => 'ASC',
'offset' => ( $this->get_pagenum() - 1 ) * $per_page,
);
if ( ! empty( $_REQUEST['s'] ) ) {
$args['s'] = $_REQUEST['s'];
}
if ( ! empty( $_REQUEST['orderby'] ) ) {
if ( 'title' == $_REQUEST['orderby'] ) {
$args['orderby'] = 'title';
} elseif ( 'author' == $_REQUEST['orderby'] ) {
$args['orderby'] = 'author';
} elseif ( 'date' == $_REQUEST['orderby'] ) {
$args['orderby'] = 'date';
}
}
if ( ! empty( $_REQUEST['order'] ) ) {
if ( 'asc' == strtolower( $_REQUEST['order'] ) ) {
$args['order'] = 'ASC';
} elseif ( 'desc' == strtolower( $_REQUEST['order'] ) ) {
$args['order'] = 'DESC';
}
}
$this->items = WPCF7_ContactForm::find( $args );
$total_items = WPCF7_ContactForm::count();
$total_pages = ceil( $total_items / $per_page );
$this->set_pagination_args( array(
'total_items' => $total_items,
'total_pages' => $total_pages,
'per_page' => $per_page,
) );
}
public function get_columns() {
return get_column_headers( get_current_screen() );
}
protected function get_sortable_columns() {
$columns = array(
'title' => array( 'title', true ),
'author' => array( 'author', false ),
'date' => array( 'date', false ),
);
return $columns;
}
protected function get_bulk_actions() {
$actions = array(
'delete' => __( 'Delete', 'contact-form-7' ),
);
return $actions;
}
protected function column_default( $item, $column_name ) {
return '';
}
public function column_cb( $item ) {
return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
$this->_args['singular'],
$item->id()
);
}
public function column_title( $item ) {
$edit_link = add_query_arg(
array(
'post' => absint( $item->id() ),
'action' => 'edit',
),
menu_page_url( 'wpcf7', false )
);
$output = sprintf(
'<a class="row-title" href="%1$s" aria-label="%2$s">%3$s</a>',
esc_url( $edit_link ),
/* translators: %s: title of contact form */
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;', 'contact-form-7' ),
$item->title() ) ),
esc_html( $item->title() )
);
$output = sprintf( '<strong>%s</strong>', $output );
if ( wpcf7_validate_configuration()
and current_user_can( 'wpcf7_edit_contact_form', $item->id() ) ) {
$config_validator = new WPCF7_ConfigValidator( $item );
$config_validator->restore();
if ( $count_errors = $config_validator->count_errors() ) {
$error_notice = sprintf(
/* translators: %s: number of errors detected */
_n(
'%s configuration error detected',
'%s configuration errors detected',
$count_errors, 'contact-form-7' ),
number_format_i18n( $count_errors )
);
$output .= sprintf(
'<div class="config-error"><span class="icon-in-circle" aria-hidden="true">!</span> %s</div>',
$error_notice
);
}
}
return $output;
}
protected function handle_row_actions( $item, $column_name, $primary ) {
if ( $column_name !== $primary ) {
return '';
}
$edit_link = add_query_arg(
array(
'post' => absint( $item->id() ),
'action' => 'edit',
),
menu_page_url( 'wpcf7', false )
);
$actions = array(
'edit' => wpcf7_link( $edit_link, __( 'Edit', 'contact-form-7' ) ),
);
if ( current_user_can( 'wpcf7_edit_contact_form', $item->id() ) ) {
$copy_link = add_query_arg(
array(
'post' => absint( $item->id() ),
'action' => 'copy',
),
menu_page_url( 'wpcf7', false )
);
$copy_link = wp_nonce_url(
$copy_link,
'wpcf7-copy-contact-form_' . absint( $item->id() )
);
$actions = array_merge( $actions, array(
'copy' => wpcf7_link( $copy_link, __( 'Duplicate', 'contact-form-7' ) ),
) );
}
return $this->row_actions( $actions );
}
public function column_author( $item ) {
$post = get_post( $item->id() );
if ( ! $post ) {
return;
}
$author = get_userdata( $post->post_author );
if ( false === $author ) {
return;
}
return esc_html( $author->display_name );
}
public function column_shortcode( $item ) {
$shortcodes = array( $item->shortcode() );
$output = '';
foreach ( $shortcodes as $shortcode ) {
$output .= "\n" . '<span class="shortcode"><input type="text"'
. ' onfocus="this.select();" readonly="readonly"'
. ' value="' . esc_attr( $shortcode ) . '"'
. ' class="large-text code" /></span>';
}
return trim( $output );
}
public function column_date( $item ) {
$post = get_post( $item->id() );
if ( ! $post ) {
return;
}
$t_time = mysql2date( __( 'Y/m/d g:i:s A', 'contact-form-7' ),
$post->post_date, true );
$m_time = $post->post_date;
$time = mysql2date( 'G', $post->post_date )
- get_option( 'gmt_offset' ) * 3600;
$time_diff = time() - $time;
if ( $time_diff > 0 and $time_diff < 24*60*60 ) {
$h_time = sprintf(
/* translators: %s: time since the creation of the contact form */
__( '%s ago', 'contact-form-7' ),
human_time_diff( $time )
);
} else {
$h_time = mysql2date( __( 'Y/m/d', 'contact-form-7' ), $m_time );
}
return sprintf( '<abbr title="%2$s">%1$s</abbr>',
esc_html( $h_time ),
esc_attr( $t_time )
);
}
}
<?php
add_action( 'wpcf7_admin_menu', 'wpcf7_admin_init_bulk_cv', 10, 0 );
function wpcf7_admin_init_bulk_cv() {
if ( ! wpcf7_validate_configuration()
or ! current_user_can( 'wpcf7_edit_contact_forms' ) ) {
return;
}
$result = WPCF7::get_option( 'bulk_validate' );
$last_important_update = '5.0.4';
if ( ! empty( $result['version'] )
and version_compare( $last_important_update, $result['version'], '<=' ) ) {
return;
}
add_filter( 'wpcf7_admin_menu_change_notice',
'wpcf7_admin_menu_change_notice_bulk_cv', 10, 1 );
add_action( 'wpcf7_admin_warnings',
'wpcf7_admin_warnings_bulk_cv', 5, 3 );
}
function wpcf7_admin_menu_change_notice_bulk_cv( $counts ) {
$counts['wpcf7'] += 1;
return $counts;
}
function wpcf7_admin_warnings_bulk_cv( $page, $action, $object ) {
if ( 'wpcf7' === $page and 'validate' === $action ) {
return;
}
$link = wpcf7_link(
add_query_arg(
array( 'action' => 'validate' ),
menu_page_url( 'wpcf7', false )
),
__( 'Validate Contact Form 7 Configuration', 'contact-form-7' )
);
$message = __( "Misconfiguration leads to mail delivery failure or other troubles. Validate your contact forms now.", 'contact-form-7' );
echo sprintf(
'<div class="notice notice-warning"><p>%1$s &raquo; %2$s</p></div>',
esc_html( $message ),
$link
);
}
add_action( 'wpcf7_admin_load', 'wpcf7_load_bulk_validate_page', 10, 2 );
function wpcf7_load_bulk_validate_page( $page, $action ) {
if ( 'wpcf7' != $page
or 'validate' != $action
or ! wpcf7_validate_configuration()
or 'POST' != $_SERVER['REQUEST_METHOD'] ) {
return;
}
check_admin_referer( 'wpcf7-bulk-validate' );
if ( ! current_user_can( 'wpcf7_edit_contact_forms' ) ) {
wp_die( __( "You are not allowed to validate configuration.", 'contact-form-7' ) );
}
$contact_forms = WPCF7_ContactForm::find();
$result = array(
'timestamp' => current_time( 'timestamp' ),
'version' => WPCF7_VERSION,
'count_valid' => 0,
'count_invalid' => 0,
);
foreach ( $contact_forms as $contact_form ) {
$config_validator = new WPCF7_ConfigValidator( $contact_form );
$config_validator->validate();
$config_validator->save();
if ( $config_validator->is_valid() ) {
$result['count_valid'] += 1;
} else {
$result['count_invalid'] += 1;
}
}
WPCF7::update_option( 'bulk_validate', $result );
$redirect_to = add_query_arg(
array(
'message' => 'validated',
),
menu_page_url( 'wpcf7', false )
);
wp_safe_redirect( $redirect_to );
exit();
}
function wpcf7_admin_bulk_validate_page() {
$contact_forms = WPCF7_ContactForm::find();
$count = WPCF7_ContactForm::count();
$submit_text = sprintf(
/* translators: %s: number of contact forms */
_n(
"Validate %s Contact Form Now",
"Validate %s Contact Forms Now",
$count, 'contact-form-7' ),
number_format_i18n( $count ) );
?>
<div class="wrap">
<h1><?php echo esc_html( __( 'Validate Configuration', 'contact-form-7' ) ); ?></h1>
<form method="post" action="">
<input type="hidden" name="action" value="validate" />
<?php wp_nonce_field( 'wpcf7-bulk-validate' ); ?>
<p><input type="submit" class="button" value="<?php echo esc_attr( $submit_text ); ?>" /></p>
</form>
<?php
echo wpcf7_link(
__( 'https://contactform7.com/configuration-validator-faq/', 'contact-form-7' ),
__( 'FAQ about Configuration Validator', 'contact-form-7' )
);
?>
</div>
<?php
}
<?php
class WPCF7_Editor {
private $contact_form;
private $panels = array();
public function __construct( WPCF7_ContactForm $contact_form ) {
$this->contact_form = $contact_form;
}
public function add_panel( $id, $title, $callback ) {
if ( wpcf7_is_name( $id ) ) {
$this->panels[$id] = array(
'title' => $title,
'callback' => $callback,
);
}
}
public function display() {
if ( empty( $this->panels ) ) {
return;
}
echo '<ul id="contact-form-editor-tabs">';
foreach ( $this->panels as $id => $panel ) {
echo sprintf( '<li id="%1$s-tab"><a href="#%1$s">%2$s</a></li>',
esc_attr( $id ), esc_html( $panel['title'] ) );
}
echo '</ul>';
foreach ( $this->panels as $id => $panel ) {
echo sprintf( '<div class="contact-form-editor-panel" id="%1$s">',
esc_attr( $id ) );
if ( is_callable( $panel['callback'] ) ) {
$this->notice( $id, $panel );
call_user_func( $panel['callback'], $this->contact_form );
}
echo '</div>';
}
}
public function notice( $id, $panel ) {
echo '<div class="config-error"></div>';
}
}
function wpcf7_editor_panel_form( $post ) {
$desc_link = wpcf7_link(
__( 'https://contactform7.com/editing-form-template/', 'contact-form-7' ),
__( 'Editing Form Template', 'contact-form-7' ) );
$description = __( "You can edit the form template here. For details, see %s.", 'contact-form-7' );
$description = sprintf( esc_html( $description ), $desc_link );
?>
<h2><?php echo esc_html( __( 'Form', 'contact-form-7' ) ); ?></h2>
<fieldset>
<legend><?php echo $description; ?></legend>
<?php
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->print_buttons();
?>
<textarea id="wpcf7-form" name="wpcf7-form" cols="100" rows="24" class="large-text code" data-config-field="form.body"><?php echo esc_textarea( $post->prop( 'form' ) ); ?></textarea>
</fieldset>
<?php
}
function wpcf7_editor_panel_mail( $post ) {
wpcf7_editor_box_mail( $post );
echo '<br class="clear" />';
wpcf7_editor_box_mail( $post, array(
'id' => 'wpcf7-mail-2',
'name' => 'mail_2',
'title' => __( 'Mail (2)', 'contact-form-7' ),
'use' => __( 'Use Mail (2)', 'contact-form-7' ),
) );
}
function wpcf7_editor_box_mail( $post, $args = '' ) {
$args = wp_parse_args( $args, array(
'id' => 'wpcf7-mail',
'name' => 'mail',
'title' => __( 'Mail', 'contact-form-7' ),
'use' => null,
) );
$id = esc_attr( $args['id'] );
$mail = wp_parse_args( $post->prop( $args['name'] ), array(
'active' => false,
'recipient' => '',
'sender' => '',
'subject' => '',
'body' => '',
'additional_headers' => '',
'attachments' => '',
'use_html' => false,
'exclude_blank' => false,
) );
?>
<div class="contact-form-editor-box-mail" id="<?php echo $id; ?>">
<h2><?php echo esc_html( $args['title'] ); ?></h2>
<?php
if ( ! empty( $args['use'] ) ) :
?>
<label for="<?php echo $id; ?>-active"><input type="checkbox" id="<?php echo $id; ?>-active" name="<?php echo $id; ?>[active]" class="toggle-form-table" value="1"<?php echo ( $mail['active'] ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( $args['use'] ); ?></label>
<p class="description"><?php echo esc_html( __( "Mail (2) is an additional mail template often used as an autoresponder.", 'contact-form-7' ) ); ?></p>
<?php
endif;
?>
<fieldset>
<legend>
<?php
$desc_link = wpcf7_link(
__( 'https://contactform7.com/setting-up-mail/', 'contact-form-7' ),
__( 'Setting Up Mail', 'contact-form-7' ) );
$description = __( "You can edit the mail template here. For details, see %s.", 'contact-form-7' );
$description = sprintf( esc_html( $description ), $desc_link );
echo $description;
echo '<br />';
echo esc_html( __( "In the following fields, you can use these mail-tags:",
'contact-form-7' ) );
echo '<br />';
$post->suggest_mail_tags( $args['name'] );
?>
</legend>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label for="<?php echo $id; ?>-recipient"><?php echo esc_html( __( 'To', 'contact-form-7' ) ); ?></label>
</th>
<td>
<input type="text" id="<?php echo $id; ?>-recipient" name="<?php echo $id; ?>[recipient]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['recipient'] ); ?>" data-config-field="<?php echo sprintf( '%s.recipient', esc_attr( $args['name'] ) ); ?>" />
</td>
</tr>
<tr>
<th scope="row">
<label for="<?php echo $id; ?>-sender"><?php echo esc_html( __( 'From', 'contact-form-7' ) ); ?></label>
</th>
<td>
<input type="text" id="<?php echo $id; ?>-sender" name="<?php echo $id; ?>[sender]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['sender'] ); ?>" data-config-field="<?php echo sprintf( '%s.sender', esc_attr( $args['name'] ) ); ?>" />
</td>
</tr>
<tr>
<th scope="row">
<label for="<?php echo $id; ?>-subject"><?php echo esc_html( __( 'Subject', 'contact-form-7' ) ); ?></label>
</th>
<td>
<input type="text" id="<?php echo $id; ?>-subject" name="<?php echo $id; ?>[subject]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['subject'] ); ?>" data-config-field="<?php echo sprintf( '%s.subject', esc_attr( $args['name'] ) ); ?>" />
</td>
</tr>
<tr>
<th scope="row">
<label for="<?php echo $id; ?>-additional-headers"><?php echo esc_html( __( 'Additional Headers', 'contact-form-7' ) ); ?></label>
</th>
<td>
<textarea id="<?php echo $id; ?>-additional-headers" name="<?php echo $id; ?>[additional_headers]" cols="100" rows="4" class="large-text code" data-config-field="<?php echo sprintf( '%s.additional_headers', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['additional_headers'] ); ?></textarea>
</td>
</tr>
<tr>
<th scope="row">
<label for="<?php echo $id; ?>-body"><?php echo esc_html( __( 'Message Body', 'contact-form-7' ) ); ?></label>
</th>
<td>
<textarea id="<?php echo $id; ?>-body" name="<?php echo $id; ?>[body]" cols="100" rows="18" class="large-text code" data-config-field="<?php echo sprintf( '%s.body', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['body'] ); ?></textarea>
<p><label for="<?php echo $id; ?>-exclude-blank"><input type="checkbox" id="<?php echo $id; ?>-exclude-blank" name="<?php echo $id; ?>[exclude_blank]" value="1"<?php echo ( ! empty( $mail['exclude_blank'] ) ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( __( 'Exclude lines with blank mail-tags from output', 'contact-form-7' ) ); ?></label></p>
<p><label for="<?php echo $id; ?>-use-html"><input type="checkbox" id="<?php echo $id; ?>-use-html" name="<?php echo $id; ?>[use_html]" value="1"<?php echo ( $mail['use_html'] ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( __( 'Use HTML content type', 'contact-form-7' ) ); ?></label></p>
</td>
</tr>
<tr>
<th scope="row">
<label for="<?php echo $id; ?>-attachments"><?php echo esc_html( __( 'File Attachments', 'contact-form-7' ) ); ?></label>
</th>
<td>
<textarea id="<?php echo $id; ?>-attachments" name="<?php echo $id; ?>[attachments]" cols="100" rows="4" class="large-text code" data-config-field="<?php echo sprintf( '%s.attachments', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['attachments'] ); ?></textarea>
</td>
</tr>
</tbody>
</table>
</fieldset>
</div>
<?php
}
function wpcf7_editor_panel_messages( $post ) {
$desc_link = wpcf7_link(
__( 'https://contactform7.com/editing-messages/', 'contact-form-7' ),
__( 'Editing Messages', 'contact-form-7' ) );
$description = __( "You can edit messages used in various situations here. For details, see %s.", 'contact-form-7' );
$description = sprintf( esc_html( $description ), $desc_link );
$messages = wpcf7_messages();
if ( isset( $messages['captcha_not_match'] )
and ! wpcf7_use_really_simple_captcha() ) {
unset( $messages['captcha_not_match'] );
}
?>
<h2><?php echo esc_html( __( 'Messages', 'contact-form-7' ) ); ?></h2>
<fieldset>
<legend><?php echo $description; ?></legend>
<?php
foreach ( $messages as $key => $arr ) {
$field_id = sprintf( 'wpcf7-message-%s', strtr( $key, '_', '-' ) );
$field_name = sprintf( 'wpcf7-messages[%s]', $key );
?>
<p class="description">
<label for="<?php echo $field_id; ?>"><?php echo esc_html( $arr['description'] ); ?><br />
<input type="text" id="<?php echo $field_id; ?>" name="<?php echo $field_name; ?>" class="large-text" size="70" value="<?php echo esc_attr( $post->message( $key, false ) ); ?>" data-config-field="<?php echo sprintf( 'messages.%s', esc_attr( $key ) ); ?>" />
</label>
</p>
<?php
}
?>
</fieldset>
<?php
}
function wpcf7_editor_panel_additional_settings( $post ) {
$desc_link = wpcf7_link(
__( 'https://contactform7.com/additional-settings/', 'contact-form-7' ),
__( 'Additional Settings', 'contact-form-7' ) );
$description = __( "You can add customization code snippets here. For details, see %s.", 'contact-form-7' );
$description = sprintf( esc_html( $description ), $desc_link );
?>
<h2><?php echo esc_html( __( 'Additional Settings', 'contact-form-7' ) ); ?></h2>
<fieldset>
<legend><?php echo $description; ?></legend>
<textarea id="wpcf7-additional-settings" name="wpcf7-additional-settings" cols="100" rows="8" class="large-text" data-config-field="additional_settings.body"><?php echo esc_textarea( $post->prop( 'additional_settings' ) ); ?></textarea>
</fieldset>
<?php
}
<?php
class WPCF7_Help_Tabs {
private $screen;
public function __construct( WP_Screen $screen ) {
$this->screen = $screen;
}
public function set_help_tabs( $type ) {
switch ( $type ) {
case 'list':
$this->screen->add_help_tab( array(
'id' => 'list_overview',
'title' => __( 'Overview', 'contact-form-7' ),
'content' => $this->content( 'list_overview' ) ) );
$this->screen->add_help_tab( array(
'id' => 'list_available_actions',
'title' => __( 'Available Actions', 'contact-form-7' ),
'content' => $this->content( 'list_available_actions' ) ) );
$this->sidebar();
return;
case 'edit':
$this->screen->add_help_tab( array(
'id' => 'edit_overview',
'title' => __( 'Overview', 'contact-form-7' ),
'content' => $this->content( 'edit_overview' ) ) );
$this->screen->add_help_tab( array(
'id' => 'edit_form_tags',
'title' => __( 'Form-tags', 'contact-form-7' ),
'content' => $this->content( 'edit_form_tags' ) ) );
$this->screen->add_help_tab( array(
'id' => 'edit_mail_tags',
'title' => __( 'Mail-tags', 'contact-form-7' ),
'content' => $this->content( 'edit_mail_tags' ) ) );
$this->sidebar();
return;
case 'integration':
$this->screen->add_help_tab( array(
'id' => 'integration_overview',
'title' => __( 'Overview', 'contact-form-7' ),
'content' => $this->content( 'integration_overview' ) ) );
$this->sidebar();
return;
}
}
private function content( $name ) {
$content = array();
$content['list_overview'] = '<p>' . __( "On this screen, you can manage contact forms provided by Contact Form 7. You can manage an unlimited number of contact forms. Each contact form has a unique ID and Contact Form 7 shortcode ([contact-form-7 ...]). To insert a contact form into a post or a text widget, insert the shortcode into the target.", 'contact-form-7' ) . '</p>';
$content['list_available_actions'] = '<p>' . __( "Hovering over a row in the contact forms list will display action links that allow you to manage your contact form. You can perform the following actions:", 'contact-form-7' ) . '</p>';
$content['list_available_actions'] .= '<p>' . __( "<strong>Edit</strong> - Navigates to the editing screen for that contact form. You can also reach that screen by clicking on the contact form title.", 'contact-form-7' ) . '</p>';
$content['list_available_actions'] .= '<p>' . __( "<strong>Duplicate</strong> - Clones that contact form. A cloned contact form inherits all content from the original, but has a different ID.", 'contact-form-7' ) . '</p>';
$content['edit_overview'] = '<p>' . __( "On this screen, you can edit a contact form. A contact form is comprised of the following components:", 'contact-form-7' ) . '</p>';
$content['edit_overview'] .= '<p>' . __( "<strong>Title</strong> is the title of a contact form. This title is only used for labeling a contact form, and can be edited.", 'contact-form-7' ) . '</p>';
$content['edit_overview'] .= '<p>' . __( "<strong>Form</strong> is a content of HTML form. You can use arbitrary HTML, which is allowed inside a form element. You can also use Contact Form 7&#8217;s form-tags here.", 'contact-form-7' ) . '</p>';
$content['edit_overview'] .= '<p>' . __( "<strong>Mail</strong> manages a mail template (headers and message body) that this contact form will send when users submit it. You can use Contact Form 7&#8217;s mail-tags here.", 'contact-form-7' ) . '</p>';
$content['edit_overview'] .= '<p>' . __( "<strong>Mail (2)</strong> is an additional mail template that works similar to Mail. Mail (2) is different in that it is sent only when Mail has been sent successfully.", 'contact-form-7' ) . '</p>';
$content['edit_overview'] .= '<p>' . __( "In <strong>Messages</strong>, you can edit various types of messages used for this contact form. These messages are relatively short messages, like a validation error message you see when you leave a required field blank.", 'contact-form-7' ) . '</p>';
$content['edit_overview'] .= '<p>' . __( "<strong>Additional Settings</strong> provides a place where you can customize the behavior of this contact form by adding code snippets.", 'contact-form-7' ) . '</p>';
$content['edit_form_tags'] = '<p>' . __( "A form-tag is a short code enclosed in square brackets used in a form content. A form-tag generally represents an input field, and its components can be separated into four parts: type, name, options, and values. Contact Form 7 supports several types of form-tags including text fields, number fields, date fields, checkboxes, radio buttons, menus, file-uploading fields, CAPTCHAs, and quiz fields.", 'contact-form-7' ) . '</p>';
$content['edit_form_tags'] .= '<p>' . __( "While form-tags have a comparatively complex syntax, you don&#8217;t need to know the syntax to add form-tags because you can use the straightforward tag generator (<strong>Generate Tag</strong> button on this screen).", 'contact-form-7' ) . '</p>';
$content['edit_mail_tags'] = '<p>' . __( "A mail-tag is also a short code enclosed in square brackets that you can use in every Mail and Mail (2) field. A mail-tag represents a user input value through an input field of a corresponding form-tag.", 'contact-form-7' ) . '</p>';
$content['edit_mail_tags'] .= '<p>' . __( "There are also special mail-tags that have specific names, but don&#8217;t have corresponding form-tags. They are used to represent meta information of form submissions like the submitter&#8217;s IP address or the URL of the page.", 'contact-form-7' ) . '</p>';
$content['integration_overview'] = '<p>' . __( "On this screen, you can manage services that are available through Contact Form 7. Using API will allow you to collaborate with any services that are available.", 'contact-form-7' ) . '</p>';
$content['integration_overview'] .= '<p>' . __( "You may need to first sign up for an account with the service that you plan to use. When you do so, you would need to authorize Contact Form 7 to access the service with your account.", 'contact-form-7' ) . '</p>';
$content['integration_overview'] .= '<p>' . __( "Any information you provide will not be shared with service providers without your authorization.", 'contact-form-7' ) . '</p>';
if ( ! empty( $content[$name] ) ) {
return $content[$name];
}
}
public function sidebar() {
$content = '<p><strong>' . __( 'For more information:', 'contact-form-7' ) . '</strong></p>';
$content .= '<p>' . wpcf7_link( __( 'https://contactform7.com/docs/', 'contact-form-7' ), __( 'Docs', 'contact-form-7' ) ) . '</p>';
$content .= '<p>' . wpcf7_link( __( 'https://contactform7.com/faq/', 'contact-form-7' ), __( 'FAQ', 'contact-form-7' ) ) . '</p>';
$content .= '<p>' . wpcf7_link( __( 'https://contactform7.com/support/', 'contact-form-7' ), __( 'Support', 'contact-form-7' ) ) . '</p>';
$this->screen->set_help_sidebar( $content );
}
}
<?php
class WPCF7_TagGenerator {
private static $instance;
private $panels = array();
private function __construct() {}
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
public function add( $id, $title, $callback, $options = array() ) {
$id = trim( $id );
if ( '' === $id
or ! wpcf7_is_name( $id ) ) {
return false;
}
$this->panels[$id] = array(
'title' => $title,
'content' => 'tag-generator-panel-' . $id,
'options' => $options,
'callback' => $callback,
);
return true;
}
public function print_buttons() {
echo '<span id="tag-generator-list">';
foreach ( (array) $this->panels as $panel ) {
echo sprintf(
'<a href="#TB_inline?width=900&height=500&inlineId=%1$s" class="thickbox button" title="%2$s">%3$s</a>',
esc_attr( $panel['content'] ),
/* translators: %s: title of form-tag like 'email' or 'checkboxes' */
esc_attr( sprintf(
__( 'Form-tag Generator: %s', 'contact-form-7' ),
$panel['title'] ) ),
esc_html( $panel['title'] )
);
}
echo '</span>';
}
public function print_panels( WPCF7_ContactForm $contact_form ) {
foreach ( (array) $this->panels as $id => $panel ) {
$callback = $panel['callback'];
$options = wp_parse_args( $panel['options'], array() );
$options = array_merge( $options, array(
'id' => $id,
'title' => $panel['title'],
'content' => $panel['content'],
) );
if ( is_callable( $callback ) ) {
echo sprintf( '<div id="%s" class="hidden">',
esc_attr( $options['content'] ) );
echo sprintf(
'<form action="" class="tag-generator-panel" data-id="%s">',
$options['id'] );
call_user_func( $callback, $contact_form, $options );
echo '</form></div>';
}
}
}
}
<?php
function wpcf7_welcome_panel() {
$classes = 'welcome-panel';
$vers = (array) get_user_meta( get_current_user_id(),
'wpcf7_hide_welcome_panel_on', true );
if ( wpcf7_version_grep( wpcf7_version( 'only_major=1' ), $vers ) ) {
$classes .= ' hidden';
}
?>
<div id="welcome-panel" class="<?php echo esc_attr( $classes ); ?>">
<?php wp_nonce_field( 'wpcf7-welcome-panel-nonce', 'welcomepanelnonce', false ); ?>
<a class="welcome-panel-close" href="<?php echo esc_url( menu_page_url( 'wpcf7', false ) ); ?>"><?php echo esc_html( __( 'Dismiss', 'contact-form-7' ) ); ?></a>
<div class="welcome-panel-content">
<div class="welcome-panel-column-container">
<div class="welcome-panel-column">
<h3><span class="dashicons dashicons-shield" aria-hidden="true"></span> <?php echo esc_html( __( "Getting spammed? You have protection.", 'contact-form-7' ) ); ?></h3>
<p><?php echo esc_html( __( "Spammers target everything; your contact forms aren&#8217;t an exception. Before you get spammed, protect your contact forms with the powerful anti-spam features Contact Form 7 provides.", 'contact-form-7' ) ); ?></p>
<p><?php /* translators: links labeled 1: 'Akismet', 2: 'reCAPTCHA', 3: 'comment blacklist' */ echo sprintf( esc_html( __( 'Contact Form 7 supports spam-filtering with %1$s. Intelligent %2$s blocks annoying spambots. Plus, using %3$s, you can block messages containing specified keywords or those sent from specified IP addresses.', 'contact-form-7' ) ), wpcf7_link( __( 'https://contactform7.com/spam-filtering-with-akismet/', 'contact-form-7' ), __( 'Akismet', 'contact-form-7' ) ), wpcf7_link( __( 'https://contactform7.com/recaptcha/', 'contact-form-7' ), __( 'reCAPTCHA', 'contact-form-7' ) ), wpcf7_link( __( 'https://contactform7.com/comment-blacklist/', 'contact-form-7' ), __( 'comment blacklist', 'contact-form-7' ) ) ); ?></p>
</div>
<?php if ( defined( 'FLAMINGO_VERSION' ) ) : ?>
<div class="welcome-panel-column">
<h3><span class="dashicons dashicons-megaphone" aria-hidden="true"></span> <?php echo esc_html( __( "Contact Form 7 needs your support.", 'contact-form-7' ) ); ?></h3>
<p><?php echo esc_html( __( "It is hard to continue development and support for this plugin without contributions from users like you.", 'contact-form-7' ) ); ?></p>
<p><?php /* translators: %s: link labeled 'making a donation' */ echo sprintf( esc_html( __( 'If you enjoy using Contact Form 7 and find it useful, please consider %s.', 'contact-form-7' ) ), wpcf7_link( __( 'https://contactform7.com/donate/', 'contact-form-7' ), __( 'making a donation', 'contact-form-7' ) ) ); ?></p>
<p><?php echo esc_html( __( "Your donation will help encourage and support the plugin&#8217;s continued development and better user support.", 'contact-form-7' ) ); ?></p>
</div>
<?php else: ?>
<div class="welcome-panel-column">
<h3><span class="dashicons dashicons-editor-help" aria-hidden="true"></span> <?php echo esc_html( __( "Before you cry over spilt mail&#8230;", 'contact-form-7' ) ); ?></h3>
<p><?php echo esc_html( __( "Contact Form 7 doesn&#8217;t store submitted messages anywhere. Therefore, you may lose important messages forever if your mail server has issues or you make a mistake in mail configuration.", 'contact-form-7' ) ); ?></p>
<p><?php /* translators: %s: link labeled 'Flamingo' */ echo sprintf( esc_html( __( 'Install a message storage plugin before this happens to you. %s saves all messages through contact forms into the database. Flamingo is a free WordPress plugin created by the same author as Contact Form 7.', 'contact-form-7' ) ), wpcf7_link( __( 'https://contactform7.com/save-submitted-messages-with-flamingo/', 'contact-form-7' ), __( 'Flamingo', 'contact-form-7' ) ) ); ?></p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php
}
add_action( 'wp_ajax_wpcf7-update-welcome-panel',
'wpcf7_admin_ajax_welcome_panel', 10, 0 );
function wpcf7_admin_ajax_welcome_panel() {
check_ajax_referer( 'wpcf7-welcome-panel-nonce', 'welcomepanelnonce' );
$vers = get_user_meta( get_current_user_id(),
'wpcf7_hide_welcome_panel_on', true );
if ( empty( $vers ) or ! is_array( $vers ) ) {
$vers = array();
}
if ( empty( $_POST['visible'] ) ) {
$vers[] = wpcf7_version( 'only_major=1' );
}
$vers = array_unique( $vers );
update_user_meta( get_current_user_id(),
'wpcf7_hide_welcome_panel_on', $vers );
wp_die( 1 );
}
( function( $ ) {
'use strict';
if ( typeof wpcf7 === 'undefined' || wpcf7 === null ) {
return;
}
$( function() {
var welcomePanel = $( '#welcome-panel' );
var updateWelcomePanel;
updateWelcomePanel = function( visible ) {
$.post( ajaxurl, {
action: 'wpcf7-update-welcome-panel',
visible: visible,
welcomepanelnonce: $( '#welcomepanelnonce' ).val()
} );
};
$( 'a.welcome-panel-close', welcomePanel ).click( function( event ) {
event.preventDefault();
welcomePanel.addClass( 'hidden' );
updateWelcomePanel( 0 );
} );
$( '#contact-form-editor' ).tabs( {
active: wpcf7.activeTab,
activate: function( event, ui ) {
$( '#active-tab' ).val( ui.newTab.index() );
}
} );
$( '#contact-form-editor-tabs' ).focusin( function( event ) {
$( '#contact-form-editor .keyboard-interaction' ).css(
'visibility', 'visible' );
} ).focusout( function( event ) {
$( '#contact-form-editor .keyboard-interaction' ).css(
'visibility', 'hidden' );
} );
wpcf7.toggleMail2( 'input:checkbox.toggle-form-table' );
$( 'input:checkbox.toggle-form-table' ).click( function( event ) {
wpcf7.toggleMail2( this );
} );
if ( '' === $( '#title' ).val() ) {
$( '#title' ).focus();
}
wpcf7.titleHint();
$( '.contact-form-editor-box-mail span.mailtag' ).click( function( event ) {
var range = document.createRange();
range.selectNodeContents( this );
window.getSelection().addRange( range );
} );
wpcf7.updateConfigErrors();
$( '[data-config-field]' ).change( function() {
var postId = $( '#post_ID' ).val();
if ( ! postId || -1 == postId ) {
return;
}
var data = [];
$( this ).closest( 'form' ).find( '[data-config-field]' ).each( function() {
data.push( {
'name': $( this ).attr( 'name' ).replace( /^wpcf7-/, '' ).replace( /-/g, '_' ),
'value': $( this ).val()
} );
} );
data.push( { 'name': 'context', 'value': 'dry-run' } );
$.ajax( {
method: 'POST',
url: wpcf7.apiSettings.getRoute( '/contact-forms/' + postId ),
beforeSend: function( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', wpcf7.apiSettings.nonce );
},
data: data
} ).done( function( response ) {
wpcf7.configValidator.errors = response.config_errors;
wpcf7.updateConfigErrors();
} );
} );
$( window ).on( 'beforeunload', function( event ) {
var changed = false;
$( '#wpcf7-admin-form-element :input[type!="hidden"]' ).each( function() {
if ( $( this ).is( ':checkbox, :radio' ) ) {
if ( this.defaultChecked != $( this ).is( ':checked' ) ) {
changed = true;
}
} else if ( $( this ).is( 'select' ) ) {
$( this ).find( 'option' ).each( function() {
if ( this.defaultSelected != $( this ).is( ':selected' ) ) {
changed = true;
}
} );
} else {
if ( this.defaultValue != $( this ).val() ) {
changed = true;
}
}
} );
if ( changed ) {
event.returnValue = wpcf7.saveAlert;
return wpcf7.saveAlert;
}
} );
$( '#wpcf7-admin-form-element' ).submit( function() {
if ( 'copy' != this.action.value ) {
$( window ).off( 'beforeunload' );
}
if ( 'save' == this.action.value ) {
$( '#publishing-action .spinner' ).addClass( 'is-active' );
}
} );
} );
wpcf7.toggleMail2 = function( checkbox ) {
var $checkbox = $( checkbox );
var $fieldset = $( 'fieldset',
$checkbox.closest( '.contact-form-editor-box-mail' ) );
if ( $checkbox.is( ':checked' ) ) {
$fieldset.removeClass( 'hidden' );
} else {
$fieldset.addClass( 'hidden' );
}
};
wpcf7.updateConfigErrors = function() {
var errors = wpcf7.configValidator.errors;
var errorCount = { total: 0 };
$( '[data-config-field]' ).each( function() {
$( this ).removeAttr( 'aria-invalid' );
$( this ).next( 'ul.config-error' ).remove();
var section = $( this ).attr( 'data-config-field' );
if ( errors[ section ] ) {
var $list = $( '<ul></ul>' ).attr( {
'role': 'alert',
'class': 'config-error'
} );
$.each( errors[ section ], function( i, val ) {
var $li = $( '<li></li>' ).append(
wpcf7.iconInCircle( '!' )
).append(
$( '<span class="screen-reader-text"></span>' ).text( wpcf7.configValidator.iconAlt )
).append( ' ' );
if ( val.link ) {
$li.append(
$( '<a></a>' ).attr( 'href', val.link ).text( val.message )
);
} else {
$li.text( val.message );
}
$li.appendTo( $list );
var tab = section
.replace( /^mail_\d+\./, 'mail.' ).replace( /\..*$/, '' );
if ( ! errorCount[ tab ] ) {
errorCount[ tab ] = 0;
}
errorCount[ tab ] += 1;
errorCount.total += 1;
} );
$( this ).after( $list ).attr( { 'aria-invalid': 'true' } );
}
} );
$( '#contact-form-editor-tabs > li' ).each( function() {
var $item = $( this );
$item.find( '.icon-in-circle' ).remove();
var tab = $item.attr( 'id' ).replace( /-panel-tab$/, '' );
$.each( errors, function( key, val ) {
key = key.replace( /^mail_\d+\./, 'mail.' );
if ( key.replace( /\..*$/, '' ) == tab.replace( '-', '_' ) ) {
var $mark = wpcf7.iconInCircle( '!' );
$item.find( 'a.ui-tabs-anchor' ).first().append( $mark );
return false;
}
} );
var $tabPanelError = $( '#' + tab + '-panel > div.config-error:first' );
$tabPanelError.empty();
if ( errorCount[ tab.replace( '-', '_' ) ] ) {
$tabPanelError.append( wpcf7.iconInCircle( '!' ) );
if ( 1 < errorCount[ tab.replace( '-', '_' ) ] ) {
var manyErrorsInTab = wpcf7.configValidator.manyErrorsInTab
.replace( '%d', errorCount[ tab.replace( '-', '_' ) ] );
$tabPanelError.append( manyErrorsInTab );
} else {
$tabPanelError.append( wpcf7.configValidator.oneErrorInTab );
}
}
} );
$( '#misc-publishing-actions .misc-pub-section.config-error' ).remove();
if ( errorCount.total ) {
var $warning = $( '<div></div>' )
.addClass( 'misc-pub-section config-error' )
.append( wpcf7.iconInCircle( '!' ) );
if ( 1 < errorCount.total ) {
$warning.append(
wpcf7.configValidator.manyErrors.replace( '%d', errorCount.total )
);
} else {
$warning.append( wpcf7.configValidator.oneError );
}
$warning.append( '<br />' ).append(
$( '<a></a>' )
.attr( 'href', wpcf7.configValidator.docUrl )
.text( wpcf7.configValidator.howToCorrect )
);
$( '#misc-publishing-actions' ).append( $warning );
}
};
/**
* Copied from wptitlehint() in wp-admin/js/post.js
*/
wpcf7.titleHint = function() {
var $title = $( '#title' );
var $titleprompt = $( '#title-prompt-text' );
if ( '' === $title.val() ) {
$titleprompt.removeClass( 'screen-reader-text' );
}
$titleprompt.click( function() {
$( this ).addClass( 'screen-reader-text' );
$title.focus();
} );
$title.blur( function() {
if ( '' === $(this).val() ) {
$titleprompt.removeClass( 'screen-reader-text' );
}
} ).focus( function() {
$titleprompt.addClass( 'screen-reader-text' );
} ).keydown( function( e ) {
$titleprompt.addClass( 'screen-reader-text' );
$( this ).unbind( e );
} );
};
wpcf7.iconInCircle = function( icon ) {
var $span = $( '<span class="icon-in-circle" aria-hidden="true"></span>' );
return $span.text( icon );
};
wpcf7.apiSettings.getRoute = function( path ) {
var url = wpcf7.apiSettings.root;
url = url.replace(
wpcf7.apiSettings.namespace,
wpcf7.apiSettings.namespace + path );
return url;
};
} )( jQuery );
( function( $ ) {
'use strict';
if ( typeof wpcf7 === 'undefined' || wpcf7 === null ) {
return;
}
wpcf7.taggen = {};
$( function() {
$( 'form.tag-generator-panel' ).each( function() {
wpcf7.taggen.update( $( this ) );
} );
} );
$( 'form.tag-generator-panel' ).submit( function() {
return false;
} );
$( 'form.tag-generator-panel .control-box :input' ).change( function() {
var $form = $( this ).closest( 'form.tag-generator-panel' );
wpcf7.taggen.normalize( $( this ) );
wpcf7.taggen.update( $form );
} );
$( 'input.insert-tag' ).click( function() {
var $form = $( this ).closest( 'form.tag-generator-panel' );
var tag = $form.find( 'input.tag' ).val();
wpcf7.taggen.insert( tag );
tb_remove(); // close thickbox
return false;
} );
wpcf7.taggen.update = function( $form ) {
var id = $form.attr( 'data-id' );
var name = '';
var name_fields = $form.find( 'input[name="name"]' );
if ( name_fields.length ) {
name = name_fields.val();
if ( '' === name ) {
name = id + '-' + Math.floor( Math.random() * 1000 );
name_fields.val( name );
}
}
if ( $.isFunction( wpcf7.taggen.update[ id ] ) ) {
return wpcf7.taggen.update[ id ].call( this, $form );
}
$form.find( 'input.tag' ).each( function() {
var tag_type = $( this ).attr( 'name' );
if ( $form.find( ':input[name="tagtype"]' ).length ) {
tag_type = $form.find( ':input[name="tagtype"]' ).val();
}
if ( $form.find( ':input[name="required"]' ).is( ':checked' ) ) {
tag_type += '*';
}
var components = wpcf7.taggen.compose( tag_type, $form );
$( this ).val( components );
} );
$form.find( 'span.mail-tag' ).text( '[' + name + ']' );
$form.find( 'input.mail-tag' ).each( function() {
$( this ).val( '[' + name + ']' );
} );
};
wpcf7.taggen.update.captcha = function( $form ) {
var captchac = wpcf7.taggen.compose( 'captchac', $form );
var captchar = wpcf7.taggen.compose( 'captchar', $form );
$form.find( 'input.tag' ).val( captchac + ' ' + captchar );
};
wpcf7.taggen.compose = function( tagType, $form ) {
var name = $form.find( 'input[name="name"]' ).val();
var scope = $form.find( '.scope.' + tagType );
if ( ! scope.length ) {
scope = $form;
}
var options = [];
scope.find( 'input.option' ).not( ':checkbox,:radio' ).each( function( i ) {
var val = $( this ).val();
if ( ! val ) {
return;
}
if ( $( this ).hasClass( 'filetype' ) ) {
val = val.split( /[,|\s]+/ ).join( '|' );
}
if ( $( this ).hasClass( 'color' ) ) {
val = '#' + val;
}
if ( 'class' == $( this ).attr( 'name' ) ) {
$.each( val.split( ' ' ), function( i, n ) {
options.push( 'class:' + n );
} );
} else {
options.push( $( this ).attr( 'name' ) + ':' + val );
}
} );
scope.find( 'input:checkbox.option' ).each( function( i ) {
if ( $( this ).is( ':checked' ) ) {
options.push( $( this ).attr( 'name' ) );
}
} );
scope.find( 'input:radio.option' ).each( function( i ) {
if ( $( this ).is( ':checked' ) && ! $( this ).hasClass( 'default' ) ) {
options.push( $( this ).attr( 'name' ) + ':' + $( this ).val() );
}
} );
if ( 'radio' == tagType ) {
options.push( 'default:1' );
}
options = ( options.length > 0 ) ? options.join( ' ' ) : '';
var value = '';
if ( scope.find( ':input[name="values"]' ).val() ) {
$.each(
scope.find( ':input[name="values"]' ).val().split( "\n" ),
function( i, n ) {
value += ' "' + n.replace( /["]/g, '&quot;' ) + '"';
}
);
}
var components = [];
$.each( [ tagType, name, options, value ], function( i, v ) {
v = $.trim( v );
if ( '' != v ) {
components.push( v );
}
} );
components = $.trim( components.join( ' ' ) );
components = '[' + components + ']';
var content = scope.find( ':input[name="content"]' ).val();
content = $.trim( content );
if ( content ) {
components += ' ' + content + ' [/' + tagType + ']';
}
return components;
};
wpcf7.taggen.normalize = function( $input ) {
var val = $input.val();
if ( $input.is( 'input[name="name"]' ) ) {
val = val.replace( /[^0-9a-zA-Z:._-]/g, '' ).replace( /^[^a-zA-Z]+/, '' );
}
if ( $input.is( '.numeric' ) ) {
val = val.replace( /[^0-9.-]/g, '' );
}
if ( $input.is( '.idvalue' ) ) {
val = val.replace( /[^-0-9a-zA-Z_]/g, '' );
}
if ( $input.is( '.classvalue' ) ) {
val = $.map( val.split( ' ' ), function( n ) {
return n.replace( /[^-0-9a-zA-Z_]/g, '' );
} ).join( ' ' );
val = $.trim( val.replace( /\s+/g, ' ' ) );
}
if ( $input.is( '.color' ) ) {
val = val.replace( /[^0-9a-fA-F]/g, '' );
}
if ( $input.is( '.filesize' ) ) {
val = val.replace( /[^0-9kKmMbB]/g, '' );
}
if ( $input.is( '.filetype' ) ) {
val = val.replace( /[^0-9a-zA-Z.,|\s]/g, '' );
}
if ( $input.is( '.date' ) ) {
// 'yyyy-mm-dd' ISO 8601 format
if ( ! val.match( /^\d{4}-\d{2}-\d{2}$/ ) ) {
val = '';
}
}
if ( $input.is( ':input[name="values"]' ) ) {
val = $.trim( val );
}
$input.val( val );
if ( $input.is( ':checkbox.exclusive' ) ) {
wpcf7.taggen.exclusiveCheckbox( $input );
}
};
wpcf7.taggen.exclusiveCheckbox = function( $cb ) {
if ( $cb.is( ':checked' ) ) {
$cb.siblings( ':checkbox.exclusive' ).prop( 'checked', false );
}
};
wpcf7.taggen.insert = function( content ) {
$( 'textarea#wpcf7-form' ).each( function() {
this.focus();
if ( document.selection ) { // IE
var selection = document.selection.createRange();
selection.text = content;
} else if ( this.selectionEnd || 0 === this.selectionEnd ) {
var val = $( this ).val();
var end = this.selectionEnd;
$( this ).val( val.substring( 0, end ) +
content + val.substring( end, val.length ) );
this.selectionStart = end + content.length;
this.selectionEnd = end + content.length;
} else {
$( this ).val( $( this ).val() + content );
}
this.focus();
} );
};
} )( jQuery );
<?php
add_filter( 'map_meta_cap', 'wpcf7_map_meta_cap', 10, 4 );
function wpcf7_map_meta_cap( $caps, $cap, $user_id, $args ) {
$meta_caps = array(
'wpcf7_edit_contact_form' => WPCF7_ADMIN_READ_WRITE_CAPABILITY,
'wpcf7_edit_contact_forms' => WPCF7_ADMIN_READ_WRITE_CAPABILITY,
'wpcf7_read_contact_form' => WPCF7_ADMIN_READ_CAPABILITY,
'wpcf7_read_contact_forms' => WPCF7_ADMIN_READ_CAPABILITY,
'wpcf7_delete_contact_form' => WPCF7_ADMIN_READ_WRITE_CAPABILITY,
'wpcf7_delete_contact_forms' => WPCF7_ADMIN_READ_WRITE_CAPABILITY,
'wpcf7_manage_integration' => 'manage_options',
'wpcf7_submit' => 'read',
);
$meta_caps = apply_filters( 'wpcf7_map_meta_cap', $meta_caps );
$caps = array_diff( $caps, array_keys( $meta_caps ) );
if ( isset( $meta_caps[$cap] ) ) {
$caps[] = $meta_caps[$cap];
}
return $caps;
}
<?php
function wpcf7_contact_form( $id ) {
return WPCF7_ContactForm::get_instance( $id );
}
function wpcf7_get_contact_form_by_old_id( $old_id ) {
global $wpdb;
$q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_old_cf7_unit_id'"
. $wpdb->prepare( " AND meta_value = %d", $old_id );
if ( $new_id = $wpdb->get_var( $q ) ) {
return wpcf7_contact_form( $new_id );
}
}
function wpcf7_get_contact_form_by_title( $title ) {
$page = get_page_by_title( $title, OBJECT, WPCF7_ContactForm::post_type );
if ( $page ) {
return wpcf7_contact_form( $page->ID );
}
return null;
}
function wpcf7_get_current_contact_form() {
if ( $current = WPCF7_ContactForm::get_current() ) {
return $current;
}
}
function wpcf7_is_posted() {
if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
return false;
}
return $contact_form->is_posted();
}
function wpcf7_get_hangover( $name, $default = null ) {
if ( ! wpcf7_is_posted() ) {
return $default;
}
$submission = WPCF7_Submission::get_instance();
if ( ! $submission
or $submission->is( 'mail_sent' ) ) {
return $default;
}
return isset( $_POST[$name] ) ? wp_unslash( $_POST[$name] ) : $default;
}
function wpcf7_get_validation_error( $name ) {
if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
return '';
}
return $contact_form->validation_error( $name );
}
function wpcf7_get_message( $status ) {
if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
return '';
}
return $contact_form->message( $status );
}
function wpcf7_form_controls_class( $type, $default = '' ) {
$type = trim( $type );
$default = array_filter( explode( ' ', $default ) );
$classes = array_merge( array( 'wpcf7-form-control' ), $default );
$typebase = rtrim( $type, '*' );
$required = ( '*' == substr( $type, -1 ) );
$classes[] = 'wpcf7-' . $typebase;
if ( $required ) {
$classes[] = 'wpcf7-validates-as-required';
}
$classes = array_unique( $classes );
return implode( ' ', $classes );
}
function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) {
if ( is_feed() ) {
return '[contact-form-7]';
}
if ( 'contact-form-7' == $code ) {
$atts = shortcode_atts(
array(
'id' => 0,
'title' => '',
'html_id' => '',
'html_name' => '',
'html_class' => '',
'output' => 'form',
),
$atts, 'wpcf7'
);
$id = (int) $atts['id'];
$title = trim( $atts['title'] );
if ( ! $contact_form = wpcf7_contact_form( $id ) ) {
$contact_form = wpcf7_get_contact_form_by_title( $title );
}
} else {
if ( is_string( $atts ) ) {
$atts = explode( ' ', $atts, 2 );
}
$id = (int) array_shift( $atts );
$contact_form = wpcf7_get_contact_form_by_old_id( $id );
}
if ( ! $contact_form ) {
return '[contact-form-7 404 "Not Found"]';
}
return $contact_form->form_html( $atts );
}
function wpcf7_save_contact_form( $args = '', $context = 'save' ) {
$args = wp_parse_args( $args, array(
'id' => -1,
'title' => null,
'locale' => null,
'form' => null,
'mail' => null,
'mail_2' => null,
'messages' => null,
'additional_settings' => null,
) );
$args = wp_unslash( $args );
$args['id'] = (int) $args['id'];
if ( -1 == $args['id'] ) {
$contact_form = WPCF7_ContactForm::get_template();
} else {
$contact_form = wpcf7_contact_form( $args['id'] );
}
if ( empty( $contact_form ) ) {
return false;
}
if ( null !== $args['title'] ) {
$contact_form->set_title( $args['title'] );
}
if ( null !== $args['locale'] ) {
$contact_form->set_locale( $args['locale'] );
}
$properties = $contact_form->get_properties();
$properties['form'] = wpcf7_sanitize_form(
$args['form'], $properties['form'] );
$properties['mail'] = wpcf7_sanitize_mail(
$args['mail'], $properties['mail'] );
$properties['mail']['active'] = true;
$properties['mail_2'] = wpcf7_sanitize_mail(
$args['mail_2'], $properties['mail_2'] );
$properties['messages'] = wpcf7_sanitize_messages(
$args['messages'], $properties['messages'] );
$properties['additional_settings'] = wpcf7_sanitize_additional_settings(
$args['additional_settings'], $properties['additional_settings'] );
$contact_form->set_properties( $properties );
do_action( 'wpcf7_save_contact_form', $contact_form, $args, $context );
if ( 'save' == $context ) {
$contact_form->save();
}
return $contact_form;
}
function wpcf7_sanitize_form( $input, $default = '' ) {
if ( null === $input ) {
return $default;
}
$output = trim( $input );
return $output;
}
function wpcf7_sanitize_mail( $input, $defaults = array() ) {
$input = wp_parse_args( $input, array(
'active' => false,
'subject' => '',
'sender' => '',
'recipient' => '',
'body' => '',
'additional_headers' => '',
'attachments' => '',
'use_html' => false,
'exclude_blank' => false,
) );
$input = wp_parse_args( $input, $defaults );
$output = array();
$output['active'] = (bool) $input['active'];
$output['subject'] = trim( $input['subject'] );
$output['sender'] = trim( $input['sender'] );
$output['recipient'] = trim( $input['recipient'] );
$output['body'] = trim( $input['body'] );
$output['additional_headers'] = '';
$headers = str_replace( "\r\n", "\n", $input['additional_headers'] );
$headers = explode( "\n", $headers );
foreach ( $headers as $header ) {
$header = trim( $header );
if ( '' !== $header ) {
$output['additional_headers'] .= $header . "\n";
}
}
$output['additional_headers'] = trim( $output['additional_headers'] );
$output['attachments'] = trim( $input['attachments'] );
$output['use_html'] = (bool) $input['use_html'];
$output['exclude_blank'] = (bool) $input['exclude_blank'];
return $output;
}
function wpcf7_sanitize_messages( $input, $defaults = array() ) {
$output = array();
foreach ( wpcf7_messages() as $key => $val ) {
if ( isset( $input[$key] ) ) {
$output[$key] = trim( $input[$key] );
} elseif ( isset( $defaults[$key] ) ) {
$output[$key] = $defaults[$key];
}
}
return $output;
}
function wpcf7_sanitize_additional_settings( $input, $default = '' ) {
if ( null === $input ) {
return $default;
}
$output = trim( $input );
return $output;
}
<?php
class WPCF7_ContactFormTemplate {
public static function get_default( $prop = 'form' ) {
if ( 'form' == $prop ) {
$template = self::form();
} elseif ( 'mail' == $prop ) {
$template = self::mail();
} elseif ( 'mail_2' == $prop ) {
$template = self::mail_2();
} elseif ( 'messages' == $prop ) {
$template = self::messages();
} else {
$template = null;
}
return apply_filters( 'wpcf7_default_template', $template, $prop );
}
public static function form() {
$template = sprintf(
'
<label> %2$s %1$s
[text* your-name] </label>
<label> %3$s %1$s
[email* your-email] </label>
<label> %4$s
[text your-subject] </label>
<label> %5$s
[textarea your-message] </label>
[submit "%6$s"]',
__( '(required)', 'contact-form-7' ),
__( 'Your Name', 'contact-form-7' ),
__( 'Your Email', 'contact-form-7' ),
__( 'Subject', 'contact-form-7' ),
__( 'Your Message', 'contact-form-7' ),
__( 'Send', 'contact-form-7' ) );
return trim( $template );
}
public static function mail() {
$template = array(
'subject' =>
/* translators: 1: blog name, 2: [your-subject] */
sprintf(
_x( '%1$s "%2$s"', 'mail subject', 'contact-form-7' ),
get_bloginfo( 'name' ), '[your-subject]' ),
'sender' => sprintf( '%s <%s>',
get_bloginfo( 'name' ), self::from_email() ),
'body' =>
/* translators: %s: [your-name] <[your-email]> */
sprintf( __( 'From: %s', 'contact-form-7' ),
'[your-name] <[your-email]>' ) . "\n"
/* translators: %s: [your-subject] */
. sprintf( __( 'Subject: %s', 'contact-form-7' ),
'[your-subject]' ) . "\n\n"
. __( 'Message Body:', 'contact-form-7' )
. "\n" . '[your-message]' . "\n\n"
. '-- ' . "\n"
/* translators: 1: blog name, 2: blog URL */
. sprintf(
__( 'This e-mail was sent from a contact form on %1$s (%2$s)', 'contact-form-7' ),
get_bloginfo( 'name' ),
get_bloginfo( 'url' ) ),
'recipient' => get_option( 'admin_email' ),
'additional_headers' => 'Reply-To: [your-email]',
'attachments' => '',
'use_html' => 0,
'exclude_blank' => 0,
);
return $template;
}
public static function mail_2() {
$template = array(
'active' => false,
'subject' =>
/* translators: 1: blog name, 2: [your-subject] */
sprintf(
_x( '%1$s "%2$s"', 'mail subject', 'contact-form-7' ),
get_bloginfo( 'name' ), '[your-subject]' ),
'sender' => sprintf( '%s <%s>',
get_bloginfo( 'name' ), self::from_email() ),
'body' =>
__( 'Message Body:', 'contact-form-7' )
. "\n" . '[your-message]' . "\n\n"
. '-- ' . "\n"
/* translators: 1: blog name, 2: blog URL */
. sprintf(
__( 'This e-mail was sent from a contact form on %1$s (%2$s)', 'contact-form-7' ),
get_bloginfo( 'name' ),
get_bloginfo( 'url' ) ),
'recipient' => '[your-email]',
'additional_headers' => sprintf( 'Reply-To: %s',
get_option( 'admin_email' ) ),
'attachments' => '',
'use_html' => 0,
'exclude_blank' => 0,
);
return $template;
}
public static function from_email() {
$admin_email = get_option( 'admin_email' );
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
if ( wpcf7_is_localhost() ) {
return $admin_email;
}
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
$sitename = substr( $sitename, 4 );
}
if ( strpbrk( $admin_email, '@' ) == '@' . $sitename ) {
return $admin_email;
}
return 'wordpress@' . $sitename;
}
public static function messages() {
$messages = array();
foreach ( wpcf7_messages() as $key => $arr ) {
$messages[$key] = $arr['default'];
}
return $messages;
}
}
function wpcf7_messages() {
$messages = array(
'mail_sent_ok' => array(
'description'
=> __( "Sender's message was sent successfully", 'contact-form-7' ),
'default'
=> __( "Thank you for your message. It has been sent.", 'contact-form-7' ),
),
'mail_sent_ng' => array(
'description'
=> __( "Sender's message failed to send", 'contact-form-7' ),
'default'
=> __( "There was an error trying to send your message. Please try again later.", 'contact-form-7' ),
),
'validation_error' => array(
'description'
=> __( "Validation errors occurred", 'contact-form-7' ),
'default'
=> __( "One or more fields have an error. Please check and try again.", 'contact-form-7' ),
),
'spam' => array(
'description'
=> __( "Submission was referred to as spam", 'contact-form-7' ),
'default'
=> __( "There was an error trying to send your message. Please try again later.", 'contact-form-7' ),
),
'accept_terms' => array(
'description'
=> __( "There are terms that the sender must accept", 'contact-form-7' ),
'default'
=> __( "You must accept the terms and conditions before sending your message.", 'contact-form-7' ),
),
'invalid_required' => array(
'description'
=> __( "There is a field that the sender must fill in", 'contact-form-7' ),
'default'
=> __( "The field is required.", 'contact-form-7' ),
),
'invalid_too_long' => array(
'description'
=> __( "There is a field with input that is longer than the maximum allowed length", 'contact-form-7' ),
'default'
=> __( "The field is too long.", 'contact-form-7' ),
),
'invalid_too_short' => array(
'description'
=> __( "There is a field with input that is shorter than the minimum allowed length", 'contact-form-7' ),
'default'
=> __( "The field is too short.", 'contact-form-7' ),
)
);
return apply_filters( 'wpcf7_messages', $messages );
}
<?php
add_action( 'parse_request', 'wpcf7_control_init', 20, 0 );
function wpcf7_control_init() {
if ( WPCF7_Submission::is_restful() ) {
return;
}
if ( isset( $_POST['_wpcf7'] ) ) {
$contact_form = wpcf7_contact_form( (int) $_POST['_wpcf7'] );
if ( $contact_form ) {
$contact_form->submit();
}
}
}
add_action( 'wp_enqueue_scripts', 'wpcf7_do_enqueue_scripts', 10, 0 );
function wpcf7_do_enqueue_scripts() {
if ( wpcf7_load_js() ) {
wpcf7_enqueue_scripts();
}
if ( wpcf7_load_css() ) {
wpcf7_enqueue_styles();
}
}
function wpcf7_enqueue_scripts() {
$in_footer = true;
if ( 'header' === wpcf7_load_js() ) {
$in_footer = false;
}
wp_enqueue_script( 'contact-form-7',
wpcf7_plugin_url( 'includes/js/scripts.js' ),
array( 'jquery' ), WPCF7_VERSION, $in_footer );
$wpcf7 = array(
'apiSettings' => array(
'root' => esc_url_raw( rest_url( 'contact-form-7/v1' ) ),
'namespace' => 'contact-form-7/v1',
),
);
if ( defined( 'WP_CACHE' ) and WP_CACHE ) {
$wpcf7['cached'] = 1;
}
if ( wpcf7_support_html5_fallback() ) {
$wpcf7['jqueryUi'] = 1;
}
wp_localize_script( 'contact-form-7', 'wpcf7', $wpcf7 );
do_action( 'wpcf7_enqueue_scripts' );
}
function wpcf7_script_is() {
return wp_script_is( 'contact-form-7' );
}
function wpcf7_enqueue_styles() {
wp_enqueue_style( 'contact-form-7',
wpcf7_plugin_url( 'includes/css/styles.css' ),
array(), WPCF7_VERSION, 'all' );
if ( wpcf7_is_rtl() ) {
wp_enqueue_style( 'contact-form-7-rtl',
wpcf7_plugin_url( 'includes/css/styles-rtl.css' ),
array(), WPCF7_VERSION, 'all' );
}
do_action( 'wpcf7_enqueue_styles' );
}
function wpcf7_style_is() {
return wp_style_is( 'contact-form-7' );
}
/* HTML5 Fallback */
add_action( 'wp_enqueue_scripts', 'wpcf7_html5_fallback', 20, 0 );
function wpcf7_html5_fallback() {
if ( ! wpcf7_support_html5_fallback() ) {
return;
}
if ( wpcf7_script_is() ) {
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'jquery-ui-spinner' );
}
if ( wpcf7_style_is() ) {
wp_enqueue_style( 'jquery-ui-smoothness',
wpcf7_plugin_url(
'includes/js/jquery-ui/themes/smoothness/jquery-ui.min.css' ),
array(), '1.11.4', 'screen' );
}
}
span.wpcf7-not-valid-tip {
direction: rtl;
}
.use-floating-validation-tip span.wpcf7-not-valid-tip {
left: auto;
right: 20%;
}
span.wpcf7-list-item {
margin: 0 1em 0 0;
}
div.wpcf7 {
margin: 0;
padding: 0;
}
div.wpcf7 .screen-reader-response {
position: absolute;
overflow: hidden;
clip: rect(1px, 1px, 1px, 1px);
height: 1px;
width: 1px;
margin: 0;
padding: 0;
border: 0;
}
div.wpcf7-response-output {
margin: 2em 0.5em 1em;
padding: 0.2em 1em;
border: 2px solid #ff0000;
}
div.wpcf7-mail-sent-ok {
border: 2px solid #398f14;
}
div.wpcf7-mail-sent-ng,
div.wpcf7-aborted {
border: 2px solid #ff0000;
}
div.wpcf7-spam-blocked {
border: 2px solid #ffa500;
}
div.wpcf7-validation-errors,
div.wpcf7-acceptance-missing {
border: 2px solid #f7e700;
}
.wpcf7-form-control-wrap {
position: relative;
}
span.wpcf7-not-valid-tip {
color: #f00;
font-size: 1em;
font-weight: normal;
display: block;
}
.use-floating-validation-tip span.wpcf7-not-valid-tip {
position: absolute;
top: 20%;
left: 20%;
z-index: 100;
border: 1px solid #ff0000;
background: #fff;
padding: .2em .8em;
}
span.wpcf7-list-item {
display: inline-block;
margin: 0 0 0 1em;
}
span.wpcf7-list-item-label::before,
span.wpcf7-list-item-label::after {
content: " ";
}
.wpcf7-display-none {
display: none;
}
div.wpcf7 .ajax-loader {
visibility: hidden;
display: inline-block;
background-image: url('../../images/ajax-loader.gif');
width: 16px;
height: 16px;
border: none;
padding: 0;
margin: 0 0 0 4px;
vertical-align: middle;
}
div.wpcf7 .ajax-loader.is-active {
visibility: visible;
}
div.wpcf7 div.ajax-error {
display: none;
}
div.wpcf7 .placeheld {
color: #888;
}
div.wpcf7 input[type="file"] {
cursor: pointer;
}
div.wpcf7 input[type="file"]:disabled {
cursor: default;
}
div.wpcf7 .wpcf7-submit:disabled {
cursor: not-allowed;
}
<?php
class WPCF7_FormTag implements ArrayAccess {
public $type;
public $basetype;
public $name = '';
public $options = array();
public $raw_values = array();
public $values = array();
public $pipes;
public $labels = array();
public $attr = '';
public $content = '';
public function __construct( $tag = array() ) {
if ( is_array( $tag )
or $tag instanceof self ) {
foreach ( $tag as $key => $value ) {
if ( property_exists( __CLASS__, $key ) ) {
$this->{$key} = $value;
}
}
}
}
public function is_required() {
return ( '*' == substr( $this->type, -1 ) );
}
public function has_option( $opt ) {
$pattern = sprintf( '/^%s(:.+)?$/i', preg_quote( $opt, '/' ) );
return (bool) preg_grep( $pattern, $this->options );
}
public function get_option( $opt, $pattern = '', $single = false ) {
$preset_patterns = array(
'date' => '([0-9]{4}-[0-9]{2}-[0-9]{2}|today(.*))',
'int' => '[0-9]+',
'signed_int' => '-?[0-9]+',
'class' => '[-0-9a-zA-Z_]+',
'id' => '[-0-9a-zA-Z_]+',
);
if ( isset( $preset_patterns[$pattern] ) ) {
$pattern = $preset_patterns[$pattern];
}
if ( '' == $pattern ) {
$pattern = '.+';
}
$pattern = sprintf( '/^%s:%s$/i', preg_quote( $opt, '/' ), $pattern );
if ( $single ) {
$matches = $this->get_first_match_option( $pattern );
if ( ! $matches ) {
return false;
}
return substr( $matches[0], strlen( $opt ) + 1 );
} else {
$matches_a = $this->get_all_match_options( $pattern );
if ( ! $matches_a ) {
return false;
}
$results = array();
foreach ( $matches_a as $matches ) {
$results[] = substr( $matches[0], strlen( $opt ) + 1 );
}
return $results;
}
}
public function get_id_option() {
return $this->get_option( 'id', 'id', true );
}
public function get_class_option( $default = '' ) {
if ( is_string( $default ) ) {
$default = explode( ' ', $default );
}
$options = array_merge(
(array) $default,
(array) $this->get_option( 'class', 'class' ) );
$options = array_filter( array_unique( $options ) );
return implode( ' ', $options );
}
public function get_size_option( $default = '' ) {
$option = $this->get_option( 'size', 'int', true );
if ( $option ) {
return $option;
}
$matches_a = $this->get_all_match_options( '%^([0-9]*)/[0-9]*$%' );
foreach ( (array) $matches_a as $matches ) {
if ( isset( $matches[1] )
and '' !== $matches[1] ) {
return $matches[1];
}
}
return $default;
}
public function get_maxlength_option( $default = '' ) {
$option = $this->get_option( 'maxlength', 'int', true );
if ( $option ) {
return $option;
}
$matches_a = $this->get_all_match_options(
'%^(?:[0-9]*x?[0-9]*)?/([0-9]+)$%' );
foreach ( (array) $matches_a as $matches ) {
if ( isset( $matches[1] ) && '' !== $matches[1] ) {
return $matches[1];
}
}
return $default;
}
public function get_minlength_option( $default = '' ) {
$option = $this->get_option( 'minlength', 'int', true );
if ( $option ) {
return $option;
} else {
return $default;
}
}
public function get_cols_option( $default = '' ) {
$option = $this->get_option( 'cols', 'int', true );
if ( $option ) {
return $option;
}
$matches_a = $this->get_all_match_options(
'%^([0-9]*)x([0-9]*)(?:/[0-9]+)?$%' );
foreach ( (array) $matches_a as $matches ) {
if ( isset( $matches[1] ) && '' !== $matches[1] ) {
return $matches[1];
}
}
return $default;
}
public function get_rows_option( $default = '' ) {
$option = $this->get_option( 'rows', 'int', true );
if ( $option ) {
return $option;
}
$matches_a = $this->get_all_match_options(
'%^([0-9]*)x([0-9]*)(?:/[0-9]+)?$%' );
foreach ( (array) $matches_a as $matches ) {
if ( isset( $matches[2] )
and '' !== $matches[2] ) {
return $matches[2];
}
}
return $default;
}
public function get_date_option( $opt ) {
$option = $this->get_option( $opt, 'date', true );
if ( preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $option ) ) {
return $option;
}
if ( preg_match( '/^today(?:([+-][0-9]+)([a-z]*))?/', $option, $matches ) ) {
$number = isset( $matches[1] ) ? (int) $matches[1] : 0;
$unit = isset( $matches[2] ) ? $matches[2] : '';
if ( ! preg_match( '/^(day|month|year|week)s?$/', $unit ) ) {
$unit = 'days';
}
$date = gmdate( 'Y-m-d',
strtotime( sprintf( 'today %1$s %2$s', $number, $unit ) ) );
return $date;
}
return false;
}
public function get_default_option( $default = '', $args = '' ) {
$args = wp_parse_args( $args, array(
'multiple' => false,
'shifted' => false,
) );
$options = (array) $this->get_option( 'default' );
$values = array();
if ( empty( $options ) ) {
return $args['multiple'] ? $values : $default;
}
foreach ( $options as $opt ) {
$opt = sanitize_key( $opt );
if ( 'user_' == substr( $opt, 0, 5 )
and is_user_logged_in() ) {
$primary_props = array( 'user_login', 'user_email', 'user_url' );
$opt = in_array( $opt, $primary_props ) ? $opt : substr( $opt, 5 );
$user = wp_get_current_user();
$user_prop = $user->get( $opt );
if ( ! empty( $user_prop ) ) {
if ( $args['multiple'] ) {
$values[] = $user_prop;
} else {
return $user_prop;
}
}
} elseif ( 'post_meta' == $opt and in_the_loop() ) {
if ( $args['multiple'] ) {
$values = array_merge( $values,
get_post_meta( get_the_ID(), $this->name ) );
} else {
$val = (string) get_post_meta( get_the_ID(), $this->name, true );
if ( strlen( $val ) ) {
return $val;
}
}
} elseif ( 'get' == $opt and isset( $_GET[$this->name] ) ) {
$vals = (array) $_GET[$this->name];
$vals = array_map( 'wpcf7_sanitize_query_var', $vals );
if ( $args['multiple'] ) {
$values = array_merge( $values, $vals );
} else {
$val = isset( $vals[0] ) ? (string) $vals[0] : '';
if ( strlen( $val ) ) {
return $val;
}
}
} elseif ( 'post' == $opt and isset( $_POST[$this->name] ) ) {
$vals = (array) $_POST[$this->name];
$vals = array_map( 'wpcf7_sanitize_query_var', $vals );
if ( $args['multiple'] ) {
$values = array_merge( $values, $vals );
} else {
$val = isset( $vals[0] ) ? (string) $vals[0] : '';
if ( strlen( $val ) ) {
return $val;
}
}
} elseif ( 'shortcode_attr' == $opt ) {
if ( $contact_form = WPCF7_ContactForm::get_current() ) {
$val = $contact_form->shortcode_attr( $this->name );
if ( strlen( $val ) ) {
if ( $args['multiple'] ) {
$values[] = $val;
} else {
return $val;
}
}
}
} elseif ( preg_match( '/^[0-9_]+$/', $opt ) ) {
$nums = explode( '_', $opt );
foreach ( $nums as $num ) {
$num = absint( $num );
$num = $args['shifted'] ? $num : $num - 1;
if ( isset( $this->values[$num] ) ) {
if ( $args['multiple'] ) {
$values[] = $this->values[$num];
} else {
return $this->values[$num];
}
}
}
}
}
if ( $args['multiple'] ) {
$values = array_unique( $values );
return $values;
} else {
return $default;
}
}
public function get_data_option( $args = '' ) {
$options = (array) $this->get_option( 'data' );
return apply_filters( 'wpcf7_form_tag_data_option', null, $options, $args );
}
public function get_first_match_option( $pattern ) {
foreach( (array) $this->options as $option ) {
if ( preg_match( $pattern, $option, $matches ) ) {
return $matches;
}
}
return false;
}
public function get_all_match_options( $pattern ) {
$result = array();
foreach( (array) $this->options as $option ) {
if ( preg_match( $pattern, $option, $matches ) ) {
$result[] = $matches;
}
}
return $result;
}
public function offsetSet( $offset, $value ) {
if ( property_exists( __CLASS__, $offset ) ) {
$this->{$offset} = $value;
}
}
public function offsetGet( $offset ) {
if ( property_exists( __CLASS__, $offset ) ) {
return $this->{$offset};
}
return null;
}
public function offsetExists( $offset ) {
return property_exists( __CLASS__, $offset );
}
public function offsetUnset( $offset ) {
}
}
<?php
function wpcf7_add_form_tag( $tag, $func, $features = '' ) {
$manager = WPCF7_FormTagsManager::get_instance();
return $manager->add( $tag, $func, $features );
}
function wpcf7_remove_form_tag( $tag ) {
$manager = WPCF7_FormTagsManager::get_instance();
return $manager->remove( $tag );
}
function wpcf7_replace_all_form_tags( $content ) {
$manager = WPCF7_FormTagsManager::get_instance();
return $manager->replace_all( $content );
}
function wpcf7_scan_form_tags( $cond = null ) {
$contact_form = WPCF7_ContactForm::get_current();
if ( $contact_form ) {
return $contact_form->scan_form_tags( $cond );
}
return array();
}
function wpcf7_form_tag_supports( $tag, $feature ) {
$manager = WPCF7_FormTagsManager::get_instance();
return $manager->tag_type_supports( $tag, $feature );
}
class WPCF7_FormTagsManager {
private static $instance;
private $tag_types = array();
private $scanned_tags = null; // Tags scanned at the last time of scan()
private function __construct() {}
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
public function get_scanned_tags() {
return $this->scanned_tags;
}
public function add( $tag, $func, $features = '' ) {
if ( ! is_callable( $func ) ) {
return;
}
if ( true === $features ) { // for back-compat
$features = array( 'name-attr' => true );
}
$features = wp_parse_args( $features, array() );
$tags = array_filter( array_unique( (array) $tag ) );
foreach ( $tags as $tag ) {
$tag = $this->sanitize_tag_type( $tag );
if ( ! $this->tag_type_exists( $tag ) ) {
$this->tag_types[$tag] = array(
'function' => $func,
'features' => $features,
);
}
}
}
public function tag_type_exists( $tag ) {
return isset( $this->tag_types[$tag] );
}
public function tag_type_supports( $tag, $feature ) {
$feature = array_filter( (array) $feature );
if ( isset( $this->tag_types[$tag]['features'] ) ) {
return (bool) array_intersect(
array_keys( array_filter( $this->tag_types[$tag]['features'] ) ),
$feature );
}
return false;
}
public function collect_tag_types( $feature = null, $invert = false ) {
$tag_types = array_keys( $this->tag_types );
if ( empty( $feature ) ) {
return $tag_types;
}
$output = array();
foreach ( $tag_types as $tag ) {
if ( ! $invert && $this->tag_type_supports( $tag, $feature )
|| $invert && ! $this->tag_type_supports( $tag, $feature ) ) {
$output[] = $tag;
}
}
return $output;
}
private function sanitize_tag_type( $tag ) {
$tag = preg_replace( '/[^a-zA-Z0-9_*]+/', '_', $tag );
$tag = rtrim( $tag, '_' );
$tag = strtolower( $tag );
return $tag;
}
public function remove( $tag ) {
unset( $this->tag_types[$tag] );
}
public function normalize( $content ) {
if ( empty( $this->tag_types ) ) {
return $content;
}
$content = preg_replace_callback(
'/' . $this->tag_regex() . '/s',
array( $this, 'normalize_callback' ),
$content );
return $content;
}
private function normalize_callback( $m ) {
// allow [[foo]] syntax for escaping a tag
if ( $m[1] == '['
and $m[6] == ']' ) {
return $m[0];
}
$tag = $m[2];
$attr = trim( preg_replace( '/[\r\n\t ]+/', ' ', $m[3] ) );
$attr = strtr( $attr, array( '<' => '&lt;', '>' => '&gt;' ) );
$content = trim( $m[5] );
$content = str_replace( "\n", '<WPPreserveNewline />', $content );
$result = $m[1] . '[' . $tag
. ( $attr ? ' ' . $attr : '' )
. ( $m[4] ? ' ' . $m[4] : '' )
. ']'
. ( $content ? $content . '[/' . $tag . ']' : '' )
. $m[6];
return $result;
}
public function replace_all( $content ) {
return $this->scan( $content, true );
}
public function scan( $content, $replace = false ) {
$this->scanned_tags = array();
if ( empty( $this->tag_types ) ) {
if ( $replace ) {
return $content;
} else {
return $this->scanned_tags;
}
}
if ( $replace ) {
$content = preg_replace_callback(
'/' . $this->tag_regex() . '/s',
array( $this, 'replace_callback' ),
$content );
return $content;
} else {
preg_replace_callback(
'/' . $this->tag_regex() . '/s',
array( $this, 'scan_callback' ),
$content );
return $this->scanned_tags;
}
}
public function filter( $input, $cond ) {
if ( is_array( $input ) ) {
$tags = $input;
} elseif ( is_string( $input ) ) {
$tags = $this->scan( $input );
} else {
$tags = $this->scanned_tags;
}
if ( empty( $tags ) ) {
return array();
}
$cond = wp_parse_args( $cond, array(
'type' => array(),
'name' => array(),
'feature' => '',
) );
$type = array_filter( (array) $cond['type'] );
$name = array_filter( (array) $cond['name'] );
$feature = is_string( $cond['feature'] ) ? trim( $cond['feature'] ) : '';
if ( '!' == substr( $feature, 0, 1 ) ) {
$feature_negative = true;
$feature = trim( substr( $feature, 1 ) );
} else {
$feature_negative = false;
}
$output = array();
foreach ( $tags as $tag ) {
$tag = new WPCF7_FormTag( $tag );
if ( $type and ! in_array( $tag->type, $type, true ) ) {
continue;
}
if ( $name and ! in_array( $tag->name, $name, true ) ) {
continue;
}
if ( $feature ) {
if ( ! $this->tag_type_supports( $tag->type, $feature )
and ! $feature_negative ) {
continue;
} elseif ( $this->tag_type_supports( $tag->type, $feature )
and $feature_negative ) {
continue;
}
}
$output[] = $tag;
}
return $output;
}
private function tag_regex() {
$tagnames = array_keys( $this->tag_types );
$tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
return '(\[?)'
. '\[(' . $tagregexp . ')(?:[\r\n\t ](.*?))?(?:[\r\n\t ](\/))?\]'
. '(?:([^[]*?)\[\/\2\])?'
. '(\]?)';
}
private function replace_callback( $m ) {
return $this->scan_callback( $m, true );
}
private function scan_callback( $m, $replace = false ) {
// allow [[foo]] syntax for escaping a tag
if ( $m[1] == '['
and $m[6] == ']' ) {
return substr( $m[0], 1, -1 );
}
$tag = $m[2];
$attr = $this->parse_atts( $m[3] );
$scanned_tag = array(
'type' => $tag,
'basetype' => trim( $tag, '*' ),
'name' => '',
'options' => array(),
'raw_values' => array(),
'values' => array(),
'pipes' => null,
'labels' => array(),
'attr' => '',
'content' => '',
);
if ( is_array( $attr ) ) {
if ( is_array( $attr['options'] ) ) {
if ( $this->tag_type_supports( $tag, 'name-attr' )
and ! empty( $attr['options'] ) ) {
$scanned_tag['name'] = array_shift( $attr['options'] );
if ( ! wpcf7_is_name( $scanned_tag['name'] ) ) {
return $m[0]; // Invalid name is used. Ignore this tag.
}
}
$scanned_tag['options'] = (array) $attr['options'];
}
$scanned_tag['raw_values'] = (array) $attr['values'];
if ( WPCF7_USE_PIPE ) {
$pipes = new WPCF7_Pipes( $scanned_tag['raw_values'] );
$scanned_tag['values'] = $pipes->collect_befores();
$scanned_tag['pipes'] = $pipes;
} else {
$scanned_tag['values'] = $scanned_tag['raw_values'];
}
$scanned_tag['labels'] = $scanned_tag['values'];
} else {
$scanned_tag['attr'] = $attr;
}
$scanned_tag['values'] = array_map( 'trim', $scanned_tag['values'] );
$scanned_tag['labels'] = array_map( 'trim', $scanned_tag['labels'] );
$content = trim( $m[5] );
$content = preg_replace( "/<br[\r\n\t ]*\/?>$/m", '', $content );
$scanned_tag['content'] = $content;
$scanned_tag = apply_filters( 'wpcf7_form_tag', $scanned_tag, $replace );
$scanned_tag = new WPCF7_FormTag( $scanned_tag );
$this->scanned_tags[] = $scanned_tag;
if ( $replace ) {
$func = $this->tag_types[$tag]['function'];
return $m[1] . call_user_func( $func, $scanned_tag ) . $m[6];
} else {
return $m[0];
}
}
private function parse_atts( $text ) {
$atts = array( 'options' => array(), 'values' => array() );
$text = preg_replace( "/[\x{00a0}\x{200b}]+/u", " ", $text );
$text = stripcslashes( trim( $text ) );
$pattern = '%^([-+*=0-9a-zA-Z:.!?#$&@_/|\%\r\n\t ]*?)((?:[\r\n\t ]*"[^"]*"|[\r\n\t ]*\'[^\']*\')*)$%';
if ( preg_match( $pattern, $text, $match ) ) {
if ( ! empty( $match[1] ) ) {
$atts['options'] = preg_split( '/[\r\n\t ]+/', trim( $match[1] ) );
}
if ( ! empty( $match[2] ) ) {
preg_match_all( '/"[^"]*"|\'[^\']*\'/', $match[2], $matched_values );
$atts['values'] = wpcf7_strip_quote_deep( $matched_values[0] );
}
} else {
$atts = $text;
}
return $atts;
}
}
<?php
function wpcf7_plugin_path( $path = '' ) {
return path_join( WPCF7_PLUGIN_DIR, trim( $path, '/' ) );
}
function wpcf7_plugin_url( $path = '' ) {
$url = plugins_url( $path, WPCF7_PLUGIN );
if ( is_ssl()
and 'http:' == substr( $url, 0, 5 ) ) {
$url = 'https:' . substr( $url, 5 );
}
return $url;
}
function wpcf7_upload_dir( $type = false ) {
$uploads = wp_get_upload_dir();
$uploads = apply_filters( 'wpcf7_upload_dir', array(
'dir' => $uploads['basedir'],
'url' => $uploads['baseurl'],
) );
if ( 'dir' == $type ) {
return $uploads['dir'];
} if ( 'url' == $type ) {
return $uploads['url'];
}
return $uploads;
}
function wpcf7_verify_nonce( $nonce, $action = 'wp_rest' ) {
return wp_verify_nonce( $nonce, $action );
}
function wpcf7_create_nonce( $action = 'wp_rest' ) {
return wp_create_nonce( $action );
}
function wpcf7_blacklist_check( $target ) {
$mod_keys = trim( get_option( 'blacklist_keys' ) );
if ( empty( $mod_keys ) ) {
return false;
}
$words = explode( "\n", $mod_keys );
foreach ( (array) $words as $word ) {
$word = trim( $word );
if ( empty( $word )
or 256 < strlen( $word ) ) {
continue;
}
$pattern = sprintf( '#%s#i', preg_quote( $word, '#' ) );
if ( preg_match( $pattern, $target ) ) {
return true;
}
}
return false;
}
function wpcf7_array_flatten( $input ) {
if ( ! is_array( $input ) ) {
return array( $input );
}
$output = array();
foreach ( $input as $value ) {
$output = array_merge( $output, wpcf7_array_flatten( $value ) );
}
return $output;
}
function wpcf7_flat_join( $input ) {
$input = wpcf7_array_flatten( $input );
$output = array();
foreach ( (array) $input as $value ) {
$output[] = trim( (string) $value );
}
return implode( ', ', $output );
}
function wpcf7_support_html5() {
return (bool) apply_filters( 'wpcf7_support_html5', true );
}
function wpcf7_support_html5_fallback() {
return (bool) apply_filters( 'wpcf7_support_html5_fallback', false );
}
function wpcf7_use_really_simple_captcha() {
return apply_filters( 'wpcf7_use_really_simple_captcha',
WPCF7_USE_REALLY_SIMPLE_CAPTCHA );
}
function wpcf7_validate_configuration() {
return apply_filters( 'wpcf7_validate_configuration',
WPCF7_VALIDATE_CONFIGURATION );
}
function wpcf7_autop_or_not() {
return (bool) apply_filters( 'wpcf7_autop_or_not', WPCF7_AUTOP );
}
function wpcf7_load_js() {
return apply_filters( 'wpcf7_load_js', WPCF7_LOAD_JS );
}
function wpcf7_load_css() {
return apply_filters( 'wpcf7_load_css', WPCF7_LOAD_CSS );
}
function wpcf7_format_atts( $atts ) {
$html = '';
$prioritized_atts = array( 'type', 'name', 'value' );
foreach ( $prioritized_atts as $att ) {
if ( isset( $atts[$att] ) ) {
$value = trim( $atts[$att] );
$html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) );
unset( $atts[$att] );
}
}
foreach ( $atts as $key => $value ) {
$key = strtolower( trim( $key ) );
if ( ! preg_match( '/^[a-z_:][a-z_:.0-9-]*$/', $key ) ) {
continue;
}
$value = trim( $value );
if ( '' !== $value ) {
$html .= sprintf( ' %s="%s"', $key, esc_attr( $value ) );
}
}
$html = trim( $html );
return $html;
}
function wpcf7_link( $url, $anchor_text, $args = '' ) {
$defaults = array(
'id' => '',
'class' => '',
);
$args = wp_parse_args( $args, $defaults );
$args = array_intersect_key( $args, $defaults );
$atts = wpcf7_format_atts( $args );
$link = sprintf( '<a href="%1$s"%3$s>%2$s</a>',
esc_url( $url ),
esc_html( $anchor_text ),
$atts ? ( ' ' . $atts ) : '' );
return $link;
}
function wpcf7_get_request_uri() {
static $request_uri = '';
if ( empty( $request_uri ) ) {
$request_uri = add_query_arg( array() );
}
return esc_url_raw( $request_uri );
}
function wpcf7_register_post_types() {
if ( class_exists( 'WPCF7_ContactForm' ) ) {
WPCF7_ContactForm::register_post_type();
return true;
} else {
return false;
}
}
function wpcf7_version( $args = '' ) {
$defaults = array(
'limit' => -1,
'only_major' => false,
);
$args = wp_parse_args( $args, $defaults );
if ( $args['only_major'] ) {
$args['limit'] = 2;
}
$args['limit'] = (int) $args['limit'];
$ver = WPCF7_VERSION;
$ver = strtr( $ver, '_-+', '...' );
$ver = preg_replace( '/[^0-9.]+/', ".$0.", $ver );
$ver = preg_replace( '/[.]+/', ".", $ver );
$ver = trim( $ver, '.' );
$ver = explode( '.', $ver );
if ( -1 < $args['limit'] ) {
$ver = array_slice( $ver, 0, $args['limit'] );
}
$ver = implode( '.', $ver );
return $ver;
}
function wpcf7_version_grep( $version, array $input ) {
$pattern = '/^' . preg_quote( (string) $version, '/' ) . '(?:\.|$)/';
return preg_grep( $pattern, $input );
}
function wpcf7_enctype_value( $enctype ) {
$enctype = trim( $enctype );
if ( empty( $enctype ) ) {
return '';
}
$valid_enctypes = array(
'application/x-www-form-urlencoded',
'multipart/form-data',
'text/plain',
);
if ( in_array( $enctype, $valid_enctypes ) ) {
return $enctype;
}
$pattern = '%^enctype="(' . implode( '|', $valid_enctypes ) . ')"$%';
if ( preg_match( $pattern, $enctype, $matches ) ) {
return $matches[1]; // for back-compat
}
return '';
}
function wpcf7_rmdir_p( $dir ) {
if ( is_file( $dir ) ) {
$file = $dir;
if ( @unlink( $file ) ) {
return true;
}
$stat = stat( $file );
if ( @chmod( $file, $stat['mode'] | 0200 ) ) { // add write for owner
if ( @unlink( $file ) ) {
return true;
}
@chmod( $file, $stat['mode'] );
}
return false;
}
if ( ! is_dir( $dir ) ) {
return false;
}
if ( $handle = opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file == "."
or $file == ".." ) {
continue;
}
wpcf7_rmdir_p( path_join( $dir, $file ) );
}
closedir( $handle );
}
if ( false !== ( $files = scandir( $dir ) )
and ! array_diff( $files, array( '.', '..' ) ) ) {
return rmdir( $dir );
}
return false;
}
/* From _http_build_query in wp-includes/functions.php */
function wpcf7_build_query( $args, $key = '' ) {
$sep = '&';
$ret = array();
foreach ( (array) $args as $k => $v ) {
$k = urlencode( $k );
if ( ! empty( $key ) ) {
$k = $key . '%5B' . $k . '%5D';
}
if ( null === $v ) {
continue;
} elseif ( false === $v ) {
$v = '0';
}
if ( is_array( $v ) or is_object( $v ) ) {
array_push( $ret, wpcf7_build_query( $v, $k ) );
} else {
array_push( $ret, $k . '=' . urlencode( $v ) );
}
}
return implode( $sep, $ret );
}
/**
* Returns the number of code units in a string.
*
* @see http://www.w3.org/TR/html5/infrastructure.html#code-unit-length
*
* @return int|bool The number of code units, or false if mb_convert_encoding is not available.
*/
function wpcf7_count_code_units( $string ) {
static $use_mb = null;
if ( is_null( $use_mb ) ) {
$use_mb = function_exists( 'mb_convert_encoding' );
}
if ( ! $use_mb ) {
return false;
}
$string = (string) $string;
$string = str_replace( "\r\n", "\n", $string );
$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
if ( $encoding ) {
$string = mb_convert_encoding( $string, 'UTF-16', $encoding );
} else {
$string = mb_convert_encoding( $string, 'UTF-16', 'UTF-8' );
}
$byte_count = mb_strlen( $string, '8bit' );
return floor( $byte_count / 2 );
}
function wpcf7_is_localhost() {
$server_name = strtolower( $_SERVER['SERVER_NAME'] );
return in_array( $server_name, array( 'localhost', '127.0.0.1' ) );
}
function wpcf7_deprecated_function( $function, $version, $replacement ) {
$trigger_error = apply_filters( 'deprecated_function_trigger_error', true );
if ( WP_DEBUG and $trigger_error ) {
if ( function_exists( '__' ) ) {
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since Contact Form 7 version %2$s! Use %3$s instead.', 'contact-form-7' ), $function, $version, $replacement ) );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since Contact Form 7 version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
}
}
}
function wpcf7_log_remote_request( $url, $request, $response ) {
$log = sprintf(
/* translators: 1: response code, 2: message, 3: body, 4: URL */
__( 'HTTP Response: %1$s %2$s %3$s from %4$s', 'contact-form-7' ),
(int) wp_remote_retrieve_response_code( $response ),
wp_remote_retrieve_response_message( $response ),
wp_remote_retrieve_body( $response ),
$url
);
$log = apply_filters( 'wpcf7_log_remote_request',
$log, $url, $request, $response
);
if ( $log ) {
trigger_error( $log );
}
}
function wpcf7_anonymize_ip_addr( $ip_addr ) {
if ( ! function_exists( 'inet_ntop' )
or ! function_exists( 'inet_pton' ) ) {
return $ip_addr;
}
$packed = inet_pton( $ip_addr );
if ( false === $packed ) {
return $ip_addr;
}
if ( 4 == strlen( $packed ) ) { // IPv4
$mask = '255.255.255.0';
} elseif ( 16 == strlen( $packed ) ) { // IPv6
$mask = 'ffff:ffff:ffff:0000:0000:0000:0000:0000';
} else {
return $ip_addr;
}
return inet_ntop( $packed & inet_pton( $mask ) );
}
function wpcf7_is_file_path_in_content_dir( $path ) {
if ( 0 === strpos( realpath( $path ), realpath( WP_CONTENT_DIR ) ) ) {
return true;
}
if ( defined( 'UPLOADS' )
and 0 === strpos( realpath( $path ), realpath( ABSPATH . UPLOADS ) ) ) {
return true;
}
return false;
}
<?php
class WPCF7_Integration {
private static $instance;
private $services = array();
private $categories = array();
private function __construct() {}
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
public function add_service( $name, WPCF7_Service $service ) {
$name = sanitize_key( $name );
if ( empty( $name )
or isset( $this->services[$name] ) ) {
return false;
}
$this->services[$name] = $service;
}
public function add_category( $name, $title ) {
$name = sanitize_key( $name );
if ( empty( $name )
or isset( $this->categories[$name] ) ) {
return false;
}
$this->categories[$name] = $title;
}
public function service_exists( $name = '' ) {
if ( '' == $name ) {
return (bool) count( $this->services );
} else {
return isset( $this->services[$name] );
}
}
public function get_service( $name ) {
if ( $this->service_exists( $name ) ) {
return $this->services[$name];
} else {
return false;
}
}
public function list_services( $args = '' ) {
$args = wp_parse_args( $args, array(
'include' => array(),
) );
$singular = false;
$services = (array) $this->services;
if ( ! empty( $args['include'] ) ) {
$services = array_intersect_key( $services,
array_flip( (array) $args['include'] ) );
if ( 1 == count( $services ) ) {
$singular = true;
}
}
if ( empty( $services ) ) {
return;
}
$action = wpcf7_current_action();
foreach ( $services as $name => $service ) {
$cats = array_intersect_key( $this->categories,
array_flip( $service->get_categories() ) );
?>
<div class="card<?php echo $service->is_active() ? ' active' : ''; ?>" id="<?php echo esc_attr( $name ); ?>">
<?php $service->icon(); ?>
<h2 class="title"><?php echo esc_html( $service->get_title() ); ?></h2>
<div class="infobox">
<?php echo esc_html( implode( ', ', $cats ) ); ?>
<br />
<?php $service->link(); ?>
</div>
<br class="clear" />
<div class="inside">
<?php
if ( $singular ) {
$service->display( $action );
} else {
$service->display();
}
?>
</div>
</div>
<?php
}
}
}
abstract class WPCF7_Service {
abstract public function get_title();
abstract public function is_active();
public function get_categories() {
return array();
}
public function icon() {
return '';
}
public function link() {
return '';
}
public function load( $action = '' ) {
}
public function display( $action = '' ) {
}
public function admin_notice( $message = '' ) {
}
}
class WPCF7_Service_OAuth2 extends WPCF7_Service {
protected $client_id = '';
protected $client_secret = '';
protected $access_token = '';
protected $refresh_token = '';
protected $authorization_endpoint = 'https://example.com/authorization';
protected $token_endpoint = 'https://example.com/token';
public function get_title() {
return '';
}
public function is_active() {
return ! empty( $this->refresh_token );
}
protected function save_data() {
}
protected function reset_data() {
}
protected function get_redirect_uri() {
return admin_url();
}
protected function menu_page_url( $args = '' ) {
return menu_page_url( 'wpcf7-integration', false );
}
public function load( $action = '' ) {
if ( 'auth_redirect' == $action ) {
$code = isset( $_GET['code'] ) ? $_GET['code'] : '';
if ( $code ) {
$this->request_token( $code );
}
if ( ! empty( $this->access_token ) ) {
$message = 'success';
} else {
$message = 'failed';
}
wp_safe_redirect( $this->menu_page_url(
array(
'action' => 'setup',
'message' => $message,
)
) );
exit();
}
}
protected function authorize( $scope = '' ) {
$endpoint = add_query_arg(
array(
'response_type' => 'code',
'client_id' => $this->client_id,
'redirect_uri' => urlencode( $this->get_redirect_uri() ),
'scope' => $scope,
),
$this->authorization_endpoint
);
if ( wp_redirect( esc_url_raw( $endpoint ) ) ) {
exit();
}
}
protected function get_http_authorization_header( $scheme = 'basic' ) {
$scheme = strtolower( trim( $scheme ) );
switch ( $scheme ) {
case 'bearer':
return sprintf( 'Bearer %s', $this->access_token );
case 'basic':
default:
return sprintf( 'Basic %s',
base64_encode( $this->client_id . ':' . $this->client_secret )
);
}
}
protected function request_token( $authorization_code ) {
$endpoint = add_query_arg(
array(
'code' => $authorization_code,
'redirect_uri' => urlencode( $this->get_redirect_uri() ),
'grant_type' => 'authorization_code',
),
$this->token_endpoint
);
$request = array(
'headers' => array(
'Authorization' => $this->get_http_authorization_header( 'basic' ),
),
);
$response = wp_remote_post( esc_url_raw( $endpoint ), $request );
$response_code = (int) wp_remote_retrieve_response_code( $response );
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
if ( WP_DEBUG and 400 <= $response_code ) {
$this->log( $endpoint, $request, $response );
}
if ( 401 == $response_code ) { // Unauthorized
$this->access_token = null;
$this->refresh_token = null;
} else {
if ( isset( $response_body['access_token'] ) ) {
$this->access_token = $response_body['access_token'];
} else {
$this->access_token = null;
}
if ( isset( $response_body['refresh_token'] ) ) {
$this->refresh_token = $response_body['refresh_token'];
} else {
$this->refresh_token = null;
}
}
$this->save_data();
return $response;
}
protected function refresh_token() {
$endpoint = add_query_arg(
array(
'refresh_token' => $this->refresh_token,
'grant_type' => 'refresh_token',
),
$this->token_endpoint
);
$request = array(
'headers' => array(
'Authorization' => $this->get_http_authorization_header( 'basic' ),
),
);
$response = wp_remote_post( esc_url_raw( $endpoint ), $request );
$response_code = (int) wp_remote_retrieve_response_code( $response );
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
if ( WP_DEBUG and 400 <= $response_code ) {
$this->log( $endpoint, $request, $response );
}
if ( 401 == $response_code ) { // Unauthorized
$this->access_token = null;
$this->refresh_token = null;
} else {
if ( isset( $response_body['access_token'] ) ) {
$this->access_token = $response_body['access_token'];
} else {
$this->access_token = null;
}
if ( isset( $response_body['refresh_token'] ) ) {
$this->refresh_token = $response_body['refresh_token'];
}
}
$this->save_data();
return $response;
}
protected function remote_request( $url, $request = array() ) {
static $refreshed = false;
$request = wp_parse_args( $request, array() );
$request['headers'] = array_merge(
$request['headers'],
array(
'Authorization' => $this->get_http_authorization_header( 'bearer' ),
)
);
$response = wp_remote_request( esc_url_raw( $url ), $request );
if ( 401 === wp_remote_retrieve_response_code( $response )
and ! $refreshed ) {
$this->refresh_token();
$refreshed = true;
$response = $this->remote_request( $url, $request );
}
return $response;
}
protected function log( $url, $request, $response ) {
wpcf7_log_remote_request( $url, $request, $response );
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment