1 | <?php |
---|
2 | /** |
---|
3 | * @author hakre <http://codex.wordpress.org/User:Hakre> |
---|
4 | * @see http://core.trac.wordpress.org/ticket/7092 |
---|
5 | * @license GPL v3 |
---|
6 | * @version 0.1.2 |
---|
7 | * |
---|
8 | * @-wp-plugin Plugin Name: commentsfeedlength |
---|
9 | * @-wp-plugin Plugin URI: http://core.trac.wordpress.org/ticket/7092 |
---|
10 | * @-wp-plugin Description: separate setting for limiting comments feed |
---|
11 | * @-wp-plugin Author: hakre |
---|
12 | * @-wp-plugin Version: 0.1 |
---|
13 | * @-wp-plugin Author URI: http://codex.wordpress.org/User:Hakre |
---|
14 | */ |
---|
15 | |
---|
16 | commentsfeedlengthPlugin::bootstrap(); |
---|
17 | |
---|
18 | /** |
---|
19 | * commentsfeed length plugin class |
---|
20 | */ |
---|
21 | class commentsfeedlengthPlugin { |
---|
22 | /** |
---|
23 | * instance local store |
---|
24 | * @var rssfeedlengthPlugin |
---|
25 | */ |
---|
26 | static $_instance = null; |
---|
27 | |
---|
28 | protected $_option = 'comments_per_rss'; |
---|
29 | |
---|
30 | /** |
---|
31 | * option getter - local helper |
---|
32 | * |
---|
33 | * @return int option value |
---|
34 | */ |
---|
35 | private function _get_option() { |
---|
36 | $value = abs(intval(get_option($this->_option))); |
---|
37 | return (int) $value; |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * plugin bootstrap to reduce interference with the global symbol table |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | public static function bootstrap() { |
---|
45 | if( null == commentsfeedlengthPlugin::$_instance ) { |
---|
46 | commentsfeedlengthPlugin::$_instance = new commentsfeedlengthPlugin(); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * plugin constructor |
---|
52 | */ |
---|
53 | public function __construct() { |
---|
54 | add_action('admin_init', array($this, 'admin_init')); |
---|
55 | add_filter('comment_feed_limits', array($this, 'comment_feed_limits')); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * admin_init |
---|
60 | * |
---|
61 | * @-wp-action admin_init |
---|
62 | * @return void |
---|
63 | */ |
---|
64 | public function admin_init() { |
---|
65 | |
---|
66 | if (false === get_option($this->_option)) { |
---|
67 | update_option($this->_option, get_option('posts_per_rss')); |
---|
68 | } |
---|
69 | |
---|
70 | $key = $this->_option; |
---|
71 | $title = __('Syndication feeds show the most recent'); |
---|
72 | $callb = array($this, 'settings_field_input_callback'); |
---|
73 | $args = array( |
---|
74 | 'label_for' => $key, |
---|
75 | 'for_text' => __('comments') |
---|
76 | ); |
---|
77 | |
---|
78 | add_settings_field($key, $title, $callb, 'reading', 'default', $args); |
---|
79 | register_setting('reading', $key); |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * comment_feed_limits |
---|
84 | * |
---|
85 | * @-wp-action comment_feed_limits |
---|
86 | * @param string $limit LIMIT clause for SQL query |
---|
87 | * @return string filtered $limit parameter |
---|
88 | */ |
---|
89 | public function comment_feed_limits($limit) { |
---|
90 | return sprintf('LIMIT %d', $this->_get_option()); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * field input callback |
---|
95 | * |
---|
96 | * used by self::admin_init() |
---|
97 | * |
---|
98 | * @param array $args |
---|
99 | * @return void |
---|
100 | */ |
---|
101 | public function settings_field_input_callback($args) { |
---|
102 | extract($args); |
---|
103 | printf( |
---|
104 | '<input name="%1$s" type="text" id="%1$s" value="%2$d" class="small-text" /> %3$s' |
---|
105 | , $label_for, $this->_get_option(), $for_text |
---|
106 | ); |
---|
107 | } |
---|
108 | |
---|
109 | } // class commentsfeedlengthPlugin |
---|