2016-06-11 71 views
0

我是WordPress新手,我已經構建了一個插件,只需在管理菜單上保存設置即可。爲什麼我的設置不能保存在WordPress的管理員?

但是,當我點擊保存按鈕,它只是帶我到options.php頁面,並沒有做任何事情。我已經查看過我的代碼幾次,我似乎無法找到爲什麼它不保存,並只停留在options.php頁面。

任何幫助將非常感謝!由於

function fflOptionsMenuLink(){ 

    add_options_page("Facebook Footer Link Options", "Facebook Footer Link","manage_options","ffl-options","fflOptionsContent"); 

} 

function fflOptionsContent(){ 


    $opt = get_option("ffl_settings"); 

    $output = "<div class='wrap'> 

     <h2>Facebook footer link settings </h2> 

     <form method='post' action='options.php' id='ffl_settings_group'>"; 

     settings_fields('ffl_settings_group'); 

    $output .= "<table class='form-table'> 
     <tbody> 
      <tr> 
       <th scope='row'><label for='ffl_settings[enable]'>Enable</label> </th> 
       <td><input name='ffl_settings[enable]' type='checkbox' id='ffl_settings[enable]' value='1' ></td> 
      </tr> 


      <tr> 
       <th scope='row'><label for='ffl_settings[facebook_url]'>Facebook Profile </label> </th> 
       <td><input name='ffl_settings[facebook_url]' type='text' id='ffl_settings[facebook_url]' value='{$opt["ffl_settings"]}' class='regular-text' ></td> 
      </tr> 


       <tr> 
       <th scope='row'><label for='ffl_settings[link_color]'>Enter color or hex value</label> </th> 
       <td><input name='ffl_settings[link_color]' type='text' id='ffl_settings[link_color]' value='{$opt["link_color"]}' class='regular-text' ></td> 
      </tr> 

      <tr> 
       <th scope='row'><label for='ffl_settings[show_in_feed]'>Show in feed</label> </th> 
       <td><input name='ffl_settings[show_in_feed]' type='checkbox' id='ffl_settings[show_in_feed]' value='1' ></td> 
      </tr> 



     </tbody> 


    </table> 
    <p class='submit'><input type='submit' name='submit' id='submit' class='button button-primary' value='Submit'> </p> 
     "; 






    $output .= "</form>"; 

    $output.="</div>"; 

    echo $output; 


} 


add_action("admin_menu","fflOptionsMenuLink"); 

//Register Settings 

function fflRegisterSetting(){ 

    register_setting("ffl_settings_group","ffl_settings"); 

} 

add_action("admin_init","ffl_register_setting"); 

回答

0

幾件事情......

  1. 發行 - 用於註冊設置fflRegisterSettingffl_register_setting在你的鉤子你函數名。
  2. 發行 - 你是不是通過輸出功能WP提交按鈕
  3. 提醒 - facebook_url字段值錯誤$opt["link_color"],但由於複選框都沒有準備好或者所以我認爲這是一個WIP)

所以,你的代碼應該是這個樣子 -

function fflOptionsMenuLink(){ 

    add_options_page("Facebook Footer Link Options", "Facebook Footer Link","manage_options","ffl-options","fflOptionsContent"); 

} 

function fflOptionsContent(){ 


    $opt = get_option("ffl_settings"); 

    echo "<div class='wrap'> 

     <h2>Facebook footer link settings </h2> 

     <form method='post' action='options.php' id='ffl_settings_group'>"; 

    settings_fields('ffl_settings_group'); 

    echo "<table class='form-table'> 
     <tbody> 
      <tr> 
       <th scope='row'><label for='ffl_settings[enable]'>Enable</label> </th> 
       <td><input name='ffl_settings[enable]' type='checkbox' id='ffl_settings[enable]' value='1' ></td> 
      </tr> 


      <tr> 
       <th scope='row'><label for='ffl_settings[facebook_url]'>Facebook Profile </label> </th> 
       <td><input name='ffl_settings[facebook_url]' type='text' id='ffl_settings[facebook_url]' value='{$opt["facebook_url"]}' class='regular-text' ></td> 
      </tr> 


       <tr> 
       <th scope='row'><label for='ffl_settings[link_color]'>Enter color or hex value</label> </th> 
       <td><input name='ffl_settings[link_color]' type='text' id='ffl_settings[link_color]' value='{$opt["link_color"]}' class='regular-text' ></td> 
      </tr> 

      <tr> 
       <th scope='row'><label for='ffl_settings[show_in_feed]'>Show in feed</label> </th> 
       <td><input name='ffl_settings[show_in_feed]' type='checkbox' id='ffl_settings[show_in_feed]' value='1' ></td> 
      </tr> 
     </tbody> 
    </table> 
    "; 

    submit_button(); // Get the submit button from this function 

    echo "</form>"; 

    echo "</div>"; 


} 


add_action("admin_menu","fflOptionsMenuLink"); 

//Register Settings 

function fflRegisterSetting(){ 

    register_setting("ffl_settings_group","ffl_settings"); 

} 

add_action("admin_init","fflRegisterSetting"); 
+0

嗨感謝您的答覆。我複製並粘貼了你的代碼,但它仍然沒有工作 – json2021

+0

嗯...你會得到什麼? – shramee

+0

Ohh ...更新了我的回答...讓我知道如果它現在:) – shramee

相關問題