Admin.php
5 years ago
FlushRules.php
8 years ago
GetArchives.php
5 years ago
Option.php
5 years ago
Permalink.php
5 years ago
Rewrite.php
5 years ago
Setting.php
6 years ago
Option.php
93 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Options. |
| 4 | * |
| 5 | * Save Options. |
| 6 | * |
| 7 | * @package Custom_Post_Type_Permalinks |
| 8 | * */ |
| 9 | |
| 10 | /** |
| 11 | * Class CPTP_Module_Option |
| 12 | * |
| 13 | * @since 0.9.6 |
| 14 | */ |
| 15 | class CPTP_Module_Option extends CPTP_Module { |
| 16 | |
| 17 | /** |
| 18 | * Add Actions. |
| 19 | */ |
| 20 | public function add_hook() { |
| 21 | add_action( 'init', array( $this, 'set_default_option' ), 1 ); |
| 22 | add_action( 'admin_init', array( $this, 'save_options' ), 30 ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Set default option values. |
| 27 | */ |
| 28 | public function set_default_option() { |
| 29 | add_option( 'no_taxonomy_structure', true ); |
| 30 | add_option( 'add_post_type_for_tax', false ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Save Options. |
| 35 | * |
| 36 | * @return bool |
| 37 | */ |
| 38 | public function save_options() { |
| 39 | if ( ! filter_input( INPUT_POST, 'submit' ) ) { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | if ( ! wp_verify_nonce( filter_input( INPUT_POST, '_wpnonce' ), 'update-permalink' ) ) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | if ( false === strpos( filter_input( INPUT_POST, '_wp_http_referer' ), 'options-permalink.php' ) ) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | $post_types = CPTP_Util::get_post_types(); |
| 52 | |
| 53 | foreach ( $post_types as $post_type ) : |
| 54 | $structure = trim( esc_attr( filter_input( INPUT_POST, $post_type . '_structure' ) ) ); // get setting. |
| 55 | |
| 56 | // default permalink structure. |
| 57 | if ( ! $structure ) { |
| 58 | $structure = CPTP_DEFAULT_PERMALINK; |
| 59 | } |
| 60 | |
| 61 | $structure = str_replace( '//', '/', '/' . $structure );// first "/" |
| 62 | // last "/". |
| 63 | $lastString = substr( trim( esc_attr( filter_input( INPUT_POST, 'permalink_structure' ) ) ), - 1 ); |
| 64 | $structure = rtrim( $structure, '/' ); |
| 65 | |
| 66 | if ( '/' === $lastString ) { |
| 67 | $structure = $structure . '/'; |
| 68 | } |
| 69 | |
| 70 | update_option( $post_type . '_structure', $structure ); |
| 71 | endforeach; |
| 72 | $no_taxonomy_structure = ! filter_input( INPUT_POST, 'no_taxonomy_structure' ); |
| 73 | $add_post_type_for_tax = filter_input( INPUT_POST, 'add_post_type_for_tax' ); |
| 74 | |
| 75 | update_option( 'no_taxonomy_structure', ! ! $no_taxonomy_structure ); |
| 76 | update_option( 'add_post_type_for_tax', ! ! $add_post_type_for_tax ); |
| 77 | update_option( 'cptp_permalink_checked', CPTP_VERSION ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Fire on uninstall. delete options. |
| 82 | * |
| 83 | * @static |
| 84 | */ |
| 85 | public static function uninstall_hook() { |
| 86 | foreach ( CPTP_Util::get_post_types() as $post_type ) { |
| 87 | delete_option( $post_type . '_structure' ); |
| 88 | } |
| 89 | |
| 90 | delete_option( 'no_taxonomy_structure' ); |
| 91 | } |
| 92 | } |
| 93 |