Skip to content

Instantly share code, notes, and snippets.

View johnalarcon's full-sized avatar
😎
Coding potently.

John Alarcon johnalarcon

😎
Coding potently.
View GitHub Profile
@johnalarcon
johnalarcon / functions.php
Created August 31, 2021 05:43
Display debugging state (enabled/disabled) in the ClassicPress admin bar
function codepotent_debug_notifier_register_admin_bar() {
// ...adjust the permission to suit your needs.
if (!current_user_can('manage_options')) {
return;
}
// Bring the admin bar into scope.
global $wp_admin_bar;
@johnalarcon
johnalarcon / functions.php
Created May 12, 2021 18:32
Remove the /users/ REST API endpoint in WordPress and ClassicPress
/**
* The following code will remove access to the /users/ endpoint. This makes the
* endpoint inaccessible while not blocking access to other endpoints. This code
* works with both WordPress and ClassicPress.
*
* Why do this? The REST API is very handy, however, by default, it exposes data
* that you may not want exposed – namely, your site's usernames. With a list of
* your usernames, the success of a brut-force attack becomes more likely.
*
*/
@johnalarcon
johnalarcon / functions.php
Created October 25, 2020 07:22
Remove plugins from search results in ClassicPress dashboard
/**
* Remove plugins from search results in ClassicPress dashboard.
* A little ditty by Code Potent. https://codepotent.com
*/
// Add slugs for any individual plugins to remove.
function codepotent_plugins_to_remove() {
$slugs = [
'wordfence',
'jetpack',
@johnalarcon
johnalarcon / somefile.js
Created March 15, 2021 22:48
Await existence of element before executing jQuery on it
// This can go into whatever file is enqueued for the given page, using the traditional admin_enqueue_scripts hook.
jQuery(document).ready(function($) {
var onElementExists = function(element, callback) {
if ($(element).length) {
callback($(element));
}
function check_again(element, callback) {
setTimeout(function() {
onElementExists(element, callback);
}, 100); // interval
-/(SHA|downloadable|zoom|jqmigrate|webfonts|mozPressure)/
Drop the above line into Firefox's browser console filter to remove certain messages.
Examples of messages removed:
- This page uses the non standard property “zoom”. Consider using calc() in the relevant property values, or using “transform” along with “transform-origin: 0 0”.
- JQMIGRATE: Migrate is installed with logging active, version 1.4.1
- MouseEvent.mozPressure is deprecated. Use PointerEvent.pressure instead.
@johnalarcon
johnalarcon / file-one.php
Created March 6, 2021 18:03
Multifile Gist Test
// Keep calm and code potent.
@johnalarcon
johnalarcon / index.php
Last active February 2, 2021 00:48
Capture div as image and save to server with html2canvas
<?php
/**
* -----------------------------------------------------------------------------
* Capture div as image and save to server with html2canvas
* -----------------------------------------------------------------------------
* Copyright 2021, John Alarcon
* -----------------------------------------------------------------------------
* This is free software released under the terms of the General Public License,
* version 2, or later. It is distributed WITHOUT ANY WARRANTY; without even the
@johnalarcon
johnalarcon / dashicons.php
Created January 5, 2021 03:24
Array of ClassicPress dashicons, sorted by type.
function get_dashicons() {
$icons = [
'admin' => [
'menu',
'admin-site',
'dashboard',
'admin-post',
'admin-media',
'admin-links',
@johnalarcon
johnalarcon / debug.php
Last active November 26, 2020 07:17
A couple of simple functions to help with debugging ClassicPress plugins in development.
<?php
// Prevent direct access.
if (strpos($_SERVER['PHP_SELF'], 'debug.php')) {
die();
}
/**
* Debug - to expose data in variables, arrays, objects.
*
@johnalarcon
johnalarcon / apply-action-after-widget-update.js
Last active October 16, 2020 18:46
Hook in to the ClassicPress widget update process
jQuery(document).ajaxSuccess(function(e, xhr, settings) {
// This is the data of interest.
console.log(settings);
// Identifier for your (or whatever) particular widget.
var widget_id_base = 'text'; // text, search, my-widget, et al.
// Check if updating a widget of this type.
if((settings.data.search('action=save-widget') != -1) && (settings.data.search('id_base='+widget_id_base) != -1)) {