Skip to content

Instantly share code, notes, and snippets.

View ka215's full-sized avatar

ka2 ka215

View GitHub Profile
@ka215
ka215 / non-narrow-down.php
Last active June 7, 2016 05:15
「Custom DataBase Tables」のショートコード[cdbt-edit]および[cdbt-view]でログインしているuserIDのデータのみを表示させる(ただし管理者は全データにアクセス可能)を実現するためのフィルターフック。
<?php
// As a prerequisite, there are stored each user ID to the "user_id" column (as numric type) in the "your_table_name" as target table.
// (対象テーブル「your_table_name」には「user_id」カラム(数値型)にユーザーIDが格納されているという前提)
function custom_filter_get_data_sql( $sql, $table_name, $sql_clauses ) {
if ( ! is_admin() && "your_table_name" === $table_name ) {
$_current_user_id = 0; // For guest user
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$_current_user_id = $current_user->ID;