Skip to content

Instantly share code, notes, and snippets.

Avatar

Greg Schoppe gschoppe

View GitHub Profile
@gschoppe
gschoppe / gjs-disable-attachment-pages.php
Last active Oct 21, 2021
WordPress plugin to properly disable attachment pages. This is not a redirect or forced 404. Attachment pages will simply not exist, and the slug will remain available for other posts and pages..
View gjs-disable-attachment-pages.php
<?php if( ! defined( 'ABSPATH' ) ) { die(); }
/**
* Plugin Name: Disable Attachment Pages
* Plugin URI: https://gschoppe.com/wordpress/disable-attachment-pages
* Description: Completely disable attachment pages the right way. No forced redirects or 404s, no reserved slugs.
* Author: Greg Schoppe
* Author URI: https://gschoppe.com/
* Version: 1.0.0
**/
@gschoppe
gschoppe / Class-CropInterface.js
Last active Jan 31, 2021
A simple class to convert a div, or other block-level element, into a zoom and crop interface for images. Sample Implementation: https://codepen.io/gschoppe/pen/xxRxwaO
View Class-CropInterface.js
function CropInterface(el, w, h, resolutionMultiple) {
// handle parameters
this.el = el;
if (!w) { w = 100; }
this.w = w;
if (!h) { h = 100; }
this.h = h;
this.r = w / h;
if (!resolutionMultiple) { resolutionMultiple = 1; }
this.resolutionMultiple = resolutionMultiple;
@gschoppe
gschoppe / Class-ImageScaler.js
Last active Jan 30, 2021
A simple JS class to manage client-side cropping. ImageScaler supports setting a focal point for the image, as well as selecting a zoom level for the crop
View Class-ImageScaler.js
function ImageScaler(canvas, focus, zoom) {
if (canvas) {
this.canvas = canvas;
} else {
this.canvas = document.createElement("CANVAS");
}
if (focus) {
this.focus = focus;
} else {
this.focus = {x:.5,y:.5};
@gschoppe
gschoppe / Class-IntervalManager.js
Last active Jan 24, 2021
Class to simplify management of intervals
View Class-IntervalManager.js
function IntervalManager() {
this.intervals = [];
// Public
this.setInterval = function(callback, interval, name) {
if (!name) {
name = "" + Date.now() + "|" + Math.random();
}
var newInterval = {
'name': name,
View Class-DB.gs
function DB(projectID) {
this.projectID = projectID;
this.types = {
'INT64' : "INT64",
'NUMERIC' : "NUMERIC",
'BIGNUMERIC': "BIGNUMERIC",
'FLOAT64' : "FLOAT64",
'BOOL' : "BOOL",
'STRING' : "STRING",
@gschoppe
gschoppe / WP_Persistent_Notices.php
Last active Nov 4, 2019 — forked from obenland/gist:5173811
Implements a standardized messaging system that allows admin notices to be passed across page redirects. usage: add_filter( 'wp_persistent_notices', function( $notices ) { $notices[] = array( 'type' => 'error', 'message' => "Houston, we have a problem!" ); return $notices; } );
View WP_Persistent_Notices.php
<?php if( !defined( 'ABSPATH' ) ) { die(); } // Include in all php files, to prevent direct execution
/**
* Class Name : WP Persistent Notices
* Description : Implements a Standardized messaging system that allows admin messages to be passed across page redirects.
* Class URI : http://gschoppe.com/wordpress/pass-wordpress-admin-notices-across-page-redirects/
* Version : 1.0.0
* Author : Greg Schoppe
* Author URI : http://gschoppe.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@gschoppe
gschoppe / cat-like-custom-taxonomy.php
Created Feb 28, 2016
Use category (checkbox-based) interface with non-hierarchical custom taxonomies
View cat-like-custom-taxonomy.php
<?php
// Event taxonomies
add_action( 'init', function() {
$labels = array(
'name' => _x( 'Terms', 'taxonomy general name' ),
'singular_name' => _x( 'Term', 'taxonomy singular name' ),
);
register_taxonomy( 'taxonomy_name', array( 'post' ), array(
'hierarchical' => false,
@gschoppe
gschoppe / wp_update_watch.php
Created Dec 6, 2018
WordPress Update Watch
View wp_update_watch.php
<?php
if( !empty($_GET['request']) ) {
$current_version = "";
$url = "https://api.wordpress.org/core/version-check/1.7/";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url
));
$result = curl_exec($curl);
@gschoppe
gschoppe / admin-bar-for-weglot.php
Last active Oct 12, 2018
Adds a "Translate" button to the admin bar, on post-edit and front end pages, that links directly to the WeGlot visual editor for that page.
View admin-bar-for-weglot.php
<?php if(!defined('ABSPATH')) { die(); }
/*
Plugin Name: Admin Bar for WeGlot
Plugin URI: https://gschoppe.com
Description: Adds an admin bar link to translate any page on your site
Version: 0.1.0
Author: Greg Schoppe
Author URI: https://gschoppe.com
Text Domain: weglotadminbar