Admin.php
9 years ago
FlushRules.php
9 years ago
GetArchives.php
9 years ago
Option.php
9 years ago
Permalink.php
9 years ago
Rewrite.php
9 years ago
Setting.php
9 years ago
Option.php
88 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 | class CPTP_Module_Option extends CPTP_Module { |
| 14 | |
| 15 | public function add_hook() { |
| 16 | add_action( 'init', array( $this, 'set_default_option' ), 1 ); |
| 17 | add_action( 'admin_init', array( $this, 'save_options' ), 30 ); |
| 18 | } |
| 19 | |
| 20 | public function set_default_option() { |
| 21 | add_option( 'no_taxonomy_structure', true ); |
| 22 | add_option( 'add_post_type_for_tax', false ); |
| 23 | } |
| 24 | |
| 25 | public function save_options() { |
| 26 | |
| 27 | if ( empty( $_POST['submit'] ) ) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | if ( empty( $_POST['_wpnonce'] ) ) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'update-permalink' ) ) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | if ( false === strpos( $_POST['_wp_http_referer'], 'options-permalink.php' ) ) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | $post_types = CPTP_Util::get_post_types(); |
| 48 | |
| 49 | foreach ( $post_types as $post_type ) : |
| 50 | |
| 51 | $structure = trim( esc_attr( $_POST[ $post_type . '_structure' ] ) );// get setting |
| 52 | |
| 53 | // default permalink structure |
| 54 | if ( ! $structure ) { |
| 55 | $structure = CPTP_DEFAULT_PERMALINK; |
| 56 | } |
| 57 | |
| 58 | $structure = str_replace( '//', '/', '/' . $structure );// first "/" |
| 59 | // last "/" |
| 60 | $lastString = substr( trim( esc_attr( $_POST['permalink_structure'] ) ), - 1 ); |
| 61 | $structure = rtrim( $structure, '/' ); |
| 62 | |
| 63 | if ( '/' == $lastString ) { |
| 64 | $structure = $structure . '/'; |
| 65 | } |
| 66 | |
| 67 | update_option( $post_type . '_structure', $structure ); |
| 68 | endforeach; |
| 69 | |
| 70 | update_option( 'no_taxonomy_structure', empty( $_POST['no_taxonomy_structure'] ) ); |
| 71 | update_option( 'add_post_type_for_tax', isset( $_POST['add_post_type_for_tax'] ) ); |
| 72 | update_option( 'cptp_permalink_checked', CPTP_VERSION ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * fire on uninstall. delete options. |
| 77 | * |
| 78 | * @static |
| 79 | */ |
| 80 | public static function uninstall_hook() { |
| 81 | foreach ( CPTP_Util::get_post_types() as $post_type ) { |
| 82 | delete_option( $post_type . '_structure' ); |
| 83 | } |
| 84 | |
| 85 | delete_option( 'no_taxonomy_structure' ); |
| 86 | } |
| 87 | } |
| 88 |