Last active
April 5, 2022 07:03
-
-
Save tnchuntic/4b1d6e33746847dc583d21eafd6e6dbb to your computer and use it in GitHub Desktop.
tablepress data filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ----------------------------------------------------------------------------- | |
* | |
* TablePress Filter Hook | |
* | |
* ----------------------------------------------------------------------------- | |
*/ | |
/** | |
* Filter the table after processing the table visibility information. | |
* | |
* @since 1.0.0 | |
* | |
* @param array $table The processed table. | |
* @param array $orig_table The unprocessed table. | |
* @param array $render_options The render options for the table. | |
*/ | |
function tc_filter_tablepress_data($table, $orig_table, $render_options) { | |
// bail early | |
if (strpos($render_options['datatables_custom_commands'], 'autolink_to') === false) | |
return $table; | |
// get the id from the string | |
$id = str_replace('autolink_to_', '', $render_options['datatables_custom_commands']); | |
// add link to cell content | |
foreach ($table['data'] as $row_idx => $row) { | |
if ($row_idx == 0) | |
continue; | |
foreach ($row as $col_idx => $col) { | |
if (empty($col) || htmlentities($col) == ' ') | |
continue; | |
$table['data'][$row_idx][$col_idx] = '<a href="' . get_permalink($id) . '">' . $col . '</a>'; | |
} | |
} | |
return $table; | |
} | |
add_filter('tablepress_table_render_data', 'tc_filter_tablepress_data', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment