2015-12-11 51 views
1

我使用插件付費會員訂閱在我的WP網站。如何設置默認所有檢查的一些選擇在PHP

我創造一些訂閱計劃這樣的形象: enter image description here

我想設置默認檢查這樣的形象的所有計劃: enter image description here

我應該添加什麼代碼下面的腳本:

<div class="pms-meta-box-field-wrapper"> 
    <label class="pms-meta-box-field-label"><?php _e('Subscription Plans', 'paid-member-subscriptions'); ?></label> 

    <?php 
    $subscription_plans = pms_get_subscription_plans(); 
    $selected_subscription_plans = get_post_meta($post->ID, 'pms-content-restrict-subscription-plan'); 
    ?> 

    <?php if(!empty($subscription_plans)): foreach($subscription_plans as $subscription_plan): ?> 

     <label class="pms-meta-box-checkbox-label" for="pms-content-restrict-subscription-plan-<?php echo $subscription_plan->id ?>"> 
      <input type="checkbox" value="<?php echo $subscription_plan->id; ?>" <?php if(in_array($subscription_plan->id, $selected_subscription_plans)) echo 'checked="checked"'; ?> name="pms-content-restrict-subscription-plan[]" id="pms-content-restrict-subscription-plan-<?php echo $subscription_plan->id ?>"> 
      <?php echo $subscription_plan->name; ?> 
     </label> 

    <?php endforeach; ?> 
     <p class="description"><?php echo __('Members subscribed to these Subscription plans will be able to view this page.', 'paid-member-subscriptions'); ?></p> 
    <?php else: ?> 
     <p class="description"><?php printf(__('You do not have any active Subscription Plans yet. Please create them <a href="%s">here</a>', 'paid-member-subscriptions'), admin_url('edit.php?post_type=pms-subscription')); ?></p> 
    <?php endif; ?> 

</div> 

(source: .../wp-content/plugins/paid-member-subscriptions/includes/admin/meta-boxes/views/view-meta-box-single-content-restriction.php) 

回答

1

添加在您的輸入標記中籤入

<input type="checkbox" checked> 
+0

感謝,我的問題得到解決。 –

1

只需更改以下行

<input type="checkbox" value="<?php echo $subscription_plan->id; ?>" <?php if(in_array($subscription_plan->id, $selected_subscription_plans)) echo 'checked="checked"'; ?> name="pms-content-restrict-subscription-plan[]" id="pms-content-restrict-subscription-plan-<?php echo $subscription_plan->id ?>"> 

這個

<input type="checkbox" value="<?php echo $subscription_plan->id; ?>" checked name="pms-content-restrict-subscription-plan[]" id="pms-content-restrict-subscription-plan-<?php echo $subscription_plan->id ?>"> 

整個if語句一直隻字代替檢查

+0

感謝您的添加答案。 –

相關問題