我编写了在页面运行时更新核心的代码。当我通过管理挂钩使用代码时,一切都正常admin_init
但当我将其添加到cron函数或通过任何前端挂钩运行它时,它不起作用(致命错误)init
或template_redirect
等
因此,我试图要求class-wp-upgrader.php
文件
add_action(\'init\', \'kit_wp_auto_update\'); // doesn\'t work
// add_action(\'admin_init\', \'kit_wp_auto_update\'); // works
function kit_do_update(){
require_once( ABSPATH . \'wp-admin/includes/class-wp-upgrader.php\' );
fb(\'kit_do_update\');
$core_transient = get_site_transient( \'update_core\' );
fb($core_transient);
$updates = $core_transient->updates;
$current = $updates[0];
if( !empty( $core ) && $current->response == \'upgrade\' ){
$skin = new Kit_Upgrader_Skin();
$upgrader = new Core_Upgrader($skin);
$result = $upgrader->upgrade($current);
if( is_wp_error( $result ) ) {
return $result;
}else{
return true;
}
}
}
但它仍然得到一些未定义的函数。
Fatal error: Call to undefined function request_filesystem_credentials() in /home4/sisir/public_html/_sites/wpkitten.com/site/wp-admin/includes/class-wp-upgrader.php on line 1113
Questions:
request_filesystem_credentials()
在文件中定义,因此I don\'t understand why its undefined.我担心的另一个问题是,我是否尝试使用cron运行该函数。这意味着访问者(注销)可能会触发升级。因为升级过程涉及文件系统进程(读/写)。Will wordpress have enough permission to do the upgrade?