2015-04-18 26 views
0

您好專家wp插件開發人員,我需要幫助。我已經應用了波紋管代碼,但沒有使用默認值,並且在點擊保存按鈕後沒有顯示更新的通知。當我把所有的價值都放在儀表板的選項頁面上時,一切都很好。但不顯示所有更新的通知。請幫幫我。默認選項值不能自動工作

<?php 
function hkhk_options() { 
add_menu_page('Scrol Line Admin Settings', 'hk Settings','manage_options', 
'hk_settings', 'hk_admin_options'); 
} 
add_action('admin_menu', 'hkhk_options'); 


function hk_defaults() 
{ 
$hk_options = array(
    'back_color' => '#ccc', 
); 

} 
if (is_admin()) : 

function hk_register_settings() { 
register_setting('hkhk_options', 'hk_options', 'hk_validate_options'); 
} 
add_action('admin_init', 'hk_register_settings'); 

function hk_admin_options() { 
global $hk_options; 

if (! isset($_REQUEST['updated'])) 
$_REQUEST['updated'] = false; 
?> 
    <div class="wrap"> 
     <h2>Select Scrol Line Option</h2> 
     <?php if (false !== $_REQUEST['updated']) : ?> 
<div class="update fade"><p><strong><?php _e('Options saved'); ?></strong></p></div> 
<?php endif; // If the form has just been submitted, this shows the notification ?> 


     <form method="post" action="options.php"> 
     <?php $settings=get_option ('hk_options', $hk_options); ?> 
     <?php settings_fields('hkhk_options'); ?> 
     <table class="form-table"> 
      <tr valign="top"> 
       <th scope="row"><label for="back_color"> Back Color </label></th> 
       <td> 
        <input id="back_color" type="text" name="hk_options[back_color]" value="<?php esc_attr_e($settings['back_color']); ?>" class="wp-picker-container" /><p class="description"> Choose any color from here for background color. </p> 
       </td> 
      </tr> 
     </table> 
     <p class="submit"><input type="submit" class="button-primary" value="Save Options" /> </p> 
     </form> 
    </div> 
<?php 
} 
function hk_validate_options($input){ 
    global $hk_options; 
    $settings = get_option('hk_options', $hk_options); 
    $input['back_color'] = wp_filter_post_kses($input['back_color']); 

    return $input; 
} 
endif; 
function scrol_line_active() {?> 
<?php global $hk_options; $hk_settings = get_option ('hk_options', $hk_options); ?> 

<script type="text/javascript"> 
jQuery(document).ready(function($) { 
    jQuery("body") .hk({ 
     backColor: "<?php echo $hk_settings['back_color']; ?>", 

    }); 
}); 
</script> 
<?php 
} 
add_action ('wp_head', 'scrol_line_active'); 
?> 

回答

0

您正在檢查錯誤的REQUEST參數。您需要檢查$_REQUEST['settings-updated']
提交選項頁時,新的URL與/wp-admin/admin.php?page=hk_settings&settings-updated=true類似。

希望這會有所幫助。

+0

謝謝nilambar。工作。但不工作的默認選項。如果我從選項面板中刪除所有值,不工作我的插件。這意味着不能使用默認選項。 –

+0

@InfoBd請解釋你的問題。我無法理解。 – Nilambar