Skip to content

Commit 86c389f

Browse files
authored
Show options to bypass XML-RPC restrictions (#25223)
* Show options to bypass XML-RPC restrictions * Use `AlertView` to replace the XMLRPC disabled modal
1 parent 30945c1 commit 86c389f

5 files changed

Lines changed: 116 additions & 40 deletions

File tree

WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsTableViewModel.swift

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import WordPressShared
55
import WordPressSharedObjC
66
import WordPressUI
77
import Support
8+
import SwiftUI
89

910
private struct Section {
1011
let title: String?
@@ -507,14 +508,71 @@ private extension BlogDetailsTableViewModel {
507508
func configureXMLRPCDisabledCell(tableView: UITableView) -> UITableViewCell {
508509
guard let cell = tableView.dequeueReusableCell(
509510
withIdentifier: CellIdentifiers.xmlrpcDisabled
510-
) as? XMLRPCDisabledCell,
511-
let viewController else {
511+
) as? XMLRPCDisabledCell else {
512512
return UITableViewCell()
513513
}
514514

515-
cell.configure(with: viewController)
515+
cell.onTapped = { [weak self] in
516+
self?.presentXMLRPCDisabledAlert()
517+
}
516518
return cell
517519
}
520+
521+
private func presentXMLRPCDisabledAlert() {
522+
guard let viewController else { return }
523+
524+
let alert = AlertView {
525+
AlertHeaderView(
526+
title: XMLRPCDisabledAlertStrings.title,
527+
description: XMLRPCDisabledAlertStrings.description
528+
)
529+
} content: {
530+
Image(systemName: "exclamationmark.triangle")
531+
.font(.system(size: 50))
532+
.foregroundStyle(.orange)
533+
} actions: {
534+
Button { [weak self, weak viewController] in
535+
viewController?.dismiss(animated: true) {
536+
self?.presentJetpackConnection()
537+
}
538+
} label: {
539+
Text(XMLRPCDisabledAlertStrings.connectJetpack)
540+
.font(.headline)
541+
.frame(maxWidth: .infinity)
542+
}
543+
.buttonStyle(.borderedProminent)
544+
.controlSize(.extraLarge)
545+
546+
Button { [weak viewController] in
547+
let url = URL(string: "https://apps.wordpress.com/support/mobile/login-signup/inaccessible-xml-rpc-connection-error/")!
548+
viewController?.dismiss(animated: true) {
549+
UIApplication.shared.open(url)
550+
}
551+
} label: {
552+
Text(XMLRPCDisabledAlertStrings.learnMore)
553+
}
554+
}
555+
556+
alert.present(in: viewController)
557+
}
558+
559+
private func presentJetpackConnection() {
560+
let controller = UIViewController.jetpackConnection(blog: blog)
561+
controller.promptType = .bypassXMLRPC
562+
controller.completionBlock = { [weak controller, weak self] in
563+
controller?.dismiss(animated: true) {
564+
self?.viewController?.refresh()
565+
}
566+
}
567+
controller.navigationItem.leftBarButtonItem = UIBarButtonItem(
568+
systemItem: .close,
569+
primaryAction: UIAction { [weak controller] _ in
570+
controller?.dismiss(animated: true)
571+
}
572+
)
573+
let nav = UINavigationController(rootViewController: controller)
574+
viewController?.present(nav, animated: true)
575+
}
518576
}
519577

520578
private extension BlogDetailsTableViewModel {
@@ -1515,3 +1573,26 @@ private enum CellIdentifiers {
15151573
static let extensiveLogging = "BlogDetailsExtensiveLoggingCellIdentifier"
15161574
static let xmlrpcDisabled = "BlogDetailsXMLRPCDisabledCellIdentifier"
15171575
}
1576+
1577+
private enum XMLRPCDisabledAlertStrings {
1578+
static let title = NSLocalizedString(
1579+
"blogDetails.xmlrpcDisabled.alert.title",
1580+
value: "XML-RPC Disabled",
1581+
comment: "Title for the XML-RPC disabled alert"
1582+
)
1583+
static let description = NSLocalizedString(
1584+
"blogDetails.xmlrpcDisabled.alert.description",
1585+
value: "XML-RPC is disabled on your site. Some features in the app currently require XML-RPC. Connect Jetpack or enable XML-RPC to access all features.",
1586+
comment: "Description explaining options to restore functionality when XML-RPC is disabled"
1587+
)
1588+
static let connectJetpack = NSLocalizedString(
1589+
"blogDetails.xmlrpcDisabled.alert.connectJetpack",
1590+
value: "Connect Jetpack",
1591+
comment: "Button title to connect Jetpack in XML-RPC disabled alert"
1592+
)
1593+
static let learnMore = NSLocalizedString(
1594+
"blogDetails.xmlrpcDisabled.alert.learnMore",
1595+
value: "Learn more",
1596+
comment: "Button title to learn more about XML-RPC being disabled"
1597+
)
1598+
}

WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public class BlogDetailsViewController: UIViewController {
153153

154154
public func pulledToRefresh(with refreshControl: UIRefreshControl, onCompletion completion: (() -> Void)?) {
155155
let completionBlock = completion ?? {}
156+
checkXMLRPCStatus()
156157
updateTableView { [weak refreshControl] in
157158
DispatchQueue.main.async {
158159
refreshControl?.endRefreshing()
@@ -161,6 +162,15 @@ public class BlogDetailsViewController: UIViewController {
161162
}
162163
}
163164

165+
public func refresh() {
166+
guard let refreshControl = tableView?.refreshControl else {
167+
wpAssertionFailure("Can't get the UIRefreshControl instance")
168+
return
169+
}
170+
refreshControl.beginRefreshing()
171+
pulledToRefreshTriggered(refreshControl)
172+
}
173+
164174
private func preloadBlogData() {
165175
// only preload on wifi
166176
guard ReachabilityUtils.internetReachability?.isReachableViaWiFi() == true else {

WordPress/Classes/ViewRelated/Blog/Blog Details/XMLRPCDisabledCell.swift

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
import WordPressUI
55

66
class XMLRPCDisabledCell: UITableViewCell {
7-
private weak var presenterViewController: UIViewController?
7+
var onTapped: (() -> Void)?
88

99
private lazy var cardView: UIView = {
1010
let view = UIView()
@@ -18,7 +18,7 @@ class XMLRPCDisabledCell: UITableViewCell {
1818
view.addSubview(content)
1919
view.pinSubviewToAllEdges(content)
2020

21-
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(showAlert)))
21+
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cardTapped)))
2222
return view
2323
}()
2424

@@ -36,26 +36,8 @@ class XMLRPCDisabledCell: UITableViewCell {
3636
contentView.pinSubviewToAllEdges(cardView)
3737
}
3838

39-
func configure(with viewController: BlogDetailsViewController) {
40-
presenterViewController = viewController
41-
}
42-
43-
@objc private func showAlert() {
44-
guard let presenter = presenterViewController else {
45-
return
46-
}
47-
48-
let alert = AlertView {
49-
AlertHeaderView(title: Strings.alertTitle, description: Strings.alertMessage)
50-
} content: {
51-
Image(systemName: "exclamationmark.triangle")
52-
.font(.system(size: 50))
53-
.foregroundStyle(.orange)
54-
} actions: {
55-
AlertDismissButton()
56-
}
57-
58-
alert.present(in: presenter)
39+
@objc private func cardTapped() {
40+
onTapped?()
5941
}
6042
}
6143

@@ -96,16 +78,4 @@ private enum Strings {
9678
value: "Some features may be limited",
9779
comment: "Subtitle for the XML-RPC disabled card on blog details"
9880
)
99-
100-
static let alertTitle = NSLocalizedString(
101-
"blogDetails.xmlrpcDisabled.alert.title",
102-
value: "XML-RPC Disabled",
103-
comment: "Alert title for XML-RPC disabled"
104-
)
105-
106-
static let alertMessage = NSLocalizedString(
107-
"blogDetails.xmlrpcDisabled.alert.message",
108-
value: "XML-RPC is currently unavailable on your site. The app is transitioning to WordPress REST API, but some features still require XML-RPC. You may experience limited functionality until this transition is complete.",
109-
comment: "Alert message explaining that XML-RPC is disabled on the site and some features may be limited"
110-
)
11181
}

WordPress/Classes/ViewRelated/Jetpack/Login/JetpackLoginViewController.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ public class JetpackLoginViewController: UIViewController {
201201
properties["source"] = "stats"
202202
case .notifications:
203203
properties["source"] = "notifications"
204+
case .bypassXMLRPC:
205+
properties["source"] = "bypass_xmlrpc"
204206
}
205207

206208
if let blog {
@@ -292,10 +294,11 @@ extension JetpackLoginViewController: JetpackRemoteInstallDelegate {
292294
public enum JetpackLoginPromptType {
293295
case stats
294296
case notifications
297+
case bypassXMLRPC
295298

296299
var image: UIImage? {
297300
switch self {
298-
case .stats:
301+
case .stats, .bypassXMLRPC:
299302
return UIImage(named: "wp-illustration-stats")
300303
case .notifications:
301304
return UIImage(named: "wp-illustration-notifications")
@@ -304,7 +307,7 @@ public enum JetpackLoginPromptType {
304307

305308
var imageName: String {
306309
switch self {
307-
case .stats:
310+
case .stats, .bypassXMLRPC:
308311
return "wp-illustration-stats"
309312
case .notifications:
310313
return "wp-illustration-notifications"
@@ -319,6 +322,12 @@ public enum JetpackLoginPromptType {
319322
case .notifications:
320323
return NSLocalizedString("To get helpful notifications on your phone from your WordPress site, you'll need to install the Jetpack plugin.",
321324
comment: "Message asking the user if they want to set up Jetpack from notifications")
325+
case .bypassXMLRPC:
326+
return NSLocalizedString(
327+
"jetpack.install.allFeatures.description",
328+
value: "To unlock all app features, you'll need to install the Jetpack plugin.",
329+
comment: "Message asking the user to install Jetpack to access all app features"
330+
)
322331
}
323332
}
324333

@@ -332,6 +341,12 @@ public enum JetpackLoginPromptType {
332341
return NSLocalizedString("jetpack.install.connectUser.notifications.description",
333342
value: "To get helpful notifications on your phone from your WordPress site, you'll need to connect to your user account.",
334343
comment: "Message asking the user if they want to set up Jetpack from notifications")
344+
case .bypassXMLRPC:
345+
return NSLocalizedString(
346+
"jetpack.install.connectUser.bypassXMLRPC.description",
347+
value: "To unlock all app features, you'll need to connect the Jetpack plugin to your user account.",
348+
comment: "Message asking the user to connect Jetpack to access all app features"
349+
)
335350
}
336351
}
337352
}

WordPress/Classes/ViewRelated/Jetpack/Login/RESTAPIJetpackLoginViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private struct JetpackConnectionView: View {
9494
viewModel.connect()
9595
}
9696
.buttonStyle(.borderedProminent)
97-
.controlSize(.small)
97+
.controlSize(.regular)
9898
.padding(.bottom, 12)
9999
} else if viewModel.isCompleted {
100100
CompletedAnimationView {

0 commit comments

Comments
 (0)