[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/classes/ -> class-bp-core-bp-options-nav-backcompat.php (source)

   1  <?php
   2  /**
   3   * Backward compatibility for the $bp->bp_options_nav global.
   4   *
   5   * @since 2.6.0
   6   */
   7  
   8  // Exit if accessed directly.
   9  defined( 'ABSPATH' ) || exit;
  10  
  11  /**
  12   * bp_options_nav backward compatibility class.
  13   *
  14   * This class is used to provide backward compatibility for extensions that access and modify
  15   * the $bp->bp_options_nav global.
  16   *
  17   * @since 2.6.0
  18   */
  19  class BP_Core_BP_Options_Nav_BackCompat extends BP_Core_BP_Nav_BackCompat {
  20      /**
  21       * Parent slug of the current nav item.
  22       *
  23       * @since 2.6.0
  24       * @access protected
  25       * @var string
  26       */
  27      protected $parent_slug = '';
  28  
  29      /**
  30       * Get a value of the nav array at the specified offset.
  31       *
  32       * @since 2.6.0
  33       *
  34       * @param mixed $offset Array offset.
  35       * @return BP_Core_BP_Nav_BackCompat
  36       */
  37  	public function offsetGet( $offset ) {
  38          _doing_it_wrong(
  39              'bp_nav',
  40              __( 'These globals should not be used directly and are deprecated. Please use the BuddyPress nav functions instead.', 'buddypress' ),
  41              '2.6.0'
  42          );
  43  
  44          if ( empty( $this->backcompat_nav[ $offset ] ) ) {
  45              $nav = $this->get_nav( $offset );
  46              if ( $nav ) {
  47                  $subnavs = $this->get_component_nav( $offset )->get_secondary( array( 'parent_slug' => $offset ) );
  48                  $subnav_keyed = array();
  49                  if ( $subnavs ) {
  50                      foreach ( $subnavs as $subnav ) {
  51                          $subnav_keyed[ $subnav->slug ] = (array) $subnav;
  52                      }
  53                  }
  54  
  55                  $subnav_object = new self( $subnav_keyed );
  56                  $subnav_object->set_component( $this->get_component() );
  57                  $subnav_object->set_parent_slug( $offset );
  58  
  59                  $this->backcompat_nav[ $offset ] = $subnav_object;
  60              }
  61          }
  62  
  63          if ( isset( $this->backcompat_nav[ $offset ] ) ) {
  64              return $this->backcompat_nav[ $offset ];
  65          }
  66  
  67          return false;
  68      }
  69  
  70      /**
  71       * Unset a nav array value at the specified offset.
  72       *
  73       * @since 2.6.0
  74       *
  75       * @param mixed $offset Array offset.
  76       */
  77  	public function offsetUnset( $offset ) {
  78          _doing_it_wrong(
  79              'bp_nav',
  80              __( 'These globals should not be used directly and are deprecated. Please use the BuddyPress nav functions instead.', 'buddypress' ),
  81              '2.6.0'
  82          );
  83  
  84          $this->get_component_nav( $offset )->delete_nav( $offset, $this->get_parent_slug() );
  85  
  86          // Clear the cached nav.
  87          unset( $this->backcompat_nav[ $offset ] );
  88      }
  89  
  90      /**
  91       * Get the parent slug of the current nav item.
  92       *
  93       * @since 2.6.0
  94       *
  95       * @return string
  96       */
  97  	public function get_parent_slug() {
  98          return $this->parent_slug;
  99      }
 100  
 101      /**
 102       * Set the parent slug of the current nav item.
 103       *
 104       * @since 2.6.0
 105       */
 106  	public function set_parent_slug( $slug ) {
 107          $this->parent_slug = $slug;
 108      }
 109  
 110      /**
 111       * Get the nav object corresponding to the specified offset.
 112       *
 113       * @since 2.6.0
 114       *
 115       * @param mixed $offset Array offset.
 116       * @return bool|array
 117       */
 118  	public function get_nav( $offset ) {
 119          $nav = parent::get_nav( $offset );
 120  
 121          if ( ! $nav ) {
 122              $component_nav = $this->get_component_nav( $offset );
 123              $secondary_nav = $component_nav->get_secondary( array( 'slug' => $offset ), false );
 124  
 125              $nav = array();
 126  
 127              if ( empty( $primary_nav ) ) {
 128                  return $nav;
 129              }
 130  
 131              foreach ( $primary_nav as $item ) {
 132                  $nav[ $item->slug ] = (array) $item;
 133              }
 134          }
 135  
 136          return $nav;
 137      }
 138  }


Generated: Thu Oct 17 01:01:39 2019 Cross-referenced by PHPXref 0.7.1