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
Option.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | /** |
| 5 | * |
| 6 | * Options. |
| 7 | * |
| 8 | * Save Options. |
| 9 | * |
| 10 | * @package Custom_Post_Type_Permalinks |
| 11 | * @since 0.9.6 |
| 12 | * |
| 13 | * */ |
| 14 | class CPTP_Module_Option extends CPTP_Module { |
| 15 | |
| 16 | public function add_hook() { |
| 17 | add_action( 'admin_init', array( $this, 'save_options' ), 30 ); |
| 18 | register_uninstall_hook( CPTP_PLUGIN_FILE, array( __CLASS__, 'uninstall_hook' ) ); |
| 19 | } |
| 20 | |
| 21 | public function save_options() { |
| 22 | |
| 23 | if ( empty( $_POST['submit'] ) ) { |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | if ( false === strpos( $_POST['_wp_http_referer'], 'options-permalink.php' ) ) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | if ( empty ( $_POST['_wpnonce'] ) ) { |
| 36 | return false; |
| 37 | } |
| 38 | $nonce = $_POST['_wpnonce']; |
| 39 | |
| 40 | if ( ! wp_verify_nonce( $nonce, 'update-permalink' ) ) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | $post_types = CPTP_Util::get_post_types(); |
| 45 | |
| 46 | foreach ( $post_types as $post_type ): |
| 47 | |
| 48 | $structure = trim( esc_attr( $_POST[ $post_type . '_structure' ] ) );#get setting |
| 49 | |
| 50 | #default permalink structure |
| 51 | if ( ! $structure ) { |
| 52 | $structure = CPTP_DEFAULT_PERMALINK; |
| 53 | } |
| 54 | |
| 55 | $structure = str_replace( '//', '/', '/' . $structure );# first "/" |
| 56 | #last "/" |
| 57 | $lastString = substr( trim( esc_attr( $_POST['permalink_structure'] ) ), - 1 ); |
| 58 | $structure = rtrim( $structure, '/' ); |
| 59 | |
| 60 | if ( $lastString == '/' ) { |
| 61 | $structure = $structure . '/'; |
| 62 | } |
| 63 | |
| 64 | update_option( $post_type . '_structure', $structure ); |
| 65 | endforeach; |
| 66 | |
| 67 | update_option( 'no_taxonomy_structure', ! isset( $_POST['no_taxonomy_structure'] ) ); |
| 68 | update_option( 'add_post_type_for_tax', isset( $_POST['add_post_type_for_tax'] ) ); |
| 69 | |
| 70 | } |
| 71 | |
| 72 | public static function uninstall_hook() { |
| 73 | foreach ( CPTP_Util::get_post_types() as $post_type ) { |
| 74 | delete_option( $post_type . '_structure' ); |
| 75 | } |
| 76 | |
| 77 | delete_option( 'no_taxonomy_structure' ); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | } |