Skip to content

Instantly share code, notes, and snippets.

😎
Coding potently.

John Alarcon johnalarcon

😎
Coding potently.
Block or report user

Report or block johnalarcon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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() {
View convert-update-manager-cpts.sql
/*
If you are switching from f(x) Updater [or] if you are moving
from Update Manager RC1 to RC2, run the following two queries
directly against your database to convert the post types into
the post types used by RC2. In these queries, you must change
the prefix "cp_" to match your own prefix. This is a one-time
thing to resolve issue #1.
See: https://github.com/codepotent/Update-Manager/issues/1
@johnalarcon
johnalarcon / functions.php
Created Oct 22, 2019
Shortcode to create a linked list of site policies.
View functions.php
/**
* Site policies shortcode.
*
* This shortcode creates a linked list of site policies. Any page that uses the
* word "policy" in the title or slug is deemed a policy to be listed. Using the
* shortcode [site-policies] in any post or page (or anywhere shortcodes work on
* your particular site,) will output a linked list the site policies.
*
* The following attributes are supported; include as many or as few as you like
* to get the desired result. The default behavior is to display all policies in
@johnalarcon
johnalarcon / functions.php
Created Sep 10, 2019
Retrieve specific fields from an attachment when only a value is known.
View functions.php
function codepotent_get_attachment_field($select, $where, $value) {
// Bring database object into scope.
global $wpdb;
// Assemble the query.
$sql = "SELECT %s FROM $wpdb->posts WHERE %s='%s';";
// Run the query.
$result = $wpdb->get_var($wpdb->prepare($sql, $select, $where, trim($value)));
@johnalarcon
johnalarcon / functions.php
Created Jul 24, 2019
Add "Documents" to media library filter options
View functions.php
<?php
function codepotent_add_media_library_document_filter($post_mime_types) {
$post_mime_types['application'] = [
0 => 'Documents',
1 => 'Manage Documents',
2 => [
0 => 'Document (%s)',
1 => 'Documents (%s)',
'singular' => 'Document (%s)',
@johnalarcon
johnalarcon / functions.php
Created Jul 14, 2019
Convert hexadecimal values to decimal values
View functions.php
function convert_hex2dec($hex) {
// Remove hashmark, if present.
if (substr($hex, 0, 1) === '#') {
$hex = substr($hex, 1);
}
// Max of 8 characters.
if (strlen($hex) > 8) {
$hex = substr($hex, 0, 8);
View attach-external-featured-image.php
@johnalarcon
johnalarcon / functions.php
Last active Apr 12, 2019
Filter examples for the Shortcodes Everywhere plugin for ClassicPress. These code snips can be added to a functionality plugin or the functions.php file.
View functions.php
<?php
// Disable shortcodes in widgets? Use this filter!
add_filter('codepotent_shortcodes_everywhere_widgets', '__return_false');
// Disable shortcodes in excerpts? Use this filter!
add_filter('codepotent_shortcodes_everywhere_excerpts', '__return_false');
// Disable shortcodes in category descriptions? Use this filter!
add_filter('codepotent_shortcodes_everywhere_terms', '__return_false');
You can’t perform that action at this time.