Upload folder via GUI - inc
This commit is contained in:
118
inc/helpers/helper-functions.php
Normal file
118
inc/helpers/helper-functions.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
function wmf_create_submissions_table() {
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . 'wmf_submissions';
|
||||
$charset = $wpdb->get_charset_collate();
|
||||
$sql = "CREATE TABLE IF NOT EXISTS {$table} (
|
||||
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
form_id BIGINT(20) UNSIGNED NOT NULL,
|
||||
data LONGTEXT NOT NULL,
|
||||
ip VARCHAR(45) DEFAULT '',
|
||||
user_agent TEXT DEFAULT '',
|
||||
status VARCHAR(20) DEFAULT 'neu',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY form_id (form_id)
|
||||
) {$charset};";
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta( $sql );
|
||||
update_option( 'wmf_db_version', '2.0' );
|
||||
}
|
||||
|
||||
function wmf_get_fields() { return WMF_Field_Registry::instance()->get_fields(); }
|
||||
function wmf_get_field( $type ) { return WMF_Field_Registry::instance()->get_field( $type ); }
|
||||
function wmf_get_shortcode( $id ) { return '[wp_multi_formular id="' . intval($id) . '"]'; }
|
||||
function wmf_unique_id() { return 'field_' . substr( md5( uniqid( '', true ) ), 0, 8 ); }
|
||||
|
||||
function wmf_get_form_meta( $form_id ) {
|
||||
$defaults = array(
|
||||
'fields' => array(),
|
||||
'submit_label' => 'Absenden',
|
||||
'success_message' => 'Vielen Dank! Ihre Nachricht wurde gesendet.',
|
||||
'error_message' => 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.',
|
||||
'notify_admin' => '1',
|
||||
'admin_email' => get_option('admin_email'),
|
||||
'admin_subject' => 'Neue Formulareinreichung',
|
||||
'admin_reply_to' => '1',
|
||||
'notify_sender' => '0',
|
||||
'sender_subject' => 'Ihre Nachricht wurde empfangen',
|
||||
'sender_message' => 'Vielen Dank für Ihre Nachricht. Wir melden uns bald.',
|
||||
'from_name' => get_bloginfo('name'),
|
||||
'from_email' => get_option('admin_email'),
|
||||
'save_submissions' => '1',
|
||||
'recaptcha_enabled' => '0',
|
||||
'honeypot_enabled' => '1',
|
||||
'active_email_service' => '',
|
||||
'email_list_field' => '',
|
||||
'redirect_url' => '',
|
||||
'css_class' => '',
|
||||
'multi_step' => '0',
|
||||
'step_labels' => array(),
|
||||
'show_progress' => '1',
|
||||
);
|
||||
$meta = get_post_meta( $form_id, '_wmf_form_data', true );
|
||||
if ( ! is_array( $meta ) ) $meta = array();
|
||||
return wp_parse_args( $meta, $defaults );
|
||||
}
|
||||
|
||||
function wmf_save_form_meta( $form_id, $data ) {
|
||||
update_post_meta( $form_id, '_wmf_form_data', $data );
|
||||
}
|
||||
|
||||
function wmf_get_submissions( $form_id, $args = array() ) {
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . 'wmf_submissions';
|
||||
$defaults = array( 'limit' => 50, 'offset' => 0, 'status' => '', 'search' => '' );
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
$where = $wpdb->prepare( 'WHERE form_id = %d', $form_id );
|
||||
if ( $args['status'] )
|
||||
$where .= $wpdb->prepare( ' AND status = %s', $args['status'] );
|
||||
if ( $args['search'] )
|
||||
$where .= $wpdb->prepare( ' AND data LIKE %s', '%' . $wpdb->esc_like( $args['search'] ) . '%' );
|
||||
|
||||
return $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT * FROM {$table} {$where} ORDER BY created_at DESC LIMIT %d OFFSET %d",
|
||||
$args['limit'], $args['offset']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wmf_count_submissions( $form_id, $status = '', $search = '' ) {
|
||||
global $wpdb;
|
||||
$where = $wpdb->prepare( 'WHERE form_id = %d', $form_id );
|
||||
if ( $status )
|
||||
$where .= $wpdb->prepare( ' AND status = %s', $status );
|
||||
if ( $search )
|
||||
$where .= $wpdb->prepare( ' AND data LIKE %s', '%' . $wpdb->esc_like( $search ) . '%' );
|
||||
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wmf_submissions {$where}" );
|
||||
}
|
||||
|
||||
function wmf_get_client_ip() {
|
||||
foreach ( array('HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','REMOTE_ADDR') as $k ) {
|
||||
if ( ! empty( $_SERVER[$k] ) ) {
|
||||
$ip = trim( explode(',', $_SERVER[$k])[0] );
|
||||
if ( filter_var($ip, FILTER_VALIDATE_IP) ) return $ip;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sicherer Redirect - funktioniert auch wenn Header bereits gesendet wurden
|
||||
* (z.B. durch Plugins die Output vor wp_redirect() ausgeben)
|
||||
*/
|
||||
function wmf_safe_redirect( $url ) {
|
||||
$url = esc_url_raw( $url );
|
||||
if ( ! headers_sent() ) {
|
||||
wp_redirect( $url );
|
||||
exit;
|
||||
}
|
||||
// JavaScript-Fallback
|
||||
echo '<script>window.location.href=' . wp_json_encode( $url ) . ';</script>';
|
||||
echo '<noscript><meta http-equiv="refresh" content="0;url=' . esc_attr( $url ) . '"></noscript>';
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user