Skip to content

Commit 5d16d7a

Browse files
authored
Merge pull request #27 from soderlind/feature/use-vmf-addon-base
Feature/use vmf addon base
2 parents 65b2c62 + 06ec648 commit 5d16d7a

6 files changed

Lines changed: 117 additions & 249 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.8.0] - 2026-03-14
9+
10+
### Changed
11+
12+
- Refactored Plugin class to extend `VirtualMediaFolders\Addon\AbstractPlugin` base class
13+
- Refactored SettingsTab to extend `AbstractSettingsTab`, removed inline enqueue and WP 7 compat logic
14+
- Removed duplicated singleton boilerplate and manual textdomain loading
15+
816
## [1.7.0] - 2026-03-10
917

1018
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vmfa-editorial-workflow",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "Role-based folder access, move restrictions, and Inbox workflow for Virtual Media Folders.",
55
"author": "Per Soderlind",
66
"license": "GPL-2.0-or-later",

readme.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: media, folders, workflow, editorial, permissions
44
Requires at least: 6.8
55
Tested up to: 7.0
66
Requires PHP: 8.3
7-
Stable tag: 1.7.0
7+
Stable tag: 1.8.0
88
License: GPL-2.0-or-later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -95,6 +95,11 @@ Existing media is not affected. The workflow only applies to new uploads and exp
9595

9696
== Changelog ==
9797

98+
= 1.8.0 =
99+
* Changed: Refactored Plugin class to extend VMF core `AbstractPlugin` base class
100+
* Changed: Refactored SettingsTab to extend `AbstractSettingsTab`
101+
* Changed: Removed duplicated singleton boilerplate and manual textdomain loading
102+
98103
= 1.7.0 =
99104
* Added: WP 7.0+ design-token style overrides for settings and review pages
100105

src/php/Admin/SettingsTab.php

Lines changed: 72 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -11,143 +11,96 @@
1111

1212
namespace VmfaEditorialWorkflow\Admin;
1313

14-
// Prevent direct access.
1514
defined( 'ABSPATH' ) || exit;
1615

