Skip to content

Instantly share code, notes, and snippets.

View dartiss's full-sized avatar
🏠
Always working from home

David Artiss dartiss

🏠
Always working from home
View GitHub Profile
<?php
/*
Plugin Name: Plugin Example
Description: An example plugin
Version: 1.0
Author: [Your name]
Author URI: [Your website]
*/
@dartiss
dartiss / functions.php
Last active June 12, 2018 19:24
Detect Gutenberg use
<?php
function is_gutenberg() {
global $post;
if ( function_exists( 'gutenberg_post_has_blocks' ) && gutenberg_post_has_blocks( $post->ID ) {
return true;
} else {
return false;
}
@dartiss
dartiss / yourplugin.php
Last active July 10, 2018 08:51
Check for a minimum level of PHP and stop activation if the current host is below this
<?php
function check_php_level() {
$php = '[[your minimum PHP level]]'; // Minimum PHP level required
/* translators: %1$s: required PHP version, %2$s: current PHP level */
$message = sprintf( __( 'The [[your plugin name]] plugin requires PHP version %1$s or greater but you are using version %2$s. The plugin has NOT been activated.', '[[your text-domain]]' ), $php, PHP_VERSION );
$title = __( 'Plugin Activation Error', '[[your text-domain]]' );
if ( version_compare( PHP_VERSION, $php, '<' ) ) {
@dartiss
dartiss / functions.php
Created July 11, 2018 07:44
Switch off 'Try Gutenberg' callout
remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
@dartiss
dartiss / draft-menu.php
Last active September 7, 2018 16:18
Add a link to draft posts in your WordPress admin
<?php
function add_drafts_to_menu() {
global $wpdb;
$author = get_current_user_id();
// Get total number of draft posts. If more than zero add a sub-menu option
$all_posts = $wpdb -> get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft'" );
if ( $all_posts > 0 ) {
@dartiss
dartiss / config-plugin-header.php
Created September 12, 2018 07:36
Header for a WordPress site configuration plugin
<?php
/*
Plugin Name: Artiss.blog Configuration
Plugin URI: https://artiss.blog
Description: Configuration Settings for Artiss.blog
Author: David Artiss
Author URI: https://artiss.blog
*/
@dartiss
dartiss / wp_fork_detect.php
Last active July 28, 2023 18:27
WordPress fork detection
<?php
/**
* WordPress fork detection
*
* Check if a WordPress fork is in use. The check is a seperate function, instead of simply using the current function_exists
* in case the method of detection needs to change.
*/
function is_fork() {
@dartiss
dartiss / functions.php
Created April 24, 2020 09:56
WordPress script to add reusable blocks to the WP Admin menu
/**
* Add a menu for the block editor
*/
function add_block_menu() {
add_menu_page(
'Reusable Blocks',
'Reusable Blocks',
'manage_options',
'edit.php?post_type=wp_block',
@dartiss
dartiss / functions.php
Last active April 24, 2020 11:45
Add modules to Jetpack menu
/**
* Admin menu changes
*/
function add_menus() {
if ( class_exists( 'Jetpack' ) ) {
add_action( 'jetpack_admin_menu', 'add_jetpack_menu' );
}
}
@dartiss
dartiss / functions.php
Last active December 5, 2021 17:08
Add theme color support to a WordPress site
<?php
/**
* Add support for a theme colour
*/
function add_theme_colour() {
?>
<meta name="theme-color" content="#BE702B" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#333333" media="(prefers-color-scheme: dark)">
<?php
}