Delete Actions
Hi,
I've built some custom magic based on Pods to implement some features I've needed. Now I'd like to prevent deleting particular pod items and I'd like to implement this using the 'pods_pre_drop_pod_item' action but I've encountered a problem: The action function doesn't receive the pod item as parameter.
I've modified the file so that the action is called with drop_pod_item's params.
The following patch based on Pods 1.11 contains my changes:
Index: wp-content/plugins/pods/classes/PodAPI.php
===================================================================
--- wp-content/plugins/pods/classes/PodAPI.php (revision 297)
+++ wp-content/plugins/pods/classes/PodAPI.php (revision )
@@ -951,7 +951,7 @@
$post_drop_helpers = str_replace(',', "','", $row['post_drop_helpers']);
// Plugin hook
- do_action('pods_pre_drop_pod_item');
+ do_action('pods_pre_drop_pod_item', $params);
// Pre-drop helpers
$result = pod_query("SELECT phpcode FROM @wp_pod_helpers WHERE name IN ('$pre_drop_helpers')");
@@ -965,7 +965,7 @@
pod_query("DELETE FROM @wp_pod_rel WHERE pod_id = $params->pod_id");
// Plugin hook
- do_action('pods_post_drop_pod_item');
+ do_action('pods_post_drop_pod_item', $params);
// Post-drop helpers
$result = pod_query("SELECT phpcode FROM @wp_pod_helpers WHERE name IN ('$post_drop_helpers')");
edited Aug 29 '11 at 3:34
3 Answers
Okay, I've added it to Pods 1.12-beta-7
The exact implementation ended up being:
// Get helper code
$result = pod_query("SELECT pre_drop_helpers, post_drop_helpers FROM @wp_pod_types WHERE id = $params->datatype_id");
$row = mysql_fetch_assoc($result);
$params->pre_drop_helpers = trim(str_replace(',', "','", $row['pre_drop_helpers']),', ');
$params->post_drop_helpers = trim(str_replace(',', "','", $row['post_drop_helpers']),', ');
// Plugin hook
do_action('pods_pre_drop_pod_item', $params);
// Pre-drop helpers
if (0 < strlen($params->pre_drop_helpers)) {
$result = pod_query("SELECT phpcode FROM @wp_pod_helpers WHERE name IN ('$params->pre_drop_helpers')");
while ($row = mysql_fetch_assoc($result)) {
if (!defined('PODS_DISABLE_EVAL') || PODS_DISABLE_EVAL)
eval('?>' . $row['phpcode']);
}
}
pod_query("DELETE FROM `@wp_pod_tbl_$params->datatype` WHERE id = $params->tbl_row_id LIMIT 1");
pod_query("UPDATE @wp_pod_rel SET sister_pod_id = NULL WHERE sister_pod_id = $params->pod_id");
pod_query("DELETE FROM @wp_pod WHERE id = $params->pod_id LIMIT 1");
pod_query("DELETE FROM @wp_pod_rel WHERE pod_id = $params->pod_id");
// Plugin hook
do_action('pods_post_drop_pod_item', $params);
// Post-drop helpers
if (0 < strlen($params->post_drop_helpers)) {
$result = pod_query("SELECT phpcode FROM @wp_pod_helpers WHERE name IN ('$params->post_drop_helpers')");
while ($row = mysql_fetch_assoc($result)) {
if (!defined('PODS_DISABLE_EVAL') || PODS_DISABLE_EVAL)
eval('?>' . $row['phpcode']);
}
}
edited Aug 30 '11 at 7:02
I didn't implement the initial actions / filters that we put in, otherwise all of them would be providing variables in them for reference. Sorry for the trouble, will add this to the Pods 1.12 beta.
edited Aug 30 '11 at 12:55
No problem, thanks for the fast implementation!


