我在WP网站上使用插件付费会员订阅。
我应该添加以下脚本的代码:
<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)
答案 0 :(得分:1)
在输入标记中添加已选中
<input type="checkbox" checked>
答案 1 :(得分: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子句已被替换为单词checked