Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
barbietunnie / add_shortcode.php
Last active September 13, 2015 17:32 — forked from danielpataki/add_shortcode.php
Google Maps Shortcode
add_shortcode( 'map', 'mgms_map' );
function mgms_map( $args ) {
$id = substr( sha1( "Google Map" . time() ), rand( 2, 10 ), rand( 5, 8 ) );
return "<div class='map' id='map-$id'></div>";
}
@barbietunnie
barbietunnie / acf-notice.php
Last active September 13, 2015 17:32 — forked from danielpataki/acf-notice.php
Admin Notices
if( !function_exists( 'the_field' ) && empty( get_option( 'my-acf-notice-dismissed' ) ) ) {
add_action( 'admin_notices', 'my_acf_admin_notice' );
}
function my_acf_admin_notice() {
?>
<div class="notice error my-acf-notice is-dismissible" >
<p><?php _e( 'ACF is not necessary for this plugin, but it will make your experience better, install it now!', 'my-text-domain' ); ?></p>
</div>
@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' );