PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.1.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.1.3
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 / packages / blocks / Controllers / BaseController.php
BaseController.php
82 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace SureCartBlocks\Controllers;
3
4 use SureCart\Models\User;
5
6 /**
7 * Base controller for dashboard pages.
8 */
9 abstract class BaseController {
10 /**
11 * Get a query param.
12 *
13 * @param string $name The query param name.
14 * @param mixed $fallback The fallback value.
15 *
16 * @return string|false
17 */
18 protected function getParam( $name, $fallback = false ) {
19 return isset( $_GET[ $name ] ) ? sanitize_text_field( wp_unslash( $_GET[ $name ] ) ) : $fallback;
20 }
21 /**
22 * Get the current tab.
23 *
24 * @return string|false
25 */
26 protected function getTab() {
27 return $this->getParam( 'tab' );
28 }
29
30 /**
31 * Get the current page.
32 *
33 * @return integer
34 */
35 protected function getPage() {
36 return $this->getParam( 'page', 1 );
37 }
38
39 /**
40 * Get the current id.
41 *
42 * @return integer|false
43 */
44 protected function getId() {
45 return $this->getParam( 'id' );
46 }
47
48 /**
49 * Get the users customer ids.
50 *
51 * @return array
52 */
53 protected function customerIds() {
54 return array_values( (array) User::current()->customerIds() );
55 }
56
57 /**
58 * Render not found view.
59 *
60 * @return string
61 */
62 protected function notFound() {
63 return '<sc-alert type="danger" open>' . esc_html__( 'Not found.', 'surecart' ) . '</sc-alert>';
64 }
65
66 /**
67 * Render not found view.
68 *
69 * @return string
70 */
71 protected function noAccess() {
72 return '<sc-alert type="danger" open>' . esc_html__( 'You do not have permission to do this.', 'surecart' ) . '</sc-alert>';
73 }
74
75 protected function isLiveMode() {
76 if ( 'false' === sanitize_text_field( wp_unslash( $_GET['live_mode'] ?? '' ) ) ) {
77 return false;
78 }
79 return true;
80 }
81 }
82