Common Errors when making a plugin - Printable Version +- MyBB Community Forums (https://community.mybb.com) +-- Forum: Resources (https://community.mybb.com/forum-8.html) +--- Forum: Tutorials (https://community.mybb.com/forum-38.html) +--- Thread: Common Errors when making a plugin (/thread-6097.html) |
Common Errors when making a plugin - zaher1988 - 2006-01-16 Heloo there, I'd like to state here some common errors that you might encounter when making your own plugins, a little bit of my little experience in plugins for those who are new. 1- Correct & Common naming When making a plugin you should ensure to have a common name for the plugin and for the activation , deactivation, info etc...functions. what i mean in. if you make for example
your plugin file should be called icons. or you will not find your plugin in the plugin manager, or the plugin will not work. 2- Escaping all joker characters like $, [, ], ?, ( and ). When making a plugin and u miss escaping the jokers, you'll plugin will not do the job when activated. this is only apllied for the find string in the function find_replace_templatesets. What i mean by escaping is in case u have Quote:$mybbuser[avatar] you have to escape it using "\" Quote:\$mybbuser\[avatar\] 3-When having multilines It's better that in the search part of the replace templateset, that you dont use multipule lines. however if u have multipule lines make sure to include the letter "s" after the # for example
4-Watch up not to use "0" in activate You dont incluse "0" at the end of the activation for a certain change of templates. As 0 means you don't want to create a new template. however if you change something, you must create a new template otherwise reverting to original won't be possible. so only use it for deactivating umm in case others would like to add things here you're free bbye RE: Common Errors when making a plugin - Ryan Gordon - 2006-01-16 I didnt know about #3. cool RE: Common Errors when making a plugin - decswxaqz - 2006-01-16 Just to correct and add to the above 2- Escaping all joker characters like $, [, ], ?, ( and ). You should NOT escape all the characters in your plugin, just the ones used for the find string in the function find_replace_templatesets I think the above poster is referring to the function find_replace_templatesets. This function will basically search a specified template with the search string and replace it with something else. The function uses the function preg_replace to look for code. This means you have to 'escape' certain characters. Most noticeably $ and all of the brackets ([{}]). There are a few others but these are the main ones you need to know about. You should use the function preg_quote to do all of this work for you. You should also store your search strings in string values instead of copying/pasting the code into the relevant places. If you want to search for something and add something after the search string, some people might use it makes more sense to store the things in strings like so Note the use of preg_quote. You won't have to manually add all of the extra slashes and if you change the code in one place, you won't have to change it anywhere else.4-Watch up not to use "0" in activate When you use the function find_replace_templatesets the last parameter is optional. If it isn't used, or set to 1, it will create a new template from the 'master' template. This means an option will appear in the Admin CP for users to revert back to the original (default) template. If set to 0 then it will try to edit all templates with that title. So when you install/edit a template for the first time (read: activating a plugin) using the function find_replace_templatesets, you should omit this parameter so that it will create a copy of the master template you are trying to edit. And when you are deactivating your plugin, you should set this parameter to 0. Like in the code above/below
Notice the extra parameter at the end of the function in plugin_deactive. That will make the find/replace work on all templates with that name. I will add some more tips when my eyes are working. RE: Common Errors when making a plugin - zaher1988 - 2006-01-16 yes sorry regarding the 2nd one i forgot to mention that yes it's only for the find string in the function find_replace_templatesets i'll edit my post ciao |