I am trying to add an action hook after the wpdatatables_after_save_table action so that I can flush the LiteSpeed cache so that pages that use wpDataTable will update. However, it doesn’t seem to be working. I have the following code where I have tried hooking up to two different actions… the save table action and also the save settings action. The save settings action properly clears the LS Cache, but when I make a change to one of my tables and hit “save changes” on the table, the LS Cache does not clear.
// this DOES NOT work when I edit a table - but I want to be able to clear cache after table edits add_action('wpdatatables_after_save_table', 'flush_litespeed_cache_on_table_save');
// this DOES work when I update wpDT settings add_action('wpdatatables_after_save_settings', 'flush_litespeed_cache_on_table_save');
function flush_litespeed_cache_on_table_save( $tableId ) { do_action( 'litespeed_purge_all' ); }
Is there something I’m doing wrong to hook up to the wpdatatables_after_save_table action, or possibly it is broken?
The page I need help with: [log in to see the link]
add_action( 'wpdatatables_after_save_table', 'after_save_table' ); function after_save_table( $tableId ) { // Check for specific table Id if ( $tableId == 1) { // Your code } }add_action( 'wpdatatables_after_save_table', 'after_save_table' );
Just add the correct table ID and test it out.
This action is executed after wpDataTables saves the table data (after the user presses “Save Changes” in the back-end table settings page).
Hi @aleksandartms, thanks. I don’t see the difference in your code and mine, other than you have add_action() before and after the defined callback. Is this required?
I don’t expect there’s any impact to filter on the specific table ID, at least not for testing to make sure it works. Have you tested your approach on your end with the latest version to ensure it is still working as expected?
This action is executed after wpDataTables saves the table data (after the user presses “Save Changes” in the back-end table settings page).
@aleksandartms but unfortunately it doesn’t appear to execute. I did a further test by adding logging to see if which parts of my code (if any) were even getting hit. The code that is adding these actions gets hit with every page load (see #1 error log message), but the code inside the action handler never gets hit (see #2 error log message). This seems like a bug to me, that the plugin is not invoking the action hook after saving the changes to a table.
function flush_litespeed_cache_on_table_save( $tableId ) { error_log( '#2 message logged when callback is made') // <-- this never gets called do_action( 'litespeed_purge_all' ); }
error_log( '#1 message on snippet loading') // <-- this gets called every page load
TL;DR – There’s a bug, I located the issue in the code. Can you engage development team on a fix? The remainder of this explains the problem.
@aleksandartms We must either be running different versions, or not testing the same flow. I’m using version 6.3.3.8 that I downloaded from https://ww.wp.xz.cn/plugins/wpdatatables/. I looked at the code and there appears to be a bug for the flow that I’m expecting should trigger this hook.
Reproduce steps:
I click on wpDataTables > wpDataTables > [TableName] to open the table edit page
make a change to the table content within the “Edit Data” tab
click “Save Settings”
Expected behavior: The ‘wpdatatables_after_save_table’ hook should be called.
Actual Behavior: The ‘wpdatatables_after_save_table’ hook is NOT called.
The Bug: I looked in the plugin code and the ‘wpdatatables_after_save_table’ action is only emitted within the WDTConfigController::saveTableToDB() function. However, as far as I can tell… clicking “Save Settings” after editing the table content does NOT reach this function.
The “Save Settings” flow:
When editing a table and clicking “Save Settings”, an AJAX call is made to the admin action: ‘wpdatatables_save_simple_table_data’
Within the controllers/wdt.admin_ajax_actions.php file, there’s a hook for this action that calls wdtSaveDataSimpleTable().
Inside wdtSaveDataSimpleTable() function, there are calls to WDTConfigController::saveRowData($rowData, $tableID), but again I do not see any calls to WDTConfigController::saveTableToDB() which would trigger the wpdatatables_after_save_table action hook.
To test my theory, I added my own do_action('wpdatatables_after_save_table', $tableID) within the wdtSaveDataSimpleTable() function after all the saveRowData() calls, and BAM!! It worked. So I think this code must have changed recently and the ‘wpdatatables_after_save_table’ hook is no longer called in the 6.3.3.8 code base.
Can you please fix this? Do I need to open a bug report somewhere else?
Hi again, and thank you for the extra details. We didn’t realize you were working with Simple tables – that changes the situation..
At the moment, the wpdatatables_after_save_table hook isn’t triggered when saving Simple tables; it only works for linked tables. Our developers have logged this and confirmed that the hook will be added for Simple tables in the next update.
While I can’t give you a precise ETA, the team has confirmed it will be included in the upcoming release.
Gladly, but I can’t promise with absolute certainty. We don’t have any automated reminders for this, so I’ll need to rely on my memory.
Apologies in advance if I happen to forget to notify you. In the meantime, please keep an eye on your Plugins page – WordPress will show the update once it’s available (and if you’ve enabled auto-updates, it will install automatically).
Kind regard
Viewing 8 replies - 1 through 8 (of 8 total)
The topic ‘wpdatatables_after_save_table action hook not working?’ is closed to new replies.