Este gist contiene los ejemplos de hooks que uso en esta entrada de WPrincipiante.
Last active
October 19, 2015 12:32
-
-
Save avillegasn/cb1bd3bff7ccb2944591 to your computer and use it in GitHub Desktop.
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
<?php | |
function notifica_al_autor( $ID, $post ) { | |
$autor = $post->post_author; /* ID del autor */ | |
$nombre = get_the_author_meta( 'display_name', $autor ); | |
$email = get_the_author_meta( 'user_email', $autor ); | |
$titulo = $post->post_title; | |
$enlace = get_permalink( $ID ); | |
$destinatario[] = sprintf( '%s <%s>', $nombre, $email ); | |
$asunto = sprintf( 'Entrada Publicada: %s', $titulo ); | |
$mensaje = sprintf ('¡Felicidades, %s! Tu entrada “%s” has sido publicada.' . "\n\n", $nombre, $titulo ); | |
$mensaje .= sprintf( 'Ver: %s', $enlace ); | |
$cabeceras[] = ''; | |
wp_mail( $destinatario, $asunto, $mensaje, $cabeceras ); | |
} | |
add_action( 'publish_post', 'notifica_al_autor', 10, 2 ); | |
?> |
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
<?php | |
function incluye_exclusiva( $title, $id = null ) { | |
if ( in_category( 'Exclusiva', $id ) ) { | |
return '¡Exclusiva! '.title; | |
} | |
return $title; | |
} | |
add_filter( 'the_title', 'incluye_exclusiva', 10, 2 ); | |
?> |
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
<?php | |
remove_action( 'publish_post', 'notifica_al_autor' ); | |
remove_filter( 'the_title', 'incluye_exclusiva' ); | |
?> |
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
<?php | |
function mi_funcion () { | |
// ell código que queramos | |
} | |
add_action( 'nombre_del_hook', 'mi_funcion', [prioridad], [parametros] ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment