| 1 |
<?php |
| 2 |
/** |
| 3 |
* Initialisation script |
| 4 |
* |
| 5 |
* Run everytime the plugin is initialised |
| 6 |
* |
| 7 |
* @package simple-embed-code |
| 8 |
* @since 2.2 |
| 9 |
*/ |
| 10 |
|
| 11 |
function ce_initialisation() { |
| 12 |
|
| 13 |
// Add exerpt filter, if required |
| 14 |
|
| 15 |
$options = get_option( 'artiss_code_embed' ); |
| 16 |
if ( isset( $options[ 'excerpt' ] ) && $options[ 'excerpt' ] == 1 ) { |
| 17 |
add_filter( 'the_excerpt', 'ce_filter', 1 ); |
| 18 |
} |
| 19 |
|
| 20 |
// Check if plugin has upgraded and, if so, perform further actions |
| 21 |
|
| 22 |
$version = get_option( 'code_embed_version' ); |
| 23 |
|
| 24 |
if ( $version != code_embed_version ) { |
| 25 |
|
| 26 |
// Set up default option values (if not already set) |
| 27 |
|
| 28 |
$options = get_option( 'artiss_code_embed' ); |
| 29 |
|
| 30 |
// If options don't exist, create an empty array |
| 31 |
|
| 32 |
if ( !is_array( $options ) ) { $options = array(); } |
| 33 |
|
| 34 |
// Because of upgrading, check each option - if not set, apply default |
| 35 |
|
| 36 |
$default_array = array( |
| 37 |
'opening_ident' => '%', |
| 38 |
'keyword_ident' => 'CODE', |
| 39 |
'closing_ident' => '%', |
| 40 |
'debug' => '', |
| 41 |
'excerpts' => '', |
| 42 |
); |
| 43 |
|
| 44 |
// Merge existing and default options - any missing from existing will take the default settings |
| 45 |
|
| 46 |
$new_options = array_merge( $default_array, $options ); |
| 47 |
|
| 48 |
// Update the options, if changed, and return the result |
| 49 |
|
| 50 |
if ( $options != $new_options ) { update_option( 'artiss_code_embed', $new_options ); } |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
add_action( 'init', 'ce_initialisation' ); |
| 57 |
?> |