Skip to content

Instantly share code, notes, and snippets.

View AaronRutley's full-sized avatar

Aaron Rutley AaronRutley

  • Melbourne, Australia
View GitHub Profile
@tdmalone
tdmalone / hottest100.php
Last active January 26, 2017 23:53
Cron this every minute or two on a server with PHP installed, to post every new hottest 100 track to a Slack channel
<?php
// ********************* START CONFIGURATION *********************
// Set up an incoming webhook at https://YOURDOMAIN.slack.com/apps/manage/custom-integrations
define( 'SLACK_INCOMING_WEBHOOK', 'https://hooks.slack.com/services/TXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX' );
// Set your data folder, which is used to prevent multiple notifications for the same song :)
define( 'DATA_FOLDER', './hottest100-data' );
@chriswinch
chriswinch / functions.php
Last active October 7, 2016 06:57
ACF - Combine the_field & the_sub_field into one function for better modularity.
<?php
function the_acf_field($acf) {
$field = get_field($acf);
if(!$field) {
$field = get_sub_field($acf);
}
echo $field;
@scottopolis
scottopolis / wp-api-user-meta.php
Last active April 18, 2020 19:13
Add user meta to the WP-API
<?php
/* Adds all user meta to the /wp-json/wp/v2/user/[id] endpoint */
function sb_user_meta( $data, $field_name, $request ) {
if( $data['id'] ){
$user_meta = get_user_meta( $data['id'] );
}
if ( !$user_meta ) {
return new WP_Error( 'No user meta found', 'No user meta found', array( 'status' => 404 ) );
}
<?php
/**
* Make an internal REST request
*
* @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server).
* @param $request_or_method WP_REST_Request|string A WP_REST_Request object or a request method
* @param $path (optional) if the path is not specific in the rest request, specify it here
* @param $data (optional) option data for the request.
* @return WP_Error|mixed
@joehoyle
joehoyle / private-wp-api.php
Created October 14, 2015 18:37
Only allow access to the API for authenticated requests
<?php
add_filter( 'rest_pre_dispatch', function() {
if ( ! is_user_logged_in() ) {
return new WP_Error( 'not-logged-in', 'API Requests are only supported for authenticated requests', array( 'status' => 401 ) );
}
} );
@scottopolis
scottopolis / wp-api-cpt.php
Last active June 23, 2017 19:23
Add multiple custom post types to the WP-API
<?php
// This is a temporary solution until register_post_type_args is available
// After adding your CPT, you can find it at mysite.com/wp-json/wp/v2/[slug]
function sb_add_cpts_to_api() {
global $wp_post_types;
// Add CPT slugs here
$arr = ['fake','movie','books'];
@simoncoulton
simoncoulton / material-theme.itermcolors
Created July 13, 2015 06:05
Material-Theme iTerm2 Colors
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.19607843137254902</real>
<key>Green Component</key>
<real>0.16078431372549021</real>
@dypsilon
dypsilon / frontendDevlopmentBookmarks.md
Last active May 7, 2024 01:27
A badass list of frontend development resources I collected over time.
// Custom Dashboard widgets
function custom_dashboard_widgets() {
global $wp_meta_boxes;
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] );
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links'] );
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'] );
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] );
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now'] );
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments'] );
@rutger1140
rutger1140 / gist:5576437
Created May 14, 2013 14:38
Clean up WordPress wp_nav_menu
<?php
//Deletes all CSS classes and id's, except for those listed in the array below
function custom_wp_nav_menu($var) {
return is_array($var) ? array_intersect($var, array(
//List of allowed menu classes
'current_page_item',
'current_page_parent',
'current_page_ancestor',
'first',
'last',