Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'jnews_dropdown_link', 'j_edit_account_dropdown', 99 );
- add_filter( 'jnews_mobile_account_url', 'j_change_acocunt_link', 99 );
- function j_edit_account_dropdown( $dropdown ) {
- if ( is_user_logged_in() ) {
- $new_dropdown = array();
- if ( function_exists( 'wc_get_page_permalink' ) ) {
- $new_dropdown['my_account'] = array(
- 'text' => __( 'My Acocunt', 'jnews' ),
- 'url' => wc_get_page_permalink( 'myaccount' ),
- );
- if ( j_is_jpw_subsribed() ) {
- $new_dropdown['download_pdf'] = array(
- 'text' => __( 'Download PDF', 'jnews' ),
- 'url' => get_permalink( 64 ), /* change 64 with your page ID */
- );
- }
- }
- if ( isset( $dropdown['logout'] ) ) {
- $new_dropdown['logout'] = $dropdown['logout'];
- }
- if ( isset( $new_dropdown ) ) {
- return $new_dropdown;
- }
- }
- return $dropdown;
- }
- function j_change_acocunt_link( $url ) {
- if ( function_exists( 'wc_get_page_permalink' ) ) {
- return wc_get_page_permalink( 'myaccount' );
- }
- return $url;
- }
- function j_is_jpw_subsribed() {
- $roles = apply_filters( 'jnews_paywall_unaffected_role_list', array( 'administrator' ) );
- $user = wp_get_current_user();
- foreach ( $roles as $role ) {
- if ( in_array( $role, $user->roles ) ) {
- return true;
- }
- }
- $subscribe_status = is_user_logged_in() ? get_user_option( 'jpw_subscribe_status', get_current_user_id() ) : false;
- if ( $subscribe_status ) {
- $subscription_type = get_user_option( 'jpw_subs_type', get_current_user_id() );
- if ( 'paypal' === $subscription_type ) {
- /* get current date by paypall timezone setting */
- $timezone = '+8'; /* change with your paypal time zone settings */
- } else {
- $timezone = '+0';
- }
- $timezone = new DateTimeZone( $timezone );
- $current_date = new DateTime( 'now', $timezone );
- $expired = get_user_option( 'jpw_expired_date', get_current_user_id() );
- $expired_timestamp = strtotime( $expired );
- if ( $expired_timestamp ) {
- $current_date = new DateTime( $current_date->format( 'Y-m-d H:i:s' ) );
- $expired_date = new DateTime( $expired );
- if ( $current_date <= $expired_date ) {
- return $subscribe_status;
- }
- }
- update_user_option( get_current_user_id(), 'jpw_subscribe_status', false );
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment