While running wordpress site, save Ram usage is always great idea and you can easily improve the site performance by simple wordpress theme tricks.
We mostly use the get_permalink(), get_the_title() methods in our wordpress theme. Do not pass the post ID as parameter.
if you’re doing a get_permalink or get_title() call with Post id, 8 out of 10 times you’ll need to more of that post than just the permalink, so this isn’t really a problem.
save Ram usage
Post object is actually already slightly faster than calling get_permalink with $post->ID (in get_post it then only sanitizes and adds to cache, it doesn’t fetch new data), but the real benefit comes when you add a variable called filter in the $post object, setting it to “sample”. Now you decide whether that post object is going to be cached or not and which variables it contains.
Pass the $Post object instead of Post ID.
Do not use the Custom fields. Your server need to fire extra custom quries on Mysql server.
If your are using $wpdb->get_results or new WP_Query( $args ) then add the order by.
Recently one of my wordpress site is hacked which is on wordpress. There is something wrong happening on server. We fixed issue with some steps, we given full steps for fixing issue. Due to disk I/O notification and CPU usages notification email I got to know.
If wordpress site is hacked then how to fix issue
There is something wrong happening on server.
First thing I did which is checking the apache access logs and error logs. I was getting per second 100 request from some IP addresses.
I stoped apache server and I took my database and filesystem backup. Deleted my admin username and added new administrator with new username.
You should use the Better WP Security wordpress plugin. This is very useful plugin.
# BLOCK BAD IPS
<limit GET POST PUT>
Order Allow,Deny
Allow from all
# uncomment/edit/repeat next line to block IPs
# Deny from 123.456.789
Deny from 192.111.152.122
Deny from 192.111.144.233
Deny from 110.85.90.123
</limit>
But above code was still not helpful to me because disk I/O and apache process was taking time to sending the request to 403.
Then I blocked the IP Address on My Linux server using following commands.
iptables -A INPUT -s 192.111.144.789 -j DROP
iptables -A INPUT -s 192.111.152.122 -j DROP
iptables -A INPUT -s 192.119.144.123 -j DROP
From last two months WordPress Under Huge Attack by Malicious Botnet. Hackers are using thousands of individual computers and IP addresses. The botnet goes for the most obvious hack attempt: target sites with admin as the username , and will try to access that site’s password with a combination of thousands of possible passwords.
The WordPress site currently powers over 60 million websites and read by over a quarter of a billion users every month.When survey website W3Techs conducted a survey, it was found that 17% of the world’s websites are powered by WordPress.
While the attack may only succeed a small percentage of the time, the attack could result in hundreds or thousands of compromised servers when averaged over tens of thousands of sites powered by WordPress software.
We can use the following article for changing the admin username
http://www.digitalkonline.com/blog/change-your-wordpress-admin-username/
Update wordpress version
WordPress founder Matt Mullenweg advises that if you do these first three “you’ll be ahead of 99% of sites out there and probably never have a problem.”
Use the Better WP Security plugin
As most WordPress attacks are a result of plugin vulnerabilities, weak passwords, and obsolete software. Better WP Security will hide the places those vulnerabilities live keeping an attacker from learning too much about your site and keeping them away from sensitive areas like login, admin, etc.Better WP Security takes the best WordPress security features and techniques and combines them in a single plugin thereby ensuring that as many security holes as possible are patched without having to worry about conflicting features or the possibility of missing anything on your site.
With one-click activation for most features as well as advanced features for experienced users Better WP Security can help protect any site.
Jquery lightbox is mostly used for slideshows in web based project. In wordpress that is most favorite. Here I collected some nice wordpress lightbox plugins.
Lightbox Plus ColorBox implements ColorBox as a lightbox image overlay tool for WordPress. ColorBox was created by Jack Moore and is licensed under the MIT License. Lightbox Plus ColorBox for WordPress implements ColorBox as a lightbox image overlay tool for WordPress. ColorBox was created by Jack Moore and is licensed under the MIT License. Lightbox Plus ColorBox permits users to view larger versions of images without having to leave the current page. Lightbox is able to add a lightbox to WordPress gallery images, display simple slide shows, video, forms and external content in overlays. The use of the dark or light background, which dims the page over which the image has been overlaid, also serves to highlight the image or video being viewed. Lightbox Plus ColorBox captures the image title for display in the overlay.
The next generation of Simple Lightbox is here and ready for brave beta testers. Sign up for SLB 2.0 beta now while there’s still space available!
Simple Lightbox is a very simple and highly customizable lightbox that is easy to add to your WordPress website. It also supports skins, so it can be fully integrated with your site’s theme.
From 2.1, the default view changed to Colorbox due to the license regulation by the plugin directory. This plugin used to add the lightbox (overlay) effect to the current page images on your WordPress blog. Used to overlay images on the current page. Extension of wp-jquery-lightbox.
Just install and sit back. This plugin enable image overlay lighbox effect for all the post images in your wordpress plugin. No configuration required.
This plugin lets you keep the awesome Lightbox 2-functionality, but sheds the bulk of the Prototype Framework and Scriptaculous Effects Library.
Warren Krewenki ported Lightbox to jQuery and this plugin is mostly a wrapper to his work: providing localization support, an admin panel for configuration, (optional) auto-boxing of your image links and support for WordPress galleries, including media library titles and captions.
the default view changed to Colorbox due to the license regulation by the plugin directory. If you would prefer the prior Lightbox to Colorbox, you need to get the script from the setting page.
Clifton’s Lightbox implements a lightbox subscription form overlay. Features a title, list, call-to-action, and image or YouTube video. Users can embed their subscription form into the lightbox and use the call-to-action area to encourage new subscribers.
Clifton’s Lightbox Demo
http://cliftonhatfield.com/cliftons-lightbox/
This plugin allows you to create a lightbox popup with custom contents. You can customize the popup display by configuring various settings such as position settings (height, width, top,left), display logic settings (time delay after page load, number of pages to browse, lightbox repeat interval) and style settings(z-index, overlay opacity, color, border etc). You can use the plugin to display any type of contents such as special promotions, subscription forms, social media icons, feedback forms, video presentations and much more.
Makes the native WordPress galleries use a lightbox script called ColorBox to display the fullsize images right there in the page. No modifications required.
Frndzk photo lightbox plugin adds lightbox effect to all photos of every post and pages. it also shows photos in a group of a post like a photo album. it has next and previous to navigate photos. Just install the plugin and see your photos! no setup or configuration needed
demo
http://bitto.us/wp/fpgdemo
In wordpress admin users listing page, wordpress admin has user search with username and email but we cannot search via display name or first name and last name.
We can add firstname, lastname and display name in users search. You just need to add following code.
/*
* functions will be applicable for only wordpress admin
*/
if (is_admin()) {
/*
* Modify the User Search in Admin to include firstname, lastname and display_name
*/
add_action('pre_user_query', 'wpapi_pre_user_query');
function wpapi_pre_user_query($user_search) {
//die();
global $wpdb;
// print_r($user_search);
$vars = $user_search->query_vars;
if (!is_null($vars['search'])) {
/* For some reason, the search term is enclosed in asterisks.
Remove them */
$search = preg_replace('/^\*/', '', $vars['search']);
$search = preg_replace('/\*$/', '', $search);
//print_r($search);
//search in display name
if(!empty($search)){
$user_search->query_where = substr(trim($user_search->query_where), 0, -1) . " OR display_name LIKE '%". $search . "%')";
}
$user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m1 ON " .
"{$wpdb->users}.ID=m1.user_id AND (m1.meta_key='first_name')";
$user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m2 ON " .
"{$wpdb->users}.ID=m2.user_id AND (m2.meta_key='last_name')";
$names_where = $wpdb->prepare("m1.meta_value LIKE '%s' OR m2.meta_value LIKE '%s'", "%{$search}%", "%$search%");
$user_search->query_where = str_replace('WHERE 1=1 AND (', "WHERE 1=1 AND ({$names_where} OR ", $user_search->query_where);
}
return $user_search;
}
}
We just saw the issue with qtranslate slug with widget is not working for 0.5 version. URL is showing but URL is not opening and 404 page is opening. we solved the of qTranslate slug with Widget not working with pages.
Solved issue qTranslate slug with Widget not working with pages
The problem was exactly at the function qTranslateSlug_filter_request inside de file qtranslate-slug-with-widget.php, which is the only one of the plugin, so it’s easy to find.
We must take a look at this part of the code:
With the last wordpress versions, mine is 3.3.1, has changed the way of passing the query to the request filter, changing the array slug position from ‘pagename’ to ‘name’, then the plugin didn’t have a way to find any page, since it expected to find in the array the position ‘pagename’, nonexistent for the current case.
Ref is taken from – http://en.codatavern.com/qtranslate-slug-with-widget-wordpress-plugin-fix/
If you have mail server then you should use the wp_mail wordpress plugin. Information about Send email through wp_mail in html format with wordpress is easy. Emails are very important feature for now in the world so you need to understand better the wordpress mail functionality.
In wordpress we use the wp_mail function for sending email. Following parameters we use for wp_mail. WP developers wants to send email through wordpress.
Send email through wp_mail in html format with wordpress
Here is some brief and introduction about wp_mail method of wordpress. wordpress itself uses the PHPmailer for sending emails.
Parameters
$to
(string or array) (required) The intended recipient(s). Multiple recipients may be specified using an array or a comma-separated string.
$subject
(string) (required) The subject of the message.
$message
(string) (required) Message content.
$headers
(string or array) (optional) Mail headers to send with the message. (advanced)
$attachments
(string or array) (optional) Files to attach: a single filename, an array of filenames, or a newline-delimited string list of multiple filenames. (advanced)
Simple example:
[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]
<?php
$attachments = array(WP_CONTENT_DIR . '/uploads/file_to_attach.zip');
$headers = 'From: My Name <myname@mydomain.com>' . "\r\n";
wp_mail('test@test.com', 'subject', 'message', $headers, $attachments);
?>
[/viral-lock]
We can use this code for contact form or in functions.php file
For html format email from wordpress. we just need to add following line in functions.php file.
Sending HTML email has risks. It could be caught in spam filters. The client may not support HTML formatting (although that’s rare). The client may disable email HTML from using javascript, CSS or grabbing remote assets like images.
WordPress news, what’s new in wordpress 3. wordpress 3.3 is released on 12th Dec 2011. This is next biggest release of 2011. We given full release notes.
what is new in wordpress 3.3
Highlights
Easier Uploading
File Type Detection – A single upload button
Drag-and-Drop Media Uploader
Dashboard Design
New Toolbar in the dashboard, combining the Admin Bar and admin header
Responsive design for some screens, including iPad/tablet support
Flyout menus, providing single-click access to any screen
New User Experience
New feature pointers, helping users navigate new features
Post-update About screen
Dashboard welcome area for new installs
Content Tools
Better co-editing that releases post locks immediately
Don’t lose widgets when switching themes
Tumblr Importer
Under the Hood improvements
Use the postname permalink structure without a performance penalty
Drag and drop multi-file uploading (except older IE)
Fix Press This editors
Switch admin menus to flyouts from dropdowns
WebMatrix support
Improve cron locking; avoid multiple cron processes looping over the same events
Add pointers feature, and pointer to admin bar
Introduce help tabs and WP_Screen
Style tweaks to the update nag
Dashboard
Ensure text in the dashboard recent comments widget wraps up properly
Posts
When inserting a Gallery to be ordered by Date/Time use the post_date field for ordering rather than ID
Rename ‘Post Tags’ to ‘Tags’
Make DFW (Distraction-Free Writing) content width match exactly the reported width from the theme
Improve the image drag-resize detection in the visual editor (supported in FF and IE only), remove the size-* class if the image is soft-resized
Add TinyMCE command to handle opening of the upload/insert popup, fix the shortcut “Alt+Shift+M”, fix the “image” button in DFW
Allow Apostrophes in Post Passwords
Add post formats to quick edit and bulk edit
Hide post title field in DFW if title is not supported by the current post type or missing
Clean up remnants from having negative Post_ID
Media
Merge media buttons into one
Add the styling for “drop area” to Media->Add New
Add support for rar and 7z file uploading
Links
Comments
Use WP_Editor when editing or replying to comments
Use ‘View Post’ instead of ‘#’ for view post links in comment rows
Appearance
Use the Settings fields/sections API in Twenty Eleven
Load all Parent theme stylesheets before Child theme stylesheets in the TinyMCE Editor
Clean up Plugin/Theme uploads after successfully installing them
Improved Theme upload and validation
Avoid losing widgets when switching themes
Make Distraction Free Writing content width match exactly the reported width from the theme
Allow current_theme_supports() to be used to check for specific post formats
Improved Menus
Contextual help for Twenty Eleven theme options page
Plugins
Improved Plugin upload and validation
Stop remembering the last viewed plugins screen; always show all plugins when returning to plugins.php
Tools
Add the Tumblr importer to the Importers List
Add wxr_export_skip_postmeta filter for skipping postmeta in exports
Users
Removed user option to disable Toolbar (admin-bar in 3.2) in the Dashboard
Settings
Add postname to Settings > Permalinks and remove the help text talking about permalink performance; make the slugs (and /archives/ rewrite base) translatable
Clarify Settings > Privacy
Use title case in Settings > General
Disallow indexing wp-admin and wp-includes in robots.txt
Install Process
Multisite
Allow creating sites with IDN domains
Move network/settings.php POST handling out of network/edit.php
Dissolve wp-admin/network/edit.php
Add ‘Network Enable’ link after installing a theme in the network admin
Use update_blog_details() in wpmu_update_blogs_date()
Change Network Settings to just Settings
Implement bulk update for network/themes.php
Fix inviting existing users to a site with email confirmation
Check for plugin/theme updates every hour when hitting update-core.php, not just themes.php/plugins.php
Development, Themes, Plugins
Abstract word-trimming from wp_trim_excerpt() into wp_trim_words()
Add wp_unique_post_slug filter
Add _doing_it_wrong() when a plugin or theme accesses $wp_scripts or $wp_styles too early (also fixes localization)
Add a general filter to wp_unique_post_slug to allow for full customisation of the uniqueness functionality
Add filter for the args into wp_dropdown_pages() in the page attributes box; give the list_pages filter the context of the post object
Add filter so the users can select custom image sizes added by themes and plugin
Add filters for install/upgrade queries, so that unit tests installer can force creating InnoDB tables, so that we can use transactions to revert the database to its initial state after each test
Add inflation support for java.util.zip.Deflater in WP_Http_Encoding::compatible_gzinflate()
Add magic get/set/isset methods to WP_User to avoid data duplication; standardize on WP_User::ID
Add pre_ent2ncr filter
add_site_option should not update existing options, should return a boolean and should only run actions on success
Allow get_blog_option(null,…) to hit the cache for the current blog; new return values for add_blog_option, update_blog_option, delete_blog_option; don’t set the cache in those functions if add/update/delete_option failed
Allow ‘id’ to work in get_bookmarks(); add link_notes even though such sorting is a bad idea
Allow sorting by id in get_bookmarks()
Allow the text parameter in wp_trim_excerpt() to be omitted altogether, instead of requiring a blank string
Automatically set ‘compare’ => ‘IN’ in WP_Meta_Query::get_sql() when the meta value is an array
Change month dropdown display in date pickers to include month number
Completely remove wp_add_script_data()
Consolidate update count code into wp_get_update_data()
Count only published posts when updating term counts; fire term count updates on transition_post_status
Deprecate add_contextual_help() for get_current_screen()->add_help_tab()
Deprecate favorite_actions(), add_contextual_help(), add_screen_option(), move meta_box_prefs() and get_screen_icon() in WP_Screen
Deprecate media_upload_(image|audio|video|file)(), type_url_form_(image|audio|video|file)(); these now wrap wp_media_upload_handler() and wp_media_insert_url_form()
Deprecate RSS 0.92 feed and 301 it to the default feed
Deprecate wpmu_admin_redirect_add_updated_param() and wpmu_admin_do_redirect()
Eliminate verbose rewrite rules for ambiguous rewrite structures, resulting in massive performance gains
Fix back compat issues with delete_postmeta and deleted_postmeta actions as these should be passed the meta ID
Fix QTags.closeAllTags(), replace ‘tb’ with ‘ed’ in quicktags,js to make it clear it is the editor instance not the toolbar, small comments quick edit fixes
Fix typos in documentation
Fix wp_update_user() so it doesn’t stomp meta fields
Force display_errors to off when WP_DEBUG_DISPLAY == false; technically a backwards incompatible change so if you want the passthrough to php.ini (which false used to provide) then use WP_DEBUG_DISPLAY === null
Harden up is_user_logged_in() against empty $current_user instances to prevent PHP Notices on XML-RPC requests
Have dbDelta() loop through tables it knows about, rather than loop through a potentially expensive and definitely unnecessary SHOW TABLES
Improve _wp_menu_output()
Improve the parsing of email addresses in wp_mail to re-support RFC2822 nameless “<address@…>” style
Instantiate some MS variables as objects before using them
Introduce ->mysql to allow drop-ins to declare themselves as MySQL and therefore allow minimum version checks to still apply
Introduce is_main_query() that compares the query object against $wp_the_query
Introduce metadata_exists(), WP_User::get_data_by(), WP_User::get(), WP_User::has_prop(). Don’t fill user objects with meta
Remove support for <link rel=start>, end, up, and index. These rel=”” values have been dropped by the HTML Working Group
Remove the old root feed files, but don’t add these files to old_files to leave them on existing installs
Require show_ui rather than public for a taxonomy’s parent post type
Rework get_hidden_meta_boxes() to leverage a full WP_Screen object; prevents custom post types from having their explicitly supported meta boxes being hidden by default
Set up the post global variable in the comment feed loops so that any calls to post related template tags work correctly
Store screen help and options as static data against WP_Screen; individual screen objects no longer hold data it can’t re-generate on construction or otherwise fetch; convert_to_screen() now returns a WP_Screen object; various globals are gone; introduces WP_Screen::get_option(); allows for a formal factory to be introduced later
Support an array or comma-seperated list of excluded category IDs in get_adjacent_post()
Sync pomo library with the current GlotPress version
Turn delete_meta() , get_post_meta_by_id(), update_meta(), delete_post_meta_by_key() into wrappers around theMetadata API; add back compat *_postmeta actions to Metadata API
Turn is_blog_user() into a convenience wrapper around get_blogs_of_user(); fixes is_blog_user() for blog prefixes that do not contain a blog ID
Update blog last_updated time only on publish_post; both private_to_published and publish_phone are overly broad and otherwise redundant
Update jQuery to 1.7.1
Update jQuery UI to 1.8.16
Update Plupload to 1.5.1.1
Update quicktags.js (HTML editor)
Update TinyMCE to 3.4.5
Use add_option() method, introduce add_option_context() method for adding specific text above the screen options
Use json_encode() for adding script data (formerly l10n); add the same functionality to WP_Styles for adding inline css after a stylesheet has been outputted
Use wp_print_scripts() in install.php
Various PHPdoc updates including: for all_items, menu_name, WP_List_Table::views(), cache.php, get_option(), wpdb::prepare(), get_template_part(), esc_url(), get_meta_sql(), WP_Screen, WP_Http_Encoding::compatible_gzinflate(), zeroise(), wp_add_script_before(), wp_editor()
WP_Filesystem_*::mkdir() untrailingslash path consistently, don’t waste time attempting to create an “empty” path
WordPress publishing URL you can change to anything using following function. Following wordpress hook is very important. You can publish article with different URL or domain also. Using your blog you can publish your article to another URL also.
change permalinks as per your choice in wordpress
You just need to open your functions.php file and put following function in that file.
<pre><pre>
add_filter('post_link', 'fitsmi_post_link');
function fitsmi_post_link($permalink) {
global $post;
$permalink = str_replace("wordpress/", "", $permalink);
return $permalink;
if (!isset($post))
return $permalink;
else
return 'http://hack.by.wordpressapi/';
}
With following function you need to be very careful.
We solved Allowed memory size of 33554432 bytes exhausted which for wordpress. Given solution for allowed memory. Change given for wordpress/wp-config.php file.
Solved Allowed memory size of 33554432 bytes exhausted
We got always following ERROR PHP Fatal error:
Allowed memory size of 33554432 bytes exhausted (tried to allocate 10485761 bytes)
This issue with old and new wordpress versions both. First you need to increase memory limit for your php package. Use following method for increase the memory for php.
Open php configuration file
# vim /etc/php.ini
Change following sections:
max_execution_time = 300 ; Maximum execution time of each script, in seconds
max_input_time = 300 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M ; Maximum amount of memory a script may consume (16MB)
After this dont forget to restart apache server.
I know on 2.5.1 i needed to increase the memdory, but i don’t know how in 2.6. in the wp-config.php there no define to increase memory. If you are using old wordpress version less than wordpress 2.6 version or you are using the wordpress MU then use following code. open your wp-settings.php file from root folder and change following line
if ( !defined('WP_MEMORY_LIMIT') )
define('WP_MEMORY_LIMIT', '32M');
to
if ( !defined('WP_MEMORY_LIMIT') )
define('WP_MEMORY_LIMIT', '128M');
If you are using the newer wordpress version greater than 2.7 then use following method. Following URL is also helpful http://codex.wordpress.org/Editing_wp-config.php
#Increasing_memory_allocated_to_PHP Edit wp-config.php and enter the following line
define('WP_MEMORY_LIMIT', '64M');
If you are using the shared hosting then use following method.
Create a file called php.ini in the root of your site (if you are using a hosted addon domain, this must be in the subdirectory of that site)
In php.ini, enter a line that says memory_limit = 64MB 3. In your site’s .htaccess (being a WordPress blog, I’m assuming there is one), enter the following line SetEnv PHPRC // (keep the slashes)
Edit wp-config.php and enter the following line
define('WP_MEMORY_LIMIT', '64M');
Upload the new files to the server Oh, and don’t tell your hosting provider you’ve done this… This will solve your issue.