This repository has been archived by the owner on Jun 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
multiple-content-blocks.php
executable file
·57 lines (51 loc) · 1.79 KB
/
multiple-content-blocks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Plugin Name: Multiple content blocks
* Description: Allow for more content blocks in WordPress than just the one.
* Text Domain: multiple-content-blocks
*
* Plugin URI: https://github.com/trendwerk/multiple-content-blocks/
*
* Author: Trendwerk
* Author URI: https://github.com/trendwerk/
*
* Version: 3.2.2
*
* @package MCB
* @subpackage Main
*/
define( 'MCB_URL', plugins_url( '/', __FILE__ ) );
include( 'assets/inc/class-mcb.php' );
include( 'assets/inc/class-mcb-settings.php' );
include( 'assets/inc/template-tags.php' );
/**
* Add translation
*/
function mcb_translation() {
load_plugin_textdomain( 'multiple-content-blocks', false, dirname( plugin_basename( __FILE__ ) ) . '/assets/languages/' );
}
add_action( 'plugins_loaded', 'mcb_translation' );
/**
* Backwards compatibility with versions lower than 3.0
*/
function mcb_upgrade() {
if( ! get_option( 'mcb-3.0-migration' ) ) {
//Rename database fields: _ot_multiplecontent_box-$name -> mcb-$id
global $wpdb;
$blocks = $wpdb->get_results( "SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key LIKE '_ot_multiplecontent_box-%'" );
if( $blocks ) {
foreach( $blocks as $block ) {
$id = sanitize_title( str_replace( '_ot_multiplecontent_box-', '', $block->meta_key ) );
update_post_meta( $block->post_id, 'mcb-' . $id, $block->meta_value );
delete_post_meta( $block->post_id, $block->meta_key );
}
}
update_option( 'mcb-3.0-migration', true );
} elseif( ! get_option( 'mcb-3.1-migration' ) ) {
//Prepend meta_key with an underscore so WordPress won't show it in Custom Fields
global $wpdb;
$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = Concat('_',meta_key) WHERE meta_key LIKE 'mcb-%'" );
update_option( 'mcb-3.1-migration', true );
}
}
add_action( 'init', 'mcb_upgrade' );