IT/Customisation de Wordpress

11 février 2020 Rédigé par Linuxine

Wordpress offre une API permettant d'ajouter facilement des boutons dans l'éditeur, la Quicktags_API.

Il est donc facile de rajouter un bouton avec un appel du type :

QTags.addButton( id, display, arg1, arg2, access_key, title, priority, instance );

On peut ajouter dans le fichier functions.php du thème des appels de fonction du type (exemple avec un ajout de bouton pour le plugin Piwigo :

// Add Quicktags
function piwitag() {
  if ( wp_script_is( 'quicktags' ) ) {
  ?>
  <script type="text/javascript">
  QTags.addButton( 'piwitag', 'Piwitag', '[PiwigoPress id=xxx url="PIWIGO_URL" size="me" class="img-shadow"]', '', 'Piwitag', '', 'piwitag',  );
  </script>
  <?php
 }
}
add_action( 'admin_print_footer_scripts', 'piwitag' );

J'en profite pour noter la fonction pour déclencher une commande à la publication d'un post (dans mon cas, publication sur une room Matrix):

function published_send_notif( $post_id ){

 // If this is just a revision, don't send the email.
 if ( wp_is_post_revision( $post_id ) )
         return;
 //if( get_post( $post_id ) == null ) {
 $post_title = get_the_title( $post_id );
 $post_url = get_permalink( $post_id );
 $subject = 'Nouveau post';

 $message = "Nouveau post:/n /n";
 $message .= $post_title . ": " . $post_url;

 // Send notification in Matrix room.
 $command = "";
 exec(escapeshellcmd($command) . " " . escapeshellarg($post_title) . " " . escapeshellarg($post_url));
 // }
}
add_action( 'publish_post', 'published_send_notif' );

 

Écrire un commentaire