Skip to content

Instantly share code, notes, and snippets.

View kharissulistiyo's full-sized avatar
🏠
Working from home

Kharis Sulistiyono kharissulistiyo

🏠
Working from home
View GitHub Profile
@kharissulistiyo
kharissulistiyo / admin-redirect.php
Last active February 16, 2023 17:20
Admin Page Redirection After WordPress Theme Activated
/**
* WordPress snippet
* Admin page redirection
* Put this inside theme setup function
*/
global $pagenow;
if ( is_admin() && 'themes.php' == $pagenow && isset( $_GET['activated'] ) ) {
@kharissulistiyo
kharissulistiyo / parent-child-cpt.php
Last active March 16, 2024 19:12
Add Custom Post Type Parent-Child Relationship Like "Page" Post Type
/**
* Source: http://justintadlock.com/archives/2013/10/07/post-relationships-parent-to-child
* Improved by Kharis Sulistiono
* Improvements:
* - Add "Select Relation" option
* - Add else conditional when no post created.
*
* To make that code works, make sure your post type supports custom meta box by adding 'register_meta_box_cb'
*
* From the code above, the CPT has to able to call a metabox callback function 'my_add_meta_boxes':
@kharissulistiyo
kharissulistiyo / gist:e32e015b86269253159a
Last active August 29, 2015 14:01
WooCommerce: Enable Email Notification of New Order Received with Paypal Checkout.
/**
* Do this in get_paypal_args method of class-wc-gateway-paypal.php
*/
global $woocommerce;
$mailer = $woocommerce->mailer();
$email = $mailer->emails['WC_Email_New_Order'];
$send_mail = $email->trigger( $order_id );
@kharissulistiyo
kharissulistiyo / gist:146a6440b039b90cf8ef
Last active August 29, 2015 14:01
Synchronous vs Asynchronous
// Asynchronous
var shirt, pants, shoes;
var getItem = function (storeName, itemName) {
var store = goToStore(storeName);
var item = store.getItem(itemName);
console.log('I got my ' + itemName);
return item;
};
/* Samsung Galaxy S4 Landscape */
@media screen (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)
and (device-width: 1920px)
and (orientation: landscape) {
/* Your styles here */
}
/* Samsung Galaxy S4 Portrait */
@media screen (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)
and (device-width: 1080px)
@kharissulistiyo
kharissulistiyo / gist:2c487a49a9394c165091
Last active August 29, 2015 14:03
Teaching Media Requirements
This is taken from my lecturer's (Bu Listyaning) slide presentation of PPL 1 class a few days ago.
The requirements of developing teaching media are:
* Visible
* Interesting
* Simple
* Useful
* Accurate
* Legitimate
@kharissulistiyo
kharissulistiyo / wp_split_loop.php
Created February 1, 2015 11:42
Modify WordPress loop to split posts into groups of two
// Query post
$args = array(
'post_type' => 'post',
'posts_per_page' => 10
);
$posts = get_posts($args);
$count = 0;
$div_open = '<div class="every-two" style="background:#f7f7f7; padding: 5px; margin-bottom: 10px;">';
@kharissulistiyo
kharissulistiyo / class-wc-product-data-fields.php
Created April 22, 2015 00:46
Woocommerce Custom Product Data Fields: Update checkbox field to allow it to be checked by default. https://wordpress.org/plugins/woocommerce-custom-product-data-fields/
/**
* Update the checkbox field whith this one
*/
case 'checkbox':
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox';
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
$field['value'] = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
$field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes';
@kharissulistiyo
kharissulistiyo / your-field-init.php
Created April 22, 2015 00:49
Woocommerce Custom Product Data Fields: Field setting to allow checkbox to be checked by default. https://wordpress.org/plugins/woocommerce-custom-product-data-fields/
$custom_product_data_fields[] = array(
'id' => '_mycheckbox',
'type' => 'checkbox',
'label' => __('Checkbox', 'wc_cpdf'),
'description' => __('Field description.', 'wc_cpdf'),
'desc_tip' => true,
'checked' => true, // Allows the checkbox to be checked by default.
);
@kharissulistiyo
kharissulistiyo / cart.php
Created May 26, 2015 07:38
Add product named "XYZ" with qty "3" then in cart it should be 3 item "XYZ" with single quantity.
<?php
/**
* Cart Page
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {