Skip to content

Instantly share code, notes, and snippets.

@kaskad88
Last active June 1, 2020 13:43
Show Gist options
  • Save kaskad88/a514ae92a27ce4b2ad0b248b1a506df3 to your computer and use it in GitHub Desktop.
Save kaskad88/a514ae92a27ce4b2ad0b248b1a506df3 to your computer and use it in GitHub Desktop.
add_action( 'gform_pre_submission', '__your_prefix__pre_submission_handler' );
function __your_prefix__pre_submission_handler( $form ) {
$media_key = 'media_key'; // Need change on your media key
$_POST[ $media_key ] = __your_prefix__get_image_id_by_url( $_POST[ $media_key ] );
}
function __your_prefix__get_image_id_by_url( $image_src ) {
global $wpdb;
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid = %s";
$id = $wpdb->get_var( $wpdb->prepare( $query, esc_url( $image_src ) ) );
return $id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment