-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-ui.php
153 lines (118 loc) · 3.6 KB
/
admin-ui.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Figuren_Theater SEO Sharing_Image\Admin_UI.
*
* @package figuren-theater/seo/sharing_image\admin_ui
*/
namespace Figuren_Theater\SEO\Sharing_Image\Admin_UI;
use Figuren_Theater\SEO\Sharing_Image; // NEEDED_CAP
use WP_DEBUG;
use function add_action;
use function add_filter;
use function current_user_can;
use function is_super_admin;
use function remove_menu_page;
use function remove_submenu_page;
/**
* Bootstrap module, when enabled.
*/
function bootstrap() {
add_action( 'admin_menu', __NAMESPACE__ . '\\remove_menu', 11 );
// TODO later
//
// use the new webfont API
// as soon as it supports
// to get the path(es) of used fonts
// AND their primary purpose (heading-fonts, body-text, etc.)
//
// 'sharing_image_get_fontpath' => ['sharing_image_get_fontpath', 10, 2],
// maybe TODO later
// This is only relevant (and called), if the metabox is visible!
//
// hand over the just yet selected
// and not yet saved fetaured-image to our autogeneration logic
// 'sharing_image_update_post_meta' => ['mf_update_post_meta_sharing_image', 10, 2],
// Disable any UI for the user
// which is not that reliable
// and not save to use.
//
// Maybe this could be re-added in a future,
// advanced version of the 'schoener_teilen' feature
add_filter( 'sharing_image_hide_metabox', __NAMESPACE__ . '\\sharing_image_hide_metabox' );
// disable "Premium" tab on settings page
add_filter( 'sharing_image_settings_tabs', __NAMESPACE__ . '\\sharing_image_settings_tabs' );
}
function remove_menu() : void {
//
if ( is_super_admin() && true === constant( 'WP_DEBUG' ) )
return;
remove_submenu_page( 'options-general.php', 'sharing-image' );
}
/**
* [sharing_image_settings_tabs description]
* @param array $tabs List of settings tabs.
*
* @see https://wpset.org/sharing-image/hooks/#sharing_image_settings_tabs
*
* @package project_name
* @version version
* @author Carsten Bach
*
* @param array $tabs [description]
* @return [type] [description]
*/
function sharing_image_settings_tabs( array $tabs ) : array {
unset( $tabs['premium'] );
return $tabs;
}
/**
* @param bool $hide_metabox Set true to hide metabox.
* @see https://wpset.org/sharing-image/hooks/#sharing_image_hide_metabox
*/
function sharing_image_hide_metabox( bool $hide_metabox ) : bool {
return current_user_can( Sharing_Image\NEEDED_CAP );
}
/**
* This is only relevant, if the metabox is visible!
*
* @param string $meta Updated post meta.
* @param string $post_id Post ID.
public function mf_update_post_meta_sharing_image( $meta, $post_id ) {
// get featured image
$featured_image = \get_post_thumbnail_id($post_id);
# error_log(var_export([
# \current_filter(),
# 'mf_update_post_meta_sharing_image()',
# $meta, $post_id
# ],true));
if($featured_image) {
if(isset($meta) && isset($meta['fieldset'])){
// loop all templates
foreach ($meta['fieldset'] as $index => $template) {
// assign featured image as attachment if no attachment defined
if(!isset($template['attachment']) || !$template['attachment']){
$meta['fieldset'][$index]['attachment'] = $featured_image;
}
}
}
}
return $meta;
}
*/
/**
* UNUSED right now
*
* @param string $path Font file path.
* @param array $layer Layer data.
*
* @see https://wpset.org/sharing-image/hooks/#sharing_image_get_fontpath
public static function sharing_image_get_fontpath( $path, $layer ) {
global $wp_styles, $wp_scripts;
wp_die(var_export([
$wp_styles,
$wp_scripts
],true));
return $path;
// return WP_PLUGIN_DIR . '/my-plugin/font.ttf';
}
*/