Checking whether a post belongs to a specific category in WordPress using the in_category() function. We search for and remove malicious code on WordPress Check the template for malicious code

💖 Do you like it? Share the link with your friends

Have you ever wondered what theme a website uses?

Often, in search of the ideal topic, we look at others completed projects to find something similar or make your own website on the same theme, only with your own individual design.

In this tutorial, we'll show you what tools and tricks you can use to find out what theme your WordPress site is using.

Method 1. IsItWP verification site

The easiest way is to go to isitwp.com and check out the site that interests you.

This is an online tool that will show you what theme WordPress is using, and whether WordPress is even being used on that site.

If the site is running WordPress, IsItWP will try to find out the name of the current theme.

It will also try to find out what active plugins are used on the site:

If you are lucky and this is not a custom or child theme, then IsItWP will display its name, and then you can find this theme in search engines.

Method 2. Determine manually

Sometimes site owners or developers change the name of a native WordPress theme. In this case, tools like IsItWP will not be able to help you.

But even if so, there may still be various clues in the site code that will help you figure out what kind of theme is installed.

Let's get a look.

Every WordPress theme is required to have a style.css file. This file contains a header inside, which usually indicates the name of the theme, the author of the theme, the version and the theme developer site. It also lists other CSS style templates that the theme uses.

To find this file, you first need to go to the site itself. Right-click somewhere on the main page and go to View Page Source.

Opens in a new tab in the browser source home page site.

Now you need to find a line of code that looks something like this:

To make the task easier, you can search this tab with the code using the "themes" fragment. This is part from the directory where style.css is located.

This way you will find the path where the style.css file is located, and you can open this file directly in the browser in a new tab.

At the top of style.css there will be a header with a title (which we talked about above). This is service information about the theme. It looks something like this:

/* Theme Name: Theme Name Theme URI: https://example.com Author: ThemeAuthorName Author URI: https://example.com Description: My Theme is a flexible WordPress theme designed for portfolio websites Version: 1.1.47 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: hestia Tags: blog, custom-logo, portfolio, e-commerce, rtl-language-support , post-formats, grid-layout, one-column, two-columns, custom-background, custom-colors, custom-header, custom-menu, featured-image-header, featured-images, flexible-header, full-width -template, sticky-post, theme-options, threaded-comments, translation-ready */

From this block you can find out the name of the topic and the address of the developer. Then all that remains is to find this topic on the Internet.

Method 3. How to find the parent theme

Many sites use child themes to customize their appearance. And this is a completely correct approach.

In this case, if you find the style.css file from the child theme, its header will contain information about the parent theme:

/* Theme Name: My Child Theme Description: Just a child theme Author: Peter Smith Author URL: Write here the author's blog or website url Template: hestia Version: 1.0 License: GNU General Public License v2 or later License URI: http ://www.gnu.org/licenses/gpl-2.0.html Text Domain: my-child-theme */

In the example above, the parent theme is pointed to by the "Template" parameter, meaning this child theme uses the parent theme "Hestia".

You can also learn about the parent theme from the source code described in Method 2. In the code, you will find a reference to the style.css file not only from the child theme, but also from the parent theme.

But do not forget that the developer could try and change all the headers for style.css to his own, in which case it will be very difficult to determine the original theme.

Periodically checking the site for availability harmful viruses necessary, this is the first commandment of any self-respecting webmaster. Even if you use a clean Twenty Eleven theme, it is not a fact that over time it also did not become infected. This phenomenon can (and most often does) occur due to the fact that the WordPress engine itself was originally designed for online publishing. So it never hurts to check again and make a copy of the site and database.

For example, I (after some time, of course) made one conclusion for myself - you just need a good hoster, and your problems with backup will disappear by themselves. I don’t need to make backups of the database or website now - the hoster does everything for me, and in automatic mode. At any time, if you wish, you can order a copy of any section of your blog (and not only), download this copy, or restore the blog directly from the control panel. That is, I don’t need to download a backup, everything happens automatically - backup, restore, etc. This is convenient because I can track, not just daily, but hourly, when a virus appeared on my blog and, accordingly, take measures to eliminate it.

