Skip to content

Instantly share code, notes, and snippets.

View kreamweb's full-sized avatar

Emanuela Antonina Castorina kreamweb

  • Kream di Emanuela Castorina
  • Acicatena (CT) - Italy
View GitHub Profile
@kreamweb
kreamweb / parser
Last active August 29, 2015 14:08
Parser a web font style
<?php
$handle = fopen("style.css", "r");
$file = 'config.json';
$arr = array();
if ($handle) {
$key = '';
while (($line = fgets($handle)) !== false) {
preg_match('/[\w-]+/', $line, $matches );
@kreamweb
kreamweb / functions.php
Created December 27, 2014 17:28
[Wordpress] Limit the Number of tags in a widget
<?php
//Register tag cloud filter callback
add_filter('widget_tag_cloud_args', 'tag_widget_limit');
//Limit number of tags inside widget
function tag_widget_limit($args){
//Check if taxonomy option inside widget is set to tags
if(isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag'){
@kreamweb
kreamweb / functions.php
Created July 29, 2015 07:41
Ajax Search from Premium to Free
<?php
if( defined('YITH_WCAS_PREMIUM') ){
global $yith_wcas;
add_filter( 'ywrac_results', 'ywrac_custom_result', 10, 2 );
remove_action( 'pre_get_posts', array( $yith_wcas, 'pre_get_posts' ) );
}
function ywrac_custom_result( $posts, $search_keyword ){
global $woocommerce;
$ordering_args = $woocommerce->query->get_catalog_ordering_args( 'title', 'asc' );
@kreamweb
kreamweb / gist:870494
Created March 15, 2011 09:26
clonare un branch
mkdir $BRANCH
cd $BRANCH
git init
git remote add -t $BRANCH -f origin $REMOTE_REPO
git checkout $BRANCH
oppure
mkdir newrepo.git
cd newrepo.git
git init
@kreamweb
kreamweb / format_date_IT.js
Created December 19, 2011 11:10
Function to format javascript date like php date function
Date.prototype.format = function(format) {
var returnStr = '';
var replace = Date.replaceChars;
for (var i = 0; i < format.length; i++) { var curChar = format.charAt(i); if (i - 1 >= 0 && format.charAt(i - 1) == "\\") {
returnStr += curChar;
}
else if (replace[curChar]) {
returnStr += replace[curChar].call(this);
} else if (curChar != "\\"){
returnStr += curChar;
@kreamweb
kreamweb / csvtoarray.php
Created May 14, 2012 13:21
csv to array
<?php
function csv2array($content, $delim = ';', $encl = '"', $optional = 1) {
if ($content[strlen($content)-1]!="\r" && $content[strlen($content)-1]!="\n")
$content .= "\r\n";
$reg = '/(('.$encl.')'.($optional?'?(?(2)':'(').'[^'.$encl.']*'.$encl.'|[^'.$delim.'\r\n]*))('.$delim.'|\r\n)/smi';
preg_match_all($reg, $content, $treffer);
$linecount = 0;
@kreamweb
kreamweb / wp_remove_gallery_css.php
Last active December 11, 2015 19:18
Filter to remove style from wordpress gallery shortcode
@kreamweb
kreamweb / gist:4649350
Created January 27, 2013 17:37
[wordpress] [filter] Add new Contact Fields to the User Profile
<?php
/*-----------------------------------------------------------------------------------*/
/* New Contacts Fiels
/*-----------------------------------------------------------------------------------*/
function new_contactmethods( $contactmethods ) {
$contactmethods['photo'] = 'Photo Link';
$contactmethods['position'] = 'Position';
$contactmethods['twitter'] = 'Twitter'; // Add Twitter
@kreamweb
kreamweb / complete_dynamic_menu
Last active December 12, 2015 08:38
[Wordpress] Display a list of pages from with all subchilds. A complete dynamic menu
<?php
$a=get_post_ancestors($post->ID,'page');
if(empty($a)){
//I'm in the root page
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$title=$post->post_title;
$id=$post->ID;
}else{
//I'm in a sub page
$last=array_pop($a);
@kreamweb
kreamweb / apply_filter
Created February 22, 2013 06:07
[Wordpress] - How use a filter in wordpress, in this case add a custom content before the content of post
<?php
function theme_slug_filter_the_content( $content ) {
$custom_content = 'YOUR CONTENT GOES HERE';
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'theme_slug_filter_the_content' );
?>