YUI link slideshows between multiple pages

this code is created by me to link galleries between pages on this squarespace site: http://irenehoffman.com/

using YUI library

 

  Y.use('node', function() {
      Y.on('domready', function() {
if (Y.one('.next-slide')) {
          if (!Modernizr.touch) {
              Y.one('body').on('mousemove', function(event) {
                  if (event.clientX <= Y.one('body').get('winWidth') / 2 && Y.one('.nav.subnav ul li.gallery-collection.active-link').previous()) {
                      Y.one('.arrow-wrapper.left').addClass('seko').siblings().removeClass('seko');
                  } else if (event.clientX > Y.one('body').get('winWidth') / 2 && Y.one('.nav.subnav ul li.gallery-collection.active-link').next()) {
                      Y.one('.arrow-wrapper.right').addClass('seko').siblings().removeClass('seko');
                  }
              });

              Y.one('body').on('mouseleave', function() {
                  Y.all('.arrow-wrapper').removeClass('seko');
              });

          }

          Y.one('.next-slide').on('click', function(event) {
              if (!Y.one('#fullscreenBrowser .slideshow > .sqs-active-slide').next() && Y.one('.nav.subnav ul li.gallery-collection.active-link').next()) {
                  window.location = Y.one('.nav.subnav ul li.gallery-collection.active-link').next().one('a').get('href');
              }
          });

          Y.one('.prev-slide').on('click', function(event) {
              if (!Y.one('#fullscreenBrowser .slideshow > .sqs-active-slide').previous() && Y.one('.nav.subnav ul li.gallery-collection.active-link').previous()) {
                  window.location = Y.one('.nav.subnav ul li.gallery-collection.active-link').previous().one('a').get('href');
              }
          });

      }


      });
  });

 

WordPress Shortcode to get today’s birthday, yesterday and the day before

this is a shortcode created for a client to get the birthday of his employee from a custom database table with 3 varchar fields : name, area and date.

you will notice there is two versions one using server time and the other using wordpress current time function. because the timezone of the server is different than the user set timezone in wordpress

// [birthday-today] shortcode
function birthday_today_func( $atts ){

global $wpdb;

    $birthdays = $wpdb->get_results("SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(NOW()) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(NOW())");

    if($birthdays){
		
		$birthdays_out =  "Today's birthdays:<br><ul>";
		foreach ( $birthdays as $birthday ) 
		{
			$birthdays_out .= '<li> '.$birthday->name. ' - '.$birthday->area. ' - '.$birthday->date.'.</li>';
		}

		$birthdays_out .= '</ul>';

	}

if(date('D', $timestamp) === 'Mon') {

	$y_birthdays = $wpdb->get_results("SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(CAST(NOW() - INTERVAL 1 DAY AS DATE)) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(CAST(NOW() - INTERVAL 1 DAY AS DATE))");

	if($y_birthdays){
		$birthdays_out .= '<br>  Birthdays on '.date("l  d/m", strtotime("yesterday")).'<br><ul>';

		foreach ( $y_birthdays as $y_birthday ) 
		{
			$birthdays_out .= '<li> '.$y_birthday->name. ' - '.$y_birthday->area. ' - '.$y_birthday->date.'.</li>';
		}

		$birthdays_out .= '</ul>';
	}




	$y2_birthdays = $wpdb->get_results("SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(CAST(NOW() - INTERVAL 2 DAY AS DATE)) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(CAST(NOW() - INTERVAL 2 DAY AS DATE))");

	if($y2_birthdays){
		$birthdays_out .= '<br>Birthdays on '.date("l d/m", strtotime("-2 day")).'<br><ul>';
		foreach ( $y2_birthdays as $y2_birthday ) 
		{
			$birthdays_out .= '<li> '.$y2_birthday->name. ' - '.$y2_birthday->area. ' - '.$y2_birthday->date.'.</li>';
		}

		$birthdays_out .= '</ul>';
	}
}

return $birthdays_out;
}
add_shortcode( 'birthday-today', 'birthday_today_func' );
// [birthday-today] shortcode
function birthday_today_func( $atts ){

global $wpdb;
$current_time =current_time( 'mysql' );
$sql = "SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH('".$current_time."') AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY('".$current_time."')";
    $birthdays = $wpdb->get_results($sql);

    if($birthdays){
		//print_r($birthdays);
		$birthdays_out =  "Hoy cumplen años:<br><ul>";
		foreach ( $birthdays as $birthday ) 
		{
			//$birthdays_out .= '<li> '.$birthday->name. ' - '.$birthday->area. ' - ' .$birthday->date. '.</li>';
			$birthdays_out .= '<li> '.$birthday->name. ' - '.$birthday->area.'.</li>';
		}

		$birthdays_out .= '</ul>';

	}
	
	
if(current_time('D') === 'Mon') {
$sql2 = "SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(CAST('".$current_time."' - INTERVAL 1 DAY AS DATE)) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(CAST('".$current_time."' - INTERVAL 1 DAY AS DATE))";
	$y_birthdays = $wpdb->get_results($sql2);

	if($y_birthdays){
		$yest = $current_time.' -1 day';
		$birthdays_out .= '<br>  Cumplieron el domingo '.date("l  d/m", strtotime($yest)).'<br><ul>';

		foreach ( $y_birthdays as $y_birthday ) 
		{
			//$birthdays_out .= '<li> '.$y_birthday->name. ' - '.$y_birthday->area. ' - ' .$y_birthday->date.  '.</li>';
			$birthdays_out .= '<li> '.$y_birthday->name. ' - '.$y_birthday->area.'.</li>';
		}

		$birthdays_out .= '</ul>';
	}



$sql3 = "SELECT * FROM Birthdays WHERE MONTH(STR_TO_DATE(date, '%d/%m/%Y')) = MONTH(CAST('".$current_time."' - INTERVAL 2 DAY AS DATE)) AND DAY(STR_TO_DATE(date, '%d/%m/%Y')) = DAY(CAST('".$current_time."' - INTERVAL 2 DAY AS DATE))";
	$y2_birthdays = $wpdb->get_results($sql3);

	if($y2_birthdays){
		$day_before_yest = $current_time.' -2 days';
		$birthdays_out .= '<br>Cumplieron el sabado '.date("l d/m", strtotime($day_before_yest)).'<br><ul>';
		foreach ( $y2_birthdays as $y2_birthday ) 
		{
			//$birthdays_out .= '<li> '.$y2_birthday->name. ' - '.$y2_birthday->area. ' - ' .$y2_birthday->date.  '.</li>';
			$birthdays_out .= '<li> '.$y2_birthday->name. ' - '.$y2_birthday->area.'.</li>';
		}

		$birthdays_out .= '</ul>';
	}
}

return $birthdays_out;
}
add_shortcode( 'birthday-today', 'birthday_today_func' );

 

