Detect if comments are allowed. - Roland - 19-03-2021
Hello,
I'm trying to turn on/off a bloc if comments are allowed or not (that is a different question if plugin is activate or not).
I tried this :
if (function_exists('printCommentForm')) { if (commentsAllowed() == true) { echo ''; echo 'Commentaires'; printCommentForm(); echo ''; } }
And this
if (function_exists('printCommentForm')) { if (comment_form_postcomment() == true) { echo ''; echo 'Commentaires'; printCommentForm(); echo ''; } }
Both make PHP fail. But I'm sure I'm close to solution if I had a correct understanding of the documentation : https://docs.zenphoto.org/1.5.x/function-comment_form_postcomment.html :) Any clue ? Thanks !
Detect if comments are allowed. - acrylian - 19-03-2021
comment_form_postcomment() is an internal function if processing comments is allowed:
https://docs.zenphoto.org/1.5.x/function-comment_form_postcomment.html
commentAllowed() requires a parameter what type of comments (which item type image, album, Zenpage page or news article) you refer to. the parameter refers howecer to the option name and not the plain item name (the doc does not tell this): https://docs.zenphoto.org/1.5.x/function-commentsAllowed.html
The best is actually to use the object model like:
if($obj->getCommentsAllowed()) { … }
$obj is here the object of an item type. For example an a standard theme image.php page you can use the global object $_zp_current_image->getCommentsAllowed() to check for this image. Basic overview about the object model:
https://www.zenphoto.org/news/zenphotos-object-model-framework/
Detect if comments are allowed. - Roland - 19-03-2021
Thanks acrylian !
|