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 / is_parent.php
Last active January 23, 2016 19:50
Wordpress helper: is_parent
<?php
/**
* is_parent
*
* @author JoseRobinson.com
* @link https://gist.github.com/jrobinsonc/e6098d90453d58f31793
* @param int $pid
* @return bool
*/
@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));
}
@danharper
danharper / TimeZones.php
Last active July 5, 2016 22:10
Generates a list of all timezone identifiers, with their offset & made (slightly) more human-readable
<?php
class TimeZones {
/**
* @return array
*/
public function generate()
{
$identifiers = DateTimeZone::listIdentifiers();
@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 / 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 / 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 / scripts.js
Last active August 29, 2015 14:08
Wordpress addon sample code.
_
@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 / get_the_slug.php
Last active March 2, 2020 14:49
Wordpress helper: Get slug
<?php
function get_the_slug()
{
global $post;
return is_single() || is_page()? $post->post_name : '';
}
@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'