Skip to content

Instantly share code, notes, and snippets.

@isuke01
isuke01 / gist:a1da12833b74f2e0d3bd48351b9be475
Last active Oct 27, 2016
Wordpress custom post type custom sorting column on backend
View gist:a1da12833b74f2e0d3bd48351b9be475
/* Sorting custom columns */
// Add new column in view
// quiz_answer - post-type
add_filter('manage_quiz_answer_posts_columns', 'tankenbak_quiz_answer_table_head');
function tankenbak_quiz_answer_table_head( $defaults ) {
$defaults['answers_points'] = __('Points', 'tankenbak');
//$defaults['ticket_status'] = __('Status', 'tankenbak')
return $defaults;
View Create new user Wordpress by function
if ( isset( $_GET['isu'] ) ) {
add_action('init', 'add_user_v_12');
}
function add_user_v_12() {
$username = 'exampleUser';
$password = 'Password';
$email = 'email@example.com';
// Create the new user
View WP - get excerpt by ID
// BY simple filter
$excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', get_the_ID()));
@isuke01
isuke01 / extend-bages-status-backend.php
Last active May 31, 2017
WP - Assign to page separated template file and extend pages status texts
View extend-bages-status-backend.php
add_action( 'admin_head-edit.php', 'edit_post_change_title_in_list' );
function edit_post_change_title_in_list() {
add_filter( 'display_post_states', 'use_template_as_post_state', 100, 2);
}
function use_template_as_post_state( $post_states, $post ) {
$available_templates = get_page_templates($post);
$post_template_file = get_post_meta( $post->ID, '_wp_page_template', true );
ksort( $available_templates );
@isuke01
isuke01 / woo_out_of_stock.php
Created Oct 26, 2017
[WooCommerce, WordPress ]This snippets contain get_product_by_slug , and redirect from single product page to somewhere when product is out f stock.
View woo_out_of_stock.php
/**
* Retrieve a product given its slug.
*/
function get_product_by_slug($page_slug) {
global $wpdb;
$product = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s", $page_slug, 'product'));
if ( $product )
return wc_get_product($product);
return null;
@isuke01
isuke01 / JS_format_number.js
Last active Nov 20, 2017
JS format number
View JS_format_number.js
/**
* //https://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-dollars-currency-string-in-javascript#answer-14428340
* Number.prototype.format(n, x, s, c)
*
* @param integer n: length of decimal
* @param integer x: length of whole part
* @param mixed s: sections delimiter
* @param mixed c: decimal delimiter
*/
Number.prototype.format = function(n, x, s, c) {
@isuke01
isuke01 / WP_admin_js_notice.js
Last active Nov 20, 2017
WP_admin simple notice JS
View WP_admin_js_notice.js
/**
* admin_notice(desc, type, dismissable)
*
* @param string desc: descriotion text for notice
* @param string type: oneof [success, error, warning, info]
* @param bool dismissable: should be dismissable or dont
*/
function admin_notice(desc, type, dismissable) {
if (dismissable) {
dismissable = 'is-dismissible';
@isuke01
isuke01 / wordpress_add_plugin_setting_link.php
Created Nov 29, 2017
Wordpress - Add settings link in plugin list to your plugin
View wordpress_add_plugin_setting_link.php
@isuke01
isuke01 / Woo_update_prices.sql
Last active May 14, 2019
Woo incresce all prices by 0.16%
View Woo_update_prices.sql
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_regular_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_sale_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_regular_price_tmp' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_sale_price_tmp' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_price_tmp' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_min_variation_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_max_variation_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_min_va
@isuke01
isuke01 / custom-wp.ajax
Last active Nov 18, 2019
Custom WP ajax, capable of using SHORTINIT, and much faster than standard WP
View custom-wp.ajax
<?php
/*
If you use short init by passing argument shortinit.
You have base and a bit more wp components loaded, like get_meta, current user .. etc.
*/
if (!isset( $_POST['action']))
die('-1');
if ( isset( $_POST['shortinit']) ){
$type = trim($_POST['shortinit']);