class-activation.php
1 year ago
class-admin-menu-organizer.php
1 year ago
class-auto-publish-posts-with-missed-schedule.php
1 year ago
class-avif-upload.php
1 year ago
class-change-login-url.php
1 year ago
class-cleanup-admin-bar.php
1 year ago
class-common-methods.php
1 year ago
class-content-duplication.php
1 year ago
class-content-order.php
1 year ago
class-custom-admin-footer-text.php
1 year ago
class-custom-body-class.php
1 year ago
class-custom-css.php
1 year ago
class-custom-nav-menu-items-in-new-tab.php
1 year ago
class-deactivation.php
1 year ago
class-disable-comments.php
1 year ago
class-disable-dashboard-widgets.php
1 year ago
class-disable-feeds.php
1 year ago
class-disable-gutenberg.php
1 year ago
class-disable-rest-api.php
1 year ago
class-disable-smaller-components.php
1 year ago
class-disable-updates.php
1 year ago
class-disable-xml-rpc.php
1 year ago
class-display-system-summary.php
1 year ago
class-email-address-obfuscator.php
1 year ago
class-email-delivery.php
1 year ago
class-enhance-list-tables.php
1 year ago
class-external-permalinks.php
1 year ago
class-heartbeat-control.php
1 year ago
class-hide-admin-bar.php
1 year ago
class-hide-admin-notices.php
1 year ago
class-image-sizes-panel.php
1 year ago
class-image-upload-control.php
1 year ago
class-insert-head-body-footer-code.php
1 year ago
class-last-login-column.php
1 year ago
class-limit-login-attempts.php
1 year ago
class-login-id-type.php
1 year ago
class-login-logout-menu.php
1 year ago
class-maintenance-mode.php
1 year ago
class-manage-ads-appads-txt.php
1 year ago
class-manage-robots-txt.php
1 year ago
class-media-replacement.php
1 year ago
class-multiple-user-roles.php
1 year ago
class-obfuscate-author-slugs.php
1 year ago
class-open-external-links-in-new-tab.php
1 year ago
class-password-protection.php
1 year ago
class-redirect-after-login.php
1 year ago
class-redirect-after-logout.php
1 year ago
class-redirect-fourofour.php
1 year ago
class-registration-date-column.php
1 year ago
class-revisions-control.php
1 year ago
class-search-engines-visibility.php
1 year ago
class-settings-fields-render.php
1 year ago
class-settings-sanitization.php
1 year ago
class-settings-sections-fields.php
1 year ago
class-show-custom-taxonomy-filters.php
1 year ago
class-site-identity-on-login-page.php
1 year ago
class-svg-upload.php
1 year ago
class-various-admin-ui-enhancements.php
1 year ago
class-view-admin-as-role.php
1 year ago
class-wider-admin-menu.php
1 year ago
class-wp-config-transformer.php
1 year ago
class-custom-nav-menu-items-in-new-tab.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class for Allow Custom Menu Links to Open in New Tab module |
| 7 | * |
| 8 | * @since 6.9.5 |
| 9 | */ |
| 10 | class Custom_Nav_Menu_Items_In_New_Tab { |
| 11 | |
| 12 | /** |
| 13 | * Add "open in new tab" checkbox in custom nav menu item settings |
| 14 | * |
| 15 | * @since 5.4.0 |
| 16 | */ |
| 17 | public function add_custom_nav_menu_open_in_new_tab_field( $item_id, $menu_item, $depth, $args ) { |
| 18 | |
| 19 | $target_blank = get_post_meta( $item_id, '_menu_item_target_blank', true ); |
| 20 | |
| 21 | if ( 'custom' == $menu_item->object ) { |
| 22 | ?> |
| 23 | <p class="field-target_blank description-wide"> |
| 24 | <label for="edit-menu-item-target-blank-<?php echo esc_attr( $item_id ); ?>"> |
| 25 | <input type="checkbox" id="edit-menu-item-target-blank-<?php echo esc_attr( $item_id ); ?>" name="menu-item-target-blank[<?php echo esc_attr( $item_id ); ?>]" value="1" <?php checked( $target_blank, '1' ); ?> /> |
| 26 | Open link in new tab and add rel="noopener noreferrer nofollow" attribute. |
| 27 | </label> |
| 28 | </p> |
| 29 | <?php |
| 30 | } |
| 31 | |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Save status of "open in new tab" checkbox in custom nav menu item settings |
| 36 | * |
| 37 | * @since 5.4.0 |
| 38 | */ |
| 39 | public function save_custom_nav_menu_open_in_new_tab_status( $menu_id, $menu_item_db_id, $args ) { |
| 40 | |
| 41 | if ( isset( $_POST['menu-item-target-blank'][$menu_item_db_id] ) ) { |
| 42 | update_post_meta( $menu_item_db_id, '_menu_item_target_blank', '1' ); |
| 43 | } else { |
| 44 | delete_post_meta( $menu_item_db_id, '_menu_item_target_blank' ); |
| 45 | } |
| 46 | |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Add attributes to custom nav menu item on the frontend |
| 51 | * |
| 52 | * @since 5.4.0 |
| 53 | */ |
| 54 | public function add_attributes_to_custom_nav_menu_item( $atts, $menu_item, $args ) { |
| 55 | |
| 56 | $target_blank = get_post_meta( $menu_item->ID, '_menu_item_target_blank', true ); |
| 57 | |
| 58 | if ( $target_blank ) { |
| 59 | $atts['target'] = '_blank'; |
| 60 | $atts['rel'] = 'noopener noreferrer nofollow'; |
| 61 | } |
| 62 | |
| 63 | return $atts; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | } |