Skip to content

Instantly share code, notes, and snippets.


Mark Wilkinson wpmark

View GitHub Profile
wpmark / wp-featured-image-url.php
Created November 18, 2012 16:12
Get WordPress Featured Image URL
View wp-featured-image-url.php
wpmark / mdw_user_has_blog_role.php
Created November 22, 2012 20:26
Check User is a Blog User on Network Site
View mdw_user_has_blog_role.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 / gist:4534059
Last active December 11, 2015 02:58
Adding a Custom table in WordPress using a WordPress plugin.
View gist:4534059
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 / gist:4534269
Created January 14, 2013 22:47
Add data to a Custom WordPress table
View gist:4534269
/* 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 / 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
View gist:5007195
Plugin Name: User Switching in Admin Bar
Plugin URI:
Description: Build upon the User Switching plugin ( 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:
Version: 1.0
wpmark / wp-sidebar-menu.php
Created October 20, 2013 11:06
WordPress Sidebar Menu for Pages
View wp-sidebar-menu.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 / gist:8160972
Last active September 9, 2017 15:19
Remove WordPress admin menu items for certain users.
View gist:8160972
/* 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 / local-config.php
Created January 10, 2014 10:10
Local Config file for WordPress Multisite.
View local-config.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 / 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.
View mdw-activation-plugin.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:
License: GPLv2 or later
wpmark / gist:9069976
Created February 18, 2014 12:22
Change Whistles WordPress Plugin Post Type Labels
View gist:9069976
* 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';