설치된 플러그인에서 WordPress 플러그인 zip 파일을 만들 수 있습니까?
WordPress가 설치되어 있고 일부 플러그인이 설치되어 활성화되어 있습니다.하지만 원래 플러그인을 잃어버렸습니다..zip새로운 WordPress에 몇 가지 플러그인을 설치하고 싶습니다.
현재 WP 설치 전체를 마이그레이션/이동/백업/복원하고 싶지 않습니다.원래 플러그인을 다시 만들고 싶을 뿐입니다..zip설치되는 일부 플러그인의 파일입니다.데이터베이스뿐만 아니라 전체 파일 트리에도 액세스할 수 있습니다.그것을 할 수 있는 방법이 있나요?
예, 먼저 다운로드 링크를 플러그인 작업 링크에 추가합니다.

/**
* Add action links to each plugin
* @author brasofilo
*/
add_filter( 'plugin_action_links', function ( $plugin_meta, $plugin_file, $plugin_data, $status )
{
$plugin_dir = dirname( $plugin_file );
if( !empty( $plugin_dir ) && '.' !== $plugin_dir )
$plugin_meta[] = sprintf(
"<a href='#' class='down-zip down-icon' data-file='%s' title='%s'></a>",
$plugin_dir,
'Download zip file for ' . $plugin_data['Name']
);
else
$plugin_meta[] = "Root plugin, cannot zip";
return $plugin_meta;
}, 10, 4 );
그런 다음 JS 작업을 스타일링하고 첨부합니다.
/**
* Style and actions for wp-admin/plugins.php
* @author brasofilo
*/
add_action( 'admin_footer-plugins.php', function() {
?>
<style>
.down-icon:before { /* http://melchoyce.github.io/dashicons/ */
content: "\f316";
display: inline-block;
-webkit-font-smoothing: antialiased;
font: normal 20px/1 'dashicons';
vertical-align: top;
}
</style>
<script>
root_wp = '<?php echo WP_PLUGIN_DIR; ?>' + '/';
/**
* Virtual $_POST
* creates form, appends and submits
*
* @author https://stackoverflow.com/a/9815335/1287812
*/
function b5f_submit_form_post( path, params, method )
{
$ = jQuery;
method = method || "post"; // Set method to post by default, if not specified.
var form = $(document.createElement( "form" ))
.attr( {"method": method, "action": path} );
$.each( params, function(key,value)
{
$.each( value instanceof Array? value : [value], function(i,val)
{
$(document.createElement("input"))
.attr({ "type": "hidden", "name": key, "value": val })
.appendTo( form );
});
});
form.appendTo( document.body ).submit();
}
jQuery(document).ready(function($)
{
/**
* Fire a plugin download
*/
$("a.down-zip").click(function()
{
event.preventDefault();
b5f_submit_form_post( '', {
action: 'zip_a_plugin',
plugin_to_zip: root_wp + $(this).data('file'),
plugin_name: $(this).data('file')
});
});
});
</script>
<?php
});
커스텀 캡처$_POST데이터를 편집하고 플러그인 디렉토리를 zip으로 처리합니다.
/**
* Dispatch $_POST['action']=>'zip_a_plugin' custom action
* @author brasofilo https://stackoverflow.com/a/23546276/1287812
*/
add_action('admin_action_zip_a_plugin', function()
{
if( empty( $_REQUEST['plugin_to_zip'] ) )
return;
zipFile( $_REQUEST['plugin_to_zip'], $_REQUEST['plugin_name'], false );
});
마지막으로 여기 Stack에 있는 ZIP 기능을 사용하여
/**
* Makes zip from folder
* @author https://stackoverflow.com/a/17585672/1287812
*/
function zipFile($source, $destination, $flag = '')
{
if ( !extension_loaded('zip') ) {
return false;
}
$zip = new ZipArchive();
$tmp_file = tempnam(WP_CONTENT_DIR,'');
if (!$zip->open($tmp_file, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', realpath($source));
if($flag)
{
$flag = basename($source) . '/';
//$zip->addEmptyDir(basename($source) . '/');
}
if (is_dir($source) === true)
{
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file)
{
$file = str_replace('\\', '/', realpath($file));
if (is_dir($file) === true)
{
$src = str_replace($source . '/', '', $flag.$file . '/');
if( WP_PLUGIN_DIR.'/' !== $src ) # Workaround, as it was creating a strange empty folder like /www_dev/dev.plugins/wp-content/plugins/
$zip->addEmptyDir( $src );
}
else if (is_file($file) === true)
{
$src = str_replace($source . '/', '', $flag.$file);
$zip->addFromString( $src, file_get_contents($file));
}
}
}
else if (is_file($source) === true)
{
$zip->addFromString($flag.basename($source), file_get_contents($source));
}
$tt = $zip->close();
if(file_exists($tmp_file))
{
// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$destination.'"');
readfile($tmp_file);
// remove zip file is exists in temp path
exit();
}
else {
echo $tt;
die();
}
}
재미있게도 기존 플러그인에서 zip 파일을 만드는 것은 사실 간단한 일입니다.
플러그인 폴더를 포함하는 zip 파일을 생성하기만 하면 됩니다.이를 위한 unix 명령어는 다음과 같습니다.
$ cd wp-content/plugins
$ zip -r my-plugin.zip my-plugin
그런 다음 결과 my-plugin을 다운로드할 수 있습니다.WordPress 플러그인 설치에서 사용할 수 있는 zip 파일입니다(예: WP Admin -> Plugins -> Add New -> Upload).
zip 파일에는 데이터베이스 테이블/모드는 포함되지 않지만 대부분의 플러그인은 설치 시 이를 테스트하고 설치 시 필요한 데이터베이스 업그레이드를 수행합니다.유감스럽게도 플러그인 소스 코드를 테스트하거나 확인하지 않으면 문제가 발생하는지 여부를 알 수 없습니다.
가장 쉽고 코드 없는 방법은 WordPress Downloader와 같은 다른 플러그인을 사용하는 것입니다.
언급URL : https://stackoverflow.com/questions/15923003/is-it-possible-to-create-a-wordpress-plugin-zip-file-from-an-installed-plugin
'programing' 카테고리의 다른 글
| 클라이언트 알림, AJAX Push 또는 Poll을 사용해야 합니까? (0) | 2023.02.16 |
|---|---|
| Woocommerce 플러그인에서 "Ship to a Different Address?" 확인란 숨기기 또는 삭제 (0) | 2023.02.12 |
| Node.js Sass 버전 7.0.0은 ^4.0.0 || ^5.0.0 || ^6.0.0과 호환되지 않습니다. (0) | 2023.02.12 |
| AFNetworking 2.0을 사용한JSON 데이터 게시 (0) | 2023.02.12 |
| 트위터 부트스트랩 양식 필드가 너무 작습니다. (0) | 2023.02.12 |