Skip to content

Instantly share code, notes, and snippets.

View mrbobbybryant's full-sized avatar

Bobby Bryant mrbobbybryant

View GitHub Profile
@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:f5df7d6e006db3ebe6de
Created February 2, 2015 21:44
Metabox Callback Function for How to build Plugin series
<?php
/**
* This is the entire callback function for the metabox. You can copy the whole thing or just the fields.
*/
function dwwp_meta_callback() {
?>
<div>
@mrbobbybryant
mrbobbybryant / gist:2a291eece8f65e54f1d1
Created February 3, 2015 03:43
WordPress Custom Fields Saving function
<?php function dwwp_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'dwwp_jobs_nonce' ] ) && wp_verify_nonce( $_POST[ 'dwwp_jobs_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
@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:6e6130f422015a794de7
Created February 17, 2015 20:04
Create a Submenu page in WordPress
<?php
function dwwp_add_submenu_page() {
add_submenu_page(
'edit.php?post_type=job',
'Reorder Jobs',
'Reorder Jobs',
'manage_options',
'reorder_jobs',
@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>';