Skip to content

Instantly share code, notes, and snippets.

@ka215
Created June 7, 2016 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ka215/42d7ea0ac94cdd893091c1545b0dc00f to your computer and use it in GitHub Desktop.
Save ka215/42d7ea0ac94cdd893091c1545b0dc00f to your computer and use it in GitHub Desktop.
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.
<?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'] ) {
$_custom_column = sprintf( 'rowData.%1$s != "" ? $("<a/>").attr("href",_.unescape(rowData.%1$s)).attr("target","_blank").text(_.unescape(rowData.%1$s)) : rowData.%1$s', $url_column );
$columns[$_i]['customColumnRenderer'] = $_custom_column;
}
}
}
return $columns;
}
add_filter( 'cdbt_shortcode_custom_columns', 'cdbt_custom_clickable_url', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment