Posted by on the 28th of June, 2021 at 2:03 am under 컴퓨터.  This post has no comments.

지난번에 iwinv에서 WordPress 업데이트가 안될 때 에서 진짜 원인 해결이라고 적었는데 사실 알고 보니 아직도 해결이 안되었다. 분명 다운로드가 30초 안에 끝나지 않아서 php 실행이 되다 멈춘거 같은데 설정을 추가했어도 여전히 30초만에 멈춘다. 다시 강제로 하려다가 뭔가 방법이 있을 거 같아 찾아봤다.

class-wp-upgrader.php 를 보다 보니 이런 부분이 있었다.

	public function download_package( $package, $check_signatures = false, $hook_extra = array() ) {
		/**
		 * Filters whether to return the package.
		 *
		 * @since 3.7.0
		 * @since 5.5.0 Added the `$hook_extra` parameter.
		 *
		 * @param bool        $reply      Whether to bail without returning the package.
		 *                                Default false.
		 * @param string      $package    The package file name.
		 * @param WP_Upgrader $this       The WP_Upgrader instance.
		 * @param array       $hook_extra Extra arguments passed to hooked filters.
		 */
		$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra );
		if ( false !== $reply ) {
			return $reply;
		}

저기 ‘upgrader_pre_download’ filter가 있다.  저기에서 주는 결과를 가지고 바로 업그레이드를 할 수 있을 거 같았다. 그래서 바로 플러그인을 하나 만들었다.

/*
Plugin Name: Jeongsu's update helper
Plugin URI: https://bmp.pe.kr/
Description: read wordpress update package from local directory
Author: Jeongsu Kim
Version: 1.0
Author URI: https://bmp.pe.kr/
*/
function filter_do_upgrader_pre_download($reply, $package, $instance, $hook_extra) {
	// from https://wordpress.stackexchange.com/questions/119064/what-should-i-use-instead-of-wp-content-dir-and-wp-plugin-dir
	$myBnm = basename(__FILE__); // value: exampleplugin.php
	$myDir = plugin_basename(__FILE__); // value: exampleplugin/exampleplugin.php
	$myStr = str_replace($myBnm,"",$myDir); // value: exampleplugin/
	$myPth = plugin_dir_path(__FILE__); // value: /home/myserver/public_html/wordpress_install/wp-content/plugins/exampleplugin/
	$pluginsDir = str_replace($myStr,"",$myPth); // returns: /home/myserver/public_html/wordpress_install/wp-content/plugins/
	$wpcontent = dirname($pluginsDir);
	$tempdir = $wpcontent."/temp";
	$zipfile = $tempdir."/".basename($package);
	return $zipfile;
};

add_filter( 'upgrader_pre_download', 'filter_do_upgrader_pre_download' , 10, 4);

이제 zip 파일을 다운로드 해야 한다. 플러그인을 켜기 전에 일단 업데이트를 해 본다. 그럼 이렇게 메시지가 나온다.

저기에서 zip 파일을 받았다. 그리고 wordpress가 설치된 디렉토리에서 wp-content/temp에 넣었다. 이제 아까 만든 플러그인을 켜고 다시 update를 했다. 이번엔 성공!



* Required

The URI to TrackBack this entry is:
https://bmp.pe.kr/blog/index.php/2021/06/28/wordpress-update-%eb%ac%b8%ec%a0%9c-%eb%b0%98-%ed%95%b4%ea%b2%b0/trackback/