-
Notifications
You must be signed in to change notification settings - Fork 1
/
meta-box-site-post.php
69 lines (61 loc) · 1.68 KB
/
meta-box-site-post.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
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Plugin Name: Meta Box Site Post
* Plugin URI:
* Description: Add-on for meta box plugin, allows you to add field type 'site_post' that allow you to choose post from other sites in the multisite network.
* Version: 1.0.0
* Author: Guillermo García
* Author URI: http://guillermogarcia.info
* License: GPL2+
*/
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'RWMB_Site_Post' ) ) {
/**
* Extension main class.
*/
class RWMB_Site_Post {
/**
* Indicate that the meta box is saved or not.
* This variable is used inside group field to show child fields.
*
* @var bool
*/
static $saved = false;
/**
* Add hooks to meta box.
*/
public function __construct() {
/**
* Hook to 'init' with priority 5 to make sure all actions are registered before Meta Box 4.9.0 runs
*/
add_action( 'init', array( $this, 'load_files' ), 5 );
add_action( 'rwmb_before', array( $this, 'set_saved' ) );
add_action( 'rwmb_after', array( $this, 'unset_saved' ) );
}
/**
* Load field group class.
*/
public function load_files() {
if ( class_exists('RWMB_Post_Field') && ! class_exists('RWMB_Site_Post_Field') && is_multisite() ) {
require plugin_dir_path( __FILE__ ) . 'class-site-post-field.php';
}
}
/**
* Check if current meta box is saved.
* This variable is used inside group field to show child fields.
*
* @param object $obj Meta Box object
*/
public function set_saved( $obj ) {
self::$saved = $obj->is_saved();
}
/**
* Unset 'saved' variable, to be ready for next meta box.
*/
public function unset_saved() {
self::$saved = false;
}
}
new RWMB_Site_Post;
}