PluginProbe ʕ •ᴥ•ʔ
Custom Post Type Permalinks / 3.4.1
Custom Post Type Permalinks v3.4.1
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 5 years ago FlushRules.php 8 years ago GetArchives.php 5 years ago Option.php 5 years ago Permalink.php 5 years ago Rewrite.php 5 years ago Setting.php 6 years ago
Admin.php
232 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 $sptp_link = admin_url( 'plugin-install.php?s=simple-post-type-permalinks&tab=search&type=term' );
87 // translators: %s simple post type permalinks install page.
88 $sptp_template = __( 'If you need post type permalink only, you should use <a href="%s">Simple Post Type Permalinks</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( $sptp_template, esc_url( $sptp_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 ( ! $value ) {
151 $value = CPTP_DEFAULT_PERMALINK;
152 }
153
154 global $wp_rewrite;
155 $front = substr( $wp_rewrite->front, 1 );
156 if ( $front && $with_front ) {
157 $slug = $front . $slug;
158 }
159 ?>
160 <p>
161 <code><?php echo esc_html( home_url() . ( $slug ? '/' : '' ) . $slug ); ?></code>
162 <input name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $name ); ?>" type="text" class="regular-text code " value="<?php echo esc_attr( $value ); ?>" <?php disabled( $disabled, true, true ); ?> />
163 </p>
164 <p>has_archive: <code><?php echo esc_html( $pt_object->has_archive ? 'true' : 'false' ); ?></code> / with_front:
165 <code><?php echo esc_html( $pt_object->rewrite['with_front'] ? 'true' : 'false' ); ?></code></p>
166 <?php
167 }
168
169 /**
170 * Show checkbox no tax.
171 */
172 public function setting_no_tax_structure_callback_function() {
173 $no_taxonomy_structure = CPTP_Util::get_no_taxonomy_structure();
174 echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, $no_taxonomy_structure, false ) . ' /> ';
175 /* translators: %s site url */
176 $txt = __( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>.", 'custom-post-type-permalinks' );
177 echo sprintf( wp_kses( $txt, array( 'code' => array() ) ), esc_html( home_url() ) );
178 }
179
180 /**
181 * Show checkbox for post type query.
182 */
183 public function add_post_type_for_tax_callback_function() {
184 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 ) . ' /> ';
185 esc_html_e( 'Custom taxonomy archive also works as post type archive. ', 'custom-post-type-permalinks' );
186 esc_html_e( 'There are cases when the template to be loaded is changed.', 'custom-post-type-permalinks' );
187 }
188
189 /**
190 * Enqueue css and js
191 *
192 * @since 0.8.5
193 */
194 public function enqueue_css_js() {
195 $pointer_name = 'custom-post-type-permalinks-settings';
196 if ( ! is_network_admin() ) {
197 $dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
198 if ( false === array_search( $pointer_name, $dismissed, true ) ) {
199 $content = '';
200 $content .= '<h3>' . __( 'Custom Post Type Permalinks', 'custom-post-type-permalinks' ) . '</h3>';
201 $content .= '<p>' . __( 'You can setting permalink for post type in <a href="options-permalink.php">Permalinks</a>.', 'custom-post-type-permalinks' ) . '</p>';
202
203 wp_enqueue_style( 'wp-pointer' );
204 wp_enqueue_script( 'wp-pointer' );
205 wp_enqueue_script( 'custom-post-type-permalinks-pointer', plugins_url( 'assets/settings-pointer.js', CPTP_PLUGIN_FILE ), array( 'wp-pointer' ), CPTP_VERSION );
206
207 wp_localize_script(
208 'custom-post-type-permalinks-pointer',
209 'CPTP_Settings_Pointer',
210 array(
211 'content' => $content,
212 'name' => $pointer_name,
213 )
214 );
215 }
216 }
217 }
218
219 /**
220 * Admin notice for update permalink settings!
221 */
222 public function admin_notices() {
223 if ( version_compare( get_option( 'cptp_permalink_checked' ), '3.0.0', '<' ) ) {
224 // translators: %s URL.
225 $format = __( '[Custom Post Type Permalinks] <a href="%s"><strong>Please check your permalink settings!</strong></a>', 'custom-post-type-permalinks' );
226 $message = sprintf( $format, admin_url( 'options-permalink.php' ) );
227 echo sprintf( '<div class="notice notice-warning"><p>%s</p></div>', wp_kses( $message, wp_kses_allowed_html( 'post' ) ) );
228 }
229 }
230 }
231
232