Changeset 3186733
- Timestamp:
- 11/12/2024 09:12:37 PM (15 months ago)
- Location:
- power-form-7/trunk
- Files:
-
- 4 edited
-
api/class-power-form-7-api.php (modified) (8 diffs)
-
includes/class-power-form-7.php (modified) (1 diff)
-
power-form-7.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
power-form-7/trunk/api/class-power-form-7-api.php
r3016494 r3186733 20 20 */ 21 21 class Power_Form_7_Api { 22 protected $_api_version = 'v1'; 22 protected $_api_version = 'v1'; 23 23 24 24 /** 25 25 * The array of routes we want to protect with our authorization 26 * 26 * 27 27 * @since 1.0.0 28 28 * @var array $routes The routes that are protected with authorization … … 38 38 return self::$_instance; 39 39 } 40 40 41 41 public function get_namespace() { 42 42 return $this->plugin_name . '/' . $this->_api_version; … … 68 68 $this->plugin_name = $plugin_name; 69 69 $this->version = $version; 70 70 71 71 $this->routes = array(); 72 72 … … 78 78 /** 79 79 * Used by controllers to register routes 80 * 80 * 81 81 * @since 1.0.0 82 82 * @param string $resource_name The resource name, used for defining route path … … 114 114 /** 115 115 * Authentication handler allows users to authenticate to the API using their license key 116 * 116 * 117 117 * Stock wordpress rest API does not include any authentication methods. We can't rely on auth plugins or wordpress.com for our clients 118 118 * Therefore we need to build out own authentication method. 119 119 * This authentication routes can be the license key for our product. 120 * 120 * 121 121 * This allows us to: 122 122 * - Allow capabilities required by our plugin … … 156 156 } 157 157 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 158 225 /*********************** PRIVATE */ 159 226 … … 180 247 */ 181 248 private static $_instance = null; 182 249 183 250 private function require_dependencies() { 184 251 } 185 252 186 253 private function load_controllers() { 187 254 // Load each controller class here … … 219 286 return $route_array; 220 287 } 221 288 222 289 } -
power-form-7/trunk/includes/class-power-form-7.php
r3114512 r3186733 299 299 $this->loader->add_action( 'rest_api_init', $plugin_api, 'rest_api_init' ); 300 300 $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 ); 301 302 } 302 303 -
power-form-7/trunk/power-form-7.php
r3114512 r3186733 17 17 * Plugin URI: https://www.powerform7.com/ 18 18 * Description: Power Form 7 integrates Contact Form 7 with Microsoft Power Automate. 19 * Version: 2. 2.719 * Version: 2.6.0 20 20 * Requires at least: 5.4 21 21 * Requires PHP: 5.6 … … 25 25 * Domain Path: /languages 26 26 * 27 * Copyright 202 0Reenhanced LLC. All Rights Reserved.27 * Copyright 2024 Reenhanced LLC. All Rights Reserved. 28 28 */ 29 29 … … 36 36 * Current plugin version. 37 37 */ 38 define( 'PF7_VERSION', '2. 2.7' );38 define( 'PF7_VERSION', '2.6.0' ); 39 39 40 40 //define( 'PF7_SERVICE_HOST', 'http://docker-host:3000/pf7'); -
power-form-7/trunk/readme.txt
r3114512 r3186733 3 3 Tags: cf7, contact form, power automate, integration, contact form 7, flow, reenhanced 4 4 Requires at least: 5.4 5 Tested up to: 6.6. 06 Stable tag: 2. 2.65 Tested up to: 6.6.2 6 Stable tag: 2.6.0 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later … … 84 84 == Changelog == 85 85 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 86 90 = 2.2.7 = 87 91 * Compatibility with WordPress 6.6.0
Note: See TracChangeset
for help on using the changeset viewer.