summaryrefslogtreecommitdiffstats
path: root/includes/class-cepis-woo-admin.php
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 16:41:48 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 16:47:14 -0300
commit535dbda6b48171f8115b455e54790de94d97d42a (patch)
tree5c0410011e61a883bdf063ee612875a637fb1d22 /includes/class-cepis-woo-admin.php
downloadwoocommerce-0.1.0.tar.gz
Initial importv0.1.0
Diffstat (limited to 'includes/class-cepis-woo-admin.php')
-rw-r--r--includes/class-cepis-woo-admin.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/includes/class-cepis-woo-admin.php b/includes/class-cepis-woo-admin.php
new file mode 100644
index 0000000..efb1959
--- /dev/null
+++ b/includes/class-cepis-woo-admin.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Admin-side wiring.
+ *
+ * @package CepisWooCommerce
+ */
+
+declare(strict_types=1);
+
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * Puts the settings screen where a store owner will look for it, and links to
+ * it from the plugins list.
+ */
+final class Cepis_Woo_Admin {
+
+ /**
+ * Hook everything the admin needs.
+ */
+ public static function init(): void {
+ add_filter( 'woocommerce_get_settings_pages', array( self::class, 'register_settings_page' ) );
+ add_filter( 'plugin_action_links_' . plugin_basename( CEPIS_WOO_FILE ), array( self::class, 'action_links' ) );
+ }
+
+ /**
+ * Add the settings tab to WooCommerce's own settings screen.
+ *
+ * The class is required here rather than at load time because it extends
+ * `WC_Settings_Page`, which does not exist until WooCommerce has booted its
+ * admin.
+ *
+ * @param array<int, mixed> $pages Settings pages WooCommerce has collected.
+ *
+ * @return array<int, mixed>
+ */
+ public static function register_settings_page( array $pages ): array {
+ if ( ! class_exists( 'WC_Settings_Page' ) ) {
+ return $pages;
+ }
+
+ require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-settings.php';
+
+ $pages[] = new Cepis_Woo_Settings();
+
+ return $pages;
+ }
+
+ /**
+ * Add a "Settings" link to the plugin's row.
+ *
+ * @param array<int|string, string> $links Existing action links.
+ *
+ * @return array<int|string, string>
+ */
+ public static function action_links( array $links ): array {
+ if ( ! current_user_can( 'manage_woocommerce' ) ) {
+ return $links;
+ }
+
+ $url = admin_url( 'admin.php?page=wc-settings&tab=cepis' );
+
+ array_unshift(
+ $links,
+ sprintf(
+ '<a href="%s">%s</a>',
+ esc_url( $url ),
+ esc_html__( 'Settings', 'cepis-woocommerce' )
+ )
+ );
+
+ return $links;
+ }
+}