Skip to content

Instantly share code, notes, and snippets.

@perezdans
Last active September 4, 2017 18:33
Show Gist options
  • Save perezdans/2429378cdc53f9a25b3eaa5820b928ca to your computer and use it in GitHub Desktop.
Save perezdans/2429378cdc53f9a25b3eaa5820b928ca to your computer and use it in GitHub Desktop.
Código para introducir en el functions.php para crear un shortcode que permita que determinados contenidos solo se muestren a determinados usuarios
<?php
add_shortcode( ‘registrado’, ‘shortcode_para_registrados’ );
function shortcode_para_registrados( $atts, $content = null ) {
global $current_user;
get_currentuserinfo();
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) {
if (is_array($atts) && $atts['usuario'] == $current_user->user_login)
return $content;
}
return '';
}
/*
Ejemplo:
[registrado usuario="alvarez"] Esto solo le sale a alvarez [/registrado]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment