Skip to content

Instantly share code, notes, and snippets.

View rveitch's full-sized avatar

Ryan Veitch rveitch

View GitHub Profile
<?php
/*
Plugin Name: Draft Feed
Plugin URI:
Description: Add a new Feed for drafts: <code>/?feed=drafts</code>
Version: 0.1
Author: Frank Bültge
Author URI: http://bueltge.de/
*/
@rveitch
rveitch / hide-admin-bar-in-wordpress.php
Created August 1, 2015 23:08
Hide admin bar in WordPress
<?php
// Simple way
add_filter( 'show_admin_bar', '__return_false' );
// Standard way
add_filter( 'show_admin_bar', 'show_admin_bar_cb' );
function show_admin_bar_cb() {
return false;
}
// Hide admin bar for all users except admin
add_filter( 'show_admin_bar', 'show_admin_bar_cb' );
@rveitch
rveitch / fcc-remove-trash.php
Created August 3, 2015 17:17
Remove "Trash" option from non-admin users in WordPress
/**
* Remove "Trash" option from non-admin users
* Added: 08/03/15 rveitch
*/
if ( ! is_admin() ) {
add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 );
function remove_row_actions( $actions )
{
if( get_post_type() === 'post' )
unset( $actions['trash'] );
@rveitch
rveitch / wp-github-plugin-repo-link.php
Created August 3, 2015 17:46
Add Github repository link to the WordPress plugin description.
@rveitch
rveitch / wp-autoload.php
Created August 3, 2015 20:50
Autoload included php files
<?php
! defined( 'ABSPATH' ) and exit;
add_filter( 'plugins_loaded', array( 'Autoload_Includes', 'get_object' ) );
// begin class
class Autoload_Includes {
/* Define folder, there have inside the autoload files */
@rveitch
rveitch / wp-load-includes.php
Created August 3, 2015 20:58
Load an included file in WordPress
<?php
/**
* Load an included file
*/
function load_this_file() {
require_once( plugin_dir_path( __FILE__ ) . 'includes/this-file.php' );
}
add_action( 'init', 'load_this_file' );
@rveitch
rveitch / wp-load-admin-css-styles.php
Created August 3, 2015 21:03
Load CSS for admin/plugin dashboard
<?php
/**
* Load CSS for admin/plugin dashboard
*/
function load_admin_css_styles() {
wp_enqueue_style( 'yourstyle-css', plugins_url( 'css/yourstyle.css', __FILE__ ) );
}
add_action( 'admin_enqueue_scripts', 'load_admin_css_styles' )
@rveitch
rveitch / insert_wp_post_category.php
Created August 5, 2015 02:33
Programmatically Insert WordPress Post Categories
<?php
/**
* Insert a new Post Category
*/
function example_insert_category() {
wp_insert_term(
'Example Category',
'category',
array(
'description' => 'This is an example category created with wp_insert_term.',
@rveitch
rveitch / insert-default-av-categories.php
Last active December 22, 2015 19:40
Insert Default AreaVoices Post Categories
<?php
/**
* Insert default AreaVoices post categories
*/
function insert_av_post_categories() {
/* Rename the default 'Uncategorized' category */
//wp_update_term(1, 'category', array( 'name' => 'Arts & Entertainment', 'slug' => 'arts-entertainment' ));
@rveitch
rveitch / json-feed-bison-media.php
Created August 10, 2015 21:15
Bison Media JSON Feed Template
<?php
/**
* JSON Feed Template for displaying JSON Posts feed.
*
*/
$callback = trim(esc_html(get_query_var('callback')));
$charset = get_option('charset');
query_posts( array( 'post_type' => 'live_video' ) );