Skip to content

Instantly share code, notes, and snippets.

Phil Johnston mintplugins

Block or report user

Report or block mintplugins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mintplugins
mintplugins / Send email of files changed on server once per day
Last active Nov 2, 2019
Put this code in a shell file called "email-if-files-changed" somewhere on your server. Then link to it from a cronjob in your crontab file using this line: 01 1 * * * root /path-to-your-custom-script/email-if-files-changed
View Send email of files changed on server once per day
#!/bin/bash
FILES_CHANGED=$(find /var/www -type f -mmin -$((60*24)) -printf '%TY-%Tm-%Td %TT %p\n' | sort -r)
if [ !$FILES_CHANGED ]
then
curl -s --user 'api:MAILGUN_API_KEY' \
https://api.mailgun.net/v3/YOURMAILGUNDOMAIN/messages \
-F from='Name of your server<support@yourdomain.com>' \
-F to=support@yourdomain.com \
View Get directory and filename of a plugin, by passing its filename only
function get_dir_and_filename_of_active_plugin( $plugin_filename = 'akismet.php' ) {
$plugin_dir_and_filename = false;
$active_plugins = get_option( 'active_plugins' );
foreach ( $active_plugins as $active_plugin ) {
if ( false !== strpos( $active_plugin, $plugin_filename ) ) {
$plugin_dir_and_filename = $active_plugin;
break;
}
}
return $plugin_dir_and_filename;
@mintplugins
mintplugins / WordPress javascript required
Last active Apr 30, 2019
If javascript is disabled, hide everything on the page and show a message.
View WordPress javascript required
function my_prefix_hide_everything_if_javascript_disabled() {
?>
<noscript id="javascript_test">
<style type="text/css">
body > * {display:none!important;}
#javascript_test{
display:block!important;
}
</style>
<div class="noscriptmsg">
@mintplugins
mintplugins / Warn when saving any EDD payment
Created Apr 23, 2019
Just a quick sample to demonstrate how you could approach asking "Are you sure" when saving a payment
View Warn when saving any EDD payment
function custom_prefix_warn_about_old_refunds_js() {
if ( ! isset( $_GET['prevent_accidental_refunds_js'] ) ) {
return false;
}
header('Content-Type: application/javascript');
?>
@mintplugins
mintplugins / edd-fix-child-licenses.php
Last active Feb 18, 2019
This is a simple plugin that can be used to set all child license keys expiration dates to their parent's. This is not for use in production, and is for example purposes only
View edd-fix-child-licenses.php
<?php
/*
Plugin Name: Easy Digital Downloads - Fix child licenses
Description: Make the child licenses of all licensed bundles match the parent license expiration
Plugin URI: https://easydigitaldownlaods.com
Author: Phil Johnston
Author URI: https://easydigitaldownloads.com
Version: 1.0
License: GPL2
*/
View Simple Theme Update Example
<?php
function simple_theme_updater( $update_themes, $transient_name ) {
// We can use the active theme name, because if this code is running, we know this is the active theme.
$active_theme_slug = get_template();
$theme = json_decode(
json_encode(
array(
View simple-plugin-update-example.php
function get_my_plugin_data(){
// You'll likely replace this with some sort of API call home.
$plugin = json_decode(
json_encode(
array(
'new_version' => 89,
'stable_version' => 89,
'name' => 'My Fake Plugin',
'slug' => 'my-fake-plugin',
'url' => 'https://myfakeplugin.com',
View wordpress-google-analytics.php
// Google Analytics
function my_website_google_analytics(){
// Don't track visits by logged-in administrators
if ( current_user_can( 'update_plugins' ) ) {
return;
}
?>
<!-- Replace me with Google Analytics Tracking Code -->
@mintplugins
mintplugins / disable-gutenberg.php
Last active Dec 13, 2018
Simple function to programmatically disable Gutenberg, and use the Classic Editor instead
View disable-gutenberg.php
if ( ! function_exists( 'disable_gutenberg' ) ) {
function disable_gutenberg() {
global $wp_filter;
$callbacks_array = $wp_filter['init']->callbacks;
foreach( $wp_filter as $tag => $priorities ) {
foreach( $priorities->callbacks as $priority => $callback_data ) {
foreach( $callback_data as $callback_function_name => $callback_function_data ) {
View JSX-Gutenberg-Blocks-without-Webpack.js
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
registerBlockType( 'my-custom-gutenberg-block/static-jsx-example', {
title: __( 'Static Block Example with JSX' ),
icon: 'lock',
category: 'common',
edit() {
You can’t perform that action at this time.