| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
/** |
| 6 |
* Setting: Auto-publish |
| 7 |
* |
| 8 |
* @package Beyondwords\Wordpress |
| 9 |
* @author Stuart McAlpine <[email protected]> |
| 10 |
* @since 5.1.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace Beyondwords\Wordpress\Component\Settings\Fields\AutoPublish; |
| 14 |
|
| 15 |
use Beyondwords\Wordpress\Component\Settings\Sync; |
| 16 |
|
| 17 |
/** |
| 18 |
* AutoPublish |
| 19 |
* |
| 20 |
* @since 5.1.0 |
| 21 |
*/ |
| 22 |
defined('ABSPATH') || exit; |
| 23 |
|
| 24 |
class AutoPublish |
| 25 |
{ |
| 26 |
/** |
| 27 |
* Default value. |
| 28 |
* |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
public const DEFAULT_VALUE = true; |
| 32 |
|
| 33 |
/** |
| 34 |
* Option name. |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
public const OPTION_NAME = 'beyondwords_project_auto_publish_enabled'; |
| 39 |
|
| 40 |
/** |
| 41 |
* Init. |
| 42 |
* |
| 43 |
* @since 5.1.0 |
| 44 |
* @since 6.0.0 Make static. |
| 45 |
*/ |
| 46 |
public static function init() |
| 47 |
{ |
| 48 |
add_action('admin_init', [self::class, 'addSetting']); |
| 49 |
add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
| 50 |
Sync::syncOptionToDashboard(self::OPTION_NAME); |
| 51 |
return $value; |
| 52 |
}); |
| 53 |
add_filter('option_' . self::OPTION_NAME, 'rest_sanitize_boolean'); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Init setting. |
| 58 |
* |
| 59 |
* @since 5.1.0 |
| 60 |
* @since 6.0.0 Make static. |
| 61 |
* |
| 62 |
* @return void |
| 63 |
*/ |
| 64 |
public static function addSetting() |
| 65 |
{ |
| 66 |
register_setting( |
| 67 |
'beyondwords_content_settings', |
| 68 |
self::OPTION_NAME, |
| 69 |
[ |
| 70 |
'type' => 'boolean', |
| 71 |
'sanitize_callback' => 'rest_sanitize_boolean', |
| 72 |
'default' => self::DEFAULT_VALUE, |
| 73 |
] |
| 74 |
); |
| 75 |
|
| 76 |
add_settings_field( |
| 77 |
'beyondwords-auto-publish', |
| 78 |
__('Auto-publish', 'speechkit'), |
| 79 |
[self::class, 'render'], |
| 80 |
'beyondwords_content', |
| 81 |
'content' |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Render setting field. |
| 87 |
* |
| 88 |
* @since 5.1.0 |
| 89 |
* @since 6.0.0 Make static. |
| 90 |
* |
| 91 |
* @return void |
| 92 |
**/ |
| 93 |
public static function render() |
| 94 |
{ |
| 95 |
$value = get_option(self::OPTION_NAME); |
| 96 |
?> |
| 97 |
<div> |
| 98 |
<label> |
| 99 |
<input type="hidden" name="<?php echo esc_attr(self::OPTION_NAME); ?>" value="" /> |
| 100 |
<input |
| 101 |
type="checkbox" |
| 102 |
id="<?php echo esc_attr(self::OPTION_NAME); ?>" |
| 103 |
name="<?php echo esc_attr(self::OPTION_NAME); ?>" |
| 104 |
value="1" |
| 105 |
<?php checked($value); ?> |
| 106 |
/> |
| 107 |
<?php |
| 108 |
esc_html_e( |
| 109 |
'When auto-publish is disabled all audio content created in WordPress will need to be manually published in the BeyondWords dashboard', // phpcs:ignore Generic.Files.LineLength.TooLong |
| 110 |
'speechkit' |
| 111 |
); |
| 112 |
?> |
| 113 |
</label> |
| 114 |
</div> |
| 115 |
<?php |
| 116 |
} |
| 117 |
} |
| 118 |
|