我不知道确切的原因,但wp\u update\u post()使chek函数无法正常工作。wpdb querys的以下代码正在运行:
<?php
add_action( 'admin_init', 'init_cf7_privacy');
function init_cf7_privacy() {
if ((check_cf7_installation()) && (find_contact_form() != "")) {
$formContent = get_contactform_content();
$acceptance = '[acceptance acceptance-842]<small>Ich habe die <a href="/datenschutzerklaerung">Datenschutzerklärung</a> zur Kenntnis genommen. Ich stimme zu, dass meine Angaben zur Kontaktaufnahme und für Rückfragen dauerhaft gespeichert werden. </small>[/acceptance]';
/*
if (check_cf7_installation())
echo "CF7 Returned true!" . "\r\n";
echo "CF Page ID: " . find_contact_form() . "\r\n";
if (check_submit( $formContent ))
echo "Submit Returned true!" . "\r\n";
if (check_acceptance( $formContent ))
echo "Acceptance Returned true!" . "\r\n";
echo concatenate_acceptance_submit( $formContent, $acceptance ) . "\r\n";
*/
add_acceptance( $formContent, $acceptance );
}
}
function check_cf7_installation() {
if (class_exists('wpcf7'))
return true;
}
function find_contact_form() {
$searchTitle = 'Kontakt';
$page = get_page_by_title( $searchTitle, OBJECT, 'wpcf7_contact_form');
return $page->ID;
}
function get_contactform_content() {
$my_postid = find_contact_form();
global $wpdb;
$content = $wpdb->get_var(
$wpdb->prepare( "
SELECT meta_value
FROM ".$wpdb->prefix."postmeta
WHERE post_id = %d
AND meta_key = %s
",
$my_postid, '_form' )
);
return $content;
}
function concatenate_acceptance_submit( $formContent, $acceptance ) {
if( preg_match('/.+\[submit\s["].+["]\].+/', $formContent, $matches ) ) {
return $acceptance . "\r\n" . "\r\n" . $matches[0];
}
}
function check_submit( $formContent ) {
if ( preg_match('/\[submit\s["].+["]\]/', $formContent) )
return true;
}
function check_acceptance( $formContent ) {
if ( preg_match('/\[acceptance\s.+\]/', $formContent, $matches) )
return true;
}
function add_acceptance( $formContent, $acceptance ) {
if ( check_submit( $formContent ) && !check_acceptance( $formContent ) ) {
if ( preg_match('/.+\[submit\s["].+["]\].+/', $formContent, $matches) ) {
$formContentRep = str_replace( $matches[0], concatenate_acceptance_submit( $formContent, $acceptance ), $formContent );
//Write new Cotact Form Content to Database
global $wpdb;
$wpdb->query(
$wpdb->prepare( "
UPDATE ".$wpdb->prefix."postmeta
SET meta_value = %s
WHERE post_id = %d
AND meta_key = %s
",
$formContentRep, find_contact_form(), '_form' )
);
}
}
}