I'll start with the good news - at least two plugins that I have used give good results in detecting and localizing malicious code. These are AntiVirus and Exploit Scanner plugins. You won't believe how much harmful code is on your blog! But don't take all the resulting information after checking as dogma - many of the lines that these plugins detect don't actually mean anything bad. The plugin just questions some lines, that's all. To make sure of this, manually check those fragments that the plugin has identified as malicious. So, when checking with the AntiVirus plugin, it turned out that even a simple call to function get_cache_file () is already considered suspicious by the plugin. So all check results will have to be tracked manually. But this, for example, is a really infected link, and it needs to be removed:

How do you know if it's a virus or just how it should be? Everything is very simple - compare your clean template (if you have one), and compare it (file by file) with the one that is installed and has already undergone some changes. It is not necessary to make a direct comparison directly, just use a search to check if your blank template contains the line that the plugin highlighted. If there is, click the “This is not a virus” button, and this line will not be taken into account during the next scan.

And here is an example of the second plugin we tested - Exploit Scanner

As you can see, everything is much more neglected here. For me, this result was shocking. But that's not all. The plugin has a function called check. So, if you turn it on, it turns out that the blog should consist of text and, at most, a couple CSS tables. So, it seems to me that the author of the plugin clearly overdid it with security here. It’s good that the plugin simply shows suspected infected fragments and does not clean them.

Having analyzed all the selected yellow lines, you can easily detect malware (malicious code), well, decide for yourself what to do with it next. The cleaning method is still the same - compare the selected code with a site backup (see) and, if you find discrepancies, find out whether you did it yourself, or someone did it for you, which means that this is no longer good and may turn out to be virus. Even WordPress developers recommend checking your site for malicious code with this plugin. But there are such harmless inserts, for example, into the body of an iframe, which the plugin can also identify as infected code. But in reality, without these lines, this area of ​​your blog will not work correctly.

How can malware even get into blog files and what is it by definition? The word malware literally means - malicious software , from English malicious software. This is any software that can be used for unauthorized access to the site and its content. You probably imagine that for an average hacker, hacking a website will not be difficult, especially after registration. After this, you can modify the blog content as you wish - it would be educational.

Malicious malware can be inserted into plugins that you install from an unknown source, and into scripts that you also sometimes take without checking, but trusting the author. The most harmless malware is a link to the author of any module that you installed on the site. And if the author himself did not warn you that such a link exists, then this is a pure virus.

Yes, I installed it on a test blog new topic, and after deleting one harmless link to some kind of men’s club in the basement of the site, it stopped opening at all, and the inscription appeared on the main page - “You do not have the right to delete links.” Here's a free theme for you. You can read about how to rip out such left-wing links.

Your database can also be used to run virus-containing code. Spammy links are also very often added to posts or comments. Such links are usually hidden when CSS help so that an inexperienced administrator does not see them, but search system distinguishes them immediately. Of course, here any antispam comes into play, for example, the same one that is licensed, tested and double-checked many times. A hacker can download files with image file extensions and add them to the code of your activated plugins. Therefore, even if the file does not have a php extension, the code in that file can be executed.

There is another simple tool with which I started getting acquainted with malware - the Theme Authenticity Checker (TAC) plugin. This is a lightweight and quite effective tool, but it only checks your topics, even inactive ones. It doesn’t touch the rest of the directories, and that’s its downside. This is what testing my current theme with this plugin gave me:

Two warnings in the active thread, and nothing more. There is no malicious code. By the way, these are the links that I inserted myself on the advice of Google - to improve the quality of the snippet (displaying personal data, organization address, etc.). But this is only checking the theme files, and you will have to find out what is being done in other directories either using other plugins or online services. For example, a service (it’s really trustworthy) like Yandex Webmaster or a similar one at Google. They have the function of checking any web resource for the presence of malicious inclusions, and they do it efficiently. But if this is not enough for you, then compare the results with the results on other services and draw conclusions.

