Created
May 27, 2022 15:39
-
-
Save MjHead/d15a4d3aa495a433463ef2253aa7eca3 to your computer and use it in GitHub Desktop.
JetFormBuilder. Use custom data as default value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', function() { | |
// Check if need to do an API request | |
if ( empty( $_GET['test_api_request'] ) ) { | |
return; | |
} | |
// get remote data | |
$response = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/jetformbuilder.json' ); | |
$data = wp_remote_retrieve_body( $response ); | |
$data = json_decode( $data, true ); | |
// set remote data into request vars to use in the form | |
$_GET['my_val_1'] = ( $data && isset( $data['name'] ) ) ? $data['name'] : ''; | |
$_GET['my_val_2'] = ( $data && isset( $data['version'] ) ) ? $data['version'] : ''; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment