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