Created
August 3, 2018 17:08
-
-
Save joelworsham/45018bf599de3d5700ddd781336ef62f to your computer and use it in GitHub Desktop.
GF Plugin Exporting Spam
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 | |
/** | |
* Class Lowry_GF_Exporting | |
* | |
* Customizes exporting entries. Specifically to include spam entries. | |
* | |
* @since {{VERSION}} | |
*/ | |
// Exit if accessed directly | |
defined( 'ABSPATH' ) || die(); | |
class Lowry_GF_Exporting { | |
/** | |
* Lowry_GF_Exporting constructor. | |
* | |
* @since {{VERSION}} | |
*/ | |
function __construct() { | |
add_filter( 'gform_leads_before_export', array( $this, 'modify_entries_before_export' ), 100, 3 ); | |
if ( isset( $_REQUEST['gf_spam_only'] ) ) { | |
add_action( 'admin_print_footer_scripts', array( $this, 'output_spam_only_script' ) ); | |
} | |
} | |
/** | |
* Modifies entries before being exported. | |
* | |
* @since {{VERSION}} | |
* @access private | |
* | |
* @param array $entries | |
* @param array $form | |
* @param array $paging | |
* | |
* @return array | |
*/ | |
function modify_entries_before_export( $entries, $form, $paging ) { | |
if ( isset( $_REQUEST['gf_spam_only'] ) ) { | |
$entries = $this->get_spammed_entries( $form['id'] ); | |
} | |
return $entries; | |
} | |
/** | |
* Returns a form's spammed entries. | |
* | |
* @since {{VERSION}} | |
* @access private | |
* | |
* @param int|string $form_ID | |
* | |
* @return array | |
*/ | |
private function get_spammed_entries( $form_ID ) { | |
$entries = GFAPI::get_entries( $form_ID, array( | |
'status' => 'spam', | |
) ); | |
return $entries; | |
} | |
/** | |
* Outputs the footer javascript for manipulating the export form to tell it to only export spam. | |
* | |
* @since {{VERSION}} | |
* @access private | |
*/ | |
function output_spam_only_script() { | |
?> | |
<script type="text/javascript"> | |
(function ($) { | |
$(function () { | |
var $form = $('#gform_export'); | |
if ( !$form.length ) { | |
return; | |
} | |
$form.append('<input type="hidden" name="gf_spam_only" value="1" />'); | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment