| 1 |
<?php |
| 2 |
namespace epiphyt\Embed_Privacy\admin; |
| 3 |
|
| 4 |
use epiphyt\Embed_Privacy\Embed_Privacy; |
| 5 |
|
| 6 |
/** |
| 7 |
* Admin settings. |
| 8 |
* |
| 9 |
* @author Epiphyt |
| 10 |
* @license GPL2 |
| 11 |
* @package epiphyt\Embed_Privacy |
| 12 |
* @since 1.10.0 |
| 13 |
*/ |
| 14 |
final class Settings { |
| 15 |
const CAPABILITY = 'manage_options'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Initialize functionality. |
| 19 |
*/ |
| 20 |
public static function init() { |
| 21 |
\add_action( 'admin_init', [ self::class, 'register' ] ); |
| 22 |
\add_action( 'admin_menu', [ self::class, 'register_menu' ] ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Get settings page. |
| 27 |
*/ |
| 28 |
public static function get_page() { |
| 29 |
if ( ! \current_user_can( self::CAPABILITY ) ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
?> |
| 34 |
<div class="wrap"> |
| 35 |
<h1 class="wp-heading-inline"><?php \esc_html_e( 'Embed Privacy', 'embed-privacy' ); ?></h1> |
| 36 |
<a href="<?php echo \esc_url( \admin_url( 'edit.php?post_type=epi_embed' ) ); ?>" class="page-title-action"><?php \esc_html_e( 'Manage embeds', 'embed-privacy' ); ?></a> |
| 37 |
<hr class="wp-header-end"> |
| 38 |
|
| 39 |
<?php \settings_errors( 'embed_privacy_messages' ); ?> |
| 40 |
|
| 41 |
<form action="options.php" method="post" class="embed-privacy__settings-form"> |
| 42 |
<?php |
| 43 |
\settings_fields( 'embed_privacy' ); |
| 44 |
\do_settings_sections( 'embed_privacy' ); |
| 45 |
\submit_button( \esc_html__( 'Save Settings', 'embed-privacy' ) ); |
| 46 |
?> |
| 47 |
</form> |
| 48 |
|
| 49 |
<h2 id="embed-privacy-support-data"><?php \esc_html_e( 'Support data', 'embed-privacy' ); ?></h2> |
| 50 |
<p><?php \esc_html_e( 'If you file a support request, please include the following data.', 'embed-privacy' ); ?></p> |
| 51 |
|
| 52 |
<div class="embed-privacy__copy-to-clipboard--container"> |
| 53 |
<button type="button" class="button embed-privacy__support-data--copy-to-clipboard embed-privacy__copy-to-clipboard" data-copy="embed-privacy__support-data--code" data-status="embed-privacy__copy-to-clipboard--status--support-data"><?php \esc_html_e( 'Copy support data to clipboard', 'embed-privacy' ); ?></button> |
| 54 |
<p class="embed-privacy__copy-to-clipboard--status embed-privacy__copy-to-clipboard--status--support-data" role="status"></p> |
| 55 |
</div> |
| 56 |
<pre class="embed-privacy__support-data--code-container" tabindex="0" role="region" aria-labelledby="embed-privacy-support-data"><code class="embed-privacy__support-data--code"><?php echo \esc_html( Support_Data::get() ); ?></code></pre> |
| 57 |
</div> |
| 58 |
<?php |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Register settings. |
| 63 |
*/ |
| 64 |
public static function register() { |
| 65 |
\add_settings_section( 'embed_privacy_general', \__( 'Embeds', 'embed-privacy' ), '__return_null', 'embed_privacy' ); |
| 66 |
\add_settings_section( 'embed_privacy_data_handling', \__( 'Data handling', 'embed-privacy' ), '__return_null', 'embed_privacy' ); |
| 67 |
\add_settings_field( |
| 68 |
'embed_privacy_local_activitypub_posts', |
| 69 |
\__return_empty_string(), |
| 70 |
[ Field::class, 'get' ], |
| 71 |
'embed_privacy', |
| 72 |
'embed_privacy_general', |
| 73 |
[ |
| 74 |
'description' => \__( 'By enabling this option, ActivityPub posts are embedded locally as text without any connection to the particular ActivityPub server, and no privacy overlay is required.', 'embed-privacy' ), |
| 75 |
'name' => 'embed_privacy_local_activitypub_posts', |
| 76 |
'option_type' => 'option', |
| 77 |
'title' => \__( 'Local ActivityPub posts', 'embed-privacy' ), |
| 78 |
'type' => 'checkbox', |
| 79 |
] |
| 80 |
); |
| 81 |
\register_setting( 'embed_privacy', 'embed_privacy_local_activitypub_posts' ); |
| 82 |
\add_settings_field( |
| 83 |
'embed_privacy_local_tweets', |
| 84 |
\__return_empty_string(), |
| 85 |
[ Field::class, 'get' ], |
| 86 |
'embed_privacy', |
| 87 |
'embed_privacy_general', |
| 88 |
[ |
| 89 |
'description' => \__( 'By enabling this option, X posts are embedded locally as text without any connection to X, and no privacy overlay is required.', 'embed-privacy' ), |
| 90 |
'name' => 'embed_privacy_local_tweets', |
| 91 |
'option_type' => 'option', |
| 92 |
'title' => \__( 'Local X posts', 'embed-privacy' ), |
| 93 |
'type' => 'checkbox', |
| 94 |
] |
| 95 |
); |
| 96 |
\register_setting( 'embed_privacy', 'embed_privacy_local_tweets' ); |
| 97 |
\add_settings_field( |
| 98 |
'embed_privacy_disable_link', |
| 99 |
\__return_empty_string(), |
| 100 |
[ Field::class, 'get' ], |
| 101 |
'embed_privacy', |
| 102 |
'embed_privacy_general', |
| 103 |
[ |
| 104 |
'description' => \__( 'Disable the direct link on the lower right corner that opens the embed directly.', 'embed-privacy' ), |
| 105 |
'name' => 'embed_privacy_disable_link', |
| 106 |
'option_type' => 'option', |
| 107 |
'title' => \__( 'Disable direct link', 'embed-privacy' ), |
| 108 |
'type' => 'checkbox', |
| 109 |
] |
| 110 |
); |
| 111 |
\register_setting( 'embed_privacy', 'embed_privacy_disable_link' ); |
| 112 |
\add_settings_field( |
| 113 |
'embed_privacy_download_thumbnails', |
| 114 |
\__return_empty_string(), |
| 115 |
[ Field::class, 'get' ], |
| 116 |
'embed_privacy', |
| 117 |
'embed_privacy_general', |
| 118 |
[ |
| 119 |
/* translators: list of supported embed providers */ |
| 120 |
'description' => \wp_sprintf( |
| 121 |
\__( 'Try to automatically download thumbnails of the embedded content and use them as background image of the overlay. Currently supported: %l.', 'embed-privacy' ), |
| 122 |
Embed_Privacy::get_instance()->thumbnail->get_provider_titles() |
| 123 |
), |
| 124 |
'name' => 'embed_privacy_download_thumbnails', |
| 125 |
'option_type' => 'option', |
| 126 |
'title' => \__( 'Download thumbnails', 'embed-privacy' ), |
| 127 |
'type' => 'checkbox', |
| 128 |
] |
| 129 |
); |
| 130 |
\register_setting( 'embed_privacy', 'embed_privacy_download_thumbnails' ); |
| 131 |
\add_settings_field( |
| 132 |
'embed_privacy_force_script_loading', |
| 133 |
\__return_empty_string(), |
| 134 |
[ Field::class, 'get' ], |
| 135 |
'embed_privacy', |
| 136 |
'embed_privacy_general', |
| 137 |
[ |
| 138 |
'description' => \__( 'This loads the embed scripts on every page. Only use this option if your website loads content dynamically via JavaScript, that can include embedded content.', 'embed-privacy' ), |
| 139 |
'name' => 'embed_privacy_force_script_loading', |
| 140 |
'option_type' => 'option', |
| 141 |
'title' => \__( 'Force script loading', 'embed-privacy' ), |
| 142 |
'type' => 'checkbox', |
| 143 |
] |
| 144 |
); |
| 145 |
\register_setting( 'embed_privacy', 'embed_privacy_force_script_loading' ); |
| 146 |
\add_settings_field( |
| 147 |
'embed_privacy_preserve_data_on_uninstall', |
| 148 |
\__return_empty_string(), |
| 149 |
[ Field::class, 'get' ], |
| 150 |
'embed_privacy', |
| 151 |
'embed_privacy_data_handling', |
| 152 |
[ |
| 153 |
'description' => \__( 'By enabling this option, all plugin data is preserved on uninstall.', 'embed-privacy' ), |
| 154 |
'name' => 'embed_privacy_preserve_data_on_uninstall', |
| 155 |
'option_type' => 'option', |
| 156 |
'title' => \__( 'Preserve data on uninstall', 'embed-privacy' ), |
| 157 |
'type' => 'checkbox', |
| 158 |
] |
| 159 |
); |
| 160 |
\register_setting( 'embed_privacy', 'embed_privacy_preserve_data_on_uninstall' ); |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Register menu items. |
| 165 |
*/ |
| 166 |
public static function register_menu() { |
| 167 |
\add_submenu_page( |
| 168 |
'options-general.php', |
| 169 |
\__( 'Embed Privacy', 'embed-privacy' ), |
| 170 |
\__( 'Embed Privacy', 'embed-privacy' ), |
| 171 |
self::CAPABILITY, |
| 172 |
'embed_privacy', |
| 173 |
[ self::class, 'get_page' ] |
| 174 |
); |
| 175 |
} |
| 176 |
} |
| 177 |
|