Last active
June 1, 2020 13:43
-
-
Save kaskad88/a514ae92a27ce4b2ad0b248b1a506df3 to your computer and use it in GitHub Desktop.
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
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