Skip to content

Instantly share code, notes, and snippets.

View wpmark's full-sized avatar

Mark Wilkinson wpmark

View GitHub Profile
@wpmark
wpmark / hd-user-categories.php
Created June 11, 2021 11:05
A WordPress plugin that adds categories to users. It allows you to assign categories to users which you could then use elsewhere in your site.
<?php
/*
Plugin Name: User Categories
Plugin URI: https://highrise.digital/
Description: Adds categories to users. It allows you to assign categories to users which you could then use elsewhere in your site.
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital Ltd
Author URI: https://highrise.digital/
Text domain: hd-user-categories
@wpmark
wpmark / php-block-styles.php
Last active November 27, 2024 10:27
Register WordPress block styles with PHP
<?php
/**
* Register some default block editor styles for this block.
*/
function hd_register_block_styles() {
// add the small image style.
register_block_style(
'core/heading', // name of your block
array(
@wpmark
wpmark / gallery-block-counters.php
Created November 25, 2024 13:38
Add image and total image count to the WordPress Gallery block
@wpmark
wpmark / block-stylesheets.php
Last active October 31, 2024 08:57
Easily enqueue a stylesheet for any block just by placing one in your theme.
<?php
/**
* Enqueues a stylesheet for each block, if it exists in the theme.
*/
function hd_enqueue_block_styles() {
// get all of the registered blocks.
$blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();
// if we have block names.
@wpmark
wpmark / render-post-terms-block-output.php
Created March 17, 2023 10:08
Modify the post terms block output in WordPress
<?php
/**
* Changes the links on post terms block for job listing category terms.
*
* @param string $block_content The block content.
* @param array $block The full block, including name and attributes.
* @param WP_Block $instance The block instance.
*
* @return string $block_content The block content.
*/
@wpmark
wpmark / wp-query-orderby-muliple-meta-keys.php
Created November 18, 2015 12:48
WP_Query Ordered By Multiple Meta Keys
<?php
/* build a new wp_query */
$classes = new WP_Query(
array(
'post_type' => 'wpmark_class_time', // post type to query
'posts_per_page' => -1, // get all the posts not limited
'meta_query' => array(
'relation' => 'AND',
'day' => array( // give the first meta key array an array key
'key' => '_wpmark_day',
@wpmark
wpmark / readme.md
Last active June 1, 2023 20:32
Escaping output with only specific allowed HTML elements.

Escaping output with only specific allowed HTML elements

Sometimes when developing for WordPress, you will want to echo something. As all good developers know, any such content must be escaped. This makes sure that nothing nasty can be echoed and keeps you code more secure.

WordPress comes with a number of escaping functions, however sometimes they don't quite do as you want. Take this example.

@wpmark
wpmark / wp-admin-page-function.php
Created November 19, 2014 16:09
WordPress Admin Page Content Function
<?php
function wpmark_admin_menu_content() {
?>
<div class="wrap">
<h2>My Admin Page</h2>
<?php
@wpmark
wpmark / wp-dashboard-tabs.php
Created March 18, 2015 19:22
WordPress Dashboard Tabs
<?php
/***************************************************************
* Function wpbasis_dashboard_content()
* Pulls in the new dashboard page content from plugin file
***************************************************************/
function wpbasis_dashboard() {
/* check for a dashboard content file in the theme folder */
if( file_exists( STYLESHEETPATH . '/wpbasis/dashboard.php' ) ) {
/* load the dashboard content file from the theme folder */
get_template_part( 'wpbasis/dashboard', 'content' );
@wpmark
wpmark / wp-custom-content-folder.php
Created November 26, 2015 19:43
Custom Content Directory for WordPress
<?php
* Custom Content Directory
*/
define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER[ 'HTTP_HOST' ] . '/content' );
?>