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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?php /** * The plugin core class which initialize plugin's code. * * @package Meta Box */
/** * The Meta Box core class. * * @package Meta Box */ class RWMB_Core { /** * Initialization. */ public function init() { load_plugin_textdomain( 'meta-box', false, plugin_basename( RWMB_DIR ) . '/languages/' );
add_filter( 'plugin_action_links_meta-box/meta-box.php', array( $this, 'plugin_links' ) );
// Uses priority 20 to support custom port types registered using the default priority. add_action( 'init', array( $this, 'register_meta_boxes' ), 20 ); add_action( 'edit_page_form', array( $this, 'fix_page_template' ) ); }
/** * Add links to Documentation and Extensions in plugin's list of action links. * * @since 4.3.11 * @param array $links Array of plugin links. * @return array */ public function plugin_links( $links ) { $links[] = '<a href="https://metabox.io/docs/">' . esc_html__( 'Documentation', 'meta-box' ) . '</a>'; $links[] = '<a href="https://metabox.io/plugins/">' . esc_html__( 'Extensions', 'meta-box' ) . '</a>'; return $links; }
/** * Register meta boxes. * Advantages: * - prevents incorrect hook. * - no need to check for class existences. */ public function register_meta_boxes() { $configs = apply_filters( 'rwmb_meta_boxes', array() ); $meta_boxes = rwmb_get_registry( 'meta_box' );
foreach ( $configs as $config ) { $meta_box = rwmb_get_meta_box( $config ); $meta_boxes->add( $meta_box ); $meta_box->register_fields(); } }
/** * WordPress will prevent post data saving if a page template has been selected that does not exist. * This is especially a problem when switching to our theme, and old page templates are in the post data. * Unset the page template if the page does not exist to allow the post to save. * * @param WP_Post $post Post object. * @since 4.3.10 */ public function fix_page_template( WP_Post $post ) { $template = get_post_meta( $post->ID, '_wp_page_template', true ); $page_templates = wp_get_theme()->get_page_templates();
// If the template doesn't exists, remove the data to allow WordPress to save. if ( ! isset( $page_templates[ $template ] ) ) { delete_post_meta( $post->ID, '_wp_page_template' ); } }
/** * Get registered meta boxes via a filter. * * @deprecated No longer used. Keep for backward-compatibility with extensions. * * @return array */ public static function get_meta_boxes() { $meta_boxes = rwmb_get_registry( 'meta_box' )->all(); return wp_list_pluck( $meta_boxes, 'meta_box' ); } }
|