Skip to content

Instantly share code, notes, and snippets.

View mrbobbybryant's full-sized avatar

Bobby Bryant mrbobbybryant

View GitHub Profile
var acs_action = 'myprefix_autocompletesearch';
$("#autosearch").autocomplete({
source: function(req, response){
$.getJSON(AUTOSEARCH.ajaxurl+'?callback=?&action='+acs_action, req, response);
},
select: function(event, response) {
$('#added-posts').append( '<li id="' + response.item.id + '">' + response.item.label + '<i class="fa fa-pencil"></i><i class="fa fa-times"></i></li>' );
$("#autosearch_posts").attr( "value", response.item.id );
$(this).val(''); return false;
},
<?php
function autosearch_metabox_callback() {
$output = '<div id="added-posts"><ul><input type="hidden" value=" " id="autosearch_posts" name="autosearch_posts" /></ul></div>';
$output .= '<label for="autosearch" id="autosearch-label" >';
$output .= '<input type="text" id="autosearch" name="autosearch" size="80" />';
echo $output;
}
add_action( 'add_meta_boxes', 'wp_autosearch_add_metabox' );
@mrbobbybryant
mrbobbybryant / gist:742dd80725c95da96b57
Last active August 29, 2015 14:14
Change the default WordPress title placeholder text
<?php
//If you only need to change one use this version.
function dwwp_change_title( $title_placeholder) {
$screen = get_current_screen();
if ( $screen->post_type == 'job' ) { //<--Your post type name goes here.
$title_placeholder = 'I changed the title yo';
@mrbobbybryant
mrbobbybryant / gist:46f90933e6c46dc4c287
Created January 27, 2015 21:07
Fake WordPress metabox after title and above editor
<?php
function dwwp_after_title_sudo_metabox() {
$screen = get_current_screen();
$edit_post_type = $screen->post_type;
if ( 'job' != $edit_post_type ) {
return;
}
?>
<div class="after-title-help postbox">
@mrbobbybryant
mrbobbybryant / gist:34327461d89a26efebf0
Created January 28, 2015 13:23
Adding items to the help tab.
<?php
function my_contextual_help( $contextual_help, $screen_id, $screen ) {
if ( 'job' == $screen->id ) {
$contextual_help = '<h2>Products</h2>
<p>Products show the details of the items that we sell on the website. You can see a list of them on this page in reverse chronological order - the latest one we added is first.</p>
<p>You can view/edit the details of each product by clicking on its name, or you can perform bulk actions using the dropdown menu and selecting multiple items.</p>';
} elseif ( 'edit-product' == $screen->id ) {
@mrbobbybryant
mrbobbybryant / gist:3ca96d187c3184728f55
Last active August 29, 2015 14:15
Move Featured Image Metabox
<?php
function gmwm_move_featured_image() {
remove_meta_box( 'postimagediv', 'metabox', 'side' );
add_meta_box('featured_image', 'Add Featured Image', 'post_thumbnail_meta_box', 'metabox', 'normal', 'high');
}
add_action( 'do_meta_boxes', 'gmwm_move_featured_image' );
@mrbobbybryant
mrbobbybryant / gist:ab038826d9c2470dd226
Created February 17, 2015 19:57
Conditionally Loading Scripts in WordPress
<?php
function dwwp_admin_enqueue_scripts() {
//These varibales allow us to target the post type and the post edit screen.
global $pagenow, $typenow;
if ( ($pagenow == 'post.php' || $pagenow == 'post-new.php') && $typenow == 'job' ) {
//Plugin Main CSS File.
wp_enqueue_style( 'dwwp-admin-css', plugins_url( 'css/admin-jobs.css', __FILE__ ) );
//Plugin Main js File.
@mrbobbybryant
mrbobbybryant / gist:f0665474dea5d29cead8
Last active August 29, 2015 14:18
Create user profile upload field
<?php
function bootstrap_bob_user_image($user) {
?>
<h3>User Profile Picture</h3>
<table>
<tr>
<th><label for="upload_image">Enter a URL or upload an image.</label></th>
<td><input id="upload_image" type="text" size="36" name="ad_image" value="<?php if ( !empty( get_the_author_meta( 'upload_image', $user->ID ) ) ) echo esc_attr(get_the_author_meta( 'upload_image', $user->ID )); ?>" /></td>
jQuery(document).ready(function($){
var custom_uploader;
$('#upload_image_button').click(function(e) {
e.preventDefault();
@mrbobbybryant
mrbobbybryant / gist:238578ac4d4fb500bf63
Created April 19, 2015 20:18
Querying all taxonomies for all post types
<?php
function agency_wp_test() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
$taxonomy_names = get_object_taxonomies( $post_type );
$terms = get_terms( $taxonomy_names, array( 'hide_empty' => false ));
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<h5>'.$post_type.'</h5>';