Skip to content

Instantly share code, notes, and snippets.

@MjHead
Created May 27, 2022 15:39
Show Gist options
  • Save MjHead/d15a4d3aa495a433463ef2253aa7eca3 to your computer and use it in GitHub Desktop.
Save MjHead/d15a4d3aa495a433463ef2253aa7eca3 to your computer and use it in GitHub Desktop.
JetFormBuilder. Use custom data as default value
<?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