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 / wp-get_id_by_slug
Created September 6, 2016 11:48 — forked from eddt/wp-get_id_by_slug
WordPress: Get page ID from slug
// Usage:
// get_id_by_slug('any-page-slug','any-post-type');
function get_id_by_slug($page_slug, $slug_page_type = 'page') {
$find_page = get_page_by_path($page_slug, OBJECT, $slug_page_type);
if ($find_page) {
return $find_page->ID;
} else {
return null;
}
@theperfectwill
theperfectwill / functions.php
Created September 22, 2016 21:27 — forked from lukecav/functions.php
Remove WooCommerce PayPal Powered by Braintree Payment Gateway PayPal button from the checkout and cart
// Remove PayPal button from checkout
add_filter( 'woocommerce_available_payment_gateways', '_wc_remove_braintree_pay_with_paypal' );
function _wc_remove_braintree_pay_with_paypal( $gateways ) {
unset( $gateways['paypalbraintree_paypal'] );
return $gateways;
}
// Remove PayPal button from cart
add_filter( 'wc_gateway_paypal_braintree_data', '_wc_remove_braintree_checkout_with_paypal' );
function _wc_remove_braintree_checkout_with_paypal( $data ) {
<?php
// Version CSS file in a theme
wp_enqueue_style( 'theme-styles', get_stylesheet_directory_uri() . '/style.css', array(), filemtime( get_stylesheet_directory() . '/style.css' ) );
// Version JS file in a theme
wp_enqueue_script( 'theme-scripts', get_stylesheet_directory_uri() . '/js/scripts.js', array(), filemtime( get_stylesheet_directory() . '/js/scripts.js' ) );
@theperfectwill
theperfectwill / class-kc-section-importer.php
Created November 4, 2016 14:14 — forked from sohan5005/class-kc-section-importer.php
A class that can can be used to have some default sections to King Composer for WordPress
<?php
if( class_exists( 'KC_Section_Importer' ) ) {
return;
}
class KC_Section_Importer {
/**
* Define the post_type & taxonomy to use
*/
<?php
$arg = 'status';
$valid_status_args = array('status', 'setting');
$valid_theme_args = array('theme_data', 'theme');
if (!in_array($arg, $valid_status_args)) {
echo 'Status Arg FAILED!!!'; echo PHP_EOL;
@theperfectwill
theperfectwill / .php
Created March 1, 2017 17:52
S.O. / Misc. How to determine if a function has an output.
<?php
// Create our return TRUE function
function Function_TRUE($arg = '') {
$arg = TRUE;
return $arg;
}
// Create our return FALSE function
@theperfectwill
theperfectwill / wysiwyg-meta-box.php
Created March 11, 2017 14:03 — forked from retgef/wysiwyg-meta-box.php
How to add a Wordpress WYSIWYG editor to a meta box.
<?php
define('WYSIWYG_META_BOX_ID', 'my-editor');
define('WYSIWYG_EDITOR_ID', 'myeditor'); //Important for CSS that this is different
define('WYSIWYG_META_KEY', 'extra-content');
add_action('admin_init', 'wysiwyg_register_meta_box');
function wysiwyg_register_meta_box(){
add_meta_box(WYSIWYG_META_BOX_ID, __('WYSIWYG Meta Box', 'wysiwyg'), 'wysiwyg_render_meta_box', 'post');
}
@theperfectwill
theperfectwill / disable-plugins-when-doing-local-dev.php
Created May 29, 2017 13:04 — forked from johnpbloch/disable-plugins-when-doing-local-dev.php
Disables specified WordPress plugins when doing local development
<?php
/*
Plugin Name: Disable plugins when doing local dev
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
@theperfectwill
theperfectwill / wp-migrate-db-pro-tweaks.php
Created September 22, 2017 19:07 — forked from anonymous/wp-migrate-db-pro-tweaks.php
King Composer Base64 Encoded CSS and WP Migrate DB Pro
<?php
/*
Plugin Name: WP Migrate DB Pro Tweaks
Plugin URI: http://github.com/deliciousbrains/wp-migrate-db-pro-tweaks
Description: Examples of using WP Migrate DB Pro's filters
Author: Delicious Brains
Version: 0.2
Author URI: http://deliciousbrains.com
*/
@theperfectwill
theperfectwill / compare.php
Created October 1, 2017 19:58 — forked from naholyr/compare.php
Extract namespace from a PHP file
<?php
// Works in every situations
function by_token ($src) {
$tokens = token_get_all($src);
$count = count($tokens);
$i = 0;
$namespace = '';
$namespace_ok = false;
while ($i < $count) {