Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.2k views
in Q2A Core by
SOS

2 Answers

0 votes
by

The question is a bit unclear but it should be something like: "Can pending approval posts be edited before approving them?". The answer is: they can not. You have to first approve them and then edit then.

Partially discussed here: https://github.com/q2a/question2answer/issues/123

by
Sorry @pupi1985 this time you are wrong, or maybe you don't know this, there is a plugin "Edit and Moderate " by @jatin.soni on q2amarket.com which helps you edit posts before you approve them.
I think this plugin and help you @SAJ.
by
I answer from a core's perspective. But I have to say your comment is useful, though. I will extend it by saying that those kind of plugins that operate on posts that way ("breaking" the rules imposed by the core, which are there for a reason) might result in unpredictable outcome (e.g: is an edit event fired after that? If it is not, how will the post be indexed?).

I also took a quick a look at the plugin and noticed this: https://github.com/q2amarket/q2am-edit-and-moderate/blob/master/qa-plugin.php#L37 which is a plugin override for the q2a core version available on Sep 25, 2013. The plugin replaces a whole function of that core's version with its own version. It's been over a year now and that function could have changed. So the result of using that plugin today is indeed unpredictable without taking a detailed look at the code and performing any necessary change.

Having said that, if you know what you're doing, of course, you'll be fine. If you don't, add the request to the huge 1.7 request list (which I guess will be used as a wishlist for 1.8) list and hope people is interested in it. In the meanwhile... approve and edit :)
by
Definitely if this functionality is added in core then that would be great but for now this plugin can solve the problem till 1.8 version comes out (which I don't think will be release anytime soon).
Secondly your knowledge is way ahead of mine is in respect to core so I am in no mood to challenge you for the technical working of the plugin the core. All I know is, whatever you suggest will be good :-)
by
Of course, the safest thing would be not to use any plugin, the same way if you don't want to get a virus in your computer then just don't connect it to Internet :D

Probably, a better approach here would be to ask jatin to update the plugin readme file with the exact q2a versions supported. He might need to slightly adapt the function or maybe not.
by
@pupi1985,

I agree and also not in favor of overriding core function but when system doesn't have any hook or rock solid function overriding system (such as WordPress) I found this is the best way to make it happen what I was looking for.

Q2A allows to override the function. Also there is nothing wrong in overriding function, if you update it as the function update (unfortunately, I am unable to be on time due to busy schedule). So, I don't see anything wrong with it.

The update process is not only limits to the override function but everything including themes, plugins and any custom works once/if any used function has been updated in the core system.

I would appreciate if you can share the hook or idea to achieve this with different approach where function overriding can be avoided.

Lastly, I had to wipe up my machine and just finished setting-up my Linux environment and will start to pick the issue and updates one by one and will update this soon.
by
D'oh... I get so stressed when I have to install and configure a new OS! I feel I'm not finishing ever!

This is the issue with the plugin override. Of course, they're more dangerous than events as they are operating directly with data that the core uses for its own. This is different from the case of events in which data is sent to plugins and they can do whatever they want with that data. So there is a risk when using even a silly override: suppose you want to override a function that returns an array with valid values and you want to allow an extra valid value to the array. So you just call the parent function (the one you're overriding), then add the element in your overriden function and then return the array. This will work flawlessly... but what if the core, in a minor update, modifies the returned value so that it can also return a null value? Then that could break your code or worse: adding an element to a null $arr variable in this way $arr['new'] = 'val' would create the array and assign that element... so you'd be changing the data the core uses to make decisions and hence, the core's logic.

So there is a risk in a simple plugin override that calls a parent method and adds a single element to an array. Now, the override of this plugin is not calling the parent which, in practice, is even worse. This is because, in case of an update, the core's function could change. And not only change the result value but any part of it, for example, an event could be generated, an email could be sent, and IF statement could be added to split the logic of the function, etc. So any change that the core performs to that function won't be executed because the plugin override is replacing the whole function instead of first calling the core's version and then performing the plugin's custom logic. So when you replace a whole function there is more risk when upgrading.

In both cases, but particularly on the second one, it is important to keep track of the changes the core performs to that function so that a developer can compare the override with the new core's function. If they are have not change, it is very likely that the plugin override would still work. If they have changed then the override, in the first scenario, should be checked to see if it needs changes or not. In the second scenario, in which the function is fully replaced, the function must be changed.

