Fragen\GitHub_Updater\Plugin::get_plugin_meta PHP Method

get_plugin_meta() protected method

Get details of Git-sourced plugins from those that are installed.
protected get_plugin_meta ( ) : array
return array Indexed array of associative arrays of plugin details.
    protected function get_plugin_meta()
    {
        /*
         * Ensure get_plugins() function is available.
         */
        include_once ABSPATH . '/wp-admin/includes/plugin.php';
        $plugins = get_plugins();
        $git_plugins = array();
        /**
         * Filter to add plugins not containing appropriate header line.
         *
         * @since   5.4.0
         * @access  public
         *
         * @param   array $additions    Listing of plugins to add.
         *                              Default null.
         * @param   array $plugins      Listing of all plugins.
         * @param         string        'plugin'    Type being passed.
         */
        $additions = apply_filters('github_updater_additions', null, $plugins, 'plugin');
        $plugins = array_merge($plugins, (array) $additions);
        foreach ((array) $plugins as $plugin => $headers) {
            $git_plugin = array();
            if (empty($headers['GitHub Plugin URI']) && empty($headers['Bitbucket Plugin URI']) && empty($headers['GitLab Plugin URI'])) {
                continue;
            }
            foreach ((array) self::$extra_headers as $value) {
                $repo_enterprise_uri = null;
                $repo_enterprise_api = null;
                $repo_languages = null;
                if (in_array($value, array('Requires PHP', 'Requires WP'))) {
                    continue;
                }
                if (empty($headers[$value]) || false === stristr($value, 'Plugin') && false === stristr($value, 'Languages')) {
                    continue;
                }
                $header_parts = explode(' ', $value);
                $repo_parts = $this->get_repo_parts($header_parts[0], 'plugin');
                if ($repo_parts['bool']) {
                    $header = $this->parse_header_uri($headers[$value]);
                }
                $self_hosted_parts = array_diff(array_keys(self::$extra_repo_headers), array('branch'));
                foreach ($self_hosted_parts as $part) {
                    if (array_key_exists($repo_parts[$part], $headers) && !empty($headers[$repo_parts[$part]])) {
                        switch ($part) {
                            case 'languages':
                                $repo_languages = $headers[$repo_parts[$part]];
                                break;
                            case 'enterprise':
                            case 'gitlab_ce':
                                $repo_enterprise_uri = $headers[$repo_parts[$part]];
                                break;
                            case 'ci_job':
                                $repo_ci_job = $headers[$repo_parts[$part]];
                                break;
                        }
                    }
                }
                if (!empty($repo_enterprise_uri)) {
                    $repo_enterprise_uri = trim($repo_enterprise_uri, '/');
                    switch ($header_parts[0]) {
                        case 'GitHub':
                            $repo_enterprise_api = $repo_enterprise_uri . '/api/v3';
                            break;
                        case 'GitLab':
                            $repo_enterprise_api = $repo_enterprise_uri . '/api/v3';
                            break;
                    }
                }
                $git_plugin['type'] = $repo_parts['type'];
                $git_plugin['uri'] = $repo_parts['base_uri'] . $header['owner_repo'];
                $git_plugin['enterprise'] = $repo_enterprise_uri;
                $git_plugin['enterprise_api'] = $repo_enterprise_api;
                $git_plugin['owner'] = $header['owner'];
                $git_plugin['repo'] = $header['repo'];
                $git_plugin['extended_repo'] = implode('-', array($repo_parts['git_server'], $header['owner'], $header['repo']));
                $git_plugin['branch'] = !empty($headers[$repo_parts['branch']]) ? $headers[$repo_parts['branch']] : 'master';
                $git_plugin['slug'] = $plugin;
                $git_plugin['local_path'] = WP_PLUGIN_DIR . '/' . $header['repo'] . '/';
                $git_plugin['local_path_extended'] = WP_PLUGIN_DIR . '/' . $git_plugin['extended_repo'] . '/';
                $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $git_plugin['slug']);
                $git_plugin['author'] = $plugin_data['AuthorName'];
                $git_plugin['name'] = $plugin_data['Name'];
                $git_plugin['local_version'] = strtolower($plugin_data['Version']);
                $git_plugin['sections']['description'] = $plugin_data['Description'];
                $git_plugin['languages'] = !empty($repo_languages) ? $repo_languages : null;
                $git_plugin['ci_job'] = !empty($repo_ci_job) ? $repo_ci_job : null;
                $git_plugin['release_asset'] = true == $plugin_data['Release Asset'] ? true : false;
            }
            $git_plugins[$git_plugin['repo']] = (object) $git_plugin;
        }
        return $git_plugins;
    }