Skip to content

Instantly share code, notes, and snippets.

View mkokes's full-sized avatar

Marty Kokes mkokes

View GitHub Profile
@mkokes
mkokes / perl-wordpress-xmlrpc.pl
Created October 12, 2015 15:16
Simple perl script for making a post on wordpress via xmlrpc
#!/usr/bin/perl
# Modules
use utf8;
use XMLRPC::Lite;
use Data::Dumper;
$blogid = 1;
$username="username goes here";
$password="password goes here";
@mkokes
mkokes / max-child-php5-fpm.sh
Created October 15, 2015 19:23
Calculate max number of php5-fpm processes
echo "pm.max_children = $(( $(awk '/MemTotal:/ { printf "%d\n", ($2*0.80) }' /proc/meminfo) / $(ps --no-headers -o "rss,cmd" -C php5-fpm | awk '{ sum+=$1 } END { printf ("%d\n", sum/NR) }') ))"
@mkokes
mkokes / 0_reuse_code.js
Created November 6, 2015 16:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mkokes
mkokes / backstretch-slider.css
Created November 27, 2015 21:06
Backstretch Slider
#bg-slider{ height: 450px; }
@mkokes
mkokes / the_parent_slug.php
Created November 30, 2015 02:50
Wordpress function that returns the slug of the parent page if there is one
//* Return the slug of the parent page if there is one
function the_parent_slug() {
global $post;
if($post->post_parent == 0) return '';
$post_data = get_post($post->post_parent);
return $post_data->post_name;
}
@mkokes
mkokes / gravity-forms-referring-url.php
Created November 30, 2015 16:44
Add referring url to a hidden gravity form field
//* Grab the referring page and place it in a gravity form hidden field. In this example the referring url is being placed in a hidden field called 'refurl' alter the filter target accordingly if a different field name is used
add_filter("gform_field_value_refurl", "referral_url");
function referral_url( $form ) {
//Grab URL from HTTP Server Var and put it into a variable
$refurl = $_SERVER['HTTP_REFERER'];
//Return that value to the form
return esc_url_raw($refurl);
}
@mkokes
mkokes / retrieve-field-via-url.php
Created November 30, 2015 19:34
Grab the contents of a field on a particular page via the page's url in wordpress and add it to a gravity form hidden field
//* Return the department for a job posting based on url and place it in a gravity form hidden field
add_filter("gform_field_value_dept", "op_career_dept");
function op_career_dept() {
//Get the referring URL
$posturl = $_SERVER['HTTP_REFERER'];
//Get the ID of the referring page
$postid = url_to_postid( $posturl );
//Get the dept field based on the post ID
$dept = get_field('op_department', $postid);
return $dept;
@mkokes
mkokes / genesis-custom-loop-pagination.php
Created December 12, 2015 21:37 — forked from billerickson/genesis-custom-loop-pagination.php
Genesis custom loop with pagination
<?php
/* Template Name: Test */
/**
* Genesis custom loop
*/
function be_custom_loop() {
global $post;
// arguments, adjust as needed
@mkokes
mkokes / no-rel-youtube.php
Created December 24, 2015 17:49
Remove related videos from youtube oembeds
//* Removes related videos from youtube
function remove_related_videos($embed) {
if (strstr($embed,'http://www.youtube.com/embed/')) {
return str_replace('?fs=1','?fs=1&rel=0',$embed);
} else {
return $embed;
}
}
add_filter('oembed_result', 'remove_related_videos', 1, true);
@mkokes
mkokes / functions.php
Created December 26, 2015 21:33 — forked from rileypaulsen/functions.php
Add Advanced Custom Fields Fields to the WP REST API
function wp_api_encode_acf($data,$post,$context){
$data['meta'] = array_merge($data['meta'],get_fields($post['ID']));
return $data;
}
if( function_exists('get_fields') ){
add_filter('json_prepare_post', 'wp_api_encode_acf', 10, 3);
}