Merhaba,
Site üzerinden premium üyelik alan kullanıcılara site reklamsız gösterilecek. Bu nasıl yapılabilir?
Premium WordPress
7
●179
- 19-08-2019, 16:46:07
add_action( 'user_register', 'add_premium_field', 10, 1 ); function add_premium_field( $user_id ) { add_user_meta($user_id, 'premium_user', 0); } add_action( 'show_user_profile', 'premium_user_profile_fields' ); add_action( 'edit_user_profile', 'premium_user_profile_fields' ); function premium_user_profile_fields( $user ) { if($user->ID == 1): ?> <h3><?php _e("Premium Kullanıcı Alanı", "theme_name"); ?></h3> <table class="form-table"> <tr> <th><label for="premium_user"><?php _e("Premium User"); ?></label></th> <td> <input type="text" name="premium_user" id="premium_user" value="<?php echo esc_attr( get_the_author_meta( 'premium_user', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Premium aktif etmek için 1, pasif yapmak için 0 yazın"); ?></span> </td> </tr> <?php endif; } add_action( 'personal_options_update', 'save_premium_user_profile_fields' ); add_action( 'edit_user_profile_update', 'save_premium_user_profile_fields' ); function save_premium_user_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) { return false; } if($user_id == 1){ update_user_meta( $user_id, 'premium_user', $_POST['premium_user'] ); } } function premium_ads_css() { $checkPremium = get_user_meta( $user_id, 'premium_user', true ); if($checkPremium == 1): ?> <style> .adsContainer{ display:none; } </style> <?php endif; } add_action('wp_head', 'premium_ads_css');.adsContainer kısmındaki cssi siz reklam alanlarınızın classlarını yazarak gizletebilirsiniz. temanızın functions.php dosyasına eklenecek kodlar. - 19-08-2019, 18:10:47Şu anda satış yapmıyorum. Sadece bilgi için yazdım.redevelop adlı üyeden alıntı: mesajı görüntüle
Hocam, classları düzenleyemedim. Yardımcı olabilir misiniz?Ecancan adlı üyeden alıntı: mesajı görüntüle - 19-08-2019, 21:05:25site adresinizi pm ile iletin. Reklam alanlarınızın konumlarını tespit ettikten sonra son halini ekleyeyim.vidtekno adlı üyeden alıntı: mesajı görüntüle
- 19-08-2019, 21:06:47P.M. GönderildiEcancan adlı üyeden alıntı: mesajı görüntüle
@Ecancan; çok yardımcı oldu. Teşekkürler. - 19-08-2019, 22:43:08Kodun son hali aşaağıdır. Bizzat hedef sitede test edilmiştir. Premium üyelik ayrıcağılı yapmak isteyen arkadaşlar için kullanışlı ve basit bir sistemdir.
add_action( 'user_register', 'add_premium_field', 10, 1 ); function add_premium_field( $user_id ) { add_user_meta($user_id, 'premium_user', 0); } add_action( 'show_user_profile', 'premium_user_profile_fields' ); add_action( 'edit_user_profile', 'premium_user_profile_fields' ); function premium_user_profile_fields( $user ) { $user_meta = get_userdata(get_current_user_id()); $user_roles = $user_meta->roles; if ( in_array( 'administrator', $user_roles, true ) ) : ?> <h3><?php _e("Premium Kullanıcı Alanı", "theme_name"); ?></h3> <table class="form-table"> <tr> <th><label for="premium_user"><?php _e("Premium User"); ?></label></th> <td> <input type="text" name="premium_user" id="premium_user" value="<?php echo esc_attr( get_the_author_meta( 'premium_user', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description"><?php _e("Premium aktif etmek için 1, pasif yapmak için 0 yazın"); ?></span> </td> </tr> <?php endif; } add_action( 'personal_options_update', 'save_premium_user_profile_fields' ); add_action( 'edit_user_profile_update', 'save_premium_user_profile_fields' ); function save_premium_user_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) { return false; } $user_meta = get_userdata(get_current_user_id()); $user_roles = $user_meta->roles; if ( in_array( 'administrator', $user_roles, true ) ) { update_user_meta( $user_id, 'premium_user', $_POST['premium_user'] ); } } function premium_ads_css() { $checkPremium = get_user_meta( get_current_user_id(), 'premium_user', true ); if($checkPremium == 1): ?> <script type="text/javascript"> $(document).ready(function(){ $("ins.adsbygoogle").hide(); }); </script> <?php endif; } add_action( 'wp_footer', 'premium_ads_css', 100 );