Skip to content

Instantly share code, notes, and snippets.

View salvatorecapolupo's full-sized avatar
🎯
Focusing

Salvatore Capolupo salvatorecapolupo

🎯
Focusing
View GitHub Profile
@trevex
trevex / scraper.js
Created August 25, 2015 19:56
simple web scraper to download the audio from gamemusic.siroro.co.uk/
var request = require("request"),
cheerio = require("cheerio"),
root = "http://gamemusic.siroro.co.uk/";
function process(url, dir) {
request(url, function(error, response, body) {
if (!error) {
var $ = cheerio.load(body),
filenames = $("span.file-name"),
alert = $("div.alert")[0];
@salvatorecapolupo
salvatorecapolupo / Coffescript -> JS conversion
Last active June 29, 2016 16:13
coffeescript basic: how to install and basic massive compiling
# Using Mac you will need importing cooffe-script library:
sudo npm install -g coffee-script
# now you can convert cooffee-scripts ("compressed" version of a normal javascript file) into more familiar JS, i.e
coffee -c --output gamejs/ game/
#which converts all file into game/ in a new directory called gamejs/.
@technoknol
technoknol / wp-create-own-shortcode.php
Created January 27, 2014 06:50
wordpress create your own shortcode.
<?php
/********************************
This code will allow you to create your own shortcode.
*************************************/
// SHORTCODE FOR GOOGLE ADSENSE
@jackreichert
jackreichert / gist-shortcode.php
Last active September 27, 2017 15:44
WordPress Gist ShortCode
// github gist Shortcode Usage: [gist un="" id=""]
function gist_shortcode( $atts ) {
extract(shortcode_atts(array(
'un' => '',
'id' => ''
), $atts));
return '<script src="https://gist.github.com/' . $username . '/' . $id.'.js"></script>';
}
add_shortcode('gist', 'gist_shortcode');
@danielpataki
danielpataki / ajax-action.php
Last active March 15, 2018 16:22
Ajax in WordPress
add_action( 'wp_ajax_button_click', 'user_clicked' );
function user_clicked() {
update_user_meta( get_current_user_id(), 'clicked_link', 'yes' );
wp_redirect( $_SERVER['HTTP_REFERER'] );
exit();
}
<?php
function writeLog($string) {
$log_file = dirname(__FILE__) . '/log.txt';
if ($fh = @fopen($log_file, "a+")) {
fputs($fh, $string, strlen($string));
fclose($fh);
return true;
}
else {
@nucklearproject
nucklearproject / gist:3895429
Created October 15, 2012 20:59
Jquery regex plugin
:regex
jQuery.expr[':'].regex = function(elem, index, match) {
var matchParams = match[3].split(','),
validLabels = /^(data|css):/,
attr = {
method: matchParams[0].match(validLabels) ?
matchParams[0].split(':')[0] : 'attr',
property: matchParams.shift().replace(validLabels,'')
},
regexFlags = 'ig',
@imath
imath / bp-custom.php
Created September 18, 2014 22:26
add BuddyPress auto suggest mention feature in bbPress.
<?php
/** You could put this in the bp-custom.php file
* @see http://codex.buddypress.org/themes/bp-custom-php/
*/
function custom_bbpress_maybe_load_mentions_scripts( $retval = false ) {
if ( function_exists( 'bbpress' ) && is_bbpress() ) {
$retval = true;
}
return $retval;
@scottopolis
scottopolis / wp-api-user-meta.php
Last active April 18, 2020 19:13
Add user meta to the WP-API
<?php
/* Adds all user meta to the /wp-json/wp/v2/user/[id] endpoint */
function sb_user_meta( $data, $field_name, $request ) {
if( $data['id'] ){
$user_meta = get_user_meta( $data['id'] );
}
if ( !$user_meta ) {
return new WP_Error( 'No user meta found', 'No user meta found', array( 'status' => 404 ) );
}
@jackreichert
jackreichert / inputtitle_submit.js
Last active September 26, 2020 15:03
Example showing how to use AJAX in WordPress
(function ($) {
$(document).ready(function () {
$('#next').click(function () {
$.post(
PT_Ajax.ajaxurl,
{
// wp ajax action
action: 'ajax-inputtitleSubmit',
// vars