Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
310 views
in Q2A Core by
edited by
I'd like to create a category which won't be visible for users during adding posts (except admins). Only admins could post in this category, but everyone could see this posts. I plan to use it for adding important notifications. Any possibilities to do that? Thanks in advance for any help.
by
I am working on something like this. Using admin-only categories to differentiate discussion type. If "Announcement", then all Answers are visually turned off or turned to comments.
If I succeed you will hear from me.

3 Answers

+1 vote
by
Can you try below plugin on test site and see if it meets your requirement.

https://github.com/ProThoughts/permission2categories

Let us know if it works.
by
edited by
This plugin is very powerful, and I suppose quite hackable, thanks for sharing. I will work on it.

But unless I am mistaken, the OP wants to restrict other users so that they are prevented from USING / POSTING in the category (and even better, they won't see the said category listed in the dropdown)

This plugin allows users to post in said category but prohibits them from VIEWING all posts with said category - (even their own).
+1 vote
by
edited by

It appears that there is a feature already present in Q2A. I hope it gets fleshed out in a future release - add a form in the admin area or something. There are wonders you can do with categories. I am turning different Posts to questions, blog posts, discussion etc. Each post type will behave and look drastically different from the other.

In v1.8 and previous version go to:

q2a/qa-include/app/format.php

Find:

function qa_set_up_category_field(&$qa_content, &$field, $fieldname, $navcategories, $categoryid, $allownone, $allownosub, $maxdepth = null, $excludecategoryid = null)

Alter to this:

function qa_set_up_category_field(&$qa_content, &$field, $fieldname, $navcategories, $categoryid, $allownone, $allownosub, $maxdepth = null, $excludecategoryid = null)
{
	$bigAdminsLevels = array(QA_USER_LEVEL_SUPER, QA_USER_LEVEL_ADMIN, QA_USER_LEVEL_MODERATOR);
	$currentUserLevel = qa_get_logged_in_level();

	//check if current user is SUPER ADMIN, ADMIN, MODERATOR
	if(!in_array($currentUserLevel, $bigAdminsLevels)){
	 $excludecategoryid = 1;
	 //see q2a/qa-content/qa-global.js and qa-ask.js
	 //can be refactored to take multiple values
	 //and administered via a forked ProThoughts plugin
	}

UPDATE

To allow multiple categories (by name, not id), you need a tiny alteration in global.js (anyone know how we can avoid touching core files???)

In format.php, use instead

$excludecategoryid = "adminCategory,announcement,notice";

In global.js,  find:

for (var i = 2; i < lines.length; i++) { //find this line

Alter to:

var catsExcluded = String(qa_cat_exclude).split(','); //added
 for (var i = 2; i < lines.length; i++) { //find this line
  var parts = lines[i].split('/');

  // if (String(qa_cat_exclude).length && (String(qa_cat_exclude) == parts[0])) //removed
  if (catsExcluded.indexOf(parts[1]) > -1) //added
   continue;

UPDATE

It so happens you can use your own global.js  via a plugin file. Just annotate your changes carefully so that you can update it when you please, with ease.

$qa_content['script_rel'][] = 'qa-plugin/myPlugin/qa-global.js?' . QA_VERSION;
by
I could not find a way to extend that function in a template, so that you don't touch the core file.
+1 vote
by

Try this:

https://github.com/kfuchs/permission2categories

and Sam55 post here:

https://github.com/kfuchs/permission2categories/issues/2

Sam55's code above solves the problem of users being able to see the category in the drop down box when posting.

by
Does the OP want to HIDE the posts in categories that users are not allowed to POST in?
by
No. Not as I understand it.

"Only admins could post in this category, but everyone could see this posts."
...