-
Notifications
You must be signed in to change notification settings - Fork 2
/
Helper.php
68 lines (61 loc) · 2.06 KB
/
Helper.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
<?php
namespace cw\divi;
class Helper{
#https://divibooster.com/enable-divi-builder-on-custom-post-types/
public static function enableLibraryForCustomLayouts(){
add_filter( 'et_pb_show_all_layouts_built_for_post_type', function() {
return 'page';
});
}
public static function setEditorAsDefault(){
add_action('load-post-new.php', function(){
add_filter('et_builder_always_enabled', '__return_true');
});
}
public static function enableEditorForCustomPostTypes(){
/* Enable Divi Builder on all post types with an editor box */
add_filter('et_builder_post_types', function($post_types) {
foreach(get_post_types() as $pt) {
if (!in_array($pt, $post_types)
&& post_type_supports($pt, 'editor'))
$post_types[] = $pt;
}
return $post_types;
});
/* Add Divi Custom Post Settings box */
add_action('add_meta_boxes', function() {
foreach(get_post_types() as $pt) {
if (post_type_supports($pt, 'editor')
&& function_exists('et_single_settings_meta_box'))
add_meta_box('et_settings_meta_box',
__('Divi Custom Post Settings', 'Divi'),
'et_single_settings_meta_box',
$pt,
'side',
'high');
}
});
/* Ensure Divi Builder appears in correct location */
add_action('admin_head', function() {
$s = get_current_screen();
if(!empty($s->post_type)
&& $s->post_type!='page'
&& $s->post_type!='post') {
?>
<script>
jQuery(function($){
$('#et_pb_layout').insertAfter($('#et_pb_main_editor_wrap'));
});
</script>
<style>
#et_pb_layout { margin-top:20px; margin-bottom:0px }
</style>
<?php
}
});
// Ensure that Divi Builder framework is loaded - required for some post types when using Divi Builder plugin
add_filter('et_divi_role_editor_page', function($page) {
return isset($_GET['page'])?$_GET['page']:$page;
});
}
}