martedì 22 ottobre 2013

Plugins per un ecommerce fotografico.

1) CP Imagestore

http://wordpress.org/plugins/cp-image-store/

vantaggi:
diversi formati fotografici
upload automatico dopo acquisto

a pagamento:
watermark
shopper cart


2) Imagestore
http://wordpress.org/plugins/image-store/

vantaggi:
multiupload immagini
cartelle protette
diversi formati fotografici

Plugin Wordpress: Subscribe 2

1) Per il problema di TITLE sull'oggetto della mail va sostituito su Template TITLE con {TITLE}

2) Per inviare mail HTML o modificare il corpo del messaggio bisogna intervenire su class-s2-core.php

ad esempio nella linea 242

if ( 'html' == $type ) {
$headers = $this->headers('html');
if ( 'yes' == $this->subscribe2_options['stylesheet'] ) {
$mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title><link rel=\"stylesheet\" href=\"" . get_stylesheet_uri() . "\" type=\"text/css\" media=\"screen\" /></head><body><table><tr><td><img src='URL IMMAGINE' /></td></tr><tr><td bgolor='#FFFFFF'>" . $message . "</td></tr></table></body></html>", $subject, $message);
} else {
$mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title></head><body><table><tr><td><img src='URL IMMAGINE'/></td></tr><tr><td bgolor='#FFFFFF'>" . $message . "</td></tr></table></body></html>", $subject, $message);

}

giovedì 10 ottobre 2013

Creare un nuovo Post Type

Ad esempio un post type "Issuu":

Codice su function.php

add_action( 'init', 'ts_issuu_cpt_register' );

function ts_issuu_cpt_register() {

    $labels = array(
        'name' => _x( 'Issuu', 'issuu' ),
        'singular_name' => _x( 'Issuu', 'issuu' ),
        'add_new' => _x( 'Add New', 'Issuu' ),
        'add_new_item' => _x( 'Add New Issuu', 'issuu' ),
        'edit_item' => _x( 'Edit Issuu', 'issuu' ),
        'new_item' => _x( 'New Isuu', 'issuu' ),
        'view_item' => _x( 'View Isuu', 'issuu' ),
        'search_items' => _x( 'Search Isuu', 'issuu' ),
        'not_found' => _x( 'No issus found', 'issuu' ),
        'not_found_in_trash' => _x( 'No issuu found in Trash', 'video' ),
        'parent_item_colon' => _x( 'Parent Issuu:', 'issuu' ),
        'menu_name' => _x( 'Issuu', 'issuu' ),
    );

    $args = array(
        'labels' => $labels,
        'hierarchical' => false,      
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields'),
        'taxonomies' => array( 'category' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 6,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );

    register_post_type( 'issuu', $args );
   
    flush_rewrite_rules();
}

Da notare che si modifica la funziona da loggato per vedere le novità bisogna sloggarsi e entrare di nuovo.

Alcune caratteristiche:

       'taxonomies' => array( 'category' ) per usare le categorie di default 

venerdì 4 ottobre 2013

Intervenire su Wordpress da database

1) Disattivare Plugins

Tabella: wp_options
option_name: active_plugins -> Si trovano gli elenchi dei plugin attivi.

2) Reimpostare i permalink con l'impostazione base

Tabella: wp_options
option_name:permalink_structure  valore:vuoto

venerdì 19 aprile 2013

Funzioni Devel

dpm($x);


dvm($x)

lunedì 1 aprile 2013

Funzione per creare breadcrumbs in wordpress

