Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am caratage on github.
  • I am caratage (https://keybase.io/caratage) on keybase.
  • I have a public key ASCFS7elX_L7uAoF9l42kY56fQSakUaueh0-QYRY9w8Lpwo

To claim this, I am signing this object:

@caratage
caratage / example.java
Last active May 7, 2018 08:41
Implementation of Java equals function
public class Example {
private int value;
//getters and setters, constructor
@Override
public boolean equals(Object o) {
// same address
if (o == this) return true;
// other type
if (!(o instanceof Example)) {
return false;
@caratage
caratage / osx-show-hidden-files.sh
Last active April 27, 2018 06:17
OSX - show hidden files
#!/bin/bash
# defaults write com.apple.finder AppleShowAllFiles NO
defaults write com.apple.finder AppleShowAllFiles YES
killall Finder /System/Library/CoreServices/Finder.app
#!/bin/sh
mkdir ${TMPDIR}/com.apple.IconServices
@caratage
caratage / index.php
Created April 21, 2013 10:36
Custom Taxonomy - Conditional Tag
if (is_object_in_term( $post->ID, 'taxonomy-slug' )) {
// do something
}
@caratage
caratage / functions.php
Created April 21, 2013 10:33
Protected Posts - Custom Form, Message, Title
/**********************************************
* Custom Password Form
**********************************************/
add_filter( 'the_password_form', 'custom_password_form' );
function custom_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form class="protected-post-form form-inline" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
@caratage
caratage / functions.php
Created December 9, 2012 07:08
Sort admin columns by meta key query
/**********************************************
* Sort columns for TOUR DATE post type
**********************************************/
function set_date_post_types_admin_order($wp_query) {
if (is_admin()) {
// Get the post type from the query
$post_type = $wp_query->query['post_type'];
@caratage
caratage / Asset.php
Created December 4, 2012 10:16 — forked from SubZane/Asset.php
WordPress: get_attachment_id_from_src
function get_attachment_id_from_src ($src) {
global $wpdb;
$reg = "/-[0-9]+x[0-9]+?.(jpg|jpeg|png|gif)$/i";
$src1 = preg_replace($reg,'',$src);
if($src1 != $src){
$ext = pathinfo($src, PATHINFO_EXTENSION);
$src = $src1 . '.' .$ext;
}
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$src'";
$id = $wpdb->get_var($query);
@caratage
caratage / query.php
Created November 28, 2012 13:08
Variants of query_posts
// http://www.binarymoon.co.uk/2010/03/5-wordpress-queryposts-tips/
<?php
$query = 'posts_per_page=10';
$queryObject = new WP_Query($query);
// The Loop...
if ($queryObject->have_posts()) {
while ($queryObject->have_posts()) {
$queryObject->the_post();
the_title();
@caratage
caratage / functions.php
Created November 28, 2012 13:04
Removing Admin Menu items
function remove_menu_pages() {
remove_menu_page('link-manager.php');
remove_menu_page('edit-comments.php');
}
add_action( 'admin_init', 'remove_menu_pages' );
// http://www.netmagazine.com/tutorials/customise-wordpress-admin-area