Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Customize WordPress Toolbar
*
* @param obj $wp_admin_bar An instance of the global object WP_Admin_Bar
*/
function myplugin_customize_toolbar( $wp_admin_bar ){
$user = wp_get_current_user();
if ( ! ( $user instanceof WP_User ) ){
@carlodaniele
carlodaniele / remove-toolbar.php
Last active February 27, 2016 06:23
Remove WordPress Toolbar for non-admin users
<?php
/**
* Remove WordPress Toolbar for subscribers
*/
function myplugin_remove_admin_bar() {
if ( ! current_user_can( 'publish_posts' ) ) {
show_admin_bar( false );
}
}
add_action( 'plugins_loaded', 'myplugin_remove_admin_bar' );
@carlodaniele
carlodaniele / login-redirect.php
Created February 27, 2016 16:37
Redirect user after successful login
<?php
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function frontend_login_redirect( $redirect_to, $request, $user ) {
@carlodaniele
carlodaniele / login-extra-field.php
Created February 28, 2016 07:53
Add an additional field to the login form
<?php
/**
* Print an extra field into the login form
*
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/login_form
*/
function my_login_extra_field() {
?>
<p>
<label for="rd"><?php _e( 'Take me to' ); ?></label>
@carlodaniele
carlodaniele / login-redirect-2.php
Created February 28, 2016 07:54
Redirect user to selected resource on successful login
<?php
/**
* Redirect user on login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect
@carlodaniele
carlodaniele / login-header.html
Created February 28, 2016 19:20
wp-login.php header
<h1>
<a href="https://wordpress.org/" title="Powered by WordPress" tabindex="-1">Example WordPress website</a>
</h1>
@carlodaniele
carlodaniele / public_query_vars.php
Last active March 12, 2016 08:56
An array of WordPress public query vars
<?php
$keys = array(
'error',
'm',
'p',
'post_parent',
'subpost',
'subpost_id',
'attachment',
'attachment_id',
@carlodaniele
carlodaniele / notify.php
Last active March 16, 2016 11:56
A plugin to notify users on post publication
<?php
/**
* @package notify
* @version 1.0
*/
/*
Plugin Name: Notify Me
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin fo ioProgrammo readers
Author: Carlo Daniele
array(
array(
'key' => 'field_name',
'value' => 'field_value',
'type' => 'field_type',
'compare' => 'logic_operator'
)
)
@carlodaniele
carlodaniele / register-book-author-query-var.php
Created March 16, 2016 20:27
Register the 'book-author' custom query variable
<?php
/**
* Register custom query vars
*
* @param array $vars The array of available query variables
*
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
*/
function myplugin_register_query_vars( $vars ) {
$vars[] = 'book-author';