id ) { wp_enqueue_style( '5ftf-admin' ); } } } /** * Render results and download button. */ function render_company_report_page() { $status = sanitize_title( $_GET['status'] ); if ( ! in_array( $status, array( 'draft', '5ftf-deactivated', 'publish' ) ) ) { $status = 'all'; } $pledges = get_posts( array( 'post_type' => '5ftf_pledge', 'post_status' => $status, 'posts_per_page' => 250, // set to 250 to avoid unexpected memory overuse. 'orderby' => 'post_title', 'order' => 'ASC', ) ); // Add visible warning on page if we hit the upper limit of the query. if ( 250 == count( $pledges ) ) { echo '
WARNING: pledge limit reached, check the code query.
'; } ?>Total: Status: All Draft Publish Deactivated
Company | Status | Total Hours | Contributors | Usernames | Team(s) | URL | Pledge URL | Pledge created | Pledge updated | |
---|---|---|---|---|---|---|---|---|---|---|
' . esc_html( $pledge->post_title ) . ' | '; echo '' . esc_html( $pledge->post_status ) . ' | '; echo '' . esc_html( $hours ) . ' | '; echo '' . esc_html( $contributors ) . ' | '; echo '' . esc_html( $usernames ) . ' | '; echo '' . esc_html( $teams ) . ' | '; echo '' . esc_html( $company_url ) . ' | '; echo '' . esc_html( $pledge_url ) . ' | '; echo '' . esc_html( $email ). ' | '; echo '' . esc_html( $date_created ) . ' | '; echo '' . esc_html( $date_modified ) . ' | '; echo '
Total contributors: ' . esc_html( $all_contributors ) . '
'; // Sets a transient to avoid double data lookup for export, might need to adjust timeout to longer. set_transient( 'wporg_5ftf_company_report_' . $status, $export_data, 60 ); } /** * CSV export runner, grabs data lazily from a transient. */ function export_csv() { if ( ! isset( $_POST['wporg-5ftf-cr'] ) || ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $_POST['_wpnonce'], '5ftf_download_company_report' ) ) { return; } $status = $_POST['status']; $data = get_transient( 'wporg_5ftf_company_report_' . $status ); $exporter = new Export_CSV( array( 'filename' => 'company-report-' . $status, 'headers' => array( 'Company', 'Status', 'Hours', 'Contributors', 'Users', 'Teams', 'Company URL', 'Pledge URL', 'Email', 'Created', 'Last updated' ), 'data' => $data, ) ); $exporter->emit_file(); }