問題描述
為了避免與其他外掛衝突,應該使用唯一字首的所有全域性函式,操作和外掛字首,例如:
function xyz_function_name() { ... }
問題是,如何驗證 xyz 確實是獨一無二的?例如,Yoast SEO 使用 wpseo_,我可以想象其他 SEO 外掛也可以輕鬆使用。搜尋可用的 WordPress 外掛潛在的衝突的最佳方式是什麼?還是在那裡?
最佳解決方案
您可以使用 Mark Jaquith 的 WordPres Plugin Directory Slurper shell 指令碼從 WordPress.org repo 下載所有外掛的最新版本。一旦外掛被下載,你可以 grep 你想檢查的外掛/鉤子字首,例如:
grep -r --include=*.php 'wpseo_' ./
將 WordPres Plugin Directory Slurper 軟體包解壓縮到檔案根目錄。預設目錄名為 WordPress-Plugin-Directory-Slurper,它包含:
/plugins/
/readmes/
/zips/
LICENSE
README.markdown
update
從 WordPress-Plugin-Directory-Slurper 目錄中執行 php update 執行 bash 指令碼。拉鍊外掛將下載到/zips 並提取到/plugins 。整個售後服務在 15GB 左右,首次下載需要幾個小時。
update 指令碼的內容:
#!/usr/bin/php
<?php
$args = $argv;
$cmd = array_shift( $args );
$type = 'all';
if ( !empty( $args[0] ) ) {
$type = $args[0];
}
switch ( $type ) {
case 'readme':
$directory = 'readmes';
$download = 'readmes/%s.readme';
$url = 'http://plugins.svn.wordpress.org/%s/trunk/readme.txt';
break;
case 'all':
$directory = 'plugins';
$download = 'zips/%s.zip';
$url = 'http://downloads.wordpress.org/plugin/%s.latest-stable.zip?nostats=1';
break;
default:
echo $cmd . ": invalid commandrn";
echo 'Usage: php ' . $cmd . " [command]rnrn";
echo "Available commands:rn";
echo " all - Downloads full plugin zipsrn";
echo " readme - Downloads plugin readmes onlyrn";
die();
}
echo "Determining most recent SVN revision...rn";
try {
$changelog = @file_get_contents( 'http://plugins.trac.wordpress.org/log/?format=changelog&stop_rev=HEAD' );
if ( !$changelog )
throw new Exception( 'Could not fetch the SVN changelog' );
preg_match( '#[([0-9]+)]#', $changelog, $matches );
if ( !$matches[1] )
throw new Exception( 'Could not determine most recent revision.' );
} catch ( Exception $e ) {
die( $e->getMessage() . "rn" );
}
$svn_last_revision = (int) $matches[1];
echo "Most recent SVN revision: " . $svn_last_revision . "rn";
if ( file_exists( $directory . '/.last-revision' ) ) {
$last_revision = (int) file_get_contents( $directory . '/.last-revision' );
echo "Last synced revision: " . $last_revision . "rn";
} else {
$last_revision = false;
echo "You have not yet performed a successful sync. Settle in. This will take a while.rn";
}
$start_time = time();
if ( $last_revision != $svn_last_revision ) {
if ( $last_revision ) {
$changelog_url = sprintf( 'http://plugins.trac.wordpress.org/log/?verbose=on&mode=follow_copy&format=changelog&rev=%d&limit=%d', $svn_last_revision, $svn_last_revision - $last_revision );
$changes = file_get_contents( $changelog_url );
preg_match_all( '#^' . "t" . '** ([^/A-Z ]+)[ /].* ((added|modified|deleted|moved|copied))' . "n" . '#m', $changes, $matches );
$plugins = array_unique( $matches[1] );
} else {
$plugins = file_get_contents( 'http://svn.wp-plugins.org/' );
preg_match_all( '#<li><a href="http://([/%5D+)/">([^/]+)/</a></li>#', $plugins, $matches );
$plugins = $matches[1];
}
foreach ( $plugins as $plugin ) {
$plugin = urldecode( $plugin );
echo "Updating " . $plugin;
$output = null; $return = null;
exec( 'wget -q -np -O ' . escapeshellarg( sprintf($download, $plugin) ) . ' ' . escapeshellarg( sprintf($url, $plugin) ) . ' > /dev/null', $output, $return );
if ( $return === 0 && file_exists( sprintf($download, $plugin) ) ) {
if ($type === 'all') {
if ( file_exists( 'plugins/' . $plugin ) )
exec( 'rm -rf ' . escapeshellarg( 'plugins/' . $plugin ) );
exec( 'unzip -o -d plugins ' . escapeshellarg( 'zips/' . $plugin . '.zip' ) );
exec( 'rm -rf ' . escapeshellarg( 'zips/' . $plugin . '.zip' ) );
}
} else {
echo '... download failed.';
}
echo "rn";
}
if ( file_put_contents( $directory . '/.last-revision', $svn_last_revision ) )
echo "[CLEANUP] Updated $directory/.last-revision to " . $svn_last_revision . "rn";
else
echo "[ERROR] Could not update $directory/.last-revision to " . $svn_last_revision . "rn";
}
$end_time = time();
$minutes = ( $end_time - $start_time ) / 60;
$seconds = ( $end_time - $start_time ) % 60;
echo "[SUCCESS] Done updating plugins!rn";
echo "It took " . number_format($minutes) . " minute" . ( $minutes == 1 ? '' : 's' ) . " and " . $seconds . " second" . ( $seconds == 1 ? '' : 's' ) . " to update ". count($plugins) ." plugin" . ( count($plugins) == 1 ? '' : 's') . "rn";
echo "[DONE]rn";
如果您想下載所有最新的批准主題,還有一個指令碼:Aaron Jorbin 的 WordPress Theme Directory Slurper 。
這些 shell 指令碼是為 Unix 系統而設計的。如果您使用的是 Windows,則可以使用 cygwin 執行 Plugin /Theme Directory Slurper 指令碼。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。