Replies: 0
Hi everyone,
I have a plugin, that uses CF7-Form-Data for a calculation and I want to show the dynamic results in a table with shortcodes. The shortcode-values are displayed, but I don’t manage to change the shortcodes. From my understanding the call-back-function should be called, when the shortcode is rendered on the page. It seems to be called before the rest of the functions were called.
Any idea? Thanks a million…
<?php
//Grundsätzliche Initialisierung des Plugins
function XXX_betriebskosten() {
//Übersetzung
betriebskosten_shortcodes();
}
/*SETTINGS */
$betriebskosten_formid = 3027;
$betriebskosten_shortcodes = array(
'betriebstage' => 1,
'spuelleistung' => 2,
'betriebskosten' => 3
);
//Alle Aktionen nur ausführen, wenn es sich um das Betriebskosten-Form handelt.
add_action( 'wpcf7_contact_form', 'action_wpcf7_contact_form', 1, 1 );
//Form-ID prüfen und nur für Betriebskosten-Form die weiteren Filter laden, damit die Performance der Website nicht leidet. .
function action_wpcf7_contact_form( $instance ) {
//Wenn es die richtige Form-ID ist, können alle weiteren Filter ausgeführt werden.
//Kommt oben aus den Settings.
global $betriebskosten_formid;
if ( $instance->ID() == $betriebskosten_formid ) {
//Filter ruft Funktion auf, die automatisch das data:maschinen füllt
add_filter('wpcf7_form_tag_data_option', 'get_machine_select_values' , 10, 3);
//Wenn Action gesetzt ist, wurde das Formular abgeschickt, die Validierung sollte erfolgt sein und die Berechnung kann beginnen
if ( isset( $_POST["action"] ) ) {
vergleichStarten();
}
}
};
function vergleichStarten() {
//Holt die in der Funktion getPostedData ausgewählten Daten, die vom Formular übertragen wurden.
/* */
changeBetriebsKostenShortcode('betriebskosten','1234');
}
function betriebskosten_shortcodes() {
global $betriebskosten_shortcodes;
foreach ( $betriebskosten_shortcodes as $shortcodekey => $shortcodevalue) {
add_shortcode($shortcodekey,'shortcodeOutput');
}
}
function changeBetriebsKostenShortcode($key, $value) {
global $betriebskosten_shortcodes;
$betriebskosten_shortcodes[$key] = $value;
}
function shortcodeOutput( $atts = [], $content = null, $tag) {
global $betriebskosten_shortcodes;
$content = "Es wurde ". $tag . "aufgerufen: " . $betriebskosten_shortcodes[$tag];
return $content;
}
add_action('init', 'XXX_betriebskosten');