PluginProbe
BeyondWords – AI audio for publishers / 6.0.3
BeyondWords – AI audio for publishers v6.0.3
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / Component / Post / DisplayPlayer / DisplayPlayer.php

DisplayPlayer.php in BeyondWords – AI audio for publishers 6.0.3, at src/Component/Post/DisplayPlayer/DisplayPlayer.php

108 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /**
6 * BeyondWords Display Player element.
7 *
8 * @package Beyondwords\Wordpress
9 * @author Stuart McAlpine <stu@beyondwords.io>
10 * @since 3.0.0
11 */
12
13 namespace Beyondwords\Wordpress\Component\Post\DisplayPlayer;
14
15 use Beyondwords\Wordpress\Component\Post\PostMetaUtils;
16 use Beyondwords\Wordpress\Component\Settings\SettingsUtils;
17
18 /**
19 * PostMetabox
20 *
21 * @since 3.0.0
22 */
23 class DisplayPlayer
24 {
25 /**
26 * Init.
27 *
28 * @since 4.0.0
29 * @since 6.0.0 Make static.
30 */
31 public static function init()
32 {
33 add_action('wp_loaded', function (): void {
34 $postTypes = SettingsUtils::getCompatiblePostTypes();
35
36 if (is_array($postTypes)) {
37 foreach ($postTypes as $postType) {
38 add_action("save_post_{$postType}", [self::class, 'save'], 20);
39 }
40 }
41 });
42 }
43
44 /**
45 * Save the meta when the post is saved.
46 *
47 * @since 6.0.0 Make static.
48 *
49 * @param int $postId The ID of the post being saved.
50 */
51 public static function save($postId)
52 {
53 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
54 return $postId;
55 }
56
57 // "save_post" can be triggered at other times, so verify this request came from the our component
58 if (
59 ! isset($_POST['beyondwords_display_player_nonce']) ||
60 ! wp_verify_nonce(
61 sanitize_key($_POST['beyondwords_display_player_nonce']),
62 'beyondwords_display_player'
63 )
64 ) {
65 return $postId;
66 }
67
68 if (isset($_POST['beyondwords_display_player'])) {
69 update_post_meta($postId, 'beyondwords_disabled', '');
70 } else {
71 update_post_meta($postId, 'beyondwords_disabled', '1');
72 }
73
74 return $postId;
75 }
76
77 /**
78 * Render the element.
79 *
80 * @since 6.0.0 Make static, fix checkbox checked bug.
81 *
82 * @param \WP_Post $post The post object.
83 */
84 public static function element($post)
85 {
86 if (!($post instanceof \WP_Post)) {
87 return;
88 }
89
90 wp_nonce_field('beyondwords_display_player', 'beyondwords_display_player_nonce');
91
92 $displayPlayer = ! PostMetaUtils::getDisabled($post->ID);
93 ?>
94 <!-- checkbox -->
95 <p id="beyondwords-metabox-display-player">
96 <input
97 type="checkbox"
98 id="beyondwords_display_player"
99 name="beyondwords_display_player"
100 value="1"
101 <?php checked($displayPlayer); ?>
102 />
103 <?php esc_html_e('Display player', 'speechkit'); ?>
104 </p>
105 <?php
106 }
107 }
108