我想使用WordPress REST api获取所有安装的WordPress主题的列表,以及它们的元信息(例如名称、状态、作者等)。我还希望能够通过API客户端激活任何主题。
我经历过this documentation 但我没有找到任何相关的终点。
现在有可能吗?
我想使用WordPress REST api获取所有安装的WordPress主题的列表,以及它们的元信息(例如名称、状态、作者等)。我还希望能够通过API客户端激活任何主题。
我经历过this documentation 但我没有找到任何相关的终点。
现在有可能吗?
您可以编写自己的端点并使用wp_get_themes
通过它获取主题列表。这里有一个简单的例子:
add_action( \'rest_api_init\', function () {
//Path to rest endpoint
register_rest_route( \'theme_API/v1\', \'/get_theme_list/\', array(
\'methods\' => \'GET\',
\'callback\' => \'theme_list_function\'
) );
});
// Our function to get the themes
function theme_list_function(){
// Get a list of themes
$list = wp_get_themes();
// Return the value
return $list;
}
现在,您可以通过访问http://example.com/wp-json/theme_API/v1/get_theme_list
.我不建议通过API激活/停用主题。它会把事情搞得一团糟,比如激活的小部件。
当窗体未能通过register\\u设置的sanitize回调中定义的验证时,我试图保留窗体的旧值。但它不这样做,而是保存默认值register_setting(\'setting-wpse3401\', \'wpse3401_options\', array( \'sanitize_callback\' => [$this, \'wpse3401_sanitize_value\'])); public function wpse3401_sanitize_value( $val