Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
WP_Ajax_Upgrader_Skin example
if
(
is_wp_error
(
$api
)
)
{
if
(
str_contains
(
$api
->
get_error_message
(
)
, 'Plugin not found.'
)
)
{
$api
->
add_data
(
array
(
'status' => 404
)
)
;
}
else
{
$api
->
add_data
(
array
(
'status' => 500
)
)
;
}
return
$api
;
}
$skin
=
new
WP_Ajax_Upgrader_Skin
(
)
;
$upgrader
=
new
Plugin_Upgrader
(
$skin
)
;
$result
=
$upgrader
->
install
(
$api
->download_link
)
;
if
(
is_wp_error
(
$result
)
)
{
$result
->
add_data
(
array
(
'status' => 500
)
)
;
return
$result
;
}
// This should be the same as $result above.
array
(
'slug' =>
$slug
,
'fields' => array
(
'sections' => false
)
,
)
)
;
if
(
is_wp_error
(
$api
)
)
{
$status
[
'errorMessage'
]
=
$api
->
get_error_message
(
)
;
wp_send_json_error
(
$status
)
;
}
$skin
=
new
WP_Ajax_Upgrader_Skin
(
)
;
$upgrader
=
new
Theme_Upgrader
(
$skin
)
;
$result
=
$upgrader
->
install
(
$api
->download_link
)
;
if
(
defined
(
'WP_DEBUG'
)
&& WP_DEBUG
)
{
$status
[
'debug'
]
=
$skin
->
get_upgrade_messages
(
)
;
}
if
(
is_wp_error
(
$result
)
)
{
$status
[
'errorCode'
]
=
$result
->
get_error_code
(
)
;
$status
[
'errorMessage'
]
=
$result
->
get_error_message
(
)
;
wp_send_json_error
(
$status
)
;
}