Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am levymetal on github.
  • I am levymetal (https://keybase.io/levymetal) on keybase.
  • I have a public key whose fingerprint is 9B4B CA67 E4CB 4791 1894 BA66 A223 AEAA B714 64F3

To claim this, I am signing this object:

<?php
function my_wp_nav_menu( $theme_location = 'primary', $container = false, $items_wrap = "<div class='widget'><nav><ul>%3\$s</ul></nav></div>" ) {
$menu = wp_nav_menu(array(
'container' => $container,
'items_wrap' => $items_wrap,
'sub_menu' => true,
'theme_location' => $theme_location,
'echo' => false
));
@levymetal
levymetal / gist:03085a8656d8eb104deb
Last active November 1, 2022 02:42
Allow hyphenated usernames in Wordpress Multisite
<?php
/**
* Allow hypenated usernames
*
* @wp-hook wpmu_validate_user_signup
* @param array $result
* @return array
*/
function wpse_59760_allow_hyphenated_usernames( $result ) {
@levymetal
levymetal / application.js
Last active November 1, 2022 02:42
How to add quantity to product archives in WooCommerce (and keep ajax). From blog post: http://christianvarga.com/how-to-add-quantity-to-product-archives-in-woocommerce-and-keep-ajax
$('.input-text.qty', 'ul.products').on('input', function() {
$(this).closest('li').find('.add_to_cart_button').data('quantity', $(this).val());
});
@levymetal
levymetal / finder-resize.scpt
Last active November 1, 2022 02:41
Small applescript that makes the finder window really large then back to its original size to force the name column to resize fluidly. Used to fix a bug in OSX Mavericks whereby the name column is randomly wider than the window. Best to use a tool such as BTT to bind it to a keyboard shortcut, I used CMD + E.
tell application "Finder"
tell the front Finder window
-- get the current bounds of the finder window
set b to the bounds
-- create a really wide window
set the bounds to {item 1 of b, item 2 of b, 3000, item 4 of b}
-- set window back to its original size
set the bounds to b
end tell
end tell
@levymetal
levymetal / style.css
Created October 4, 2013 02:53
Show a wordpress submenu using only CSS
#sub-menu ul li {
display: none;
}
#sub-menu .menu > li > a {
display: none;
}
#sub-menu ul .current-menu-item,
#sub-menu ul .current-menu-item li,
@levymetal
levymetal / twitter_cache.php
Last active November 1, 2022 02:40
A simple php twitter cache, which can be used with the v1.1 api
<?php
error_reporting( 0 ); // don't let any php errors ruin the feed
$username = 'username';
$number_tweets = 4;
$feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={$username}&count={$number_tweets}&include_rts=1";
$cache_file = dirname(__FILE__).'/cache/'.'twitter-cache';
$modified = filemtime( $cache_file );
$now = time();
@levymetal
levymetal / get_bearer_token.php
Last active November 1, 2022 02:40
Obtain a bearer token from Twitter, which can use used to send signed requests without the need for an oauth library.
<?php
$ch = curl_init();
//set the endpoint url
curl_setopt($ch,CURLOPT_URL, 'https://api.twitter.com/oauth2/token');
// has to be a post
curl_setopt($ch,CURLOPT_POST, true);
$data = array();
$data['grant_type'] = "client_credentials";
@levymetal
levymetal / direct_parent.php
Last active November 27, 2023 04:17
Custom Wordpress function which uses a nav walker to display a list of child pages from a common parent, which can be called from either the parent page (displays children) or any of the child pages (displays siblings). Detailed instructions available on my blog post here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-…
<?php
wp_nav_menu( array(
'menu' => 'Menu Name',
'sub_menu' => true,
'direct_parent' => true
) );
@levymetal
levymetal / functions.php
Last active November 1, 2022 02:39
Similar to https://gist.github.com/levymetal/5064699, except this displays all sub-pages as well.
<?php
function my_custom_submenu() {
global $post;
$menu_items = wp_get_nav_menu_items('Menu');
$current_menu_id = 0;
// get current top level menu item id
foreach ( $menu_items as $item ) {