settings = new Post_Types_Settings( $this->options ); if ( ! empty( $this->options ) ) { add_action( 'init', [ $this, 'register_custom_post_type' ] ); } // Any write to the post types (settings screen, import, WP-CLI) flushes // the rules on the next request. While the module is off its post types // are not registered, and switching it on is caught by the Section's // toggle watcher. Flush_Rewrite::watch_option( self::OPTION_NAME, self::MODULE_ID ); } /** * Render the settings page * * @return void */ public function render_settings_page() { $this->settings->render_settings_page(); } /** * Register custom post types * * @return void */ public function register_custom_post_type() { if ( ! empty( $this->options ) ) { foreach ( $this->options as $slug => $post_type_arg ) { if ( isset( $post_type_arg['rewrite'] ) && is_array( $post_type_arg['rewrite'] ) ) { $rewrite_slug = isset( $post_type_arg['rewrite']['slug'] ) ? trim( (string) $post_type_arg['rewrite']['slug'] ) : ''; if ( '' === $rewrite_slug ) { $post_type_arg['rewrite']['slug'] = $slug; } } unset( $post_type_arg['do_rewrite'] ); unset( $post_type_arg['do_capabilities'] ); unset( $post_type_arg['capability_type'] ); register_post_type( $slug, $post_type_arg ); } } } }