Replacing functions in "actions.php"

General questions pertaining to how certain issues can be resolved
Forum rules
1. No offensive language and no mocking
2. Please do a thorough search before you post something. Trust us, there is a high probability that the question you are asking has been asked previously.
3. No soliciting. You cannot post here soliciting bids for people offer you quotes, or even offer money to people for some work. You will be moderated if you do so. If you are looking for help, please post your request on http://jobs.wordpress.net or http://codepoet.com
4. Please be reasonable. You are getting software and support. For free. Complicated requests from a general purpose theme are not welcome and some volunteers might lose patience with you.
5. Please do your due diligence. If you posted a query and we answered with a link, take the trouble to go through the link contents.
6. Please post with complete information. Requests for help MUST be accompanied with your URL, particularly if you are asking something like "Why am I seeing a blank space?"

Replacing functions in "actions.php"

Postby traductionbiz » 03 Nov 2010, 03:52

Hi, :-)

I'm making a child theme for Suffusion. I need to rewrite one function defined in "../suffusion/functions/actions.php" and put that rewritten function in "wp-content/themes/suffusion-child/functions/actions.php".

But I want to preserve "../suffusion/functions/actions.php" unchanged in any way. (Future theme updates would just overwrite any changes I made. And I don't want to simply replace Suffusion's "actions.php" altogether, because then I won't benefit from any future updates to it, and my child theme might just break altogether.

So, in my new "actions.php", I put an include followed by the replacement function definition, named identically to the one I want to replace:

Code: Select all
<?php

include '../suffusion/functions/actions.php';

function foo($arg_1, $arg_2, /* ..., */ $arg_n)
{
   echo "All my new code.\n";
}

?>


Because this duplicate foo() function definition comes after the foo()
defined in the included file, does it replace the included foo()?

Or how can I achieve what I want?

Big thanks in advance for any suggestions. :-)

David
traductionbiz
 
Posts: 10
Joined: 02 Nov 2010, 04:25

Re: Replacing functions in "actions.php"

Postby traductionbiz » 03 Nov 2010, 04:12

I forgot to say that the site in question is at http://www.traduction.biz/

BTW, the changes I want to make are to change the date format in article titles, and to modify the footer.

Sayontan still gets a credit, but on a separate, dedicated page that credits a much longer list of software installed on the server than just WordPress and Suffusion. I also plan to buy Sayontan a much-deserved "coffee" at the end of the month... ;)

David
traductionbiz
 
Posts: 10
Joined: 02 Nov 2010, 04:25

Re: Replacing functions in "actions.php"

Postby sayontan » 03 Nov 2010, 09:05

David,
You don't need the include statement. If you create your function in wp-content/themes/suffusion-child/functions.php it will get automatically included.

Secondly, using the same function name wouldn't work, because it would require me to encase the original function definition in actions.php in a "function_exists" clause. I would suggest using a different function name, then using remove_action to remove the older action and add_action to add the new action.
Sayontan Sinha | http://mynethome.net/blog | http://www.aquoid.com/news
I don't do freelance work (for Suffusion or otherwise), so please don't contact me for quotes or offers.
sayontan
Site Admin
 
Posts: 10159
Joined: 15 Sep 2009, 16:39
Location: Houston, Texas

Re: Replacing functions in "actions.php"

Postby flashbytes » 30 Oct 2011, 19:12

Hello folks,

instead of opening a new topic I'll use this, because I want to do the very same thing as the topic starter, only I'm not sure how to make it so it will work.

I have a child theme setup and want to replace the entire function "suffusion_display_main_navigation". So far I have been able to figure out everything by myself, but I don't know how this would work. Can anyone please point me in the right direction?

flashbytes
flashbytes
 
Posts: 26
Joined: 12 Aug 2010, 07:50

Re: Replacing functions in "actions.php"

Postby sayontan » 30 Oct 2011, 21:07

The answer I have written above should work: write your own function, then use remove_action to remove the existing one.

Of course, there is a much easier way now (since version 3.8.3), wherein you can create a folder called "custom" in your child theme, then add a file called navigation-menu.php there. Code it up as you want, and you can use the one in Suffusion's "custom" folder for the structure. The top of the file gives instructions if you want to have different markups for the top or the main navigation bar.
Sayontan Sinha | http://mynethome.net/blog | http://www.aquoid.com/news
I don't do freelance work (for Suffusion or otherwise), so please don't contact me for quotes or offers.
sayontan
Site Admin
 
Posts: 10159
Joined: 15 Sep 2009, 16:39
Location: Houston, Texas

Re: Replacing functions in "actions.php"

Postby flashbytes » 31 Oct 2011, 04:44

Alright. The custom folder and a "navigation-menu.php" doesn't help me, since - if I interpreted the file correctly - it is really only a part of the whole function suffusion_display_main_navigation.

So, I looked for the function and tried the corresponding remove_action. But I must have gotten something wrong, because the function is not being removed.

This what I wrote into the functions.php:
Code: Select all
<?php
/**
 * Core functions file for the theme. Includes other key files.
 *
 * @package Suffusion
 * @subpackage Functions
 */

  remove_action('suffusion_page_header', 'suffusion_display_main_navigation');

?>


I have also tried adding a function and that works like a charm.

This here's the website: http://inbetween-worlds.net/wordpress_ifag/
flashbytes
 
Posts: 26
Joined: 12 Aug 2010, 07:50

Re: Replacing functions in "actions.php"

Postby sayontan » 31 Oct 2011, 11:39

I haven't seen your code in full, but my guess is that this applies to you: viewtopic.php?f=4&t=5595&p=23133&hilit=race#p23133
Sayontan Sinha | http://mynethome.net/blog | http://www.aquoid.com/news
I don't do freelance work (for Suffusion or otherwise), so please don't contact me for quotes or offers.
sayontan
Site Admin
 
Posts: 10159
Joined: 15 Sep 2009, 16:39
Location: Houston, Texas

Re: Replacing functions in "actions.php"

Postby flashbytes » 31 Oct 2011, 14:37

Thank you bunches! That - was - it! :)
Now it's working and I've replaced two functions. Maybe I can find some more... lol ;)
flashbytes
 
Posts: 26
Joined: 12 Aug 2010, 07:50


Return to Support Requests

Who is online

Users browsing this forum: Google [Bot] and 8 guests