I went ahead with this and took an actual look at the function, then performed a diff with the current 1.7-beta-2 versions. Luckily, the diff only displayed one line with the !$rules['queued'] removed. It is possible to go for the first scenario in which you call the parent in this case. Just call the parent in the override, then get the $rules array, focus only on the $rules['editbutton'] and modify it in a similar way as you did in the current override and then just return the $rules array again. That is much safer as, if a new rule is added in 1.7.1 this solution won't break while the one currently implemented would as the rule would be omitted.

Having said that, IMO, the most important issue here, is that the plugin is changing the core's logic. Other parts of the core might depend on that rule or make assumptions based on it and now it is different from what the core expects. That might bring trouble to the core itself and to plugins that also depend or make assumptions on data that is derived from that function.

Anyway, due to the nature of the requirement, I don't think this could be solved in a core-safe and user-friendly way (e.g.: using events) :/
by
Regarding the original question: I agree it's a good idea to be able to edit posts before approving them, so it's hopefully something that will be added in future.

Regarding function overrides: pupi1985 is correct that you should call through to the parent function instead of copy-pasting an entire function (especially such a huge function like qa_page_q_post_rules!) See http://www.question2answer.org/overrides.php

In almost every single circumstance you should be calling through to the base/parent function, it's almost never necessary to completely replace a function. As pupi1985 says you can call through to the base function then edit one of the variables and return as normal.

As an example, I recently noticed an instance in the new Snow theme where an overridden function could be replaced by one small change and a call-through to the parent function: https://github.com/q2a/question2answer/commit/b4844889ed342ccb0e1f84f0803b7ddc4a6d5e42
by
Here's an example for your plugin:

function qa_page_q_post_rules($post, $parentpost=null, $siblingposts=null, $childposts=null)
{
    $rules = qa_page_q_post_rules_base($post, $parentpost, $siblingposts, $childposts);

    $rules['editbutton'] = (!$post['hidden']) && (!$rules['closed']) &&
        ($rules['isbyuser'] || (($permiterror_edit!='level') && ($permiterror_edit!='approve')));

    return $rules;
}
by
I agree with both of you and @scott, thanks for the snippet.

I admit my mistake, I have done junk code in hurry. This is just because, I wanted to make something quick in few hours. So quickly dig and created. But no excuse, mistake is mistake and again admit.

However, regarding overriding function. What I believe is once system allow to do  things than there is nothing wrong to do, if you do it in correct way (I did a mistake) and we should not bound Devs to use it.

For example WordPress ( I use always WP as an reference just because most of the people aware of it, not comparing Q2A to WP)

It has great system to override function using add_action() and add_filter() which allows to override core function within the limits so use won't be able to override entire function but just can manipulate the result. But what if they say to Developers, hey you should not override the core function!

Uhh! now in this case, there will be a big question arise on the system itself. Why than you add such hook where use can override??? So, here in Q2A where not all functions are allowed to override but some of them. This means, Devs (Gideo and all contributors) know the risk or I would say the possible drawback instead.

Since long I am keep commenting on function overriding issue. Even the theme methods also creating many issues when multiple plugins/themes override the same method.

Please keep in mind that above words is not to save myself from the mistake I did in hurry, ( I have already admin ) but to aware once again to all of contributors (including me) to make a system like add_action() where Devs can override in certain limits and not entire core.

Out of the topic: I am still looking for best theme engine so we can rid off all inline HTML. I can work on this part but the time is the issue.

I will fix this plugin as per scott's snippet.

I thankful and appreciate to pupi and scott to aware me for my mistake. Also gurjyot to notify me for this post otherwise I would miss it due to hell lot of work.
by
The add_action and add_filter methods in WP are almost exactly like event and filter plugins in Q2A. I suppose instead of overriding an entire function, those functions could have 'hooks' similar to event plugins.

The reason for allowing entire functions to be overridden is because in some cases that is what you want to do. Sometimes you want to do something completely different that you can't do by just modifying some variables.

But still for most cases you only want to change one thing in a function and leave the rest, that's exactly why you should call through to the base functions. The problems you mention about multiple plugins/themes overriding the same method *shouldn't* happen, because those overrides should change only what they need to change.
0 votes
by

http://store.q2amarket.com/q2a-free-plugins/edit-and-moderate

If I use this plugin, how do I add a button to change the admin panel ...
 
Now it's like this:
 
1. Click on the question
 
2. edit
 
3. To approve.
 
 
 
must be in the admin panel - moderated
 
button
 
approve --- refuse ---- edit.
 
 
 
on the basis of the plugin
...