2012-08-14 3 views
1

먼저, 나는 순진하고 어리석은 일을 사전에 사과하고 싶습니다. 나는 초보 프로그래머이지만 배우려고 노력하고있다. 바로 지금, 인턴쉽의 일환으로 wordpress 용 플러그인을 개발하려고합니다. 플러그인은 대부분 필요한 작업을 수행하지만 설정 페이지를 원하는 방식으로 작동시키지 못하는 것 같습니다. 플러그인의 초기화 부분이 제대로 작동하고 있음을 알고 있지만 설정 페이지를 사용하는 데 문제가 있습니다. 특히, 정보를 저장하기 위해 _POST을 어디에서 어떻게 사용하지 않습니까? 또한 설정 페이지에서 정보를받은 후 update_option 함수 호출을 배치 할 위치를 지정하지 않습니다. 여기 내 코드는 바로 지금입니다 :WordPress 용 사용자 정의 PHP 플러그인의 저축 설정

add_action('admin_menu', 'menu'); 
add_action('admin_init', 'plugin_admin_init'); 

function plugin_admin_init() { // whitelist options 
    register_setting('plugin_options', 'plugin_options', 'plugin_options_validate'); 
    add_settings_section('plugin_main', 'Main Settings', 'plugin_section_text',   'plugin'); 
    add_settings_field('plugin_text_string', 'REE View Count Settings',   'plugin_setting_string', 'plugin', 'plugin_main'); 
} 

function menu() { 
    add_options_page('REE View Count Options', 'REE View Count', 'manage_options',  'plugin', 'plugin_options_page'); 
} 

// generates the settings web page 
function plugin_options_page() { 
    echo '<div class="wrap">'; 
    echo '<h2>Options</h2>'; 
    echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">'; 
    // In the line above, I don't know what to put. The file name of the plugin? 
    // The URL of the settings page on the admin page? Or what I have currently? 
    // Both the first and last options bring up a 404 page. 
    settings_fields('plugin_options'); 
    do_settings_sections('plugin'); 
    echo '<input name="Submit" type="submit" value="' . esc_attr_e('Save Changes') . '"   />'; 
    echo '</form>'; 
    //update_option('plugin_options', $_POST['plugin_options']); 
    // Where should I try to update the option? And how? 
    echo '</div>'; 
} 

//from add_settings_section parameter 3, in plugin_admin_init 
function plugin_section_text() { 
    echo '<p>Main description of this section here.</p>'; 
} 

//Function from 3 paramter of add_settings_field in plugin_admin_init that outputs  input HTML 
function plugin_setting_string() { 
    $options = get_option('plugin_options'); 
    echo 'value of options is: ' . $options; 
    echo "<input id='plugin_text_string' name='plugin_options' size='40' type='text' 
    value='{$options}' />"; 
} 

//Validation function from register_setting in plugin_admin_init 
function plugin_options_validate($input) { 
    echo "this is input: " . $input; 
    $newinput = trim($input); 
    if(!preg_match('/^[0-9]+$/', $newinput)) { 
     $newinput = 10; 
    } 
    update_option('plugin_options', $newinput); 
    return $newinput; 
} 

참고 : 실제로 사용하지 않는이 정확한 기능/변수 이름 - 나는 그들 실제 플러그인 이름을 접두어로했다.

도와 주시겠습니까? 관리자가 입력 한 정보를 설정 페이지로 가져 와서 해당 정보 (이 경우 단일 번호)로 데이터베이스를 업데이트하고 싶습니다. 나는 PHP _POST를 사용해야한다는 것을 알고 있지만 어떻게 해야할지 모르겠습니다. 또한 action = "the_file_name.php"를 사용하면 제출할 때 404 오류가 발생하므로 게시 할 위치가 없습니다. 내가 제출 한 정보를 나중에 사용할 수 있도록 양식의 조치는 무엇입니까? 그리고 내가 그렇게 한 후 어떻게 설정을 업데이트합니까? 그리고 어떻게하면 update_option을 어디에 두어야합니까? 이것이 뻔뻔 ​​스럽거나 모호하게 보인다면 사과드립니다. 나는 머리가 다소 이상하다고 느낍니다. 도움이된다면

, 나는이 가이드의 도움으로, 플러그인 자체와 동일한 파일에이 설정 페이지를 구축했습니다 : 불행하게도 http://ottopress.com/2009/wordpress-settings-api-tutorial/

, 내가 말하는 그 가이드에 아무것도 표시되지 않습니다 정보 업데이트, 단지 페이지 자체 만들기.

답변

관련 문제