16+
use VirtualMediaFolders\Addon\AbstractSettingsTab;
17+
1718
/**
1819
* Settings Tab class.
1920
*
2021
* Adds a settings tab to VMF settings page.
2122
*/
22-
class SettingsTab {
23-
24-
/**
25-
* Tab ID.
26-
*
27-
* @var string
28-
*/
29-
public const TAB_ID = 'editorial-workflow';
23+
class SettingsTab extends AbstractSettingsTab {
3024

31-
/**
32-
* Constructor.
33-
*/
34-
public function __construct() {
35-
$this->init_hooks();
25+
/** @inheritDoc */
26+
protected function get_tab_slug(): string {
27+
return 'editorial-workflow';
3628
}
3729

38-
/**
39-
* Initialize hooks.
40-
*
41-
* @return void
42-
*/
43-
private function init_hooks(): void {
44-
// Register tab with VMF settings.
45-
add_filter( 'vmfo_settings_tabs', [ $this, 'register_tab' ] );
46-
47-
// Enqueue settings assets.
48-
add_action( 'vmfo_settings_enqueue_scripts', [ $this, 'enqueue_assets' ], 10, 2 );
30+
/** @inheritDoc */
31+
protected function get_tab_label(): string {
32+
return __( 'Editorial Workflow', 'vmfa-editorial-workflow' );
4933
}
5034

51-
/**
52-
* Register settings tab.
53-
*
54-
* @param array $tabs Existing tabs.
55-
* @return array Modified tabs.
56-
*/
57-
public function register_tab( array $tabs ): array {
58-
$tabs[ self::TAB_ID ] = [
59-
'title' => __( 'Editorial Workflow', 'vmfa-editorial-workflow' ),
60-
'callback' => [ $this, 'render_tab' ],
61-
];
62-
63-
return $tabs;
35+
/** @inheritDoc */
36+
protected function get_text_domain(): string {
37+
return 'vmfa-editorial-workflow';
6438
}
6539

66-
/**
67-
* Enqueue assets for settings tab.
68-
*
69-
* @param string $active_tab Currently active tab.
70-
* @param string $active_subtab Currently active subtab.
71-
* @return void
72-
*/
73-
public function enqueue_assets( string $active_tab, string $active_subtab ): void {
74-
if ( self::TAB_ID !== $active_tab ) {
75-
return;
76-
}
40+
/** @inheritDoc */
41+
protected function get_build_path(): string {
42+
return VMFA_EDITORIAL_WORKFLOW_PATH . 'build/';
43+
}
7744

78-
$asset_file = VMFA_EDITORIAL_WORKFLOW_PATH . 'build/settings.asset.php';
79-
$asset = file_exists( $asset_file ) ? require $asset_file : [
80-
'dependencies' => [ 'wp-element', 'wp-components', 'wp-api-fetch', 'wp-i18n' ],
81-
'version' => VMFA_EDITORIAL_WORKFLOW_VERSION,
82-
];
45+
/** @inheritDoc */
46+
protected function get_build_url(): string {
47+
return VMFA_EDITORIAL_WORKFLOW_URL . 'build/';
48+
}
8349

84-
wp_enqueue_style(
85-
'vmfa-editorial-workflow-settings',
86-
VMFA_EDITORIAL_WORKFLOW_URL . 'build/settings.css',
87-
[ 'wp-components' ],
88-
$asset[ 'version' ]
89-
);
50+
/** @inheritDoc */
51+
protected function get_languages_path(): string {
52+
return VMFA_EDITORIAL_WORKFLOW_PATH . 'languages';
53+
}
9054

91-
wp_enqueue_script(
92-
'vmfa-editorial-workflow-settings',
93-
VMFA_EDITORIAL_WORKFLOW_URL . 'build/settings.js',
94-
$asset[ 'dependencies' ],
95-
$asset[ 'version' ],
96-
true
97-
);
55+
/** @inheritDoc */
56+
protected function get_plugin_version(): string {
57+
return VMFA_EDITORIAL_WORKFLOW_VERSION;
58+
}
9859

99-
wp_set_script_translations(
100-
'vmfa-editorial-workflow-settings',
101-
'vmfa-editorial-workflow',
102-
VMFA_EDITORIAL_WORKFLOW_PATH . 'languages'
103-
);
60+
/** @inheritDoc */
61+
protected function get_localized_name(): string {
62+
return 'vmfaSettings';
63+
}
10464

105-
// WP 7+ design-token overrides.
106-
if ( function_exists( 'vmfo_is_wp7' ) && vmfo_is_wp7() ) {
107-
$wp7_asset_file = VMFA_EDITORIAL_WORKFLOW_PATH . 'build/wp7-compat.asset.php';
108-
$wp7_version = file_exists( $wp7_asset_file )
109-
? ( include $wp7_asset_file )['version'] ?? VMFA_EDITORIAL_WORKFLOW_VERSION
110-
: VMFA_EDITORIAL_WORKFLOW_VERSION;
65+
/** @inheritDoc */
66+
protected function get_asset_entry(): string {
67+
return 'settings';
68+
}
11169

112-
wp_enqueue_style(
113-
'vmfa-editorial-workflow-wp7',
114-
VMFA_EDITORIAL_WORKFLOW_URL . 'build/wp7-compat.css',
115-
[ 'vmfa-editorial-workflow-settings', 'wp-base-styles' ],
116-
$wp7_version
117-
);
118-
}
70+
/** @inheritDoc */
71+
protected function get_app_container_id(): string {
72+
return 'vmfa-settings-root';
73+
}
11974

120-
wp_localize_script(
121-
'vmfa-editorial-workflow-settings',
122-
'vmfaSettings',
123-
[
124-
'restUrl' => rest_url( 'vmfa-editorial/v1' ),
125-
'nonce' => wp_create_nonce( 'wp_rest' ),
126-
'roles' => $this->get_editable_roles(),
127-
'folders' => $this->get_folders(),
128-
'actions' => $this->get_actions(),
129-
'i18n' => [
130-
'title' => __( 'Editorial Workflow Settings', 'vmfa-editorial-workflow' ),
131-
'permissions' => __( 'Folder Permissions', 'vmfa-editorial-workflow' ),
132-
'permissionsDesc' => __( 'Configure which roles can access each folder.', 'vmfa-editorial-workflow' ),
133-
'inbox' => __( 'Inbox Mapping', 'vmfa-editorial-workflow' ),
134-
'inboxDesc' => __( 'Set the default upload folder for each role.', 'vmfa-editorial-workflow' ),
135-
'workflow' => __( 'Workflow Settings', 'vmfa-editorial-workflow' ),
136-
'workflowDesc' => __( 'Configure workflow states and behavior.', 'vmfa-editorial-workflow' ),
137-
'enableWorkflow' => __( 'Enable workflow folders', 'vmfa-editorial-workflow' ),
138-
'save' => __( 'Save Changes', 'vmfa-editorial-workflow' ),
139-
'saving' => __( 'Saving…', 'vmfa-editorial-workflow' ),
140-
'saved' => __( 'Settings saved.', 'vmfa-editorial-workflow' ),
141-
'error' => __( 'Error saving settings.', 'vmfa-editorial-workflow' ),
142-
'selectFolder' => __( 'Select folder…', 'vmfa-editorial-workflow' ),
143-
'noInbox' => __( 'No inbox (use default)', 'vmfa-editorial-workflow' ),
144-
'view' => __( 'View', 'vmfa-editorial-workflow' ),
145-
'move' => __( 'Move to', 'vmfa-editorial-workflow' ),
146-
'upload' => __( 'Upload to', 'vmfa-editorial-workflow' ),
147-
'delete' => __( 'Delete', 'vmfa-editorial-workflow' ),
148-
],
149-
]
150-
);
75+
/** @inheritDoc */
76+
protected function get_localized_data(): array {
77+
return [
78+
'restUrl' => rest_url( 'vmfa-editorial/v1' ),
79+
'nonce' => wp_create_nonce( 'wp_rest' ),
80+
'roles' => $this->get_editable_roles(),
81+
'folders' => $this->get_folders(),
82+
'actions' => $this->get_actions(),
83+
'i18n' => [
84+
'title' => __( 'Editorial Workflow Settings', 'vmfa-editorial-workflow' ),
85+
'permissions' => __( 'Folder Permissions', 'vmfa-editorial-workflow' ),
86+
'permissionsDesc' => __( 'Configure which roles can access each folder.', 'vmfa-editorial-workflow' ),
87+
'inbox' => __( 'Inbox Mapping', 'vmfa-editorial-workflow' ),
88+
'inboxDesc' => __( 'Set the default upload folder for each role.', 'vmfa-editorial-workflow' ),
89+
'workflow' => __( 'Workflow Settings', 'vmfa-editorial-workflow' ),
90+
'workflowDesc' => __( 'Configure workflow states and behavior.', 'vmfa-editorial-workflow' ),
91+
'enableWorkflow' => __( 'Enable workflow folders', 'vmfa-editorial-workflow' ),
92+
'save' => __( 'Save Changes', 'vmfa-editorial-workflow' ),
93+
'saving' => __( 'Saving…', 'vmfa-editorial-workflow' ),
94+
'saved' => __( 'Settings saved.', 'vmfa-editorial-workflow' ),
95+
'error' => __( 'Error saving settings.', 'vmfa-editorial-workflow' ),
96+
'selectFolder' => __( 'Select folder…', 'vmfa-editorial-workflow' ),
97+
'noInbox' => __( 'No inbox (use default)', 'vmfa-editorial-workflow' ),
98+
'view' => __( 'View', 'vmfa-editorial-workflow' ),
99+
'move' => __( 'Move to', 'vmfa-editorial-workflow' ),
100+
'upload' => __( 'Upload to', 'vmfa-editorial-workflow' ),
101+
'delete' => __( 'Delete', 'vmfa-editorial-workflow' ),
102+
],
103+
];
151104
}
152105

153106
/**
@@ -159,7 +112,7 @@ public function enqueue_assets( string $active_tab, string $active_subtab ): voi
159112
*/
160113
public function render_tab( string $active_tab, string $active_subtab ): void {
161114
?>
162-
<div id="vmfa-settings-root">
115+
<div id="<?php echo esc_attr( $this->get_app_container_id() ); ?>">
163116
<p class="description">
164117
<?php esc_html_e( 'Loading settings…', 'vmfa-editorial-workflow' ); ?>
165118
</p>
@@ -177,19 +130,17 @@ private function get_editable_roles(): array {
177130
$wp_roles = wp_roles();
178131

179132
foreach ( $wp_roles->roles as $role_key => $role_data ) {
180-
// Skip administrator - they always have full access.
181133
if ( 'administrator' === $role_key ) {
182134
continue;
183135
}
184136

185-
// Only include roles that can upload files.
186-
if ( ! isset( $role_data[ 'capabilities' ][ 'upload_files' ] ) || ! $role_data[ 'capabilities' ][ 'upload_files' ] ) {
137+
if ( ! isset( $role_data['capabilities']['upload_files'] ) || ! $role_data['capabilities']['upload_files'] ) {
187138
continue;
188139
}
189140

190141
$roles[] = [
191142
'key' => $role_key,
192-
'name' => translate_user_role( $role_data[ 'name' ] ),
143+
'name' => translate_user_role( $role_data['name'] ),
193144
];
194145
}
195146

0 commit comments

Comments
 (0)