Created
November 17, 2020 22:25
-
-
Save polevaultweb/8a604e2311a5f4c787a7dad57863564c to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Plugin Name: Ninja Forms Uploads Connect Submissions | |
* Plugin URI: https://ninjaforms.com/extensions/file-uploads/ | |
* Description: Debug plugin | |
* Version: 3.0 | |
* Author: polevaultweb | |
* Author URI: https://polevaultweb.com | |
*/ | |
add_action( 'admin_init', function () { | |
if ( ! isset( $_GET['nf_fu_connect_submissions'] ) ) { | |
return; | |
} | |
$dry_run = false; | |
if ( isset( $_GET['dry-run'] ) ) { | |
$dry_run = true; | |
} | |
$where = "WHERE `data` NOT LIKE '%sub_id%'"; | |
$uploads = NF_File_Uploads()->model->fetch( $where ); | |
global $wpdb; | |
if ( $dry_run ) { | |
print 'NF Connect Submissions - Total: '. count( $uploads ); | |
} | |
foreach ( $uploads as $upload ) { | |
$data = maybe_unserialize( $upload['data'] ); | |
$url = $data['file_url']; | |
$query = " | |
SELECT p.ID, p.post_date, pm1.meta_value as form_id | |
FROM $wpdb->posts p | |
INNER JOIN $wpdb->postmeta pm | |
ON p.ID = pm.post_id | |
INNER JOIN $wpdb->postmeta pm1 | |
ON p.ID = pm1.post_id | |
AND pm1.meta_key = '_form_id' | |
WHERE pm.meta_value LIKE '%%%s%%'"; | |
$posts = $wpdb->get_results( $wpdb->prepare( $query, $url ) ); | |
if ( count( $posts ) == 1 && $posts[0]->form_id == $upload['form_id'] ) { | |
if ( $dry_run ) { | |
print 'NF Connect Submissions - File URL: ' . $url; | |
print 'NF Connect Submissions - Found Sub: ' . $posts[0]->ID; | |
} else { | |
$data['sub_id'] = $posts[0]->ID; | |
NF_File_Uploads()->model->update( $upload['id'], $data ); | |
} | |
} | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment