WP Robots Txt - Version 1.1

Version Description

  • Moved the settings field "officially" to the reading page
  • General code clean up

=

Download this release

Release Info

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

Code changes from version 1.0 to 1.1

Files changed (4) hide show
  1. inc/core.php +67 -0
  2. inc/options-page.php +103 -52
  3. readme.txt +10 -3
  4. robots-txt.php +39 -67
inc/core.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WP Robots Txt
4
+ *
5
+ * Copyright 2013 Christopher Davis <http://christopherdavis.me>
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License, version 2, as
9
+ * published by the Free Software Foundation.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ * @category WordPress
21
+ * @package WPRobotsTxt
22
+ * @copyright 2013 Christopher Davis
23
+ * @license http://opensource.org/licenses/GPL-2.0 GPL-2.0+
24
+ */
25
+
26
+ /**
27
+ * Makes the magic happen. Get our saved robots.txt file and, if there's
28
+ * something there replace WP's default robots file.
29
+ *
30
+ * @since 1.0
31
+ * @uses get_option
32
+ * @uses esc_attr
33
+ * @return string
34
+ */
35
+ function cd_rdte_filter_robots($rv, $public)
36
+ {
37
+ $content = get_option('cd_rdte_content');
38
+ if ($content) {
39
+ $rv = esc_attr(strip_tags($content));
40
+ }
41
+
42
+ return $rv;
43
+ }
44
+
45
+ /**
46
+ * Deactivation hook. Deletes our option containing the robots.txt content
47
+ *
48
+ * @since 1.0
49
+ * @uses delete_option
50
+ * @return void
51
+ */
52
+ function cd_rdte_deactivation()
53
+ {
54
+ delete_option('cd_rdte_content');
55
+ }
56
+
57
+ /**
58
+ * Activation hook. Adds the option we'll be uses
59
+ *
60
+ * @since 1.0
61
+ * @uses add_option
62
+ * @return void
63
+ */
64
+ function cd_rdte_activation()
65
+ {
66
+ add_option('cd_rdte_content', false);
67
+ }
inc/options-page.php CHANGED
@@ -1,4 +1,28 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /**
3
  * Wrapper for all our admin area functionality.
4
  *
@@ -6,64 +30,94 @@
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
@@ -72,46 +126,43 @@ class CD_RDTE_Admin_Page
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();
1
  <?php
2
+ /**
3
+ * WP Robots Txt
4
+ *
5
+ * Copyright 2013 Christopher Davis <http://christopherdavis.me>
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License, version 2, as
9
+ * published by the Free Software Foundation.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ * @category WordPress
21
+ * @package WPRobotsTxt
22
+ * @copyright 2013 Christopher Davis
23
+ * @license http://opensource.org/licenses/GPL-2.0 GPL-2.0+
24
+ */
25
+
26
  /**
27
  * Wrapper for all our admin area functionality.
28
  *
30
  */
31
  class CD_RDTE_Admin_Page
32
  {
33
+ private static $ins = null;
34
+
35
  protected $setting = 'cd_rdte_content';
36
+
37
+ public static function instance()
38
+ {
39
+ if (null === self::$ins) {
40
+ self::$ins = new self();
41
+ }
42
+
43
+ return self::$ins;
44
+ }
45
+
46
  /**
47
+ * Kick everything off.
48
  *
49
+ * @since 1.0
50
+ * @access public
51
+ * @uses add_action
52
+ * @return void
53
  */
54
+ public static function init()
55
  {
56
+ add_action('admin_init', array(self::instance(), 'settings'));
57
  }
58
 
59
  /**
60
  * Registers our setting and takes care of adding the settings field
61
  * we need to edit our robots.txt file
62
  *
63
+ * @since 1.0
64
+ * @access public
65
+ * @uses register_setting
66
+ * @uses add_settings_field
67
+ * @return void
68
  */
69
+ public function settings()
70
  {
71
  register_setting(
72
+ 'reading',
73
  $this->setting,
74
+ array($this, 'cleanSetting')
75
+ );
76
+
77
+ add_settings_section(
78
+ 'robots-txt',
79
+ __('Robots.txt Content', 'wp-robots-txt'),
80
+ '__return_false',
81
+ 'reading'
82
  );
83
+
84
  add_settings_field(
85
  'cd_rdte_robots_content',
86
+ __('Robots.txt Content', 'wp-robots-txt'),
87
+ array($this, 'field'),
88
+ 'reading',
89
+ 'robots-txt',
90
+ array('label_for' => $this->setting)
91
  );
92
  }
93
+
94
  /**
95
+ * Callback for the settings field.
96
  *
97
+ * @since 1.0
98
+ * @access public
99
+ * @uses get_option
100
+ * @uses esc_attr
101
+ * @return void
102
  */
103
+ public function field()
104
  {
105
+ $content = get_option($this->setting);
106
+ if (!$content) {
107
+ $content = $this->getDefaultRobots();
108
+ }
109
+
110
+ printf(
111
+ '<textarea name="%1$s" id="%1$s" rows="10" class="large-text">%2$s</textarea>',
112
+ esc_attr($this->setting),
113
+ esc_textarea($content)
114
+ );
115
+
116
+ echo '<p class="description">';
117
+ _e('The content of your robots.txt file. Delete the above and save to restore the default.', 'wp-robots-txt');
118
+ echo '</p>';
119
  }
120
+
121
  /**
122
  * Strips tags and escapes any html entities that goes into the
123
  * robots.txt field
126
  * @uses esc_html
127
  * @uses add_settings_error
128
  */
129
+ public function cleanSetting($in)
130
  {
131
+ if(empty($in)) {
 
132
  // TODO: why does this kill the default settings message?
133
  add_settings_error(
134
  $this->setting,
135
  'cd-rdte-restored',
136
+ __('Robots.txt restored to default.', 'wp-robots-txt'),
137
  'updated'
138
  );
139
  }
140
+
141
+ return esc_html(strip_tags($in));
142
  }
143
 
144
  /**
145
  * Get the default robots.txt content. This is copied straight from
146
  * WP's `do_robots` function
147
  *
148
+ * @since 1.0
149
+ * @access protected
150
+ * @uses get_option
151
+ * @return string The default robots.txt content
152
  */
153
+ protected function getDefaultRobots()
154
  {
155
+ $public = get_option('blog_public');
156
+
157
  $output = "User-agent: *\n";
158
+ if ('0' == $public) {
 
 
159
  $output .= "Disallow: /\n";
160
+ } else {
161
+ $path = parse_url(site_url(), PHP_URL_PATH);
 
 
 
162
  $output .= "Disallow: $path/wp-admin/\n";
163
  $output .= "Disallow: $path/wp-includes/\n";
164
  }
165
+
166
  return $output;
167
  }
168
  }
 
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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
 
@@ -12,7 +12,7 @@ WP Robots Txt Allows you to edit the content of your robots.txt file.
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
 
@@ -46,7 +46,14 @@ Yes. Be careful! That said, `robots.txt` files are suggestions. They don't real
46
  = 1.0 =
47
  * Initial version
48
 
 
 
 
 
49
  == Upgrade Notice ==
50
 
51
  = 1.0 =
52
  * Everyone wants to edit their `robots.txt` files.
 
 
 
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.6
7
+ Stable tag: 1.1
8
 
9
  WP Robots Txt Allows you to edit the content of your robots.txt file.
10
 
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 "Reading" admin page where you can do just that.
16
 
17
  == Installation ==
18
 
46
  = 1.0 =
47
  * Initial version
48
 
49
+ = 1.1 =
50
+ * Moved the settings field "officially" to the reading page
51
+ * General code clean up
52
+
53
  == Upgrade Notice ==
54
 
55
  = 1.0 =
56
  * Everyone wants to edit their `robots.txt` files.
57
+
58
+ = 1.1 =
59
+ * Should actually work in 3.5+ now
robots-txt.php CHANGED
@@ -1,73 +1,45 @@
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
  }
 
 
 
 
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.1
7
+ * Text Domain: wp-robots-txt
8
+ * Author: Christopher Davis
9
+ * Author URI: http://christopherdavis.me
10
+ * License: GPL-2.0+
11
+ *
12
+ * Copyright 2013 Christopher Davis <http://christopherdavis.me>
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ *
27
+ * @category WordPress
28
+ * @package WPRobotsTxt
29
+ * @copyright 2013 Christopher Davis
30
+ * @license http://opensource.org/licenses/GPL-2.0 GPL-2.0+
31
  */
 
 
 
 
 
 
 
 
 
32
 
33
+ !defined('ABSPATH') && exit;
 
 
 
 
 
 
 
 
 
 
34
 
35
+ define('WP_ROBOTS_TXT_DIR', plugin_dir_path(__FILE__));
36
+
37
+ require_once WP_ROBOTS_TXT_DIR . 'inc/core.php';
38
+ if (is_admin()) {
39
+ require_once WP_ROBOTS_TXT_DIR . 'inc/options-page.php';
40
+ CD_RDTE_Admin_Page::init();
 
 
 
 
41
  }
42
+
43
+ add_filter('robots_txt', 'cd_rdte_filter_robots', 10, 2);
44
+ register_activation_hook(__FILE__, 'cd_rdte_activation');
45
+ register_deactivation_hook(__FILE__, 'cd_rdte_deactivation');