PluginProbe
Simple Page Redirect / 1.7
Simple Page Redirect v1.7
trunk 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8
simple-post-redirect / simple-post-redirect.php

simple-post-redirect.php in Simple Page Redirect 1.7, at simple-post-redirect.php

117 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Simple Post Redirect
4 Plugin URI: http://wordpress.org/plugins/simple-post-redirect/
5 Description: This plugin allows you to make simple redirects of single pages of any custom post type to any url.
6 Author: Mohit Agarwal
7 Version: 1.7
8 Text Domain: simple-post-redirect
9 Stable tag: "trunk"
10 License: GPLv2 or later
11 License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
13
14 Simple Post Redirect is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 2 of the License, or
17 any later version.
18
19 Simple Post Redirect is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with Simple Post Redirect. If not, see http://www.gnu.org/licenses/gpl-2.0.html
26 */
27
28
29 /**
30 * @package Simple Post Redirect
31 * @version 1.7
32 */
33
34 function me_spr_redirect_add_meta_boxes()
35 {
36 foreach (array_keys($GLOBALS['wp_post_types']) as $post_type)
37 {
38 // Skip:
39 if (in_array($post_type, array(
40 'attachment',
41 'revision',
42 'nav_menu_item'
43 ))) continue;
44
45 $args = array();
46
47 add_meta_box('me_spr_redirect_url', __('Simple Redirect to: ', 'simple-post-redirect') , // Title
48 'me_spr_redirect_callback_function', // Callback function that renders the content of the meta box
49 $post_type, // Admin page (or post type) to show the meta box on
50 'side', // Context where the box is shown on the page
51 'high', // Priority within that context
52 $args
53 // Arguments to pass the callback function, if any
54 );
55 }
56 }
57
58 add_action('add_meta_boxes', 'me_spr_redirect_add_meta_boxes');
59
60 function me_spr_redirect_callback_function($args)
61 {
62
63 $saved_url = get_post_meta(get_the_ID() , 'me_spr_post_redirect', true);
64 $html = '<input style="width:100%;margin-top:5px;" placeholder="' . __('Type a URL here.', 'simple-post-redirect') . '" type="text" name="me_spr_post_redirect" value="' . $saved_url . '">';
65 echo $html;
66 wp_nonce_field('me_spr_redirect_nonce_action', 'me_spr_redirect_nonce');
67 }
68
69 function me_spr_redirect_load_plugin_textdomain()
70 {
71 load_plugin_textdomain('simple-post-redirect', false, basename(dirname(__FILE__)) . '/languages/');
72 }
73 add_action('plugins_loaded', 'me_spr_redirect_load_plugin_textdomain');
74
75 function me_spr_redirect_metabox_save($post_id)
76 {
77
78 if (!isset($_POST['me_spr_redirect_nonce']) || !wp_verify_nonce($_POST['me_spr_redirect_nonce'], 'me_spr_redirect_nonce_action'))
79 {
80 return;
81 }
82
83 if (!current_user_can('edit_post', $post_id))
84 {
85 // print 'Sorry, you do not have sufficient permission to edit this page.';
86 return;
87 }
88
89 if (isset($_POST['me_spr_post_redirect']))
90 {
91 update_post_meta($post_id, 'me_spr_post_redirect', esc_url_raw($_POST['me_spr_post_redirect']));
92 }
93 else
94 {
95 delete_post_meta($post_id, 'me_spr_post_redirect');
96 }
97
98 }
99 add_action('save_post', 'me_spr_redirect_metabox_save');
100
101 add_filter('template_redirect', 'me_spr_permalink_redirect');
102 function me_spr_permalink_redirect($permalink)
103 {
104
105 if (!is_singular())
106 {
107 return true;
108 }
109 global $post;
110 $url = get_post_meta($post->ID, 'me_spr_post_redirect', true);
111 if (!empty($url))
112 {
113 wp_redirect($url, 301);
114 exit;
115 }
116 return;
117 }