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 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 / 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
View zip codes regex
"GB", "GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\d{1,4}"
"JE", "JE\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}"
"GG", "GY\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}"
"IM", "IM\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}"
"US", "\d{5}([ \-]\d{4})?"
"CA", "[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ ]?\d[ABCEGHJ-NPRSTV-Z]\d"
"DE", "\d{5}"
"JP", "\d{3}-\d{4}"
"FR", "\d{2}[ ]?\d{3}"
"AU", "\d{4}"
@isuke01
isuke01 / Functions.php
Last active May 28, 2018
Wordpress + GravityForm + VUE + React etc
View Functions.php
<?php
// Hook up the AJAX actions
add_action( 'wp_ajax_nopriv_gf_button_get_form', 'gf_button_ajax_get_form' );
add_action( 'wp_ajax_gf_button_get_form', 'gf_button_ajax_get_form' );
function gf_button_ajax_get_form(){
$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
/*
used in case if you need additional dynamic fields
@isuke01
isuke01 / support_for_svg_in_wp.php
Created Jul 23, 2018
Add SVG support to Wordpress Media library view + upload SVG
View support_for_svg_in_wp.php
<?php
/**
* Add support to SVG in WP media viewer
*/
function svg_meta_data_support($data, $id){
$attachment = get_post($id); // Filter makes sure that the post is an attachment
$mime_type = $attachment->post_mime_type; // The attachment mime_type
@isuke01
isuke01 / wp_navi_siblings.php
Created Jul 23, 2018
Wordpress navigation for siblings
View wp_navi_siblings.php
<?php
/*
* Based on https://gist.github.com/LL782/3551634
*/
function wp_links_siblings($postID = null){
if(!$postID){
global $post;
$postID = $post->ID;
}
$ancestors = get_post_ancestors( $postID );