Archive for the ‘Wordpress’ Category
Give Editors access to Redirection
Redirection is a powerful tool allowing you to manage redirects for your WordPress site. For a recent project we needed to allow users with a role of Editor to add and manage redirects, so we had to do a little plugin tweaking to get that access granted. Here is what you need to do.
On line 121 of this file:
/wp-content/plugins/redirection/redirection.php
Replace this:
function admin_menu() { add_management_page( __( "Redirection", 'redirection' ), __( "Redirection", 'redirection' ), "delete_others_pages", basename( __FILE__ ), array( &$this, "admin_screen" ) ); }
With this:
function admin_menu() { add_management_page( __( "Redirection", 'redirection' ), __( "Redirection", 'redirection' ), "manage_options", basename( __FILE__ ), array( &$this, "admin_screen" ) ); }
On line 36 of this file:
/wp-content/plugins/redirection/ajax.php
Replace this:
function init() { if ( current_user_can( 'administrator' ) ) { $this->post = stripslashes_deep( $_POST ); $this->register_ajax( 'red_log_show' ); $this->register_ajax( 'red_log_hide' ); $this->register_ajax( 'red_log_delete' );
With this:
function init() { if ( current_user_can( 'delete_others_pages' ) ) { $this->post = stripslashes_deep( $_POST ); $this->register_ajax( 'red_log_show' ); $this->register_ajax( 'red_log_hide' ); $this->register_ajax( 'red_log_delete' );
The first edit above allows Editors to see the Redirection navigation item under the Tools menu in the admin area. The second edit allows Editors to add/edit/save redirects via the Redirection screen.
Da Tag(s): Redirection Da Categorie(s): Plugins, Wordpress
Convert one post type to another another
If you can’t tell yet, we’re a huge fan of custom post types in our theme development and blog tutorials. They allow us to create feature rich admin areas while keeping with the intuitiveness that is WordPress; so, of course, we dig em! Have you ever created a custom post type, but wanted to convert a bunch of already written posts into that new post type? To accomplish this task, we’ve used a Post Type Switcher in the past, however, as of WordPress 3.1 that plugin no longer works so we needed to get down and dirty in the database for this one. Here is how you do it:
- Backup your database just in case you need to roll back for some reason, we’ve never had a problem running the SQL below, but its generally a good idea to back up the DB when performing any action like this.
- Run the SQL below in phpMyAdmin, tweaking it to your needs first.
UPDATE wp_posts p JOIN wp_term_relationships tr ON (p.ID = tr.object_id) JOIN wp_term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) JOIN wp_terms t ON (tt.term_id = t.term_id) SET post_type = 'event' WHERE p.post_type = 'post' AND p.post_status = 'publish' AND tt.taxonomy = 'category' AND t.name = 'Events'
The code above takes posts in the “post” post type that are “publish”ed and in the category “Events” and converts them to the post type “event”. Yes, we’re using The Events Calendar as an example yet again. Now your events that used to be grouped in with all your other posts now have a neat new home under their own Event post type menu in the admin, making tutorials for clients that much easier!
Da Tag(s): database, mySQL Da Categorie(s): Custom Post Types, Wordpress
Custom Post Type Admin Icons
Let’s face it, its pretty awesome having the ability to add a custom icon to your admin menus for custom post types. Here is a bit of code we added to the function.php file of our theme for a recent project. All you need to do is drop your custom icons in the images directory of you theme and tweak the code below. “Newsletters” and “Events” are the names of our 2 custom post types for this project.
add_action( 'admin_head', 'cpt_icons' ); function cpt_icons() { ?> <style type="text/css" media="screen"> #menu-posts-newsletters .wp-menu-image { background: url(<?php bloginfo('template_url') ?>/images/mail.png) no-repeat 6px -17px !important; } #menu-posts-events .wp-menu-image { background: url(<?php bloginfo('template_url') ?>/images/calendar-blue.png) no-repeat 6px -17px !important; } #menu-posts-newsletters:hover .wp-menu-image, #menu-posts-newsletters.wp-has-current-submenu .wp-menu-image, #menu-posts-events:hover .wp-menu-image, #menu-posts-events.wp-has-current-submenu .wp-menu-image { background-position: 6px 7px!important; } </style> <?php }
You can find a sweet collection of icons and further direction at RandyJensenOnline.com.
Da Categorie(s): Code, Custom Post Types, Wordpress
Custom Post Type RSS Feed
Comments Off on Custom Post Type RSS Feed
Here is a neat little trick to display all posts from a custom post type via feed in WordPress. This comes in handy if you’re looking to pull posts from a certain post type into an external site using something like the Google RSS Feed Displayer.
http://example.com/feed/?post_type=yourposttype
Da Categorie(s): Custom Post Types, Wordpress
The Events Calendar Doesn’t Display Today’s Event on Upcoming Events Page
We’ve seen this issue a couple times on a few different sites. It seems to come and go and is always a major issue when it happens. The Events Calendar plugin will stop displaying today’s event on the upcoming events page and move it to the past events page which leads to chaos if you’re in the process of promoting that event. Here is a simple fix to correct this problem, remember to update this code each time you upgrade the plugin.
On line 15 of this file:
/wp-content/plugins/the-events-calendar/the-events-calendar.class.php
Replace this:
const DBDATETIMEFORMAT = 'Y-m-d G:i:s';
With this:
const DBDATETIMEFORMAT = 'Y-m-d';