Skip to content

Instantly share code, notes, and snippets.

@propertyhive
Created January 27, 2026 15:43
Show Gist options
  • Select an option

  • Save propertyhive/ceb0529bce2c68493377c68a626ac8b3 to your computer and use it in GitHub Desktop.

Select an option

Save propertyhive/ceb0529bce2c68493377c68a626ac8b3 to your computer and use it in GitHub Desktop.
add_filter('update_post_metadata', function ($check, $object_id, $meta_key, $meta_value, $prev_value) {
if ($meta_key !== 'fave_property_id') {
return $check;
}
// 1) Manual edits in wp-admin should always be allowed.
// We treat "manual" as the classic post edit save (not AJAX/REST).
$is_manual_admin_save =
is_admin()
&& !wp_doing_ajax()
&& !wp_is_json_request()
&& (
doing_action('save_post')
|| doing_action('post_updated')
|| (isset($_POST['action']) && $_POST['action'] === 'editpost')
);
if ($is_manual_admin_save) {
return $check; // don't interfere with manual changes
}
// 2) Only apply "write once" rule if call originates from the plugin.
$plugin_path_fragment = DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'houzez-property-feed' . DIRECTORY_SEPARATOR;
$from_feed_plugin = false;
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 25) as $frame) {
if (!empty($frame['file']) && strpos($frame['file'], $plugin_path_fragment) !== false) {
$from_feed_plugin = true;
break;
}
}
if (!$from_feed_plugin) {
return $check; // not from that plugin => allow
}
// 3) From the plugin: only update if meta does not exist yet.
if (metadata_exists('post', $object_id, $meta_key)) {
return false; // block overwrite, keep existing value
}
return $check; // allow first write
}, 10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment