PluginProbe ʕ •ᴥ•ʔ
Custom Post Type Permalinks / trunk
Custom Post Type Permalinks vtrunk
1.2.0 1.3.0 1.3.1 1.4.0 1.5.1 1.5.2 1.5.4 2.0.0 2.0.1 2.0.2 2.1.1 2.1.2 2.1.3 2.2.0 3.0.0 3.0.1 3.1.0 3.1.1 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.3.0 3.3.1 3.3.4 3.3.5 3.4.0 3.4.0-rc.1 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.5.2 3.5.3 3.5.4 3.5.5 trunk 0.6 0.6.1 0.6.2 0.7 0.7.1 0.7.10 0.7.2 0.7.2.1 0.7.3 0.7.3.1 0.7.4 0.7.4.1 0.7.5 0.7.5.1 0.7.5.2 0.7.5.6 0.7.6 0.7.8 0.7.9 0.7.9.1 0.7.9.2 0.8 0.8.1 0.8.6 0.8.7 0.8.7.1 0.8.7.5 0.8.7.6 0.9 0.9.1 0.9.2.1 0.9.3.1 0.9.3.2 0.9.3.3 0.9.5 0.9.5.1 0.9.5.2 0.9.5.3 0.9.5.4 0.9.5.6 0.9.6 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0
custom-post-type-permalinks / CPTP / Module / Admin.php
custom-post-type-permalinks / CPTP / Module Last commit date
Admin.php 1 month ago FlushRules.php 8 years ago GetArchives.php 5 years ago Option.php 5 years ago Permalink.php 1 year ago Rewrite.php 1 year ago Setting.php 6 years ago
Admin.php
239 lines
1 <?php
2 /**
3 * Admin Page View.
4 *
5 * @package Custom_Post_Type_Permalinks
6 * @since 0.9.4
7 * */
8
9 /**
10 * Admin Page Class.
11 *
12 * @since 0.9.4
13 * */
14 class CPTP_Module_Admin extends CPTP_Module {
15
16 /**
17 * Add actions.
18 */
19 public function add_hook() {
20 add_action( 'admin_init', array( $this, 'settings_api_init' ), 30 );
21 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_css_js' ) );
22 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
23 }
24
25 /**
26 * Setting Init
27 *
28 * @since 0.7
29 */
30 public function settings_api_init() {
31 add_settings_section(
32 'cptp_setting_section',
33 __( 'Permalink Settings for Custom Post Types', 'custom-post-type-permalinks' ),
34 array( $this, 'setting_section_callback_function' ),
35 'permalink'
36 );
37
38 $post_types = CPTP_Util::get_post_types();
39
40 foreach ( $post_types as $post_type ) {
41 add_settings_field(
42 $post_type . '_structure',
43 $post_type,
44 array( $this, 'setting_structure_callback_function' ),
45 'permalink',
46 'cptp_setting_section',
47 array(
48 'label_for' => $post_type . '_structure',
49 'post_type' => $post_type,
50 )
51 );
52 register_setting( 'permalink', $post_type . '_structure' );
53 }
54
55 add_settings_field(
56 'no_taxonomy_structure',
57 __( 'Use custom permalink of custom taxonomy archive.', 'custom-post-type-permalinks' ),
58 array( $this, 'setting_no_tax_structure_callback_function' ),
59 'permalink',
60 'cptp_setting_section',
61 array(
62 'label_for' => 'no_taxonomy_structure',
63 )
64 );
65
66 register_setting( 'permalink', 'no_taxonomy_structure' );
67
68 add_settings_field(
69 'add_post_type_for_tax',
70 __( 'Add <code>post_type</code> query for custom taxonomy archive.', 'custom-post-type-permalinks' ),
71 array( $this, 'add_post_type_for_tax_callback_function' ),
72 'permalink',
73 'cptp_setting_section',
74 array(
75 'label_for' => 'add_post_type_for_tax',
76 )
77 );
78
79 register_setting( 'permalink', 'add_post_type_for_tax' );
80 }
81
82 /**
83 * Setting section view.
84 */
85 public function setting_section_callback_function() {
86 $slug_automator_link = admin_url( 'plugin-install.php?s=slug-automator&tab=search&type=term' );
87 // translators: %s slug-automator plugin install page.
88 $slug_automator_template = __( 'If you want URLs without percent-encoding, try <a href="%s">Slug Automator</a>.', 'custom-post-type-permalinks' );
89 ?>
90 <p>
91 <strong>
92 <?php
93 $allowed_html = array(
94 'a' => array(
95 'href' => true,
96 ),
97 );
98 echo wp_kses( sprintf( $slug_automator_template, esc_url( $slug_automator_link ) ), $allowed_html );
99 ?>
100 </strong>
101 </p>
102 <?php
103 $allowed_html_code_tag = array(
104 'code' => array(),
105 );
106 ?>
107
108 <?php
109 $taxonomies = CPTP_Util::get_taxonomies();
110 ?>
111 <p><?php esc_html_e( 'The tags you can use are WordPress structure tags and taxonomy tags.', 'custom-post-type-permalinks' ); ?></p>
112 <p><?php esc_html_e( 'Available taxonomy tags:', 'custom-post-type-permalinks' ); ?>
113 <?php
114 foreach ( $taxonomies as $taxonomy ) {
115 echo sprintf( '<code>%%%s%%</code>', esc_html( $taxonomy ) );
116 }
117 ?>
118 </p>
119
120 <p><?php esc_html_e( "Presence of the trailing '/' is unified into a standard permalink structure setting.", 'custom-post-type-permalinks' ); ?>
121 <p><?php echo wp_kses( __( 'If <code>has_archive</code> is true, add permalinks for custom post type archive.', 'custom-post-type-permalinks' ), $allowed_html_code_tag ); ?></p>
122
123 <?php
124 }
125
126 /**
127 * Show setting structure input.
128 *
129 * @param array $option {
130 * Callback option.
131 *
132 * @type string 'post_type' post type name.
133 * @type string 'label_for' post type label.
134 * }
135 */
136 public function setting_structure_callback_function( $option ) {
137 $post_type = $option['post_type'];
138 $name = $option['label_for'];
139 $pt_object = get_post_type_object( $post_type );
140 $slug = $pt_object->rewrite['slug'];
141 $with_front = $pt_object->rewrite['with_front'];
142
143 $value = CPTP_Util::get_permalink_structure( $post_type );
144
145 $disabled = false;
146 if ( isset( $pt_object->cptp_permalink_structure ) && $pt_object->cptp_permalink_structure ) {
147 $disabled = true;
148 }
149
150 if ( isset( $pt_object->cptp ) && ! empty( $pt_object->cptp['permalink_structure'] ) ) {
151 $disabled = true;
152 }
153
154 if ( ! $value ) {
155 $value = CPTP_DEFAULT_PERMALINK;
156 }
157
158 global $wp_rewrite;
159 $front = substr( $wp_rewrite->front, 1 );
160 if ( $front && $with_front ) {
161 $slug = $front . $slug;
162 }
163 ?>
164 <p>
165 <code><?php echo esc_html( home_url() . ( $slug ? '/' : '' ) . $slug ); ?></code>
166 <input
167 name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $name ); ?>" type="text"
168 class="regular-text code "
169 value="<?php echo esc_attr( $value ); ?>" <?php disabled( $disabled, true, true ); ?> />
170 </p>
171 <p>has_archive: <code><?php echo esc_html( $pt_object->has_archive ? 'true' : 'false' ); ?></code> / with_front:
172 <code><?php echo esc_html( $pt_object->rewrite['with_front'] ? 'true' : 'false' ); ?></code></p>
173 <?php
174 }
175
176 /**
177 * Show checkbox no tax.
178 */
179 public function setting_no_tax_structure_callback_function() {
180 $no_taxonomy_structure = CPTP_Util::get_no_taxonomy_structure();
181 echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, $no_taxonomy_structure, false ) . ' /> ';
182 /* translators: %s site url */
183 $txt = __( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>.", 'custom-post-type-permalinks' );
184 echo sprintf( wp_kses( $txt, array( 'code' => array() ) ), esc_html( home_url() ) );
185 }
186
187 /**
188 * Show checkbox for post type query.
189 */
190 public function add_post_type_for_tax_callback_function() {
191 echo '<input name="add_post_type_for_tax" id="add_post_type_for_tax" type="checkbox" value="1" class="code" ' . checked( true, get_option( 'add_post_type_for_tax' ), false ) . ' /> ';
192 esc_html_e( 'Custom taxonomy archive also works as post type archive. ', 'custom-post-type-permalinks' );
193 esc_html_e( 'There are cases when the template to be loaded is changed.', 'custom-post-type-permalinks' );
194 }
195
196 /**
197 * Enqueue css and js
198 *
199 * @since 0.8.5
200 */
201 public function enqueue_css_js() {
202 $pointer_name = 'custom-post-type-permalinks-settings';
203 if ( ! is_network_admin() ) {
204 $dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
205 if ( false === array_search( $pointer_name, $dismissed, true ) ) {
206 $content = '';
207 $content .= '<h3>' . __( 'Custom Post Type Permalinks', 'custom-post-type-permalinks' ) . '</h3>';
208 $content .= '<p>' . __( 'You can setting permalink for post type in <a href="options-permalink.php">Permalinks</a>.', 'custom-post-type-permalinks' ) . '</p>';
209
210 wp_enqueue_style( 'wp-pointer' );
211 wp_enqueue_script( 'wp-pointer' );
212 wp_enqueue_script( 'custom-post-type-permalinks-pointer', plugins_url( 'assets/settings-pointer.js', CPTP_PLUGIN_FILE ), array( 'wp-pointer' ), CPTP_VERSION );
213
214 wp_localize_script(
215 'custom-post-type-permalinks-pointer',
216 'CPTP_Settings_Pointer',
217 array(
218 'content' => $content,
219 'name' => $pointer_name,
220 )
221 );
222 }
223 }
224 }
225
226 /**
227 * Admin notice for update permalink settings!
228 */
229 public function admin_notices() {
230 if ( version_compare( get_option( 'cptp_permalink_checked' ), '3.0.0', '<' ) ) {
231 // translators: %s URL.
232 $format = __( '[Custom Post Type Permalinks] <a href="%s"><strong>Please check your permalink settings!</strong></a>', 'custom-post-type-permalinks' );
233 $message = sprintf( $format, admin_url( 'options-permalink.php' ) );
234 echo sprintf( '<div class="notice notice-warning"><p>%s</p></div>', wp_kses( $message, wp_kses_allowed_html( 'post' ) ) );
235 }
236 }
237 }
238
239