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