For some reason I want to trust Yandex, not plugins. Another good resource is http://2ip.ru/site-virus-scanner/. After checking one of my blogs, this is what I found:

Here you can also check individual files for malicious code if you have any doubts. In general, the service is not bad.

From all that has been said, I would draw the following conclusions:

1. To prevent the appearance of malicious code, you must first of all use proven services for downloading files - plugins, themes, etc.

2. Do it regularly backups everything that the site contains - databases, content, admin panel, uploaded third-party files, including.

3. Take advantage of the updates that WordPress offers. At least they do not contain viruses, although they are not always functionally justified. But by updating, you thereby remove any viruses that may be present.

4. Delete unused themes, plugins, images and files without regret - this is another escape route for malware that you may never even guess about.

5. Properly password-protect your FTP accesses, login to PhpAdmin, the admin panel, and generally where no one but you should have access.

6. Try (even if your desire is as great as the sky) not to change or replace WordPress core files - developers know better what should work and how.

7. After detecting and removing viruses, change all passwords. I think you will have a great desire to make a password of 148 characters in different registers and with special characters. But don’t get carried away with too complex passwords, you may lose it, and then you’ll have to restore everything, which is not very pleasant.

All these methods and components that I have described that will help you get rid of viruses are, of course, free, of course, almost homemade, and of course, they do not provide a 100% guarantee that your site will be cleaned of malicious inserts. Therefore, if you are already concerned about cleaning your blog, then it is better to contact professionals, for example, the Sucuri service (http://sucuri.net/). Here your site will be thoroughly monitored, practical recommendations will be given, which will be sent to you by letter, and if you do not want to clean up the site yourself, then specialists are at your service who will do everything in the best possible way within 4 hours:

Well, this is what my test blog looks like after monitoring, and this despite the fact that other methods (home-grown) always show different results. As you can see, the test is free, but if viruses are detected, you should pay to remove them without harm to the site (unless, of course, you are a guru in cleaning your blog from malware).

Let me emphasize once again - hackers do not sleep, viruses are constantly being updated, and it is impossible to keep track of everything on your own. All innovations are so carefully hidden and disguised that only the team can reveal them! professionals, and not the self-taught blogger that many are. This is why manual detection and removal of malware is so ineffective: no experience means no result, but there is a virus. Use licensed programs and entrust the removal of danger to professionals

Hi all! Time does not stand still and every time after another new functions appear in the kernel. If previously most non-standard tasks at that time had to be implemented using additional programming, then the situation is changing now. There is a clear trend of expanding functionality out of the box.

Looking back at 2010, when I stood on the threshold of discoveries and first became acquainted with , I remember how difficult it was for me to take my first steps. For each elementary task, I found and installed plugins; their total number could reach several dozen! 😮 Then came the time of rethinking and the pursuit of minimalism. The Optimization section reflects some aspects of the work I have done to speed up the blog.

Enable WordPress Debug Mode

The blog template has undergone changes since the first days, acquiring new functions, styles, and classes. Having gained a critical mass, it became clumsy - it is very difficult to maintain working condition and high performance. Big changes, invisible at first glance, took place last year - from new layout and work with thumbnails to micro markup.

The first thing after the transformation was to open the developer console in the browser and check for errors and warnings. The next step is to debug WordPress. The mode is enabled in the wp-config.php configuration file, find the line in it:

Define("WP_DEBUG" , false );

and replace false with true . The line should look like:

Define("WP_DEBUG" , true );

If there are errors, a message will be displayed where the error occurred, describing the problem and the files affected. These could be parsing errors or obsolete functions that have been removed from the kernel or replaced with new ones.

The warning is based on one simple fact: the error message contains the absolute path to the file relative to the server's root directory. The message is seen not only by the administrator, but by all users. An illustrative example:

Parse error: syntax error, unexpected ‘endif’ (T_ENDIF) in /u57109403/data/www/site.ru/wp-content/themes/default/index.php on line 23

As can be seen from the example, the value u57109403 can be the login for accessing the server and attackers only have to guess the password. Be carefull.

Theme Check - WordPress Theme Testing Tool

In addition to the built-in function WP_DEBUG there is good tool developer, designed to test the theme for compliance with modern Codex standards.

It is implemented as a Theme Check plugin, which you can download from the official repository page.

After activating the plugin, go to its page ( Appearance- Theme Check). When debugging mode is disabled, you will see the following message:

WARNING WP_DEBUG is not enabled! Please test your theme with debug enabled before you upload!

I described how to activate this mode in the first part of the article. This is not necessary, but is highly recommended for completeness of the analysis. To start the check, click “Check it”.

If you use Cyrillic in the source code of your theme files, then be prepared to encounter information of this kind in the report:

INFO: Non-printable characters were found in the single.php file. You may want to check this file for errors.

You can disable the display of such messages by checking the box next to “Suppress INFO”. Note for the future: when localizing a theme, use the special translation files ru_RU.po and ru_RU.mo instead of editing the source code by replacing English words to Russian.

The Theme Check plugin will be useful for WordPress theme developers and site administrators. The report is based on checking a standard set minimum requirements in the current topic and contains the following notation:

  • Required - a required function, class or description is missing;
  • Warning - warnings, for example, about the presence of hidden files;
  • Recommended - recommendations on the possible use of new functions;
  • Info - other information messages.

Most of the outstanding requirements are supported by references to the Code describing functions and parameters. However, the report is already quite informative. A small fragment:

The test results must be treated with a certain degree of caution. You should not use absolutely all the functions recommended by the plugin - among them there will probably be some that you really do not plan to use.

Using debug mode and the Theme Check plugin, I was able to identify a number of problems that were caused by outdated functions. Some improvements in functions.php were removed as unnecessary or replaced with standard solutions that appeared in latest versions. I recommend checking out your blogs!

Before you figure out how to clean a WordPress site, you need to understand what, exactly, we will be dealing with. In a broad sense, the concept of “virus” means malicious software that can cause some damage to the owner of a web resource. Thus, almost any code embedded by attackers into engine scripts can be included in this category. These may be hidden links leading to pessimism in search results, backdoors that provide the hacker with admin access, or complex structures that turn the site into a zombie network node, and even a Bitcoin miner. We will talk about how to identify and eliminate viruses of various calibers, as well as protect against them.

Many of the tips mentioned in previous articles can protect your site from infection. For example, “infection” can be found in pirated templates and plugins; complete rejection of such components is an important step from a security point of view. However, there are a number of more specific nuances.

1. Install a reliable antivirus

A malicious program can be introduced not only from the outside; the source of infection could very well be the computer from which the project is administered. Modern Trojans can not only steal the FTP password, but also download executable code on their own, or modify CMS files, which means that the security of your web resource directly depends on the security of your work machine.

The IT market offers many antiviruses. However, the most reasonable choice is the products of large companies:
● Among domestic products, the leading positions are occupied by proposals from Kaspersky Lab and Dr. Web.
● Among foreign commercial solutions we can highlight the Norton line from Symantek Corporation and the popular ESET NOD;
● If we talk about free options, Avast and Comodo are the undisputed leaders here.

2. Scan the site using online services

When found suspicious activity(engine errors, brakes, the appearance of pop-ups and third-party banners), the simplest thing you can think of is to run the resource through an online scanner that can determine the fact of infection. The undisputed leader here is VirusTotal, located at virustotal.com. To use it, just go to the “URL address” tab, enter the link you are interested in and click on the “Check!” button.

After some time, the system will issue a report with the following content:

It should be clarified: VirusTotal is not an independent project, but a kind of aggregator of anti-virus scanners. In this regard, it becomes possible to check WordPress for viruses on 67 systems simultaneously. An undoubted advantage is a detailed report that provides data on all supported services. After all, antiviruses are very fond of raising false alarms, so even if the detection rate differs from the ideal (for example, 3/64), this does not mean that the resource is infected. Focus primarily on large players (Kaspersky, McAfee, Symantec NOD32 and others); small companies often identify certain sections of code as dangerous - do not take this seriously!

3. Use Yandex.Webmaster

You probably noticed that some links in search results are provided with a warning message: “The site may threaten your computer or mobile device" The fact is that the search engine has its own algorithms for detecting malicious code, notifying users of the potential risk. To be aware of what is happening and be the first to receive notifications, just register in the Webmaster service. You can view all the necessary information on the “Security” tab:

If a threat is detected, information about infected pages will be displayed here. Unfortunately, selective scanning of WordPress for viruses is impossible - Yandex scans it independently, and moreover, not all downloaded web documents are included in the sample, but only a part of them, determined at random.

4. Check Google Reports

The most popular search engine in the world offers an even simpler way of monitoring - just follow the link google.com/transparencyreport/safebrowsing/diagnostic/?hl=ru, and enter the address of the site of interest in the appropriate field. You will receive comprehensive data on the resource and see whether Google has any complaints in terms of detecting malicious scripts:

How to clean a WordPress website from viral links?

Let's move on from general recommendations to specific ones. Let's start with common variants of malicious code - the introduction of extraneous URLs and redirects to the target web resource. Unfortunately, black hat SEO is still popular, which means hackers are not sitting idle, fortunately this task is one of the simplest. Let's sort it out in order.

1. Redirect to third-party resources

Imagine the situation: you go to your own website, but you are immediately transferred to another “leisure” directory, or landing page offering to make money on Forex. This almost certainly means that the web resource has been hacked, and several new lines have appeared in .htaccess. The treatment is simple: open the file, find directives containing the address to which the redirection is made, and then delete them. So, for a conditional malwaresite.com, the necessary constructions could be as follows:

< IfModule mod_alias. c>Redirect 301 https://site/ http://malwaresite.com/

RewriteEngine On RewriteBase / RewriteCond % ( HTTP_HOST ) ! ^tekseo\. su [NC] RewriteRule ^(.* ) http: //malwaresite.com/$1

RewriteEngine On RewriteBase / RewriteCond %(HTTP_HOST) !^tekseo\.su RewriteRule ^(.*) http://malwaresite.com/$1

A more sophisticated option is a permanent redirect written in PHP. If you checked but didn't find anything suspicious, the problem is most likely in the index.php file. Redirection here is done by sending the necessary headers to the visitor:

include("redirect.php"); exit();

Remember - such fragments are not found in the original index.php, so you can safely delete them all. Also find and delete the included file (in our example it will be redirect.php, located in the root folder).

A more cunning move is a redirect for mobile gadgets. By accessing your resource from personal computer, you will never detect the fact of infection, but users of smartphones and tablets will be unpleasantly surprised when they end up on another page. This redirection can be implemented:

1. .htaccess
The simplest method, which can be easily calculated. The device is identified by the presented User Agent. It might look like this:

< IfModule mod_rewrite. c>RewriteEngine on RewriteBase / RewriteCond % ( HTTP_USER_AGENT) ^.* (ipod| iphone| android).* [ NC] RewriteRule ^(.* ) $ http: //malwaresite.com/

RewriteEngine on RewriteBase / RewriteCond %(HTTP_USER_AGENT) ^.*(ipod|iphone|android).* RewriteRule ^(.*)$ http://malwaresite.com/

2.PHP
The redirect is implemented in PHP in a similar way. The construct below can be found in the index file. Again, don’t forget about the ubiquitous include:

3. JavaScript
Here the screen resolution is checked; if the width is 480 pixels or less, the visitor is redirected to a malicious site. If your project uses a similar method, be sure to check this block for address changes.

< script type= "text/javascript" >if (screen. width

tell friends