Skip to content

Instantly share code, notes, and snippets.

View theperfectwill's full-sized avatar
💭
Coding... Working on The WPOnion Framework with Varun

The Perfect Will theperfectwill

💭
Coding... Working on The WPOnion Framework with Varun
View GitHub Profile
@theperfectwill
theperfectwill / register_post_type() - WordPress
Created March 21, 2022 08:24 — forked from jamestrevorlees/register_post_type() - WordPress
register_post_type() example - WordPress
// Create Post Type for the In Person Assessment Logging
function psgp_in_person_assessments_create_post_type() {
/* Set up the arguments for the post type. */
$args = array(
/**
* A short description of what your post type is. As far as I know, this isn't used anywhere
* in core WordPress. However, themes may choose to display this on post type archives.
@theperfectwill
theperfectwill / php-style-guide.md
Created January 16, 2022 14:55 — forked from heiswayi/php-style-guide.md
PHP style guide with coding standards and best practices.

PHP Style Guide

All rules and guidelines in this document apply to PHP files unless otherwise noted. References to PHP/HTML files can be interpreted as files that primarily contain HTML, but use PHP for templating purposes.

The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Most sections are broken up into two parts:

  1. Overview of all rules with a quick example
  2. Each rule called out with examples of do's and don'ts
@theperfectwill
theperfectwill / is-meta-box-registered.php
Created January 9, 2022 05:11 — forked from natebot/is-meta-box-registered.php
Test if a WordPress meta box has been registered.
<?php
/**
* Check if a meta box has been registered.
* Returns true if the supplied meta box id has been registered. false if not.
* Note that this does not check what page type
* @param String $meta_box_id An id for the meta box.
* @param String $post_type The post type the box is registered to (optional)
* @return mixed Returns boolean or a WP_Error if $wp_meta_boxes is not yet set.
*/
@theperfectwill
theperfectwill / wp-config.php
Created November 6, 2021 13:01 — forked from aydinjavadly/wp-config.php
WordPress - Enable WP_DEBUG only for specific IP address.
<?php
/**
* File: wp-config.php
*
* Enable WordPress debug only for your IP address
*
* Once you know your IP address you can edit your wp-config.php file and edit the WP_DEBUG constant and replace it with this function and your IP address.
*
* NOTE: If you re-boot your router and have a dynamic IP address you will need to update your IP address in wp-config.php
*/
@theperfectwill
theperfectwill / functions.php.patch
Created November 6, 2021 12:55 — forked from westonruter/functions.php.patch
WordPress patches needed to allow each theme to serve its own favicon; hack to disable wp_favicon_request()
Index: wp-content/themes/twentyten/functions.php
===================================================================
--- wp-content/themes/twentyten/functions.php (revision 16586)
+++ wp-content/themes/twentyten/functions.php (working copy)
@@ -39,6 +39,32 @@
*/
/**
+ * Allow each theme to serve their own favicon (e.g. for multisite WordPress)
+ */
@theperfectwill
theperfectwill / array-cascade.php
Created July 2, 2021 02:32 — forked from neilgee/array-cascade.php
Beaver Builder Global Settings Filter
<?php //<~ don't add me in
add_filter( 'fl_builder_register_settings_form', 'wb_builder_register_settings_form_short', 10, 2 );
/**
* Filter the Global Settings Options.
* Media breakpoints and form title have been changed.
*/
function wb_builder_register_settings_form_short( $form, $id ) {
if ( 'global' == $id ) {
@theperfectwill
theperfectwill / how-not-to-use-wp-filter.php
Created August 30, 2020 20:42 — forked from damiencarbery/how-not-to-use-wp-filter.php
Use $wp_filter global to view functions attached to actions and filters
<?php
/*
Plugin Name: wp_filter functions
Plugin URI: http://www.damiencarbery.com/2017/06/list-functions-attached-to-an-action/
Description: List functions attached to all actions and filters. DON'T DO IT!
Author: Damien Carbery
Version: 0.1
*/
add_action( 'wp_head', 'wp_filter_the_wrong_way' );
@theperfectwill
theperfectwill / handle_upload.md
Created July 13, 2020 21:10 — forked from rahilwazir/handle_upload.md
Change upload directory, async upload, handle upload in WordPress

Change upload directory

// Grabbed from edd plugin
function set_upload_dir() {

	// Override the year / month being based on the post publication date, if year/month organization is enabled
	if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
		// Generate the yearly and monthly dirs
 $time = current_time( 'mysql' );
@theperfectwill
theperfectwill / php-style-guide.md
Created May 14, 2020 18:36 — forked from ryansechrest/php-style-guide.md
PHP style guide with coding standards and best practices.

PHP Style Guide

All rules and guidelines in this document apply to PHP files unless otherwise noted. References to PHP/HTML files can be interpreted as files that primarily contain HTML, but use PHP for templating purposes.

The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Most sections are broken up into two parts:

  1. Overview of all rules with a quick example
  2. Each rule called out with examples of do's and don'ts
@theperfectwill
theperfectwill / 01-limit.php
Created April 8, 2020 20:16 — forked from davilera/01-limit.php
WordPress Image Size Limit
<?php
function nelio_max_image_size( $file ) {
$size = $file['size'];
$size = $size / 1024;
$type = $file['type'];
$is_image = strpos( $type, 'image' ) !== false;
$limit = 250;
$limit_output = '250kb';