Skip to content

Instantly share code, notes, and snippets.

ka2 ka215

Block or report user

Report or block ka215

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ka215
ka215 / wp-emergency.php
Created Jun 16, 2017
This is the tool for WordPress to manually deactivate any plugins and rollback to default theme.
View wp-emergency.php
<?php
/**
* WordPress Emergency Tools v1.0
*
* This is a tool to manually deactivate a theme and any plugins when you can not
* access the admin panel due to WordPress theme or plugins bug etc.
* Usage it please place this file in the same directory as "wp-config.php" and
* access it directly from the browser.
* Please delete this file promptly after use (If this file will remain, it will
* be a serious security hole for your service).
@ka215
ka215 / fn.date.js
Last active Mar 24, 2017
The function datetime formatter for JavaScript like date function of PHP
View fn.date.js
/**
* JavaScript datetime formatter like date() of PHP
* ------------------------
* Version: 1.0.0
* Coded by: Ka2 (https://ka2.org/)
* Lisenced: MIT
*/
function date( format, date ) {
// Date format like PHP
var baseDt = Object.prototype.toString.call( date ) === '[object Date]' ? date : new Date( date ),
@ka215
ka215 / table_relation_fields.php
Last active Aug 29, 2016
CDBT: How to display the input fields (select list, combobox) that is related the column of foreign tables by using filter hook.
View table_relation_fields.php
<?php
function my_shortcode_custom_forms( $elements_options, $shortcode_name, $table ){
if ( 'master_data' === $table ) {
global $cdbt;
$cities = $cdbt->get_data( 'cities' );
$_city_list = [];
$jobs = $cdbt->get_data( 'jobs' );
$_job_list = [];
foreach ( $elements_options as $_i => $_option ) {
$_default_value = $elements_options[$_i]['defaultValue'];
@ka215
ka215 / filter_after_user_search.php
Last active Jun 25, 2016
This example of filter hook is for rendering dynamically the shortcode by using that search value after searching at the frontend.
View filter_after_user_search.php
<?php
/**
* The markup content of frontend (as post content):
* ---
* <form method="get">
* <input type="search" name="search_keyword" value="">
* <button type="submit">Search</button>
* </form>
* [cdbt-view table="your_table_name" narrow_keyword="ID:0"]
* ---
@ka215
ka215 / enum_aggregate.php
Last active Jun 25, 2016
ユーザーごとにenum型の登録値を合計して、ショートコードに一覧化するフィルターフックおよび集計関数の例。 デモはこちら -> http://demo.ka2.org/narrow-by-sum/
View enum_aggregate.php
<?php
/**
* Function to aggregate the value of the enum type
*
* @param string $target_table [requied]
* @param string $userid_col [requied]
* @param string $enum_col [required]
* @param string $period [optional] It must be a target date string, ex."2016-06-23"
*/
function enum_aggregate( $target_table, $userid_col, $enum_col, $period=null ) {
@ka215
ka215 / filter_date_type_column.php
Created Jun 15, 2016
If you want to filter in each years at the datetime type column as like the "date" type, you will resolve by using this filter hooks. However, because some plugin core sources should be modified, it's not able to work correctly in the current version (2.1.32). In the next version 2.1.33, I'm going to support.
View filter_date_type_column.php
<?php
// Note: this code will be enabled since the CDBT plugin version 2.1.33.
function add_filtered_column_sql( $sql, $table_name, $sql_clauses ) {
$target_tables = [ 'your_table_name' ];
$filter_date_column = 'date_type_column'; // Column name that you want to filter by the filtering dropdown box
if ( in_array( $table_name, $target_tables ) && strpos( $sql_clauses[0], $filter_date_column ) !== false ) {
$select_clause = $sql_clauses[0] .',CAST(YEAR(`'. $filter_date_column .'`) AS CHAR) AS `year`'; // "year" is alias column for filtering
$_overwrite_sql = <<< SQL
SELECT %s
@ka215
ka215 / narrow-down-one-column.php
Created Jun 15, 2016
This example of filter hook is in which to narrow down the data by a plurality of conditions to the values stored in one column. This code should be inserted to as like "functions.php" in your theme.
View narrow-down-one-column.php
<?php
// In the variables of "$target_tables", "$narrow_column", "$narrow_keywords", you should be optimized by your environment and project.
function custom_filter_sql( $sql, $table_name, $sql_clauses ) {
$target_tables = [ 'your_table_name' ];
$narrow_column = 'specific_column_name';
$narrow_keywords = [ 'keyword1', 'keyword2', 'keyword3' ];
if ( in_array( $table_name, $target_tables ) ) {
if ( is_array( $sql_clauses[1] ) ) {
// Narrowing is find_data()
@ka215
ka215 / modify_datatime_format.php
Last active Jun 8, 2016
For Custom DataBase Tables plugin; this filter hook code is sample to modify the display format of any datetime column of the specified table. About the allowed the alias of datetime format, please refer: https://ka2.org/cdbt/v2/basic-info/plugin-options/general-setting/#datetime-formats
View modify_datatime_format.php
<?php
// You should be optimize the variables of "$target_table" and "$target_column" in proportion to your table structure.
function cdbt_custom_datetime_format( $columns, $shortcode_name, $table ) {
$target_table = 'your_table_name';
$target_column = 'datetime_column_name';
if ( $target_table === $table ) {
foreach ( $columns as $_i => $_column ) {
if ( $target_column === $_column['property'] ) {
$_custom_column = sprintf( 'convert_datetime(rowData["%s"], ["%s"])', $target_column, 'F j, Y' );
@ka215
ka215 / clickable_url_column.php
Created Jun 7, 2016
You should use this filter hook code for the Custom DataBase Tables if you want to be able to click the specific column value that stored the strings of url at the time of using shortcode. Also this filter is enable since plugin version 2.x.
View clickable_url_column.php
<?php
// Please insert this code to as like your theme's "functions.php".
// Note: you should be modified variable of "$target_table" and "$url_column" in this code.
function cdbt_custom_clickable_url( $columns, $shortcode_name, $table ) {
$target_table = 'string'; // Your table name that you want to filter.
$url_column = 'varchar'; // This column name should be stored the url strings, and column type is "varchar".
if ( $target_table === $table ) {
foreach ( $columns as $_i => $_column ) {
if ( $url_column === $_column['property'] ) {
@ka215
ka215 / file0.js
Created Jun 2, 2016
JavaScriptのすぐ使える7つのユーティリティ関数 ref: http://qiita.com/ka215/items/d059a78e29adef3978b5
View file0.js
/**
* Return as an object by parsing the query string of the current URL
*/
$.QueryString = (function(queries) {
if ('' === queries) { return {}; }
var results = {};
for (var i=0; i<queries.length; ++i) {
var param = queries[i].split('=');
if (param.length !== 2) { continue; }
results[param[0]] = decodeURIComponent(param[1].replace(/\+/g, ' '));
You can’t perform that action at this time.