-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgruenerator.php
266 lines (238 loc) · 10.1 KB
/
gruenerator.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/**
* @package Gruenerator
* @version 1.0.0
*
* @wordpress-plugin
* Plugin Name: Grünerator WordPress
* Description: Erstelle professionelle Kandidatenseiten für grüne Kandidierende mit speziellen Gutenberg-Blöcken. Dieses Plugin wurde speziell für das Sunflower WordPress-Theme entwickelt und erfordert dessen Installation.
* Version: 1.0.0
* Author: Moritz Wächter
* License: GPL v2 oder später
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: gruenerator
* Domain Path: /languages
* Requires at least: 5.8
* Requires PHP: 7.4
* Requires Plugins:
* Requires Themes: sunflower
*
* Dieses Plugin ist eine Erweiterung für das Sunflower-Theme und fügt spezielle
* Gutenberg-Blöcke und Funktionen hinzu, die auf das Theme abgestimmt sind.
*
* @since 1.0.0
*/
if (!defined('ABSPATH')) {
exit;
}
// Definiere Konstanten für Pfade
define('GRUENERATOR_PATH', plugin_dir_path(__FILE__));
define('GRUENERATOR_URL', plugin_dir_url(__FILE__));
// Lade die Hauptklassen
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-customizer.php';
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-blocks.php';
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-meta-fields.php';
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-social-media.php';
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-settings.php';
// Lade Admin-spezifische Dateien
require_once GRUENERATOR_PATH . 'admin/gruenerator-setup-wizard.php';
require_once GRUENERATOR_PATH . 'admin/social-media-settings-page.php';
require_once GRUENERATOR_PATH . 'admin/gruenerator-settings.php';
// Erforderliche Dateien einbinden
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-default-content.php';
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-content-source.php';
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-customizer.php';
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-settings.php';
require_once GRUENERATOR_PATH . 'includes/class-gruenerator-meta-fields.php';
/**
* Enqueue Frontend Styles und Inline CSS
*/
function gruenerator_enqueue_custom_css() {
$custom_css = get_option('gruenerator_custom_css', '');
if (!empty($custom_css)) {
wp_add_inline_style('gruenerator-blocks-frontend', $custom_css);
}
}
add_action('wp_enqueue_scripts', 'gruenerator_enqueue_custom_css');
// Hier können weitere Funktionen und Hooks hinzugefügt werden...
/**
* Initialisiert das Admin-Menü
*
* @since 1.0.0
* @return void
*/
function gruenerator_add_admin_menu() {
add_menu_page(
__('Grünerator', 'gruenerator'),
__('Grünerator', 'gruenerator'),
'manage_options',
'gruenerator-generator',
'gruenerator_main_page',
'dashicons-admin-generic'
);
add_submenu_page(
'gruenerator-generator',
__('Social Media Einstellungen', 'gruenerator'),
__('Social Media', 'gruenerator'),
'manage_options',
'gruenerator-social-media',
'gruenerator_social_media_settings_page'
);
add_submenu_page(
'gruenerator-generator',
__('Setup-Assistent', 'gruenerator'),
__('Setup-Assistent', 'gruenerator'),
'manage_options',
'gruenerator-setup-wizard',
'gruenerator_setup_wizard'
);
add_submenu_page(
'gruenerator-generator',
__('Einstellungen', 'gruenerator'),
__('Einstellungen', 'gruenerator'),
'manage_options',
'gruenerator-settings',
'gruenerator_settings_page'
);
}
add_action('admin_menu', 'gruenerator_add_admin_menu');
function gruenerator_create_page_callback() {
?>
<div class="wrap">
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
<p><?php _e('Klicke auf den Button unten, um eine neue Seite mit dem Grünerator Landing Page Pattern zu erstellen.', 'gruenerator'); ?></p>
<form method="post" action="">
<?php wp_nonce_field('gruenerator_create_page', 'gruenerator_nonce'); ?>
<input type="submit" name="gruenerator_create_page" class="button button-primary" value="<?php _e('Neue Seite erstellen', 'gruenerator'); ?>">
</form>
</div>
<?php
if (isset($_POST['gruenerator_create_page']) && check_admin_referer('gruenerator_create_page', 'gruenerator_nonce')) {
$page_title = 'Grünerator Landing Page';
$page_content = '<!-- wp:pattern {"slug":"gruenerator/landing-page"} /-->';
$page_id = wp_insert_post(array(
'post_title' => $page_title,
'post_content' => $page_content,
'post_status' => 'publish',
'post_type' => 'page',
));
if ($page_id) {
$page_url = get_permalink($page_id);
echo '<div class="notice notice-success"><p>' . sprintf(__('Seite erfolgreich erstellt. <a href="%s" target="_blank">Seite anzeigen</a>', 'gruenerator'), esc_url($page_url)) . '</p></div>';
} else {
echo '<div class="notice notice-error"><p>' . __('Fehler beim Erstellen der Seite.', 'gruenerator') . '</p></div>';
}
}
}
function gruenerator_main_page() {
?>
<div class="wrap gruenerator-dashboard">
<div class="gruenerator-header">
<h1>
<span class="dashicons dashicons-admin-generic"></span>
Willkommen beim Grünerator
</h1>
<p class="about-description">
Erstelle eine professionelle politische Landingpage in wenigen Minuten.
</p>
</div>
<div class="gruenerator-grid">
<div class="gruenerator-card">
<div class="gruenerator-card-header">
<span class="dashicons dashicons-admin-settings"></span>
<h2>Setup-Assistent</h2>
</div>
<p>Starte den Setup-Assistenten, um deine Landingpage Schritt für Schritt zu erstellen.</p>
<a href="<?php echo admin_url('admin.php?page=gruenerator-setup-wizard'); ?>" class="button button-primary">
Zum Setup-Assistenten
</a>
</div>
<div class="gruenerator-card">
<div class="gruenerator-card-header">
<span class="dashicons dashicons-share"></span>
<h2>Social Media</h2>
</div>
<p>Verwalte deine Social Media Links und Einstellungen.</p>
<a href="<?php echo admin_url('admin.php?page=gruenerator-social-media'); ?>" class="button button-primary">
Social Media verwalten
</a>
</div>
<div class="gruenerator-card">
<div class="gruenerator-card-header">
<span class="dashicons dashicons-admin-tools"></span>
<h2>Einstellungen</h2>
</div>
<p><?php echo Gruenerator_Settings::get_dashboard_description(); ?></p>
<a href="<?php echo admin_url('admin.php?page=gruenerator-settings'); ?>" class="button button-primary">
Einstellungen verwalten
</a>
</div>
<div class="gruenerator-footer">
<h3>Hilfe & Support</h3>
<p>
Benötigst du Hilfe? Besuche unsere <a href="https://github.com/netzbegruenung/Gruenerator_Wordpress" target="_blank">GitHub-Seite</a>
oder schreibe eine E-Mail an <a href="mailto:[email protected]">[email protected]</a>.
</p>
</div>
</div>
</div>
<?php
}
/**
* Definiere die Block-Kategorie
*/
function gruenerator_block_category( $categories, $post ) {
return array_merge(
$categories,
array(
array(
'slug' => 'gruenerator-category',
'title' => __( 'Grünerator Blöcke', 'gruenerator' ),
'icon' => null,
),
)
);
}
add_filter('block_categories_all', 'gruenerator_block_category', 10, 2);
/**
* Modifiziert den Output des Kontaktformular-Blocks, um ein Hintergrundbild hinzuzufügen
*/
function gruenerator_modify_contact_form_output($block_content, $block) {
if ($block['blockName'] === 'sunflower/contact-form') {
$background_image = isset($block['attrs']['grueneratorBackgroundImage']) ? $block['attrs']['grueneratorBackgroundImage'] : '';
$title = isset($block['attrs']['grueneratorTitle']) ? $block['attrs']['grueneratorTitle'] : '';
if ($background_image || $title) {
$wrapper_start = '<div class="wp-block-sunflower-contact-form-wrapper"' . ($background_image ? ' style="background-image: url(\'' . esc_url($background_image) . '\');"' : '') . '>';
$wrapper_end = '</div>';
if ($title) {
$title_html = '<h2 class="wp-block-sunflower-contact-form-title">' . esc_html($title) . '</h2>';
$block_content = $title_html . $block_content;
}
$block_content = $wrapper_start . $block_content . $wrapper_end;
}
}
return $block_content;
}
add_filter('render_block', 'gruenerator_modify_contact_form_output', 10, 2);
function gruenerator_enqueue_admin_scripts($hook) {
// Lade Media-Scripts auf allen Admin-Seiten, die sie benötigen könnten
if (strpos($hook, 'gruenerator') !== false ||
$hook == 'post.php' ||
$hook == 'post-new.php' ||
$hook == 'page.php' ||
$hook == 'page-new.php') {
wp_enqueue_media();
wp_enqueue_script('jquery');
wp_enqueue_script('gruenerator-admin-js', GRUENERATOR_URL . 'admin/js/gruenerator-admin.js', array('jquery'), '1.0.0', true);
}
}
add_action('admin_enqueue_scripts', 'gruenerator_enqueue_admin_scripts');
/**
* Enqueue Admin Styles
*/
function gruenerator_enqueue_admin_styles($hook) {
// Fügen Sie hier Bedingungen hinzu, um die Styles nur auf bestimmten Admin-Seiten zu laden
wp_enqueue_style('gruenerator-admin-styles', GRUENERATOR_URL . 'build/index.css', array(), '1.0.0');
}
add_action('admin_enqueue_scripts', 'gruenerator_enqueue_admin_styles');
?>