Skip to content

Instantly share code, notes, and snippets.

View rsharrer's full-sized avatar

Ryan Sharrer rsharrer

View GitHub Profile
@rsharrer
rsharrer / 0_reuse_code.js
Created September 25, 2013 20:28
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rsharrer
rsharrer / new_gist_file.php
Created September 25, 2013 20:31
WP-Functions /Add custom field automatically when post or page is publish
add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post'. 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
global $wpdb;
if(!wp_is_post_revision($post_ID)) {
add_post_meta($post_ID, 'FIELD_NAME', 'CUSTOM VALUE', true);
}
}
@rsharrer
rsharrer / Force specific pages to be secure, ssl, https.php
Created September 25, 2013 20:33
WP-Functions /Force specific pages to be secure, ssl, https
function wps_force_ssl( $force_ssl, $post_id = 0, $url = '' ) {
if ( $post_id == 25 ) {
return true
}
return $force_ssl;
}
add_filter('force_ssl' , 'wps_force_ssl', 10, 3);
@rsharrer
rsharrer / Remove unset URL field from comment form.php
Created September 25, 2013 20:35
WP-Functions /Remove unset URL field from comment form
add_filter('comment_form_default_fields', 'unset_url_field');
function unset_url_field($fields){
if(isset($fields['url']))
unset($fields['url']);
return $fields;
}
@rsharrer
rsharrer / Redirect admin pages to any location.php
Created September 25, 2013 20:37
WP-Functions /Redirect admin pages to any location Redirecting the admin pages was something I needed to do for a recent project. The following snippet will let you redirect any of the admin pages to any location you wish based on the user ‘capability’. Another option would be to replace wp_redirect with wp_die(“some custom message”); to display…
function wps_admin_pages_redirect() {
global $pagenow;
$admin_pages = array(
'edit-tags.php?taxonomy=category',
'edit-tags.php?taxonomy=post_tag',
'link-manager.php',
'options-writing.php',
'options-reading.php',
'options-discussion.php',
'options-media.php',
@rsharrer
rsharrer / Custom Customer Plugin Starter.php
Created September 26, 2013 13:35
Custom Customer Plugin Starter
<?php
/**
*
* Plugin Name: Custom Client Plugin
* Plugin URI: http://webdesign.com/
* Description: Add custom tweaks to a client's site
* Version: 1.0.0
* Author: Benjamin Bradley
* Author URI: http://www.benjaminbradley.com/
*
@rsharrer
rsharrer / Add Categories and Tags to the Pages.php
Created September 26, 2013 13:36
WP-Functions /Add Categories and Tags to the Pages
function add_cat_tag_page() {
add_meta_box('tagsdiv-post_tag', __('Page Tags'), 'post_tags_meta_box', 'page', 'side', 'low');
register_taxonomy_for_object_type('post_tag','page');
add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box','page','side','core');
register_taxonomy_for_object_type('category','page');
}
add_action('admin_init','add_cat_tag_page');
function page_tag_cat_request($q) {
if (isset($q['tag']) || isset($q['category']))
@rsharrer
rsharrer / Get rid of widgets that have to do with blogging.php
Created September 26, 2013 13:37
Get rid of widgets that have to do with blogging.
function unregister_default_wp_widgets() {
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Tag_Cloud');
}
add_action('widgets_init', 'unregister_default_wp_widgets', 1);
@rsharrer
rsharrer / Remove certain meta-boxes from the Pages edit screen.php
Created September 26, 2013 13:38
Remove certain meta-boxes from the Pages edit screen
function remove_default_page_screen_metaboxes() {
remove_meta_box( 'commentstatusdiv','page','normal' ); // Comments
remove_meta_box( 'trackbacksdiv','page','normal' ); // Talkback
}
add_action('admin_menu','remove_default_page_screen_metaboxes');
@rsharrer
rsharrer / Remove admin menu items.php
Created September 26, 2013 13:39
Remove admin menu items
//start remove admin menus
function remove_menus() {
global $menu;
$restricted = array(
__('Posts'),
__('Dashboard'),
__('Comments'),
__('Appearance'),
__('Plugins'),
__('Tools'),