Skip to content

Instantly share code, notes, and snippets.

@meoso
meoso / shotcut.sh
Last active December 3, 2020 17:45
Shotcut launcher bash script
#!/bin/bash
#assumes new downloads of shotcut is always in ~/Downloads
currpath=$(pwd)
cd ~/Downloads
chmod +x ./[Ss]hotcut-*.AppImage
#always choose the latest Shotcut-*.AppImage download
shotcut=$(ls -Art [Ss]hotcut-*.AppImage | tail -n 1 | cut -d' ' -f 9-)
cd "${currpath}"
@DavidWells
DavidWells / async-await-node-style-promises.js
Last active June 30, 2023 14:08
Nicer business logic with async wait promises that won't swallow native JS errors. Update to https://gist.github.com/DavidWells/54f9dd1af4a489e5f1358f33ce59e8ad where we handle native JS errors instead of potentially missing them. Now a package here https://www.npmjs.com/package/safe-await
/* Native Error types https://mzl.la/2Veh3TR */
const nativeExceptions = [
EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError
].filter((except) => typeof except === 'function')
/* Throw native errors. ref: https://bit.ly/2VsoCGE */
function throwNative(error) {
for (const Exception of nativeExceptions) {
if (error instanceof Exception) throw error
}
@WordPress-Handbuch
WordPress-Handbuch / listing-18-17.php
Created April 23, 2019 06:09
WordPress 5 dropin for db-error.php, a custom error message in case of a failed database connection
<?php ob_start();
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
mail("info@ihredomain", "Datenbankfehler", "Schon wieder die Datenbank!", "From: Meine Website");
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Website nicht erreichbar</title>
@jasonbahl
jasonbahl / disable-frontent.php
Last active August 27, 2024 17:03
Disable frontend but allow REST, CRON and GraphQL Requests
<?php
add_action( 'parse_request', 'disable_front_end', 99 );
function disable_front_end() {
global $wp;
/**
* If the request is not part of a CRON, REST Request, GraphQL Request or Admin request,
@damiencarbery
damiencarbery / disable-plugins-by-url.php
Last active December 29, 2020 05:14
Class To Disable WordPress Plugins By URL - Disable specified plugins except for certain pages - enhanced with caching. http://www.damiencarbery.com/2019/03/class-to-disable-wordpress-plugins-by-url/
<?php
/*
Plugin Name: Class To Disable WordPress Plugins By URL
Plugin URI: http://www.damiencarbery.com/2019/03/class-to-disable-wordpress-plugins-by-url/
Description: Disable specified plugins except for certain pages - enhanced with caching.
Version: 0.1
Author: Damien Carbery
Author URI: http://www.damiencarbery.com/
*/
@bueltge
bueltge / disable-rest-api.php
Last active April 30, 2020 04:22
Disable WordPress REST API for users, there have not enough rights
<?php # -*- coding: utf-8 -*-
declare(strict_types=1);
/**
* Plugin Name: Disable REST API
*/
// Completely disable wp-json access.
add_filter(
'rest_authentication_errors',
function () {
<?php
$consumer_key = '';
$consumer_secret = '';
// If the $_GET parameters are present, use those first.
if ( ! empty( $_GET['consumer_key'] ) && ! empty( $_GET['consumer_secret'] ) ) {
$consumer_key = $_GET['consumer_key']; // WPCS: sanitization ok.
$consumer_secret = $_GET['consumer_secret']; // WPCS: sanitization ok.
}
@lukecav
lukecav / functions.php
Created March 12, 2019 19:40
Preload product categories in WooCommerce when using WP Super Cache
add_filter( 'wp_cache_preload_taxonomies', 'wpsc_preload_taxonomies' );
function wpsc_preload_taxonomies( $taxes ) {
return array_merge( $taxes, array( 'product_tag' => 'product_tag', 'product_cat' => 'product_cat' ) );
}
<?php
/**
* Gravity Perks // Populate Anything // Populate Post Meta as Choices
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*/
// Update "123" with your form ID; Update "4" with your field ID.
add_filter( 'gppa_input_choices_123_4', function( $choices, $field, $objects ) {
$custom_field = str_replace( 'meta_', '', $field['gppa-choices-templates']['label'] );
$meta = get_post_meta( $objects[0]->ID, $custom_field );
<?php
/**
* GP Unique ID // Gravity Perks // Date-specific Sequences
* http://gravitywiz.com/
*
* Requirements:
* - Your form ID cannot be more than 3 digits.
* - Your field ID cannot be more than 2 digits.
*/
// Update "123" to your form ID. Update "4" to your Unique ID field ID.