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 / alar-minimum-php.php
Last active May 6, 2018
A simple object-oriented approach to ensure that a minimum version of PHP is installed before allowing installation of your WordPress plugin. This code should live in your plugin's root file; your actual (PHP7) plugin code is included at line 73.
View alar-minimum-php.php
<?php
/**
* Plugin Name: My Plugin Name
* Description: Create a robust admin settings page for your WordPress plugin in minutes! More than 20 HTML5 input types are supported, including clickable labels, input hints, and even beautiful tooltips. Simply define your needed sections and inputs – everything else is automatic. Your settings are displayed with tabbed navigation that looks exactly like WordPress built it – no wonky styles, no silly cartoon characters, no in-your-face nags. The CSS totals less than 50 lines and the Javascript is less 25. This is built entirely inline with WordPress core standards and has no outside dependencies. The interface loads super-fast – you can even navigate across sections/tabs, changing settings along the way, and then click “Save” just once to save all the settings at once. Because I love you. But, you know, just as friends.
* Version: 1.0.0
* Author: John Alarcon
* Author URI: https://github.com/johnalarcon/my-plugin-name
* Text Domain: my-plugin-name
* Domain Pat
@johnalarcon
johnalarcon / exclude-filetypes.php
Created Jun 6, 2018
A simple snip for removing MS document support from the WordPress Media Uploader. Created after a brief discussion during our 6/5/18 meetup.
View exclude-filetypes.php
/**
* Remove support for files of type doc, docx, docm, dotx, and dotm from the
* WordPress Media Uploader. Place this code into your theme's functions.php file.
*/
add_filter('upload_mimes', 'jalarcon_remove_filetypes', 1, 1);
function jalarcon_remove_filetypes($filetypes) {
unset($filetypes['doc']);
unset($filetypes['docx']);
unset($filetypes['docm']);
@johnalarcon
johnalarcon / code-comment-counter.php
Last active Sep 1, 2018
This bit of code takes a relative path, scans that directory, then determines how many lines of code and how many lines of comments are within.
View code-comment-counter.php
<?php
$dir = 'C:/xampp/htdocs/wordpress/wp-content/plugins/my-plugin-name/';
echo get_code_size($dir);
function get_code_size($dir) {
// The directory to scan; include trailing slash.
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST);
@johnalarcon
johnalarcon / functions.php
Last active Nov 1, 2018
Change core WP post item labels
View functions.php
add_action('admin_menu', 'change_admin_menu_for_editors');
function change_admin_menu_for_editors() {
global $menu;
global $submenu;
// Update labels for Posts menu items.
$menu[5][0] = __('Blog Articles', 'my-text-domain');
$submenu['edit.php'][5][0] = __('All Articles', 'my-text-domain');
$submenu['edit.php'][10][0] = __('Add New Article', 'my-text-domain');
$submenu['edit.php'][15][0] = __('Blog Categories', 'my-text-domain');
}
@johnalarcon
johnalarcon / constants.php
Last active Nov 24, 2018
Path/URL constants for use in WordPress/ClassicPress plugins to speed IDE autocompletion.
View constants.php
<?php
// Declare the namespace.
namespace MYPLUGINNAME;
// Prevent direct access.
if (!defined('ABSPATH')) {
die();
}
@johnalarcon
johnalarcon / functions.php
Last active Dec 28, 2018
Remove the WP 5.0 update nag
View functions.php
<?php
// Add the following to your functions.php file to hide the WP 5.0 update nag.
add_action('after_setup_theme', 'codepotent_remove_wp50_update_nag');
function codepotent_remove_wp50_update_nag() {
add_filter('pre_option_update_core','__return_null');
add_filter('pre_site_transient_update_core','__return_null');
}
@johnalarcon
johnalarcon / autoloader.php
Created Dec 18, 2018
Autoloader for ClassicPress/WordPress Plugin Classes
View autoloader.php
<?php
/**
* Autoload classes
*
* Autoloaded classes? Yes. Support for namespaces, too? Of course! It helps
* to have a good understanding of how this autoloader works, so you can use
* it to your benefit, and not as a reason to pull out your hair. ;) Classes
* do not have to be namespaced, but it is recommended they are, for maximum
* plays-well-with-others...ness. Let's start with the super-basics...
@johnalarcon
johnalarcon / functions.php
Last active Jan 7, 2019
Prevent username enumeration via WordPress / ClassicPress REST API.
View functions.php
/**
* Prevent username enumeration via REST API
*
* This function allows normal (anonymous) access to the REST API, but makes
* sure that site usernames are not exposed through it. This code can be added
* to your theme's functions.php file.
*
* Note: there has been a report that this code may interfere with JetPack's operation.
* See https://twitter.com/PrysmcatBooks/status/1082022370817261568
*/
@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)
@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');
You can’t perform that action at this time.