PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.22.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.22.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Controllers / Admin / Restore / RestoreController.php
RestoreController.php
93 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Controllers\Admin\Restore;
4
5 use SureCart\Controllers\Admin\AdminController;
6
7 /**
8 * Handles restore page admin requests.
9 */
10 class RestoreController extends AdminController {
11 /**
12 * Index.
13 *
14 * @param \SureCartCore\Requests\RequestInterface $request Request.
15 */
16 public function index( \SureCartCore\Requests\RequestInterface $request ) {
17 $restore = sanitize_text_field( wp_unslash( $request->query( 'restore' ) ) );
18 if ( empty( $restore ) ) {
19 wp_die( esc_html__( 'Invalid page selected. Please choose the correct page to restore.', 'surecart' ) );
20 }
21
22 $this->withHeader(
23 array(
24 'breadcrumbs' => [
25 'restore' => [
26 'title' => __( 'Restore', 'surecart' ),
27 ],
28 ],
29 )
30 );
31
32 return \SureCart::view( 'admin/restore/index' )
33 ->with(
34 [
35 'restore' => $restore,
36 ]
37 );
38 }
39
40 /**
41 * Restore.
42 *
43 * @param \SureCartCore\Requests\RequestInterface $request Request.
44 *
45 * @return function
46 */
47 public function restore( \SureCartCore\Requests\RequestInterface $request ) {
48 $page = $request->body( 'restore' );
49
50 if ( empty( $page ) ) {
51 wp_die( esc_html__( 'Invalid page selected. Please choose the correct page to restore.', 'surecart' ) );
52 }
53
54 $page_id = \SureCart::pages()->getId( $page, 'page' );
55
56 if ( empty( $page_id ) ) {
57 wp_die( esc_html__( 'Invalid page selected. Please choose the correct page to restore.', 'surecart' ) );
58 }
59
60 $post_status = get_post_status( $page_id );
61
62 if ( ! empty( get_post_status_object( $post_status )->label ) ) {
63 $restored = wp_update_post(
64 [
65 'ID' => $page_id,
66 'post_status' => 'publish',
67 ]
68 );
69 if ( is_wp_error( $restored ) ) {
70 wp_die( esc_html__( 'Unable to restore page. Please try again.', 'surecart' ) );
71 }
72
73 return \SureCart::redirect()->to( esc_url_raw( admin_url( 'post.php?post=' . $page_id . '&action=edit' ) ) );
74 }
75
76 $restore_functions = [
77 'checkout' => 'createPages',
78 'cart' => 'createCartPost',
79 'shop' => 'createShopPage',
80 'dashboard' => 'createPages',
81 ];
82
83 try {
84 \SureCart::page_seeder()->{$restore_functions[ $page ]}();
85 } catch ( \Exception $e ) {
86 wp_die( esc_html__( 'Unable to restore page. Please try again.', 'surecart' ) );
87 }
88
89 $page_id = (int) \SureCart::pages()->getId( $page, 'page' );
90 return \SureCart::redirect()->to( esc_url_raw( admin_url( 'post.php?post=' . $page_id . '&action=edit' ) ) );
91 }
92 }
93