Created
February 7, 2024 14:41
-
-
Save florianziegler/7fa44c6200e48bf29bbabfc40c1d1a05 to your computer and use it in GitHub Desktop.
picu .csv Proof File
This file contains hidden or 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
/** | |
* Create .csv proof file content | |
* | |
* Puts the email in the first column, selected filenames in the follwing columns, | |
* each recipient on a new line. | |
* | |
* @param string $proof_file_content The original proof file content | |
* @param int $post_id The collection post ID | |
* @return string The filtered proof file content | |
*/ | |
function my_picu_proof_file_content( $proof_file_content, $post_id ) { | |
$emails = picu_get_collection_emails( $post_id ); | |
$temp = []; | |
foreach( $emails as $email ) { | |
$ident = picu_get_ident_from_email( $post_id, $email ); | |
$img_filenames = picu_get_approved_filenames( $post_id, $ident ); | |
$filename_separator = apply_filters( 'picu_filename_separator', ' ' ); | |
$temp[$email] = explode( $filename_separator, $img_filenames ); | |
} | |
ob_start(); | |
foreach( $temp as $email => $filenames ) { | |
echo $email .','; | |
echo implode( ',', $filenames ); | |
echo "\n"; | |
} | |
return ob_get_clean(); | |
} | |
add_filter( 'picu_proof_file_content', 'my_picu_proof_file_content', 10, 2 ); | |
/** | |
* Filter file name, use .csv as file extension | |
* | |
* @param string $filename The original filename | |
* @parem int $post_id The collection post ID | |
* @return string The filtered filename | |
*/ | |
function my_picu_proof_file_name( $filename, $post_id ) { | |
$filename = sanitize_title( get_the_title( $post_id ) ) . '.csv'; | |
return $filename; | |
} | |
add_filter( 'picu_proof_file_name', 'my_picu_proof_file_name', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment