Skip to content

Instantly share code, notes, and snippets.

View sutandang's full-sized avatar

eringga sutandang

  • indonesia
  • yogyakarta , indonesia
View GitHub Profile
@sutandang
sutandang / add front end menu , programitically
Created June 6, 2017 16:04
add front end menu , programitically
function new_nav_menu_items($items) {
$homelink = '<li class="home"><a href="' . home_url( '/solutions' ) . '">' . __('Solutions') . '</a></li>';
$items = $homelink . $items;
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
@sutandang
sutandang / default page woocommerce
Last active June 6, 2017 16:13
how to create default page woocommerce
function azweb_marketplace_wc_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
global $wpdb;
$option_value = get_option( $option );
if ( $option_value > 0 ) {
$page_object = get_post( $option_value );
if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
return $page_object->ID;
@sutandang
sutandang / Basic PSR 4 autoloader
Last active June 6, 2017 16:16
Basic PSR 4 autoloader
<?php
// Inside MyApp/ create composer.json with the below contents
{
"require": {
},
"autoload": {
"psr-4": {
"MyApp\\": ["src/", "tests/"]
}
}
@sutandang
sutandang / Filter Wordpress media by user
Created June 6, 2017 16:17
Filter Wordpress media by user
add_action('pre_get_posts', 'um_filter_media_files');
add_filter('wp_count_attachments', 'um_recount_attachments');
function um_recount_attachments($counts_in){
global $wpdb;
global $current_user;
$and = wp_post_mime_type_where(''); // Default mime type // AND post_author = {$current_user->ID}
add_action( 'woocommerce_product_after_variable_attributes','variation_settings_fields', 10, 3 );
// Save Variation Settings
add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
/**
* Create new fields for variations
*
*/
function variation_settings_fields( $loop, $variation_data, $variation ) {
// Text Field
woocommerce_wp_text_input(
@sutandang
sutandang / .gitignore
Created August 27, 2018 03:03 — forked from salcode/.gitignore
See https://salferrarello.com/wordpress-gitignore/ for the latest version of my WordPress .gitignore file
# -----------------------------------------------------------------
# .gitignore for WordPress
# Bare Minimum Git
# http://ironco.de/bare-minimum-git/
# ver 20150227
#
# This file is tailored for a WordPress project
# using the default directory structure
#
# This file specifies intentionally untracked files to ignore
# remove specific file from git cache
git rm --cached filename
# remove all files from git cache
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@sutandang
sutandang / remote_url.md
Created August 27, 2018 03:27 — forked from hofnerb/remote_url.md
git remote set-url

Review and Change Remote URL

git remote -v
# View existing remotes

git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL

git remote -v
@sutandang
sutandang / Undo Changes
Created August 27, 2018 03:53 — forked from warolv/Undo Changes
Undo Changes
git reset --soft HEAD^ -> undo last commit and save changes
git reset --hard HEAD~1 -> undo last commit and remove changes
git reset --hard HEAD~2 -> undo 2 last commits and remove changes
git revert commit-hash -> create new commit which reverts last commit
git checkout . -> remove all uncommitted changes
git checkout filename -> undo changes in specific file
git clear -df -> remove all untracked files
git rm filename -> remove file from index, after your did git add filename
git commit --amend -> change message of last commit
@sutandang
sutandang / wp-config.php
Created September 5, 2018 07:06
Set WordPress site URL in the config file instead of the database
<?php
// WordPress stores the site URL in the database by default (which I have never
// understood), and it's a pain to have to type out the UPDATE SQL or search in
// phpMyAdmin to change it. This is a simple way to put the URL into
// wp-config.php instead.
// Note that you will still need to update any URLs that appear in the content,
// especially when you copy a database from a development site to production:
// https://gist.github.com/davejamesmiller/a8733a3fbb17e0ff0fb5