Skip to content

Instantly share code, notes, and snippets.

@mintplugins
mintplugins / Send email of files changed on server once per day
Last active November 2, 2019 15:27
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
#!/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 \
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 April 30, 2019 17:02
If javascript is disabled, hide everything on the page and show a message.
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 April 23, 2019 22:20
Just a quick sample to demonstrate how you could approach asking "Are you sure" when saving a 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 February 18, 2019 14:46
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
<?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
*/
<?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(
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',
// 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 May 8, 2020 14:53
Simple function to programmatically disable Gutenberg, and use the Classic Editor instead
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 ) {
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() {