ID) . '">' . $addReadMore . ''; if ($addP) $output = '

' . $output . '

'; if ($echo) echo $output; else return $output; } // FINE EXCERPT // INIZIO FUNZIONE PER TIMTHUMBS function get_thumb($img, $w = false, $h = false, $zc = false, $a = false) { $img = preg_replace("!http(s)?://{$_SERVER['SERVER_NAME']}/!", '/', $img); $size = array(); if ( $w ) $size[] = "w={$w}"; if ( $h ) $size[] = "h={$h}"; if ( $zc ) $size[] = "zc={$zc}"; if ( $a ) $size[] = "a={$a}"; return esc_attr(sprintf('%s/tt.php?src=%s&%s', get_option('siteurl'), urlencode($img), implode('&', $size))); } // FINE FUNZIONE PER TIMTHUMBS function get_tpl_url($relative_uri, $encode = true) { $return = get_template_directory_uri() . $relative_uri; return $encode ? esc_attr($return) : $return; } // INIZIO FUNZIONE PERSONALE PER MENU class My_Walker_Page extends Walker_Page { private $forceCurrent = false, $sm_class = 'children', $active_class = 'active'; public function __construct($subMenuClass = Null, $activeClass = Null, $curentPage = Null) { if (!is_null($subMenuClass)) $this->sm_class = $subMenuClass; if (!is_null($activeClass)) $this->active_class = $activeClass; if (!is_null($curentPage)) $this->forceCurrent = $curentPage; } public function start_lvl( &$output, $depth = 0, $args = array() ) { $output .= sprintf('"; } public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) { if ($this->forceCurrent) $current_page = $this->forceCurrent; $css_class = array( 'page-' . $page->ID ); if (isset($args['pages_with_children'][$page->ID])) $css_class[] = 'parent'; If (!empty($current_page)) { $_current_page = get_post($current_page); if ($page->ID == $current_page || ($_current_page && $page->ID == $_current_page->post_parent)) $css_class[] = $this->active_class; } elseIf ($page->ID == get_option('page_for_posts')) $css_class[] = $this->active_class; if ($page->post_title === '') $page->post_title = $page->ID; $output .= sprintf( '
  • %s%s%s', implode(' ', $css_class), get_permalink($page->ID), empty($args['link_before']) ? '' : $args['link_before'], $page->post_title, empty($args['link_after']) ? '' : $args['link_after'] ); } public function end_el( &$output, $page, $depth = 0, $args = array() ) { $output .= "
  • "; } } function my_wp_list_pages( $depth = 2, $subMenuClass = Null, $activeClass = Null, $parent = 0 ) { global $currentPage; if (!isset($currentPage)) $currentPage = Null; return wp_list_pages(array ( 'echo' => false, 'title_li' => false, 'depth' => $depth, 'child_of' => $parent, 'walker' => new My_Walker_Page($subMenuClass, $activeClass, $currentPage) )); } // FINE FUNZIONE PERSONALE PER MENU // INIZIO FUNZIONE PER IL DEBUG function gDebug($mixed, $exit = true) { echo '
    ';
        print_r($mixed);
        echo '
    '; if ($exit) exit; } // FINE FUNZIONE PER IL DEBUG // INIZIO FUNZIONE PER PULIRE UN ARRAY function cleanArrayData($array, $assoc = false, $recursive = false) { foreach ($array as $key => $value) { if (is_array($value)) { if (!$recursive) continue; $value = cleanArrayData($value, $assoc, $recursive); if ( !empty($value) ) $array[$key] = $value; else unset($array[$key]); } else { if (is_string($value)) { $clean_value = trim(stripslashes($value)); if (empty($clean_value)) unset($array[$key]); else $array[$key] = $clean_value; } else if (empty($value)) unset($array[$key]); } } return $assoc ? $array : array_values($array); } // FINE FUNZIONE PER PULIRE UN ARRAY // INIZIO FUNZIONE PER OFFUSCARE JAVASCRIPT function jsPack($source) { if (!class_exists('JavaScriptPacker')) require_once 'scripts/JavaScriptPacker.php'; $packer = new JavaScriptPacker($source); return trim($packer->pack()) . ';'; } // FINE FUNZIONE PER OFFUSCARE JAVASCRIPT // INIZIO FUNZIONE PER OFFUSCARE INDIRIZZI EMAIL function antispam_email_shortcode($atts, $content = null) { $email = explode('@', $content); $code = array(); $code[] = sprintf("var email = ('%s' + '@' + '%s');", $email[0], $email[1]); $code[] = "document.write('' + email + '');"; return sprintf('', jsPack(implode(PHP_EOL, $code))); } add_shortcode('email', 'antispam_email_shortcode'); // FINE FUNZIONE PER OFFUSCARE INDIRIZZI EMAIL // INIZIO FUNZIONE PER LESS function addLess($path, $params = array(), $compress = true) { if (!class_exists('lessc')) require_once 'scripts/lessc.inc.php'; $Lessc = new lessc(); $Lessc->setVariables($params); if ($compress) $Lessc->setFormatter('compressed'); $filename = pathinfo($path, PATHINFO_FILENAME); $css = sprintf('/css/%s%s.css', $filename, count($params) ? ('-' . md5(serialize($params))) : ''); $Lessc->checkedCompile(get_template_directory() . $path, get_template_directory() . $css); return get_template_directory_uri() . $css; } // FINE FUNZIONE PER LESS // INIZIO FUNZIONE PER VERIFICARE ESECUZIONE ONLINE function imOnline() { return !isset($_SERVER['LOCALHOST_EXEC']); } // FINE FUNZIONE PER VERIFICARE ESECUZIONE ONLINE function register_my_menu() { register_nav_menu('main-menu', __('Main menu', 'base')); } add_action('init', 'register_my_menu'); function my_wp_nav_menu_items($sorted_menu_items, $args) { global $forceCurrentMenuItem; if ($forceCurrentMenuItem) { foreach($sorted_menu_items as &$item) { if ($item->object_id == $forceCurrentMenuItem) { $item->classes[] = 'current-menu-item'; } } } return $sorted_menu_items; } add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_items', 10, 2); if (function_exists('acf_add_options_page')) { acf_add_options_page(array ( 'page_title' => 'Opzioni generali', 'menu_title' => 'Opzioni generali', 'menu_slug' => 'general-settings', 'capability' => 'edit_posts', 'redirect' => false )); } function the_my_posts_pagination($customQuery = null) { $backup = null; if (is_object($customQuery)) { $backup = $GLOBALS['wp_query']; $GLOBALS['wp_query'] = $customQuery; } $pagination = get_the_posts_pagination(array ( 'prev_text' => '<', 'next_text' => '>', )); $pagination = str_replace("\n", '', $pagination); echo $pagination; if (is_object($customQuery)) $GLOBALS['wp_query'] = $backup; } function my_get_post_image_src($postid = null) { $src = wp_get_attachment_image_src(get_post_thumbnail_id($postid), 'full'); return $src[0]; } function add_my_body_class($classes, $class) { if (get_field('force_small_header')) $classes[] = 'small-header'; return $classes; } add_filter('body_class', 'add_my_body_class', 10, 2); // Callback function to insert 'styleselect' into the $buttons array function my_mce_buttons_2( $buttons ) { array_unshift( $buttons, 'styleselect' ); return $buttons; } // Register our callback to the appropriate filter add_filter('mce_buttons_2', 'my_mce_buttons_2'); // Callback function to filter the MCE settings function my_mce_before_init_insert_formats( $init_array ) { // Define the style_formats array $style_formats = array( // Each array child is a format with it's own settings array( 'title' => 'Bottone Read More', 'selector' => 'a', 'classes' => 'more-link' ) ); // Insert the array, JSON ENCODED, into 'style_formats' $init_array['style_formats'] = json_encode( $style_formats ); return $init_array; } // Attach callback to 'tiny_mce_before_init' add_filter( 'tiny_mce_before_init', 'my_mce_before_init_insert_formats' );