Skip to content

Instantly share code, notes, and snippets.

View aolin480's full-sized avatar

Aaron Olin aolin480

View GitHub Profile
# This is a template .gitignore file for git-managed WordPress projects.
#
# Fact: you don't want WordPress core files, or your server-specific
# configuration files etc., in your project's repository. You just don't.
#
# Solution: stick this file up your repository root (which it assumes is
# also the WordPress root directory) and add exceptions for any plugins,
# themes, and other directories that should be under version control.
#
# See the comments below for more info on how to add exceptions for your
@aolin480
aolin480 / woocommerce-product-attribute-text-formatting.php
Last active September 27, 2015 19:06
Woocommerce Format product attributes by adding the "or" word for the last element in the array
<?php
// They could be pa_color, pa_flavor, pa_scent, it all depends how you named your product attribute
// all attributes are formated with the prefix pa_ *then your attrbute name*
// get the current product object to get the pa_size attributes, these might differ.
global $product;
// grab an array of product "size" attributes
$_sizes = wc_get_product_terms( $product->id, 'pa_size', array( 'fields' => 'names' ) );
@aolin480
aolin480 / owl-carousel-group-items-into-divs.php
Last active October 5, 2015 21:08
This can be used in anything, but I recently had the pleasure of working with Owl Carousel and a client needed to group 3 images in a owl carousel slide, this PROPERLY groups elements into a div without creating an orphan div group towards the end.
@aolin480
aolin480 / woocommerce-custom-cart-item-data.php
Created October 29, 2015 02:37 — forked from RadGH/woocommerce-custom-cart-item-data.php
Get and set custom cart item/product information prior to WooCommerce checkout, and carry those valus over to Order Item Metadata.
<?php
/*
Instructions:
1) Save data when adding to cart
When adding an item to your cart, use ld_woo_set_item_data. The best action for this to occur is
"woocommerce_add_to_cart". The first parameter for this action contains the "cart_item_key",
which is required for the function.
@aolin480
aolin480 / wp_export_post_by_id
Last active April 1, 2016 04:12
Export Wordpress Post by ID - by setting a temporary author, assigning it to the post, then reverting temp author
<?php
/*
NOT TOTALLY FUNCTIONAL - NOT TOTALLY FUNCTIONAL - NOT TOTALLY FUNCTIONAL - YOU MAY HAVE TO WORK IT INTO YOUR PROJECT DIFFERENTLY
*/
add_action('admin_init', function(){
if( isset( $_GET['di_export'] ) ) :
// post id = 177 // Collision Center
@aolin480
aolin480 / example-wp-list-table.php
Created March 8, 2017 20:41 — forked from paulund/example-wp-list-table.php
An example code of using the WP_List_Table class. With Pagination.
<?php
/*
* Plugin Name: Paulund WP List Table Example
* Description: An example of how to use the WP_List_Table class to display data in your WordPress Admin area
* Plugin URI: http://www.paulund.co.uk
* Author: Paul Underwood
* Author URI: http://www.paulund.co.uk
* Version: 1.0
* License: GPL2
*/
@aolin480
aolin480 / my-wordpress-permalink-api-endpoint.php
Last active June 16, 2017 22:05
Custom Wordpress endpoint permalink to do whatever you like
@aolin480
aolin480 / wpml_translate_create_translate_post_programatically
Created July 21, 2017 15:26
Creates an English post, and attaches a Russian translation to English post programatically. Thanks janekS!
function multilingual_post_creation(){
global $sitepress;
/**
/**
Creating first post in english
*/
//arguments for post creation
$def_args = array(
@aolin480
aolin480 / class-CustomEndpoint.php
Last active November 2, 2017 15:56
Custom Wordpress Query Page - Custom Permalinks
<?php
/**
* Custom Wordpress Query Page - Custom Permalinks
* @author Aaron Olin
*/
if (! class_exists('CustomEndpoint')) {
class CustomEndpoint {
protected static $_instance = null;
protected $templateFile;
@aolin480
aolin480 / epoch-to-wordpress-post-date.php
Created June 27, 2018 16:12
Convert EPOCH timestamp to Wordpress post_date
<?php
$timestamp = '1517341140000';
$post_arr = [
'post_title' => 'Meh title',
'post_type' => 'post', //could be any custom post type
'post_content' => 'Meh body',
'post_category' => ['meh category'],
'post_status' => 'publish'