PluginProbe
BeyondWords – AI audio for publishers / 4.5.0
BeyondWords – AI audio for publishers v4.5.0
7.2.0 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 All 44 releases
speechkit / src / Component / Posts / Column / Column.php

Column.php in BeyondWords – AI audio for publishers 4.5.0, at src/Component/Posts/Column/Column.php

113 lines 2.8 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 Posts Column.
7 *
8 * @package Beyondwords\Wordpress
9 * @author Stuart McAlpine <[email protected]>
10 * @since 3.0.0
11 */
12
13 namespace Beyondwords\Wordpress\Component\Posts\Column;
14
15 use Beyondwords\Wordpress\Component\Post\PostMetaUtils;
16 use Beyondwords\Wordpress\Component\Settings\SettingsUtils;
17
18 /**
19 * Column setup
20 *
21 * @since 3.0.0
22 */
23 class Column
24 {
25 public const OUTPUT_YES = '<span class="dashicons dashicons-yes"></span> ';
26
27 public const OUTPUT_NO = '—';
28
29 public const OUTPUT_DISABLED = ' <span class="beyondwords--disabled">Disabled</span>';
30
31 public const OUTPUT_ERROR_PREFIX = '<span class="dashicons dashicons-warning"></span> ';
32
33 /**
34 * Init.
35 *
36 * @since 4.0.0
37 */
38 public function init()
39 {
40 add_action('wp_loaded', function () {
41 $postTypes = SettingsUtils::getCompatiblePostTypes();
42
43 if (is_array($postTypes)) {
44 foreach ($postTypes as $postType) {
45 add_filter("manage_{$postType}_posts_columns", array($this, 'renderColumnsHead'));
46 add_action("manage_{$postType}_posts_custom_column", array($this, 'renderColumnsContent'), 10, 2);
47 }
48 }
49 });
50 }
51
52 /**
53 * Add a custom column with player status.
54 *
55 * @since 3.0.0
56 *
57 * @param array $columns Array of <td> headers
58 *
59 * @return array
60 **/
61 public function renderColumnsHead($columns)
62 {
63 return array_merge($columns, array(
64 'beyondwords' => __('BeyondWords', 'speechkit'),
65 ));
66 }
67
68 /**
69 * Render ✗|✓ in Posts list, under the BeyondWords column.
70 *
71 * @since 3.0.0
72 *
73 * @param string $columnName Column name
74 * @param int $postId Post ID
75 *
76 * @return void
77 **/
78 public function renderColumnsContent($columnName, $postId)
79 {
80 if ($columnName !== 'beyondwords') {
81 return;
82 }
83
84 $postTypes = SettingsUtils::getCompatiblePostTypes();
85
86 if (empty($postTypes)) {
87 return;
88 }
89
90 $errorMessage = PostMetaUtils::getErrorMessage($postId);
91 $contentId = PostMetaUtils::getContentId($postId);
92 $disabled = PostMetaUtils::getDisabled($postId);
93
94 $allowedTags = array(
95 'span' => array(
96 'class' => array(),
97 ),
98 );
99
100 if (! empty($errorMessage)) {
101 echo wp_kses(self::OUTPUT_ERROR_PREFIX . $errorMessage, $allowedTags);
102 } elseif (empty($contentId)) {
103 echo wp_kses(self::OUTPUT_NO, $allowedTags);
104 } else {
105 echo wp_kses(self::OUTPUT_YES, $allowedTags);
106 }
107
108 if (! empty($disabled)) {
109 echo wp_kses(self::OUTPUT_DISABLED, $allowedTags);
110 }
111 }
112 }
113