Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/contact-form-to-any-api/admin/class-cf7-to-any-api-admin.php
+++ b/contact-form-to-any-api/admin/class-cf7-to-any-api-admin.php
@@ -113,23 +113,21 @@
if ( isset($_GET['page'], $_GET['post_type']) && sanitize_text_field(wp_unslash($_GET['page'])) === 'cf7anyapi_entries' && sanitize_text_field(wp_unslash($_GET['post_type'])) === 'cf7_to_any_api' ) {
wp_enqueue_script('jquery');
wp_enqueue_script( $this->plugin_name.'-datatables', plugin_dir_url( __FILE__ ) . 'js/entries/jquery.dataTables.min.js', array( 'jquery' ), '1.10.19', true );
- wp_enqueue_script( $this->plugin_name.'-bootstrap', plugin_dir_url( __FILE__ ) . 'js/entries/bootstrap.min.js', array( 'jquery' ), '4.0.0', true );
wp_enqueue_script( $this->plugin_name.'-buttons', plugin_dir_url( __FILE__ ) . 'js/entries/dataTables.buttons.min.js', array( $this->plugin_name . '-datatables' ), '1.5.2', true );
wp_enqueue_script( $this->plugin_name.'-jszip', plugin_dir_url( __FILE__ ) . 'js/entries/jszip.min.js', array(), '3.1.3', true );
wp_enqueue_script( $this->plugin_name.'-pdfmake', plugin_dir_url( __FILE__ ) . 'js/entries/pdfmake.min.js', array(), '0.1.36', true );
wp_enqueue_script( $this->plugin_name.'-vfs-fonts', plugin_dir_url( __FILE__ ) . 'js/entries/vfs_fonts.js', array( $this->plugin_name . '-pdfmake' ), '0.1.36', true );
wp_enqueue_script( $this->plugin_name.'-buttons-html5', plugin_dir_url( __FILE__ ) . 'js/entries/buttons.html5.min.js', array( $this->plugin_name . '-buttons', $this->plugin_name . '-jszip', $this->plugin_name . '-pdfmake' ), '1.5.2', true );
wp_enqueue_script( $this->plugin_name.'-buttons-print', plugin_dir_url( __FILE__ ) . 'js/entries/buttons.print.min.js', array( $this->plugin_name . '-buttons' ), '1.5.2', true );
- wp_enqueue_script($this->plugin_name.'-datatables-bs4', plugin_dir_url(__FILE__) . 'js/entries/dataTables.bootstrap4.min.js', array($this->plugin_name . '-datatables', $this->plugin_name . '-bootstrap'), '1.10.19', true );
+ // Bootstrap's JavaScript is intentionally not loaded (the bundled 4.0.0 had known XSS
+ // issues, CVE-2018-14041); the DataTables Bootstrap 4 integration only needs its CSS.
+ wp_enqueue_script($this->plugin_name.'-datatables-bs4', plugin_dir_url(__FILE__) . 'js/entries/dataTables.bootstrap4.min.js', array($this->plugin_name . '-datatables'), '1.10.19', true );
wp_enqueue_script( $this->plugin_name.'-select', plugin_dir_url( __FILE__ ) . 'js/entries/dataTables.select.min.js', array( $this->plugin_name . '-datatables' ), '1.6.1', true );
wp_enqueue_script( $this->plugin_name.'-checkboxes', plugin_dir_url( __FILE__ ) . 'js/entries/dataTables.checkboxes.min.js', array( $this->plugin_name . '-datatables' ), '1.2.12', true );
}
- // Doc Page JS
- // phpcs:ignore WordPress.Security.NonceVerification.Recommended
- if ( isset($_GET['page'], $_GET['post_type']) && sanitize_text_field(wp_unslash($_GET['page'])) === 'cf7anyapi_docs' && sanitize_text_field(wp_unslash($_GET['post_type'])) === 'cf7_to_any_api' ) {
- wp_enqueue_script( $this->plugin_name.'-bootstrap', plugin_dir_url( __FILE__ ) . 'js/entries/bootstrap.min.js', array(), '1.2.12', true );
- }
+ // Doc Page JS: tab switching is handled by js/cf7-to-any-api-admin.js
+ // (Bootstrap's JavaScript is no longer loaded).
$data = array(
'cf7_to_any_api_site_url' => site_url(),
@@ -197,8 +195,82 @@
'rewrite' => false,
'menu_icon' => 'dashicons-smiley',
'menu_position' => 31,
+ // Integrations decide where form submissions are sent, so only users who can
+ // manage Contact Form 7 forms (Administrators and Editors by default) may manage them.
+ 'map_meta_cap' => true,
+ 'capabilities' => self::cf7anyapi_get_post_type_capabilities(),
+ );
+ register_post_type('cf7_to_any_api', $args);
+ }
+
+ /**
+ * Capability required to create, edit and delete API integrations.
+ *
+ * Defaults to the capability Contact Form 7 requires to edit forms
+ * (WPCF7_ADMIN_READ_WRITE_CAPABILITY, "publish_pages" by default), so that
+ * users who could manage integrations through Contact Form 7 keep doing so,
+ * while lower roles (Author, Contributor, Subscriber) cannot.
+ *
+ * @since 3.0.8
+ * @return string
+ */
+ public static function cf7anyapi_get_manage_capability() {
+ $capability = defined( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY' ) ? WPCF7_ADMIN_READ_WRITE_CAPABILITY : 'publish_pages';
+
+ /**
+ * Filters the capability required to manage CF7 to Any API integrations.
+ *
+ * @since 3.0.8
+ * @param string $capability Capability name.
+ */
+ $capability = apply_filters( 'cf7anyapi_manage_capability', $capability );
+
+ return ( is_string( $capability ) && '' !== $capability ) ? $capability : 'manage_options';
+ }
+
+ /**
+ * Primitive capabilities of the cf7_to_any_api post type.
+ *
+ * @since 3.0.8
+ * @return array
+ */
+ public static function cf7anyapi_get_post_type_capabilities() {
+ $capability = self::cf7anyapi_get_manage_capability();
+ return array(
+ 'edit_posts' => $capability,
+ 'edit_others_posts' => $capability,
+ 'edit_private_posts' => $capability,
+ 'edit_published_posts' => $capability,
+ 'publish_posts' => $capability,
+ 'read_private_posts' => $capability,
+ 'delete_posts' => $capability,
+ 'delete_others_posts' => $capability,
+ 'delete_private_posts' => $capability,
+ 'delete_published_posts' => $capability,
+ 'create_posts' => $capability,
);
- register_post_type('cf7_to_any_api', $args);
+ }
+
+ /**
+ * Whether the current user may connect an integration to the given CF7 form.
+ *
+ * @since 3.0.8
+ * @param int $form_id Contact Form 7 form ID.
+ * @return bool
+ */
+ public static function cf7anyapi_current_user_can_use_form( $form_id ) {
+ $form_id = absint( $form_id );
+ if ( ! $form_id || 'wpcf7_contact_form' !== get_post_type( $form_id ) ) {
+ return false;
+ }
+ if ( ! current_user_can( self::cf7anyapi_get_manage_capability() ) ) {
+ return false;
+ }
+ if ( ! function_exists( 'wpcf7_map_meta_cap' ) ) {
+ return true;
+ }
+ // Contact Form 7 maps this meta capability to its own capability for the given form.
+ return current_user_can( 'wpcf7_edit_contact_form', $form_id );
}
/**
@@ -317,8 +389,24 @@
if($cf7_to_any_api->post_type == 'cf7_to_any_api'){
$status = 'false';
if(isset($_POST['cf7_to_any_api_cpt_nonce']) && wp_verify_nonce(sanitize_text_field( wp_unslash( $_POST['cf7_to_any_api_cpt_nonce'] ) ), 'cf7_to_any_api_cpt_nonce')){
+ if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $cf7_to_any_api_id ) ) {
+ return;
+ }
+ // Authorization: the user must be allowed to edit this integration.
+ if ( ! current_user_can( 'edit_post', $cf7_to_any_api_id ) ) {
+ return;
+ }
+ $options = array();
if (isset($_POST['cf7anyapi_selected_form'])) {
$options['cf7anyapi_selected_form'] = (int)sanitize_text_field( wp_unslash( $_POST['cf7anyapi_selected_form']) );
+ // Authorization: the user must also be allowed to manage the selected Contact Form 7 form.
+ if ( ! self::cf7anyapi_current_user_can_use_form( $options['cf7anyapi_selected_form'] ) ) {
+ wp_die(
+ esc_html__( 'Sorry, you are not allowed to connect an API integration to this contact form.', 'contact-form-to-any-api' ),
+ esc_html__( 'Not allowed', 'contact-form-to-any-api' ),
+ array( 'response' => 403, 'back_link' => true )
+ );
+ }
}
if (isset($_POST['cf7anyapi_base_url'])) {
$options['cf7anyapi_base_url'] = esc_url_raw(wp_unslash($_POST['cf7anyapi_base_url']));
@@ -498,20 +586,31 @@
exit();
}
- // Capability check: require at minimum the ability to edit posts.
- if ( ! current_user_can( 'edit_posts' ) ) {
+ // Capability check: only users who can manage API integrations.
+ if ( ! current_user_can( self::cf7anyapi_get_manage_capability() ) ) {
echo wp_json_encode( __( 'You do not have permission to perform this action.', 'contact-form-to-any-api' ) );
exit();
}
- if(empty((int)sanitize_text_field(wp_unslash($_POST['form_id'])))){
+ if( ! isset( $_POST['form_id'] ) || empty((int)sanitize_text_field(wp_unslash($_POST['form_id'])))){
echo wp_json_encode(__( 'No Fields Found for Selected Form.', 'contact-form-to-any-api' ));
exit();
}
$html = '';
$form_ID = (int)sanitize_text_field(wp_unslash($_POST['form_id']));
$post_id = isset( $_POST['post_id'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : 0;
+
+ // The user must be allowed to manage the requested form and, when given, the integration.
+ if ( ! self::cf7anyapi_current_user_can_use_form( $form_ID ) || ( $post_id && ( 'cf7_to_any_api' !== get_post_type( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) ) ) {
+ echo wp_json_encode( __( 'You do not have permission to perform this action.', 'contact-form-to-any-api' ) );
+ exit();
+ }
+
$ContactForm = WPCF7_ContactForm::get_instance($form_ID);
+ if ( ! $ContactForm ) {
+ echo wp_json_encode(__( 'No Fields Found for Selected Form.', 'contact-form-to-any-api' ));
+ exit();
+ }
$form_fields = $ContactForm->scan_form_tags();
$post_form_id = get_post_meta($post_id,'cf7anyapi_selected_form',true);
@@ -642,10 +741,10 @@
if( !empty($cf7files) && get_option('cf7_to_api_entry_hide') != true ) {
foreach ($cf7files as $key => $cf7file) {
if(!empty($cf7file)){
- $ext = sanitize_file_name( pathinfo( $cf7file[0], PATHINFO_EXTENSION ) );
+ $ext = self::cf7anyapi_get_safe_upload_extension( $cf7file[0] );
// Use a cryptographically random token instead of a predictable
// form_id + timestamp pattern to prevent unauthenticated file enumeration.
- $fileName = 'cf7-' . wp_generate_password( 16, false ) . '.' . $ext;
+ $fileName = 'cf7-' . wp_generate_password( 16, false ) . ( '' !== $ext ? '.' . $ext : '' );
copy($cf7file[0], $cf7_uploads_dir.'/'.$fileName);
$posted_data[$key] = '<a href="'.wp_upload_dir()['baseurl'] . '/cf7-to-any-api-uploads/'.esc_attr($fileName).'" target="_blank">'.esc_html($fileName).'</a>';
}
@@ -743,9 +842,22 @@
$wpdb->insert($table,array('Created' => current_time( 'mysql' )));
$data_id = (int)$wpdb->insert_id;
+ $cf7anyapi_object = new Cf7_To_Any_Api();
+
foreach($posted_data as $field => $value){
-
- $posted_value = (is_array($value) ? implode(',',$value) : $value);
+
+ $posted_value = (is_array($value) ? implode(',', array_map('strval', array_filter($value, 'is_scalar'))) : $value);
+ $field = sanitize_text_field( (string) $field );
+
+ // Store entries as plain text. The only markup kept is the upload link this
+ // plugin generates itself, which is rebuilt from the file name.
+ $upload_link = $cf7anyapi_object->cf7toanyapi_parse_upload_link( $posted_value );
+ if ( $upload_link ) {
+ $posted_value = '<a href="' . esc_url( $upload_link['url'] ) . '" target="_blank">' . esc_html( $upload_link['name'] ) . '</a>';
+ } else {
+ $posted_value = self::cf7anyapi_sanitize_entry_value( $posted_value );
+ }
+
if (is_string($posted_value) && strlen($posted_value) > 255) {
$posted_value = substr($posted_value, 0, 255);
}
@@ -765,6 +877,52 @@
}
/**
+ * Safe file extension for a copy of an uploaded file.
+ *
+ * sanitize_file_name() must not be used on a bare extension: it treats "pdf"
+ * as a file without a name and returns "unnamed-file.pdf". This keeps only
+ * letters and digits, and neutralises server-side script extensions as
+ * defence in depth (Contact Form 7 already renames those).
+ *
+ * @since 3.0.8
+ * @param string $file_path Path of the uploaded file.
+ * @return string Lower-case extension without the dot, or '' if none.
+ */
+ public static function cf7anyapi_get_safe_upload_extension( $file_path ) {
+ $ext = strtolower( preg_replace( '/[^A-Za-z0-9]/', '', (string) pathinfo( (string) $file_path, PATHINFO_EXTENSION ) ) );
+ if ( '' === $ext ) {
+ return '';
+ }
+ if ( preg_match( '/^(phpd*|phtml|phar|pht|phps|cgi|pl|py|asp|aspx|jsp|sh|shtml|htaccess|exe|js|html?|svg)$/', $ext ) ) {
+ $ext .= '_.txt'; // Same format Contact Form 7 uses, e.g. "file.php_.txt".
+ }
+ return $ext;
+ }
+
+ /**
+ * Sanitize a submitted value before it is stored in the entries table.
+ *
+ * Removes HTML tags (like sanitize_textarea_field()) while keeping line breaks,
+ * a lone "<" character and percent-encoded sequences, so legitimate text is
+ * stored unchanged.
+ *
+ * @since 3.0.8
+ * @param mixed $value Submitted value.
+ * @return string
+ */
+ public static function cf7anyapi_sanitize_entry_value( $value ) {
+ if ( ! is_scalar( $value ) ) {
+ return '';
+ }
+ $value = wp_check_invalid_utf8( (string) $value );
+ if ( false !== strpos( $value, '<' ) ) {
+ $value = wp_pre_kses_less_than( $value );
+ $value = wp_strip_all_tags( $value, false );
+ }
+ return $value;
+ }
+
+ /**
* Child Fuction of specific form data send to the API
*
* @since 1.0.0
@@ -1162,7 +1320,7 @@
wp_send_json_error( __( 'Security check failed.', 'contact-form-to-any-api' ) );
}
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
+ if ( 'cf7_to_any_api' !== get_post_type( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
wp_send_json_error( __( 'You are not allowed to do this.', 'contact-form-to-any-api' ) );
}
--- a/contact-form-to-any-api/admin/partials/cf7-to-any-api-admin-display-docs.php
+++ b/contact-form-to-any-api/admin/partials/cf7-to-any-api-admin-display-docs.php
@@ -39,7 +39,7 @@
<div class="tab-index"></div>
<?php esc_html_e( 'CF7 Hidden Fields', 'contact-form-to-any-api' ); ?>
</a>
- <a class="nav-link tab-index-10" id="v-pills-contact-us-tab" data-toggle="pill" href="#v-pills-contact-us" role="tab" aria-controls="v-pills-contact-us" aria-selected="false">
+ <a class="nav-link tab-index-8" id="v-pills-contact-us-tab" data-toggle="pill" href="#v-pills-contact-us" role="tab" aria-controls="v-pills-contact-us" aria-selected="false">
<div class="tab-index"></div>
<?php esc_html_e( 'Contact Us', 'contact-form-to-any-api' ); ?>
</a>
--- a/contact-form-to-any-api/admin/partials/cf7-to-any-api-admin-entries.php
+++ b/contact-form-to-any-api/admin/partials/cf7-to-any-api-admin-entries.php
@@ -108,11 +108,23 @@
} else if($cf7anyapi_instance->cf7toanyapi_admin_get_field_name($cf7anyapi_value2) == 'submitted_from'){
echo '<td data-head="'.esc_attr( $cf7anyapi_instance->cf7toanyapi_admin_get_field_name($cf7anyapi_value2) ).'"><a href="'.esc_url(get_the_permalink($cf7anyapi_inner_value)).'" target="_blank">'.esc_html(get_the_title($cf7anyapi_inner_value)).'</a></td>';
} else{
- $cf7anyapi_inner_values_decoded = wp_kses_post(html_entity_decode($cf7anyapi_inner_value));
- if(strlen($cf7anyapi_inner_values_decoded) > $cf7anyapi_display_character){
- echo '<td data-head="'. esc_attr( $cf7anyapi_instance->cf7toanyapi_admin_get_field_name($cf7anyapi_value2) ).'">'.wp_kses_post(substr(html_entity_decode($cf7anyapi_inner_value), 0, $cf7anyapi_display_character)).'...</td>';
- }else{
- echo '<td data-head="'. esc_attr( $cf7anyapi_instance->cf7toanyapi_admin_get_field_name($cf7anyapi_value2) ).'">'.wp_kses_post( htmlspecialchars_decode( $cf7anyapi_inner_value ) ).'</td>';
+ $cf7anyapi_field_head = $cf7anyapi_instance->cf7toanyapi_admin_get_field_name($cf7anyapi_value2);
+ $cf7anyapi_upload_link = $cf7anyapi_instance->cf7toanyapi_parse_upload_link($cf7anyapi_inner_value);
+
+ if ( $cf7anyapi_upload_link ) {
+ // File uploaded through the form and stored by this plugin as a link.
+ ?><td data-head="<?php echo esc_attr( $cf7anyapi_field_head ); ?>">
+ <a href="<?php echo esc_url( $cf7anyapi_upload_link['url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $cf7anyapi_upload_link['name'] ); ?></a>
+ </td><?php
+ } else {
+ // Submitted values are untrusted: always print them as plain text.
+ // Entities are decoded first so legacy stored values (e.g. &, ')
+ // display as before; esc_html() then escapes everything again.
+ $cf7anyapi_plain_value = ( ' ' === $cf7anyapi_inner_value ) ? '' : html_entity_decode( (string) $cf7anyapi_inner_value, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
+ if ( mb_strlen( $cf7anyapi_plain_value ) > $cf7anyapi_display_character ) {
+ $cf7anyapi_plain_value = mb_substr( $cf7anyapi_plain_value, 0, $cf7anyapi_display_character ) . '...';
+ }
+ echo '<td data-head="' . esc_attr( $cf7anyapi_field_head ) . '">' . esc_html( $cf7anyapi_plain_value ) . '</td>';
}
}
}//Close foreach
--- a/contact-form-to-any-api/cf7-to-any-api.php
+++ b/contact-form-to-any-api/cf7-to-any-api.php
@@ -1,90 +1,90 @@
-<?php
-if ( ! defined( 'ABSPATH' ) ) exit;
-/**
- * The plugin bootstrap file
- *
- * This file is read by WordPress to generate the plugin information in the plugin
- * admin area. This file also includes all of the dependencies used by the plugin,
- * registers the activation and deactivation functions, and defines a function
- * that starts the plugin.
- *
- * @link https://www.itpathsolutions.com/
- * @since 1.0.0
- * @package Cf7_To_Any_Api
- *
- * @wordpress-plugin
- * Plugin Name: Contact Form to Any API
- * Plugin URI: https://wordpress.org/plugins/contact-form-to-any-api/
- * Description: Send Contact Form 7 leads and data to any CRM, Webhook or REST API with flexible payloads, endpoints, and authentication.
- * Version: 3.0.7
- * Author: IT Path Solutions
- * Author URI: https://www.itpathsolutions.com/
- * Requires Plugins: contact-form-7
- * License: GPL-2.0+
- * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
- * Text Domain: contact-form-to-any-api
- * Domain Path: /languages
- *
- */
-
-// If this file is called directly, abort.
-if ( ! defined( 'WPINC' ) ) {
- die;
-}
-
-/**
- * Currently plugin version.
- * Start at version 1.0.0 and use SemVer - https://semver.org
- * Rename this for your plugin and update it as you release new versions.
- */
-define( 'CF7_TO_ANY_API_VERSION', '3.0.7' );
-
-define( 'CF7_TO_ANY_API_DB_VERSION', '1.1');
-
-define( 'CF7_CURL_DOMAIN', 'https://www.contactformtoapi.com' );
-
-define( 'CF7_TO_ANY_API_PLUGIN_BASENAME', basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) );
-
-/**
- * The code that runs during plugin activation.
- * This action is documented in includes/class-cf7-to-any-api-activator.php
- */
-function activate_cf7_to_any_api() {
- require_once plugin_dir_path( __FILE__ ) . 'includes/class-cf7-to-any-api-activator.php';
- Cf7_To_Any_Api_Activator::activate();
-}
-
-/**
- * The code that runs during plugin deactivation.
- * This action is documented in includes/class-cf7-to-any-api-deactivator.php
- */
-function deactivate_cf7_to_any_api() {
- require_once plugin_dir_path( __FILE__ ) . 'includes/class-cf7-to-any-api-deactivator.php';
- Cf7_To_Any_Api_Deactivator::deactivate();
-}
-
-register_activation_hook( __FILE__, 'activate_cf7_to_any_api' );
-register_deactivation_hook( __FILE__, 'deactivate_cf7_to_any_api' );
-
-/**
- * The core plugin class that is used to define internationalization,
- * admin-specific hooks, and public-facing site hooks.
- */
-require plugin_dir_path( __FILE__ ) . 'includes/class-cf7-to-any-api.php';
-
-/**
- * Begins execution of the plugin.
- *
- * Since everything within the plugin is registered via hooks,
- * then kicking off the plugin from this point in the file does
- * not affect the page life cycle.
- *
- * @since 1.0.0
- */
-function run_cf7_to_any_api() {
-
- $plugin = new Cf7_To_Any_Api();
- $plugin->run();
-
-}
-run_cf7_to_any_api();
+<?php
+if ( ! defined( 'ABSPATH' ) ) exit;
+/**
+ * The plugin bootstrap file
+ *
+ * This file is read by WordPress to generate the plugin information in the plugin
+ * admin area. This file also includes all of the dependencies used by the plugin,
+ * registers the activation and deactivation functions, and defines a function
+ * that starts the plugin.
+ *
+ * @link https://www.itpathsolutions.com/
+ * @since 1.0.0
+ * @package Cf7_To_Any_Api
+ *
+ * @wordpress-plugin
+ * Plugin Name: Contact Form to Any API
+ * Plugin URI: https://wordpress.org/plugins/contact-form-to-any-api/
+ * Description: Send Contact Form 7 leads and data to any CRM, Webhook or REST API with flexible payloads, endpoints, and authentication.
+ * Version: 3.0.8
+ * Author: IT Path Solutions
+ * Author URI: https://www.itpathsolutions.com/
+ * Requires Plugins: contact-form-7
+ * License: GPL-2.0+
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
+ * Text Domain: contact-form-to-any-api
+ * Domain Path: /languages
+ *
+ */
+
+// If this file is called directly, abort.
+if ( ! defined( 'WPINC' ) ) {
+ die;
+}
+
+/**
+ * Currently plugin version.
+ * Start at version 1.0.0 and use SemVer - https://semver.org
+ * Rename this for your plugin and update it as you release new versions.
+ */
+define( 'CF7_TO_ANY_API_VERSION', '3.0.8' );
+
+define( 'CF7_TO_ANY_API_DB_VERSION', '1.1');
+
+define( 'CF7_CURL_DOMAIN', 'https://www.contactformtoapi.com' );
+
+define( 'CF7_TO_ANY_API_PLUGIN_BASENAME', basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) );
+
+/**
+ * The code that runs during plugin activation.
+ * This action is documented in includes/class-cf7-to-any-api-activator.php
+ */
+function activate_cf7_to_any_api() {
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-cf7-to-any-api-activator.php';
+ Cf7_To_Any_Api_Activator::activate();
+}
+
+/**
+ * The code that runs during plugin deactivation.
+ * This action is documented in includes/class-cf7-to-any-api-deactivator.php
+ */
+function deactivate_cf7_to_any_api() {
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-cf7-to-any-api-deactivator.php';
+ Cf7_To_Any_Api_Deactivator::deactivate();
+}
+
+register_activation_hook( __FILE__, 'activate_cf7_to_any_api' );
+register_deactivation_hook( __FILE__, 'deactivate_cf7_to_any_api' );
+
+/**
+ * The core plugin class that is used to define internationalization,
+ * admin-specific hooks, and public-facing site hooks.
+ */
+require plugin_dir_path( __FILE__ ) . 'includes/class-cf7-to-any-api.php';
+
+/**
+ * Begins execution of the plugin.
+ *
+ * Since everything within the plugin is registered via hooks,
+ * then kicking off the plugin from this point in the file does
+ * not affect the page life cycle.
+ *
+ * @since 1.0.0
+ */
+function run_cf7_to_any_api() {
+
+ $plugin = new Cf7_To_Any_Api();
+ $plugin->run();
+
+}
+run_cf7_to_any_api();
--- a/contact-form-to-any-api/includes/class-cf7-to-any-api.php
+++ b/contact-form-to-any-api/includes/class-cf7-to-any-api.php
@@ -353,6 +353,40 @@
return esc_html($field);
}
+ /**
+ * Detect a file-upload link stored by this plugin in the entries table.
+ *
+ * Uploaded files are saved in the entries table as
+ * <a href="{uploads}/cf7-to-any-api-uploads/{file}" target="_blank">{file}</a>.
+ * Instead of trusting that markup, only the file name is extracted and the
+ * URL is rebuilt from the current uploads directory, so the value can be
+ * rendered as a link without printing any stored HTML.
+ *
+ * @since 3.0.8
+ * @param string $value Stored entry value.
+ * @return array|false array( 'url' => string, 'name' => string ) or false.
+ */
+ public function cf7toanyapi_parse_upload_link( $value ) {
+ if ( ! is_string( $value ) || false === stripos( $value, 'cf7-to-any-api-uploads/' ) ) {
+ return false;
+ }
+
+ if ( ! preg_match( '#^s*<as[^>]*href=(["'])[^"']*/cf7-to-any-api-uploads/([^"'/?#]+)1[^>]*>[^<]*</a>s*$#i', $value, $matches ) ) {
+ return false;
+ }
+
+ $file_name = rawurldecode( $matches[2] );
+ if ( '' === $file_name || sanitize_file_name( $file_name ) !== $file_name ) {
+ return false;
+ }
+
+ $uploads = wp_upload_dir( null, false );
+ return array(
+ 'url' => trailingslashit( $uploads['baseurl'] ) . 'cf7-to-any-api-uploads/' . rawurlencode( $file_name ),
+ 'name' => $file_name,
+ );
+ }
+
public function cf7toanyapi_field_type_info($fid){
if(empty($fid) || !intval($fid)) return ;