플러그인 접두사의 고유성을 확인하는 방법은 무엇입니까?


11

다른 플러그인과의 충돌을 피하려면 모든 전역 함수, 액션 및 플러그인 앞에 고유 한 접두사를 붙여야합니다. 예 :

function xyz_function_name() { ... }

문제는 이것이 xyz실제로 고유 하다는 것을 어떻게 확인 합니까? 예를 들어 Yoast SEO는 wpseo_다른 SEO 플러그인도 쉽게 사용할 수 있다고 생각합니다. 충돌 가능성에 대해 사용 가능한 WordPress 플러그인을 검색하는 가장 좋은 방법은 무엇입니까? 아니면 있습니까?


4
접두사는 과거의 일입니다. 요즘에는 네임 스페이스를 사용하므로 원하는만큼 네임 스페이스를 중첩 할 수 있습니다.
fuxia

전역 적이며 클래스를 사용하여 접두사를 사용할 수없는 작업 및 필터를 포함하도록 질문을 업데이트합니다.
Borek Bernard

그 업데이트로, 이것은 매우 좋은 질문입니다
prosti

1
나는 대답이 어려울 것이라고 생각하기 때문에 이것을 투표했다. 그러나 접두사와 함수 이름의 무한한 조합이 가능하기 때문에 이것이 꼭 필요한 것은 아니라고 생각합니다. 실제 솔루션은 함수 이름에 더 자세해야한다고 생각합니다. 또한 과잉 일 수도 있지만 접미사가 추가 될 수도 있습니다.
stims

답변:


5

Mark Jaquith 의 WordPres Plugin Directory Slurper 셸 스크립트를 사용하여 WordPress.org 저장소에서 모든 플러그인의 최신 버전을 다운로드 할 수 있습니다. 플러그인이 다운로드되면 확인할 플러그인 / 후크 접두사를 grep 할 수 있습니다. 예를 들면 다음과 같습니다.

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

WordPres 플러그인 디렉토리 Slurper 패키지를 문서 루트에 압축 해제하십시오. 기본 디렉토리 이름은 다음 WordPress-Plugin-Directory-Slurper과 같습니다.

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

디렉토리 php update내에서 실행하여 bash 스크립트를 실행 하십시오 WordPress-Plugin-Directory-Slurper. 압축 된 플러그인 다운로드됩니다 /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 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";

가장 최근에 승인 된 테마를 모두 다운로드하려면 Aaron Jorbin의 WordPress Theme Directory Slurper 라는 스크립트도 있습니다.

이 쉘 스크립트는 Unix 시스템 용으로 설계되었습니다. Windows를 사용하는 경우 cygwin을 사용하여 플러그인 / 테마 디렉토리 Slurper 스크립트를 실행할 수 있습니다.


0
  1. 일반적이지 않은 이름을 사용하십시오.
  2. 새로운 플러그인을 설치하는 사람은 더 이상 PHP 5.2를 사용하지 않으며 (2016 년 10 월), PHP 네임 스페이스를 사용하여 플러그인 이름과 같이 길지만 관련성이 높은 것으로 만듭니다.
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.