Skip to content

Instantly share code, notes, and snippets.

View xeiter's full-sized avatar

Anton Zaroutski xeiter

View GitHub Profile
<?php
function example_ajax_enqueue() {
// Enqueue javascript on the frontend.
wp_enqueue_script(
'example-ajax-script',
get_template_directory_uri() . '/js/simple-ajax-example.js',
array('jquery')
);
// The wp_localize_script allows us to output the ajax_url path for our script to use.
@xeiter
xeiter / shell-disk-usage.sh
Last active January 3, 2017 03:40
Check disk usage in Ubuntu
#!/bin/sh
sudo du -hd 1 | sort -h
@xeiter
xeiter / action-via-rest-api.php
Created December 14, 2016 04:04
WP Rest API example
<?php
// Register a new route
add_action( 'rest_api_init', function () {
register_rest_route( 'portal/v1', '/messages/favourite/toggle', array(
'methods' => 'POST',
'callback' => 'change_favorite_status_of_a_message',
) );
} );
@xeiter
xeiter / wordpress-get-current-menu-item.php
Created September 28, 2016 00:13
Work out the current menu item
<?php
// Get menu items
$menu_items = wp_get_nav_menu_items( 'main-menu' );
// Work out the current menu item
$parent_menu_item_id = current( wp_filter_object_list( $menu_items, array( 'object_id' => get_queried_object_id() ) ) )->ID;
@xeiter
xeiter / shell-rsync-wordpress-uploads.sh
Created September 3, 2016 09:00
Rsync .../uploads directories on local and development servers running WordPress
sudo rsync -avz -e "ssh -p 1234" ssh-user@domain:path-to-uploads/* .
@xeiter
xeiter / wordpress-acf-programmatic-conditionals.php
Last active September 3, 2016 04:56
Control the display of ACF groups programmatically in WordPress
<?php
add_filter('acf/load_field/name=name', 'az_acf_meta_box_display');
add_filter('acf/load_field/name=age', 'az_acf_meta_box_display');
add_filter('acf/load_field/name=favorite_colour', 'az_acf_meta_box_display');
/**
* Control the display of ACF groups programmatically in WordPress
*
* @param array $field
@xeiter
xeiter / wordpress-wppolarity-sage-theme.md
Last active September 1, 2016 14:48
Install Sage WordPress theme and 3rd party libraries on OS X

Installing Sage WordPress theme and 3rd party libraries with Pressmatic

  • Updated 31 August 2016

Create a new Pressmatic site

  1. Create new site using "Add Site" button

Installing Sage WordPress theme

@xeiter
xeiter / unit-testing-with-pressmatic.md
Last active March 16, 2017 01:18 — forked from tommcfarlin/unit-testing-with-pressmatic.md
[WordPress] Unit Testing with Pressmatic

Unit Testing with Pressmatic

  • Updated 20 August 2016

Installing Composer on Pressmatic

  1. SSH into the Pressmatic box
  2. $ apt-get update
  3. $ apt-get install curl php5-cli git subversion
  4. $ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
@xeiter
xeiter / utf8-csv.php
Created August 13, 2016 03:39
Fix UTF-8 in CSV output
<?php
// Open file pointer to standard output
$fp = fopen( 'php://output', 'w' );
// Write BOM character sequence to fix UTF-8 in Excel
fputs( $fp, $bom = chr(0xEF) . chr(0xBB) . chr(0xBF) );
// Write the rest of CSV to the file
if ( $fp ) {
@xeiter
xeiter / functions.php
Last active July 3, 2016 21:58
Wordpress - add custom rewrite rule
<?php
// Create the query var so that WP catches your custom /staff/username url
add_filter( 'query_vars', 'bb_rewrite_add_var' );
function bb_rewrite_add_var( $vars )
{
$vars[] = 'staff';
return $vars;
}