안녕하세요 저는 데이터베이스 테이블에 데이터를 입력하기 위해 Admin이 필요한 곳에 워드 프레스 플러그인을 만들고 있습니다. 플러그인이 활성화 될 때 db 테이블을 설치할 수 있지만 사용자 입력을 저장하는 방법을 알 수는 없습니다. 저는 WP 포럼에 질문했지만 그들은 죽었습니다. 어떤 지침을 빌려줄 수있는 경험 많은 전문가는 크게 감사 할 것입니다.도움말 Wordpress 플러그인을 사용하여 데이터베이스에 입력 데이터 작성
<?php
/*******************************************************************
* INSTALL DB TABLE - ONLY AT RUN TIME *
*******************************************************************/
function ed_xml_install() {
global $wpdb;
$ed_xml_data = $wpdb->prefix . "ed_xml_data";
if($wpdb->get_var("SHOW TABLES LIKE '$ed_xml_data'") != $ed_xml_data) {
$sql = "CREATE TABLE " . ed_xml_data . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name tinytext NOT NULL,
address text NOT NULL,
url VARCHAR(55) NOT NULL,
phone bigint(11) DEFAULT '0' NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$name = "Example Business Name";
$address = "1234 Example Street";
$url = "http://www.google.com";
$phone = "523-3232-323232";
$insert = "INSERT INTO " . ed_xml_data .
" (phone, name, address, url) " .
"VALUES ('" . phone() . "','" . $wpdb->escape($name) . "','" . $wpdb->escape($address) . "', '" . $wpdb->escape($url) . "')";
$results = $wpdb->query($insert);
}
}
//call the install hook
register_activation_hook(__FILE__,'ed_xml_install');
/*******************************************************************
* CREATE MENU, CREATE MENU CONTENT *
*******************************************************************/
if (is_admin()){
/* place it under the ED menu */
//TODO $allowed_group = '';
/* Call the html code */
add_action('admin_menu', 'ed_xmlcreator_admin_menu');
function ed_xmlcreator_admin_menu() {
add_options_page('ED XML Creator', 'ED XML Creator', 'administrator',
'ed_xml_creator', 'ed_xmlcreator_html_page');
}
}
/*******************************************************************
* CONTENT OF MENU CONTENT *
*******************************************************************/
function ed_xmlcreator_html_page() {
<div>
<h2>Editors Deal XML Options</h2>
<p>Fill in the below information which will get passed to the .XML file.</p>
<p>[<a href="" title="view XML file">view XML file</a>]</p>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<table width="510">
<!-- title -->
<tr valign="top">
<th width="92" scope="row">Deal URL</th>
<td width="406">
<input name="url" type="text" id="url"
value="<?php echo get_option('url'); ?>" />
</td>
</tr>
<!-- description -->
<tr valign="top">
<th width="92" scope="row">Deal Address</th>
<td width="406">
<input name="address" type="text" id="address"
value="<?php echo get_option('address'); ?>" />
</td>
</tr>
<!-- business name -->
<tr valign="top">
<th width="92" scope="row">Business Phone</th>
<td width="406">
<input name="phone" type="text" id="phone"
value="<?php echo get_option('phone'); ?>" />
</td>
</tr>
<!-- address -->
<tr valign="top">
<th width="92" scope="row">Business Name</th>
<td width="406">
<input name="name" type="text" id="name"
value="<?php echo get_option('name'); ?>" />
</td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="hello_world_data" />
<p>
<input type="submit" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
?>
'($ _POST ['제출 '=='업데이트 옵션 ') { // db에 SQL 바를 추가 }' – HollerTrain