← All changes
|
includes/admin/tools/class-charitable-tools.php
+70
-11
1.8.11.2
→
1.8.13
View file →
| @@ -185,8 +185,9 @@ | ||
| 185 | 185 | 'tags' => __( 'Tags', 'charitable' ), |
| 186 | 186 | 'customize' => __( 'Customize', 'charitable' ), |
| 187 | 187 | 'export' => __( 'Export', 'charitable' ), |
| 188 | 188 | 'import' => __( 'Import', 'charitable' ), |
| 189 | + 'ai-mcp' => __( 'AI MCP', 'charitable' ), | |
| 189 | 190 | 'system-info' => __( 'System Info', 'charitable' ), |
| 190 | 191 | 'snippets' => __( 'Code Snippets', 'charitable' ), |
| 191 | 192 | 'logs' => __( 'Logs', 'charitable' ), |
| 192 | 193 | 'misc' => __( 'Misc', 'charitable' ), |
| @@ -194,8 +195,43 @@ | ||
| 194 | 195 | ); |
| 195 | 196 | } |
| 196 | 197 | |
| 197 | 198 | /** |
| 199 | + * The "New" badge markup for a Tools tab, or '' when it has none. | |
| 200 | + * | |
| 201 | + * A method rather than HTML inside the get_sections() label, because the | |
| 202 | + * two navs that render those labels escape them differently - | |
| 203 | + * views/tools/tools.php echoes the label raw, the taxonomy-page nav in | |
| 204 | + * this class runs it through esc_html() - so markup smuggled into the | |
| 205 | + * label would render in one place and print as literal tags in the | |
| 206 | + * other. Keeping labels plain text and the badge separate means both | |
| 207 | + * navs can escape correctly. | |
| 208 | + * | |
| 209 | + * It also means ONE place decides which tab is new. Both navs call this, | |
| 210 | + * the same way both now loop get_sections(); a second hand-written copy | |
| 211 | + * is exactly how the AI MCP tab went missing from the taxonomy screens | |
| 212 | + * in the first place. | |
| 213 | + * | |
| 214 | + * Removing the badge is a manual edit next cycle, matching how | |
| 215 | + * `.charitable-menu-new-indicator` is used on the Donors menu item - | |
| 216 | + * there is no dismissal state and it is not tied to a version check, so | |
| 217 | + * it stays until somebody takes it out. | |
| 218 | + * | |
| 219 | + * @since 1.8.13 | |
| 220 | + * | |
| 221 | + * @param string $tab_key The tab key from get_sections(). | |
| 222 | + * @return string Badge HTML, already escaped, or '' for every other tab. | |
| 223 | + */ | |
| 224 | + public function get_section_badge( $tab_key ) { | |
| 225 | + | |
| 226 | + if ( 'ai-mcp' !== $tab_key ) { | |
| 227 | + return ''; | |
| 228 | + } | |
| 229 | + | |
| 230 | + return ' <span class="charitable-tab-new-badge">' . esc_html__( 'New', 'charitable' ) . '</span>'; | |
| 231 | + } | |
| 232 | + | |
| 233 | + /** | |
| 198 | 234 | * Register setting. |
| 199 | 235 | * |
| 200 | 236 | * @since 1.0.0 |
| 201 | 237 | * |
| @@ -530,25 +566,48 @@ | ||
| 530 | 566 | public function add_tools_nav_to_taxononmy_pages( $taxonomy = false ) { // phpcs:ignore |
| 531 | 567 | |
| 532 | 568 | ob_start(); |
| 533 | 569 | |
| 534 | - $categories_css = isset( $_GET['taxonomy'] ) && 'campaign_category' == $_GET['taxonomy'] ? 'nav-tab-active' : ''; // phpcs:ignore | |
| 535 | - $tags_css = isset( $_GET['taxonomy'] ) && 'campaign_tag' == $_GET['taxonomy'] ? 'nav-tab-active' : ''; // phpcs:ignore | |
| 570 | + $taxonomy_now = isset( $_GET['taxonomy'] ) ? $_GET['taxonomy'] : ''; // phpcs:ignore | |
| 536 | 571 | |
| 572 | + /* | |
| 573 | + * Driven from get_sections() rather than a hand-written list. | |
| 574 | + * | |
| 575 | + * This nav is a SECOND copy of the one in views/tools/tools.php, | |
| 576 | + * needed because the Categories and Tags tabs redirect out to | |
| 577 | + * edit-tags.php (see taxonomy_redirects()), where that view never | |
| 578 | + * runs. It used to hardcode nine anchors, and so it silently went | |
| 579 | + * stale every time a tab was added: `ai-mcp` landed in | |
| 580 | + * get_sections() in 1.8.13 and never appeared here, which is | |
| 581 | + * exactly how the AI MCP tab went missing on the two taxonomy | |
| 582 | + * screens while showing correctly everywhere else. Looping the same | |
| 583 | + * source both navs share is what stops the next tab drifting too. | |
| 584 | + * | |
| 585 | + * Only the two taxonomy tabs need a non-standard href, since they | |
| 586 | + * are the ones that live outside page=charitable-tools. | |
| 587 | + */ | |
| 588 | + $taxonomy_tabs = array( | |
| 589 | + 'categories' => 'campaign_category', | |
| 590 | + 'tags' => 'campaign_tag', | |
| 591 | + ); | |
| 592 | + | |
| 537 | 593 | ?> |
| 538 | 594 | |
| 539 | 595 | <div id="charitable-tools-nav"> |
| 540 | 596 | <h1><?php echo esc_html__( 'Charitable Tools', 'charitable' ); ?></h1> |
| 541 | 597 | <h2 class="nav-tab-wrapper"> |
| 542 | - <a href="<?php echo esc_url( admin_url( 'edit-tags.php?taxonomy=campaign_category&post_type=campaign' ) ); ?>" class="nav-tab <?php echo esc_attr( $categories_css ); ?>"><?php echo esc_html__( 'Categories', 'charitable' ); ?></a> | |
| 543 | - <a href="<?php echo esc_url( admin_url( 'edit-tags.php?taxonomy=campaign_tag&post_type=campaign' ) ); ?>" class="nav-tab <?php echo esc_attr( $tags_css ); ?>"><?php echo esc_html__( 'Tags', 'charitable' ); ?></a> | |
| 544 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=charitable-tools&tab=customize' ) ); ?>" class="nav-tab "><?php echo esc_html__( 'Customize', 'charitable' ); ?></a> | |
| 545 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=charitable-tools&tab=export' ) ); ?>" class="nav-tab"><?php echo esc_html__( 'Export', 'charitable' ); ?></a> | |
| 546 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=charitable-tools&tab=import' ) ); ?>" class="nav-tab"><?php echo esc_html__( 'Import', 'charitable' ); ?></a> | |
| 547 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=charitable-tools&tab=system-info' ) ); ?>" class="nav-tab"><?php echo esc_html__( 'System Info', 'charitable' ); ?></a> | |
| 548 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=charitable-tools&tab=snippets' ) ); ?>" class="nav-tab"><?php echo esc_html__( 'Code Snippets', 'charitable' ); ?></a> | |
| 549 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=charitable-tools&tab=logs' ) ); ?>" class="nav-tab"><?php echo esc_html__( 'Logs', 'charitable' ); ?></a> | |
| 550 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=charitable-tools&tab=misc' ) ); ?>" class="nav-tab"><?php echo esc_html__( 'Misc', 'charitable' ); ?></a> | |
| 598 | + <?php foreach ( charitable_get_admin_tools()->get_sections() as $tab_key => $tab_label ) : ?> | |
| 599 | + <?php | |
| 600 | + if ( isset( $taxonomy_tabs[ $tab_key ] ) ) { | |
| 601 | + $tab_url = admin_url( 'edit-tags.php?taxonomy=' . $taxonomy_tabs[ $tab_key ] . '&post_type=campaign' ); | |
| 602 | + $tab_active = $taxonomy_tabs[ $tab_key ] === $taxonomy_now ? 'nav-tab-active' : ''; | |
| 603 | + } else { | |
| 604 | + $tab_url = admin_url( 'admin.php?page=charitable-tools&tab=' . $tab_key ); | |
| 605 | + $tab_active = ''; | |
| 606 | + } | |
| 607 | + ?> | |
| 608 | + <a href="<?php echo esc_url( $tab_url ); ?>" class="nav-tab <?php echo esc_attr( $tab_active ); ?>"><?php echo esc_html( $tab_label ); ?><?php echo $this->get_section_badge( $tab_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in get_section_badge(). ?></a> | |
| 609 | + <?php endforeach; ?> | |
| 551 | 610 | </h2> |
| 552 | 611 | </div> |
| 553 | 612 | |
| 554 | 613 | <?php |