Existe-t-il un moyen de définir une légende par défaut pour toutes les images téléchargées
-
-
Bem-vinda ao WPSE,Miriam!- Vouspouvez consulter certaines applications denotification (http://stackapps.com/) qui vous aideront à suivre vos questionset réponsesici.Saudações :)Bem-vinda ao WPSE, Miriam! - You may want to check some notification apps (http://stackapps.com/) that will help you to follow up your Questions and Answers here. Saudações :)
- 1
- 2012-05-30
- brasofilo
-
@brasofilo +1pour quelquesportugaistrès accueillants sur WPSE.:)@brasofilo +1 for some very welcoming portuguese on WPSE. :)
- 1
- 2012-05-30
- moraleida
-
1 réponses
- votes
-
- 2012-05-30
Iln'y a vraimentpasencore de documentation à ce sujet,mais vouspourrezprobablement lefaireen vous connectant aufiltre
attachment_fields_to_save
et en yinsérant la légendepar défaut.attachment_fields_to_save
appliqué aux champs associés à un piècejointe avant de lesenregistrer dans labase de données. Appelé dans le fonctionmedia_upload_form_handler. Arguments de lafonction defiltrage: an tableau d'attributs depublication,untableau de champs depiècejointe comprenant le modifications soumises àpartir duformulaireIlest défini sur wp- admin/includes/media.php :
// TESTED :) function wpse300512_image_attachment_fields_to_save($post, $attachment) { if ( substr($post['post_mime_type'], 0, 5) == 'image' ) { if ( '' === trim( $post['post_title'] ) ) { $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid'])); $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.'); } // captions are saved as the post_excerpt, so we check for it before overwriting if ( '' === trim( $post['post_excerpt'] ) ) { $post['post_excerpt'] = 'default caption'; } } return $post; } add_filter('attachment_fields_to_save', 'wpse300512_image_attachment_fields_to_save', 10, 2);
MISE À JOUR: J'ai réussi à letester,et celafonctionnetel quel. Déposez-le simplement sur votrefunctions.php :)
There's really no documentation for it yet, but you'll probably be able to do it hooking to the
attachment_fields_to_save
filter and inserting the default caption there.attachment_fields_to_save
applied to fields associated with an attachment prior to saving them in the database. Called in the media_upload_form_handler function. Filter function arguments: an array of post attributes, an array of attachment fields including the changes submitted from the formIt is defined on wp-admin/includes/media.php:
// TESTED :) function wpse300512_image_attachment_fields_to_save($post, $attachment) { if ( substr($post['post_mime_type'], 0, 5) == 'image' ) { if ( '' === trim( $post['post_title'] ) ) { $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid'])); $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.'); } // captions are saved as the post_excerpt, so we check for it before overwriting if ( '' === trim( $post['post_excerpt'] ) ) { $post['post_excerpt'] = 'default caption'; } } return $post; } add_filter('attachment_fields_to_save', 'wpse300512_image_attachment_fields_to_save', 10, 2);
UPDATE: I managed to test it, and it works as is. Just drop it on your functions.php :)
Comme l'indique letitre de cette réponse,je souhaite définir une légendepar défautpourtoutes lesimagestéléchargées dansmon WordPress ... Y a-t-il unmoyen defaire quelque chose comme ça?