จะตรวจสอบเอกลักษณ์ของคำนำหน้าปลั๊กอินได้อย่างไร


11

เพื่อหลีกเลี่ยงการชนกับปลั๊กอินอื่น ๆ หนึ่งควรนำหน้าฟังก์ชั่นทั่วโลกทั้งหมดการกระทำและปลั๊กอินด้วยคำนำหน้าที่ไม่ซ้ำกันเช่น:

function xyz_function_name() { ... }

คำถามคือฉันจะยืนยันได้อย่างไรว่าxyzมีเอกลักษณ์ ตัวอย่างเช่น Yoast SEO ใช้wpseo_ซึ่งฉันสามารถนึกภาพปลั๊กอิน SEO อื่น ๆ ได้อย่างง่ายดายเช่นกัน วิธีที่ดีที่สุดในการค้นหาปลั๊กอิน WordPress ที่มีอยู่สำหรับการชนที่อาจเกิดขึ้นคืออะไร? หรือว่ามี


4
คำนำหน้าเป็นเรื่องของอดีต ทุกวันนี้เราใช้เนมสเปซและคุณสามารถสร้างที่ลึกที่สุดเท่าที่คุณต้องการ
fuxia

ฉันจะอัปเดตคำถามเพื่อรวมการกระทำและตัวกรองที่เป็นสากลและไม่สามารถนำหน้าด้วยชั้นเรียนได้
Borek Bernard

ด้วยการอัปเดตดังกล่าวนี่เป็นคำถามที่ดีมาก
prosti

1
ฉันโหวตให้คะแนนเพราะฉันคิดว่าคำตอบนั้นจะยาก แต่ฉันไม่คิดว่านี่เป็นสิ่งจำเป็นเนื่องจากอาจมีการรวมกันของคำนำหน้าและชื่อฟังก์ชันจำนวนไม่ จำกัด ฉันคิดว่าทางออกที่แท้จริงคือการให้รายละเอียดเพิ่มเติมในชื่อฟังก์ชัน นอกจากนี้และอาจ overkill แต่สามารถเพิ่ม postfix ได้
stims

คำตอบ:


5

คุณสามารถใช้เชลล์สคริปต์Slurper ของไดเรกทอรีปลั๊กอิน WordPresโดย Mark Jaquith เพื่อดาวน์โหลดปลั๊กอินทั้งหมดเวอร์ชันล่าสุดจาก repo WordPress.org เมื่อดาวน์โหลดปลั๊กอินแล้วคุณสามารถ grep สำหรับคำนำหน้า plugin / hook ที่คุณต้องการตรวจสอบเช่น:

grep -r --include=*.php 'wpseo_' ./

แตกไฟล์บีบอัดปลั๊กอินของ WordPres Package ไปยังรูทเอกสารของคุณ ชื่อไดเรกทอรีเริ่มต้นคือWordPress-Plugin-Directory-Slurperและมันมี:

  /plugins/
  /readmes/
  /zips/
  LICENSE
  README.markdown
  update

รันสคริปต์ทุบตีโดยดำเนินการphp updateจากภายในWordPress-Plugin-Directory-Slurperไดเรกทอรี ปลั๊กอินที่ซิปจะถูกดาวน์โหลดไปยัง/zipsและ/pluginsแตกไฟล์ repo ทั้งหมดอยู่ที่ประมาณ 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 command\r\n";
        echo 'Usage: php ' . $cmd . " [command]\r\n\r\n";
        echo "Available commands:\r\n";
        echo "  all - Downloads full plugin zips\r\n";
        echo "  readme - Downloads plugin readmes only\r\n";
        die();
}

echo "Determining most recent SVN revision...\r\n";
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() . "\r\n" );
}
$svn_last_revision = (int) $matches[1];
echo "Most recent SVN revision: " . $svn_last_revision . "\r\n";
if ( file_exists( $directory . '/.last-revision' ) ) {
    $last_revision = (int) file_get_contents( $directory . '/.last-revision' );
    echo "Last synced revision: " . $last_revision . "\r\n";
} else {
    $last_revision = false;
    echo "You have not yet performed a successful sync. Settle in. This will take a while.\r\n";
}

$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="([^/]+)/">([^/]+)/</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 "\r\n";
    }

    if ( file_put_contents( $directory . '/.last-revision', $svn_last_revision ) )
        echo "[CLEANUP] Updated $directory/.last-revision to " . $svn_last_revision . "\r\n";
    else
        echo "[ERROR] Could not update $directory/.last-revision to " . $svn_last_revision . "\r\n";
}

$end_time = time();
$minutes = ( $end_time - $start_time ) / 60;
$seconds = ( $end_time - $start_time ) % 60;

echo "[SUCCESS] Done updating plugins!\r\n";
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') . "\r\n";
echo "[DONE]\r\n";

หากคุณต้องการดาวน์โหลดชุดรูปแบบที่ได้รับการอนุมัติล่าสุดทั้งหมดมีสคริปต์สำหรับชุดนั้นเช่นกัน: WordPress Theme Directory Slurperโดย Aaron Jorbin

เชลล์สคริปต์เหล่านี้ออกแบบมาสำหรับระบบ Unix หากคุณใช้ Windows คุณสามารถเรียกใช้สคริปต์ปลั๊กอิน / ธีมไดเรกทอรี Slurper โดยใช้ cygwin


0
  1. อย่าเป็นชื่อสามัญใช้ชื่อของคุณบางรูปแบบ
  2. ไม่มีใครที่ติดตั้งปลั๊กอินใหม่ใช้ PHP 5.2 อีกต่อไป (ต.ค. 2559) เพียงแค่ใช้ PHP namespace และทำให้บางสิ่งยาว แต่มีความเกี่ยวข้องเช่นชื่อปลั๊กอิน
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.