Hook replace (deprecated)
From Sohowiki
(Difference between revisions)
(16 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
+ | <br> | ||
+ | <font color=red> | ||
+ | ;'''IMPORTANT: This function is deprecated and should not be used. Newly submitted plugins that use hook_replace will not be accepted. | ||
+ | ''' | ||
+ | </font> | ||
+ | ---- | ||
+ | <br> | ||
+ | |||
+ | ==Syntax and Description== | ||
;Syntax | ;Syntax | ||
− | :hook_replace(source file | + | :hook_replace(path to source file from docroot, replacement manifest file name) |
Line 8: | Line 17: | ||
− | + | ==Example 1 - Calling hook_replace from your plugin's install manifest== | |
+ | The following example would be used to replace certain code in main_menu.php with code defined in your replacement manifest file (here named main_menu-replacements.php"). | ||
<pre>hook_replace("sohoadmin/program/main_menu.php", "main_menu-replacements.php");</pre> | <pre>hook_replace("sohoadmin/program/main_menu.php", "main_menu-replacements.php");</pre> | ||
− | + | ==Example 2 - Content of replacement manifest file (i.e. main_menu-replacements.php)== | |
− | + | ||
<pre> | <pre> | ||
− | |||
# Add another title row below the "Basic Features Group" row. | # Add another title row below the "Basic Features Group" row. | ||
+ | #new replacement# | ||
<oldcode> | <oldcode> | ||
<tr> | <tr> | ||
Line 33: | Line 42: | ||
</newcode> | </newcode> | ||
− | |||
# Replace title row with modifed version | # Replace title row with modifed version | ||
+ | #new replacement# | ||
<oldcode> | <oldcode> | ||
<tr> | <tr> | ||
Line 47: | Line 56: | ||
</newcode> | </newcode> | ||
</pre> | </pre> | ||
+ | |||
+ | ==Things that screw it up== | ||
+ | The following is a list of common problems that can preven hook_replace calls from working properly. | ||
+ | *'''Permissions''' - If php can't write to the file, then your hook_replace won't work on it. | ||
+ | |||
+ | *'''Not remembering [[the deal with client_files]]''' - If you're using hook_replace on, for example, client_files/shopping_cart/pgm-add_cart.php it's good practice (and less work for you while developing) to include an additional hook_replace call in your install manifest so that you're writing to both copies of the file, like so... | ||
+ | hook_replace("sohoadmin/client_files/shopping_cart/pgm-add_cart.php", "pgm-add_cart-replacements.php"); | ||
+ | hook_replace("shopping/pgm-add_cart.php", "pgm-add_cart-replacements.php"); | ||
+ | |||
+ | Note that "pgm-add_cart-replacements.php" is just an example of what your [[#Example_2_-_Content_of_replacement_manifest_file_.28i.e._main_menu-replacements.php.29|replacement manifest file]] might be called. Could just as easily be "myreplacements.php". | ||
[[Category:Plugins]] | [[Category:Plugins]] |
Latest revision as of 17:35, 11 October 2013
- IMPORTANT: This function is deprecated and should not be used. Newly submitted plugins that use hook_replace will not be accepted.
Contents |
Syntax and Description
- Syntax
- hook_replace(path to source file from docroot, replacement manifest file name)
- Description
- Reads your replacement manifest file and replaces specified chunk(s) of code in source file with your different (modified) code.
- Specific replacements for a particular source file should be placed in a dedicated file (this is your replacement manifest).
Example 1 - Calling hook_replace from your plugin's install manifest
The following example would be used to replace certain code in main_menu.php with code defined in your replacement manifest file (here named main_menu-replacements.php").
hook_replace("sohoadmin/program/main_menu.php", "main_menu-replacements.php");
# Add another title row below the "Basic Features Group" row. #new replacement# <oldcode> <tr> <td class="fgroup_title"><? echo lang("Basic Features Group"); ?></td> </tr> </oldcode> <newcode> <tr> <td class="fgroup_title"><? echo lang("Basic Features Group"); ?></td> </tr> <tr> <td class="fgroup_title">Hello World!</td> </tr> </newcode> # Replace title row with modifed version #new replacement# <oldcode> <tr> <td class="fgroup_title"><? echo lang("Basic Features Group"); ?></td> </tr> </oldcode> <newcode> <tr> <td class="fgroup_title" style="font-style: italic;">Hello World!</td> </tr> </newcode>
Things that screw it up
The following is a list of common problems that can preven hook_replace calls from working properly.
- Permissions - If php can't write to the file, then your hook_replace won't work on it.
- Not remembering the deal with client_files - If you're using hook_replace on, for example, client_files/shopping_cart/pgm-add_cart.php it's good practice (and less work for you while developing) to include an additional hook_replace call in your install manifest so that you're writing to both copies of the file, like so...
hook_replace("sohoadmin/client_files/shopping_cart/pgm-add_cart.php", "pgm-add_cart-replacements.php"); hook_replace("shopping/pgm-add_cart.php", "pgm-add_cart-replacements.php");
Note that "pgm-add_cart-replacements.php" is just an example of what your replacement manifest file might be called. Could just as easily be "myreplacements.php".