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
@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 / 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 / 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 / functions.php
Created July 11, 2018 07:44
Switch off 'Try Gutenberg' callout
remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
@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
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;
}
<?php
/*
Plugin Name: Plugin Example
Description: An example plugin
Version: 1.0
Author: [Your name]
Author URI: [Your website]
*/
<?php
function embed_code( $content ) {
global $post;
$i = 1;
while ( $i < 6 ) {
$code = 'CODE' . $i;
@dartiss
dartiss / functions.php
Last active March 25, 2018 15:43
Add Gutenberg promo to the site of WordPress posts
<?php
function add_gutenberg_promo( $content ) {
global $post;
if ( function_exists( 'gutenberg_post_has_blocks' ) && gutenberg_post_has_blocks( $post->ID ) && is_single() ) {
$content = '<div style="background:#fff8c4; border:1px solid #f2c779; border-radius:10px; padding:10px; margin-bottom:10px;">This post was created using Gutenberg, the new editor, coming soon, for WordPress. You can <a href="https://wordpress.org/gutenberg/">learn more about it here</a>, <a href="https://wordpress.org/plugins/gutenberg/">try the Beta plugin</a> or simply <a href="https://testgutenberg.com">try it out for yourself</a>, no site required.</div>' . $content;
}
@dartiss
dartiss / function.php
Last active March 8, 2018 09:22
Adding AdSense Auto ads to your WordPress site
function google_autoads() {
?>
[[insert your AdSense script here]]
<?php
}
add_action( 'wp_head', 'google_autoads' );