Skip to content

Instantly share code, notes, and snippets.

View fastmover's full-sized avatar

Steven Kohlmeyer fastmover

View GitHub Profile
// SUBMENU AUTOMATION OF INTERIOR MENUS
// It takes the main navigation and if there are any submenu items corresponding with the page, it will generate the navigation
function my_custom_submenu($menu, $returnParent = false) {
global $post;
$menu_items = wp_get_nav_menu_items($menu);
$menu_childs = array();
$menu_IDs = array();
$parent_item = 0;
@fastmover
fastmover / OptionsFW.php
Last active August 29, 2015 13:57
This is an object to make life easier when dealing with the Wordpress plugin Options Framework. Options Framework makes it much easier to create theme options. This is my efforts to help make it more efficient and this is still very incomplete. So far functionality covered is Color Picker, Font Styles Control, File, Tab and Small Select Box.
<?php
/**
* Created by PhpStorm.
* User: skohlmeyer
* Date: 3/27/14
* Time: 2:27 PM
*/
/*
Usage:
/*
Replace wp_options and wp_posts with the table names in your database
You may have used a different prefix for the table names besides wp_
Obviously plugins may store their own urls, you're own your own to incorporate these statements into something usable for that.
*/
@fastmover
fastmover / clean_absolute_urls_in_wp_posts_table.php
Last active January 2, 2016 18:29
clean_absolute_urls() function searched the wp_posts table for references to the current hostname, and removes them making all urls relative instead of absolute. This is especially useful if migrating servers or urls.
function find_and_replace($needle, &$haystack) {
if(strpos($haystack, $needle) !== false) {
$haystack = preg_replace('|' . preg_quote($needle) . '|', '', $haystack);
}
}
/**
* This function makes relative urls from all absolute urls of the current domain.
*
*
@fastmover
fastmover / php.ini
Last active January 2, 2016 03:08
Xdebug Settings
[xdebug]
xdebug.remote_enable=1
xdebug.remote_connect_back = 1
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_handler=dbgp
xdebug.remote_host = 127.0.0.1
@fastmover
fastmover / gist:8187957
Last active January 16, 2024 14:10
Speed up wordpress image file 404's - This will stop Wordpress from rendering the template and stop further process of the rest of the request as a normal page request. This will just output the error message and exit. This will speed up wordpress if there are many missing images, or many request on the server for missing images. Put this in you…
<?php
add_action('template_redirect', function() {
if( is_404() ) {
$uri = $_SERVER["REQUEST_URI"];
if( preg_match('%.jpg|.png|.jpeg|.gif%', $uri, $matches) ) {
header('HTTP/1.0 404 Not Found');
echo "<h1>404 - Image Not Found</h1>";
echo "The page that you have requested could not be found.";
exit();
@fastmover
fastmover / setupsoftware.sh
Last active October 24, 2022 13:07
Auto install software for new Mac Setup.
#!/bin/bash
mkdir ~/getmacapps_temp
cd ~/getmacapps_temp
# Installing Chrome
curl -L -O "https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg"
hdiutil mount googlechrome.dmg
cp -R "/Volumes/Google Chrome/Google Chrome.app" /Applications
hdiutil unmount "/Volumes/Google Chrome"
@fastmover
fastmover / setup.sh
Last active December 31, 2015 21:09
Setup Dev Environment on Mac
#!/bin/bash
mkdir ~/ezSetupTemp
cd ~/ezSetupTemp
# Install RVM & Ruby
sudo curl -L https://get.rvm.io | sudo bash -s stable --ruby
# Install Homebrew
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@fastmover
fastmover / gist:7771483
Created December 3, 2013 15:47
Wordpress is lacking an is_subscriber method.
function is_subscriber() {
// Test if role is subscriber
$cu = wp_get_current_user();
if (!empty($cu->roles) && is_array($cu->roles)) {
if(in_array('subscriber', $cu->roles)) {
return true;
}
}
return false;
}
@fastmover
fastmover / gist:6555485
Created September 13, 2013 20:12
Disable navigation when dropping files (images) into browser.
document.body.addEventListener('dragover', function(e) {
e.preventDefault()
return false;
});
document.body.addEventListener('drop', function(e) {
e.preventDefault()
return false;
});