Skip to content

Instantly share code, notes, and snippets.

@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-logo.php
Created February 28, 2016 08:47
Login page logo customization
<?php
/**
* Replace default login logo with custom image
*
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/login_head
*/
function my_login_logo() {
echo '<style type="text/css">.login h1 a { background-image:url('. get_stylesheet_directory_uri() .'/imgs/super_wp.png); }</style>';
}
add_action('login_head', 'my_login_logo');
@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 / login-logout-menu-items.php
Created February 29, 2016 18:17
Add login and logout links to main menu
<?php
/**
* Add login and logout links to main menu
*
* @param string $items The HTML list content for the menu items.
* @param obj $args An object containing wp_nav_menu() arguments.
*
* @link https://codex.wordpress.org/Function_Reference/wp_login_url
* @link https://codex.wordpress.org/Function_Reference/wp_logout_url
* @link https://developer.wordpress.org/reference/functions/wp_nav_menu/
@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 / add-query-vars.php
Last active June 27, 2023 03:25
Register custom query vars
<?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[] = 'key1';
@carlodaniele
carlodaniele / build-custom-query.php
Last active November 6, 2022 10:36
Build a custom query with pre_get_posts
<?php
/**
* Build a custom query
*
* @param $query obj The WP_Query instance (passed by reference)
*
* @link https://codex.wordpress.org/Class_Reference/WP_Query
* @link https://codex.wordpress.org/Class_Reference/WP_Meta_Query
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
@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