Skip to content

Instantly share code, notes, and snippets.

@pavlo-bondarchuk
Created March 18, 2021 09:23
Show Gist options
  • Select an option

  • Save pavlo-bondarchuk/f01cbd2ce6c34f82ecf1c824be842795 to your computer and use it in GitHub Desktop.

Select an option

Save pavlo-bondarchuk/f01cbd2ce6c34f82ecf1c824be842795 to your computer and use it in GitHub Desktop.
CPT Class as Plugin
<?php
/**
* Plugin.
*
* Plugin Name: Plugin
* Version: 1.0.0
* License: MIT
* Text Domain: plugin
*/
class FlushTester
{
public function __construct() {
$this->register();
}
public function custom_post_type() {
register_post_type(
'test',
[
'public' => true,
'has_archive' => true,
'rewrite' => ['slug' => 'testing'],
'label' => esc_html__( 'Test', 'flushtester' ),
'supports' => ['title', 'editor', 'thumbnail'],
'menu_icon' => 'dashicons-screenoptions',
]
);
}
public function register() {
add_action( 'init', [ $this, 'custom_post_type' ] );
}
static function flush() {
delete_option( 'rewrite_rules' );
// flush_rewrite_rules();
}
}
$dpc = new FlushTester();
register_activation_hook( __FILE__, [ FlushTester::class, 'flush' ] );
register_deactivation_hook( __FILE__, [ FlushTester::class, 'flush' ] );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment