NavMenuActions.php
11 years ago
NavMenuRemoveItem.php
11 years ago
NavMenuRepository.php
11 years ago
NavMenuSync.php
11 years ago
NavMenuSyncInterface.php
11 years ago
NavMenuSyncListing.php
11 years ago
NavMenuSyncMenu.php
11 years ago
NavMenuTrashActions.php
11 years ago
NavMenuTrashActions.php
43 lines
| 1 | <?php namespace NestedPages\Entities\NavMenu; |
| 2 | |
| 3 | use NestedPages\Entities\NavMenu\NavMenuRepository; |
| 4 | |
| 5 | /** |
| 6 | * Performs necessary actions when a menu item is trashed |
| 7 | */ |
| 8 | class NavMenuTrashActions { |
| 9 | |
| 10 | /** |
| 11 | * Nav Menu Repository |
| 12 | */ |
| 13 | private $nav_menu_repo; |
| 14 | |
| 15 | public function __construct() |
| 16 | { |
| 17 | $this->nav_menu_repo = new NavMenuRepository; |
| 18 | add_action( 'before_delete_post', array( $this, 'removeLinkItem'), 10 ); |
| 19 | add_action( 'before_delete_post', array( $this, 'hidePagefromNav'), 10 ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Remove Link Post (np-redirect) when a link in the menu is removed |
| 24 | */ |
| 25 | public function removeLinkItem($post_id) |
| 26 | { |
| 27 | remove_action( 'before_delete_post', array( $this, 'removeLinkItem'), 10 ); |
| 28 | $redirect_id = get_post_meta($post_id, '_menu_item_xfn', true); |
| 29 | if ( $redirect_id !== "" ) wp_delete_post($redirect_id, true); |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Set Page items to hide from nav if page nav item is deleted |
| 35 | */ |
| 36 | public function hidePagefromNav($post_id) |
| 37 | { |
| 38 | if ( get_post_type($post_id) == 'nav_menu_item' ){ |
| 39 | |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | } |