Plugin Directory

Changeset 3821161


Ignore:
Timestamp:
11/24/2026 05:57:50 PM (less than one hour ago)
Author:
mariovalney
Message:

v5.2.0

Location:
cf7-to-zapier
Files:
21 added
8 edited

Legend:

Unmodified
Added
Removed
  • cf7-to-zapier/trunk/cf7-to-zapier.php

    r3820731 r3821161  
    88 * Plugin URI:        https://cf7-to-webhook.valney.dev
    99 * Description:       Use Contact Form 7 as a trigger to any Webhook.
    10  * Version:           5.1.1
     10 * Version:           5.2.0
    1111 * Author:            Mário Valney
    1212 * Author URI:        http://mariovalney.com/me
    1313 * Text Domain:       cf7-to-zapier
    1414 * Domain Path:       /languages
     15 * License:           GPLv2 or later
     16 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     17 * Requires at least: 4.7
     18 * Requires PHP:      7.4
    1519 *
    1620 */
    … …  
    6771         */
    6872        public function on_activation() {
    69             flush_rewrite_rules();
     73            // The plugin registers no rewrite rules yet. Flush again only after adding some.
     74            // flush_rewrite_rules();
    7075        }
    7176
    … …  
    181186        public function run() {
    182187            // Definitions to plugin
    183             define( 'CFTZ_VERSION', '5.1.1' );
     188            define( 'CFTZ_VERSION', '5.2.0' );
    184189            define( 'CFTZ_PLUGIN_FILE', __FILE__ );
    185190            define( 'CFTZ_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
  • cf7-to-zapier/trunk/includes/functions-debug.php

    r3221232 r3821161  
    2323}
    2424
     25/**
     26 * The debug helpers below have generic names that other libraries also use (dd, dump),
     27 * so they only exist when a developer asks for them with CFTZ_ADD_DEBUG_FUNCTIONS.
     28 * With them on, webhook errors are logged with dump_table() instead of emailed.
     29 */
    2530function cftz_activated_debug_functions() {
    26     return ctz_is_developing() && ! ( defined( 'CFTZ_REMOVE_DEBUG_FUNCTIONS' ) && CFTZ_REMOVE_DEBUG_FUNCTIONS );
     31    return ctz_is_developing() && defined( 'CFTZ_ADD_DEBUG_FUNCTIONS' ) && CFTZ_ADD_DEBUG_FUNCTIONS;
    2732}
    2833
  • cf7-to-zapier/trunk/modules/cf7/admin/assets/admin.css

    r3464704 r3821161  
    8181#webhook-panel .select2 {
    8282  width: 100% !important;
     83}
     84
     85/* A notice row in a form table, right above the setting it is about. Aligned with the row labels. */
     86#webhook-panel .form-table .ctz-row-notice td {
     87  padding: 20px 10px 0 0;
     88}
     89
     90/* Destructive action, like the block editor's "Move to trash" (components-button is-secondary is-destructive). */
     91#webhook-panel .button.ctz-button-destructive:not(:disabled) {
     92  color: #cc1818;
     93  border-color: #cc1818;
     94  background: transparent;
     95}
     96
     97#webhook-panel .button.ctz-button-destructive:not(:disabled):hover {
     98  color: #9e1313;
     99  border-color: #9e1313;
     100  background: rgba(204, 24, 24, 0.04);
     101}
     102
     103#webhook-panel .button.ctz-button-destructive:not(:disabled):active {
     104  background: rgba(204, 24, 24, 0.08);
     105}
     106
     107#webhook-panel .button.ctz-button-destructive:not(:disabled):focus {
     108  border-color: #cc1818;
     109  box-shadow: 0 0 0 1px #cc1818;
     110}
     111
     112/* The original select hidden by select2: WordPress 7 gives selects a min-height that keeps it 40px tall. */
     113#webhook-panel .select2-hidden-accessible {
     114  min-height: 0 !important;
     115  width: 0 !important;
    83116}
    84117
    … …  
    178211  margin: 0 0 3rem;
    179212  color: #FF4A00;
    180   font-size: 2rem;
     213  font-size: 1.7rem;
    181214  line-height: 1.4;
    182215  font-weight: 300;
  • cf7-to-zapier/trunk/modules/cf7/admin/assets/admin.js

    r3214555 r3821161  
    9494      ( has_headers ? CTZ_ADMIN.messages.confirm_all : CTZ_ADMIN.messages.confirm_body ),
    9595      function() {
    96         console.log('triggered');
    97 
    9896        $('#ctz-webhook-special_mail_tags').html('').trigger('change');
    9997        $('#ctz-webhook-custom_headers').html( has_headers ? template.headers.join('\n') : '' ).trigger('change');
    10098
    101         const fields = (CTZ_ADMIN_TAGS || []).map((tag) => `[${tag}]`).join(template.separator || ' | ');
     99        const fields = (window.CTZ_ADMIN_TAGS || []).map((tag) => `[${tag}]`).join(template.separator || ' | ');
    102100        $('#ctz-webhook-custom_body').html(template.body.replace('__VALUES__', fields)).trigger('change');
    103101
    104         if (! (template?.docs || false)) {
     102        // The link comes from the remote templates file: open only web addresses.
     103        if (! /^https?:\/\//i.test(template?.docs || '')) {
    105104          return;
    106105        }
    … …  
    112111      }
    113112    );
     113  });
     114
     115  // Delete uploaded files
     116  $('#ctz-webhook-delete-uploads').on('click', function(event) {
     117    event.preventDefault();
     118
     119    const button = $(this);
     120    const summary = $('#ctz-webhook-uploads-summary');
     121
     122    Confirm(CTZ_ADMIN.messages.confirm_delete_uploads, function() {
     123      button.prop('disabled', true);
     124
     125      $.post(ajaxurl, {
     126        action: 'ctz_delete_uploads',
     127        form_id: button.data('form-id'),
     128        nonce: button.data('nonce'),
     129      }).done(function(response) {
     130        if (! response.success) {
     131          summary.text(CTZ_ADMIN.messages.delete_uploads_error);
     132          return;
     133        }
     134
     135        summary.text(response.data.summary);
     136      }).fail(function() {
     137        summary.text(CTZ_ADMIN.messages.delete_uploads_error);
     138      }).always(function() {
     139        button.prop('disabled', false);
     140      });
     141    });
    114142  });
    115143
  • cf7-to-zapier/trunk/modules/cf7/admin/webhook-panel-html.php

    r3562678 r3821161  
    11<?php
    2 
    3 global $ctz_admin_tags_script;
    42
    53// If this file is called directly, call the cops.
    … …  
    6664}
    6765
    68 // Global footer script — registered via wp_add_inline_script to avoid raw echo of <script> blocks.
    69 wp_add_inline_script( 'ctz-admin-script', 'window.CTZ_ADMIN_TAGS = ' . json_encode( array_values( $form_tags ) ) . ';' );
    70 $ctz_admin_tags_script = '';
     66// Form tags for the templates. admin.js is printed in the footer, so this is still added in time.
     67wp_add_inline_script( 'ctz-admin-script', 'window.CTZ_ADMIN_TAGS = ' . wp_json_encode( array_values( $form_tags ) ) . ';', 'before' );
    7168
    7269/**
    … …  
    8178
    8279    <p class="donation-alert">
    83         <strong><?php _e( 'Give your support!', 'cf7-to-zapier' ); ?></strong>
     80        <strong><?php esc_html_e( 'Give your support!', 'cf7-to-zapier' ); ?></strong>
    8481        <?php
    8582            printf(
    … …  
    9390<?php endif; ?>
    9491
    95 <h1 class="ctz-section-title" class="ctz-section-title"><?php _e( 'Webhook', 'cf7-to-zapier' ) ?></h1>
     92<h1 class="ctz-section-title" class="ctz-section-title"><?php esc_html_e( 'Webhook', 'cf7-to-zapier' ) ?></h1>
    9693
    9794<fieldset>
    9895    <legend>
    99         <p><?php _e( 'In these options you can activate or deactivate Webhook integration.', 'cf7-to-zapier' ); ?></p>
    100         <p><?php _e( 'To integrate you should insert your webhook URL below. For example, into Zapier you can create a trigger using "Webhooks" app and choose "Catch Hook" option.', 'cf7-to-zapier' ); ?></p>
     96        <p><?php esc_html_e( 'In these options you can activate or deactivate Webhook integration.', 'cf7-to-zapier' ); ?></p>
     97        <p><?php esc_html_e( 'To integrate you should insert your webhook URL below. For example, into Zapier you can create a trigger using "Webhooks" app and choose "Catch Hook" option.', 'cf7-to-zapier' ); ?></p>
    10198    </legend>
    10299
    … …  
    106103                <th scope="row">
    107104                    <label>
    108                         <?php _e( 'Integrate', 'cf7-to-zapier' ) ?>
     105                        <?php esc_html_e( 'Integrate', 'cf7-to-zapier' ) ?>
    109106                    </label>
    110107                </th>
    … …  
    113110                        <label for="ctz-webhook-activate">
    114111                            <?php ctz_checkbox_input( 'activate', $activate ); ?>
    115                             <?php _e( 'Send to Webhook', 'cf7-to-zapier' ) ?>
     112                            <?php esc_html_e( 'Send to Webhook', 'cf7-to-zapier' ) ?>
    116113                        </label>
    117114                    </p>
    … …  
    121118                <th scope="row">
    122119                    <label>
    123                         <?php _e( 'Webhook URL', 'cf7-to-zapier' ) ?>
     120                        <?php esc_html_e( 'Webhook URL', 'cf7-to-zapier' ) ?>
    124121                    </label>
    125122                </th>
    … …  
    132129                    <?php if ( $activate && empty( $hook_url ) ): ?>
    133130                        <p class="description" style="color: #D00;">
    134                             <?php _e( 'You should insert webhook URL here to finish configuration.' ); ?>
     131                            <?php esc_html_e( 'You should insert webhook URL here to finish configuration.' ); ?>
    135132                        </p>
    136133                    <?php else: ?>
    137134                        <p class="description">
    138135                            <?php
    139                                 _e( 'You can add multiple webhook: one per line' );
     136                                esc_html_e( 'You can add multiple webhook: one per line' );
    140137
    141138                                echo '<br>';
    … …  
    154151</fieldset>
    155152
    156 <h1 class="ctz-section-title"><?php _e( 'Settings', 'cf7-to-zapier' ) ?></h1>
     153<h1 class="ctz-section-title"><?php esc_html_e( 'Settings', 'cf7-to-zapier' ) ?></h1>
    157154
    158155<fieldset>
    … …  
    162159                <th scope="row">
    163160                    <label>
    164                         <?php _e( 'Send Mail', 'cf7-to-zapier' ) ?>
     161                        <?php esc_html_e( 'Send Mail', 'cf7-to-zapier' ) ?>
    165162                    </label>
    166163                </th>
    … …  
    169166                        <label for="ctz-webhook-send_mail">
    170167                            <?php ctz_checkbox_input( 'send_mail', $send_mail ); ?>
    171                             <?php _e( 'Send CF7 mail as usually', 'cf7-to-zapier' ) ?>
     168                            <?php esc_html_e( 'Send CF7 mail as usually', 'cf7-to-zapier' ) ?>
    172169                        </label>
    173170                    </p>
    … …  
    177174                <th scope="row">
    178175                    <label>
    179                         <?php _e( 'Template', 'cf7-to-zapier' ) ?>
     176                        <?php esc_html_e( 'Template', 'cf7-to-zapier' ) ?>
    180177                    </label>
    181178                </th>
    … …  
    183180                    <p>
    184181                        <label for="ctz-webhook-template">
    185                             <select id="ctz-webhook-template" class="ctz-template-select"><option></option></select>
    186                             <p class="description"><?php _e( 'You can choose a template from community to update your header/body settings.', 'cf7-to-zapier' ) ?></p>
     182                            <select id="ctz-webhook-template" class="ctz-template-select"><option value="" selected></option></select>
     183                            <p class="description"><?php esc_html_e( 'You can choose a template from community to update your header/body settings.', 'cf7-to-zapier' ) ?></p>
    187184                        </label>
    188185                    </p>
    … …  
    196193    <div class="ctz-accordion-trigger">
    197194        <div>
    198             <h2><?php _e( 'Files', 'cf7-to-zapier' ) ?></h2>
    199             <p class="description"><?php _e( 'Define how you want to send files.', 'cf7-to-zapier' ) ?></p>
     195            <h2><?php esc_html_e( 'Files', 'cf7-to-zapier' ) ?></h2>
     196            <p class="description"><?php esc_html_e( 'Define how you want to send files.', 'cf7-to-zapier' ) ?></p>
    200197        </div>
    201198    </div>
    … …  
    208205                        <th scope="row">
    209206                            <label>
    210                                 <?php _e( 'Send content', 'cf7-to-zapier' ) ?>
     207                                <?php esc_html_e( 'Send content', 'cf7-to-zapier' ) ?>
    211208                            </label>
    212209                        </th>
    … …  
    215212                                <label for="ctz-webhook-files_send_content">
    216213                                    <?php ctz_checkbox_input( 'files_send_content', $files_send_content ); ?>
    217                                     <?php _e( 'Check to send file content insted of a link', 'cf7-to-zapier' ) ?>
     214                                    <?php esc_html_e( 'Check to send file content insted of a link', 'cf7-to-zapier' ) ?>
    218215                                </label>
    219216                            </p>
    … …  
    223220            </table>
    224221        </fieldset>
    225     </div>
    226 </div>
    227 
    228 <div class="ctz-accordion-wrapper">
    229     <div class="ctz-accordion-trigger">
    230         <div>
    231             <h2><?php _e( 'Special Mail Tags', 'cf7-to-zapier' ) ?></h2>
    232             <p class="description"><?php _e( 'When you need more information.', 'cf7-to-zapier' ) ?></p>
     222
     223        <p class="description ctz-mt3"><?php esc_html_e( 'More options for files in "Media", under Advanced settings.', 'cf7-to-zapier' ) ?></p>
     224    </div>
     225</div>
     226
     227<div class="ctz-accordion-wrapper">
     228    <div class="ctz-accordion-trigger">
     229        <div>
     230            <h2><?php esc_html_e( 'Special Mail Tags', 'cf7-to-zapier' ) ?></h2>
     231            <p class="description"><?php esc_html_e( 'When you need more information.', 'cf7-to-zapier' ) ?></p>
    233232        </div>
    234233    </div>
    … …  
    260259</div>
    261260
    262 <h1 class="ctz-section-title"><?php _e( 'Advanced settings', 'cf7-to-zapier' ) ?></h1>
    263 
    264 <div class="ctz-accordion-wrapper">
    265     <div class="ctz-accordion-trigger">
    266         <div>
    267             <h2><?php _e( 'Method', 'cf7-to-zapier' ) ?></h2>
    268             <p class="description"><?php _e( 'When you are not making a POST.', 'cf7-to-zapier' ) ?></p>
    269         </div>
    270     </div>
    271 
    272     <div class="ctz-accordion-content">
    273         <p class="description"><strong class="ctz-color-red"><?php _e( 'BE CAREFUL!', 'cf7-to-zapier' ) ?></strong> <?php _e( 'If you select GET, we will send your data as "query params" (if your body is not a valid JSON we will trigger a error).', 'cf7-to-zapier' ) ?></p>
     261<h1 class="ctz-section-title"><?php esc_html_e( 'Advanced settings', 'cf7-to-zapier' ) ?></h1>
     262
     263<div class="ctz-accordion-wrapper">
     264    <div class="ctz-accordion-trigger">
     265        <div>
     266            <h2><?php esc_html_e( 'Method', 'cf7-to-zapier' ) ?></h2>
     267            <p class="description"><?php esc_html_e( 'When you are not making a POST.', 'cf7-to-zapier' ) ?></p>
     268        </div>
     269    </div>
     270
     271    <div class="ctz-accordion-content">
     272        <p class="description"><strong class="ctz-color-red"><?php esc_html_e( 'BE CAREFUL!', 'cf7-to-zapier' ) ?></strong> <?php esc_html_e( 'If you select GET, we will send your data as "query params" (if your body is not a valid JSON we will trigger a error).', 'cf7-to-zapier' ) ?></p>
    274273
    275274        <fieldset>
    … …  
    279278                        <th scope="row">
    280279                            <label>
    281                                 <?php _e( 'Method', 'cf7-to-zapier' ) ?>
     280                                <?php esc_html_e( 'Method', 'cf7-to-zapier' ) ?>
    282281                            </label>
    283282                        </th>
    … …  
    286285                                <label for="ctz-custom_method">
    287286                                    <?php ctz_select_input( 'custom_method', $custom_method, [ 'GET', 'POST', 'PUT', 'PATCH', 'DELETE' ] ); ?>
    288                                     <p class="description"><?php _e( 'Choose a HTTP method. In general, you should not change this.', 'cf7-to-zapier' ); ?></p>
     287                                    <p class="description"><?php esc_html_e( 'Choose a HTTP method. In general, you should not change this.', 'cf7-to-zapier' ); ?></p>
    289288                                </label>
    290289                            </p>
    … …  
    301300    <div class="ctz-accordion-trigger">
    302301        <div>
    303             <h2><?php _e( 'Headers', 'cf7-to-zapier' ) ?></h2>
    304             <p class="description"><?php _e( 'When you need authentication/authorization.', 'cf7-to-zapier' ) ?></p>
    305         </div>
    306     </div>
    307 
    308     <div class="ctz-accordion-content">
    309         <p class="description ctz-mb3"><strong class="ctz-color-red"><?php _e( 'BE CAREFUL!', 'cf7-to-zapier' ) ?></strong> <?php _e( "This can break your integration (check spaces and colons).", 'cf7-to-zapier' ) ?></p>
     302            <h2><?php esc_html_e( 'Headers', 'cf7-to-zapier' ) ?></h2>
     303            <p class="description"><?php esc_html_e( 'When you need authentication/authorization.', 'cf7-to-zapier' ) ?></p>
     304        </div>
     305    </div>
     306
     307    <div class="ctz-accordion-content">
     308        <p class="description ctz-mb3"><strong class="ctz-color-red"><?php esc_html_e( 'BE CAREFUL!', 'cf7-to-zapier' ) ?></strong> <?php esc_html_e( "This can break your integration (check spaces and colons).", 'cf7-to-zapier' ) ?></p>
    310309
    311310        <fieldset>
    … …  
    340339    <div class="ctz-accordion-trigger">
    341340        <div>
    342             <h2><?php _e( 'Body', 'cf7-to-zapier' ) ?></h2>
    343             <p class="description"><?php _e( 'When you need customize your request.', 'cf7-to-zapier' ) ?></p>
    344         </div>
    345     </div>
    346 
    347     <div class="ctz-accordion-content">
    348         <p class="description"><strong class="ctz-color-red"><?php _e( 'BE CAREFUL!', 'cf7-to-zapier' ) ?></strong> <?php _e( "This can break your integration (check your quotes).", 'cf7-to-zapier' ) ?></p>
    349         <p class="description ctz-mb3"><strong><?php _e( 'REMEMBER:', 'cf7-to-zapier' ) ?></strong> <?php printf( __( 'You can change field name with webhook config: %s', 'cf7-to-zapier' ), '<span style="font-family: monospace; font-size: 12px; font-weight: bold;">[email* your_email webhook:email]</span>' ); ?></p>
    350 
    351         <p class="description"><?php _e( 'To create your own body, you can replace values like in mail body (case sensitive).', 'cf7-to-zapier' ); ?></p>
    352         <p class="description"><?php _e( 'You should provide your own "quotes" for strings/text (use only the mail tag without quotes for "checkbox" and "acceptance" fields).', 'cf7-to-zapier' ); ?></p>
    353         <p class="description"><?php _e( 'For example:', 'cf7-to-zapier' ); ?></p>
     341            <h2><?php esc_html_e( 'Body', 'cf7-to-zapier' ) ?></h2>
     342            <p class="description"><?php esc_html_e( 'When you need customize your request.', 'cf7-to-zapier' ) ?></p>
     343        </div>
     344    </div>
     345
     346    <div class="ctz-accordion-content">
     347        <p class="description"><strong class="ctz-color-red"><?php esc_html_e( 'BE CAREFUL!', 'cf7-to-zapier' ) ?></strong> <?php esc_html_e( "This can break your integration (check your quotes).", 'cf7-to-zapier' ) ?></p>
     348        <p class="description ctz-mb3"><strong><?php esc_html_e( 'REMEMBER:', 'cf7-to-zapier' ) ?></strong> <?php printf( __( 'You can change field name with webhook config: %s', 'cf7-to-zapier' ), '<span style="font-family: monospace; font-size: 12px; font-weight: bold;">[email* your_email webhook:email]</span>' ); ?></p>
     349
     350        <p class="description"><?php esc_html_e( 'To create your own body, you can replace values like in mail body (case sensitive).', 'cf7-to-zapier' ); ?></p>
     351        <p class="description"><?php esc_html_e( 'You should provide your own "quotes" for strings/text (use only the mail tag without quotes for "checkbox" and "acceptance" fields).', 'cf7-to-zapier' ); ?></p>
     352        <p class="description"><?php esc_html_e( 'For example:', 'cf7-to-zapier' ); ?></p>
    354353        <pre>{
    355354    "composed-message": "Sir [your-name] from [your-city].",
    … …  
    359358}</pre>
    360359
    361         <p class="description ctz-mt3"><?php _e( 'Enter your custom body:', 'cf7-to-zapier' ); ?></p>
     360        <p class="description ctz-mt3"><?php esc_html_e( 'Enter your custom body:', 'cf7-to-zapier' ); ?></p>
    362361        <fieldset>
    363362            <label for="ctz-custom_body">
    … …  
    368367        <fieldset class="ctz-mt3">
    369368            <legend>
    370                 <?php $body_preview_is_json ? _e( 'We will send your form data as JSON:', 'cf7-to-zapier' ) : _e( 'We will send your form data as plain/text:', 'cf7-to-zapier' ); ?>
     369                <?php $body_preview_is_json ? esc_html_e( 'We will send your form data as JSON:', 'cf7-to-zapier' ) : esc_html_e( 'We will send your form data as plain/text:', 'cf7-to-zapier' ); ?>
    371370            </legend>
    372371            <pre id="ctz-webhook-preview"><?php echo $body_preview_is_json ? esc_html( json_encode( $body_preview, JSON_PRETTY_PRINT ) ) : esc_html( $body_preview ); ?></pre>
    373             <p class="description"><?php _e( 'This is just a example of field names and will not reflect data or customizations.', 'cf7-to-zapier' ); ?></p>
    374         </fieldset>
    375     </div>
    376 </div>
    377 
    378 <div class="ctz-accordion-wrapper">
    379     <div class="ctz-accordion-trigger">
    380         <div>
    381             <h2><?php _e( 'Errors', 'cf7-to-zapier' ) ?></h2>
    382             <p class="description"><?php _e( 'How we handle errors.', 'cf7-to-zapier' ) ?></p>
    383         </div>
    384     </div>
    385 
    386     <div class="ctz-accordion-content ctz-b0">
     372            <p class="description"><?php esc_html_e( 'This is just a example of field names and will not reflect data or customizations.', 'cf7-to-zapier' ); ?></p>
     373        </fieldset>
     374    </div>
     375</div>
     376
     377<div class="ctz-accordion-wrapper">
     378    <div class="ctz-accordion-trigger">
     379        <div>
     380            <h2><?php esc_html_e( 'Media', 'cf7-to-zapier' ) ?></h2>
     381            <p class="description"><?php esc_html_e( 'When you need to keep uploaded files.', 'cf7-to-zapier' ) ?></p>
     382        </div>
     383    </div>
     384
     385    <div class="ctz-accordion-content">
    387386        <fieldset>
    388387            <table class="form-table">
    … …  
    391390                        <th scope="row">
    392391                            <label>
    393                                 <?php _e( 'Notification', 'cf7-to-zapier' ) ?>
     392                                <?php esc_html_e( 'Add to Library', 'cf7-to-zapier' ) ?>
     393                            </label>
     394                        </th>
     395                        <td>
     396                            <p>
     397                                <label for="ctz-webhook-add_to_library">
     398                                    <?php ctz_checkbox_input( 'add_to_library', $add_to_library ); ?>
     399                                    <?php esc_html_e( 'Check to add files to library', 'cf7-to-zapier' ) ?>
     400                                </label>
     401                            </p>
     402                            <p class="description"><?php esc_html_e( 'Files are added as private media (only administrators and editors see them in the library), even when sending file content. Their URLs are public (but hard to guess), like the links sent to the webhook.', 'cf7-to-zapier' ) ?> <a href="https://cf7-to-webhook.valney.dev/docs/features/media-library" target="_blank" rel="noopener"><?php esc_html_e( 'Read more', 'cf7-to-zapier' ) ?></a></p>
     403                        </td>
     404                    </tr>
     405                    <?php if ( $contactform->id() ) : ?>
     406                    <tr class="ctz-row-notice">
     407                        <td colspan="2">
     408                            <p class="description"><strong class="ctz-color-red"><?php esc_html_e( 'BE CAREFUL!', 'cf7-to-zapier' ) ?></strong> <?php esc_html_e( 'Deletes the files of every submission of this form, sent as links or added to the media library.', 'cf7-to-zapier' ) ?></p>
     409                        </td>
     410                    </tr>
     411                    <tr>
     412                        <th scope="row">
     413                            <label>
     414                                <?php esc_html_e( 'Delete files', 'cf7-to-zapier' ) ?>
     415                            </label>
     416                        </th>
     417                        <td>
     418                            <p>
     419                                <button type="button" class="button ctz-button-destructive" id="ctz-webhook-delete-uploads" data-form-id="<?php echo esc_attr( $contactform->id() ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'ctz_delete_uploads_' . $contactform->id() ) ); ?>" <?php disabled( ! current_user_can( 'manage_options' ) ); ?>><?php esc_html_e( 'Delete all files', 'cf7-to-zapier' ) ?></button>
     420                            </p>
     421                            <?php if ( ! current_user_can( 'manage_options' ) ) : ?>
     422                            <p class="description"><?php esc_html_e( 'Only administrators can delete files.', 'cf7-to-zapier' ) ?></p>
     423                            <?php endif; ?>
     424                            <p class="description" id="ctz-webhook-uploads-summary"><?php echo esc_html( CFTZ_Module_CF7::get_uploads_summary_text( $contactform->id() ) ); ?></p>
     425                        </td>
     426                    </tr>
     427                    <?php endif; ?>
     428                </tbody>
     429            </table>
     430        </fieldset>
     431    </div>
     432</div>
     433
     434<div class="ctz-accordion-wrapper">
     435    <div class="ctz-accordion-trigger">
     436        <div>
     437            <h2><?php esc_html_e( 'Errors', 'cf7-to-zapier' ) ?></h2>
     438            <p class="description"><?php esc_html_e( 'How we handle errors.', 'cf7-to-zapier' ) ?></p>
     439        </div>
     440    </div>
     441
     442    <div class="ctz-accordion-content ctz-b0">
     443        <fieldset>
     444            <table class="form-table">
     445                <tbody>
     446                    <tr>
     447                        <th scope="row">
     448                            <label>
     449                                <?php esc_html_e( 'Notification', 'cf7-to-zapier' ) ?>
    394450                            </label>
    395451                        </th>
    … …  
    401457                            </p>
    402458                            <p class="description">
    403                                 <?php _e( 'One or more emails (separated by comma) to be notified on webhook error.', 'cf7-to-zapier' ) ?>
     459                                <?php esc_html_e( 'One or more emails (separated by comma) to be notified on webhook error.', 'cf7-to-zapier' ) ?>
    404460                            </p>
    405461                        </td>
    … …  
    408464                        <th scope="row">
    409465                            <label>
    410                                 <?php _e( 'Success Codes', 'cf7-to-zapier' ) ?>
     466                                <?php esc_html_e( 'Success Codes', 'cf7-to-zapier' ) ?>
    411467                            </label>
    412468                        </th>
    … …  
    428484</div>
    429485
    430 <h1 class="ctz-section-title"><?php _e( 'Help', 'cf7-to-zapier' ) ?></h1>
    431 
    432 <div class="ctz-accordion-wrapper">
    433     <div class="ctz-accordion-trigger">
    434         <div>
    435             <h2><?php _e( 'URL Params', 'cf7-to-zapier' ) ?></h2>
    436             <p class="description"><?php _e( 'Send data in your URL.', 'cf7-to-zapier' ); ?></p>
     486<h1 class="ctz-section-title"><?php esc_html_e( 'Help', 'cf7-to-zapier' ) ?></h1>
     487
     488<div class="ctz-accordion-wrapper">
     489    <div class="ctz-accordion-trigger">
     490        <div>
     491            <h2><?php esc_html_e( 'URL Params', 'cf7-to-zapier' ) ?></h2>
     492            <p class="description"><?php esc_html_e( 'Send data in your URL.', 'cf7-to-zapier' ); ?></p>
    437493        </div>
    438494    </div>
    … …  
    445501
    446502            <pre><?php
    447                 _e( 'To get utm_source: https://example.com/?utm_source=example', 'cf7-to-zapier' );
     503                esc_html_e( 'To get utm_source: https://example.com/?utm_source=example', 'cf7-to-zapier' );
    448504                echo "\n";
    449                 _e( 'Use this shortcode: [hidden utm_source default:get]', 'cf7-to-zapier' );
     505                esc_html_e( 'Use this shortcode: [hidden utm_source default:get]', 'cf7-to-zapier' );
    450506            ?></pre>
    451507        </fieldset>
    … …  
    456512    <div class="ctz-accordion-trigger">
    457513        <div>
    458             <h2><?php _e( 'FAQ', 'cf7-to-zapier' ) ?></h2>
    459             <p class="description"><?php _e( 'You can check more information or search for help.', 'cf7-to-zapier' ); ?></p>
     514            <h2><?php esc_html_e( 'FAQ', 'cf7-to-zapier' ) ?></h2>
     515            <p class="description"><?php esc_html_e( 'You can check more information or search for help.', 'cf7-to-zapier' ); ?></p>
    460516        </div>
    461517    </div>
    … …  
    463519    <div class="ctz-accordion-content ctz-b0">
    464520        <ul class="faq-list">
    465             <li><a target="_blank" href="https://github.com/mariovalney/cf7-to-zapier/issues/19"><?php _e( 'How to make multiple webhooks optionals?', 'cf7-to-zapier' ); ?></a></li>
    466             <li><a target="_blank" href="https://wordpress.org/plugins/cf7-to-zapier/#faq"><?php _e( 'Check FAQ from plugin page.', 'cf7-to-zapier' ); ?></a></li>
    467             <li class="new-topic"><?php _e( 'Or...', 'cf7-to-zapier' ); ?> <a target="_blank" href="https://wordpress.org/support/plugin/cf7-to-zapier/#new-topic-0"><?php _e( 'ask a question!', 'cf7-to-zapier' ); ?></a></li>
     521            <li><a target="_blank" href="https://github.com/mariovalney/cf7-to-zapier/issues/19"><?php esc_html_e( 'How to make multiple webhooks optionals?', 'cf7-to-zapier' ); ?></a></li>
     522            <li><a target="_blank" href="https://wordpress.org/plugins/cf7-to-zapier/#faq"><?php esc_html_e( 'Check FAQ from plugin page.', 'cf7-to-zapier' ); ?></a></li>
     523            <li class="new-topic"><?php esc_html_e( 'Or...', 'cf7-to-zapier' ); ?> <a target="_blank" href="https://wordpress.org/support/plugin/cf7-to-zapier/#new-topic-0"><?php esc_html_e( 'ask a question!', 'cf7-to-zapier' ); ?></a></li>
    468524        </ul>
    469525    </div>
  • cf7-to-zapier/trunk/modules/cf7/class-module-cf7.php

    r3820731 r3821161  
    6565            $this->core->add_action( 'admin_notices', [ $this, 'check_cf7_plugin' ] );
    6666            $this->core->add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
    67             $this->core->add_action( 'admin_print_footer_scripts', [ $this, 'admin_print_footer_scripts' ] );
     67            $this->core->add_action( 'wp_ajax_ctz_delete_uploads', [ $this, 'wp_ajax_ctz_delete_uploads' ] );
    6868        }
    6969
    … …  
    9393            }
    9494
    95             if ( file_exists( ABSPATH . PLUGINDIR . '/contact-form-7/wp-contact-form-7.php' ) ) {
     95            if ( file_exists( WP_PLUGIN_DIR . '/contact-form-7/wp-contact-form-7.php' ) ) {
    9696                $url = 'plugins.php';
    9797            } else {
    … …  
    9999            }
    100100
    101             echo '. <a href="' . admin_url( $url ) . '">' . __( "Do it now?", "cf7-to-zapier" ) . '</a></p>';
     101            echo '. <a href="' . esc_url( admin_url( $url ) ) . '">' . esc_html__( 'Do it now?', 'cf7-to-zapier' ) . '</a></p>';
    102102            echo '</div>';
    103103        }
    … …  
    122122
    123123            wp_enqueue_script( 'ctz-select2-script', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.9/js/select2.min.js', [ 'jquery' ], $version );
    124             wp_enqueue_script( 'ctz-admin-script', CFTZ_PLUGIN_URL . '/modules/cf7/admin/assets/admin.js', [ 'ctz-select2-script' ], $version );
    125 
    126             // For developers: in your enviroment make "/ci/website/public" point to "/cf7-to-webhook-valney-dev"
    127             $templates_url = ctz_is_developing() ? home_url( '/cf7-to-webhook-valney-dev/templates.json' ) : 'https://cf7-to-webhook.valney.dev/templates.json';
     124            // In the footer: the webhook panel adds CTZ_ADMIN_TAGS to it with wp_add_inline_script()
     125            // while rendering, and a script printed in the header would have gone out without it.
     126            wp_enqueue_script( 'ctz-admin-script', CFTZ_PLUGIN_URL . '/modules/cf7/admin/assets/admin.js', [ 'ctz-select2-script' ], $version, true );
     127
     128            // A repository checkout loads the templates from the website files, so changes show up before deploy.
     129            // Released copies do not ship ci/ and always load the published file, even with WP_DEBUG on.
     130            $templates_url = 'https://cf7-to-webhook.valney.dev/templates.json';
     131            if ( ctz_is_developing() && file_exists( CFTZ_PLUGIN_PATH . '/ci/website/public/templates.json' ) ) {
     132                $templates_url = CFTZ_PLUGIN_URL . '/ci/website/public/templates.json';
     133            }
     134
    128135            wp_localize_script( 'ctz-admin-script', 'CTZ_ADMIN', array(
    129136                'templates_url' => $templates_url,
    … …  
    132139                ),
    133140                'messages'      => array(
    134                     'open_docs'         => __( 'This template has documentation. Want to open (another tab)?', 'cf7-to-zapier' ),
    135                     'confirm_all'       => __( 'This action will replace "Headers" and "Body" and remove "Special Mail Tags".', 'cf7-to-zapier' ),
    136                     'confirm_body'      => __( 'This action will replace "Body" and remove "Special Mail Tags" and "Headers".', 'cf7-to-zapier' ),
    137                     'save_to_preview'   => __( 'Save to load preview.', 'cf7-to-zapier' ),
    138                     'btn_no'            => __( 'No', 'cf7-to-zapier' ),
    139                     'btn_yes'           => __( 'Yes', 'cf7-to-zapier' ),
    140                     'btn_cancel'        => __( 'Cancel', 'cf7-to-zapier' ),
    141                     'btn_continue'      => __( 'Continue', 'cf7-to-zapier' ),
    142                     'choose_template'   => __( 'Choose a template', 'cf7-to-zapier' ),
     141                    'open_docs'              => __( 'This template has documentation.', 'cf7-to-zapier' ) . '<br>' . __( 'Open in another tab?', 'cf7-to-zapier' ),
     142                    'confirm_all'            => __( 'This action will replace "Headers" and "Body" and remove "Special Mail Tags".', 'cf7-to-zapier' ),
     143                    'confirm_body'           => __( 'This action will replace "Body" and remove "Special Mail Tags" and "Headers".', 'cf7-to-zapier' ),
     144                    'save_to_preview'        => __( 'Save to load preview.', 'cf7-to-zapier' ),
     145                    'btn_no'                 => __( 'No', 'cf7-to-zapier' ),
     146                    'btn_yes'                => __( 'Yes', 'cf7-to-zapier' ),
     147                    'btn_cancel'             => __( 'Cancel', 'cf7-to-zapier' ),
     148                    'btn_continue'           => __( 'Continue', 'cf7-to-zapier' ),
     149                    'choose_template'        => __( 'Choose a template', 'cf7-to-zapier' ),
     150                    'confirm_delete_uploads' => __( 'This action will delete all files uploaded with this form since always.', 'cf7-to-zapier' ) . '<br>' . __( 'Links sent to webhook will stop working.', 'cf7-to-zapier' ),
     151                    'delete_uploads_error'   => __( 'The files could not be deleted. Reload the page and try again.', 'cf7-to-zapier' ),
    143152                ),
    144153            ) );
    … …  
    146155
    147156        /**
    148          * Action: 'admin_print_footer_scripts'
     157         * Action: 'wp_ajax_ctz_delete_uploads'
     158         *
     159         * Delete every file uploaded with a form: its media library attachments and its
     160         * folder in the uploads, with everything inside.
     161         *
     162         * @since    5.2.0
    149163         *
    150164         * @return void
    151165         */
    152         public function admin_print_footer_scripts() {
    153             global $ctz_admin_tags_script;
    154             echo $ctz_admin_tags_script;
     166        public function wp_ajax_ctz_delete_uploads() {
     167            $form_id = absint( $_POST['form_id'] ?? 0 );
     168
     169            // Only administrators: it deletes files that other users and webhooks may still need.
     170            if ( ! check_ajax_referer( 'ctz_delete_uploads_' . $form_id, 'nonce', false ) || ! current_user_can( 'manage_options' ) ) {
     171                wp_send_json_error( null, 403 );
     172            }
     173
     174            if ( empty( $form_id ) || ! wpcf7_contact_form( $form_id ) ) {
     175                wp_send_json_error( null, 404 );
     176            }
     177
     178            foreach ( self::get_upload_attachments( $form_id ) as $attachment_id ) {
     179                wp_delete_attachment( $attachment_id, true );
     180            }
     181
     182            self::delete_upload_dir( $form_id );
     183
     184            wp_send_json_success( array(
     185                'summary' => self::get_uploads_summary_text( $form_id ),
     186            ) );
    155187        }
    156188
    … …  
    430462         */
    431463        private function trigger_error_notification( $error_mails, $contact_form, $hook_url, $exception, $data = [] ) {
    432             if ( empty( $error_mails ) && ! ctz_is_developing() ) {
     464            if ( empty( $error_mails ) && ! cftz_activated_debug_functions() ) {
    433465                return;
    434466            }
    … …  
    462494            );
    463495
    464             // Log in development
    465             if ( ctz_is_developing() && function_exists( 'dump_table' ) ) {
     496            // Log in development, only when the debug helpers were asked for (CFTZ_ADD_DEBUG_FUNCTIONS)
     497            if ( cftz_activated_debug_functions() && function_exists( 'dump_table' ) ) {
    466498                dump_table( $replacements );
    467499                return;
    … …  
    557589                    $files = $uploaded_files[ $tag->name ];
    558590
     591                    $send_content   = ! empty( $properties['files_send_content'] );
     592                    $add_to_library = ! empty( $properties['add_to_library'] );
     593
    559594                    $copied_files = [];
    560595                    foreach ( (array) $files as $file ) {
     596                        // CF7 deletes its upload at the end of the request, so links and the media library need a copy.
     597                        $copy = '';
     598                        if ( ! $send_content || $add_to_library ) {
     599                            wp_mkdir_p( $upload_dir );
     600                            $this->protect_upload_dirs( array(
     601                                $wp_upload_dir['basedir'] . '/' . CFTZ_UPLOAD_DIR,
     602                                $wp_upload_dir['basedir'] . '/' . CFTZ_UPLOAD_DIR . '/' . $contact_form->id(),
     603                                $upload_dir,
     604                            ) );
     605
     606                            $filename = wp_unique_filename( $upload_dir, $tag->name . '-' . basename( $file ) );
     607
     608                            if ( copy( $file, $upload_dir . '/' . $filename ) ) {
     609                                $copy = $upload_dir . '/' . $filename;
     610                            }
     611                        }
     612
     613                        if ( $copy && $add_to_library ) {
     614                            $this->add_file_to_library( $copy, $contact_form, $tag->name );
     615                        }
     616
    561617                        // Send file content
    562                         if ( ! empty( $properties['files_send_content'] ) ) {
     618                        if ( $send_content ) {
    563619                            $file_content = file_get_contents( $file );
    564620                            $file_content = base64_encode( $file_content );
    … …  
    573629
    574630                        // Send file link
    575                         wp_mkdir_p( $upload_dir );
    576 
    577                         $filename = wp_unique_filename( $upload_dir, $tag->name . '-' . basename( $file ) );
    578 
    579                         if ( ! copy( $file, $upload_dir . '/' . $filename ) ) {
     631                        if ( ! $copy ) {
    580632                            $submission = WPCF7_Submission::get_instance();
    581633                            $submission->set_status( 'mail_failed' );
    … …  
    760812
    761813            return $tag->pipes->do_pipe( wp_unslash( $value ) );
     814        }
     815
     816        /**
     817         * Add a copied upload to the media library as a private attachment.
     818         *
     819         * WordPress would create resized copies and a "-scaled" or "-rotated" version next to
     820         * the file, and point the attachment to them. The filters turn that off, so the
     821         * attachment keeps the same file and URL sent to the webhook.
     822         *
     823         * @since    5.2.0
     824         *
     825         * @param    string             $path           Absolute path of the copied file
     826         * @param    WPCF7_ContactForm  $contact_form   ContactForm Obj
     827         * @param    string             $field          Name of the file field
     828         * @return   int                $attachment_id  Attachment ID or 0 if it was not added
     829         */
     830        private function add_file_to_library( $path, $contact_form, $field ) {
     831            // Every file type goes in: the file is already public in the uploads folder. CF7 has
     832            // renamed risky extensions (svg, html, js, php...) to ".txt". The content check gives
     833            // the real type, and a file whose content does not match its extension, or that
     834            // WordPress does not know, is stored as a generic binary file.
     835            $filetype  = wp_check_filetype_and_ext( $path, basename( $path ), wp_get_mime_types() );
     836            $mime_type = ! empty( $filetype['type'] ) ? $filetype['type'] : 'application/octet-stream';
     837
     838            $attachment_id = wp_insert_attachment( array(
     839                'post_title'     => sanitize_text_field( pathinfo( $path, PATHINFO_FILENAME ) ),
     840                'post_mime_type' => $mime_type,
     841                'post_status'    => 'private',
     842            ), $path, 0, true );
     843
     844            if ( is_wp_error( $attachment_id ) ) {
     845                return 0;
     846            }
     847
     848            update_post_meta( $attachment_id, '_ctz_contact_form_id', $contact_form->id() );
     849            update_post_meta( $attachment_id, '_ctz_field', $field );
     850
     851            require_once ABSPATH . 'wp-admin/includes/image.php';
     852            require_once ABSPATH . 'wp-admin/includes/media.php';
     853
     854            add_filter( 'intermediate_image_sizes_advanced', '__return_empty_array', 999 );
     855            add_filter( 'fallback_intermediate_image_sizes', '__return_empty_array', 999 );
     856            add_filter( 'big_image_size_threshold', '__return_false', 999 );
     857            add_filter( 'wp_image_maybe_exif_rotate', '__return_false', 999 );
     858
     859            wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $path ) );
     860
     861            remove_filter( 'intermediate_image_sizes_advanced', '__return_empty_array', 999 );
     862            remove_filter( 'fallback_intermediate_image_sizes', '__return_empty_array', 999 );
     863            remove_filter( 'big_image_size_threshold', '__return_false', 999 );
     864            remove_filter( 'wp_image_maybe_exif_rotate', '__return_false', 999 );
     865
     866            return $attachment_id;
     867        }
     868
     869        /**
     870         * Absolute path of the folder with the files uploaded with a form.
     871         *
     872         * @since    5.2.0
     873         *
     874         * @param    int                $form_id    Contact form ID
     875         * @return   string
     876         */
     877        public static function get_upload_dir( $form_id ) {
     878            return wp_get_upload_dir()['basedir'] . '/' . CFTZ_UPLOAD_DIR . '/' . absint( $form_id );
     879        }
     880
     881        /**
     882         * IDs of the media library attachments created from a form's uploads.
     883         *
     884         * @since    5.2.0
     885         *
     886         * @param    int                $form_id    Contact form ID
     887         * @return   array
     888         */
     889        public static function get_upload_attachments( $form_id ) {
     890            return get_posts( array(
     891                'post_type'   => 'attachment',
     892                'post_status' => array( 'inherit', 'private', 'trash' ),
     893                'numberposts' => -1,
     894                'fields'      => 'ids',
     895                'meta_key'    => '_ctz_contact_form_id',
     896                'meta_value'  => absint( $form_id ),
     897            ) );
     898        }
     899
     900        /**
     901         * Files, total size and media library attachments uploaded with a form.
     902         *
     903         * @since    5.2.0
     904         *
     905         * @param    int                $form_id    Contact form ID
     906         * @return   array              { files, size, attachments }
     907         */
     908        public static function get_uploads_summary( $form_id ) {
     909            $files = 0;
     910            $size  = 0;
     911            $dir   = self::get_upload_dir( $form_id );
     912
     913            if ( is_dir( $dir ) ) {
     914                $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ) );
     915
     916                foreach ( $iterator as $file ) {
     917                    // The index.php files only protect the folders.
     918                    if ( ! $file->isFile() || 'index.php' === $file->getFilename() ) {
     919                        continue;
     920                    }
     921
     922                    $files++;
     923                    $size += $file->getSize();
     924                }
     925            }
     926
     927            return array(
     928                'files'       => $files,
     929                'size'        => $size,
     930                'attachments' => count( self::get_upload_attachments( $form_id ) ),
     931            );
     932        }
     933
     934        /**
     935         * Text for the webhook panel with the summary of a form's uploads.
     936         *
     937         * @since    5.2.0
     938         *
     939         * @param    int                $form_id    Contact form ID
     940         * @return   string
     941         */
     942        public static function get_uploads_summary_text( $form_id ) {
     943            $summary = self::get_uploads_summary( $form_id );
     944
     945            if ( empty( $summary['files'] ) && empty( $summary['attachments'] ) ) {
     946                return __( 'No files uploaded with this form.', 'cf7-to-zapier' );
     947            }
     948
     949            return sprintf(
     950                /* translators: 1: number of files, 2: total size, 3: number of media library items */
     951                __( '%1$s (%2$s), %3$s in the media library.', 'cf7-to-zapier' ),
     952                sprintf( _n( '%s file', '%s files', $summary['files'], 'cf7-to-zapier' ), number_format_i18n( $summary['files'] ) ),
     953                size_format( $summary['size'] ),
     954                number_format_i18n( $summary['attachments'] )
     955            );
     956        }
     957
     958        /**
     959         * Delete a form's upload folder with everything inside.
     960         *
     961         * The real path must be inside the plugin upload folder, so a wrong path or a link
     962         * cannot delete anything else.
     963         *
     964         * @since    5.2.0
     965         *
     966         * @param    int                $form_id    Contact form ID
     967         * @return   void
     968         */
     969        private static function delete_upload_dir( $form_id ) {
     970            $base = realpath( wp_get_upload_dir()['basedir'] . '/' . CFTZ_UPLOAD_DIR );
     971            $dir  = realpath( self::get_upload_dir( $form_id ) );
     972
     973            if ( empty( $base ) || empty( $dir ) || 0 !== strpos( $dir, $base . DIRECTORY_SEPARATOR ) ) {
     974                return;
     975            }
     976
     977            $iterator = new RecursiveIteratorIterator(
     978                new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ),
     979                RecursiveIteratorIterator::CHILD_FIRST
     980            );
     981
     982            foreach ( $iterator as $item ) {
     983                if ( $item->isDir() && ! $item->isLink() ) {
     984                    rmdir( $item->getPathname() );
     985                    continue;
     986                }
     987
     988                wp_delete_file( $item->getPathname() );
     989            }
     990
     991            rmdir( $dir );
     992        }
     993
     994        /**
     995         * Add an empty index.php to upload folders.
     996         *
     997         * A server with directory listing on would show every submission from the base
     998         * and form folders, and every file of a submission from its own folder.
     999         *
     1000         * @since    5.2.0
     1001         *
     1002         * @param    array              $dirs       Absolute folder paths
     1003         * @return   void
     1004         */
     1005        private function protect_upload_dirs( $dirs ) {
     1006            foreach ( $dirs as $dir ) {
     1007                $index = $dir . '/index.php';
     1008
     1009                if ( is_dir( $dir ) && ! file_exists( $index ) ) {
     1010                    file_put_contents( $index, "<?php\n// Silence is golden.\n" );
     1011                }
     1012            }
    7621013        }
    7631014
    … …  
    8631114                [
    8641115                    'key'     => 'files_send_content',
     1116                    'default' => '0',
     1117                    'type'    => 'checkbox',
     1118                ],
     1119                [
     1120                    'key'     => 'add_to_library',
    8651121                    'default' => '0',
    8661122                    'type'    => 'checkbox',
  • cf7-to-zapier/trunk/modules/zapier/class-module-zapier.php

    r3820731 r3821161  
    264264                        $value = apply_filters( 'wpcf7_special_mail_tags', $value, $tag, false, $mail_tag );
    265265
     266                        // Form data must not add lines to the request: a line break would start a new header.
     267                        $value = preg_replace( '/[\x00-\x1F\x7F]+/', ' ', (string) $value );
     268
    266269                        $header_value = str_replace( $placeholder, $value, $header_value );
    267270                    }
  • cf7-to-zapier/trunk/readme.txt

    r3820731 r3821161  
    66Requires at least: 4.7
    77Tested up to: 7.1.5
    8 Stable tag: 5.1.1
     8Stable tag: 5.2.0
    99Requires PHP: 7.4
    1010License: GPLv2 or later
    … …  
    4949= Support =
    5050
    51 * Contact Form 7 - 6.1.5
     51* Contact Form 7 - 6.2.6
    5252
    5353Tested with other plugins:
    5454
    5555* MultiLine files for Contact Form 7 - 2.9.1
    56 * Contact Form 7 Multi-Step Forms - 4.6
     56* Contact Form 7 Multi-Step Forms - 4.8.1
    5757
    5858== Installation ==
    … …  
    9898Just add one webhook per line in "Webhook URL" settings.
    9999
    100 Please, read [this topic](https://cf7-to-webhook.valney.dev/docs/make-multiple-webhooks-optionals) for more information.
     100Please, read [this topic](https://cf7-to-webhook.valney.dev/docs/how-to/make-multiple-webhooks-optionals) for more information.
    101101
    102102= How can I show webhook errors on form submit? =
    … …  
    108108If you send a form with file, we will copy this to a directory before CF7 remove it and send the link to Zapier.
    109109
     110You can also add the files to the media library, as private media, with "Add to Library" in "Media", under Advanced settings. Read more in the [media library documentation](https://cf7-to-webhook.valney.dev/docs/features/media-library).
     111
     112= How can I delete uploaded files? =
     113
     114Use "Delete all files" in "Media", under Advanced settings. It deletes every file uploaded with the form, including the ones in the media library. Links already sent to webhooks stop working. Only administrators can use it.
     115
    110116= How can I rename a field to webhook? =
    111117
    … …  
    126132By default, the plugin blocks requests to private, loopback, and link-local addresses (e.g. `192.168.x.x`, `10.x.x.x`, `127.0.0.1`, `169.254.x.x`) to prevent SSRF attacks.
    127133
    128 If you run a trusted internal service and need to reach it, you can whitelist specific hosts using WordPress's `http_request_host_is_external` filter in your theme's `functions.php` or a custom plugin:
     134If you run a trusted internal service and need to reach it, you can whitelist specific hosts using WordPress's `http_request_host_is_external` filter. Add this code as explained in [Add custom code](https://cf7-to-webhook.valney.dev/docs/how-to/add-custom-code):
    129135
    130136`add_filter( 'http_request_host_is_external', function( $external, $host ) {
    … …  
    167173== Changelog ==
    168174
     175= 5.2.0 =
     176
     177New feature: Add uploaded files to the media library (props to @Zodiac1978 for the suggestion).
     178
     179* New "Add to Library" option, in "Media" under Advanced settings: each uploaded file becomes a private attachment, even when sending file content.
     180* New "Delete all files" button to delete every file uploaded with a form, including its media library attachments. Only administrators can use it.
     181* Upload folders now get an empty index.php, so servers with directory listing on do not list submissions.
     182* Fixed templates not filling the body with the form fields since 5.1.0.
     183* Fixed the template selector staying empty on sites with WP_DEBUG on.
     184* Fixed the form editor asking to confirm leaving the page without changes.
     185* Documentation moved to [cf7-to-webhook.valney.dev/docs](https://cf7-to-webhook.valney.dev/docs).
     186* Reviewed the plugin with the [WordPress agent skills](https://github.com/WordPress/agent-skills) and made some improvements, including a fix for header injection through form fields in custom headers. Debug helpers now need CFTZ_ADD_DEBUG_FUNCTIONS.
     187
    169188= 5.1.1 =
    170189
    171 * Fixed webhooks not being sent when the submitted data has invalid UTF-8. Invalid sequences are now replaced, as Contact Form 7 does (props to @Zodiac1978).
     190* Fixed webhooks not being sent when the submitted data has invalid UTF-8. Invalid sequences are now replaced, as Contact Form 7 does (props to @Zodiac1978 for a suggestion).
    172191* Fixed fields with invalid UTF-8 being sent empty when using a custom body.
    173192* Fixed a PHP warning ("Undefined variable $data") in error notifications.
    … …  
    355374== Upgrade Notice ==
    356375
     376= 5.2.0 =
     377
     378Adds uploaded files to the media library and a button to delete them. Fixes templates not filling the body since 5.1.0.
     379
    357380= 5.1.1 =
    358381
Note: See TracChangeset for help on using the changeset viewer.