Inventory_Presser_Email_A_Friend::maybe_change_link( string $menu_item, WP_Post $item, int $depth, object $args )
maybe_change_link
On This Page
Description Description
Fills out a mailto: link with vehicle information
Target a specific button in a specific menu and modify the URL.
Parameters Parameters
- $menu_item
-
(string) (Required) item HTML
- $item
-
(WP_Post) (Required) post object for the menu item
- $depth
-
(int) (Required) depth of the item for padding
- $args
-
(object) (Required) nav menu arguments
Return Return
(string)
Source Source
File: includes/class-menu-item-email-a-friend.php
function maybe_change_link( $menu_item, $item, $depth, $args ) { // looking for $menu_item = <a href="mailto:">Email a Friend</a> // is it the vehicle details menu? if ( empty( $args ) || empty( $args->menu ) || empty( $args->menu->name ) || __( 'Vehicle Details Buttons', 'inventory-presser' ) != $args->menu->name ) { // no return $menu_item; } // is it a custom link labeled email a friend? if ( 'Custom Link' != $item->type_label || strtolower( __( 'Email a Friend', 'inventory-presser' ) ) != strtolower( $item->title ) ) { // no return $menu_item; } // change the link to contain vehicle information global $post; $menu_item = str_replace( 'mailto:', $this->url( $post ) . '" target="_blank', $menu_item ); return $menu_item; }
Expand full source codeCollapse full source codeView on Github