PluginProbe
seQura / trunk
seQura vtrunk
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / src / Controllers / Hooks / Settings / class-settings-controller.php

class-settings-controller.php in seQura trunk, at src/Controllers/Hooks/Settings/class-settings-controller.php

180 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Implementation for the settings controller.
4 *
5 * @package SeQura/WC
6 * @subpackage SeQura/WC/Controllers
7 */
8
9 namespace SeQura\WC\Controllers\Hooks\Settings;
10
11 use SeQura\WC\Controllers\Controller;
12 use SeQura\WC\Services\Log\Interface_Logger_Service;
13 use SeQura\WC\Services\Service\Interface_Settings_Service;
14
15 /**
16 * Implementation for the settings controller.
17 */
18 class Settings_Controller extends Controller implements Interface_Settings_Controller {
19
20 /**
21 * Settings service.
22 *
23 * @var Interface_Settings_Service
24 */
25 private $settings_service;
26
27 /**
28 * Plugin basename.
29 */
30 private $plugin_basename;
31
32 /**
33 * Constructor.
34 */
35 public function __construct(
36 string $templates_path,
37 Interface_Settings_Service $settings_service,
38 Interface_Logger_Service $logger,
39 string $plugin_basename
40 ) {
41 parent::__construct( $logger, $templates_path );
42 $this->settings_service = $settings_service;
43 $this->plugin_basename = $plugin_basename;
44 }
45
46 /**
47 * Register the settings page.
48 *
49 * @return void
50 */
51 public function register_page() {
52 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
53 \add_submenu_page(
54 $this->settings_service->get_parent_page(),
55 __( 'seQura', 'sequra' ),
56 __( 'seQura', 'sequra' ),
57 'manage_options',
58 $this->settings_service->get_page(),
59 array( $this, 'render_page' )
60 );
61
62 // Additionally remove WP version footer text if we are in the settings page.
63 if ( $this->settings_service->is_settings_page() ) {
64 \remove_filter( 'update_footer', 'core_update_footer' );
65 }
66 }
67
68 /**
69 * Render the settings page.
70 *
71 * @return void
72 */
73 public function render_page() {
74 $this->logger->log_debug( 'Callback executed', __FUNCTION__, __CLASS__ );
75 \wc_get_template( 'admin/settings_page.php', array(), '', $this->templates_path );
76 }
77
78 /**
79 * Get the settings page URL.
80 *
81 * @param string|null $url The URL.
82 * @return string
83 */
84 public function get_settings_page_url( $url = null ) {
85 return \admin_url( 'admin.php?page=' . $this->settings_service->get_page() );
86 }
87
88 /**
89 * Add action links to the plugin settings page.
90 *
91 * @param string[] $actions The actions.
92 * @param string $plugin_file The plugin file.
93 * @param string $plugin_data The plugin data.
94 * @param string $context The context.
95 * @return string[]
96 */
97 public function add_action_link( $actions, $plugin_file, $plugin_data, $context ) {
98 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
99 $args = array(
100 'href' => $this->get_settings_page_url(),
101 'text' => esc_attr__( 'Settings', 'sequra' ),
102 );
103 ob_start();
104 \wc_get_template( 'admin/action_link.php', $args, '', $this->templates_path );
105 $actions['settings'] = ob_get_clean();
106 return $actions;
107 }
108
109 /**
110 * Removes the WP footer message
111 *
112 * @param string $text The footer text.
113 * @return string
114 */
115 public function remove_footer_admin( $text ) {
116 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
117 if ( ! $this->settings_service->is_settings_page() ) {
118 return $text;
119 }
120 return '';
121 }
122
123 /**
124 * Show row meta on the plugin screen.
125 *
126 * @param array $links Plugin Row Meta.
127 * @param string $file Plugin Base file.
128 * @return string[]
129 */
130 public function add_plugin_row_meta( $links, $file ) {
131 if ( $this->plugin_basename === $file ) {
132 $row_meta = array(
133 'docs' => sprintf(
134 '<a href="%s" aria-label="%s" target="_blank">%s</a>',
135 \esc_url(
136 /**
137 * Filters the URL of the plugin documentation.
138 *
139 * @since 2.0.0
140 */
141 \apply_filters( 'sequrapayment_docs_url', 'https://sequra.atlassian.net/wiki/spaces/DOC/pages/2247524378/WOOCOMMERCE' )
142 ),
143 esc_attr__( 'View WooCommerce documentation', 'sequra' ),
144 esc_html__( 'Docs', 'woocommerce' )
145 ),
146 'apidocs' => sprintf(
147 '<a href="%s" aria-label="%s" target="_blank">%s</a>',
148 \esc_url(
149 /**
150 * Filters the URL of the plugin API documentation.
151 *
152 * @since 2.0.0
153 */
154 \apply_filters( 'sequrapayment_apidocs_url', 'https://docs.sequrapi.com/' )
155 ),
156 esc_attr__( 'View WooCommerce API docs', 'sequra' ),
157 esc_html__( 'API docs', 'sequra' )
158 ),
159 'support' => sprintf(
160 '<a href="%s" aria-label="%s" target="_blank">%s</a>',
161 \esc_url(
162 /**
163 * Filters the URL of the plugin support.
164 *
165 * @since 2.0.0
166 */
167 \apply_filters( 'sequrapayment_support_url', 'https://sequra.atlassian.net/servicedesk/customer/portal/5/group/-1' )
168 ),
169 esc_attr__( 'Support', 'sequra' ),
170 esc_html__( 'Support', 'sequra' )
171 ),
172 );
173
174 return array_merge( $links, $row_meta );
175 }
176
177 return (array) $links;
178 }
179 }
180