function create_breadcrumbs() {
  
  $delimiter = '/';
  $home = 'Home';
  $before = '<span class="current">';
  $after = '</span>';
  
  if ( !is_home() && !is_front_page() || is_paged() ) {
  
    echo '<div id="breadcrumbs">';
  
    global $post;
    $homeLink = get_bloginfo('url');
    echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
  
    if ( is_category() ) {
      global $wp_query;
      $cat_obj = $wp_query->get_queried_object();
      $thisCat = $cat_obj->term_id;
      $thisCat = get_category($thisCat);
      $parentCat = get_category($thisCat->parent);
      if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
      echo $before . single_cat_title('', false) . $after;
  
    } elseif ( is_day() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
      echo $before . get_the_time('d') . $after;
  
    } elseif ( is_month() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo $before . get_the_time('F') . $after;
  
    } elseif ( is_year() ) {
      echo $before . get_the_time('Y') . $after;
  
    } elseif ( is_single() && !is_attachment() ) {
      if ( get_post_type() != 'post' ) {
        $post_type = get_post_type_object(get_post_type());
        $slug = $post_type->rewrite;
        echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
        echo $before . get_the_title() . $after;
      } else {
        $cat = get_the_category(); $cat = $cat[0];
        echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
        echo $before . get_the_title() . $after;
      }
  
    } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
      $post_type = get_post_type_object(get_post_type());
      echo $before . $post_type->labels->singular_name . $after;
  
    } elseif ( is_attachment() ) {
      $parent = get_post($post->post_parent);
      $cat = get_the_category($parent->ID); $cat = $cat[0];
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
      echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
      echo $before . get_the_title() . $after;
  
    } elseif ( is_page() && !$post->post_parent ) {
      echo $before . get_the_title() . $after;
  
    } elseif ( is_page() && $post->post_parent ) {
      $parent_id  = $post->post_parent;
      $breadcrumbs = array();
      while ($parent_id) {
        $page = get_page($parent_id);
        $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
        $parent_id  = $page->post_parent;
      }
      $breadcrumbs = array_reverse($breadcrumbs);
      foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
      echo $before . get_the_title() . $after;
  
    } elseif ( is_search() ) {
      echo $before . get_search_query() . $after;
  
    } elseif ( is_tag() ) {
      echo $before . single_tag_title('', false) . $after;
  
    } elseif ( is_author() ) {
       global $author;
      $userdata = get_userdata($author);
      echo $before . $userdata->display_name . $after;
  
    } elseif ( is_404() ) {
      echo $before . 'Error 404' . $after;
    }
  
    if ( get_query_var('paged') ) {
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
      echo __('Page') . ' ' . get_query_var('paged');
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
    }
  
  
    echo '</div>';
  
  }
}
<?php create_breadcrumbs(); ?>
Presa da html.it

domenica 31 marzo 2013

Plugin Wordpress: qtranslate

Plugin per la gestione lingue:

1) Il plugin può interagire con la visualizzazione delle date. Per visualizzare le date tradotto e non "%d 28UTC %B 28UTC %Y" bisogna andare su impostazioni avanzate e su "conversione data e ora" spuntare "Usa strftime invece di date e e sostituisce con i formati predefiniti per ciascun linguaggio."

sabato 30 marzo 2013

Path assoluto in WP

Usare la costante ABSPATH.

Ad esempio puo' essere utile per utilizzare la funzione getimagesize su un magic_field, visto che:

1) getimagesize non accetta url assoluti
2) magic_field non reagisce con wp_get_attachment_src

 quindi si puo' usare:

 $absurl=ABSPATH."wp-content/files_mf/".$step["date_image"][1]["name"];

 dove $step["date_image"][1]["name"] e' il nome dell'immagine

e poi:

$dim=getimagesize($absurl);

domenica 24 febbraio 2013

Plugin Wordpress: Event Manager

Crea Eventi e calendario associato.

Alcune info utili:

1) Visualizzare il calendario con script:

the_widget("EM_Widget_Calendar");

Per cambiare dei parametri:

the_widget("EM_Widget_Calendar", $instance, $arg);

Ad esempio aggiungendo precedentemente l'idcategoria per restituire solo un calendario relativo alla categoria:

$instance["category"]=$idcategoriaevento

2) Tabelle nel db di wordpress:

I singoli eventi vengono inseriti nella tabella wp_post come post_type "event" e nella tabella nuova wp_em_events in cui viene chiamato l'id del post.

3) Categorie evento.

Per recuperare le categorie evento tramite script:

$cat_evento=array_keys($event->get_categories()->categories)

dove l'id della categoria è restituita da

$cat_evento[0];


