get_sql_website_by_id( $current_wpid );
$websites = MainWP_DB::instance()->query( $sql );
$allThemes = array();
if ( $websites ) {
$website = MainWP_DB::fetch_object( $websites );
if ( $website && '' !== $website->themes ) {
$themes = json_decode( $website->themes, 1 );
if ( is_array( $themes ) && ! empty( $themes ) ) {
foreach ( $themes as $theme ) {
$allThemes[] = $theme;
}
}
}
MainWP_DB::free_result( $websites );
}
static::render_html_widget( $website, $allThemes );
}
/**
*
* Method render_html_widget().
*
* Render html themes widget for current site.
*
* @param object $website Object containing the child site info.
* @param array $allThemes Array containing all detected themes data.
*
* @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having()
* @uses \MainWP\Dashboard\MainWP_Utility::sortmulti()
*/
public static function render_html_widget( $website, $allThemes ) { // phpcs:ignore -- NOSONAR - complex.
$is_demo = MainWP_Demo_Handle::is_demo_mode();
$actived_themes = MainWP_Utility::get_sub_array_having( $allThemes, 'active', 1 );
$actived_themes = MainWP_Utility::sortmulti( $actived_themes, 'name', 'asc' );
$inactive_themes = MainWP_Utility::get_sub_array_having( $allThemes, 'active', 0 );
$inactive_themes = MainWP_Utility::sortmulti( $inactive_themes, 'name', 'asc' );
?>
esc_html__( 'Theme has been activated!', 'mainwp' ) ) ) );
}
/**
* Method delete_theme()
*
* Fire off action deactivate & display result
*/
public static function delete_theme() {
static::action( 'delete' );
die( wp_json_encode( array( 'result' => esc_html__( 'Theme has been permanently deleted!', 'mainwp' ) ) ) );
}
/**
* Method action()
*
* Initiate try catch for chosen Action.
*
* @param mixed $action Theme Action.
*
* @throws \MainWP_Exception Error message.
*
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
* @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
* @uses \MainWP\Dashboard\MainWP_Exception
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
* @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
*/
public static function action( $action ) {
$theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( empty( $theme ) || empty( $websiteId ) ) {
die( wp_json_encode( array( 'error' => esc_html__( 'Theme or site ID not found. Please, reload the page and try again.', 'mainwp' ) ) ) );
}
$website = MainWP_DB::instance()->get_website_by_id( $websiteId );
if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
die( wp_json_encode( array( 'error' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) );
}
if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
die(
wp_json_encode(
array(
'error' => esc_html__( 'Suspended site.', 'mainwp' ),
'errorCode' => 'SUSPENDED_SITE',
)
)
);
}
/**
* Action: mainwp_before_theme_action
*
* Fires before theme activate/delete actions.
*
* @since 4.1
*/
do_action( 'mainwp_before_theme_action', $action, $theme, $website );
try {
$information = MainWP_Connect::fetch_url_authed(
$website,
'theme_action',
array(
'action' => $action,
'theme' => $theme,
)
);
} catch ( MainWP_Exception $e ) {
die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) );
}
/**
* Action: mainwp_after_theme_action
*
* Fires after theme activate/delete actions.
*
* @since 4.1
*/
do_action( 'mainwp_after_theme_action', $information, $action, $theme, $website );
if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) {
die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) );
}
}
}