Skip to content

Instantly share code, notes, and snippets.

View jamestrevorlees's full-sized avatar

James Lees jamestrevorlees

  • Advantage Learn + Pango
  • Durban, South Africa
View GitHub Profile
@jamestrevorlees
jamestrevorlees / order_has_trial.php
Created May 8, 2019 02:41 — forked from chrisvanpatten/order_has_trial.php
Function to check if a WooCommerce order contains a free trial (via the Subscriptions extension)
<?php
/**
* Loop through an order's items and see if there's a free trial set
*
* @param WC_Order $order
* @return bool|WP_Error
*/
function custom_order_has_trial( $order ) {
if ( ! $order instanceof WC_Order )
@jamestrevorlees
jamestrevorlees / .gitignore
Created July 18, 2018 12:29
.gitignore (WordPress local environment)
# ignore everything in the root except the "wp-content" directory.*
/*
!wp-content/
# ignore everything in the "wp-content" directory, except:
wp-content/*
!wp-content/plugins/
!wp-content/themes/
!wp-content/mu-plugins/
# ignore all files starting with . or ~
.*
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@jamestrevorlees
jamestrevorlees / gist:ab17a1a172d0e488097ab8a81820bcf2
Created April 4, 2018 12:23 — forked from minio/gist:6982551
query to get all posts and associated categories from Wordpress database
$all_posts = $wpdb->get_results("
SELECT wp_posts.ID,wp_posts.post_date,wp_posts.post_title,wp_posts.post_name,
wp_terms.name,wp_terms.slug,wp_term_taxonomy.description
from wp_posts
join wp_term_relationships on wp_posts.ID = wp_term_relationships.object_id
join wp_terms on wp_term_relationships.term_taxonomy_id = wp_terms.term_id
join wp_term_taxonomy on wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
WHERE wp_posts.post_status = 'publish'
ORDER BY wp_terms.slug,wp_posts.ID;
", ARRAY_A);
@jamestrevorlees
jamestrevorlees / Wordpress Bootstrap 3 nav.php
Created November 10, 2017 15:01 — forked from jfitzsimmons2/Wordpress Bootstrap 3 nav.php
How to structure your WP <nav> tag using wp_nav_menu to use Bootstrap 3's navbar. Note this is specifically for the "fixed top" version of the navbar (http://getbootstrap.com/components/#navbar-fixed-top). Also only works for single-level navs. If there are sub-menus, additional tweaking is needed.
<nav id="site-navigation" class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><?php bloginfo( 'name' ); ?></a>
@jamestrevorlees
jamestrevorlees / country-shortcode.php
Created November 10, 2017 14:09 — forked from MatthewEppelsheimer/country-shortcode.php
WP Contact Form 7 shortcode with list of Countries
<?php
/*
UPDATED: December 31, 2011.
Modifications:
- Truncated the longest country names, including:
-- British Indian Ocean Territories (Chagos Archipelago) -> British Indian Ocean Territories
-- South Georgia and the South Sandhich Islands -> South Georgia & S. Sandwich Islands
@jamestrevorlees
jamestrevorlees / timber_repeaterloop_bullets.txt
Last active March 17, 2017 13:31
Loop through repeater field on timber and twig
<div class="col">
<ul>
{% set i = 1 %}
{% for item in post.get_field('home_what_band_bullets_section_a') %}
<li>{{ item.bullet_copy_text }}</li>
{% set i = i + 1 %}
{% endfor %}
</ul>
@jamestrevorlees
jamestrevorlees / update-links-mysql-db-wordpress
Created October 11, 2016 09:20
SQL Query to update links from a migrated WordPress Database
@jamestrevorlees
jamestrevorlees / how-to-git-recache.txt
Last active October 9, 2016 09:07
Adding or removing files onto your .gitignore when you are already tracking
Often we have to add or remove files from a gitignore. In order to do so I choose to recache git and this is how I do it:
1. make your .gitignore changes
2. Recache git
cmd: git rm -r --cached .
--> this tells git to remove the cache for all your files that are currently being tracked
3. Add all the files to git again
@jamestrevorlees
jamestrevorlees / HTML, CSS and JS
Created September 17, 2016 09:28
How to create a youtube video iframe in a lightbox with the youtube API
#1.First create the button / CTA for the youtube video. eg.
<div>
<a href="https://www.youtube.com/embed/gUNSGk3SHhI" class="lightbox"><i class="fa fa-play fa-8 home-play-btn" aria-hidden="true" style="font-size: 4em"></i></a>
</div>
#ensure that the class "lightbox" is added.
#2.Add the following html at the base of the doc
<div id="youtubelightbox" class="parent">
<div class="centeredchild">
<div class="videowrapper">