PluginProbe ʕ •ᴥ•ʔ
Custom Post Type Permalinks / 1.4.0
Custom Post Type Permalinks v1.4.0
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 10 years ago FlushRules.php 11 years ago GetArchives.php 10 years ago Option.php 11 years ago Permalink.php 10 years ago Rewrite.php 11 years ago Setting.php 10 years ago
Admin.php
181 lines
1 <?php
2
3
4 /**
5 *
6 * Admin Page View.
7 *
8 * @package Custom_Post_Type_Permalinks
9 * @since 0.9.4
10 *
11 * */
12 class CPTP_Module_Admin extends CPTP_Module {
13
14 public function add_hook() {
15 add_action( 'admin_init', array( $this, 'settings_api_init' ), 30 );
16 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_css_js' ) );
17 add_action( 'admin_footer', array( $this, 'pointer_js' ) );
18 }
19
20
21 /**
22 *
23 * Setting Init
24 * @since 0.7
25 *
26 */
27 public function settings_api_init() {
28 add_settings_section( 'cptp_setting_section',
29 __( 'Permalink Settings for Custom Post Types', 'custom-post-type-permalinks' ),
30 array( $this, 'setting_section_callback_function' ),
31 'permalink'
32 );
33
34 $post_types = CPTP_Util::get_post_types();
35
36 foreach ( $post_types as $post_type ) {
37
38 add_settings_field(
39 $post_type . '_structure',
40 $post_type,
41 array( $this, 'setting_structure_callback_function' ),
42 'permalink',
43 'cptp_setting_section',
44 array( 'label_for' => $post_type . '_structure', 'post_type' => $post_type )
45 );
46 register_setting( 'permalink', $post_type . '_structure' );
47 }
48
49 add_settings_field(
50 'no_taxonomy_structure',
51 __( 'Use custom permalink of custom taxonomy archive.', 'custom-post-type-permalinks' ),
52 array( $this, 'setting_no_tax_structure_callback_function' ),
53 'permalink',
54 'cptp_setting_section',
55 array( 'label_for' => 'no_taxonomy_structure' )
56 );
57
58 register_setting( 'permalink', 'no_taxonomy_structure' );
59
60 add_settings_field(
61 'add_post_type_for_tax',
62 __( 'Add <code>post_type</code> query for custom taxonomy archive.', 'custom-post-type-permalinks' ),
63 array( $this, 'add_post_type_for_tax_callback_function' ),
64 'permalink',
65 'cptp_setting_section',
66 array( 'label_for' => 'add_post_type_for_tax' )
67 );
68
69 register_setting( 'permalink', 'no_taxonomy_structure' );
70
71 }
72
73 public function setting_section_callback_function() {
74 ?>
75 <p><?php _e( 'Set the permalinks of your Custom Post Types.', 'custom-post-type-permalinks' ); ?><br/>
76 <?php _e( "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' ); ?>
77 <br/>
78 <?php _e( "<code>%\"custom_taxonomy_slug\"%</code> will replace the taxonomy's term.", 'custom-post-type-permalinks' ); ?></p>
79
80 <p><?php _e( "Presence of the trailing '/' is unified into a standard permalink structure setting.", 'custom-post-type-permalinks' ); ?>
81 <p><?php _e( 'If <code>has_archive</code> is true, add permalinks for custom post type archive.', 'custom-post-type-permalinks' ); ?>
82 <?php _e( "If you don't enter a permalink structure, permalinks will be configured as <code>/%postname%/</code>.", 'custom-post-type-permalinks' ); ?>
83 </p>
84 <?php
85 }
86
87 public function setting_structure_callback_function( $option ) {
88
89 $post_type = $option['post_type'];
90 $name = $option['label_for'];
91 $pt_object = get_post_type_object( $post_type );
92 $slug = $pt_object->rewrite['slug'];
93 $with_front = $pt_object->rewrite['with_front'];
94
95
96 $value = CPTP_Util::get_permalink_structure( $post_type );
97
98 $disabled = false;
99 if ( isset( $pt_object->cptp_permalink_structure ) and $pt_object->cptp_permalink_structure ) {
100 $disabled = true;
101 }
102
103 if ( ! $value ) {
104 $value = CPTP_DEFAULT_PERMALINK;
105 }
106
107 global $wp_rewrite;
108 $front = substr( $wp_rewrite->front, 1 );
109 if ( $front and $with_front ) {
110 $slug = $front . $slug;
111 }
112 ?>
113 <p>
114 <code><?php echo home_url() . ( $slug ? '/' : '' ) . esc_html( $slug ); ?></code>
115 <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 );?> />
116 </p>
117 <p>has_archive: <code><?php echo $pt_object->has_archive ? 'true' : 'false';?></code> / with_front: <code><?php echo $pt_object->rewrite['with_front'] ? 'true' : 'false';?></code></p>
118 <?php
119 }
120
121
122 public function setting_no_tax_structure_callback_function() {
123 echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option( 'no_taxonomy_structure' ), false ) . ' /> ';
124 $txt = __( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>.", 'custom-post-type-permalinks' );
125 printf( $txt, home_url() );
126 }
127
128
129 public function add_post_type_for_tax_callback_function() {
130 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 ) . ' /> ';
131 _e( "Custom taxonomy archive also works as post type archive. ", 'custom-post-type-permalinks' );
132 _e( "There are cases when the template to be loaded is changed.", 'custom-post-type-permalinks' );
133 }
134
135
136 /**
137 *
138 * enqueue CSS and JS
139 * @since 0.8.5
140 *
141 */
142 public function enqueue_css_js() {
143 wp_enqueue_style( 'wp-pointer' );
144 wp_enqueue_script( 'wp-pointer' );
145 }
146
147
148 /**
149 *
150 * add js for pointer
151 * @since 0.8.5
152 */
153 public function pointer_js() {
154 if ( ! is_network_admin() ) {
155 $dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
156 if ( false === array_search( 'cptp_pointer0871', $dismissed ) ) {
157 $content = __( "<h3>Custom Post Type Permalinks</h3><p>From <a href='options-permalink.php'>Permalinks</a>, set a custom permalink for each post type.</p>", 'custom-post-type-permalinks' );
158 ?>
159 <script type="text/javascript">
160 jQuery(function ($) {
161
162 $("#menu-settings .wp-has-submenu").pointer({
163 content: "<?php echo $content;?>",
164 position: {"edge": "left", "align": "center"},
165 close: function () {
166 $.post('admin-ajax.php', {
167 action: 'dismiss-wp-pointer',
168 pointer: 'cptp_pointer0871'
169 })
170
171 }
172 }).pointer("open");
173 });
174 </script>
175 <?php
176 }
177 }
178 }
179 }
180
181