mercoledì 13 febbraio 2013

shortcode

La funzione add_shortcode('shortcode', 'do_something') aggiunge un shortcode 'shortcode' abbinandolo a una funzione.

Se nel shortcode sono presenti attributi [shortcode titolo="X"]
l'attributo viene poi chiamato nella funzione do_something($attr) con

$titolo=$attr["titolo"]

lunedì 4 febbraio 2013

Font esterne con css3

Esempio:

@font-face {
 font-family: 'Ball';
 src: url("../font/BALLW___.eot") /* EOT file for IE */
}

@font-face{
font-family: 'Ball';
src: url('../font/BALLW___.TTF');
}

martedì 29 gennaio 2013

Upload multifile con wordpress via script

Per aggiungere piu' di un file (in rosso le differenze rispetto allo script precedente).

for($x=1;$x<7;$x++) {
    
     $nomefile="file_".$x;
     if($_FILES[$nomefile]['name']) {
  
 if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
$uploadedfile = $_FILES[$nomefile];
$wp_filetype = wp_check_filetype(basename($uploadedfile), null );
//print_r($_FILES[$nomefile]);
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
  //  echo "File is valid, and was successfully uploaded.\n";
    var_dump( $movefile);
} else {
  //  echo "Possible file upload attack!\n";
}$title = $_FILES[$nomefile]['name'];

  $attachment = array(
                'post_mime_type'    => 'image/jpeg',
                'post_title'        => addslashes($title),
                'post_content'      => '',
                'post_status'       => 'inherit',
                'post_parent'       => $newpostID
            );

$attach_id  = wp_insert_attachment($attachment, $uploadedfile, $newpostID);


$wp_upload_dir = wp_upload_dir();
$filename=$wp_upload_dir['path'] . '/' . $title;

  require_once(ABSPATH . 'wp-admin/includes/image.php');


  $attach_data = wp_generate_attachment_metadata( $attach_id, $filename);

 
  $nuovaurl=$attach_data["file"];

 update_post_meta($attach_id, '_wp_attached_file', $nuovaurl);

 if($nomefile=="file_1") {

update_post_meta($newpostID, '_thumbnail_id', $attach_id);

 
 }


     } else {
     header('Location: http://www.ateamgarage.com/wp/form?message=ok');
          }

     }

Upload di file via script con wordpress

if($_FILES["file"]) {
  
 if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
$uploadedfile = $_FILES['file'];
$wp_filetype = wp_check_filetype(basename($uploadedfile), null );

$upload_overrides = array( 'test_form' => false );


// fa l'upload del file
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
    echo "File is valid, and was successfully uploaded.\n";
    var_dump( $movefile);
} else {
    echo "Possible file upload attack!\n";
}
 $title = $_FILES['file']['name'];
      
  $attachment = array(
                'post_mime_type'    => 'image/jpeg',
                'post_title'        => addslashes($title),
                'post_content'      => '',
                'post_status'       => 'inherit',
                'post_parent'       => $newpostID
            );


// crea il collegamento tra tra file uploadato e post
$attach_id  = wp_insert_attachment($attachment, $uploadedfile, $newpostID);




$wp_upload_dir = wp_upload_dir();
$filename=$wp_upload_dir['path'] . '/' . $title;

  require_once(ABSPATH . 'wp-admin/includes/image.php');

// crea i thumbnail
  $attach_data = wp_generate_attachment_metadata( $attach_id, $filename);

 
  $nuovaurl=$attach_data["file"];

  // aggiorna l'informazione sull'url del file nel database
 return update_post_meta($attach_id, '_wp_attached_file', $nuovaurl);


// rende l'immagine come immagine in evidenza
 return update_post_meta($newpostID, '_thumbnail_id', $attach_id);

     }

venerdì 11 gennaio 2013

Aggiornare wordpress manualmente

1) Disattivare plugins e temi non default
2) Files da conservare: wp-config.php e cartella wp-content
3) Cancellare il resto e uploadare wp-admin / wp-include e i files della root
4) Una volta finito l'upload eseguire la pagina /wp-admin/upgrade.php