PluginProbe ʕ •ᴥ•ʔ
Custom Post Type Permalinks / 3.3.1
Custom Post Type Permalinks v3.3.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 8 years ago FlushRules.php 8 years ago GetArchives.php 8 years ago Option.php 8 years ago Permalink.php 8 years ago Rewrite.php 7 years ago Setting.php 8 years ago
Admin.php
219 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( 'cptp_setting_section',
32 __( 'Permalink Settings for Custom Post Types', 'custom-post-type-permalinks' ),
33 array( $this, 'setting_section_callback_function' ),
34 'permalink'
35 );
36
37 $post_types = CPTP_Util::get_post_types();
38
39 foreach ( $post_types as $post_type ) {
40
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', 'no_taxonomy_structure' );
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 <p><?php echo wp_kses( __( 'The tags you can use are WordPress Structure Tags and <code>%"custom_taxonomy_slug"%</code> (e.g. <code>%actors%</code> or <code>%movie_actors%</code>).', 'custom-post-type-permalinks' ), $allowed_html_code_tag ); ?>
109 <?php echo wp_kses( __( '<code>%"custom_taxonomy_slug"%</code> is replaced by the term of taxonomy.', 'custom-post-type-permalinks' ), $allowed_html_code_tag ); ?></p>
110
111 <p><?php esc_html_e( "Presence of the trailing '/' is unified into a standard permalink structure setting.", 'custom-post-type-permalinks' ); ?>
112 <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>
113
114 <?php
115 }
116
117 /**
118 * Show setting structure input.
119 *
120 * @param array $option {
121 * Callback option.
122 * @type string 'post_type' post type name.
123 * @type string 'label_for' post type label.
124 * }
125 */
126 public function setting_structure_callback_function( $option ) {
127
128 $post_type = $option['post_type'];
129 $name = $option['label_for'];
130 $pt_object = get_post_type_object( $post_type );
131 $slug = $pt_object->rewrite['slug'];
132 $with_front = $pt_object->rewrite['with_front'];
133
134 $value = CPTP_Util::get_permalink_structure( $post_type );
135
136 $disabled = false;
137 if ( isset( $pt_object->cptp_permalink_structure ) && $pt_object->cptp_permalink_structure ) {
138 $disabled = true;
139 }
140
141 if ( ! $value ) {
142 $value = CPTP_DEFAULT_PERMALINK;
143 }
144
145 global $wp_rewrite;
146 $front = substr( $wp_rewrite->front, 1 );
147 if ( $front && $with_front ) {
148 $slug = $front . $slug;
149 }
150 ?>
151 <p>
152 <code><?php echo esc_html( home_url() . ( $slug ? '/' : '' ) . $slug ); ?></code>
153 <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 ); ?> />
154 </p>
155 <p>has_archive: <code><?php echo esc_html( $pt_object->has_archive ? 'true' : 'false' ); ?></code> / with_front:
156 <code><?php echo esc_html( $pt_object->rewrite['with_front'] ? 'true' : 'false' ); ?></code></p>
157 <?php
158 }
159
160 /**
161 * Show checkbox no tax.
162 */
163 public function setting_no_tax_structure_callback_function() {
164 $no_taxonomy_structure = CPTP_Util::get_no_taxonomy_structure();
165 echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, $no_taxonomy_structure, false ) . ' /> ';
166 $txt = __( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>.", 'custom-post-type-permalinks' );
167 echo sprintf( wp_kses( $txt, array( 'code' => array() ) ), esc_html( home_url() ) );
168 }
169
170 /**
171 * Show checkbox for post type query.
172 */
173 public function add_post_type_for_tax_callback_function() {
174 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 ) . ' /> ';
175 esc_html_e( 'Custom taxonomy archive also works as post type archive. ', 'custom-post-type-permalinks' );
176 esc_html_e( 'There are cases when the template to be loaded is changed.', 'custom-post-type-permalinks' );
177 }
178
179
180 /**
181 * Enqueue css and js
182 *
183 * @since 0.8.5
184 */
185 public function enqueue_css_js() {
186 $pointer_name = 'custom-post-type-permalinks-settings';
187 if ( ! is_network_admin() ) {
188 $dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
189 if ( false === array_search( $pointer_name, $dismissed, true ) ) {
190 $content = '';
191 $content .= '<h3>' . __( 'Custom Post Type Permalinks', 'custom-post-type-permalinks' ) . '</h3>';
192 $content .= '<p>' . __( 'You can setting permalink for post type in <a href="options-permalink.php">Permalinks</a>.', 'custom-post-type-permalinks' ) . '</p>';
193
194 wp_enqueue_style( 'wp-pointer' );
195 wp_enqueue_script( 'wp-pointer' );
196 wp_enqueue_script( 'custom-post-type-permalinks-pointer', plugins_url( 'assets/settings-pointer.js', CPTP_PLUGIN_FILE ), array( 'wp-pointer' ), CPTP_VERSION );
197
198 wp_localize_script( 'custom-post-type-permalinks-pointer', 'CPTP_Settings_Pointer', array(
199 'content' => $content,
200 'name' => $pointer_name,
201 ) );
202 }
203 }
204 }
205
206 /**
207 * Admin notice for update permalink settings!
208 */
209 public function admin_notices() {
210 if ( version_compare( get_option( 'cptp_permalink_checked' ), '3.0.0', '<' ) ) {
211 // translators: %s URL.
212 $format = __( '[Custom Post Type Permalinks] <a href="%s"><strong>Please check your permalink settings!</strong></a>', 'custom-post-type-permalinks' );
213 $message = sprintf( $format, admin_url( 'options-permalink.php' ) );
214 echo sprintf( '<div class="notice notice-warning"><p>%s</p></div>', wp_kses( $message, wp_kses_allowed_html( 'post' ) ) );
215 }
216 }
217 }
218
219