| @@ -30,8 +30,9 @@ | ||
| 30 | 30 | */ |
| 31 | 31 | public function __construct() { |
| 32 | 32 | add_action( 'admin_init', array( $this, 'handle_external_redirects' ) ); |
| 33 | 33 | add_action( 'admin_menu', array( $this, 'menu_page_callback' ) ); |
| 34 | + add_action( 'admin_footer', array( $this, 'sync_addon_submenu_visibility' ) ); | |
| 34 | 35 | add_action( 'in_admin_header', array( $this, 'remove_all_notices' ) ); |
| 35 | 36 | add_filter( 'plugin_row_meta', array( $this, 'plugin_settings_meta' ), 10, 2 ); |
| 36 | 37 | add_filter( 'plugin_action_links_' . ULTP_BASE, array( $this, 'plugin_action_links_callback' ) ); |
| 37 | 38 | } |
| @@ -69,70 +70,15 @@ | ||
| 69 | 70 | * @param array $links Default plugin action links. |
| 70 | 71 | * @return array Modified plugin action links. |
| 71 | 72 | */ |
| 72 | 73 | public function plugin_action_links_callback( $links ) { |
| 73 | - $offer_config = array( | |
| 74 | - array( | |
| 75 | - 'start' => '2026-07-06 00:00 Asia/Dhaka', | |
| 76 | - 'end' => '2026-08-01 23:59 Asia/Dhaka', | |
| 77 | - 'text' => __( | |
| 78 | - 'Summer Sale - Up to 50% OFF', | |
| 79 | - 'ultimate-post' | |
| 80 | - ), | |
| 81 | - 'utmKey' => 'summer_sale_meta', | |
| 82 | - ), | |
| 83 | - array( | |
| 84 | - 'start' => '2026-08-02 00:00 Asia/Dhaka', | |
| 85 | - 'end' => '2026-08-16 23:59 Asia/Dhaka', | |
| 86 | - 'text' => __( | |
| 87 | - 'Summer Sale - Up to 50% OFF', | |
| 88 | - 'ultimate-post' | |
| 89 | - ), | |
| 90 | - 'utmKey' => 'summer_sale_meta', | |
| 91 | - ), | |
| 92 | - ); | |
| 93 | - | |
| 94 | 74 | $setting_link = array( |
| 95 | 75 | 'ultp_options' => '<a href="' . esc_url( admin_url( 'admin.php?page=ultp-settings#startersites' ) ) . '">' . esc_html__( 'Starter Sites', 'ultimate-post' ) . '</a>', |
| 96 | 76 | ); |
| 97 | 77 | |
| 98 | - $upgrade_link = array(); | |
| 99 | - | |
| 100 | - // Free user or expired license user. | |
| 101 | - if ( ! defined( 'ULTP_PRO_VER' ) || Xpo::is_lc_expired() ) { | |
| 102 | - | |
| 103 | - $license_key = Xpo::get_lc_key() ?? ''; | |
| 104 | - | |
| 105 | - if ( Xpo::is_lc_expired() ) { | |
| 106 | - $text = esc_html__( 'Renew License', 'ultimate-post' ); | |
| 107 | - $url = 'https://account.wpxpo.com/checkout/?edd_license_key=' . $license_key; | |
| 108 | - } else { | |
| 109 | - | |
| 110 | - $text = esc_html__( 'Upgrade to Pro', 'ultimate-post' ); | |
| 111 | - $url = Xpo::generate_utm_link(array( | |
| 112 | - 'utmKey' => 'sub_menu', | |
| 113 | - )); | |
| 114 | - | |
| 115 | - foreach ( $offer_config as $offer ) { | |
| 116 | - $current_time = gmdate( 'U' ); | |
| 117 | - $notice_start = gmdate( 'U', strtotime( $offer['start'] ) ); | |
| 118 | - $notice_end = gmdate( 'U', strtotime( $offer['end'] ) ); | |
| 119 | - if ( $current_time >= $notice_start && $current_time <= $notice_end ) { | |
| 120 | - $url = Xpo::generate_utm_link( | |
| 121 | - array( | |
| 122 | - 'utmKey' => $offer['utmKey'], | |
| 123 | - ) | |
| 124 | - ); | |
| 125 | - $text = $offer['text']; | |
| 126 | - break; | |
| 127 | - } | |
| 128 | - } | |
| 129 | - } | |
| 130 | - | |
| 131 | - $upgrade_link['ultp_pro'] = '<a style="color: #0062ff; font-weight: bold;" target="_blank" href="' . esc_url( $url ) . '">' . esc_html( $text ) . '</a>'; | |
| 132 | - } | |
| 133 | - | |
| 134 | - return array_merge( $setting_link, $links, $upgrade_link ); | |
| 78 | + // The "Upgrade to Pro" / "Renew License" link is added after this by | |
| 79 | + // includes/notice/class-promo-links.php. | |
| 80 | + return array_merge( $setting_link, $links ); | |
| 135 | 81 | } |
| 136 | 82 | |
| 137 | 83 | |
| 138 | 84 | /** |
| @@ -193,52 +139,10 @@ | ||
| 193 | 139 | 'ultp-setup-wizard', |
| 194 | 140 | array( __CLASS__, 'ultp_wizard_page' ) |
| 195 | 141 | ); |
| 196 | 142 | |
| 197 | - $pro_link = ''; | |
| 198 | - $pro_link_text = ''; | |
| 143 | + // The "Upgrade to Pro" / "Renew License" item is added last by includes/notice/class-promo-links.php. | |
| 199 | 144 | |
| 200 | - // Check if current date is between November 5th and December 10th | |
| 201 | - $current_date = current_time( 'Y-m-d' ); | |
| 202 | - $start_date = date( 'Y' ) . '-01-01'; // January 1st of current year | |
| 203 | - $end_date = date( 'Y' ) . '-02-15'; // February 15th of current year | |
| 204 | - $menu_pro_text_period = ( $current_date >= $start_date && $current_date <= $end_date ); | |
| 205 | - | |
| 206 | - if ( ! Xpo::is_lc_active() ) { | |
| 207 | - $pro_link = Xpo::generate_utm_link( | |
| 208 | - array( | |
| 209 | - 'utmKey' => 'sub_menu', | |
| 210 | - ) | |
| 211 | - ); | |
| 212 | - $pro_link_text = $menu_pro_text_period ? __( 'New Year Offer!', 'ultimate-post' ) : __( 'Upgrade to Pro', 'ultimate-post' ); | |
| 213 | - } elseif ( Xpo::is_lc_expired() ) { | |
| 214 | - $license_key = Xpo::get_lc_key(); | |
| 215 | - $pro_link = 'https://account.wpxpo.com/checkout/?edd_license_key=' . $license_key; | |
| 216 | - $pro_link_text = __( 'Renew License', 'ultimate-post' ); | |
| 217 | - } | |
| 218 | - | |
| 219 | - if ( ! empty( $pro_link ) ) { | |
| 220 | - ob_start(); | |
| 221 | - ?> | |
| 222 | - <a href="<?php echo esc_url( $pro_link ); ?>" target="_blank" class="ultp-go-pro"> | |
| 223 | - <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> | |
| 224 | - <path d="M2.86 6.553a.5.5 0 01.823-.482l3.02 2.745c.196.178.506.13.64-.098L9.64 4.779a.417.417 0 01.72 0l2.297 3.939a.417.417 0 00.64.098l3.02-2.745a.5.5 0 01.823.482l-1.99 8.63a.833.833 0 01-.813.646H5.663a.833.833 0 01-.812-.646L2.86 6.553z" stroke="currentColor" stroke-width="1.5"></path> | |
| 225 | - </svg> | |
| 226 | - <span><?php echo esc_html( $pro_link_text ); ?></span> | |
| 227 | - </a> | |
| 228 | - <?php | |
| 229 | - $submenu_content = ob_get_clean(); | |
| 230 | - | |
| 231 | - add_submenu_page( | |
| 232 | - 'ultp-settings', | |
| 233 | - '', | |
| 234 | - $submenu_content, | |
| 235 | - 'manage_options', | |
| 236 | - 'ultp-pro', | |
| 237 | - array( self::class, 'handle_external_redirects' ) | |
| 238 | - ); | |
| 239 | - } | |
| 240 | - | |
| 241 | 145 | add_theme_page( |
| 242 | 146 | __( 'Starter Sites', 'ultimate-post' ), |
| 243 | 147 | __( 'Starter Sites', 'ultimate-post' ), |
| 244 | 148 | $menupage_cap, |
| @@ -247,8 +151,46 @@ | ||
| 247 | 151 | ); |
| 248 | 152 | } |
| 249 | 153 | |
| 250 | 154 | /** |
| 155 | + * Sync addon-backed WordPress submenu items with addon enabled status. | |
| 156 | + * | |
| 157 | + * @since v.4.1.7 | |
| 158 | + * @return void No return value. | |
| 159 | + */ | |
| 160 | + public function sync_addon_submenu_visibility() { | |
| 161 | + $settings = ultimate_post()->get_setting(); | |
| 162 | + $submenus = array( | |
| 163 | + 'builder' => 'ultp_builder', | |
| 164 | + 'saved-templates' => 'ultp_templates', | |
| 165 | + 'custom-font' => 'ultp_custom_font', | |
| 166 | + ); | |
| 167 | + | |
| 168 | + foreach ( $submenus as $slug => $setting_key ) { | |
| 169 | + $submenus[ $slug ] = isset( $settings[ $setting_key ] ) && $settings[ $setting_key ] !== 'false'; | |
| 170 | + } | |
| 171 | + ?> | |
| 172 | + <script> | |
| 173 | + ( function() { | |
| 174 | + const postxAddonSubmenus = <?php echo wp_json_encode( $submenus ); ?>; | |
| 175 | + | |
| 176 | + Object.keys( postxAddonSubmenus ).forEach( function( slug ) { | |
| 177 | + const link = document.querySelector( '#adminmenu a[href*="page=ultp-settings#' + slug + '"]' ); | |
| 178 | + const item = link ? link.closest( 'li' ) : null; | |
| 179 | + | |
| 180 | + if ( ! item ) { | |
| 181 | + return; | |
| 182 | + } | |
| 183 | + | |
| 184 | + item.id = 'postx-submenu-' + slug; | |
| 185 | + item.style.display = postxAddonSubmenus[ slug ] ? '' : 'none'; | |
| 186 | + } ); | |
| 187 | + }() ); | |
| 188 | + </script> | |
| 189 | + <?php | |
| 190 | + } | |
| 191 | + | |
| 192 | + /** | |
| 251 | 193 | * Handle external redirects for menu and pro links. |
| 252 | 194 | * |
| 253 | 195 | * @since v.1.0.0 |
| 254 | 196 | * @return void No return value. |
| @@ -256,13 +198,14 @@ | ||
| 256 | 198 | public function handle_external_redirects() { |
| 257 | 199 | if (empty($_GET['page'])) { // @codingStandardsIgnoreLine |
| 258 | 200 | return; |
| 259 | 201 | } |
| 260 | - $_page = sanitize_key( $_GET['page'] ); | |
| 202 | + $_page = sanitize_key( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug. | |
| 261 | 203 | if ('ultp-startersites' === $_page) { // @codingStandardsIgnoreLine |
| 262 | - exit( wp_safe_redirect( admin_url( 'admin.php?page=ultp-settings#startersites' ) ) ); | |
| 204 | + wp_safe_redirect( admin_url( 'admin.php?page=ultp-settings#startersites' ) ); | |
| 205 | + exit; | |
| 263 | 206 | } else if ('go_postx_pro' === $_page) { // @codingStandardsIgnoreLine |
| 264 | - wp_redirect( | |
| 207 | + wp_redirect( // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Intentional redirect to the fixed wpxpo.com pricing URL. | |
| 265 | 208 | Xpo::generate_utm_link( |
| 266 | 209 | array( |
| 267 | 210 | 'utmKey' => 'dashboard_go_pro', |
| 268 | 211 | ) |