Wordpress 3
Override WordPress Options using a Filter
The basic format for the add_filter function is: add_filter(‘pre_option_’.$option, ‘override_function_name’); Where $option is the name of the Option as found in the wp_options table of the database. This example uses a filter to update the admin_email set in Options to that of the current user, so ‘admin_email’ becomes ‘pre_option_admin_email’. add_filter(‘pre_option_admin_email’, ‘override_option_admin_email’); function override_option_admin_email() { global…
Read MoreDetermine User Role by Name in WordPress
This function returns the user role by name rather than by capabilities which is useful for determining whether the current user is a Wholesale customer for instance. It can also return the name of the user role given the user ID as a parameter. /** * Checks if a particular user has a role. *…
Read MoreRestrict Non-WordPress Page Access to Logged in User
This is useful for non WordPress pages on a WordPress installation. Add this to the top of the page: <?php include(‘wp-load.php’); if(!current_user_can(‘editor’)) { wp_redirect( wp_login_url() ); } ?> To restrict access to admin only change “editor” to “administrator”. wp-load.php loads the WordPress functions so yo can use the current_user_can() function
Read MoreShow content to logged in users only
This function can be used to make content visible only to logged in users: <?php if ( is_user_logged_in() ) { echo ‘Welcome, registered user!’; } else { echo ‘Welcome, visitor!’; } ?> Full details here: http://codex.wordpress.org/Function_Reference/is_user_logged_in
Read MoreEdit Thumbnail Cropping in Media Library
To change how WordPress crops an image to create the thumbnail: Select the image in Media Library Click the “Edit Image” button under the large image If you only want the change to apply to the thumbnail select “Apply changes to thumbnail” in “Thumbnail Settings” Click and drag the cursor over the image to highlight…
Read MoreDisable all Plugins in the WordPress Database
Run this query on the wp-options table to disable all plugins: UPDATE wp_options SET option_value = ” WHERE option_name = ‘active_plugins’;
Read MoreRunning WordPress with Tilde (~) in Site URL
For example to run WordPress on a URL such as:http://www.babelscribe.com/~mysite/ Change siteurl and blogname in the options table to the above url. Change default htaccess redirects to: RewriteEngine On RewriteBase /~mysite/ RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /~mysite/index.php [L] This is useful if you need to access an account…
Read MoreTrack Contact Form 7 Submissions using Google Analytics
In additional settings field of Contact From 7 admin: on_sent_ok: “_gaq.push([‘_trackEvent’, ‘Contact Form’, ‘Submit’]);” Google Analytics will track it as an event with Contact Form as the Category, and Submit as the Action. In Google Analytics go to Content > Events > Overview
Read MoreUpdate all URLs in database except in serialized data fields
Updating URLs in the database can cause problems if you include those in serialized arrays. These queries leave serialized arrays untouched: UPDATE wp_options SET option_value = REPLACE(option_value, ‘http://devdomain.local‘, ‘http://livedomain.com‘) WHERE option_value NOT LIKE ‘%{%’; UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, ‘http://devdomain.local‘, ‘http://livedomain.com‘) WHERE meta_value NOT LIKE ‘%{%’; UPDATE wp_posts SET post_content = REPLACE(post_content, ‘http://devdomain.local‘, ‘http://livedomain.com‘)…
Read MoreEnable 'Read More' link in posts outside the default blog page
Add the $more variable before the content in the loop: global $more; $more = 0; the_content(‘[Read more…]’);
Read More