Plugin Foundation Flashcards

1
Q

Write plugin activation hook with function to deactivate plugin if WP version < 3.1

A

register_activation_hook( __FILE__, ‘boj_install’ );

function boj_install() {

If ( version_compare( get_bloginfo( ‘version’ ), ‘3.1’, ‘<’ ) ) {

deactivate_plugins( basename( __FILE__ ) );

}

}

?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write plugin activation hook with function to create default settings of view = grid, food = bacon, mode = zombie.

A

<?php </p>

register_activation_hook( __FILE__, ‘boj_install’ );

function boj_install() {

$boj_myplugin_options = array(

‘view’ => ‘grid’,

‘food’ => ‘bacon’,

‘mode’ => ‘zombie’

);

update_option( ‘boj_myplugin_options’, $boj_myplugin_options);

}

?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why shoudn’t you include uninstall functionality when a plugin is deactivated?

A

Imagine if you accidentally deactivate a plugin and upon reactivation you realize all your settings for that plugin have been deleted. Also, remember the WordPress automatic update feature deactivates all plugins prior to installing the new version of WordPress.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write uninstall.php script that A.) ensures WP is actually calling the uninstall file and B.) deletes the plugin’s options(boj_myplugin_options) from the DB.

A

<?php </p>

if( !defined( ‘WP_UNINSTALL_PLUGIN’ ) )

exit ();

delete_option( ‘boj_myplugin_options’ );

?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How should PHP functions be written?

A

lowercase with underscores

function function_name ( $myplugin_variable ) {

//do something

}

?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How should plugin files be named?

A

With a unique name, lowercase, hyphen-separated.

boj-plugin-name.php

How well did you know this?
1
Not at all
2
3
4
5
Perfectly