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
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');
@johnalarcon
johnalarcon / functions.php
Last active Apr 12, 2019
Filter examples for the Registration Honeypot plugin for ClassicPress. These code snips can be added to a functionality plugin or the functions.php file.
View functions.php
<?php
// Enable mail server ping during registration.
add_filter('codepotent_registration_honeypot_ping_mail_server', '__return_true');
@johnalarcon
johnalarcon / functions.php
Last active Apr 2, 2019
Filter examples for the Discourse Stats plugin for ClassicPress. These code snips can be added to a functionality plugin or the functions.php file.
View functions.php
<?php
// Change the update interval of the Discourse Stats plugin widgets.
function codepotent_discourse_stats_update_interval($seconds) {
return 86400; // 1 day
}
add_filter('codepotent_discourse_stats_update_interval', 'codepotent_discourse_stats_update_interval');
// Change the date format for the "Join date" of the Discourse Stats plugin for ClassicPress.
// See https://www.php.net/manual/en/function.date.php for all the possible date tokens.
@johnalarcon
johnalarcon / functions.php
Created Jan 30, 2019
Filter examples for the Estimated Read Time plugin for ClassicPress. These code snips can be added to a functionality plugin or the functions.php file.
View functions.php
<?php
// Define reading speed of your audience. 200 WPM is average; adjust to suit.
add_filter('codepotent_estimated_read_time_speed', 'codepotent_estimated_read_time_speed');
function codepotent_estimated_read_time_speed($reading_speed) {
return 125;
}
@johnalarcon
johnalarcon / update-classicpress-urls.sql
Created Jan 30, 2019
SQL query to update URLs after moving a ClassicPress site.
View update-classicpress-urls.sql
UPDATE cp_options SET option_value = replace(option_value, 'OLD_URL', 'NEW_URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE cp_posts SET guid = replace(guid, 'OLD_URL', 'NEW_URL');
UPDATE cp_posts SET post_content = replace(post_content, 'OLD_URL', 'NEW_URL');
UPDATE cp_postmeta SET meta_value = replace(meta_value,'OLD_URL', 'NEW_URL');
UPDATE cp_usermeta SET meta_value = replace(meta_value, 'OLD_URL', 'NEW_URL');
You can’t perform that action at this time.