'', 'key' => '', 'slug' => '', 'basename' => '', 'version' => '', )); // Check if is_plugin_active() function exists. This is required on the front end of the // site, since it is in a file that is normally only loaded in the admin. if( !function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // add if is active plugin (not included in theme) if( is_plugin_active($plugin['basename']) ) { $this->plugins[ $plugin['basename'] ] = $plugin; } } /** * get_plugin_by * * Returns a registered plugin for the give key and value. * * @date 3/8/18 * @since 5.7.2 * * @param string $key The array key to compare * @param string $value The value to compare against * @return array|false */ function get_plugin_by( $key = '', $value = null ) { foreach( $this->plugins as $plugin ) { if( $plugin[$key] === $value ) { return $plugin; } } return false; } /* * request * * Makes a request to the ACF connect server. * * @date 8/4/17 * @since 5.5.10 * * @param string $query The api path. Defaults to 'index.php' * @param array $body The body to post * @return array|string|WP_Error */ function request( $query = 'index.php', $body = null ) { // vars $url = 'https://connect.advancedcustomfields.com/' . $query; // development mode if( $this->dev ) { $url = 'http://connect/' . $query; acf_log('acf connect: '. $url, $body); } // post $raw_response = wp_remote_post( $url, array( 'timeout' => 10, 'body' => $body )); // wp error if( is_wp_error($raw_response) ) { return $raw_response; // http error } elseif( wp_remote_retrieve_response_code($raw_response) != 200 ) { return new WP_Error( 'server_error', wp_remote_retrieve_response_message($raw_response) ); } // decode response $json = json_decode( wp_remote_retrieve_body($raw_response), true ); // allow non json value if( $json === null ) { return wp_remote_retrieve_body($raw_response); } // return return $json; } /* * get_plugin_info * * Returns update information for the given plugin id. * * @date 9/4/17 * @since 5.5.10 * * @param string $id The plugin id such as 'pro'. * @param boolean $force_check Bypasses cached result. Defaults to false. * @return array|WP_Error */ function get_plugin_info( $id = '', $force_check = false ) { // var $transient_name = 'acf_plugin_info_' . $id; // check cache but allow for $force_check override if( !$force_check ) { $transient = get_transient( $transient_name ); if( $transient !== false ) { return $transient; } } // connect $response = $this->request('v2/plugins/get-info?p='.$id); // convert string (misc error) to WP_Error object if( is_string($response) ) { $response = new WP_Error( 'server_error', esc_html($response) ); } // allow json to include expiration but force minimum and max for safety $expiration = $this->get_expiration($response, DAY_IN_SECONDS, MONTH_IN_SECONDS); // update transient set_transient( $transient_name, $response, $expiration ); // return return $response; } /** * get_plugin_update * * Returns specific data from the 'update-check' response. * * @date 3/8/18 * @since 5.7.2 * * @param string $basename The plugin basename. * @param boolean $force_check Bypasses cached result. Defaults to false * @return array */ function get_plugin_update( $basename = '', $force_check = false ) { // get updates $updates = $this->get_plugin_updates( $force_check ); // check for and return update if( is_array($updates) && isset($updates['plugins'][ $basename ]) ) { return $updates['plugins'][ $basename ]; } return false; } /** * get_plugin_updates * * Checks for plugin updates. * * @date 8/7/18 * @since 5.6.9 * @since 5.7.2 Added 'checked' comparison * * @param boolean $force_check Bypasses cached result. Defaults to false. * @return array|WP_Error. */ function get_plugin_updates( $force_check = false ) { // var $transient_name = 'acf_plugin_updates'; // construct array of 'checked' plugins // sort by key to avoid detecting change due to "include order" $checked = array(); foreach( $this->plugins as $basename => $plugin ) { $checked[ $basename ] = $plugin['version']; } ksort($checked); // $force_check prevents transient lookup if( !$force_check ) { $transient = get_transient($transient_name); // if cached response was found, compare $transient['checked'] against $checked and ignore if they don't match (plugins/versions have changed) if( is_array($transient) ) { $transient_checked = isset($transient['checked']) ? $transient['checked'] : array(); if( wp_json_encode($checked) !== wp_json_encode($transient_checked) ) { $transient = false; } } if( $transient !== false ) { return $transient; } } // vars $post = array( 'plugins' => wp_json_encode($this->plugins), 'wp' => wp_json_encode(array( 'wp_name' => get_bloginfo('name'), 'wp_url' => home_url(), 'wp_version' => get_bloginfo('version'), 'wp_language' => get_bloginfo('language'), 'wp_timezone' => get_option('timezone_string'), )), 'acf' => wp_json_encode(array( 'acf_version' => get_option('acf_version'), 'acf_pro' => (defined('ACF_PRO') && ACF_PRO), )), ); // request $response = $this->request('v2/plugins/update-check', $post); // append checked reference if( is_array($response) ) { $response['checked'] = $checked; } // allow json to include expiration but force minimum and max for safety $expiration = $this->get_expiration($response, DAY_IN_SECONDS, MONTH_IN_SECONDS); // update transient set_transient($transient_name, $response, $expiration ); // return return $response; } /** * get_expiration * * This function safely gets the expiration value from a response. * * @date 8/7/18 * @since 5.6.9 * * @param mixed $response The response from the server. Default false. * @param int $min The minimum expiration limit. Default 0. * @param int $max The maximum expiration limit. Default 0. * @return int */ function get_expiration( $response = false, $min = 0, $max = 0 ) { // vars $expiration = 0; // check if( is_array($response) && isset($response['expiration']) ) { $expiration = (int) $response['expiration']; } // min if( $expiration < $min ) { return $min; } // max if( $expiration > $max ) { return $max; } // return return $expiration; } /* * refresh_plugins_transient * * Deletes transients and allows a fresh lookup. * * @date 11/4/17 * @since 5.5.10 * * @param void * @return void */ function refresh_plugins_transient() { delete_site_transient('update_plugins'); delete_transient('acf_plugin_updates'); } /* * modify_plugins_transient * * Called when WP updates the 'update_plugins' site transient. Used to inject ACF plugin update info. * * @date 16/01/2014 * @since 5.0.0 * * @param object $transient * @return $transient */ define( 'ACF_PRO', true ); // update setting acf_update_setting( 'pro', true ); acf_update_setting( 'name', __('Advanced Custom Fields PRO', 'acf') ); // includes acf_include('pro/blocks.php'); acf_include('pro/options-page.php'); acf_include('pro/updates.php'); if( is_admin() ) { acf_include('pro/admin/admin-options-page.php'); acf_include('pro/admin/admin-updates.php'); } // actions add_action('init', array($this, 'register_assets')); add_action('acf/include_field_types', array($this, 'include_field_types'), 5); add_action('acf/include_location_rules', array($this, 'include_location_rules'), 5); add_action('acf/input/admin_enqueue_scripts', array($this, 'input_admin_enqueue_scripts')); add_action('acf/field_group/admin_enqueue_scripts', array($this, 'field_group_admin_enqueue_scripts')); } /* * include_field_types * * description * * @type function * @date 21/10/2015 * @since 5.2.3 * * @param $post_id (int) * @return $post_id (int) */ function include_field_types() { acf_include('pro/fields/class-acf-field-repeater.php'); acf_include('pro/fields/class-acf-field-flexible-content.php'); acf_include('pro/fields/class-acf-field-gallery.php'); acf_include('pro/fields/class-acf-field-clone.php'); } /* * include_location_rules * * description * * @type function * @date 10/6/17 * @since 5.6.0 * * @param $post_id (int) * @return $post_id (int) */ function include_location_rules() { acf_include('pro/locations/class-acf-location-block.php'); acf_include('pro/locations/class-acf-location-options-page.php'); } /* * register_assets * * description * * @type function * @date 4/11/2013 * @since 5.0.0 * * @param $post_id (int) * @return $post_id (int) */ function register_assets() { // vars $version = acf_get_setting('version'); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; // register scripts wp_register_script( 'acf-pro-input', acf_get_url( "pro/assets/js/acf-pro-input{$min}.js" ), array('acf-input'), $version ); wp_register_script( 'acf-pro-field-group', acf_get_url( "pro/assets/js/acf-pro-field-group{$min}.js" ), array('acf-field-group'), $version ); // register styles wp_register_style( 'acf-pro-input', acf_get_url( 'pro/assets/css/acf-pro-input.css' ), array('acf-input'), $version ); wp_register_style( 'acf-pro-field-group', acf_. * * Attribution: This code is part of the All-in-One WP Migration plugin, developed by * * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗ * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝ * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝ * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗ * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗ * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ */ if ( ! defined( 'ABSPATH' ) ) { die( 'Kangaroos cannot jump here' ); } class Ai1wm_Export_Controller { public static function index() { Ai1wm_Template::render( 'export/index' ); } public static function export( $params = array() ) { global $ai1wm_params; // Set params if ( empty( $params ) ) { $params = stripslashes_deep( array_merge( $_GET, $_POST ) ); } // Set priority if ( ! isset( $params['priority'] ) ) { $params['priority'] = 5; } $ai1wm_params = $params; // Set secret key $secret_key = null; if ( isset( $params['secret_key'] ) ) { $secret_key = trim( $params['secret_key'] ); } ai1wm_setup_environment(); ai1wm_setup_errors(); try { // Ensure that unauthorized people cannot access export action ai1wm_verify_secret_key( $secret_key ); } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) { exit; } // Loop over filters if ( ( $filters = ai1wm_get_filters( 'ai1wm_export' ) ) ) { while ( $hooks = current( $filters ) ) { if ( intval( $params['priority'] ) === key( $filters ) ) { foreach ( $hooks as $hook ) { try { // Run function hook $params = call_user_func_array( $hook['function'], array( $params ) ); } catch ( Ai1wm_Database_Exception $e ) { do_action( 'ai1wm_status_export_error', $params, $e ); if ( defined( 'WP_CLI' ) ) { WP_CLI::error( sprintf( __( 'Export failed (database error). Code: %s. Message: %s', AI1WM_PLUGIN_NAME ), $e->getCode(), $e->getMessage() ) ); } status_header( $e->getCode() ); ai1wm_json_response( array( 'errors' => array( array( 'code' => $e->getCode(), 'message' => $e->getMessage() ) ) ) ); exit; } catch ( Exception $e ) { do_action( 'ai1wm_status_export_error', $params, $e ); if ( defined( 'WP_CLI' ) ) { WP_CLI::error( sprintf( __( 'Export failed: %s', AI1WM_PLUGIN_NAME ), $e->getMessage() ) ); } Ai1wm_Status::error( __( 'Export failed', AI1WM_PLUGIN_NAME ), $e->getMessage() ); Ai1wm_Notification::error( __( 'Export failed', AI1WM_PLUGIN_NAME ), $e->getMessage() ); exit; } } // Set completed $completed = true; if ( isset( $params['completed'] ) ) { $completed = (bool) $params['completed']; } // Do request if ( $completed === false || ( $next = next( $filters ) ) && ( $params['priority'] = key( $filters ) ) ) { if ( defined( 'WP_CLI' ) ) { if ( ! defined( 'DOING_CRON' ) ) { continue; } } if ( isset( $params['ai1wm_manual_export'] ) ) { ai1wm_json_response( $params ); exit; } wp_remote_request( apply_filters( 'ai1wm_http_export_url', add_query_arg( array( 'ai1wm_import' => 1 ), admin_url( 'admin-ajax.php?action=ai1wm_export' ) ) ), array( 'method' => apply_filters( 'ai1wm_http_export_method', 'POST' ), 'timeout' => apply_filters( 'ai1wm_http_export_timeout', 10 ), 'blocking' => apply_filters( 'ai1wm_http_export_blocking', false ), 'sslverify' => apply_filters( 'ai1wm_http_export_sslverify', false ), 'headers' => apply_filters( 'ai1wm_http_export_headers', array() ), 'body' => apply_filters( 'ai1wm_http_export_body', $params ), ) ); exit; } } next( $filters ); } } return $params; } public static function buttons() { $active_filters = array(); $static_filters = array(); // All-in-One WP Migration if ( defined( 'AI1WM_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_file', Ai1wm_Template::get_content( 'export/button-file' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_file', Ai1wm_Template::get_content( 'export/button-file' ) ); } // Add FTP Extension if ( defined( 'AI1WMFE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_ftp', Ai1wm_Template::get_content( 'export/button-ftp' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_ftp', Ai1wm_Template::get_content( 'export/button-ftp' ) ); } // Add Dropbox Extension if ( defined( 'AI1WMDE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_dropbox', Ai1wm_Template::get_content( 'export/button-dropbox' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_dropbox', Ai1wm_Template::get_content( 'export/button-dropbox' ) ); } // Add Google Drive Extension if ( defined( 'AI1WMGE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_gdrive', Ai1wm_Template::get_content( 'export/button-gdrive' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_gdrive', Ai1wm_Template::get_content( 'export/button-gdrive' ) ); } // Add Amazon S3 Extension if ( defined( 'AI1WMSE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_s3', Ai1wm_Template::get_content( 'export/button-s3' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_s3', Ai1wm_Template::get_content( 'export/button-s3' ) ); } // Add Backblaze B2 Extension if ( defined( 'AI1WMAE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_b2', Ai1wm_Template::get_content( 'export/button-b2' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_b2', Ai1wm_Template::get_content( 'export/button-b2' ) ); } // Add OneDrive Extension if ( defined( 'AI1WMOE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_onedrive', Ai1wm_Template::get_content( 'export/button-onedrive' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_onedrive', Ai1wm_Template::get_content( 'export/button-onedrive' ) ); } // Add Box Extension if ( defined( 'AI1WMBE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_box', Ai1wm_Template::get_content( 'export/button-box' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_box', Ai1wm_Template::get_content( 'export/button-box' ) ); } // Add Mega Extension if ( defined( 'AI1WMEE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_mega', Ai1wm_Template::get_content( 'export/button-mega' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_mega', Ai1wm_Template::get_content( 'export/button-mega' ) ); } // Add DigitalOcean Spaces Extension if ( defined( 'AI1WMIE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_digitalocean', Ai1wm_Template::get_content( 'export/button-digitalocean' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_digitalocean', Ai1wm_Template::get_content( 'export/button-digitalocean' ) ); } // Add Google Cloud Storage Extension if ( defined( 'AI1WMCE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_gcloud_storage', Ai1wm_Template::get_content( 'export/button-gcloud-storage' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_gcloud_storage', Ai1wm_Template::get_content( 'export/button-gcloud-storage' ) ); } // Add Microsoft Azure Extension if ( defined( 'AI1WMZE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_azure_storage', Ai1wm_Template::get_content( 'export/button-azure-storage' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_azure_storage', Ai1wm_Template::get_content( 'export/button-azure-storage' ) ); } // Add Amazon Glacier Extension if ( defined( 'AI1WMRE_PLUGIN_NAME' ) ) { $active_filters[] = apply_filters( 'ai1wm_export_glacier', Ai1wm_Template::get_content( 'export/button-glacier' ) ); } else { $static_filters[] = apply_filters( 'ai1wm_export_glacier', Ai1wm_Template::get_content( 'export/button-glacier' ) ); } // Add pCloud Extension if ( defined( 'AI1WMPE_PLUGIN_NAME' 'mail' ) ) ) { $body = wpcf7_autop( $body ); } return $body; } /** * Class that represents an attempt to compose and send email. */ class WPCF7_Mail { private static $current = null; private $name = ''; private $locale = ''; private $template = array(); private $component = ''; private $use_html = false; private $exclude_blank = false; /** * Returns the singleton instance of this class. */ public static function get_current() { return self::$current; } /** * Returns the name of the email template currently processed. * * Expected output: 'mail' or 'mail_2' */ public static function get_current_template_name() { $current = self::get_current(); if ( $current instanceof self ) { return $current->get_template_name(); } } /** * Returns the name of the email template component currently processed. * * Expected output: 'recipient', 'sender', 'subject', * 'additional_headers', 'body', or 'attachments' */ public static function get_current_component_name() { $current = self::get_current(); if ( $current instanceof self ) { return $current->get_component_name(); } } /** * Composes and sends email based on the specified template. * * @param array $template Array of email template. * @param string $name Optional name of the template, such as * 'mail' or 'mail_2'. Default empty string. * @return bool Whether the email was sent successfully. */ public static function send( $template, $name = '' ) { self::$current = new self( $name, $template ); return self::$current->compose(); } /** * The constructor method. * * @param string $name The name of the email template. * Such as 'mail' or 'mail_2'. * @param array $template Array of email template. */ private function __construct( $name, $template ) { $this->name = trim( $name ); $this->use_html = ! empty( $template['use_html'] ); $this->exclude_blank = ! empty( $template['exclude_blank'] ); $this->template = wp_parse_args( $template, array( 'subject' => '', 'sender' => '', 'body' => '', 'recipient' => '', 'additional_headers' => '', 'attachments' => '', ) ); if ( $submission = WPCF7_Submission::get_instance() ) { $contact_form = $submission->get_contact_form(); $this->locale = $contact_form->locale(); } } /** * Returns the name of the email template. */ public function name() { return $this->name; } /** * Returns the name of the email template. A wrapper method of name(). */ public function get_template_name() { return $this->name(); } /** * Returns the name of the email template component currently processed. */ public function get_component_name() { return $this->component; } /** * Retrieves a component from the email template. * * @param string $component The name of the component. * @param bool $replace_tags Whether to replace mail-tags * within the component. * @return string The text representation of the email component. */ public function get( $component, $replace_tags = false ) { $this->component = $component; $use_html = ( $this->use_html && 'body' === $component ); $exclude_blank = ( $this->exclude_blank && 'body' === $component ); $template = $this->template; $component = isset( $template[$component] ) ? $template[$component] : ''; if ( $replace_tags ) { $component = $this->replace_tags( $component, array( 'html' => $use_html, 'exclude_blank' => $exclude_blank, ) ); if ( $use_html ) { // Convert to <example@example.com>. $component = preg_replace_callback( '/<(.*?)>/', static function ( $matches ) { if ( is_email( $matches[1] ) ) { return sprintf( '<%s>', $matches[1] ); } else { return $matches[0]; } }, $component ); if ( ! preg_match( '%\s].*%is', $component ) ) { $component = $this->htmlize( $component ); } } } $this->component = ''; return $component; } /** * Creates HTML message body by adding the header and footer. * * @param string $body The body part of HTML. * @return string Formatted HTML. */ private function htmlize( $body ) { if ( $this->locale ) { $lang_atts = sprintf( ' %s', wpcf7_format_atts( array( 'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr', 'lang' => str_replace( '_', '-', $this->locale ), ) ) ); } else { $lang_atts = ''; } $header = apply_filters( 'wpcf7_mail_html_header', ' ' . esc_html( $this->get( 'subject', true ) ) . ' ', $this ); $body = apply_filters( 'wpcf7_mail_html_body', $body, $this ); $footer = apply_filters( 'wpcf7_mail_html_footer', ' ', $this ); return $header . $body . $footer; } /** * Composes an email message and attempts to send it. * * @param bool $send Whether to attempt to send email. Default true. */ private function compose( $send = true ) { $components = array( 'subject' => $this->get( 'subject', true ), 'sender' => $this->get( 'sender', true ), 'body' => $this->get( 'body', true ), 'recipient' => $this->get( 'recipient', true ), 'additional_headers' => $this->get( 'additional_headers', true ), 'attachments' => $this->attachments(), ); $components = apply_filters( 'wpcf7_mail_components', $components, wpcf7_get_current_contact_form(), $this ); if ( ! $send ) { return $components; } $subject = wpcf7_strip_newline( $components['subject'] ); $sender = wpcf7_strip_newline( $components['sender'] ); $recipient = wpcf7_strip_newline( $components['recipient'] ); $body = $components['body']; $additional_headers = trim( $components['additional_headers'] ); $headers = "From: $sender\n"; if ( $this->use_html ) { $headers .= "Content-Type: text/html\n"; $headers .= "X-WPCF7-Content-Type: text/html\n"; } else { $headers .= "X-WPCF7-Content-Type: text/plain\n"; } if ( $additional_headers ) { $headers .= $additional_headers . "\n"; } $attachments = array_filter( (array) $components['attachments'], function ( $attachment ) { $path = path_join( WP_CONTENT_DIR, $attachment ); if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) { wp_trigger_error( '', sprintf( /* translators: %s: Attachment file path. */ __( 'Failed to attach a file. %s is not in the allowed directory.', 'contact-form-7' ), $path ), E_USER_NOTICE ); return false; } if ( ! is_readable( $path ) or ! is_file( $path ) ) { wp_trigger_error( '', sprintf( /* translators: %s: Attachment file path. */ __( 'Failed to attach a file. %s is not a readable file.', 'contact-form-7' ), $path ), E_USER_NOTICE ); return false; } static $total_size = array(); if ( ! isset( $total_size[$this->name] ) ) { $total_size[$this->name] = 0; } $file_size = (int) @filesize( $path ); if ( 25 * MB_IN_BYTES < $total_size[$this->name] + $file_size ) { wp_trigger_error( '', __( 'Failed to attach a file. The total file size exceeds the limit of 25 megabytes.', 'contact-form-7' ), E_USER_NOTICE ); return false; } $total_size[$this->name] += $file_size; return true; } ); return wp_mail( $recipient, $subject, $body, $headers, $attachments ); } /** * Replaces mail-tags within the given text. */ public function replace_tags( $content, $options = '' ) { if ( true === $options ) { $options = array( 'html' => true ); } $options = wp_parse_args( $options, array( 'html' => false, 'exclude_blank' => false, ) ); return wpcf7_mail_replace_tags( $content, $options ); } /** * Creates an array of attachments based on uploaded files and local files. */ private function attachments( $template = null ) { if ( ! $template ) { $template = $this->get( 'attachments' ); } $attachments = array(); if ( $submission = WPCF7_Submission::get_instance() ) { $uploaded_files = $submission->uploaded_files(); foreach ( (array) $uploaded_files as $name => $paths ) { if ( false !== strpos( $template, "[{$name}]" ) ) { $attachments = array_merge( $attachments, (array) $paths ); } } } foreach ( explode( "\n", $template ) as $line ) { $line = trim( $line ); if ( '' === $line or '[' === substr( $line, 0, 1 ) ) { continue; } $attachments[] = path_join( WP_CONTENT_DIR, $line ); } if ( $submission = WPCF7_Submission::get_instance() ) { $attachments = array_merge( $attachments, (array) $submission->extra_attachments( $this->name ) ); } return $attachments; } } /** * Replaces all mail-tags within the given text content. * * @param string $content Text including mail-tags. * @param string|array $options Optional. Output options. * @return string Result of replacement. */ function wpcf7_mail_replace_tags( $content, $options = '' ) { $options = wp_parse_args( $options, array( 'html' => false, 'exclude_blank' => false, ) ); if ( is_array( $content ) ) { foreach ( $content as $key => $value ) { $content[$key] = wpcf7_mail_replace_tags( $value, $options ); } return $content; } $content = explode( "\n", $content ); foreach ( $content as $num => $line ) { $line = new WPCF7_MailTaggedText( $line, $options ); $replaced = $line->replace_tags(); if ( $options['exclude_blank'] ) { $replaced_tags = $line->get_replaced_tags(); if ( empty( $replaced_tags ) or array_filter( $replaced_tags, 'strlen' ) ) { $content[$num] = $replaced; } else { unset( $content[$num] ); // Remove a line. } } else { $content[$num] = $replaced; } } $content = implode( "\n", $content ); return $content; } add_action( 'phpmailer_init', 'wpcf7_phpmailer_init', 10, 1 ); /** * Adds custom properties to the PHPMailer object. */ function wpcf7_phpmailer_init( $phpmailer ) { $custom_headers = $phpmailer->getCustomHeaders(); $phpmailer->clearCustomHeaders(); $wpcf7_content_type = false; foreach ( (array) $custom_headers as $custom_header ) { $name = $custom_header[0]; $value = $custom_header[1]; if ( 'X-WPCF7-Content-Type' === $name ) { $wpcf7_content_type = trim( $value ); } else { $phpmailer->addCustomHeader( $name, $value ); } } if ( 'text/html' === $wpcf7_content_type ) { $phpmailer->msgHTML( $phpmailer->Body ); } elseif ( 'text/plain' === $wpcf7_content_type ) { $phpmailer->AltBody = ''; } } /** * Class that represents a single-line text including mail-tags. */ class WPCF7_MailTaggedText { private $html = false; private $callback = null; private $content = ''; private $replaced_tags = array(); /** * The constructor method. */ public function __construct( $content, $options = '' ) { $options = wp_parse_args( $options, array( 'html' => false, 'callback' => null, ) ); $this->html = (bool) $options['html']; if ( null !== $options['callback'] and is_callable( $options['callback'] ) ) { $this->callback = $options['callback']; } elseif ( $this->html ) { $this->callback = array( $this, 'replace_tags_callback_html' ); } else { $this->callback = array( $this, 'replace_tags_callback' ); } $this->content = $content; } /** * Retrieves mail-tags that have been replaced by this instance. * * @return array List of mail-tags replaced. */ public function get_replaced_tags() { return $this->replaced_tags; } /** * Replaces mail-tags based on regexp. */ public function replace_tags() { $regex = '/(\[?)\[[\t ]*' . '([a-zA-Z_][0-9a-zA-Z:._-]*)' // [2] = name . '((?:[\t ]+"[^"]*"|[\t ]+\'[^\']*\')*)' // [3] = values . '[\t ]*\](\]?)/'; return preg_replace_callback( $regex, $this->callback, $this->content ); } /** * Callback function for replacement. For HTML message body. */ private function replace_tags_callback_html( $matches ) { return $this->replace_tags_callback( $matches, true ); } /** * Callback function for replacement. */ private function replace_tags_callback( $matches, $html = false ) { // allow [[foo]] syntax for escaping a tag if ( '[' === $matches[1] and ']' === $matches[4] ) { return substr( $matches[0], 1, -1 ); } $tag = $matches[0]; $tagname = $matches[2]; $values = $matches[3]; $mail_tag = new WPCF7_MailTag( $tag, $tagname, $values ); $field_name = $mail_tag->field_name(); $submission = WPCF7_Submission::get_instance(); $sub