是否可以允许用户从新的站点注册页面中选择他们想要安装的主题?创建网站后,显然可以安装他们选择的任何主题。
我发现了wp_get_themes。这是您将如何使用所有可用主题预填充下拉菜单的方法吗?您如何将主题的信息传递给实际的注册过程,以便使用正确的主题创建网站?
如果有人知道如何通过重力形式做到这一点,那也很好。
更新:
这是我到目前为止的内容,它没有考虑到儿童主题,将在之后
此函数将输出带有单选按钮的主题列表,将所选主题存储在$ _POST ['custom_theme']中
/**
* Show list of themes at bottom of wp-signup.php (multisite)
*/
function 70169_add_signup_extra_fields() { ?>
Themes<br />
<?php
$themes = wp_get_themes();
foreach ( $themes as $theme ) {
$theme_name = $theme['Name'];
$theme_stylesheet = $theme->stylesheet;
?>
<label>
<input id="<?php echo $theme_stylesheet; ?>" type="radio" <?php if ( isset( $_POST['custom_theme'] ) ) checked( $_POST['custom_theme'], $theme_stylesheet ); ?> name="custom_theme" value="<?php echo $theme_stylesheet; ?>" ><?php echo $theme_name; ?>
</label>
<?php } ?>
<?php }
add_action( 'signup_extra_fields', '70169_add_signup_extra_fields' );
我以为我会添加一个隐藏字段,以将主题的价值传递到网站创建中。但是,这有问题-在最后一步,它失去了价值,不确定为什么。
/**
* Add a hidden field with the theme's value
*/
function 70169_theme_hidden_fields() { ?>
<?php
$theme = isset( $_POST['custom_theme'] ) ? $_POST['custom_theme'] : null;
?>
<input type="hidden" name="user_theme" value="<?php echo $theme; ?>" />
<?php }
add_action( 'signup_hidden_fields', '70169_theme_hidden_fields' );
最后是一个将主题名称传递给新创建的站点的函数。如果我对变量进行了硬编码,则此方法有效,但是我尚无法传递custom_theme的值。可以很好地创建网站,但是模板和样式表选项为空白。无论我如何尝试,都无法获得价值。我想我必须使用$ _GET来访问我之前创建的隐藏字段。再说一次,我现在要做的就是将相同的主题名称传递给模板和样式表选项,我将弄清楚如何使它们区别开来。
/**
* Create the new site with the theme name
*/
function 70169_wpmu_new_blog( $blog_id ) {
// need to get this working, use $_GET?
// $theme = ???
update_blog_option( $blog_id, 'template', $theme ); // $theme works if I hardcode it with a theme name
update_blog_option( $blog_id, 'stylesheet', $theme );
}
add_action( 'wpmu_new_blog', '70169_wpmu_new_blog' );