Skip to content

Instantly share code, notes, and snippets.

Avatar
😎
Coding potently.

John Alarcon johnalarcon

😎
Coding potently.
View GitHub Profile
@johnalarcon
johnalarcon / index.php
Last active Feb 2, 2021
Capture div as image and save to server with html2canvas
View index.php
<?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 Jan 5, 2021
Array of ClassicPress dashicons, sorted by type.
View dashicons.php
function get_dashicons() {
$icons = [
'admin' => [
'menu',
'admin-site',
'dashboard',
'admin-post',
'admin-media',
'admin-links',
@johnalarcon
johnalarcon / debug.php
Last active Nov 26, 2020
A couple of simple functions to help with debugging ClassicPress plugins in development.
View debug.php
<?php
// Prevent direct access.
if (strpos($_SERVER['PHP_SELF'], 'debug.php')) {
die();
}
/**
* Debug - to expose data in variables, arrays, objects.
*
@johnalarcon
johnalarcon / functions.php
Created Oct 25, 2020
Remove plugins from search results in ClassicPress dashboard
View functions.php
/**
* 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 / apply-action-after-widget-update.js
Last active Oct 16, 2020
Hook in to the ClassicPress widget update process
View apply-action-after-widget-update.js
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)) {
@johnalarcon
johnalarcon / apply-action-after-plugin-update.php
Created Oct 16, 2020
Apply action after ClassicPress plugin update
View apply-action-after-plugin-update.php
if ($options['action'] == 'update') {
if ($options['type'] == 'plugin') {
if (!empty($options['plugins'])) {
if (in_array(plugin_basename(__FILE__), $options['plugins'], true)) {
// Do stuff.
}
}
}
}
@johnalarcon
johnalarcon / codepotent-readme-complete.php
Created Sep 29, 2020
Extract full plugin details from README.md in a typical ClassicPress plugin.
View codepotent-readme-complete.php
<?php
namespace CodePotent\Readme2Complete;
// Usage
$readme_file = 'https://gist.githubusercontent.com/johnalarcon/c19d3111dc73578a3fe224084e2194ec/raw/9a9facfc849e915851fd99cbb6495ded9904340a/README.md';
$readme_lines = file($readme_file);
$readme_array = parse_readme($readme_lines);
// Result
@johnalarcon
johnalarcon / codepotent-readme-sections.php
Created Sep 29, 2020
Extract sections from README.md in a typical ClassicPress plugin.
View codepotent-readme-sections.php
<?php
namespace CodePotent\Readme2Sections;
// Usage
$readme_file = 'https://gist.githubusercontent.com/johnalarcon/c19d3111dc73578a3fe224084e2194ec/raw/9a9facfc849e915851fd99cbb6495ded9904340a/README.md';
$readme_lines = file($readme_file);
$sections_array = get_sections($readme_lines);
// Result
@johnalarcon
johnalarcon / README.md
Created Sep 29, 2020
For testing purposes.
View README.md

=== Update Manager ===

Description: Painlessly push updates to your ClassicPress plugin and theme users! Serve updates from GitHub, your own site, or somewhere in the cloud. 100% integrated with the ClassicPress update process; slim and performant. Version: 2.0.0 Text Domain: codepotent-update-manager Domain Path: /languages Requires PHP: 5.6 Requires: 1.0.0 Tested: 4.9.99 Author: Code Potent

@johnalarcon
johnalarcon / hierarchy.php
Created Apr 17, 2020 — forked from johnbillion/hierarchy.php
ASCII WordPress Template Hierarchy
View hierarchy.php
<?php
/*
WordPress Template Hierarchy (as of WordPress 4.9)
is_404() -------------------------------------------------------------------------------------------------> 404.php
is_search() ----------------------------------------------------------------------------------------------> search.php
is_front_page() ------------------------------------------------------------------------------------------> front-page.php
is_home() ------------------------------------------------------------------------------------------------> home.php