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 / 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: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
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
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
/*
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