Esempio n. 1
0
/**
 * Query the list of add-ons from wordpress.org with keyword 'learnpress'
 * This requires have a keyword named 'learnpress' in plugin header Tags
 *
 * @param array
 * @return array
 */
function learn_press_get_add_ons_from_wp($args = null)
{
    $args = wp_parse_args($args, array('search' => 'learnpress', 'include' => null, 'exclude' => null));
    // the number of plugins on each page queried, when we can reach to this figure?
    $per_page = 300;
    $paged = 1;
    $query_args = array('page' => $paged, 'per_page' => $per_page, 'fields' => array('last_updated' => true, 'icons' => true, 'active_installs' => true), 'locale' => get_locale(), 'installed_plugins' => get_installed_plugin_slugs(), 'search' => $args['search'], 'exclude' => $args['exclude']);
    $transient_key = "learn_press_add_ons" . md5(serialize($query_args));
    delete_transient($transient_key);
    if ($plugins = get_transient($transient_key)) {
    } else {
        learn_press_require_plugins_api();
        $api = plugins_api('query_plugins', $query_args);
        if (is_wp_error($api)) {
            return false;
        }
        if (is_array($api->plugins)) {
            // filter plugins with tag contains 'learnpress'
            $plugins = array_filter($api->plugins, create_function('$plugin', 'return $plugin->slug != \'learnpress\';'));
            if (!empty($args['exclude'])) {
                for ($n = sizeof($plugins), $i = $n - 1; $i >= 0; $i--) {
                    if (in_array($plugins[$i]->slug, $args['exclude'])) {
                        unset($plugins[$i]);
                    }
                }
            }
            set_transient($transient_key, $plugins, 60 * 5);
        }
    }
    return $plugins;
}
/**
 * Query the list of add-ons from wordpress.org with keyword 'learnpress'
 * This requires have a keyword named 'learnpress' in plugin header Tags
 *
 * @param array
 * @return array
 */
function learn_press_get_add_ons_from_wp($args = null)
{
    $args = wp_parse_args($args, array('search' => 'learnpress', 'include' => null, 'exclude' => null));
    // the number of plugins on each page queried, when we can reach to this figure?
    $per_page = 300;
    $paged = 1;
    $query_args = array('page' => $paged, 'per_page' => $per_page, 'fields' => array('last_updated' => true, 'icons' => true, 'active_installs' => true), 'locale' => get_locale(), 'installed_plugins' => get_installed_plugin_slugs(), 'search' => $args['search']);
    $transient_key = "learn_press_add_ons" . md5(serialize($query_args));
    if ($plugins = get_transient($transient_key)) {
        $this->items = $plugins;
        return;
    }
    $api = plugins_api('query_plugins', $query_args);
    if (is_wp_error($api)) {
        $this->error = $api;
        return;
    }
    if (is_array($api->plugins)) {
        // filter plugins with tag contains 'learnpress'
        $plugins = array_filter($api->plugins, create_function('$plugin', 'return $plugin->slug != \'learnpress\';'));
        set_transient($transient_key, $plugins, 60 * 5);
    }
    return $plugins;
}