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 / update-classicpress-urls.sql
Created January 30, 2019 05:48
SQL query to update URLs after moving a ClassicPress site.
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');
@johnalarcon
johnalarcon / functions.php
Created January 30, 2019 09:26
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.
<?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 / functions.php
Last active April 2, 2019 05:17
Filter examples for the Discourse Stats plugin for ClassicPress. These code snips can be added to a functionality plugin or the functions.php file.
<?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
Last active April 12, 2019 21:40
Filter examples for the Registration Honeypot plugin for ClassicPress. These code snips can be added to a functionality plugin or the functions.php file.
<?php
// Enable mail server ping during registration.
add_filter('codepotent_registration_honeypot_ping_mail_server', '__return_true');
@johnalarcon
johnalarcon / functions.php
Last active April 12, 2019 21:39
Filter examples for the Shortcodes Everywhere plugin for ClassicPress. These code snips can be added to a functionality plugin or the functions.php file.
<?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
Created July 14, 2019 12:57
Convert hexadecimal values to decimal values
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);
@johnalarcon
johnalarcon / functions.php
Created July 24, 2019 19:32
Add "Documents" to media library filter options
<?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 September 10, 2019 02:13
Retrieve specific fields from an attachment when only a value is known.
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 October 22, 2019 04:57
Shortcode to create a linked list of site policies.
/**
* 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