2016-04-07 42 views
0

我將此序列化數據放入我的wp_option表中。 我想創建一個函數來獲取數據(get_option),然後將過濾器應用於改變「http://mywebsite.com/wp-content/uploads/2016/03/logo.png」值成別的東西......如何將過濾器(add_filter)應用於Wordpress中的get_option

(146「theme_mods_theme兒」,「一:9 :{i:0; b:0; s:8:「bg_color」; s:7:「#ef4036」; s:11:「header_logo」; s:65:「http://mywebsite.com/wp-content/uploads/2016/03/logo.png」; s:14:「menu_no_switch」 ; S:0: 「」,S:10: 「main_color」; S:7: 「#ef4036」; S:18: 「nav_menu_locations」;一個:1:{S:11: 「首標菜單」; I: 2;} s:9:「copyright」; s:77:「nom nom nom nom nom」; s:7:「credits」; s:66:「la la la la」; s:8:「sidebars」; s :51:「音頻1 |音頻2 |音頻3 |音頻4 |新聞1 |新聞2 |新聞3 |新聞4」;}','是'),

回答

1

您需要使用apply_filters將過濾器添加到變量。

首先,從數據庫中獲取get_option的選項數組。然後拔出header_logo密鑰並將其存儲在一個變量中。

接下來,添加一個過濾器的變量。最後,編寫一個函數返回新值並使用add_filter將其註冊到您的過濾器。

// The header logo 
$theme_mods_theme_child_options = get_option('theme_mods_theme-child'); 

$header_logo = apply_filters('my_header_logo_filter', $theme_mods_theme_child_options['header_logo']); 

// Do something with $header_logo 

// functions.php or a plugin 
function my_header_logo_filter_function(){ 
    return 'some-new-image.png'; 
} 

add_filter('my_header_logo_filter', 'my_header_logo_filter_function'); 
相關問題