Skip to content

Instantly share code, notes, and snippets.

@habibmac
habibmac / instagram-fetch.php
Created April 8, 2023 22:43 — forked from kingkool68/instagram-fetch.php
A brief example of working with an external API in WordPress
<?php
// In this brief example we'll scrape an Instagram post and save it as a WordPress post
// Go to a URL and get the contents back
// See https://developer.wordpress.org/reference/functions/wp_remote_get/
$instagram_request = wp_remote_get( 'https://www.instagram.com/p/BSBvNVIF8tI/' );
// If it's succesful, the payload of the request will be in $instagram_request['body']
$instagram_html = $instagram_request['body'];
@habibmac
habibmac / gist:4123753
Created November 21, 2012 08:12 — forked from shrwnsan/gist:2860805
Sublime Text 2 - Fetch Settings
{
"files":
{
"jquery" : "http://code.jquery.com/jquery.js",
"jquery.min" : "http://code.jquery.com/jquery.min.js",
"jquery-cookie" : "https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js",
"jquery-dotimeout" : "https://raw.github.com/cowboy/jquery-dotimeout/master/jquery.ba-dotimeout.min.js",
"jquery-extra-selectors" : "https://raw.github.com/keithclark/JQuery-Extended-Selectors/master/jquery-extra-selectors.js",
"jquery-flexslider" : "https://raw.github.com/mbmufffin/FlexSlider/master/jquery.flexslider-min.js",
"jquery-mediaelement" : "https://raw.github.com/johndyer/mediaelement/master/build/mediaelement-and-player.js",
@habibmac
habibmac / gist:3006847
Created June 27, 2012 21:05 — forked from boonebgorges/gist:2185537
Recursively sort the output of get_categories() in order of parent-child hierarchy
<?php
$categories = get_the_category();
// Assemble a tree of category relationships
// Also re-key the category array for easier
// reference
$category_tree = array();
$keyed_categories = array();
@habibmac
habibmac / Blitar
Created June 23, 2012 16:51
BlitarFurniture
Category:
pagination
category links
sidebar: child category
Sub Category 1 (eg. Interior)
category title
pagination
Portfolio/ Product
@habibmac
habibmac / Custom.css
Created June 6, 2012 18:07 — forked from bentruyman/Custom.css
IR_Black Theme for Chrome Developer Tools
/**********************************************/
/*
/* IR_Black Skin by Ben Truyman - 2011
/*
/* Based on Todd Werth's IR_Black:
/* http://blog.toddwerth.com/entries/2
/*
/* Inspired by Darcy Clarke's blog post:
/* http://darcyclarke.me/design/skin-your-chrome-inspector/
/*
@habibmac
habibmac / gist:2883255
Created June 6, 2012 16:55
WP: Sharpen resized images (JPG only)
function ajx_sharpen_resized_files( $resized_file ) {
$image = wp_load_image( $resized_file );
if ( !is_resource( $image ) )
return new WP_Error( 'error_loading_image', $image, $file );
$size = @getimagesize( $resized_file );
if ( !$size )
return new WP_Error('invalid_image', __('Could not read image size'), $file);
list($orig_w, $orig_h, $orig_type) = $size;
@habibmac
habibmac / gist:2883235
Created June 6, 2012 16:52
WP: Conditional to check for hierarchy descendant
// A conditional function to check if the current page is a descendant of the ID given to it. Useful for determining if a page is a grandchild, great-grandchild or father down the hierarchy tree.
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
$anc = get_post_ancestors( $post->ID );
foreach($anc as $ancestor) {
if(is_page() && $ancestor == $pid) {
return true;
}
@habibmac
habibmac / gist:2883213
Created June 6, 2012 16:48
WP: Custom admin footer
// customize admin footer text
function custom_admin_footer() {
echo 'add your custom footer text and html here';
}
add_filter('admin_footer_text', 'custom_admin_footer');
@habibmac
habibmac / gist:2883191
Created June 6, 2012 16:47
WP: Disable RSS feeds
function fb_disable_feed() {
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}
add_action('do_feed', 'fb_disable_feed', 1);
add_action('do_feed_rdf', 'fb_disable_feed', 1);
add_action('do_feed_rss', 'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1);
@habibmac
habibmac / gist:2883176
Created June 6, 2012 16:45
WP: Enable GZIP output compression
if(extension_loaded("zlib") && (ini_get("output_handler") != "ob_gzhandler"))
add_action('wp', create_function('', '@ob_end_clean();@ini_set("zlib.output_compression", 1);'));