Skip to content

Instantly share code, notes, and snippets.

@gmutschler
gmutschler / element.less
Created October 19, 2014 12:33
LESS Elements A set of useful mixins for LESS, the CSS pre-processor: http://lesscss.org More information and usage examples over at: http://lesselements.com Examples page of all the mixins here: http://lesselements.com/tests Oreolek has a good fork with the mixins organized under namespaces here: https://github.com/Oreolek/elements I recommend …
/*---------------------------------------------------
LESS Elements 0.9
---------------------------------------------------
A set of useful LESS mixins
More info at: http://lesselements.com
---------------------------------------------------*/
.gradient(@color: #F5F5F5, @start: #EEE, @stop: #FFF) {
background: @color;
background: -webkit-gradient(linear,
@gmutschler
gmutschler / formatted_content
Created October 16, 2014 12:39
Similar to get_the_content() but formatted
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
@gmutschler
gmutschler / get_base.php
Created September 14, 2014 21:47
Usefull for site located in subdirectories. Usage: put it in script located in the "home directory" of your site
<?php
function get_base() {
$scriptSubDir = str_replace(dirname(__FILE__), '', str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']));
$baseURI = str_replace($scriptSubDir , '', str_replace('\\', '/',$_SERVER['SCRIPT_NAME']) );
$baseURI = preg_replace('/^\//', '', $baseURI);
$baseURI = preg_replace('/\/$/', '', $baseURI);
return $baseURI;
}
@gmutschler
gmutschler / wordpress post text.less
Last active March 31, 2017 19:59
Basic styling for all elements in wordpress default WYSIWYG editor (without colors)
.entry {
del {text-decoration: line-through;}
strong {font-weight: bold;}
em {font-style: italic;}
h1,h2,h3,h4,h5,h6 {
font-weight: bold;
letter-spacing: -0.005em;
}
@gmutschler
gmutschler / regex cheat sheet
Created September 2, 2014 10:14
Tool to validate regex espressions
http://regex101.com/

PHP Sanitizing filters

List all filters available with your version of PHP

PHP Filters for validation and sanitization are activated by passing at least two values to the PHP Filters Extension function filter_var. As an example, let's use the Sanitize Filter for an Integer number like so:

$value =  '123abc456def';
echo filter_var($value, FILTER_SANITIZE_NUMBER_INT);

In the example, we have a variable $value that is passed through the Filters Extension function filter_var using the FILTER_SANITIZE_NUMBER_INT filter. This results in the following output:

#Data Validation

Untrusted data comes from many sources (users, third party sites, your own database!, ...) and all of it needs to be validated both on input and output.

Easing functions specify the rate of change of a parameter over time.

Objects in real life don’t just start and stop instantly, and almost never move at a constant speed. When we open a drawer, we first move it quickly, and slow it down as it comes out. Drop something on the floor, and it will first accelerate downwards, and then bounce back up after hitting the floor.

This page helps you choose the right easing function.

@gmutschler
gmutschler / sanitizing.md
Created August 20, 2014 11:15
Securing $_POST cheat sheet (from http://stackoverflow.com/posts/3126175)

#Stop!

You're making a mistake here. Oh, no, you've picked the right PHP functions to make your data a bit safer. That's fine. Your mistake is in the order of operations, and how and where to use these functions.

It's important to understand the difference between sanitizing and validating user data, escaping data for storage, and escaping data for presentation.

##Sanitizing and Validating User Data

When users submit data, you need to make sure that they've provided something you expect.

<?php
// WARNING STILL NEED TO SANITIZE
class MyContactPage {
/** Holds the values to be used in the fields callbacks */
private $options;
private $my_option_name = 'contact_infos';
private $my_option_admin_slug = 'contact-informations';