Skip to content

Instantly share code, notes, and snippets.

@kjbrum
kjbrum / Terminal Commands
Last active December 20, 2015 14:39
Useful commands for Terminal.
// Move all .jpgs files to a jpg folder
mkdir jpg && mv *.jpg jpg
mkdir jpg && find . -type f -name "*.jpg" -exec mv {} jpg \;
// Show hidden files in finder
defaults write com.apple.finder AppleShowAllFiles -boolean true && killall Finder
// Hide hidden files in finder
defaults delete com.apple.finder AppleShowAllFiles && killall Finder
@kjbrum
kjbrum / wp_is_child.php
Last active May 21, 2016 02:22
Check if we are on a child or grandchild page of the page.
<?php
/**
* Check if we are on a child or grandchild page of the page.
*
* @param integer $id The ID of the page we're looking for pages underneath
* @param boolean $parent Whether to check if we are on the parent page as well
* @return boolean
*/
function wp_is_child( $id=0, $parent=false ) {
global $post;
@kjbrum
kjbrum / wp_localhost_access.php
Last active May 21, 2016 02:21
Access projects being served on your localhost to other devices on the same network, keeping CSS, JS and images intact (add to wp-config.php file before settings). View at: your-ip-address/project-folder
<?php
/** Access localhost on same network **/
$IP = $_SERVER['HTTP_HOST'];
$projectDir = 'projectfolder';
$localIPs = array( '127.0.0.1','::1' );
if( !in_array( $_SERVER['REMOTE_ADDR'], $localIPs ) ) {
define( 'WP_SITEURL', "http://$IP/$projectDir" );
define( 'WP_HOME', "http://$IP/$projectDir" );
}
@kjbrum
kjbrum / db-backup.php
Created June 2, 2014 13:52
Quick database backup
<?php
backup_tables('localhost',DB_USER,DB_PASSWORD,DB_NAME);
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
@kjbrum
kjbrum / wp_gravity_forms_unrequire.php
Last active May 21, 2016 02:21
Un-require all required fields so you don't have to fill them out.Place this snippet into your functions.php file and then add the gfunrequire=1 parameter to the url of the page your form is on.
<?php
/**
* Gravity Forms Unrequire.
* Unrequire all required fields so you don't have to fill them out during testing.
*/
class GravityFormsUnrequire {
var $args = null;
public function __construct( $args = array() ) {
extract( wp_parse_args( $args, array(
'admins_only' => true,
@kjbrum
kjbrum / wp_single_year_monthly_archives.php
Last active February 4, 2017 02:00
Display the monthly archive links for a specific year.
<?php
/**
* Display the archive links for a single year.
*
* @param integer $year The year you would like to display the archives for
* @param string $menu_class Class to add to the ul tag
* @return void
*/
function wp_single_year_monthly_archives($year=null, $menu_class=null) {
if($year == null) {
@kjbrum
kjbrum / wp_disable_search.php
Last active May 21, 2016 02:20
Disable searching if it isn't needed.
<?php
// Disable Searching
add_action( 'parse_query', function($query){if(is_search())$query->is_404=true;} );
add_filter( 'get_search_form', 'return null' );
@kjbrum
kjbrum / wp_force_parent_template.php
Last active May 21, 2016 02:20
Force sub pages to have the same template as parent
<?php
/**
* Force child pages to have the same template as their parent
*
* @param boolean $include_grandchildren Whether to include grandchildren
* @return void
*/
function wp_force_parent_template( $include_grandchildren=false ) {
global $post;
if( is_page() ) {
@kjbrum
kjbrum / wp_get_custom_post_nav.php
Last active May 21, 2016 02:20
Create navigation links for a specific set of posts (post_type, meta_key, etc...).
<?php
/**
* Create navigation links for a specific set of posts (post_type, meta_key, etc...)
*
* @param string $post_type Optional post_type
* @param string $meta_key Optional meta_key
* @return array $nav_links The array of navigation links
*/
function wp_get_custom_post_nav( $post_type='post', $meta_key='' ) {
global $post;
@kjbrum
kjbrum / wp_gform_error_style.scss
Last active May 21, 2016 02:20
Better looking gravity form errors.
$error: #ff4856;
.gfield_required {
color: $error;
}
.validation_error {
text-align: center;
margin: 1rem 0 !important;
font-size: 0.9rem !important;