主题_安装程序_皮肤{}

WordPress主题安装程序的主题安装程序皮肤。

描述

另请参见

方法

姓名描述
主题安装程序皮肤::__construct建造师。
Theme_Installer_Skin::之后在单个主题安装后执行操作。
Theme_Installer_Skin::之前在安装主题之前执行操作。
主题_安装_皮肤::do_overwrite检查主题是否可以被覆盖,并输出用于在上载时覆盖主题的HTML。
Theme_Installer_Skin::hide_process_failed通过上载zip文件更新主题时隐藏“process_failed”错误。

来源

类Theme_Installer_Skin扩展了WP_Upgrader_Skin{公共$api;公共$type;公共$url;公共$overwrite;private$is_downgrading=false;/***建造师。**设置主题安装程序外观。**@自2.8.0起**@param数组$args*/公共函数__construct($args=array()){$defaults=数组(“type”=>“web”,“url”=>“”,'主题'=>'',“nonce”=>“”,“标题”=>“”,“覆盖”=>“”,);$args=wp_parse_args($args,$defaults);$this->类型=$args['type'];$this->url=$args['url'];$this->api=isset($args['api'])$args['api']:数组();$this->overwrite=$args['overwrite'];父级::__construct($args);}/***在安装主题之前执行操作。**@自2.8.0起*/public函数before(){if(!空($this->api)){$this->upgrader->strings['process_success']=sprintf($this->upgrader->strings['process_success_specific'],$this->api->名称,$this->api->版本);}}/***通过上载zip文件更新主题时隐藏“process_failed”错误。**@自5.5.0起**@param WP_Error$WP_Error WP_Error对象。*@return bool如果应该隐藏错误,则返回True,否则返回false。*/公共函数hide_process_failed($wp_error){如果(“上传”===$this->type&&“”===$this->覆盖&&$wp_error->get_error_code()===“文件夹存在”) {返回true;}返回false;}/***在单个主题安装后执行操作。**@自2.8.0起*/公共函数after(){if($this->do_overwrite()){回报;}if(空($this->upgrader->result['destination_name']){回报;}$theme_info=$this->升级程序->theme_info();if(空($theme_info)){回报;}$name=$theme_info->显示(“名称”);$stylesheet=$this->upgrader->result['destination_name'];$template=$theme_info->get_template();$activate_link=添加查询_arg(阵列(“action”=>“activate”,'template'=>urlencode($template),“样式表”=>urlencode($stylesheet),),admin_url('themes.php'));$activate_link=wp_nonce_url($activate_link,'switch-theme_'.$stylesheet);$install_actions=数组();if(currentusercan('edit_themeoptions')&&currentUsercan('customize')&&$主题信息->是块主题()){$customize_url=添加查询参数(阵列(“主题”=>urlencode($stylesheet),“return”=>urlencode(admin_url(“web”===$this->类型?“theme-install.php”:“themes.php)),),admin_url('自定义.php'));$install_actions['preview']=冲刺('<a href=“%s”class=“hide-if-no-customize load-customise”>'。“%s”,esc_url($customize_url),__(“实时预览”),/*转换器:隐藏的辅助功能文本。%s: 主题名称*/sprintf(__('实时预览&#8220;%s&#8221;'),$name));}$install_actions['activate']=sprintf('<a href=“%s”class=“activatelink”>'。“%s”,esc_url($activate_link),_x('激活','主题'),/*转换器:隐藏的辅助功能文本。%s: 主题名称*/sprintf(_x('激活&#8220;%s&#8221;','主题'),$name));if(is_network_admin()&&current_user_can('manage_network_themes')){$install_actions['network_enable']=冲刺('<a href=“%s”target=“_parent”>%s</a>',esc url(wp_nonce_url('themes.php?action=enable&amp;theme='.urlencode($stylesheet),'enable-theme_')$样式表),__(“网络启用”));}if('web'===$this->type){$install_actions['themes_page']=冲刺('<a href=“%s”target=“_parent”>%s</a>',self_admin_url('theme-install.php'),__(“转到主题安装程序”));}elseif(current_user_can(“switch_themes”)||当前用户-can(“edit_theme_options”){$install_actions['temes_page']=sprintf('<a href=“%s”target=“_parent”>%s</a>',self_admin_url('themes.php'),__('转到主题页'));}if(!$this->result||is_wp_error($this->result)||is_network_admin()||!current_user_can('切换主题'){取消设置($install_actions['activate'],$install-actions[`preview']);}elseif(get_option('template')===$stylesheet){取消设置($install_actions['activate']);}/***过滤单个主题安装后可用的操作链接列表。**@自2.8.0起**@param string[]$install_actions主题操作链接数组。*@param object$api包含WordPress.org api主题数据的对象。*@param string$stylesheet主题目录名。*@param WP_Theme$Theme_info主题对象。*/$install_actions=apply_filters('install_theme_complete_actions',$install_actions,$this->api,$stylesheet,$theme_info);if(!空($install_actions)){$this->反馈(内爆('|',(数组)$install_actions));}}/***检查主题是否可以被覆盖,并输出用于在上载时覆盖主题的HTML。**@自5.5.0起**@return bool是否可以覆盖主题并输出HTML。*/私有函数do_overwrite(){if('upload'!==$this->type||!iswp_error($this->结果)||'folder_exists'!==$此->结果->获取错误代码()){返回false;}$folder=$this->result->get_error_data('folder_exists');$folder=rtrim($folder,'/');$current_theme_data=false;$all_themes=wp_get_themes(数组('errors'=>null));foreach($all_themes作为$theme){$stylesheet_dir=wp_normalize_path($theme->get_stylesheet_directory());if(rtrim($stylesheet_dir,'/')!==$文件夹){继续;}$current_theme_data=$theme;}$new_theme_data=$this->upgrader->new_themes_data;if(!$current_theme_data||!$new_theme-data){返回false;}echo'<h2 class=“update-from-upload-heading”>'。esc_html__('此主题已安装。')。'</h2>';//检查活动主题的错误。if(is_wp_error($current_theme_data->errors())){$this->反馈('current_theme_has_errors',$current_theme_data->errors()->get_error_message());}$this->is_downgrading=version_compare($current_theme_data['version'],$new_theme_data['version'],'>');$is_invalid_parent=假;if(!empty($new_theme_data['Template'])){$is_invalid_parent=!in_array($new_theme_data['Template'],array_keys($all_themes),true);}$rows=数组(“名称”=>__(“主题名称”),“版本”=>__(“版本”),“作者”=>__(“作者”),“RequiresWP”=>__(“所需WordPress版本”),“RequiresPHP”=>__(“所需PHP版本”),“模板”=>__(“父主题”),);$table='<table class=“update-from-upload-comparison”><tbody>';$table.='<tr><th></th><th>’。esc_html_x(“活动”,“主题”)。”</th><th>’。esc_html_x('上传','主题')。'</th></tr>';$is_same_theme=true;//让我们只考虑这些行。foreach($rows作为$field=>$label){$old_value=$current_theme_data->display($field,false);$old_value=$old_value?(字符串)$old_value:“-”;$new_value=!空($new_theme_data[$field])?(字符串)$new_theme_data[$field]:'-';if($old_value===$new_value&&‘-’====$新值&&‘模板’===$字段){继续;}$is_same_theme=$is_same_theme&&($old_value==$new_value);$diff_field=('版本'!==$field&&$new_value!==$旧值);$diff_version=(“版本”===$field&&$this->is_downgrading);$invalid_parent=false;if(“模板”===$field&&$is_invalid_parent){$invalid_parent=true;$new_value.=“”__(“(未找到)”);}$table.='<tr><td class=“name-label”>'$标签。'</td><td>'。wp_strip_all_tags($old_value)。'</td>';$表.=($diff字段||$diff版本||$invalid_parent)?'<td class=“warning”>':'<td>';$表.=wp_strip_all_tags($new_value)。”</td></tr>';}$table.='</tbody></table>';/***过滤比较表输出,以便在上载时覆盖主题包。**@自5.5.0起**@param string$table带有Name、Version、Author、RequiresWP和RequiresPHP info的输出表。*@param WP_Theme$current_Theme_data激活主题数据。*@param array$new_theme_data已上载主题数据的数组。*/echo apply_filters(“安装主题覆盖比较”,$table,$current_theme_data,$new_theme-data);$install_actions=数组();$can_update=true;$blocked_message=“<p>”。esc_html__('由于以下原因无法更新主题:')。'</p> ';$blocked_message.='<ul class=“ul-disc”>';$requires_php=isset($new_theme_data['RequiresPHP'])$new_theme_data['RequiresPHP']:空;$requires_wp=isset($new_theme_data['RequiresWP'])$new_theme_data['RequiresWP']:空;if(!is_php_version_compatible($requires_php)){$error=冲刺(/*翻译:1:当前PHP版本,2:上传主题所需的版本*/__('您服务器上的PHP版本是%1$s,但上传的主题需要%2$s。'),PHP_版本,$要求_php);$blocked_message.='<li>’。esc_html($error)。'</li>';$can_update=false;}如果(!iswpversioncompatible($requireswp)){$error=冲刺(/*翻译:1:当前WordPress版本,2:上传主题所需的版本*/__('您的WordPress版本是%1$s,但上传的主题需要%2$s。'),get_bloginfo(“版本”),$requires_wp);$blocked_message.='<li>’。esc_html($error)。'</li>';$can_update=false;}$blocked_message.='</ul>';if($can_update){if($this->is_downgrading){$warning=冲刺(/*转换器:%s:文档URL*/__('您正在上传活动主题的旧版本。您可以继续安装旧版本,但请务必首先备份数据库和文件。'),__( 'https://developer.wordpress.org/advanced-administration/security/backup/' ));}其他{$warning=冲刺(/*转换器:%s:文档URL*/__('您正在更新主题。请确保先备份数据库和文件</a>。'),__( 'https://developer.wordpress.org/advanced-administration/security/backup/' ));}echo'<p class=“update-from-upload-notice”>'$警告。”</p> ';$overwrite=$this->is_downgrading?'降级主题':'更新主题';$install_actions['overwrite_theme']=冲刺('<a class=“button button-primary update-from-upload-overwrite”href=“%s”target=“_parent”>%s</a>',wp_nonce_url(add_query_arg(“覆盖”,$overwrite,$this->url),“主题上传”),_x('用上传内容替换活动内容','主题'));}其他{echo$blocked_message;}$cancel_url=add_query_arg('action','upload-theme-cancel-overwrite',$this->url);$install_actions['themes_page']=冲刺('<a class=“button”href=“%s”target=“_parent”>%s</a>',wp_nonce_url($cancel_url,'theme-upload-cancel-overwrite'),__(“取消并返回”));/***筛选单个主题安装失败后可用的操作链接列表*当允许覆盖时。**@自5.5.0起**@param string[]$install_actions主题操作链接数组。*@param object$api包含WordPress.org api主题数据的对象。*@param array$new_theme_data已上载主题数据的数组。*/$install_actions=apply_filters('install_theme_overwrite_actions',$install_actions,$this->api,$new_theme_data);if(!空($install_actions)){打印('<p class=“update-from-upload-expired hidden”>%s</p>',__('上传的文件已过期。请返回并再次上传。'));echo'<p class=“update-from-upload-actions”>'。内爆(“”,(数组)$install_actions)</p> ';}返回true;}}

变更日志

版本描述
4.6.0已从wp-admin/includes/class-wp-upgrader-skins.php移至其自己的文件。
2.8.0介绍。

用户贡献的笔记

你必须登录在能够贡献笔记或反馈之前。