PluginProbe
Embed Privacy / 1.9.1
Embed Privacy v1.9.1
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
embed-privacy / inc / class-admin.php

class-admin.php in Embed Privacy 1.9.1, at inc/class-admin.php

250 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace epiphyt\Embed_Privacy;
3
4 use WP_Post;
5
6 /**
7 * Admin related methods for Embed Privacy.
8 *
9 * @since 1.2.0
10 *
11 * @author Epiphyt
12 * @license GPL2
13 * @package epiphyt\Embed_Privacy
14 */
15 class Admin {
16 /**
17 * @var array Admin to output
18 */
19 public $fields = [];
20
21 /**
22 * @var \epiphyt\Embed_Privacy\Admin
23 */
24 private static $instance;
25
26 /**
27 * Post Type constructor.
28 */
29 public function __construct() {
30 self::$instance = $this;
31 }
32
33 /**
34 * Initialize functions.
35 */
36 public function init() {
37 \add_action( 'admin_init', [ $this, 'init_settings' ] );
38 \add_action( 'admin_menu', [ $this, 'register_menu' ] );
39 \add_filter( 'map_meta_cap', [ $this, 'disallow_deleting_system_embeds' ], 10, 4 );
40 \add_filter( 'plugin_row_meta', [ $this, 'add_meta_link' ], 10, 2 );
41 }
42
43 /**
44 * Add plugin meta links.
45 *
46 * @since 1.6.0
47 *
48 * @param array $input Registered links.
49 * @param string $file Current plugin file.
50 * @return array Merged links
51 */
52 public function add_meta_link( $input, $file ) {
53 // bail on other plugins
54 if ( $file !== \plugin_basename( Embed_Privacy::get_instance()->plugin_file ) ) {
55 return $input;
56 }
57
58 return \array_merge(
59 $input,
60 [
61 '<a href="https://epiph.yt/en/embed-privacy/documentation/?version=' . \rawurlencode( \EMBED_PRIVACY_VERSION ) . '" target="_blank" rel="noopener noreferrer">' . \esc_html__( 'Documentation', 'embed-privacy' ) . '</a>',
62 ]
63 );
64 }
65
66 /**
67 * Disallow deletion of system embeds.
68 *
69 * @since 1.4.0
70 *
71 * @param array $caps The current capabilities
72 * @param string $cap The capability to check
73 * @param int $user_id The user ID
74 * @param array $args Additional arguments
75 * @return array The updated capabilities
76 * @noinspection PhpUnusedParameterInspection
77 */
78 function disallow_deleting_system_embeds( array $caps, $cap, $user_id, array $args ) {
79 if ( $cap !== 'delete_post' ) {
80 return $caps;
81 }
82
83 $post_id = \reset( $args );
84
85 if ( $post_id ) {
86 $post = \get_post( $post_id );
87
88 if ( $post instanceof WP_Post && $post->post_type === 'epi_embed' && \get_post_meta( $post->ID, 'is_system', true ) === 'yes' ) {
89 $caps[] = 'do_not_allow';
90
91 return $caps;
92 }
93 }
94
95 return $caps;
96 }
97
98 /**
99 * Wrapping function to get a field HTML.
100 *
101 * @param array $attributes Field attributes
102 */
103 public function get_field( array $attributes ) {
104 Fields::get_instance()->get_the_input_field_html( 0, $attributes );
105 }
106
107 /**
108 * Get a unique instance of the class.
109 *
110 * @return \epiphyt\Embed_Privacy\Admin The single instance of this class
111 */
112 public static function get_instance() {
113 if ( self::$instance === null ) {
114 self::$instance = new self();
115 }
116
117 return self::$instance;
118 }
119
120 /**
121 * Initialize the settings page.
122 */
123 public function init_settings() {
124 \add_settings_section(
125 'embed_privacy_general',
126 null,
127 '__return_null',
128 'embed_privacy'
129 );
130 \add_settings_field(
131 'embed_privacy_javascript_detection',
132 __( 'JavaScript detection', 'embed-privacy' ),
133 [ $this, 'get_field' ],
134 'embed_privacy',
135 'embed_privacy_general',
136 [
137 'description' => \__( 'By enabling this option, checks for embed providers are made via JavaScript on the client-side rather than on your server. Enabling this option is recommended when using a caching plugin.', 'embed-privacy' ),
138 'name' => 'embed_privacy_javascript_detection',
139 'option_type' => 'option',
140 'title' => \__( 'JavaScript detection for active providers', 'embed-privacy' ),
141 'type' => 'checkbox',
142 ]
143 );
144 \register_setting( 'embed_privacy', 'embed_privacy_javascript_detection' );
145 \add_settings_field(
146 'embed_privacy_local_tweets',
147 __( 'Embeds', 'embed-privacy' ),
148 [ $this, 'get_field' ],
149 'embed_privacy',
150 'embed_privacy_general',
151 [
152 'description' => \__( 'By enabling this option, tweets are embedded locally as text without any connection to Twitter, and no privacy overlay is required.', 'embed-privacy' ),
153 'name' => 'embed_privacy_local_tweets',
154 'option_type' => 'option',
155 'title' => \__( 'Local tweets', 'embed-privacy' ),
156 'type' => 'checkbox',
157 ]
158 );
159 \register_setting( 'embed_privacy', 'embed_privacy_local_tweets' );
160 \add_settings_field(
161 'embed_privacy_disable_link',
162 null,
163 [ $this, 'get_field' ],
164 'embed_privacy',
165 'embed_privacy_general',
166 [
167 'description' => \__( 'Disable the direct link on the lower right corner that opens the embed directly.', 'embed-privacy' ),
168 'name' => 'embed_privacy_disable_link',
169 'option_type' => 'option',
170 'title' => \__( 'Disable direct link', 'embed-privacy' ),
171 'type' => 'checkbox',
172 ]
173 );
174 \register_setting( 'embed_privacy', 'embed_privacy_disable_link' );
175 \add_settings_field(
176 'embed_privacy_download_thumbnails',
177 null,
178 [ $this, 'get_field' ],
179 'embed_privacy',
180 'embed_privacy_general',
181 [
182 /* translators: list of supported embed providers */
183 'description' => \wp_sprintf(
184 \__( 'Try to automatically download thumbnails of the embedded content and use them as background image of the overlay. Currently supported: %l.', 'embed-privacy' ),
185 Embed_Privacy::get_instance()->thumbnail->get_provider_titles()
186 ),
187 'name' => 'embed_privacy_download_thumbnails',
188 'option_type' => 'option',
189 'title' => \__( 'Download thumbnails', 'embed-privacy' ),
190 'type' => 'checkbox',
191 ]
192 );
193 \register_setting( 'embed_privacy', 'embed_privacy_download_thumbnails' );
194 \add_settings_field(
195 'embed_privacy_preserve_data_on_uninstall',
196 __( 'Data handling', 'embed-privacy' ),
197 [ $this, 'get_field' ],
198 'embed_privacy',
199 'embed_privacy_general',
200 [
201 'description' => \__( 'By enabling this option, all plugin data is preserved on uninstall.', 'embed-privacy' ),
202 'name' => 'embed_privacy_preserve_data_on_uninstall',
203 'option_type' => 'option',
204 'title' => \__( 'Preserve data on uninstall', 'embed-privacy' ),
205 'type' => 'checkbox',
206 ]
207 );
208 \register_setting( 'embed_privacy', 'embed_privacy_preserve_data_on_uninstall' );
209 }
210
211 /**
212 * Output the options HTML.
213 */
214 public function options_html() {
215 // check user capabilities
216 if ( ! \current_user_can( 'manage_options' ) ) {
217 return;
218 }
219
220 // show error/update messages
221 \settings_errors( 'embed_privacy_messages' );
222 ?>
223 <div class="wrap">
224 <h1><?php \esc_html_e( 'Embed Privacy', 'embed-privacy' ); ?> <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></h1>
225 <form action="options.php" method="post">
226 <?php
227 \settings_fields( 'embed_privacy' );
228 \do_settings_sections( 'embed_privacy' );
229 \submit_button( esc_html__( 'Save Settings', 'embed-privacy' ) );
230 ?>
231 </form>
232 </div>
233 <?php
234 }
235
236 /**
237 * Register menu entries.
238 */
239 public function register_menu() {
240 \add_submenu_page(
241 'options-general.php',
242 \__( 'Embed Privacy', 'embed-privacy' ),
243 \__( 'Embed Privacy', 'embed-privacy' ),
244 'manage_options',
245 'embed_privacy',
246 [ $this, 'options_html' ]
247 );
248 }
249 }
250