web-dev-qa-db-ja.com

ユーザーがサインアップ時にインストールするテーマを選択できるようにします

新しいサイトの申し込みページからインストールしたいテーマをユーザーに選択させることはできますか?そして一度サイトが作成されると、それは明らかに彼らが選択したテーマをインストールします。

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' );
11
Andrew

あなたがやりたいことをするために、あなたが欲しいどんなフィールドでも追加して、それからそれらをuser_metaに保存することができます...

$user_info配列/オブジェクトにそれらを格納することもできますが、何が利点になるのか私にはわかりません。)

  // Render Form Fields
add_action('register_form','k99_register_form_add_theme_field');
// Checking
add_action('register_post','k99_check_fields',10,3);
// Insert Data
add_action('user_register', 'k99_register_new_register_fields');

// Render the form with the additional radio field 
function k99_register_form_add_theme_field(){
?>

<p>
<label>Theme<br />
 <?php $themes=wp_get_themes();
foreach ($themes as $theme ) {
$theme['Name'] = sanitize_title_with_dashes($theme['Name']);
$checked = checked( $_POST['custom_theme'], 1 );
 echo '<input id="custom_theme'.$theme['Name'] .'" type="radio" name="custom_theme" value="'. $theme['Name'] .'" '.$checked.'>  '. $theme['Name'].'<br />';
$custom_theme = $_POST['custom_theme'];
} ?>
</label>
</p>

<?php
}

// checking , sanitation etc .. of course this is not done...

function k99_check_fields($login, $email, $errors) {
global $custom_theme;
if ($_POST['custom_theme'] == '') {
$errors->add('empty_theme', "<strong>Error:</strong> Please select theme.");
}
else {
$custom_theme = $_POST['custom_theme'];
}
}

// Write to DB ... if you will..
function k99_register_new_register_fields($user_id, $password="", $meta=array())  {

$custom_theme = $_POST['custom_theme']; //just in case ..
update_usermeta($user_id, 'user_custom_theme',$custom_theme);

}

結局のところ、あなたはそのようにuser_themeを検索することができます:

get_user_meta($user_id, 'user_custom_theme', true);

注: これはその場で書かれています。マルチブログでは検証されていませんが、単純なwpインストールでは、それほど大きな違いはありませんが、これは本番機能ではありませんが、正しい軌道に乗せるためだけのものでした。他のユーザー関連の画面(ユーザーの作成、ユーザーの編集、プロファイルの編集など)にもフィールドを追加するのと同様に、変数の衛生管理とチェック、清掃コード、FORM MARKUPが必要です。

NOTE II: あなたはあなたのuodateの重力フォームについて尋ねました - 彼らはそのためのアドオンを持っています

5
krembo99

私はこれが一種の不正行為であることを知っていますが、私はこのプラグインを使います。既存のネットワークサイトをコピーして、新しいユーザーがサインアップしたときにテンプレートとして利用できるようにします。新しいブログテンプレートをいくつでも作成できます。それらはすべてのコンテンツ、プラグイン、設定などを含み、ユーザーは新しいサイト/アカウントを設定するときに1つを選択できます:)

http://premium.wpmudev.org/project/new-blog-template/ /

1
speedypancake

この種のあなたの質問に答える:このサイト:focusww.comに ' Theme Switch 'と呼ばれるプラグインを入れて、それはあなたがテーマのリストから選択できるサイドバーを置いています。使用され、Cookieがデフォルトのテーマに戻るまでに期限切れになるまでの時間。

0
Nohl

それでも関連性があるのであれば、おそらくこれは他の人が似たような解決策を探すのに役立つでしょう。

/**
 * Add custom field to registration form
 */
add_action( 'signup_blogform', 'aoc_show_addtional_fields' );
add_action( 'user_register', 'aoc_register_extra_fields' );

function aoc_show_addtional_fields() 
{
    $themes = wp_get_themes();
    echo '<label>Choose template for your site';
    foreach ($themes as $theme){
        echo '<img src="'.$theme->get_screenshot().'" width="240"/>';
        echo $theme->name . ' <input id="template" type="radio" tabindex="30" size="25" value="'.$theme->template.'" name="template" />';
    }
    echo '</label>';
}

function aoc_register_extra_fields ( $user_id, $password = "", $meta = array() ) {
    update_user_meta( $user_id, 'template', $_POST['template'] );
}

// The value submitted in our custom input field needs to be added to meta array as the user might not be created yet.
add_filter('add_signup_meta', 'aoc_append_extra_field_as_meta');
function aoc_append_extra_field_as_meta($meta) 
{
    if(isset($_REQUEST['template'])) {
        $meta['template'] = $_REQUEST['template'];
    }
    return $meta;
}

// Once the new site added by registered user is created and activated by user after email verification, update the template selected by user in database.
add_action('wpmu_new_blog', 'aoc_extra_field', 10, 6);
function aoc_extra_field($blog_id, $user_id, $domain, $path, $site_id, $meta) 
{
    update_blog_option($blog_id, 'template', $meta['template']);
    update_blog_option($blog_id, 'stylesheet', $meta['template']);
}

私が同様の要件を持っていたときに私はここにブログ記事( http://artofcoding.in/select-theme-while-registering-wordpress-multisite-network/ /)を書きました。これが役に立つことを願っています。

0
ankittiwaari