Skip to content

Instantly share code, notes, and snippets.

Avatar

David Artiss dartiss

View GitHub Profile
@dartiss
dartiss / functions.php
Last active Apr 24, 2020
Add modules to Jetpack menu
View functions.php
/**
* Admin menu changes
*/
function add_menus() {
if ( class_exists( 'Jetpack' ) ) {
add_action( 'jetpack_admin_menu', 'add_jetpack_menu' );
}
}
@dartiss
dartiss / functions.php
Created Apr 24, 2020
WordPress script to add reusable blocks to the WP Admin menu
View functions.php
/**
* 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 / wp_fork_detect.php
Last active Dec 31, 2019
WordPress fork detection
View wp_fork_detect.php
<?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 / config-plugin-header.php
Created Sep 12, 2018
Header for a WordPress site configuration plugin
View config-plugin-header.php
<?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 / draft-menu.php
Last active Sep 7, 2018
Add a link to draft posts in your WordPress admin
View draft-menu.php
<?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 / functions.php
Created Jul 11, 2018
Switch off 'Try Gutenberg' callout
View functions.php
remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
@dartiss
dartiss / yourplugin.php
Last active Jul 10, 2018
Check for a minimum level of PHP and stop activation if the current host is below this
View yourplugin.php
<?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
Last active Jun 12, 2018
Detect Gutenberg use
View functions.php
<?php
function is_gutenberg() {
global $post;
if ( function_exists( 'gutenberg_post_has_blocks' ) && gutenberg_post_has_blocks( $post->ID ) {
return true;
} else {
return false;
}
View plugin-example.php
<?php
/*
Plugin Name: Plugin Example
Description: An example plugin
Version: 1.0
Author: [Your name]
Author URI: [Your website]
*/
View code-embed.php
<?php
function embed_code( $content ) {
global $post;
$i = 1;
while ( $i < 6 ) {
$code = 'CODE' . $i;
You can’t perform that action at this time.