WP Robots Txt - Version 1.0

Version Description

  • Initial version

=

Download this release

Release Info

Developer chrisguitarguy
Plugin Icon 128x128 WP Robots Txt
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (4) hide show
  1. inc/options-page.php +117 -0
  2. readme.txt +52 -0
  3. robots-txt.php +73 -0
  4. screenshot-1.png +0 -0
inc/options-page.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Wrapper for all our admin area functionality.
4
+ *
5
+ * @since 0.1
6
+ */
7
+ class CD_RDTE_Admin_Page
8
+ {
9
+ protected $setting = 'cd_rdte_content';
10
+
11
+ /**
12
+ * Constructor. Adds an action to `admin_init`
13
+ *
14
+ * @since 1.0
15
+ * @uses add_action
16
+ */
17
+ function __construct()
18
+ {
19
+ add_action( 'admin_init', array( &$this, 'settings' ) );
20
+ }
21
+
22
+ /**
23
+ * Registers our setting and takes care of adding the settings field
24
+ * we need to edit our robots.txt file
25
+ *
26
+ * @since 1.0
27
+ * @uses register_setting
28
+ * @uses add_settings_field
29
+ */
30
+ function settings()
31
+ {
32
+ register_setting(
33
+ 'privacy',
34
+ $this->setting,
35
+ array( &$this, 'clean_setting' )
36
+ );
37
+
38
+ add_settings_field(
39
+ 'cd_rdte_robots_content',
40
+ __( 'Robots.txt Content', 'wp-robots-txt' ),
41
+ array( &$this, 'field' ),
42
+ 'privacy',
43
+ 'default',
44
+ array( 'lable_for' => 'cd_crte_text' )
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Callback for the settings field.
50
+ *
51
+ * @since 1.0
52
+ * @uses get_option
53
+ * @uses esc_attr
54
+ */
55
+ function field()
56
+ {
57
+ $content = get_option( $this->setting );
58
+ if( ! $content ) $content = $this->get_default_robots();
59
+ ?>
60
+ <textarea name="<?php echo esc_attr( $this->setting ); ?>" id="cd_cdte_text" rows="10" cols="50" style="width:97%"><?php echo esc_html( $content ); ?></textarea>
61
+ <p class="description">
62
+ <?php _e( 'The content of your robots.txt file. Delete the above and save to restore the default.', 'wp-robots-txt' ); ?>
63
+ </p>
64
+ <?php
65
+ }
66
+
67
+ /**
68
+ * Strips tags and escapes any html entities that goes into the
69
+ * robots.txt field
70
+ *
71
+ * @since 1.0
72
+ * @uses esc_html
73
+ * @uses add_settings_error
74
+ */
75
+ function clean_setting( $in )
76
+ {
77
+ if( empty( $in ) )
78
+ {
79
+ // TODO: why does this kill the default settings message?
80
+ add_settings_error(
81
+ $this->setting,
82
+ 'cd-rdte-restored',
83
+ __( 'Robots.txt restored to default.', 'wp-robots-txt' ),
84
+ 'updated'
85
+ );
86
+ }
87
+ return esc_html( strip_tags( $in ) );
88
+ }
89
+
90
+ /**
91
+ * Get the default robots.txt content. This is copied straight from
92
+ * WP's `do_robots` function
93
+ *
94
+ * @since 1.0
95
+ * @uses get_option
96
+ * @return string The default robots.txt content
97
+ */
98
+ function get_default_robots()
99
+ {
100
+ $output = "User-agent: *\n";
101
+ $public = get_option( 'blog_public' );
102
+ if ( '0' == $public )
103
+ {
104
+ $output .= "Disallow: /\n";
105
+ }
106
+ else
107
+ {
108
+ $site_url = parse_url( site_url() );
109
+ $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : '';
110
+ $output .= "Disallow: $path/wp-admin/\n";
111
+ $output .= "Disallow: $path/wp-includes/\n";
112
+ }
113
+ return $output;
114
+ }
115
+ }
116
+
117
+ new CD_RDTE_Admin_Page();
readme.txt ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP Robots Txt ===
2
+ Contributors: chrisguitarguy
3
+ Donate link: http://www.pwsausa.org/give.htm
4
+ Tags: robots.txt, robots, seo
5
+ Requires at least: 3.3
6
+ Tested up to: 3.3.1
7
+ Stable tag: 1.0
8
+
9
+ WP Robots Txt Allows you to edit the content of your robots.txt file.
10
+
11
+ == Description ==
12
+
13
+ WordPress, by default, includes a simple robots.txt file that's dynamically generated from within the WP application. This is great! but maybe you want to change the content.
14
+
15
+ Enter WP Robots Txt, a plugin that adds an additional field to the "Privacy Settings" admin page where you can do just that.
16
+
17
+ == Installation ==
18
+
19
+ 1. Download the plugin
20
+ 2. Unzip it
21
+ 3. Upload the unzipped folder to `wp-content/plugins` directory
22
+ 4. Activate and enjoy!
23
+
24
+ Or you can simply install it through the admin area plugin installer.
25
+
26
+ == Screenshots ==
27
+
28
+ 1. A view of the admin option
29
+
30
+ == Frequently Asked Questions ==
31
+
32
+ = I totally screwed up my `robots.txt` file. How can I restore the default version? =
33
+
34
+ Delete all the content from the *Robots.txt Content* field and save the privacy options.
35
+
36
+ = Could I accidently block all search bots with this? =
37
+
38
+ Yes. Be careful! That said, `robots.txt` files are suggestions. They don't really *block* bots as much as they *suggest* that bots don't crawl portions of a site. That's why the options on the Privacy Settings page say "Ask search engines not to index this site."
39
+
40
+ = Where can I learn more about `robots.txt` files? =
41
+
42
+ [Here](https://developers.google.com/webmasters/control-crawl-index/docs/robots_txt).
43
+
44
+ == Changelog ==
45
+
46
+ = 1.0 =
47
+ * Initial version
48
+
49
+ == Upgrade Notice ==
50
+
51
+ = 1.0 =
52
+ * Everyone wants to edit their `robots.txt` files.
robots-txt.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP Robots Txt
4
+ Plugin URI: https://github.com/chrisguitarguy/WP-Robots-Txt
5
+ Description: Edit your robots.txt file from the WordPress admin
6
+ Version: 1.0
7
+ Author: Christopher Davis
8
+ Author URI: http://christopherdavis.me
9
+ License: GPL2
10
+
11
+ Copyright 2012 Christopher Davis (email: chris@classicalguitar.org)
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License, version 2, as
15
+ published by the Free Software Foundation.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+ */
26
+
27
+ if( is_admin() )
28
+ {
29
+ require_once( plugin_dir_path( __FILE__ ) . 'inc/options-page.php' );
30
+ }
31
+
32
+ add_filter( 'robots_txt', 'cd_rdte_filter_robots', 10, 2 );
33
+ /**
34
+ * Makes the magic happen. Get our saved robots.txt file and, if there's
35
+ * something there replace WP's default robots file.
36
+ *
37
+ * @since 1.0
38
+ * @uses get_option
39
+ * @uses esc_attr
40
+ */
41
+ function cd_rdte_filter_robots( $rv, $public )
42
+ {
43
+ $content = get_option( 'cd_rdte_content' );
44
+ if( $content )
45
+ {
46
+ $rv = esc_attr( strip_tags( $content ) );
47
+ }
48
+ return $rv;
49
+ }
50
+
51
+ register_activation_hook( __FILE__, 'cd_rdte_activation' );
52
+ /**
53
+ * Activation hook. Adds the option we'll be uses
54
+ *
55
+ * @since 1.0
56
+ * @uses add_option
57
+ */
58
+ function cd_rdte_activation()
59
+ {
60
+ add_option( 'cd_rdte_content', false );
61
+ }
62
+
63
+ register_deactivation_hook( __FILE__, 'cd_rdte_deactivation' );
64
+ /**
65
+ * Deactivation hook. Deletes our option containing the robots.txt content
66
+ *
67
+ * @since 1.0
68
+ * @uses delete_option
69
+ */
70
+ function cd_rdte_deactivation()
71
+ {
72
+ delete_option( 'cd_rdte_content' );
73
+ }
screenshot-1.png ADDED
Binary file