/
class-boldgrid-seo-butterbean.php
107 lines (96 loc) · 3.31 KB
/
class-boldgrid-seo-butterbean.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
class Boldgrid_Seo_Butterbean {
public function __construct( $configs ) {
$this->configs = $configs;
$this->util = new Boldgrid_Seo_Util();
}
public function load() {
require_once( BOLDGRID_SEO_PATH . '/includes/lib/butterbean/butterbean.php' );
}
/**
* Get custom control templates and load them in to render in our metabox.
*
* @since 1.2.1
*/
public function get_html_template( $located, $slug ) {
// Get the analysis control template.
if ( $slug === 'dashboard' ) {
$located = plugin_dir_path( dirname( __FILE__ ) ) . "/assets/partials/control-dashboard.php";
}
// Get the keywords control template.
if ( $slug === 'keywords' ) {
$located = plugin_dir_path( dirname( __FILE__ ) ) . "/assets/partials/control-keywords.php";
}
// Override the default textarea template.
if ( $slug === 'textarea' ) {
$located = plugin_dir_path( dirname( __FILE__ ) ) . "/assets/partials/control-bgseo-textarea.php";
}
return $located;
}
public function register( $butterbean, $post_type ) {
if ( 'page' !== $post_type && 'post' !== $post_type )
return;
/* === Register Managers === */
$butterbean->register_manager( 'boldgrid_seo', $this->configs['meta-box']['manager'] );
$manager = $butterbean->get_manager( 'boldgrid_seo' );
// Custom Analysis Control.
if ( ! class_exists( 'Boldgrid_Seo_Control_Dashboard' ) ) {
include_once plugin_dir_path( __FILE__ ) . "/class-boldgrid-seo-control-dashboard.php";
}
$butterbean->register_control_type( 'dashboard', 'Boldgrid_Seo_Control_Dashboard' );
// Custom Keywords Control.
if ( ! class_exists( 'Boldgrid_Seo_Control_Keywords' ) ) {
include_once plugin_dir_path( __FILE__ ) . "/class-boldgrid-seo-control-keywords.php";
}
$butterbean->register_control_type( 'keywords', 'Boldgrid_Seo_Control_Keywords' );
/* === Register Sections === */
$sections = $this->configs['meta-box']['section'];
foreach( $sections as $section => $settings ) {
$manager->register_section( $section, $settings );
}
/* === Register Controls === */
$controls = $this->configs['meta-box']['control'];
$controls['bgseo_canonical']['attr']['placeholder'] = ( isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) ? get_permalink( $_GET['post'] ) : '';
foreach( $controls as $control => $settings ) {
$manager->register_control( $control, $settings );
}
/* === Register Settings === */
$manager->register_setting(
'bgseo_title',
array( 'sanitize_callback' => function( $setting ) {
return wp_specialchars_decode( wp_filter_nohtml_kses ( $setting ) );
} )
);
$manager->register_setting(
'bgseo_description',
array( 'sanitize_callback' => function( $setting ) {
return wp_specialchars_decode( wp_kses_post( $setting ) );
} )
);
$manager->register_setting(
'bgseo_canonical',
array( 'sanitize_callback' => 'esc_url_raw' )
);
$manager->register_setting(
'bgseo_robots_index',
array(
'default' => 'index',
'sanitize_callback' => 'sanitize_key'
)
);
$manager->register_setting(
'bgseo_robots_follow',
array(
'default' => 'follow',
'sanitize_callback' => 'sanitize_key'
)
);
$manager->register_setting(
'bgseo_custom_keyword',
array( 'sanitize_callback' => function( $setting ) {
return wp_specialchars_decode( wp_filter_nohtml_kses ( $setting ) );
} )
);
}
}
?>