@@ -9,7 +9,7 @@ |
||
9 | 9 | <h1>CPT Date Archives Settings</h1> |
10 | 10 | |
11 | 11 | <form action="options.php" method="post"> |
12 | - <?php settings_fields( $page->id ); ?> |
|
13 | - <?php do_settings_sections( $page->id ); ?> |
|
14 | - <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( __( 'Save Changes', 'cpt_date_archives' ) ); ?>" /> |
|
12 | + <?php settings_fields($page->id); ?> |
|
13 | + <?php do_settings_sections($page->id); ?> |
|
14 | + <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e(__('Save Changes', 'cpt_date_archives')); ?>" /> |
|
15 | 15 | </form> |
@@ -6,10 +6,10 @@ |
||
6 | 6 | */ |
7 | 7 | $disabled = ''; |
8 | 8 | |
9 | -if ( ! $post_type->has_archive ) { |
|
9 | +if ( ! $post_type->has_archive) { |
|
10 | 10 | $disabled = ' disabled'; |
11 | 11 | } |
12 | 12 | ?> |
13 | 13 | <p> |
14 | - <input type="checkbox" name="cpt_date_archive_post_types[]" value="<?php esc_attr_e( $post_type->name ); ?>"<?php checked( $post_type->checked, true ); ?><?php esc_html_e( $disabled ); ?>><?php esc_html_e( $post_type->labels->name ); ?> |
|
14 | + <input type="checkbox" name="cpt_date_archive_post_types[]" value="<?php esc_attr_e($post_type->name); ?>"<?php checked($post_type->checked, true); ?><?php esc_html_e($disabled); ?>><?php esc_html_e($post_type->labels->name); ?> |
|
15 | 15 | </p> |
@@ -24,11 +24,11 @@ |
||
24 | 24 | Author URI: http://github.com/clubduece |
25 | 25 | License: GPLv2 or later |
26 | 26 | */ |
27 | -if ( ! defined( 'CPT_DATE_ARCHIVES' ) ) { |
|
28 | - define( 'CPT_DATE_ARCHIVES', true ); |
|
27 | +if ( ! defined('CPT_DATE_ARCHIVES')) { |
|
28 | + define('CPT_DATE_ARCHIVES', true); |
|
29 | 29 | } |
30 | 30 | |
31 | -if ( CPT_DATE_ARCHIVES ) { |
|
31 | +if (CPT_DATE_ARCHIVES) { |
|
32 | 32 | require_once 'includes/class-cpt-date-archives.php'; |
33 | 33 | require_once 'includes/class-settings.php'; |
34 | 34 |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | */ |
35 | 35 | protected function __construct() { |
36 | 36 | |
37 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
38 | - add_action( 'update_option_cpt_date_archive_post_types', array( $this, 'update_option' ) ); |
|
37 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
38 | + add_action('update_option_cpt_date_archive_post_types', array($this, 'update_option')); |
|
39 | 39 | |
40 | 40 | $this->page = new stdClass; |
41 | 41 | $this->page->id = 'cpt_date_archives'; |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function admin_menu() { |
53 | 53 | |
54 | - register_setting( $this->page->id, 'cpt_date_archive_post_types', array( $this, 'sanitize_input' ) ); |
|
54 | + register_setting($this->page->id, 'cpt_date_archive_post_types', array($this, 'sanitize_input')); |
|
55 | 55 | |
56 | - add_options_page( __( 'CPT Date Archives Settings', 'cpt_date_archives' ), __( 'CPT Date Archives', 'cpt_date_archives' ), 'manage_options', $this->page->id, array( $this, 'render' ) ); |
|
57 | - add_settings_section( 'general', __( 'General', 'cpt_date_archives' ), null, $this->page->id ); |
|
58 | - add_settings_field( 'post-types', __( 'Post Types', 'cpt_date_archives' ), array( $this, 'render_field_post_types' ), $this->page->id, 'general' ); |
|
56 | + add_options_page(__('CPT Date Archives Settings', 'cpt_date_archives'), __('CPT Date Archives', 'cpt_date_archives'), 'manage_options', $this->page->id, array($this, 'render')); |
|
57 | + add_settings_section('general', __('General', 'cpt_date_archives'), null, $this->page->id); |
|
58 | + add_settings_field('post-types', __('Post Types', 'cpt_date_archives'), array($this, 'render_field_post_types'), $this->page->id, 'general'); |
|
59 | 59 | |
60 | 60 | } |
61 | 61 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | $page = $this->page; |
71 | 71 | |
72 | - include dirname( __DIR__ ) . '/templates/settings-page.php'; |
|
72 | + include dirname(__DIR__).'/templates/settings-page.php'; |
|
73 | 73 | |
74 | 74 | } |
75 | 75 | |
@@ -81,17 +81,17 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function render_field_post_types() { |
83 | 83 | |
84 | - $post_types = get_post_types( array( 'public' => 'true', '_builtin' => false ), 'objects' ); |
|
84 | + $post_types = get_post_types(array('public' => 'true', '_builtin' => false), 'objects'); |
|
85 | 85 | $selected = $this->get_post_type_objects(); |
86 | 86 | |
87 | - esc_html_e( __( 'Inputs are disabled for post types that do not support archives.', 'cpt_date_archive_post_types' ) ); |
|
87 | + esc_html_e(__('Inputs are disabled for post types that do not support archives.', 'cpt_date_archive_post_types')); |
|
88 | 88 | |
89 | - foreach ( $post_types as $post_type ) { |
|
90 | - if ( $this->has_date_archive( $post_type ) ) { |
|
89 | + foreach ($post_types as $post_type) { |
|
90 | + if ($this->has_date_archive($post_type)) { |
|
91 | 91 | $post_type->checked = true; |
92 | 92 | } |
93 | 93 | |
94 | - include dirname( __DIR__ ) . '/templates/post-types-field.php'; |
|
94 | + include dirname(__DIR__).'/templates/post-types-field.php'; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | } |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | * @access public |
104 | 104 | * @since 0.2 |
105 | 105 | */ |
106 | - public function sanitize_input( $input ) { |
|
106 | + public function sanitize_input($input) { |
|
107 | 107 | |
108 | - if ( ! empty( $input ) ) { |
|
109 | - foreach ( $input as $key => $post_type ) { |
|
110 | - $input[ $key ] = sanitize_text_field( $post_type ); |
|
108 | + if ( ! empty($input)) { |
|
109 | + foreach ($input as $key => $post_type) { |
|
110 | + $input[$key] = sanitize_text_field($post_type); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | |
127 | 127 | $post_types = $this->get_post_types(); |
128 | 128 | |
129 | - foreach ( $post_types as $key => $post_type ) { |
|
130 | - $post_types[ $key ] = get_post_type_object( $post_type ); |
|
129 | + foreach ($post_types as $key => $post_type) { |
|
130 | + $post_types[$key] = get_post_type_object($post_type); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | return $post_types; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function get_post_types() { |
145 | 145 | |
146 | - return get_option( 'cpt_date_archive_post_types', array() ); |
|
146 | + return get_option('cpt_date_archive_post_types', array()); |
|
147 | 147 | |
148 | 148 | } |
149 | 149 | |
@@ -154,15 +154,15 @@ discard block |
||
154 | 154 | * @access public |
155 | 155 | * @since 0.2 |
156 | 156 | */ |
157 | - public function has_date_archive( $post_type ) { |
|
157 | + public function has_date_archive($post_type) { |
|
158 | 158 | |
159 | 159 | $value = false; |
160 | 160 | |
161 | - if ( ! is_object( $post_type ) ) { |
|
162 | - $post_type = get_post_type_object( $post_type ); |
|
161 | + if ( ! is_object($post_type)) { |
|
162 | + $post_type = get_post_type_object($post_type); |
|
163 | 163 | } |
164 | 164 | |
165 | - if ( in_array( $post_type->name, $this->get_post_types() ) ) { |
|
165 | + if (in_array($post_type->name, $this->get_post_types())) { |
|
166 | 166 | $value = true; |
167 | 167 | } |
168 | 168 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function update_option() { |
182 | 182 | |
183 | - delete_option( 'rewrite_rules' ); |
|
183 | + delete_option('rewrite_rules'); |
|
184 | 184 | |
185 | 185 | } |
186 | 186 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @access private |
199 | 199 | * @since 0.2 |
200 | 200 | */ |
201 | - private function __wakeup () {} |
|
201 | + private function __wakeup() {} |
|
202 | 202 | |
203 | 203 | /** |
204 | 204 | * Singleton model |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public static function init() { |
210 | 210 | |
211 | - if ( ! isset( self::$instance ) ) { |
|
211 | + if ( ! isset(self::$instance)) { |
|
212 | 212 | self::$instance = new CPT_Date_Archive_Settings; |
213 | 213 | } |
214 | 214 |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | */ |
16 | 16 | public function __construct() { |
17 | 17 | |
18 | - add_action( 'init', array( $this, 'custom_rewrite_rules' ) ); |
|
19 | - add_action( 'init', array( $this, 'settings_page' ) ); |
|
18 | + add_action('init', array($this, 'custom_rewrite_rules')); |
|
19 | + add_action('init', array($this, 'settings_page')); |
|
20 | 20 | |
21 | 21 | } |
22 | 22 | |
@@ -31,22 +31,22 @@ discard block |
||
31 | 31 | $settings_page = CPT_Date_Archive_Settings::init(); |
32 | 32 | $post_types = $settings_page->get_post_type_objects(); |
33 | 33 | |
34 | - foreach( $post_types as $post_type ) { |
|
34 | + foreach ($post_types as $post_type) { |
|
35 | 35 | //Day archive |
36 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/([0-9]{2})/feed/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]$matches[2]$matches[3]&feed=$matches[4]','top'); |
|
37 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/([0-9]{2})/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]$matches[2]$matches[3]&feed=$matches[4]','top'); |
|
38 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/?([0-9]{1,})/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]$matches[2]$matches[3]&paged=$matches[4]','top'); |
|
39 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/([0-9]{1,2})/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]$matches[2]$matches[3]', 'top' ); |
|
36 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/([0-9]{2})/feed/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]$matches[2]$matches[3]&feed=$matches[4]', 'top'); |
|
37 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/([0-9]{2})/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]$matches[2]$matches[3]&feed=$matches[4]', 'top'); |
|
38 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/?([0-9]{1,})/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]$matches[2]$matches[3]&paged=$matches[4]', 'top'); |
|
39 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/([0-9]{1,2})/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]$matches[2]$matches[3]', 'top'); |
|
40 | 40 | //Monthly archive |
41 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/feed/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]$matches[2]&feed=$matches[3]','top'); |
|
42 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]$matches[2]&feed=$matches[3]','top'); |
|
43 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]$matches[2]&paged=$matches[3]','top'); |
|
44 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]$matches[2]', 'top' ); |
|
41 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/feed/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]$matches[2]&feed=$matches[3]', 'top'); |
|
42 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]$matches[2]&feed=$matches[3]', 'top'); |
|
43 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]$matches[2]&paged=$matches[3]', 'top'); |
|
44 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/([0-9]{2})/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]$matches[2]', 'top'); |
|
45 | 45 | //Yearly archive |
46 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]&feed=$matches[2]','top'); |
|
47 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]&feed=$matches[2]','top'); |
|
48 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/page/?([0-9]{1,})/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]&paged=$matches[2]','top'); |
|
49 | - add_rewrite_rule( "{$post_type->rewrite['slug']}/([0-9]{4})/?$", 'index.php?post_type=' . $post_type->name . '&m=$matches[1]', 'top' ); |
|
46 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]&feed=$matches[2]', 'top'); |
|
47 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]&feed=$matches[2]', 'top'); |
|
48 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/page/?([0-9]{1,})/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]&paged=$matches[2]', 'top'); |
|
49 | + add_rewrite_rule("{$post_type->rewrite['slug']}/([0-9]{4})/?$", 'index.php?post_type='.$post_type->name.'&m=$matches[1]', 'top'); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function settings_page() { |
61 | 61 | |
62 | - if ( is_admin() ) { |
|
62 | + if (is_admin()) { |
|
63 | 63 | CPT_Date_Archive_Settings::init(); |
64 | 64 | } |
65 | 65 |