Plugin Directory

Changeset 3186733


Ignore:
Timestamp:
11/12/2024 09:12:37 PM (15 months ago)
Author:
reenhanced
Message:

power-form-7 v2.6.0

Location:
power-form-7/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • power-form-7/trunk/api/class-power-form-7-api.php

    r3016494 r3186733  
    2020 */
    2121class Power_Form_7_Api {
    22     protected $_api_version = 'v1'; 
     22    protected $_api_version = 'v1';
    2323
    2424    /**
    2525     * The array of routes we want to protect with our authorization
    26      * 
     26     *
    2727     * @since   1.0.0
    2828     * @var     array   $routes The routes that are protected with authorization
     
    3838            return self::$_instance;
    3939    }
    40    
     40
    4141    public function get_namespace() {
    4242        return $this->plugin_name . '/' . $this->_api_version;
     
    6868        $this->plugin_name = $plugin_name;
    6969        $this->version = $version;
    70        
     70
    7171        $this->routes = array();
    7272
     
    7878    /**
    7979     * Used by controllers to register routes
    80      * 
     80     *
    8181     * @since 1.0.0
    8282     * @param   string    $resource_name  The resource name, used for defining route path
     
    114114    /**
    115115     * Authentication handler allows users to authenticate to the API using their license key
    116      * 
     116     *
    117117     * Stock wordpress rest API does not include any authentication methods. We can't rely on auth plugins or wordpress.com for our clients
    118118     * Therefore we need to build out own authentication method.
    119119     * This authentication routes can be the license key for our product.
    120      * 
     120     *
    121121     * This allows us to:
    122122     * - Allow capabilities required by our plugin
     
    156156    }
    157157
     158    /**
     159     * Modify incoming REST API request data for the Contact Form 7 feedback endpoint.
     160     *
     161     * This filter intercepts and modifies incoming POST requests to the
     162     * `contact-form-7/v1/contact-forms/<id>/feedback` endpoint before the data
     163     * reaches the callback function, allowing custom adjustments to be made
     164     * to the request parameters.
     165     *
     166     * The `rest_pre_dispatch` filter is applied in the WordPress core within
     167     * the `WP_REST_Server::dispatch()` method, providing an opportunity to
     168     * short-circuit or modify a request before it is executed.
     169     *
     170     * @link https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/
     171     *
     172     * @param mixed           $result  Response to replace the requested version, can short-circuit request.
     173     * @param WP_REST_Server  $server  Server instance handling the request.
     174     * @param WP_REST_Request $request The current request object.
     175     *
     176     * @return mixed Filtered response, or null to proceed to the next stage in processing.
     177     */
     178    public function request_pre_handler( $result, $server, $request ) {
     179        if ( preg_match( '#^/contact-form-7/v1/contact-forms/\d+/feedback$#', $request->get_route() ) &&
     180                 'POST' === $request->get_method() ) {
     181
     182            // Check the license and make sure this request is ours
     183            $license_opt = $this->plugin()->get_app_setting('license_key');
     184            $auth_header = $_SERVER['HTTP_LICENSE_AUTHORIZATION'];
     185
     186            if ( $auth_header !== $license_opt || empty( $auth_header ) ) {
     187                return $result;
     188            }
     189
     190            $this->plugin()->log_debug( __METHOD__ . '() - Intercepting request to CF7 feedback endpoint' );
     191
     192            $content_type = $request->get_header( 'Content-Type' );
     193            if ( ! str_starts_with( $content_type, 'multipart/form-data' ) ) {
     194                // Check if it is application/json. If so, change the content type to multipart/form-data and set the parameters from the json body.
     195                if ( str_starts_with( $content_type, 'application/json' ) ) {
     196                    $request->set_header( 'Content-Type', 'multipart/form-data' );
     197
     198                    // Get the JSON body.
     199                    $body = $request->get_body();
     200                    $data = json_decode( $body, true );
     201
     202                    // Set the parameters from the JSON body.
     203                    if ( is_array( $data ) ) {
     204                        foreach ( $data as $key => $value ) {
     205                            $request->set_param( $key, $value );
     206                            $_POST[ $key ] = $value;
     207                        }
     208                    }
     209                }
     210            }
     211
     212            $unit_tag = $request->get_param( '_wpcf7_unit_tag' );
     213            if ( empty( $unit_tag ) ) {
     214                // Source: contact-form-7/includes/contact-form.php function generate_unit_tag()
     215                $unit_tag = sprintf( 'wpcf7-f%d-o1', $request->get_param( 'id' ) );
     216
     217                $request->set_param( '_wpcf7_unit_tag', $unit_tag );
     218            }
     219        }
     220
     221        return $result;
     222
     223    }
     224
    158225    /*********************** PRIVATE */
    159226
     
    180247     */
    181248    private static $_instance = null;
    182    
     249
    183250    private function require_dependencies() {
    184251    }
    185    
     252
    186253    private function load_controllers() {
    187254        // Load each controller class here
     
    219286        return $route_array;
    220287    }
    221    
     288
    222289}
  • power-form-7/trunk/includes/class-power-form-7.php

    r3114512 r3186733  
    299299        $this->loader->add_action( 'rest_api_init', $plugin_api, 'rest_api_init' );
    300300        $this->loader->add_filter( 'determine_current_user', $plugin_api, 'license_auth_handler');
     301        $this->loader->add_filter( 'rest_pre_dispatch', $plugin_api, 'request_pre_handler', 10, 3 );
    301302    }
    302303
  • power-form-7/trunk/power-form-7.php

    r3114512 r3186733  
    1717 * Plugin URI:        https://www.powerform7.com/
    1818 * Description:       Power Form 7 integrates Contact Form 7 with Microsoft Power Automate.
    19  * Version:           2.2.7
     19 * Version:           2.6.0
    2020 * Requires at least: 5.4
    2121 * Requires PHP:      5.6
     
    2525 * Domain Path:       /languages
    2626 *
    27  * Copyright 2020 Reenhanced LLC. All Rights Reserved.
     27 * Copyright 2024 Reenhanced LLC. All Rights Reserved.
    2828 */
    2929
     
    3636 * Current plugin version.
    3737 */
    38 define( 'PF7_VERSION', '2.2.7' );
     38define( 'PF7_VERSION', '2.6.0' );
    3939
    4040//define( 'PF7_SERVICE_HOST', 'http://docker-host:3000/pf7');
  • power-form-7/trunk/readme.txt

    r3114512 r3186733  
    33Tags: cf7, contact form, power automate, integration, contact form 7, flow, reenhanced
    44Requires at least: 5.4
    5 Tested up to: 6.6.0
    6 Stable tag: 2.2.6
     5Tested up to: 6.6.2
     6Stable tag: 2.6.0
    77Requires PHP: 5.6
    88License: GPLv2 or later
     
    8484== Changelog ==
    8585
     86= 2.6.0 =
     87* Compability with Contact Form 6.0
     88* New versioning scheme will attempt to sync with CF7 versioning so you can easily see compatibility. (New features may change this.)
     89
    8690= 2.2.7 =
    8791* Compatibility with WordPress 6.6.0
Note: See TracChangeset for help on using the changeset viewer.