Skip to content

Instantly share code, notes, and snippets.

View quasel's full-sized avatar
🙃
Don't worry be happy!

Bernhard quasel

🙃
Don't worry be happy!
View GitHub Profile
@quasel
quasel / index.php
Last active July 12, 2017 17:50 — forked from SGudbrandsson/index.php
Clone WP Script (Staging)
<?php
/**
*
* This script will copy your wordpress from public_html (or wherever)
* and place it in a staging folder.
* It will then clone the database, reconfigure the config file
* and replace URL's from the original URL to your staging URL.
* It will then make sure to NOT allow search engines to index the page.
*
* Use this script to clone your main wp in order to test maintenance work
@quasel
quasel / gist:9df42794030519d207b6
Last active August 29, 2015 14:27 — forked from basepack/gist:09fdbdd569020e2a0ff1
WooCommerce : add custom fields to product variations v2.0
<?php
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_save_product_variation', 'save_variable_fields', 10, 1 );
/**
<?php
//set up pods::find parameters to limit to 5 items
$param = array(
'limit' => 5,
);
//create pods object
$pods = pods('pod_name', $params );
//check that total values (given limit) returned is greater than zero
if ( $pods->total() > 0 ) {
@quasel
quasel / objects_arrays.md
Last active September 11, 2015 12:20 — forked from nikic/objects_arrays.md
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@quasel
quasel / custom_related_field.php
Last active September 15, 2015 08:59 — forked from Shelob9/custom_related_field.php
Get related posts from a Pods custom relationship field and show post title--as a link--and a custom field. For full explanation see: http://pods.io/tutorials/get-values-from-a-custom-relationship-field/
@quasel
quasel / register-post-type.php
Created September 23, 2015 19:10 — forked from justintadlock/register-post-type.php
Help file when registering post types.
<?php
/* Register custom post types on the 'init' hook. */
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 0.1.0
* @access public
@quasel
quasel / wp-api-custom-taxonomies.php
Created October 29, 2015 09:29 — forked from scottopolis/wp-api-custom-taxonomies.php
Add custom taxonomies to the WP-API
<?php
function ms_add_tax_to_api() {
$taxonomies = get_taxonomies( '', 'objects' );
foreach( $taxonomies as $taxonomy ) {
$taxonomy->show_in_rest = true;
}
}
add_action( 'init', 'ms_add_tax_to_api', 30 );
@quasel
quasel / gist:37c61aeb933bb8956745
Created November 7, 2015 09:21 — forked from BurlesonBrad/gist:de5b1ca4644d2b58a10f
Full Potential of Schema and WooCommerce
<div itemscope itemtype="http://schema.org/Product">
<span itemprop="name">Kenmore White 17" Microwave</span>
<img src="kenmore-microwave-17in.jpg" alt='Kenmore 17" Microwave' />
<div itemprop="aggregateRating"
itemscope itemtype="http://schema.org/AggregateRating">
Rated <span itemprop="ratingValue">3.5</span>/5
based on <span itemprop="reviewCount">11</span> customer reviews
</div>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<!--price is 1000, a number, with locale-specific thousands separator
@quasel
quasel / move-proceed-to-checkout.php
Created November 7, 2015 09:41 — forked from BurlesonBrad/move-proceed-to-checkout.php
Bump the Proceed to Checkout button right next to the Update Cart button (this looks AWESOME on mobile devices!!)
add_action( 'woocommerce_cart_actions', 'move_proceed_button' );
function move_proceed_button( $checkout ) {
echo '<a href="' . esc_url( WC()->cart->get_checkout_url() ) . '" class="checkout-button button alt wc-forward" >' . __( 'Proceed to Checkout', 'woocommerce' ) . '</a>';
}
@quasel
quasel / page-resources.php
Created December 3, 2015 03:23 — forked from nicdford/page-resources.php
A Pods Example on running a loop inside a loop.
<?php
/**
* Template Name: Library Resource List
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package asotin_county_library