the result:

PSA Peugeot Citroën 2014-09-30 03-49-11

 

used with this plugin to import csv into the database table:
https://www.tipsandtricks-hq.com/wp-csv-to-database-plugin-import-excel-file-content-into-wordpress-database-2116

get wordpress menu custom css classes and add it to body classes

 

add_filter('body_class','add_nav_menu_css');
function add_nav_menu_css($classes) {

$menu_name = 'primary'; // menu theme location
global $wp_query;
$queried_object = $wp_query->get_queried_object();
$current_id = $queried_object->ID; 
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
        $items = wp_get_nav_menu_items($menu->term_id);

        foreach ($items as $i) {
                if($current_id == $i->object_id){
					$menuClasses .= $i->classes[0].' ';
				}
				
        }

        $classes[] = $menuClasses;

}
        return $classes;

}

force scripts into the footer in wordpress

function custom_clean_head() {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);

add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
}

add_action( 'wp_enqueue_scripts', 'custom_clean_head' );

know your client from his password

if the client password is too complicated then he is not feeling safe or secure and he needs assurance or he uses lastpass . if the password is too simple and silly then he is not totally into the web thing. the web is a game for him. if it is really simple and gues free, either he have a lot to remember already or he is just lazy

code to exclude posts on homepage

this code in function.php

function get_hidden_posts() {
global $WP_Query;
$now_minus2 = date('Y-m-d H:i:s', strtotime('-120 minute', current_time('timestamp')));
$args = array(
    'date_query' => array(
        array(
            'before' => $now_minus2
        )
    ),
    'meta_query' => array(
        array(
            'key' => '¿directo?',
            'value' => 'Si',
            'compare' => '='
        )
    ),
    'posts_per_page' => -1,
    'fields' => 'ids'
);
$query_post_to_hide = new WP_Query($args);
$post_to_hide = array();
while ( $query_post_to_hide->have_posts() ) {
	$query_post_to_hide->the_post();
	$post_to_hide[] = get_the_ID();
}
return $post_to_hide;

}

function exclude_hidden_posts( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post__not_in', get_hidden_posts() );
    }
}
add_action( 'pre_get_posts', 'exclude_hidden_posts' );

 

how to fix wordpress http error on image upload

install the default to gd wordpress plugin
https://github.com/alhoseany/default-to-gd As of WordPress 3.5, GD has been abstracted out into WP_Image_Editor, and Imagick has been made the default image manipulation engine.

In most cases, this is what you want.  However, if you’re having issues with Imagick, or just prefer the way that GD handles your images, this plugin sets GD as the default WP_Image_Editor class for WordPress.

other fixes:

1- change permission on async-upload.php

usually this is done when the normal browser uploader is working and the multiple file uploader or the flash uploader is not working

chmod 644 /public_html/wp-admin/async-upload.php

2- htaccess solution in wp-admin folder

# Exclude the file upload and WP CRON scripts from authentication
<FilesMatch "(async-upload.php|wp-cron.php|xmlrpc.php)$">
    Satisfy Any
    Order allow,deny
    Allow from all
    Deny from none
</FilesMatch>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

3- htaccess above the web root or in “public_html”

<IfModule mod_security.c>
  <Files async-upload.php>
    SecFilterEngine Off
    SecFilterScanPOST Off
  </Files>
</IfModule>