Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
barbietunnie / basic.php
Last active September 13, 2015 17:32 — forked from danielpataki/basic.php
Toolbar Modifications
add_action( 'admin_bar_menu', 'my_new_toolbar_item', 999 );
function my_new_toolbar_item( $wp_admin_bar ) {
$args = array(
'id' => 'my_new_item',
'title' => 'Media Settings',
'href' => admin_url() . 'options-media.php',
);
$wp_admin_bar->add_node( $args );
}
@barbietunnie
barbietunnie / add-role-basic.php
Last active September 13, 2015 17:32 — forked from danielpataki/add-role-basic.php
Roles And Caps
add_role( 'company', 'Company', array( 'read' => true, 'level_0' => true, 'view_ad_stats' => true ) );
@barbietunnie
barbietunnie / ajax-action.php
Last active September 13, 2015 17:34 — forked from danielpataki/ajax-action.php
Uploading With WordPress
add_action( 'wp_ajax_nopriv_submit_content', 'my_submission_processor' );
add_action( 'wp_ajax_submit_content', 'my_submission_processor' );
function my_submission_processor() {
// Handle the form in here
}
@barbietunnie
barbietunnie / delete-tax.php
Last active September 13, 2015 17:34 — forked from danielpataki/delete-tax.php
Database cleaning
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy IN ( 'unwanted_tax_1', 'unwanted_tax_2' ) );
DELETE FROM wp_term_relationships WHERE term_taxonomy_id IN (SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE taxonomy IN ( 'unwanted_tax_1', 'unwanted_tax_2' ) );
DELETE FROM wp_term_taxonomy WHERE taxonomy IN ( 'unwanted_tax_1', 'unwanted_tax_2' );
@barbietunnie
barbietunnie / docblock.php
Last active September 13, 2015 17:34 — forked from danielpataki/docblock.php
docblock
/**
* Retrive Channel IDs
*
* This function retreives all categories which are set as channels.
* Channels on the website are special categories that have a mailing
* list attached which users can subscribe to.
*
* It returns an array of term objects if $format is set to 'objects',
* otherwise returns an array of term_ids.
*
@barbietunnie
barbietunnie / auto-add.php
Last active September 13, 2015 17:35 — forked from danielpataki/auto-add.php
OOP plugin
/*
Plugin Name: Auto Add Read Posts
Description: A plugin that adds read posts to the user's read list - requires the Unread Posts plugin
Version: 1.0.0
Author: Daniel Pataki
Author URI: http://danielpataki.com/
License: GPLv2 or later
*/
add_action( 'wp', 'auto_add_post_to_read_list' );
@barbietunnie
barbietunnie / display-skeleton.php
Last active September 13, 2015 17:35 — forked from danielpataki/display-skeleton.php
Creating An Authors Widget
public function widget( $args, $instance ) {
echo $args['before_widget'];
if( !empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title'];
}
// Main Widget Code Here
@barbietunnie
barbietunnie / nonce-url.php
Last active September 13, 2015 17:35 — forked from danielpataki/nonce-url.php
Nonces
$delete_link = wp_get_shortlink( get_the_ID() ) . '&delete=true';
$nonced_link = wp_nonce_url( $delete_link, 'delete-post-' . get_the_ID(), '_mynonce' );
@barbietunnie
barbietunnie / enqueue.php
Last active September 13, 2015 17:35 — forked from danielpataki/enqueue.php
Tabbed Interface
function welcome_screen_assets( $hook ) {
if( 'dashboard_page_welcome-screen-about' == $hook ) {
wp_enqueue_style( 'welcome_screen_css', plugin_dir_url( __FILE__ ) . '/style.css' );
}
}
add_action( 'admin_enqueue_scripts', 'welcome_screen_assets' );
@barbietunnie
barbietunnie / new-role.php
Last active September 13, 2015 17:35 — forked from danielpataki/new-role.php
Hide Pages
register_activation_hook( __FILE__, 'my_initial_setup' );
function my_initial_setup() {
$admin = get_role( 'administrator' );
$overlord_caps = $admin->capabilities;
$overlord_caps[] = 'be_overlord';
$role = add_role( 'overlord', 'Overlord', $overlord_caps );
}