Este gist contiene los ejemplos de hooks que uso en esta entrada de WPrincipiante.
This file contains 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
// ** MySQL settings - You can get this info from your web host ** // | |
/** The name of the database for WordPress */ | |
define('DB_NAME', 'database_name_here'); | |
/** MySQL database username */ | |
define('DB_USER', 'username_here'); | |
/** MySQL database password */ | |
define('DB_PASSWORD', 'password_here'); |
This file contains 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 | |
if ( have_posts() ) : | |
while ( have_posts() ) : the_post(); | |
// contenido de la entrada E (template tags, html, etc) | |
?><h2> | |
<a href="<?php the_permalink(); ?>"><?php the_title();?></a> | |
</h2><?php | |
the_content(); | |
// cogemos las etiquetas de la entrada E actual |
Códigos de ejemplo para extender la WP REST API (http://wp-api.org/). Para probarlos, sólo tienes que:
- incluirlos en el archivo functions.php de tu tema WordPress, y
- tener instalada la WP REST API v1 (https://es.wordpress.org/plugins/json-rest-api/) o v2 (https://wordpress.org/plugins/rest-api/).
This file contains 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 wprin_buscador_shortcode( $atts, $content=null ) { | |
ob_start(); | |
extract( shortcode_atts( array( 'nombre' => '' ), $atts ) ); | |
$string = $atts['nombre']; | |
$args = array( 's' => $string ); | |
$the_query = new WP_Query( $args ); |
This file contains 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 // no copies esta línea | |
add_action( 'transition_post_status', 'comprueba_publicacion', 10, 3 ); | |
function comprueba_publicacion( $new_status, $old_status, $post ) { | |
if ( 'publish' === $new_status ) { | |
// Comprueba que existe una imagen destacada | |
if ( !tiene_imagen_destacada( $post ) ) { | |
wp_die( 'Has olvidado incluir una imagen destacada.' ); |
This file contains 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 | |
if ( have_posts() ) : | |
while ( have_posts() ) : | |
the_post(); | |
//contenido del loop (template tags, html, etc) | |
endwhile; | |
endif; | |
?> |
This file contains 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 my_task() { | |
// Do something. Anything. | |
}//end my_task() | |
add_action( 'my_action', 'my_task' ); | |
// Execute my_task one hour from now... | |
wp_schedule_single_event( time() + 3600, 'my_action' ); |
This file contains 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 my_hourly_task() { | |
// Do something every hour. Anything. | |
}//end my_hourly_task() | |
add_action( 'my_hourly_event', 'my_hourly_task' ); | |
if ( ! wp_next_scheduled ( 'my_hourly_event' ) ) { | |
wp_schedule_event( time(), 'hourly', 'my_hourly_event' ); |
OlderNewer