Skip to content

Instantly share code, notes, and snippets.

@igmoweb
igmoweb / arguments.js
Created March 16, 2015 20:28
Arguments
// extend the Function object to include a wrap instance method
Function.prototype.wrap = function( callback ) {
var original = this;
// Aquí arguments tiene un sólo elemento (la función anónima que se pasa a speak)
console.log(arguments);
return function() {
// Aquí arguments tiene 23 elementos (¿Por qué?). Son 'Mary' y 'Kate'
// Si estamos en una función anónima sin parámetros,¿No debería estar vacío?
console.log(arguments);
@igmoweb
igmoweb / locations.js
Created February 26, 2015 13:32
locations.js
jQuery(document).ready(function($) {
window.CalendarPlusAdmin = {
models: {},
views: {},
collections: {},
/*****************************************************************/
/** HELPERS **/
@igmoweb
igmoweb / dolly-dynamic.php
Created January 30, 2015 09:17
Generate dynamic CSS
<?php
add_action( 'plugins_loaded', 'dolly_generate_css_file' );
function dolly_generate_css_file() {
if ( isset( $_GET['dolly-styles'] ) && $_GET['dolly-styles'] === 'true' ) {
header( 'Content-type: text/css' );
$options = get_option( 'dolly-options' );
?>
.mi-clase {
background:<?php echo $options['background-color']; ?>;
@igmoweb
igmoweb / dolly-dynamic.php
Last active August 29, 2015 14:14
Generate dynamic CSS stylesheet
<?php
add_action( 'plugins_loaded', 'dolly_generate_css_file' );
function dolly_generate_css_file() {
if ( isset( $_GET['dolly-styles'] ) && $_GET['dolly-styles'] === 'true' ) {
// "Engañar la cabecera"
// Generar aquí el CSS
exit;
}
}
@igmoweb
igmoweb / dynnamic-style.php
Created January 30, 2015 08:57
Enqueue a dynamic style
<?php
add_action( 'wp_enqueue_scripts', 'dolly_load_styles' );
function dolly_load_styles() {
$css_url = add_query_arg( 'dolly-styles', 'true', home_url() );
wp_enqueue_style( 'dolly-styles', $css_url );
}
@igmoweb
igmoweb / wp-head-css.php
Last active August 29, 2015 14:14
Use wp_head to dinamically generate CSS
<?php
add_action( 'wp_head', 'dolly_print_styles' );
function dolly_print_styles() {
$options = get_option( 'my-options' );
?>
<style>
.my-class {
background-color:<?php echo $options['background-color']; ?>;
font-size:<?php echo $options['font-size']; ?>px;
}
@igmoweb
igmoweb / phpunit.xml
Last active August 29, 2015 14:13
phpunit.xml for multisites
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<php>
<const name="WP_TESTS_MULTISITE" value="1" />
<?php
add_action( 'wp_ajax_fictizia_load_posts', 'fictizia_load_posts' );
add_action( 'wp_ajax_nopriv_fictizia_load_posts', 'fictizia_load_posts' );
function fictizia_load_posts() {
$posts = // SELECCIONAMOS LOS POSTS
wp_send_json( $posts );
}
<?php
add_action( 'admin_menu', 'fictizia_add_settings_menu' );
function fictizia_add_settings_menu() {
add_submenu_page( 'fictizia-main', 'Settings', 'Settings', 'manage_options', 'fictizia-settings', 'fictizia_display_settings_menu' );
}
function fictizia_settings_init() {
register_setting( 'OPTIONS_GROUP', 'OPTIONS_GROUP', 'SANITIZE_CALLBACK' );
add_settings_section( 'SECTION_ID', __( 'SECTION_TITLE', 'fictizia' ), 'SECTION_CALLBACK', 'MENU_SLUG' );
<form action="" method="POST">
<table class="form-table">
<tr>
<th scope="row"><?php _e( 'New customer', 'fictizia' ); ?></th>
<td>
<input type="text" name="cliente" value=""/>
</td>
</tr>
</table>