Comment puis-je ajouter un champ URL à la fenêtre des pièces jointes?
-
-
Ne "namespace"pas vosfonctions avec "my_".Trop degens lefont déjà.;)Don't "namespace" your functions with "my_". Too many people do that already. ;)
- 1
- 2010-10-22
- fuxia
-
J'adorerais savoir comment l'utiliser avec unbouton radio.Changer detypene fait rien.Would love to know how to use this with a radio button. Changing type doesn't do anything.
- 0
- 2012-10-03
- Drew Baker
-
@scottb Au lieu demettre votre solution dans la question,vous devriez la couper de làet la coller dans une réponse,puis l'accepter.Certainespersonnespensent qu'il y a quelque chose quine vapas dans lefait d'accepter sapropre réponse,mais c'estbien et cela aide les recherchesfutures (commemoi) à obtenir la vraie réponseplus rapidement.@scottb Instead of putting your solution in the question, you should cut it out of there and paste it into an answer and then accept that. Some people think there something seems off about accepting ones own answer, but its fine and it helps future searches (like me) to get to the real answer more quickly.
- 0
- 2015-11-11
- Jeff
-
1 réponses
- votes
-
- 2015-11-11
En réponse à la question de Drew dans les commentaires,vouspouvezpersonnaliser le code HTML du champen définissant
input
sur unenouvelle chaîne,puisen ajoutant cettemême chaîneen tant que clé au$form_fields
.Par défaut,WordPressn'acceptera que les
text
ettextarea
pour letypeinput
.Tout le reste devra être défini demanièrepersonnalisée comme ci-dessous.Jen'aipasessayé de conserver les champs deformulaire de cettefaçon,doncpour créer un autretype d'entrée,comme unbouton radio,celapeutprendre unpeuplus definesse.add_filter( 'attachment_fields_to_edit', 'change_fields', 10, 2 ); function change_fields( $form_fields, $post ) { $form_fields["some_new_field"] = array( "label" => __("Type something"), "input" => "arbitrary_value", "value" => get_post_meta($post->ID, "some_new_field", true), "arbitrary_value" => "hello world!" ); }
Responding to Drew's question in the comments, you can customize the HTML for the field by setting the
input
to a new string, and then adding that same string as a key to the$form_fields
array.By default, WordPress will only accept
text
andtextarea
for theinput
type. Anything else will have to be defined in a custom way as below. I haven't tried actually persisting form fields this way so in order to make another input type, like a radio button, might take a little extra finesse.add_filter( 'attachment_fields_to_edit', 'change_fields', 10, 2 ); function change_fields( $form_fields, $post ) { $form_fields["some_new_field"] = array( "label" => __("Type something"), "input" => "arbitrary_value", "value" => get_post_meta($post->ID, "some_new_field", true), "arbitrary_value" => "hello world!" ); }
Parexemple ...
Ajoute un champ de saisie "Catégorie" augestionnairemultimédiaet à l'éditeur depiècesjointes. J'aimerais savoir s'ilestpossible demodifier cettefonctionpour capturer une URL de "destination de lien" à laplace. L'URL seraitexécutée lorsque l'utilisateur clique sur l'image.
Vous devez également savoir comment récupérer la valeur de cenouveau champ.
MISE À JOUR: Merci à Thomas Answer ci-dessous,voicima solutionfinale ...