MyBB Community Forums

Full Version: [Tutorial] Upgrading to 1.6.5: Making Plugins Compatible
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Since some people seem to be having some difficulty with the changes affecting plugins in MyBB 1.6.5, below is a short tutorial of how to correct your plugins manually.

Step 1

Download pavemen's script which will identify plugins that need looking at from this thread or here.

[attachment=24805]

Upload this file to your plugins folder via FTP, which should be found in:

/inc/plugins/

Step 2

Once uploaded, now browse to the file you have just uploaded:

http://www.yourdomain.com/inc/plugins/pl...update.php

Where you should see a list which looks something like the image below.

[attachment=24806]

Please Note: Pavemen's script will only identify where affected hooks are being used, whether or not alterations have been made. Some plugins like Pirata's MyDownloads will be flagged on the list, but the code has already been rectified.

Step 3

The script does nearly all the hard work for you. 3 different actions may be needed from the results.

Result 1: No action needs to be taken if a plugin has no hooks listed as below.

[attachment=24807]

Result 2: Issue Type 'Return Code'.

[attachment=24808]

In this situation we need to add a return value at the end of the function. Go into your /inc/plugins and find the file that has been identified; in this case it is shops.php.

Open up the file and search for what is listed under Function Called, which in this case is: shops_user_groups_edit_graph_tab. Below is the snippet of code:

$plugins->add_hook("admin_user_groups_edit_graph_tabs", "shops_user_groups_edit_graph_tabs");
function shops_user_groups_edit_graph_tabs($tabs){
	global $lang;
	$tabs['shops'] = $lang->shops;
}

We should change this to:

$plugins->add_hook("admin_user_groups_edit_graph_tabs", "shops_user_groups_edit_graph_tabs");
function shops_user_groups_edit_graph_tabs(&$tabs){
	global $lang;
	$tabs['shops'] = $lang->shops;
}

Do this for all plugins that have been identified.

Result 3: Issue Type 'Reference Check'.

This is the same fix as for Return Code, we need to add an & in front of any variables affected.

[attachment=24809]

Once again, go into your /inc/plugins and find the file that has been identified; in this case it is gomobile.php.


Open up the file and search for what is listed under Function Called, which in this case is: gomobile_posts. Below is the snippet of code:

function gomobile_posts($p)
{
    global $mybb;
....

We should change this to:

function gomobile_posts(&$p)
{
    global $mybb;
....

Do this for all plugins that have been identified. (In the above example, the same would be done for gomobile_threads).

Note

(1) Plugin authors should keep be keeping their plugins up to date so please check for plugin updates. This manual process will most likely only apply for plugins that are older/authors are not active anymore.

Hope this helps.

Thanks to pavemen.
Return code is not necessary.
(2011-11-27, 06:07 PM)Solidus Wrote: [ -> ]Return code is not necessary.

yup, as he stated in Notes #2.
(2011-11-27, 06:07 PM)Solidus Wrote: [ -> ]Return code is not necessary.

I had that in the notes, but have updated the tutorial.
Theres no need to fix the "Reference Check" in the "Return Code" issue. The return code issue requires a return variable at the end of the function.
(2011-11-27, 08:43 PM)Frank.Barry Wrote: [ -> ]Theres no need to fix the "Reference Check" in the "Return Code" issue. The return code issue requires a return variable at the end of the function.

If you are saying that to fix the Return Code issue you would do the following:

$plugins->add_hook("admin_user_groups_edit_graph_tabs", "shops_user_groups_edit_graph_tabs");
function shops_user_groups_edit_graph_tabs($tabs){
    global $lang;
    $tabs['shops'] = $lang->shops;

    return $tabs;
}

that's apparently not the case. The correct fix would be as ITT.
Thats correct. You DONT need to do this in a return code issue, thats a reference check issue:

Quote:function shops_user_groups_edit_graph_tabs(&$tabs){

I wasn't aware either, but i've had pointed out to me twice now that a return issue can be fixed with:

function shops_user_groups_edit_graph_tabs(&$tabs){

I.e. The same as the Ref Issue where you don't need a return.

I might be getting a little confused, are we agreeing or disagreeing?
MyBB checks for a returned value, so it was probably intended for you to return it. However reference works too, although this might be unintended. But it works unless you modify the variable by reference and then return something else entirely. Because MyBB then simply throws away the old data and continues with the returned value.

At least, that's how it is for hooks that are called by run_hooks. There's also run_hooks_by_ref where only the reference method works. Very few hooks are _by_ref now, only datahandler_ hooks and admin_form_end.

Why they behave differently I haven't the faintest idea, IMHO the run_hooks_by_ref function should be a one liner calling the run_hooks function, but whatever.
(2011-11-27, 10:02 PM)frostschutz Wrote: [ -> ]MyBB checks for a returned value, so it was probably intended for you to return it. However reference works too, although this might be unintended. But it works unless you modify the variable by reference and then return something else entirely. Because MyBB then simply throws away the old data and continues with the returned value.

At least, that's how it is for hooks that are called by run_hooks. There's also run_hooks_by_ref where only the reference method works. Very few hooks are _by_ref now, only datahandler_ hooks and admin_form_end.

Why they behave differently I haven't the faintest idea, IMHO the run_hooks_by_ref function should be a one liner calling the run_hooks function, but whatever.

It can't be for one very simple reason... run_hooks doesn't receive by ref. I do plan on folding them into one function down the road though, as it would be simpler and smarter to have run_hooks() just receive by ref and check for a return value. You just have to be a responsible plugin author with this!