1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flynt\Features\TinyMce; |
4
|
|
|
|
5
|
|
|
use Flynt\Utils\Feature; |
6
|
|
|
|
7
|
|
|
// Clean Up TinyMCE Buttons |
8
|
|
|
|
9
|
|
|
// First Bar |
10
|
|
|
add_filter('mce_buttons', function ($buttons) { |
|
|
|
|
11
|
|
|
$toolbarsFromFile = getToolbarsFromJson(); |
12
|
|
|
return $toolbarsFromFile['Default']; |
13
|
|
|
}); |
14
|
|
|
|
15
|
|
|
// Second Bar |
16
|
|
|
add_filter('mce_buttons_2', function ($buttons) { |
|
|
|
|
17
|
|
|
return []; |
18
|
|
|
}); |
19
|
|
|
|
20
|
|
|
add_filter('tiny_mce_before_init', function ($init) { |
21
|
|
|
// Add block format elements you want to show in dropdown |
22
|
|
|
$init['block_formats'] = 'Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6'; |
23
|
|
|
|
24
|
|
|
// Load Styleformat Dropdown and parse it into TinyMCE |
25
|
|
|
$options = Feature::getOptions('flynt-tiny-mce'); |
26
|
|
View Code Duplication |
if (isset($options[0]) && isset($options[0]['styleformatsConfigPath'])) { |
|
|
|
|
27
|
|
|
$configPath = $options[0]['styleformatsConfigPath']; |
28
|
|
|
} else { |
29
|
|
|
$configPath = 'config/toolbars.json'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$filePath = get_template_directory() . '/Features/TinyMce/' . $configPath; |
33
|
|
|
if (file_exists($filePath)) { |
34
|
|
|
$loadedStyle = file_get_contents($filePath); |
35
|
|
|
$init['style_formats'] = $loadedStyle; |
36
|
|
|
} |
37
|
|
|
return $init; |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
add_filter('acf/fields/wysiwyg/toolbars', function ($toolbars) { |
41
|
|
|
// Load Toolbars and parse them into TinyMCE |
42
|
|
|
$toolbarsFromFile = getToolbarsFromJson(); |
43
|
|
|
if ($toolbarsFromFile) { |
44
|
|
|
$toolbars = []; |
45
|
|
|
foreach ($toolbars as $name => $toolbar) { |
46
|
|
|
array_unshift($toolbar, []); |
47
|
|
|
$toolbars[$name] = $toolbar; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $toolbars; |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
function getToolbarsFromJson() |
55
|
|
|
{ |
56
|
|
|
$options = Feature::getOptions('flynt-tiny-mce'); |
57
|
|
View Code Duplication |
if (isset($options[0]) && isset($options[0]['toolbarsConfigPath'])) { |
|
|
|
|
58
|
|
|
$configPath = $options[0]['toolbarsConfigPath']; |
59
|
|
|
} else { |
60
|
|
|
$configPath = 'config/toolbars.json'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$filePath = get_template_directory() . '/Features/TinyMce/' . $configPath; |
64
|
|
|
if (file_exists($filePath)) { |
65
|
|
|
return json_decode(file_get_contents($filePath), true); |
66
|
|
|
} else { |
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.