Example #1
0
function wpcf7_captcha_ajax_echo_filter($items)
{
    global $wpcf7_contact_form;
    if (!is_a($wpcf7_contact_form, 'WPCF8_ContactForm')) {
        return $items;
    }
    if (!is_array($items)) {
        return $items;
    }
    $fes = $wpcf7_contact_form->form_scan_shortcode(array('type' => 'captchac'));
    if (empty($fes)) {
        return $items;
    }
    $refill = array();
    foreach ($fes as $fe) {
        $name = $fe['name'];
        $options = $fe['options'];
        if (empty($name)) {
            continue;
        }
        $op = wpcf7_captchac_options($options);
        if ($filename = wpcf7_generate_captcha($op)) {
            $captcha_url = trailingslashit(wpcf7_captcha_tmp_url()) . $filename;
            $refill[$name] = $captcha_url;
        }
    }
    if (!empty($refill)) {
        $items['captcha'] = $refill;
    }
    return $items;
}
function wpcf7_captcha_ajax_refill($items)
{
    if (!is_array($items)) {
        return $items;
    }
    $fes = wpcf7_scan_shortcode(array('type' => 'captchac'));
    if (empty($fes)) {
        return $items;
    }
    $refill = array();
    foreach ($fes as $fe) {
        $name = $fe['name'];
        $options = $fe['options'];
        if (empty($name)) {
            continue;
        }
        $op = wpcf7_captchac_options($options);
        if ($filename = wpcf7_generate_captcha($op)) {
            $captcha_url = wpcf7_captcha_url($filename);
            $refill[$name] = $captcha_url;
        }
    }
    if (!empty($refill)) {
        $items['captcha'] = $refill;
    }
    return $items;
}
function cf7bs_captcha_ajax_refill($items)
{
    if (!is_array($items)) {
        return $items;
    }
    $fes = wpcf7_scan_shortcode(array('type' => 'captchar'));
    if (empty($fes)) {
        return $items;
    }
    $refill = array();
    foreach ($fes as $fe) {
        if (cf7bs_captchar_has_captchac($fe)) {
            $fe = cf7bs_captchar_to_captchac($fe);
            $name = $fe['name'];
            $options = $fe['options'];
            if (empty($name)) {
                continue;
            }
            $op = wpcf7_captchac_options($options);
            if ($filename = wpcf7_generate_captcha($op)) {
                $captcha_url = wpcf7_captcha_url($filename);
                $refill[$name] = $captcha_url;
            }
        }
    }
    if (count($refill) > 0) {
        if (!isset($items['captcha'])) {
            $items['captcha'] = $refill;
        } else {
            $items['captcha'] = array_merge($items['captcha'], $refill);
        }
    }
    return $items;
}