Last active
June 26, 2019 09:23
-
-
Save JRyven/84670babc06b1bf4213774fb0f3ce7e9 to your computer and use it in GitHub Desktop.
GravityViews GravityForms Restore Entry Author from No User "Changed entry creator from ... to No User"
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 | |
/**** | |
* | |
* Restore Gravity Forms Entry Author from "No Author" | |
* | |
* GravityViews plugin adds a helpful 'Change Entry Creator' dropdown to the Entry Editor Admin page for Gravity Forms. | |
* Unfortunately, if there are too many users on the site, the dropdown defaults to " - No User - ", disassociating | |
* the original entry creator upon Entry Update. When the Entry Creator is changed, a note is stored that states | |
* "Changed entry creator from [NAME] (ID #[###]) to No User". This function selects notes with such language, isolates | |
* the ID, and re-sets that ID as the created_by value for the corresponding Entry (AKA lead). | |
* | |
* Use: Place this function in your functions.php file, save the file, and then reload your website. You should see | |
* many "update(1)" printed across the header of the site. Your entries have authors now! Delete the function from your site. | |
* | |
****/ | |
add_action ('wp_head', 'restore_gf_entry_authors'); | |
function restore_gf_entry_authors() { | |
global $wpdb; | |
$update_array = array(); | |
$all_gf_notes = $wpdb->get_results( $wpdb->prepare( "SELECT id, lead_id, value FROM %s", $wpdb->prefix.rg_lead_notes ), OBJECT ); | |
foreach ($all_gf_notes as $gf_note){ | |
$this_note_twentysix = substr($gf_note->value, 0, 26); | |
if ( "Changed entry creator from" == $this_note_twentysix ){ | |
$this_note_original_author_id = explode('#', $gf_note->value); | |
$this_note_original_author_id = explode(')', $this_note_original_author_id[1]); | |
$update_array[] = array( | |
'lead_id' => intval($gf_note->lead_id), | |
'author_id' => intval($this_note_original_author_id[0]), | |
); | |
} | |
} | |
foreach( $update_array as $update_val ){ | |
$update = $wpdb->update( | |
$wpdb->prefix.'rg_lead', | |
array('created_by' => $update_val['author_id']), | |
array('id' => $update_val['lead_id']), | |
array('%d'), | |
array('%d') | |
); | |
var_dump($update); | |
} | |
} | |
?> |
Thanks, FPCSJames. Suggestion taken. Edited lines 24 and 46. Currently untested. (So if anyone runs into an error, ping me!)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you James! This was helpful in eliminating those notes quickly on a client site. You may want to substitute "wp_2_" for $wpdb->prefix.