• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

php

WordPress Maintenance Page

March 8, 2013 by Webhead

If you’ve updated WordPress, you should have noticed that wordpress goes into “maintenance mode” whenever mass plugins or WordPress itself is updated.  What if you wanted to do some manual upgrading?  Then you can manually put wordpress into maintenance mode.

To put wordpress into maintenance mode, just add a .maintenance file (notice the leading dot) in the same folder that contains wp-settings.php.  Then in the file add this:

<?php $upgrading = time(); ?>

When you’re done with your maintenance simply remove the .maintenance file.

 

source:

http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/

There’s also a way to update what the maintenance page displays.  The default is a white page with a brief message.

http://xtremelysocial.com/2010/how-to-make-an-awesome-maintenance-mode-screen-for-wordpress/

Filed Under: Coding Tagged With: php, wordpress

WordPress Cron

December 20, 2012 by Webhead

A great way to take more control of your wp-cron and also slightly speed up wordpress is to disable cron and scheduled a cron job on your server to run wp-cron.php.  You just need a server that supports cron jobs.

In wp-config.php add:

define(‘DISABLE_WP_CRON’, true);

Be careful though, sometimes this has a negative effect on your website.  For example if you have subscriptions from woocommerce, each user’s subscription is checked on every 12 hours.  If you have a ton of users, each of these users has a cron job waiting to run throughout the hour.  These jobs will slow down your server if you run wp-cron too far apart.

Setting up your cron command can look similar to:

*/30 * * * * wget http://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1

 

source:  http://bitswapping.com/2010/10/using-cron-to-trigger-wp-cron-php/

Filed Under: Coding, Server Stuff Tagged With: linux, optimize, php, wordpress

Hardening WordPress

December 18, 2012 by Webhead

I’ll be updating this post as I find more and better explanations to hardening wordpress.  The more secure, the better.  Some things to keep in mind when you are trying to secure your wordpress installation.

  • Be careful when saying a security measure is “not worth the time” to do it.  If it takes 5 minutes to do, then it’s almost always worth it to do it.
  • It is always worth doing something that will prevent those rare cases.  Just remember that most default settings will already protect you from the common cases, it’s those rare ones that get you.
  • “Simple folk” not understanding things is not an excuse to not do things.

WordPress codex has many good solutions.  This post is will only repeat those solutions if there is more explanation.

http://codex.wordpress.org/Hardening_WordPress

 

Move your wp-config.php file

  • If your server runs into some trouble (no hackers required) it can get reset and/or display php files in plain text without going through the interpreters.  .htaccess files could also be bypassed by some server problems.  A good example is in the link below where it was a common bug on a certain host.
  • This is your most sensitive file.  Any security measure for this file is worth it if done right.
  • http://wordpress.stackexchange.com/questions/58391/is-moving-wp-config-outside-the-web-root-really-beneficial

 

Filed Under: Coding, Server Stuff Tagged With: linux, php, wordpress

How to use your own template for specific times

December 14, 2012 by Webhead

There’s a great post on how to get WordPress to use your own template and override the default template.

The basic code looks like this;

function my_template() {
if (is_category() && get_query_var(‘cat’) == get_cat_id(‘fun’)) {
include (TEMPLATEPATH . ‘/category-fun.php’);
exit;
}
}

add_action(‘template_redirect’, ‘my_template’);

 

Be sure to use STYLESHEETPATH instead of his TEMPLATEPATH so that child themes respond to the code properly.

http://www.mihaivalentin.com/wordpress-tutorial-load-the-template-you-want-with-template_redirect/

Filed Under: Coding Tagged With: php, wordpress

WP Query inconsistencies in query

December 6, 2012 by Webhead

Problem

In WordPress, I created a new WP_Query with a few simple args to get a custom post type.  However, no results came back.  I could look at the query by checking WP_Query’s request property.  The query, when run in mysql returned the desired rows.  So what was happening to these rows?

 

Solution

WP_Query’s posts property holds all the posts that will be returned.  Looking into wp-includes/query.php, it turned out that I didn’t have read permissions.  I was trying to show private posts.  The user needed ‘read_post’ and ‘read_private_posts’ permissions (‘post’ can be replaced with your custom capability).

On a side note, tax_query does not work in the args if you are retrieving a single post object.  What determines this?  It depends on what args  you send WP_Query.  If you send it args like ‘name’, ‘p’, ‘page_id’, and some other parameters it will mark it as is_single and it will not perform tax_query!  This took me a while to find.

Filed Under: Coding Tagged With: php, wordpress

Optimize Custom WordPress Queries

November 20, 2012 by Webhead

A couple things that may optimize your custom wordpress queries.  First there is a parameter called ‘fields’ where  you can specify that you only want the ID field back.  Something like below:

$some_query = new WP_Query( array( ‘fields’ => ‘ids’ ) );

An even more significant optimization is by caching your data and using WordPress’ Transient API like so:

<?php

// Get any existing copy of our transient data

if ( false === ( $special_query_results = get_transient( ‘special_query_results’ ) ) ) {

// It wasn’t there, so regenerate the data and save the transient

$special_query_results = new WP_Query( ‘cat=5&order=random&tag=tech&post_meta_key=thumbnail’ );

set_transient( ‘special_query_results’, $special_query_results );

}

// Use the data like you would have normally…

?>

 

sources:

http://www.wpbeginner.com/wp-tutorials/speed-up-your-wordpress-by-caching-custom-queries-using-transients-api/
http://wordpress-hackers.1065353.n5.nabble.com/Using-WP-Query-to-get-posts-ids-td23952.html
http://codex.wordpress.org/Transients_API

keywords: wp_query only get ids, wp_query cache_results

Filed Under: Coding Tagged With: optimize, php, wordpress

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Interim pages omitted …
  • Go to page 8
  • Go to Next Page »

Primary Sidebar

Topics

apache apple block editor chrome cms css debug eCommerce embed firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery linux localization mac os x ms sql mysql open source optimize php php 5.3 responsive rest api seo svg tinymce woocommerce wordpress wpengine xss yii youtube




Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools