問題描述
我有一個問題,找出如何顯示可用於呼叫除管理員頭以外的其他地方的外掛/更新數量。我發現功能 wp_get_update_data 應該是我需要的:
How is the ” wp_get_update_data ” function used?
但是,我不知道如何將其顯示為可用的總外掛和更新的實際數量,或網際網路上的任何工作示例如何使用它。
任何建議將不勝感激。
最佳解決方案
以下是從 wp_get_update_data()函式返回的資料的示例:
Array
(
[counts] => Array
(
[plugins] => 3
[themes] => 2
[wordpress] => 0
[translations] => 0
[total] => 5
)
[title] => 3 Plugin Updates, 2 Theme Updates
)
所以可用外掛更新的數量應該可用:
// Number of available plugin updates:
$update_data = wp_get_update_data();
echo $update_data['counts']['plugins'];
更新:
要在管理區域中顯示以下外掛資訊:
There are available updates for 3 plugins out of 22
我們還可以使用 get_plugins()功能:
if ( ! function_exists( 'get_plugins' ) )
{
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$data = array(
'updates' => $update_data['counts']['plugins'],
'total' => count( get_plugins() ),
);
printf(
"There are available updates for <strong>%d</strong> plugins
out of <strong>%d</strong>",
$data['updates'],
$data['total']
);
我們可以使用 get_mu_plugins()和 get_dropins()以類似的方式新增更多資訊。
次佳解決方案
wp_get_update_data()返回此格式的陣列
-
計數
-
外掛
-
主題
-
WordPress 的
-
譯文
-
總
-
-
標題
所以,如果你想要總計數,你需要這樣使用它
$updates = wp_get_update_data();
echo $updates['counts']['total'];
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。