Skip to content

Instantly share code, notes, and snippets.

View jrobinsonc's full-sized avatar
🎯
Focusing

Jose Robinson jrobinsonc

🎯
Focusing
View GitHub Profile
@jrobinsonc
jrobinsonc / tweets.php
Created May 9, 2014 20:40
Get tweets from Twitter API v1.1
<?php
function get_twitter_access_token($consumer_key, $consumer_secret)
{
$options = array(
CURLOPT_POSTFIELDS => array('grant_type' => 'client_credentials'),
CURLOPT_HTTPHEADER => array('Authorization: Basic ' . base64_encode($consumer_key . ':' . $consumer_secret)),
CURLOPT_HEADER => FALSE,
CURLOPT_URL => 'https://api.twitter.com/oauth2/token',
CURLOPT_RETURNTRANSFER => TRUE
@jrobinsonc
jrobinsonc / linkify.php
Last active August 29, 2015 14:01
Linkify
<?php
/**
* linkify
*
* @link Github: https://gist.github.com/jrobinsonc/e79578c41ca48bac9bde
* @param string $value
* @param array $protocols
* @param array $attributes
* @param string $mode
@jrobinsonc
jrobinsonc / example.php
Last active August 29, 2015 14:04
Wordpress filter: image_downsize
<?php
/**
* Default:
*/
$post_thumbnail_id = get_post_thumbnail_id(get_the_ID());
$width = 640;
$height = 480;
@jrobinsonc
jrobinsonc / get_file_url.php
Last active August 29, 2015 14:08
Wordpress helper: Get file URL
<?php
/**
* get_file_url
*
* Usage example:
*
* URL relative to the base file:
* get_file_url('styles.css', __FILE__);
*
@jrobinsonc
jrobinsonc / scripts.js
Last active August 29, 2015 14:08
Wordpress addon sample code.
_
@jrobinsonc
jrobinsonc / wp-shortcodes.php
Last active August 29, 2015 14:08
Wordpress shortcode: Shortcodes for native functions of wordpress.
<?php
// Use shortcodes within text widgets
add_filter('widget_text', 'do_shortcode');
// wp_nav_menu
add_shortcode('wp_nav_menu', 'wp_nav_menu_shortcode');
function wp_nav_menu_shortcode($atts = array(), $content = '')
{
@jrobinsonc
jrobinsonc / get_url_shortcode.php
Last active August 29, 2015 14:08
Wordpress shortcode: get_url - Return an absolute URL.
<?php
/**
* Return an absolute URL.
*
* Usage:
* [get_url page=<page id>]
*
* or
*
@jrobinsonc
jrobinsonc / imagettftext_in_lines.php
Last active August 29, 2015 14:15
Write text to the image using TrueType fonts and split text into several lines based on a width size.
<?php
/**
* imagettftext_in_lines
*
* @author JoseRobinson.com
* @link https://gist.github.com/jrobinsonc/699ea6fadd7369146574
* @version 201502131102
* @param $image An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
* @param $font_size The font size. Depending on your version of GD, this should be specified as the pixel size (GD1) or point size (GD2).
@jrobinsonc
jrobinsonc / hex2rgb.php
Created March 9, 2015 19:32
Function for converting colors from hexadecimal to RGB.
function hex2rgb($hex)
{
$hex = str_replace("#", "", $hex);
if(strlen($hex) === 3)
{
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
}
@jrobinsonc
jrobinsonc / example1.php
Last active September 5, 2015 22:15
Wordpress helper: Post views - Set and get the number of views/hits of a post.
<?php
#####################################################
# Example to show most visited posts.
#####################################################
$custom_query = new WP_query(array(
'meta_key' => Posts_views::$key,
'orderby' => 'meta_value_num',
'order' => 'DESC'