Skip to content

Instantly share code, notes, and snippets.

@wpmu-authors
wpmu-authors / basic-example.php
Last active February 3, 2021 17:37
basic-example.php
register_activation_hook( __FILE__, 'my_plugin_activation' );
function my_plugin_activation() {
add_option( 'my_plugin_activated', time() );
}
@wpmu-authors
wpmu-authors / incorrect-cpt.php
Last active February 3, 2021 17:37
incorrect-cpt.php
register_activation_hook( __FILE__, 'my_plugin_activation' );
function my_plugin_activation() {
flush_rewrite_rules();
}
add_action( 'init', 'my_custom_post_type' );
function my_custom_post_type() {
$args = array(
'public' => true,
'label' => 'Board Games'
@wpmu-authors
wpmu-authors / option-activation.php
Last active February 3, 2021 17:38
option-activation.php
register_activation_hook( __FILE__, 'my_plugin_activation' );
function my_plugin_activation() {
add_option( 'my_plugin_activation','just-activated' );
}
add_action( 'admin_init','my_plugin_initialize' );
function my_plugin_initialize() {
if( is_admin() && get_option( 'my_plugin_activation' ) == 'just-activated' ) {
delete_option( 'my_plugin_activation' );
flush_rewrite_rules();
@wpmu-authors
wpmu-authors / best-activation.php
Last active February 3, 2021 17:39
best-activation.php
add_action( 'init', 'my_custom_post_type' );
function my_custom_post_type() {
$args = array(
'public' => true,
'label' => 'Board Games'
);
register_post_type( 'boardgames', $args );
}
@wpmu-authors
wpmu-authors / create-tables.php
Last active February 3, 2021 17:39
create-tables.php
global $jal_db_version;
$jal_db_version = '1.0';
function jal_install() {
global $wpdb;
global $jal_db_version;
$table_name = $wpdb->prefix . 'liveshoutbox';
$charset_collate = $wpdb->get_charset_collate();
@wpmu-authors
wpmu-authors / dependency-check.php
Last active February 3, 2021 17:40
dependency-check.php
register_activation_hook( __FILE__, 'my_plugin_activation' );
function my_plugin_activation() {
global $wp_version;
$php = '5.3';
$wp = '3.8';
if ( version_compare( PHP_VERSION, $php, '<' ) ) {
deactivate_plugins( basename( __FILE__ ) );
@wpmu-authors
wpmu-authors / basic-deactivation.php
Last active February 3, 2021 17:40
basic-deactivation.php
register_deactivation_hook( __FILE__, 'my_plugin_deactivation' );
function my_plugin_deactivation() {
// Deactivation rules here
}
@wpmu-authors
wpmu-authors / incorrect-deactivation-flush.php
Created February 3, 2021 17:42
incorrect-deactivation-flush.php
function myplugin_flush_rewrites_deactivate() {
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'myplugin_flush_rewrites_deactivate' );
@wpmu-authors
wpmu-authors / delete-rewrite-rules.php
Created February 3, 2021 17:43
delete-rewrite-rules.php
register_deactivation_hook( __FILE__, 'my_plugin_deactivation' );
function my_plugin_deactivation() {
delete_option('rewrite_rules');
}
@wpmu-authors
wpmu-authors / uninstall-hook.php
Created February 3, 2021 17:45
uninstall-hook.php
register_uninstall_hook( __FILE__, 'my_plugin_uninstall' );
function my_plugin_uninstall() {
// Uninstallation stuff here
}