Pledge\CPT_ID, 'post_status' => 'any', 'posts_per_page' => -1, ) ); foreach ( $all_companies as $company ) { $log = PledgeLog\get_pledge_log( $company->ID ); $creation_entry = get_creation_entry( $log ); $creation_date = $creation_entry[0]['timestamp'] ?? null; if ( 1 !== count( $creation_entry ) || empty( $creation_entry[0]['timestamp'] ) ) { WP_CLI::error( new WP_Error( 'log_mismatch', "log doesn't match expectations", array( $company, $creation_entry ) ) ); } // These companies haven't been manually verified, and many look just as inaccurate as the ones that were cleaned. // ⚠️ This is only meaningful because it just happened a few months before this script was written. It will become // less meaningful as time passes. if ( $creation_date >= strtotime( DATE_CLEANED_PLEDGES ) ) { continue; } // These were manually determined to be spam/dormant. if ( Pledge\DEACTIVE_STATUS === $company->post_status ) { $messages = implode( ' ', wp_list_pluck( $log, 'message' ) ); if ( str_contains( $messages, 'Manually removing spam/dormant pledges' ) ) { continue; } } // Don't remove companies that don't currently have any confirmed contributors, because they may have had them in the past. $valid_pledges[] = $company; } return $valid_pledges; } function get_creation_entry( array $log ): array { $creation_entry = array_filter( $log, function( $entry ) { return 'pledge_created' === $entry['type']; } ); return array_values( $creation_entry ); // remove index gaps } function get_month_counts( array $valid_pledges ) : array { $month_counts = array(); foreach ( $valid_pledges as $pledge ) { $log = PledgeLog\get_pledge_log( $pledge->ID ); $creation_entry = get_creation_entry( $log ); $month_key = date( 'Y-m', $creation_entry[0]['timestamp'] ); $month_counts[ $month_key ]++; } return $month_counts; } function filter_active_pledges( array $pledges ): array { return array_filter( $pledges, function( $pledge ) { $active_contributors = get_post_meta( $pledge->ID, PledgeMeta\META_PREFIX . 'pledge-confirmed-contributors', true ); return 'publish' === $pledge->post_status && count( $active_contributors ) > 0; } ); }