Example #1
0
function wpef7_install()
{
    global $wpdb, $wpef7;
    if (wpef7_table_exists()) {
        return;
    }
    // Exists already
    $charset_collate = '';
    if ($wpdb->has_cap('collation')) {
        if (!empty($wpdb->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
        }
        if (!empty($wpdb->collate)) {
            $charset_collate .= " COLLATE {$wpdb->collate}";
        }
    }
    $wpdb->query("CREATE TABLE IF NOT EXISTS {$wpef7->contactforms} (\r\n\t\tcf7_unit_id bigint(20) unsigned NOT NULL auto_increment,\r\n\t\ttitle varchar(200) NOT NULL default '',\r\n\t\tform text NOT NULL,\r\n\t\tmail text NOT NULL,\r\n\t\tmail_2 text NOT NULL,\r\n\t\tmessages text NOT NULL,\r\n\t\tadditional_settings text NOT NULL,\r\n\t\tPRIMARY KEY (cf7_unit_id)) {$charset_collate};");
    if (!wpef7_table_exists()) {
        return false;
    }
    // Failed to create
    $legacy_data = get_option('wpef7');
    if (is_array($legacy_data) && is_array($legacy_data['contact_forms']) && $legacy_data['contact_forms']) {
        foreach ($legacy_data['contact_forms'] as $key => $value) {
            $wpdb->insert($wpef7->contactforms, array('cf7_unit_id' => $key, 'title' => $value['title'], 'form' => maybe_serialize($value['form']), 'mail' => maybe_serialize($value['mail']), 'mail_2' => maybe_serialize($value['mail_2']), 'messages' => maybe_serialize($value['messages']), 'additional_settings' => maybe_serialize($value['additional_settings'])), array('%d', '%s', '%s', '%s', '%s', '%s', '%s'));
        }
    } else {
        wpef7_load_plugin_textdomain();
        $wpdb->insert($wpef7->contactforms, array('title' => __('Contact form', 'wpef7') . ' 1', 'form' => maybe_serialize(wpef7_default_form_template()), 'mail' => maybe_serialize(wpef7_default_mail_template()), 'mail_2' => maybe_serialize(wpef7_default_mail_2_template()), 'messages' => maybe_serialize(wpef7_default_messages_template())));
    }
}
Example #2
0
<?php

/* No table warning */
if (!wpef7_table_exists()) {
    if (current_user_can('activate_plugins')) {
        $create_table_link_url = wpef7_admin_url(array('wpef7-create-table' => 1));
        $create_table_link_url = wp_nonce_url($create_table_link_url, 'wpef7-create-table');
        $message = sprintf(__('<strong>The database table for Contact Form 7 does not exist.</strong> You must <a href="%s">create the table</a> for it to work.', 'wpef7'), $create_table_link_url);
    } else {
        $message = __("<strong>The database table for Contact Form 7 does not exist.</strong>", 'wpef7');
    }
    ?>
	<div class="wrap">
	<?php 
    screen_icon('edit-pages');
    ?>
	<h2><?php 
    echo esc_html(__('Contact Form 7', 'wpef7'));
    ?>
</h2>
	<div id="message" class="updated fade">
	<p><?php 
    echo $message;
    ?>
</p>
	</div>
	</div>
<?php 
    return;
}
?>