Skip to content

Instantly share code, notes, and snippets.

View wpmark's full-sized avatar

Mark Wilkinson wpmark

View GitHub Profile
@wpmark
wpmark / wp-featured-image-url.php
Created November 18, 2012 16:12
Get WordPress Featured Image URL
@wpmark
wpmark / mdw_user_has_blog_role.php
Created November 22, 2012 20:26
Check User is a Blog User on Network Site
<?php
/* protects site from those who are not assigned to it */
function mdw_user_has_blog_role() {
/* get the global blog id */
global $blog_id;
/* check user is part of this blog, and die if they are not */
if( ! is_blog_user( $blog_id ) )
wp_die( __("You are trying to access a site that you are not allowed to see. Naughty you!") );
@wpmark
wpmark / gist:4534059
Last active December 11, 2015 02:58
Adding a Custom table in WordPress using a WordPress plugin.
<?php
function wpct_create_db_table() {
global $wpdb;
/* create the table name using the wordpress table prefix for this site */
$wpct_tablename = $wpdb->prefix . "wpct";
/* setup the structure of the table creating these as a variable */
@wpmark
wpmark / gist:4534269
Created January 14, 2013 22:47
Add data to a Custom WordPress table
<?php
/* create a function to get the values from this page load */
function wpct_track_content() {
/* call the global post variable to gain access to post data */
global $post;
/* setup an array to store all our values */
$wpct_post_values = array();
@wpmark
wpmark / gist:5007195
Last active July 26, 2017 01:35
Plugin to add a dropdown list of users in the WordPress admin bar with a link to switch to that user (requires the User Switching plugin by http://profiles.wordpress.org/johnbillion/).
<?php
/**
Plugin Name: User Switching in Admin Bar
Plugin URI: http://markwilkinson.me
Description: Build upon the User Switching plugin (http://wordpress.org/extend/plugins/user-switching/) by John Blackbourn and adds a dropdown list of users in the WordPress admin bar with a link to switch to that user.
Author: Mark Wilkinson
Author URI: http://markwilkinson.me
Version: 1.0
*/
@wpmark
wpmark / wp-sidebar-menu.php
Created October 20, 2013 11:06
WordPress Sidebar Menu for Pages
<?php
/* check whether the current post has a parent */
if( $post->post_parent ) {
/* get the ancestors/parent of the current post */
$pxjn_ancestors = get_post_ancestors( $post->ID );
/* count the number of parents retrieved less 1 */
$pxjn_root = count( $pxjn_ancestors ) -1;
@wpmark
wpmark / gist:8160972
Last active September 9, 2017 15:19
Remove WordPress admin menu items for certain users.
<?php
/* add our function to the admin meny action */
add_action( 'admin_menu', 'pxjn_remove_menus', 999 );
function pxjn_remove_menus() {
/* get the current user id */
$pxjn_current_user_id = $current_user->ID; // get the user ID
@wpmark
wpmark / local-config.php
Created January 10, 2014 10:10
Local Config file for WordPress Multisite.
<?php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'db_name');
/** MySQL database username */
define('DB_USER', 'db_user');
/** MySQL database password */
define('DB_PASSWORD', 'db_password');
@wpmark
wpmark / mdw-activation-plugin.php
Last active January 3, 2016 19:39
Plugin which runs a function to activate other plugins when new sites are created.
<?php
/*
Plugin Name: Multisite Site Creation Activation Plugin
Plugin URI:
Description: Plugin which runs a function to activate other plugins when new sites are created.
Version: 1.0
Author: Mark Wilkinson
Author URI: http://markwilkinson.me
License: GPLv2 or later
*/
@wpmark
wpmark / gist:9069976
Created February 18, 2014 12:22
Change Whistles WordPress Plugin Post Type Labels
<?php
/***************************************************************
* Function pxlcore_whistles_post_labels()
* Changes the post labels for the Whistles post type.
***************************************************************/
function pxlcore_whistles_post_labels( $labels ) {
$labels->name = 'Snippets';
$labels->singular_name = 'Snippet';
$labels->menu_name = 'Snippets';