Skip to content

Instantly share code, notes, and snippets.

Avatar
😎
Coding potently.

John Alarcon johnalarcon

😎
Coding potently.
View GitHub Profile
@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
@johnalarcon
johnalarcon / functions.php
Created Mar 8, 2020
Whitelist the usernames that can login to a ClassicPress site.
View functions.php
function codepotent_disable_rogue_logins($user, $username, $pass) {
// An array of usernames allowed to login.
$allowed_usernames = [
'coolChick582',
'geekdude1',
'some_other_username'
];
// Not an allowed username? Fail the login.
@johnalarcon
johnalarcon / functions.php
Last active Jan 3, 2020
A few custom tweaks for the new ClassicPress Security page
View functions.php
/**
* Remove ClassicPress security page from admin menu and convert icon to text.
*
* Reasoning: After being initially in favor of the addition of a security page,
* the implementation seems rushed and incomplete. Since I already have a plugin
* for security, this means I have 2 entries for security in the top-level admin
* menu. This action hook removes the needless core menu item. This doesn't kill
* the security page's functionality; it only removes the admin menu item. For a
* plugin that has registered security settings to be displayed on that page, it
* will still have a "shield" icon on the plugin admin page leading to the right
@johnalarcon
johnalarcon / readme.txt
Last active Dec 22, 2019
A robust endpoint example demonstrating how to create a fully-populated display around a plugin. For use with Update Manager plugin for ClassicPress. This can be copied directly into the endpoint text editor and tweaked to suit.
View readme.txt
=== Update Manager ===
Description: Painlessly push updates to your ClassicPress plugin users! Serve updates from GitHub, your own site, or somewhere in the cloud. 100% integrated with the ClassicPress update process; slim and performant.
Version: 1.0.0-rc2
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 / functions.php
Last active Dec 14, 2019
Show current PHP version in ClassicPress admin bar
View functions.php
/**
* Add PHP version to ClassicPress admin bar.
*
* For environments in which the PHP version is subject to change, this will add
* the currently-running PHP version number to the admin bar to save some clicks
* and keep it immediately discoverable.
*
* @author John Alarcon
*/
function codepotent_adminbar_php_version() {
You can’t perform that action at this time.