Making WordPress.org


Ignore:
Timestamp:
02/18/2018 02:52:17 PM (6 years ago)
Author:
ocean90
Message:

Rosetta Roles: Move get_parent_project() to the main class.

See #1613.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php

    r6453 r6684  
    745745    }
    746746
     747    /**
     748     * Returns the parent project for a sub project.
     749     *
     750     * @param array $tree The project tree.
     751     * @param int $child_id The project tree.
     752     * @return object The parent project.
     753     */
     754    public function get_parent_project( $tree, $child_id ) {
     755        $parent = null;
     756        foreach ( $tree as $project ) {
     757            if ( $project->id == $child_id ) {
     758                $parent = $project;
     759                break;
     760            }
     761
     762            if ( isset( $project->sub_projects ) ) {
     763                $parent = $this->get_parent_project( $project->sub_projects, $child_id );
     764                if ( $parent ) {
     765                    $parent = $project;
     766                    break;
     767                }
     768            }
     769        }
     770
     771        return $parent;
     772    }
     773
    747774    private function _sort_name_callback( $a, $b ) {
    748775        return strnatcasecmp( $a->name, $b->name );
Note: See TracChangeset for help on using the changeset viewer.