Skip to content

Commit bbcccc2

Browse files
authored
Merge pull request #447 from beyondwords-io/s-7154-use-static-methods-throughout-to-simplify-magic-embed
Use static methods throughout to simplify Magic Embed support
2 parents d5a1878 + 2a8d5d9 commit bbcccc2

File tree

90 files changed

+1233
-1135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1233
-1135
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "beyondwords-wordpress-plugin",
3-
"version": "5.5.0",
3+
"version": "6.0.0",
44
"private": true,
55
"description": "BeyondWords WordPress Plugin",
66
"repository": {

readme.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Contributors: beyondwords, stuartmcalpine
44
Donate link: https://beyondwords.io
55
Tags: text-to-speech, tts, audio, AI, voice cloning
6-
Stable tag: 5.5.0
6+
Stable tag: 6.0.0
77
Requires PHP: 8.0
88
Tested up to: 6.8
99
License: GPLv2 or later
@@ -80,6 +80,14 @@ Any questions? [Visit our website](https://beyondwords.io/?utm_source=wordpress&
8080

8181
== Changelog ==
8282

83+
= 6.0.0 =
84+
85+
Release date: TBC
86+
87+
**Enhancements and Features:**
88+
89+
* Make PHP methods static.
90+
8391
= 5.5.0 =
8492

8593
Release date: 2nd July 2025

speechkit.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Description: The effortless way to make content listenable. Automatically create audio versions and embed via our customizable player.
1616
* Author: BeyondWords
1717
* Author URI: https://beyondwords.io
18-
* Version: 5.5.0
18+
* Version: 6.0.0
1919
* License: GPL-2.0+
2020
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
2121
* Text Domain: speechkit
@@ -35,11 +35,10 @@
3535

3636
// Define constants
3737
// phpcs:disable
38-
define('BEYONDWORDS__PLUGIN_VERSION', '5.5.0');
38+
define('BEYONDWORDS__PLUGIN_VERSION', '6.0.0');
3939
define('BEYONDWORDS__PLUGIN_DIR', plugin_dir_path(__FILE__));
4040
define('BEYONDWORDS__PLUGIN_URI', plugin_dir_url(__FILE__));
4141
// phpcs:enable
4242

4343
// Follow WordPress convention by using snakecase for variable name
44-
$beyondwords_wordpress_plugin = new Beyondwords\Wordpress\Plugin();
45-
$beyondwords_wordpress_plugin->init();
44+
Beyondwords\Wordpress\Plugin::init();

src/Compatibility/WPGraphQL/WPGraphQL.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ class WPGraphQL
2020
* Init.
2121
*
2222
* @since 3.6.0
23+
* @since 6.0.0 Make static.
2324
*/
24-
public function init()
25+
public static function init()
2526
{
2627
// Actions for WPGraphQL
27-
add_action('graphql_register_types', array($this, 'graphqlRegisterTypes'));
28+
add_action('graphql_register_types', array(__CLASS__, 'graphqlRegisterTypes'));
2829
}
2930

3031
/**
@@ -33,8 +34,9 @@ public function init()
3334
* @since 3.6.0
3435
* @since 4.0.0 Register contentId field, and contentId/podcastId are now String, not Int
3536
* @since 4.7.0 Moved graphqlRegisterTypes() from Beyondwords\Wordpress\Core to here.
37+
* @since 6.0.0 Make static.
3638
*/
37-
public function graphqlRegisterTypes()
39+
public static function graphqlRegisterTypes()
3840
{
3941
register_graphql_object_type('Beyondwords', [
4042
'description' => __('BeyondWords audio details. Use this data to embed an audio player using the BeyondWords JavaScript SDK.', 'speechkit'), // phpcs:ignore Generic.Files.LineLength.TooLong

src/Component/Post/AddPlayer/AddPlayer.php

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,42 @@ class AddPlayer
2828
* Init.
2929
*
3030
* @since 4.0.0
31+
* @since 6.0.0 Make static.
3132
*/
32-
public function init()
33+
public static function init()
3334
{
34-
add_action('init', array($this, 'registerBlock'));
35-
add_action('enqueue_block_editor_assets', array($this, 'addBlockEditorStylesheet'));
35+
add_action('init', array(__CLASS__, 'registerBlock'));
36+
add_action('enqueue_block_editor_assets', array(__CLASS__, 'addBlockEditorStylesheet'));
3637

37-
add_action('admin_head', array($this, 'addEditorStyles'));
38-
add_filter('tiny_mce_before_init', array($this, 'filterTinyMceSettings'));
38+
add_action('admin_head', array(__CLASS__, 'addEditorStyles'));
39+
add_filter('tiny_mce_before_init', array(__CLASS__, 'filterTinyMceSettings'));
3940

40-
add_filter('mce_external_plugins', array($this, 'addPlugin'));
41-
add_filter('mce_buttons', array($this, 'addButton'));
42-
add_filter('mce_css', array($this, 'addStylesheet'));
41+
add_filter('mce_external_plugins', array(__CLASS__, 'addPlugin'));
42+
add_filter('mce_buttons', array(__CLASS__, 'addButton'));
43+
add_filter('mce_css', array(__CLASS__, 'addStylesheet'));
4344
}
4445

4546
/**
4647
* Register Block.
48+
*
49+
* @since 3.2.0
50+
* @since 6.0.0 Make static.
4751
*/
48-
public function registerBlock()
52+
public static function registerBlock()
4953
{
5054
\register_block_type(__DIR__);
5155
}
5256

5357
/**
5458
* Add TinyMCE buttons.
5559
*
60+
* @since 6.0.0 Make static.
61+
*
5662
* @param array TinyMCE plugin array
63+
*
64+
* @return array
5765
*/
58-
public function addPlugin($plugin_array)
66+
public static function addPlugin($plugin_array)
5967
{
6068
$plugin_array['beyondwords_player'] = BEYONDWORDS__PLUGIN_URI . 'src/Component/Post/AddPlayer/tinymce.js';
6169
return $plugin_array;
@@ -64,9 +72,13 @@ public function addPlugin($plugin_array)
6472
/**
6573
* Register TinyMCE buttons.
6674
*
75+
* @since 6.0.0 Make static.
76+
*
6777
* @param array TinyMCE buttons array
78+
*
79+
* @return array
6880
*/
69-
public function addButton($buttons)
81+
public static function addButton($buttons)
7082
{
7183
$advIndex = array_search('wp_adv', $buttons);
7284

@@ -81,8 +93,14 @@ public function addButton($buttons)
8193

8294
/**
8395
* Filters the comma-delimited list of stylesheets to load in TinyMCE.
96+
*
97+
* @since 6.0.0 Make static.
98+
*
99+
* @param string $stylesheets Comma-delimited list of stylesheets.
100+
*
101+
* @return string Comma-delimited list of stylesheets with the "Add Player" CSS appended.
84102
*/
85-
public function addStylesheet($stylesheets)
103+
public static function addStylesheet($stylesheets)
86104
{
87105
return $stylesheets . ',' . BEYONDWORDS__PLUGIN_URI . 'src/Component/Post/AddPlayer/AddPlayer.css';
88106
}
@@ -93,10 +111,11 @@ public function addStylesheet($stylesheets)
93111
* Player preview uses the CSS :after to set the content so we pass the CSS through WordPress i18n functions here.
94112
*
95113
* @since 3.3.0
114+
* @since 6.0.0 Make static.
96115
*
97116
* @return string CSS Block for player preview i18n delcerations.
98117
*/
99-
public function playerPreviewI18nStyles()
118+
public static function playerPreviewI18nStyles()
100119
{
101120
return sprintf(
102121
self::PLAYER_PREVIEW_STYLE_FORMAT,
@@ -110,17 +129,18 @@ public function playerPreviewI18nStyles()
110129
* Adds i18n-compatible TinyMCE Classic Editor CSS for the player placeholder.
111130
*
112131
* @since 3.3.0
132+
* @since 6.0.0 Make static.
113133
*
114134
* @param mixed[] $setings An array with TinyMCE config.
115135
*
116136
* @return mixed[] An array with TinyMCE config.
117137
*/
118-
public function filterTinyMceSettings($settings)
138+
public static function filterTinyMceSettings($settings)
119139
{
120140
if (isset($settings['content_style'])) {
121-
$settings['content_style'] .= ' ' . $this->playerPreviewI18nStyles() . ' ';
141+
$settings['content_style'] .= ' ' . self::playerPreviewI18nStyles() . ' ';
122142
} else {
123-
$settings['content_style'] = $this->playerPreviewI18nStyles() . ' ';
143+
$settings['content_style'] = self::playerPreviewI18nStyles() . ' ';
124144
}
125145

126146
return $settings;
@@ -132,23 +152,26 @@ public function filterTinyMceSettings($settings)
132152
* Adds i18n-compatible Block Editor CSS for the player placeholder.
133153
*
134154
* @since 3.3.0
155+
* @since 6.0.0 Make static.
135156
*/
136-
public function addEditorStyles()
157+
public static function addEditorStyles()
137158
{
138159
$allowed_html = array(
139160
'style' => array(),
140161
);
141162

142163
echo wp_kses(
143-
sprintf('<style>%s</style>', $this->playerPreviewI18nStyles()),
164+
sprintf('<style>%s</style>', self::playerPreviewI18nStyles()),
144165
$allowed_html
145166
);
146167
}
147168

148169
/**
149170
* Add Block Editor Stylesheet.
171+
*
172+
* @since 6.0.0 Make static.
150173
*/
151-
public function addBlockEditorStylesheet($hook)
174+
public static function addBlockEditorStylesheet($hook)
152175
{
153176
// Only enqueue for Gutenberg/Post screens
154177
if (CoreUtils::isGutenbergPage() || $hook === 'post.php' || $hook === 'post-new.php') {

src/Component/Post/BlockAttributes/BlockAttributes.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ class BlockAttributes
2929
* Init.
3030
*
3131
* @since 4.0.0
32+
* @since 6.0.0 Make static.
3233
*/
33-
public function init()
34+
public static function init()
3435
{
35-
add_filter('register_block_type_args', array($this, 'registerAudioAttribute'));
36-
add_filter('register_block_type_args', array($this, 'registerMarkerAttribute'));
37-
add_filter('render_block', array($this, 'renderBlock'), 10, 2);
36+
add_filter('register_block_type_args', array(__CLASS__, 'registerAudioAttribute'));
37+
add_filter('register_block_type_args', array(__CLASS__, 'registerMarkerAttribute'));
38+
add_filter('render_block', array(__CLASS__, 'renderBlock'), 10, 2);
3839
}
3940

4041
/**
4142
* Register "Audio" attribute for Gutenberg blocks.
43+
*
44+
* @since 6.0.0 Make static.
4245
*/
43-
public function registerAudioAttribute($args)
46+
public static function registerAudioAttribute($args)
4447
{
4548
// Setup attributes if needed.
4649
if (! isset($args['attributes'])) {
@@ -59,8 +62,10 @@ public function registerAudioAttribute($args)
5962

6063
/**
6164
* Register "Segment marker" attribute for Gutenberg blocks.
65+
*
66+
* @since 6.0.0 Make static.
6267
*/
63-
public function registerMarkerAttribute($args)
68+
public static function registerMarkerAttribute($args)
6469
{
6570
// Setup attributes if needed.
6671
if (! isset($args['attributes'])) {
@@ -85,13 +90,14 @@ public function registerMarkerAttribute($args)
8590
*
8691
* @since 4.0.0
8792
* @since 4.2.2 Rename method to renderBlock.
93+
* @since 6.0.0 Make static.
8894
*
8995
* @param string $blockContent The block content (HTML).
9096
* @param string $block The full block, including name and attributes.
9197
*
9298
* @return string Block Content (HTML).
9399
*/
94-
public function renderBlock($blockContent, $block)
100+
public static function renderBlock($blockContent, $block)
95101
{
96102
// Skip adding marker if player UI is disabled
97103
if (get_option('beyondwords_player_ui', PlayerUI::ENABLED) === PlayerUI::DISABLED) {

src/Component/Post/DisplayPlayer/DisplayPlayer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ class DisplayPlayer
2626
* Init.
2727
*
2828
* @since 4.0.0
29+
* @since 6.0.0 Make static.
2930
*/
30-
public function init()
31+
public static function init()
3132
{
3233
add_action('wp_loaded', function () {
3334
$postTypes = SettingsUtils::getCompatiblePostTypes();
3435

3536
if (is_array($postTypes)) {
3637
foreach ($postTypes as $postType) {
37-
add_action("save_post_{$postType}", array($this, 'save'), 20);
38+
add_action("save_post_{$postType}", array(__CLASS__, 'save'), 20);
3839
}
3940
}
4041
});
@@ -43,9 +44,11 @@ public function init()
4344
/**
4445
* Save the meta when the post is saved.
4546
*
47+
* @since 6.0.0 Make static.
48+
*
4649
* @param int $postId The ID of the post being saved.
4750
*/
48-
public function save($postId)
51+
public static function save($postId)
4952
{
5053
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
5154
return $postId;
@@ -74,9 +77,11 @@ public function save($postId)
7477
/**
7578
* Render the element.
7679
*
80+
* @since 6.0.0 Make static.
81+
*
7782
* @param WP_Post $post The post object.
7883
*/
79-
public function element($post)
84+
public static function element($post)
8085
{
8186
if (!($post instanceof \WP_Post)) {
8287
return;

src/Component/Post/ErrorNotice/ErrorNotice.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ class ErrorNotice
2525
* Init.
2626
*
2727
* @since 4.0.0
28+
* @since 6.0.0 Make static.
2829
*/
29-
public function init()
30+
public static function init()
3031
{
31-
add_action('enqueue_block_assets', array($this, 'enqueueBlockAssets'));
32+
add_action('enqueue_block_assets', array(__CLASS__, 'enqueueBlockAssets'));
3233
}
3334

34-
public function enqueueBlockAssets()
35+
/**
36+
* Enqueue Block Editor assets.
37+
*
38+
* @since 6.0.0 Make static.
39+
*/
40+
public static function enqueueBlockAssets()
3541
{
3642
// Only enqueue for Gutenberg screens
3743
if (CoreUtils::isGutenbergPage()) {

0 commit comments

Comments
 (0)