Skip to content

Instantly share code, notes, and snippets.

View cameronjonesweb's full-sized avatar
👨‍👦

Cameron Jones cameronjonesweb

👨‍👦
View GitHub Profile
@cameronjonesweb
cameronjonesweb / .htaccess
Created June 26, 2017 07:13
Noindex PDF files
<FilesMatch ".pdf$">
Header set X-Robots-Tag "noindex"
</FilesMatch>
@cameronjonesweb
cameronjonesweb / cameronjonesweb-image-generator.php
Last active July 3, 2017 06:03
[WordPress] A helper class to generate a HTML image string from a supplied image class, array or ID. Useful for dealing with images stored in custom fields.
<?php
// Helper class to generate responsive image HTML from an id or array
class cameronjonesweb_generate_image {
public $output;
function __construct( $image, $size = 'full' ) {
if( is_array( $image ) ) {
// It's an array
@cameronjonesweb
cameronjonesweb / cameronjonesweb-button-generator.php
Last active July 12, 2017 04:11
PHP button generator for WordPress
<?php
/**
* Generates a button
* @param string $label The label of the button
* @param string $link The URL to link to
* @param array $classes Additional classes to add to the button element
* @param bool $new_window Whether to open in a new window or now
* @return string The HTML button element
*/
@cameronjonesweb
cameronjonesweb / google-map.js
Last active July 17, 2017 05:11
ACF Google Maps Script
(function($) {
function new_map( $el ) {
// var
var $markers = $el.find('.marker');
// vars
var args = {
@cameronjonesweb
cameronjonesweb / cameronjonesweb-facebook-page-slug.php
Last active December 14, 2017 04:42
Get slug from Facebook page
<?php
function cameronjonesweb_facebook_page_slug( $url ) {
$slug = str_replace(
array(
'https://facebook.com/', 'https://www.facebook.com/', 'http://facebook.com/', 'http://www.facebook.com/'
),
'',
rtrim(
<?php
function cameronjonesweb_bp_mark_notifications_read() {
// Get the action.
$action = !empty( $_GET['action'] ) ? $_GET['action'] : '';
$nonce = !empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : '';
$id = !empty( $_GET['notification_id'] ) ? $_GET['notification_id'] : '';
// Bail if no action or no ID.
@cameronjonesweb
cameronjonesweb / prevent-roboto.js
Last active July 11, 2018 14:03
Prevent Google Maps from loading the Roboto font.
var head = document.getElementsByTagName( 'head' )[0];
// Save the original method
var insertBefore = head.insertBefore;
// Replace it!
head.insertBefore = function( newElement, referenceElement ) {
if ( newElement.href && newElement.href.indexOf( 'https://fonts.googleapis.com/css?family=Roboto' ) === 0 ) {
return;
@cameronjonesweb
cameronjonesweb / 404-tag-archives.php
Last active July 17, 2018 12:41
Remove taxonomies
<?php
add_action( 'pre_get_posts', 'cameronjonesweb_404_tag_archives' );
function cameronjonesweb_404_tag_archives( $query ) {
if( $query->is_main_query() && $query->is_tag() ) {
$query->set_404();
status_header( 404 );
}
}
@cameronjonesweb
cameronjonesweb / salesforce-gravity-forms.php
Last active July 17, 2018 13:02
Updates the Salesforce API endpoint for the Gravity Forms Salesforce Add-On
<?php
/**
* Updates the Salesforce API endpoint for the Gravity Forms Salesforce Add-On
* From the article Fixing The Gravity Forms Salesforce Add-On For WordPress: https://cameronjonesweb.com.au/blog/fixing-the-gravity-forms-salesforce-add-on-for-wordpress/
*
* @link https://help.salesforce.com/articleView?id=Updating-the-Web-to-Case-and-Web-to-Lead-Endpoint-URL&language=en_US&type=1
* @param string $sub The current subdomain (www or test).
* @param bool $test Whether it's in test mode or not.
* @return string The new subdomain
*/
@cameronjonesweb
cameronjonesweb / add-post-thumbnail-to-rss.php
Last active July 22, 2018 13:57
Adds the post thumbnail to the WordPress RSS feed
<?php
add_action( 'rss2_item', 'cameronjonesweb_add_post_thumbnail_to_rss' );
function cameronjonesweb_add_post_thumbnail_to_rss() {
if ( has_post_thumbnail() ) {
printf(
"\t" . '<media:content url="%1$s" type="%2$s" />' . "\n",
esc_url( get_the_post_thumbnail_url() ),
esc_attr( get_post_mime_type( get_post_thumbnail_id() ) )