Skip to content

Instantly share code, notes, and snippets.

View kucrut's full-sized avatar

Dzikri Aziz kucrut

View GitHub Profile
@kucrut
kucrut / bridge-walker-nav-menu.php
Last active September 19, 2022 15:38
WordPress Nav Menu walker that returns menu items as multidimensional array (items will children)
<?php
/**
* Nav menu walker
*/
class Bridge_Walker_Nav_Menu extends Walker_Nav_Menu {
/**
* Prepare item
*
@kucrut
kucrut / nav-menu-item-custom-fields.php
Created September 29, 2012 15:39 — forked from westonruter/nav-menu-item-custom-fields.php
Proof of concept for how to add new fields to nav_menu_item posts in the WordPress menu editor.
<?php
/**
* Proof of concept for how to add new fields to nav_menu_item posts in the WordPress menu editor.
* @author Weston Ruter (@westonruter), X-Team
*/
add_action( 'init', array( 'XTeam_Nav_Menu_Item_Custom_Fields', 'setup' ) );
class XTeam_Nav_Menu_Item_Custom_Fields {
static $options = array(
<?php
/**
* Menu item custom fields example
*
* Copy this file into your wp-content/mu-plugins directory.
*
* @package Menu_Item_Custom_Fields
* @version 0.1.0
* @author Dzikri Aziz <kvcrvt@gmail.com>
*
<?php
/**
* A helper class to implement arbitrary content at arbitrary URLs without a supporting post or page.
* Inherit from this class and implement the render_page method
*
* @author: Tom J Nowell ww.tomjn.com
* @License: GPL 2+
*/
abstract class Tomjn_Custom_Page {
@kucrut
kucrut / disable-plugins-when-doing-local-dev.php
Created October 14, 2012 14:06 — forked from markjaquith/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/
*/
<?php
/*
Plugin Name: Soliloquy Demo
Plugin URI: http://soliloquywp.com/
Description: Creates demo user and manages roles so Soliloquy can have a live demo.
Author: Thomas Griffin
Author URI: http://thomasgriffinmedia.com/
Version: 1.0.0
License: GNU General Public License v2.0 or later
License URI: http://www.opensource.org/licenses/gpl-license.php
@kucrut
kucrut / gutenberg-page-only.php
Last active February 20, 2018 02:23
Gutenberg only for pages
<?php
add_filter( 'gutenberg_can_edit_post_type', function ( $can_edit, $post_type ) {
$can_edit = $post_type === 'page';
return $can_edit;
}, 99, 2 );
<?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/
*/
<?php
/*
Usage:
$frag = new CWS_Fragment_Cache( 'unique-key', 3600 ); // Second param is TTL
if ( !$frag->output() ) { // NOTE, testing for a return of false
functions_that_do_stuff_live();
these_should_echo();
// IMPORTANT
$frag->store();
// YOU CANNOT FORGET THIS. If you do, the site will break.
<?php
/**
* This little class records how long it takes each WordPress action or filter
* takes to execute which gives a good indicator of what hooks are being slow.
* You can then debug those hooks to see what hooked functions are causing problems.
*
* This class does NOT time the core WordPress code that is being run between hooks.
* You could use similar code to this that doesn't have an end processor to do that.
*