From 707b19dc35160983694b21e5e79dd7ce6d64dfee Mon Sep 17 00:00:00 2001 From: "M. Dent" Date: Sun, 3 Nov 2019 10:12:11 +0100 Subject: Add hook to comments_are_now_closed() --- doc/hook/comments_are_now_closed.bb | 11 +++++++++++ doc/hooklist.bb | 3 +++ include/items.php | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 doc/hook/comments_are_now_closed.bb diff --git a/doc/hook/comments_are_now_closed.bb b/doc/hook/comments_are_now_closed.bb new file mode 100644 index 000000000..4d3baa95a --- /dev/null +++ b/doc/hook/comments_are_now_closed.bb @@ -0,0 +1,11 @@ +[h3]comments_are_now_closed[/h3] + +Called when deciding whether or not commenting is closed for an item. + + +Hook data (array): + item => posted item + closed => 'unset' + + +To over-ride the default behaviour, change closed to true or false diff --git a/doc/hooklist.bb b/doc/hooklist.bb index e11bf1c6f..a923e7ae3 100644 --- a/doc/hooklist.bb +++ b/doc/hooklist.bb @@ -154,6 +154,9 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the [zrl=[baseurl]/help/hook/comment_buttons]comment_buttons[/zrl] Called when rendering the edit buttons for comments +[zrl=[baseurl]/help/hook/comments_are_now_closed]comments_are_now_closed[/zrl] + Called when deciding whether or not to present a comment box for a post + [zrl=[baseurl]/help/hook/connect_premium]connect_premium[/zrl] Called when connecting to a premium channel diff --git a/include/items.php b/include/items.php index 6786b8b05..917808ad5 100755 --- a/include/items.php +++ b/include/items.php @@ -206,6 +206,25 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) { } function comments_are_now_closed($item) { + + $x = [ + 'item' => $item, + 'closed' => 'unset' + ]; + + /** + * @hooks comments_are_now_closed + * Called to determine whether commenting should be closed + * * \e array \b item + * * \e boolean \b closed - return value + */ + + call_hooks('comments_are_now_closed', $x); + + if ($x['closed'] != 'unset') { + return $x['closed']; + } + if($item['comments_closed'] > NULL_DATE) { $d = datetime_convert(); if($d > $item['comments_closed']) -- cgit v1.2.3