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 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');
@johnalarcon
johnalarcon / functions.php
Last active Jan 30, 2019
Filter examples for the Username Protection plugin for ClassicPress. These code snips can be added to a functionality plugin or the functions.php file.
View functions.php
<?php
// Change text used for display names in feeds. Default set by plugin is your site's name.
add_filter('codepotent_username_protection_feeds', 'codepotent_feeds');
function codepotent_feeds($display_name) {
return $display_name;
}
// Change the REST API error message. Default set by plugin is "authentication required".
add_filter('codepotent_username_protection_rest_error', 'codepotent_rest_error');
@johnalarcon
johnalarcon / .htaccess
Last active Dec 29, 2018
Directives for the ClassicPress .htaccess file. These directives can be copied into your exisitng .htaccess file, but they are not intended to overwrite other directives that may already be present. Read the comment before each directive below, and you'll be fine!
View .htaccess
# CodePotent's official .htaccess directives to make your ClassicPress site ROCK!
# Prevent directory browsing.
Options -Indexes
# Enable rewrite engine - you may already have these 2 lines... don't duplicate, if so.
RewriteEngine On
RewriteBase /
# Force SSL connection to everything (URLs, images, scripts, styles, etc)
You can’t perform that action at this time.