本文整理汇总了PHP中plugins_api函数的典型用法代码示例。如果您正苦于以下问题:PHP plugins_api函数的具体用法?PHP plugins_api怎么用?PHP plugins_api使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了plugins_api函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rtbiz_install_plugin
public function rtbiz_install_plugin($plugin_slug)
{
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$api = plugins_api('plugin_information', array('slug' => $plugin_slug, 'fields' => array('sections' => false)));
if (is_wp_error($api)) {
die(sprintf(__('ERROR: Error fetching plugin information: %s', RTBIZ_TEXT_DOMAIN), $api->get_error_message()));
}
if (!class_exists('Plugin_Upgrader')) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
if (!class_exists('Rtbiz_Plugin_Upgrader_Skin')) {
require_once RTBIZ_PATH . 'admin/abstract/class-rtbiz-plugin-upgrader-skin.php';
}
$upgrader = new Plugin_Upgrader(new Rtbiz_Plugin_Upgrader_Skin(array('nonce' => 'install-plugin_' . $plugin_slug, 'plugin' => $plugin_slug, 'api' => $api)));
$install_result = $upgrader->install($api->download_link);
if (!$install_result || is_wp_error($install_result)) {
// $install_result can be false if the file system isn't writeable.
$error_message = __('Please ensure the file system is writeable', RTBIZ_TEXT_DOMAIN);
if (is_wp_error($install_result)) {
$error_message = $install_result->get_error_message();
}
die(sprintf(__('ERROR: Failed to install plugin: %s', RTBIZ_TEXT_DOMAIN), $error_message));
}
$activate_result = activate_plugin($this->rtbiz_get_path_for_plugin($plugin_slug));
if (is_wp_error($activate_result)) {
die(sprintf(__('ERROR: Failed to activate plugin: %s', RTBIZ_TEXT_DOMAIN), $activate_result->get_error_message()));
}
}
示例2: hmbkp_contextual_help
/**
* Add Contextual Help to Backups tools page.
*
* Help is pulled from the readme FAQ.
*
* @return null
*/
function hmbkp_contextual_help()
{
// Pre WordPress 3.3 compat
if (!method_exists(get_current_screen(), 'add_help_tab')) {
return;
}
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
if (!($plugin = get_transient('hmbkp_plugin_data'))) {
$plugin = plugins_api('plugin_information', array('slug' => HMBKP_PLUGIN_SLUG));
// Cache for one day
set_transient('hmbkp_plugin_data', $plugin, 1 * DAY_IN_SECONDS);
}
$warning = '';
// Check if help is for the right version.
if (!empty($plugin->version) && version_compare(HMBKP_VERSION, $plugin->version, '!=')) {
$warning = sprintf('<div id="message" class="updated inline"><p><strong>' . __('You are not using the latest stable version of BackUpWordPress', 'hmbkp') . '</strong> — ' . __('The information below is for version %1$s. View the %2$s file for help specific to version %3$s.', 'hmbkp') . '</p></div>', '<code>' . esc_attr($plugin->version) . '</code>', '<code>readme.txt</code>', '<code>' . esc_attr(HMBKP_VERSION) . '</code>');
}
ob_start();
require_once HMBKP_PLUGIN_PATH . 'admin/constants.php';
$constants = ob_get_clean();
ob_start();
include_once HMBKP_PLUGIN_PATH . 'admin/faq.php';
$faq = ob_get_clean();
get_current_screen()->add_help_tab(array('title' => __('FAQ', 'hmbkp'), 'id' => 'hmbkp_faq', 'content' => wp_kses_post($faq)));
get_current_screen()->add_help_tab(array('title' => __('Constants', 'hmbkp'), 'id' => 'hmbkp_constants', 'content' => wp_kses_post($constants)));
get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'hmbkp') . '</strong></p>' . '<p><a href="https://github.com/humanmade/backupwordpress" target="_blank">GitHub</a></p>' . '<p><a href="http://wordpress.org/tags/backupwordpress?forum_id=10" target="_blank">' . __('Support Forums', 'hmbkp') . '</a></p>' . '<p><a href="http://translate.hmn.md/" target="_blank">' . __('Help with translation', 'hmbkp') . '</a></p>');
}
示例3: manage
public function manage()
{
if (!function_exists('plugins_api')) {
require_once ABSPATH . '/wp-admin/includes/plugin-install.php';
}
preg_match_all('/####([\\d\\w\\-]{1,})####/', $this->template, $plugin_list);
if (isset($plugin_list[1]) && is_array($plugin_list[1])) {
$search = array();
foreach ($plugin_list[1] as $plugin) {
$api = plugins_api('plugin_information', array('slug' => stripslashes($plugin)));
$status = install_plugin_install_status($api);
switch ($status['status']) {
case 'install':
$search["####{$plugin}####"] = isset($status['url']) ? $status['url'] : 'javascript:void();';
$search["###{$plugin}-install-text###"] = __('Install Now');
break;
case 'update_available':
$search["####{$plugin}####"] = isset($status['url']) ? $status['url'] : 'javascript:void();';
$search["###{$plugin}-install-text###"] = __('Install Update Now');
break;
case 'newer_installed':
$search["####{$plugin}####"] = 'javascript:void();';
$search["###{$plugin}-install-text###"] = sprintf(__('Newer Version (%s) Installed'), $status['version']);
break;
case 'latest_installed':
$search["####{$plugin}####"] = 'javascript:void();';
$search["###{$plugin}-install-text###"] = __('Latest Version Installed');
break;
}
}
$this->template = str_replace(array_keys($search), $search, $this->template);
}
echo $this->template;
}
示例4: prepare_items
function prepare_items()
{
include ABSPATH . 'wp-admin/includes/plugin-install.php';
global $tabs, $tab, $paged, $type, $term;
wp_reset_vars(array('tab'));
$paged = $this->get_pagenum();
$per_page = 30;
// These are the tabs which are shown on the page
$tabs = array();
$tabs['dashboard'] = __('Search');
if ('search' == $tab) {
$tabs['search'] = __('Search Results');
}
$tabs['featured'] = _x('Featured', 'Plugin Installer');
$tabs['popular'] = _x('Popular', 'Plugin Installer');
$tabs['new'] = _x('Newest', 'Plugin Installer');
$nonmenu_tabs = array('plugin-information');
//Valid actions to perform which do not have a Menu item.
$tabs = apply_filters('install_plugins_tabs', $tabs);
$nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs);
// If a non-valid menu tab has been selected, And its not a non-menu action.
if (empty($tab) || !isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs)) {
$tab = key($tabs);
}
$args = array('page' => $paged, 'per_page' => $per_page);
switch ($tab) {
case 'search':
$type = isset($_REQUEST['type']) ? stripslashes($_REQUEST['type']) : 'term';
$term = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '';
switch ($type) {
case 'tag':
$args['tag'] = sanitize_title_with_dashes($term);
break;
case 'term':
$args['search'] = $term;
break;
case 'author':
$args['author'] = $term;
break;
}
add_action('install_plugins_table_header', 'install_search_form', 10, 0);
break;
case 'featured':
case 'popular':
case 'new':
$args['browse'] = $tab;
break;
default:
$args = false;
}
if (!$args) {
return;
}
$api = plugins_api('query_plugins', $args);
if (is_wp_error($api)) {
wp_die($api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __('Try again') . '</a>');
}
$this->items = $api->plugins;
$this->set_pagination_args(array('total_items' => $api->info['results'], 'per_page' => $per_page));
}
示例5: install
function install()
{
$plugin = array('name' => 'Clef', 'slug' => 'wpclef');
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
// Need for plugins_api
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// Need for upgrade classes
require_once 'plugin-install.php';
$api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => false)));
if (is_wp_error($api)) {
$this->clef_install_errors = array($api->get_error_message());
add_action('admin_notices', array(&$this, 'clef_install_errors'));
return;
} elseif (isset($api->download_link)) {
$plugin['source'] = $api->download_link;
} else {
$this->clef_install_errors = array('Error trying to download Clef');
add_action('admin_notices', array(&$this, 'clef_install_errors'));
return;
}
/** Pass all necessary information via URL if WP_Filesystem is needed */
$url = wp_nonce_url(add_query_arg(array('page' => 'bruteprotect-clef', 'bruteprotect-clef-action' => 'install'), admin_url('admin.php')), 'bruteprotect-clef-install');
$method = '';
// Leave blank so WP_Filesystem can populate it as necessary
$fields = array(sanitize_key('bruteprotect-clef-install'));
// Extra fields to pass to WP_Filesystem
if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) {
return;
}
if (!WP_Filesystem($creds)) {
request_filesystem_credentials($url, $method, true, false, $fields);
// Setup WP_Filesystem
return;
}
/** Set type, based on whether the source starts with http:// or https:// */
$type = preg_match('|^http(s)?://|', $plugin['source']) ? 'web' : 'upload';
/** Prep variables for Plugin_Installer_Skin class */
$title = sprintf('Installing %s', $plugin['name']);
$url = add_query_arg(array('action' => 'install-plugin', 'plugin' => $plugin['slug']), 'update.php');
if (isset($_GET['from'])) {
$url .= add_query_arg('from', urlencode(stripslashes($_GET['from'])), $url);
}
$nonce = 'install-plugin_' . $plugin['slug'];
$source = $plugin['source'];
/** Create a new instance of Plugin_Upgrader */
$upgrader = new Plugin_Upgrader($skin = new Silent_Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api')));
/** Perform the action and install the plugin from the $source urldecode() */
$upgrader->install($source);
if (!empty($skin->errors)) {
$this->clef_install_errors = $skin->errors;
add_action('admin_notices', array(&$this, 'clef_install_errors'));
return;
}
/** Flush plugins cache so we can make sure that the installed plugins list is always up to date */
wp_cache_flush();
}
示例6: __invoke
/**
* List plugins a user has favorited in the WordPress.org plugins directory.
*
* ## OPTIONS
*
* <user>
* : The username of the wordpress.org account whose favorite plugins you are listing.
*
* [--slug]
* : Only return plugin slugs. Can be combined with `wp plugin install` (see examples).
*
* [--verbose]
* : Display more information about the plugins.
*
* ## EXAMPLES
*
* wp plugin favorites matt
* wp plugin favorites matt --verbose
* wp plugin favorites matt --slug | xargs wp plugin install --activate
* wp plugin favorites matt --slug | grep -vwE "(hello-dolly|bbpress)" | xargs wp plugin install --activate
*
* @synopsis <user> [--slug] [--verbose]
*/
public function __invoke($args, $assoc_args)
{
// prepare variables
list($user) = $args;
extract($assoc_args = wp_parse_args($assoc_args, array('slug' => false, 'verbose' => false)));
// get access to plugins_api
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
// query wordpress.org
$api = plugins_api('query_plugins', array('user' => $user, 'fields' => array('last_updated' => true, 'active_installs' => true)));
// only return slug?
if ($slug) {
foreach ($api->plugins as $plugin) {
WP_CLI::log($plugin->slug);
}
return;
}
// get table columns
$props = array('name', 'last_updated', 'rating', 'num_ratings', 'active_installs');
if ($verbose) {
$props = array_merge($props, array('author', 'version', 'requires', 'tested', 'short_description'));
}
// pull object properties into an array
$plugins = array();
foreach ($api->plugins as $plugin) {
$args = array();
foreach ($props as $prop) {
$args[$prop] = '';
if (isset($plugin->{$prop})) {
$args[$prop] = $plugin->{$prop};
// clean up some fields for output
switch ($prop) {
case 'rating':
$args[$prop] = (int) $args['rating'] / 100 * 5 . '/5';
break;
case 'author':
$args[$prop] = strip_tags($args['author']);
break;
case 'last_updated':
$args[$prop] = date('Y-m-d', strtotime($args['last_updated']));
break;
case 'active_installs':
$args[$prop] = number_format($args['active_installs']);
break;
}
}
}
$plugins[$plugin->slug] = $args;
}
if (!$plugins) {
WP_CLI::log('No favorite plugins found.');
return;
}
// output as list table
$formatter = new \WP_CLI\Formatter($assoc_args, $props, 'plugin');
$formatter->display_items($plugins);
}
示例7: get_information
public function get_information()
{
if (!function_exists('plugins_api')) {
require ABSPATH . 'wp-admin/includes/plugin-install.php';
}
$fields = array('short_description' => true, 'screenshots' => false, 'changelog' => false, 'installation' => false, 'description' => false);
$args = array('slug' => $this->slug, 'fields' => $fields);
$this->information = plugins_api('plugin_information', $args);
return $this->information;
}
示例8: install_link
function install_link()
{
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$info = plugins_api('plugin_information', array('slug' => $this->slug));
if (is_wp_error($info)) {
return false;
}
// plugin not available from wordpress.org
return wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $this->slug), 'install-plugin_' . $this->slug);
}
示例9: get_plugin_data_from_api
protected function get_plugin_data_from_api()
{
$data = plugins_api('plugin_information', array('slug' => $this->slug, 'is_ssl' => is_ssl(), 'fields' => self::$fields));
if (!is_wp_error($data)) {
return $this->transform_plugin_data($data);
} else {
$this->_error = $data;
}
return false;
}
示例10: _retrieve_data
/**
* @access protected
*
* @return bool
*/
public function _retrieve_data()
{
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$args = array('author' => $this->options['username'], 'per_page' => 100, 'fields' => array('description' => false, 'compatibility' => false, 'icons' => true, 'downloaded' => true, 'last_updated' => true));
$data = plugins_api('query_plugins', $args);
if ($data && isset($data->plugins)) {
$data = array('data' => $data->plugins, 'expiration' => time() + $this->expiration);
update_post_meta($this->post->ID, '_plugins', $data);
return $data;
}
return false;
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$env = Validators::validateEnv($input->getOption('env'));
$root = $this->skeleton->getWebRoot();
$plugins = $this->skeleton->get(sprintf('wordpress.%s.plugins', $env));
require $root . '/wp-load.php';
require ABSPATH . 'wp-admin/includes/admin.php';
require ABSPATH . 'wp-admin/includes/plugin-install.php';
foreach ($plugins as $slug => $version) {
$plugin = plugins_api('plugin_information', array('slug' => $slug));
if (is_wp_error($plugin)) {
throw new \Exception('Could not get plugin information for ' . $slug);
}
if ($version) {
list($prefix) = explode($slug, $plugin->download_link);
$link = sprintf('%s%s.%s.zip', $prefix, $slug, $version);
$response = wp_remote_head($link);
if (!isset($response['response']['code']) || $response['response']['code'] != 200) {
throw new \Exception('Unable to verify ' . $link);
}
$plugin->download_link = $link;
$plugin->version = $version;
}
require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$status = install_plugin_install_status($plugin);
$upgrader = new \Plugin_Upgrader(new UpgraderSkin($output));
$current = current(get_plugins("/{$slug}"));
switch ($status['status']) {
case 'install':
$output->write(sprintf('Installing <info>%s</info> v<comment>%s</comment>', $plugin->name, $plugin->version));
$upgrader->install($plugin->download_link);
break;
case 'update_available':
if ($plugin->version == $current['Version']) {
$output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $plugin->version));
} else {
$output->write(sprintf('Upgrading <info>%s</info> from <comment>%s</comment> to <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
$file = sprintf('%s/%s', $slug, key(get_plugins("/{$slug}")));
$upgrader->upgrade($file);
}
break;
case 'latest_installed':
$output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $current['Version']));
break;
case 'newer_installed':
$output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is installed & newer than <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
break;
}
}
if ($plugins) {
$output->writeln(sprintf('<info>Activate plugins in the WordPress Admin</info>', $plugin->name));
}
}
示例12: install_wp_super_cache
function install_wp_super_cache()
{
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// code from wp-admin/update.php
$api = plugins_api('plugin_information', array('slug' => 'wp-super-cache', 'fields' => array('short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false)));
if (is_wp_error($api)) {
wp_die($api);
}
$upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api')));
$upgrader->install($api->download_link);
}
示例13: check_plugins
function check_plugins()
{
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$plugins = get_plugin_updates();
if (!empty($plugins)) {
foreach ((array) $plugins as $plugin_file => $plugin_data) {
plugins_api('plugin_information', array('slug' => $plugin_data->update->slug));
}
WP_CLI::success('Plugin updates refreshed.');
} else {
WP_CLI::log('All plugins are up to date.');
}
}
示例14: get_information
public function get_information()
{
$key = str_replace('_', '_', $this->slug) . '_information';
if (false === ($this->information = get_transient($key))) {
if (!function_exists('plugins_api')) {
require ABSPATH . 'wp-admin/includes/plugin-install.php';
}
$fields = array('short_description' => true, 'screenshots' => false, 'changelog' => false, 'installation' => false, 'description' => false);
$args = array('slug' => $this->slug, 'fields' => $fields);
$this->information = plugins_api('plugin_information', $args);
set_transient($key, $this->information, DAY_IN_SECONDS);
}
return $this->information;
}
示例15: rkv_plugin_favorites
function rkv_plugin_favorites()
{
/** If plugins_api isn't available, load the file that holds the function */
if (!function_exists('plugins_api')) {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
}
/** Prepare our query */
$api = plugins_api('query_plugins', array('user' => 'norcross'));
/** Display the results */
if (is_wp_error($api)) {
echo 'Something went wrong!';
} else {
$favorites = $api->plugins;
}
shuffle($favorites);
// grab the first one after randomizing the array
$plugin_name = $favorites[0]->name;
$plugin_slug = $favorites[0]->slug;
$plugin_link = $favorites[0]->homepage;
$plugin_text = $favorites[0]->short_description;
$author_name = $favorites[0]->author;
$author_link = $favorites[0]->author_profile;
echo '<div class="widget plugin-details plugin-favorite">';
echo '<h4 class="nav-header">Other Favorites <i class="icon icon-tags pull-right"></i></h4>';
// first one
echo '<div class="favorite-single">';
echo '<h5><a href="' . $plugin_link . '" target="_blank">' . $plugin_name . '</a></h5>';
echo '<p class="plugin-author"><em><small>by</small></em> <a href="' . $author_link . '" target="_blank">' . $author_name . '</a></p>';
echo '<p>' . $plugin_text . '</p>';
echo '<p class="more-link"><a class="btn" href="http://wordpress.org/extend/plugins/' . $plugin_slug . '/" target="_blank">Learn More →</a></p>';
echo '</div>';
// now grab the second one after randomizing the array
$plugin_name = $favorites[1]->name;
$plugin_slug = $favorites[1]->slug;
$plugin_link = $favorites[1]->homepage;
$plugin_text = $favorites[1]->short_description;
$author_name = $favorites[1]->author;
$author_link = $favorites[1]->author_profile;
// second one
echo '<div class="favorite-single">';
echo '<h5><a href="' . $plugin_link . '" target="_blank">' . $plugin_name . '</a></h5>';
echo '<p class="plugin-author"><em><small>by</small></em> <a href="' . $author_link . '" target="_blank">' . $author_name . '</a></p>';
echo '<p>' . $plugin_text . '</p>';
echo '<p class="more-link"><a class="btn" href="http://wordpress.org/extend/plugins/' . $plugin_slug . '/" target="_blank">Learn More →</a></p>';
echo '</div>';
echo '<p class="disclaimer"><strong>Note:</strong> these plugins are not developed by me.</p>';
// close it out
echo '</div>';
}