Admin.php
10 years ago
FlushRules.php
11 years ago
GetArchives.php
11 years ago
Option.php
11 years ago
Permalink.php
10 years ago
Rewrite.php
11 years ago
Setting.php
11 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 Setting for custom post type', 'cptp' ), |
| 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.', 'cptp' ), |
| 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 post_type query for custom taxonomy archive.', 'cptp' ), |
| 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( 'Setting permalinks of custom post type.', 'cptp' ); ?><br/> |
| 76 | <?php _e( "The tags you can use is WordPress Structure Tags and '%\"custom_taxonomy_slug\"%'. (e.g. %actors%)", 'cptp' ); ?> |
| 77 | <br/> |
| 78 | <?php _e( "%\"custom_taxonomy_slug\"% is replaced the taxonomy's term.'.", 'cptp' ); ?></p> |
| 79 | |
| 80 | <p><?php _e( "Presence of the trailing '/' is unified into a standard permalink structure setting.", 'cptp' ); ?> |
| 81 | <p><?php _e( 'If <code>has_archive</code> is true, add permalinks for custom post type archive.', 'cptp' ); ?> |
| 82 | <?php _e( "If you don't entered permalink structure, permalink is configured /%postname%/'.", 'cptp' ); ?> |
| 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,The custom taxonomy's permalinks is <code>%s/post_type/taxonomy/term</code>.", 'cptp' ); |
| 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.", 'cptp' ); |
| 132 | _e( "There are cases when template to be loaded is changed.", 'cptp' ); |
| 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>", 'cptp' ); |
| 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 |