Skip to content

Instantly share code, notes, and snippets.

@jgarciaruiz
jgarciaruiz / check_user_can_access_content.php
Last active October 7, 2015 16:10
Personal extension that connects moodle with my wp plugin "Bookr". Allow access to any Moodle course if you have previously unlocked it in WordPress via Bookr. *Addon for Moodle, must be activated the extension that allows wp authentication (md5).
<?php
/*
//CÓDIGO A INSERTAR EN EL HEADER DEL THEME DE MOODLE
ftp://dominio.es//domains/dominio.es/public_html/tuaulavirtual/theme/essential/layout/includes/header.php
<!-- jvrdbug -->
<?php
include($_SERVER['DOCUMENT_ROOT'].'/tuaulavirtual/check_user_can_access_content.php');
//echo "<div style='display:none' id='jvrdbug'>".($_SERVER['DOCUMENT_ROOT'].'/tuaulavirtual/check_user_can_access_content.php')."</div>";
@jgarciaruiz
jgarciaruiz / makeClickableLinks.php
Created October 16, 2015 13:33
//php function to convert text url into links.
@jgarciaruiz
jgarciaruiz / Added my custom column hpd
Created October 19, 2015 17:11
Add custom field column to WC products admin table
/* WC HPD */
//manage_product_posts_custom_column
add_filter( 'manage_edit-product_columns', 'products_customcol_fn' );
function products_customcol_fn($columns){
$new_columns = (is_array($columns)) ? $columns : array();
$new_columns['HPD'] = 'hpd';
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'products_customcol_value_fn', 2 );
<?php
/**
* Template Name: Movie Reviews
**/
get_header();
?>
<?php
global $post;
$posts = get_posts( array( 'post_type' => 'movie-reviews' ) );
@jgarciaruiz
jgarciaruiz / functions.php
Last active December 9, 2015 13:10
WP movie reviews functions.php
<?php
//create custom post type: movie review
function movie_reviews_init() {
$args = array(
'label' => 'Movie Reviews',
'public' => true,
'show_ui' => true,
'capability_type' => 'page',//post
'hierarchical' => false,
'rewrite' => array('slug' => 'movie-reviews'),
@jgarciaruiz
jgarciaruiz / jsflush.js
Last active October 22, 2015 12:42
JS function to prevent file caching, version randomizer
//fn to prevent file caching
function flushVersion(length) {
var glyphs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP1234567890";
var version = "";
for (var j = 0; j < length; j++) {
var i = Math.floor(Math.random() * glyphs.length);
version += glyphs.charAt(i);
}
return version;
}
@jgarciaruiz
jgarciaruiz / gist:7a1af8dd94f2acb6bfd9
Last active December 9, 2015 13:12
wp-content/mu-plugins -> Disables plugins for API requests in order to speed up the API response times.
<?php
//wp_get_active_and_valid_plugins() is the function which fetches all the active plugins and load them.
//This function gets these active plugins from the database where the list of active plugins are stored
//as an array in the wpdb_options table with option name as “active_plugins”
foreach ( wp_get_active_and_valid_plugins() as $plugin )
include_once( $plugin );
unset( $plugin );
?>
@jgarciaruiz
jgarciaruiz / wp_plugin_load_time.php
Last active December 9, 2015 13:08
Disables plugins for API requests in order to speed up the API response times.
<?php
/*
Plugin Name: WP API Load Time Enhancement
*/
//http://codex.wordpress.org/Must_Use_Plugins
$listener_term = '/webservices/';
$current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '';
// if $current_url contains $listener_term
@jgarciaruiz
jgarciaruiz / gist:0bde4a6725d024ced11f
Last active December 9, 2015 13:11
JS var with functions demo
var $test = $(".ricochet"),
multiply = function(x,y) {
console.log("multiply ok: " + x * y);
},
siberet = function(add2div){
$test.html("siberet ok");//write inside .ricochet
};
siberet( multiply(2,4) );//initialize everythin'
@jgarciaruiz
jgarciaruiz / gist:df93e9cd025edc89e870
Last active December 9, 2015 13:11
js app fn test
var app = {
layout: {
init: function() {
app.loader.init();
console.info("1. app layout init");
var wwidth = window.innerWidth;
var wheight = window.innerHeight;
windowdata(wwidth,wheight);
}