class-ad-groups-list.php
9 years ago
class-ad-type.php
9 years ago
class-licenses.php
9 years ago
class-menu.php
9 years ago
class-meta-box.php
9 years ago
class-notices.php
9 years ago
class-options.php
9 years ago
class-overview-widgets.php
9 years ago
class-settings.php
9 years ago
class-shortcode-creator.php
9 years ago
notices.php
9 years ago
shortcode-creator-l10n.php
10 years ago
class-settings.php
527 lines
| 1 | <?php |
| 2 | defined( 'ABSPATH' ) || exit; |
| 3 | |
| 4 | class Advanced_Ads_Admin_Settings { |
| 5 | /** |
| 6 | * Instance of this class. |
| 7 | * |
| 8 | * @var object |
| 9 | */ |
| 10 | protected static $instance = null; |
| 11 | |
| 12 | private function __construct() { |
| 13 | // settings handling |
| 14 | add_action( 'admin_init', array( $this, 'settings_init' ) ); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Return an instance of this class. |
| 19 | * |
| 20 | * @return object A single instance of this class. |
| 21 | */ |
| 22 | public static function get_instance() { |
| 23 | // If the single instance hasn't been set, set it now. |
| 24 | if ( null == self::$instance ) { |
| 25 | self::$instance = new self; |
| 26 | } |
| 27 | |
| 28 | return self::$instance; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * initialize settings |
| 33 | * |
| 34 | * @since 1.0.1 |
| 35 | */ |
| 36 | public function settings_init(){ |
| 37 | |
| 38 | // get settings page hook |
| 39 | $hook = Advanced_Ads_Admin::get_instance()->plugin_screen_hook_suffix; |
| 40 | |
| 41 | // register settings |
| 42 | register_setting( ADVADS_SLUG, ADVADS_SLUG, array($this, 'sanitize_settings') ); |
| 43 | |
| 44 | // general settings section |
| 45 | add_settings_section( |
| 46 | 'advanced_ads_setting_section', |
| 47 | __( 'General', 'advanced-ads' ), |
| 48 | array($this, 'render_settings_section_callback'), |
| 49 | $hook |
| 50 | ); |
| 51 | |
| 52 | // licenses section only for main blog |
| 53 | if( is_main_site( get_current_blog_id() ) ){ |
| 54 | // register license settings |
| 55 | register_setting( ADVADS_SLUG . '-licenses', ADVADS_SLUG . '-licenses' ); |
| 56 | |
| 57 | add_settings_section( |
| 58 | 'advanced_ads_settings_license_section', |
| 59 | __( 'Licenses', 'advanced-ads' ), |
| 60 | array($this, 'render_settings_licenses_section_callback'), |
| 61 | 'advanced-ads-settings-license-page' |
| 62 | ); |
| 63 | |
| 64 | add_filter( 'advanced-ads-setting-tabs', array( $this, 'license_tab') ); |
| 65 | } |
| 66 | |
| 67 | // add setting fields to disable ads |
| 68 | add_settings_field( |
| 69 | 'disable-ads', |
| 70 | __( 'Disable ads', 'advanced-ads' ), |
| 71 | array($this, 'render_settings_disable_ads'), |
| 72 | $hook, |
| 73 | 'advanced_ads_setting_section' |
| 74 | ); |
| 75 | // add setting fields for user role |
| 76 | add_settings_field( |
| 77 | 'hide-for-user-role', |
| 78 | __( 'Hide ads for logged in users', 'advanced-ads' ), |
| 79 | array($this, 'render_settings_hide_for_users'), |
| 80 | $hook, |
| 81 | 'advanced_ads_setting_section' |
| 82 | ); |
| 83 | // add setting fields for advanced js |
| 84 | add_settings_field( |
| 85 | 'activate-advanced-js', |
| 86 | __( 'Use advanced JavaScript', 'advanced-ads' ), |
| 87 | array($this, 'render_settings_advanced_js'), |
| 88 | $hook, |
| 89 | 'advanced_ads_setting_section' |
| 90 | ); |
| 91 | // add setting fields for content injection protection |
| 92 | add_settings_field( |
| 93 | 'content-injection-everywhere', |
| 94 | __( 'Unlimited ad injection', 'advanced-ads' ), |
| 95 | array($this, 'render_settings_content_injection_everywhere'), |
| 96 | $hook, |
| 97 | 'advanced_ads_setting_section' |
| 98 | ); |
| 99 | // add setting fields for content injection priority |
| 100 | add_settings_field( |
| 101 | 'content-injection-priority', |
| 102 | __( 'Priority of content injection filter', 'advanced-ads' ), |
| 103 | array($this, 'render_settings_content_injection_priority'), |
| 104 | $hook, |
| 105 | 'advanced_ads_setting_section' |
| 106 | ); |
| 107 | // add setting fields to remove injection level limitation |
| 108 | add_settings_field( |
| 109 | 'content-injection-level-limitation', |
| 110 | __( 'Disable level limitation', 'advanced-ads' ), |
| 111 | array($this, 'render_settings_content_injection_level_limitation'), |
| 112 | $hook, |
| 113 | 'advanced_ads_setting_section' |
| 114 | ); |
| 115 | // add setting fields for hiding ads from bots |
| 116 | add_settings_field( |
| 117 | 'block-bots', |
| 118 | __( 'Hide ads from bots', 'advanced-ads' ), |
| 119 | array($this, 'render_settings_block_bots'), |
| 120 | $hook, |
| 121 | 'advanced_ads_setting_section' |
| 122 | ); |
| 123 | // opt out from internal notices |
| 124 | add_settings_field( |
| 125 | 'disable-notices', |
| 126 | __( 'Disable notices', 'advanced-ads' ), |
| 127 | array($this, 'render_settings_disabled_notices'), |
| 128 | $hook, |
| 129 | 'advanced_ads_setting_section' |
| 130 | ); |
| 131 | // opt out from internal notices |
| 132 | add_settings_field( |
| 133 | 'front-prefix', |
| 134 | __( 'ID prefix', 'advanced-ads' ), |
| 135 | array($this, 'render_settings_front_prefix'), |
| 136 | $hook, |
| 137 | 'advanced_ads_setting_section' |
| 138 | ); |
| 139 | // remove id from widgets |
| 140 | add_settings_field( |
| 141 | 'remove-widget-id', |
| 142 | __( 'Remove Widget ID', 'advanced-ads' ), |
| 143 | array($this, 'render_settings_remove_widget_id'), |
| 144 | $hook, |
| 145 | 'advanced_ads_setting_section' |
| 146 | ); |
| 147 | // allow editors to manage ads |
| 148 | add_settings_field( |
| 149 | 'editors-manage-ads', |
| 150 | __( 'Allow editors to manage ads', 'advanced-ads' ), |
| 151 | array($this, 'render_settings_editors_manage_ads'), |
| 152 | $hook, |
| 153 | 'advanced_ads_setting_section' |
| 154 | ); |
| 155 | |
| 156 | add_settings_field( |
| 157 | 'add-custom-label', |
| 158 | __( 'Ad label', 'advanced-ads' ), |
| 159 | array( $this, 'render_settings_add_custom_label' ), |
| 160 | $hook, |
| 161 | 'advanced_ads_setting_section' |
| 162 | ); |
| 163 | |
| 164 | // only for main blog |
| 165 | if ( is_main_site( get_current_blog_id() ) ) { |
| 166 | add_settings_field( |
| 167 | 'uninstall-delete-data', |
| 168 | __( 'Delete data on uninstall', 'advanced-ads' ), |
| 169 | array( $this, 'render_settings_uninstall_delete_data' ), |
| 170 | $hook, |
| 171 | 'advanced_ads_setting_section' |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | // allow to disable shortcode button in TinyMCE |
| 176 | add_settings_field( |
| 177 | 'disable-shortcode-button', |
| 178 | __( 'Disable shortcode button', 'advanced-ads' ), |
| 179 | array( $this, 'render_settings_disable_shortcode_button' ), |
| 180 | $hook, |
| 181 | 'advanced_ads_setting_section' |
| 182 | ); |
| 183 | |
| 184 | // hook for additional settings from add-ons |
| 185 | do_action( 'advanced-ads-settings-init', $hook ); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * add license tab |
| 190 | * |
| 191 | * arr $tabs setting tabs |
| 192 | */ |
| 193 | public function license_tab( array $tabs ){ |
| 194 | |
| 195 | $tabs['licenses'] = array( |
| 196 | 'page' => 'advanced-ads-settings-license-page', |
| 197 | 'group' => ADVADS_SLUG . '-licenses', |
| 198 | 'tabid' => 'licenses', |
| 199 | 'title' => __( 'Licenses', 'advanced-ads' ) |
| 200 | ); |
| 201 | |
| 202 | return $tabs; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * render settings section |
| 207 | * |
| 208 | * @since 1.1.1 |
| 209 | */ |
| 210 | public function render_settings_section_callback(){ |
| 211 | // for whatever purpose there might come |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * render licenses settings section |
| 216 | * |
| 217 | * @since 1.5.1 |
| 218 | */ |
| 219 | public function render_settings_licenses_section_callback(){ |
| 220 | echo '<p>' . sprintf( __( 'Enter license keys for our powerful <a href="%s" target="_blank">add-ons</a>.', 'advanced-ads' ), ADVADS_URL . 'add-ons/#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses' ); |
| 221 | echo ' ' . sprintf( __( 'See also <a href="%s" target="_blank">Issues and questions about licenses</a>.', 'advanced-ads' ), ADVADS_URL . 'manual-category/purchase-licenses/#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses') . '</p>'; |
| 222 | // nonce field |
| 223 | echo '<input type="hidden" id="advads-licenses-ajax-referrer" value="' . wp_create_nonce( "advads_ajax_license_nonce" ) . '"/>'; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * options to disable ads |
| 228 | * |
| 229 | * @since 1.3.11 |
| 230 | */ |
| 231 | public function render_settings_disable_ads(){ |
| 232 | $options = Advanced_Ads::get_instance()->options(); |
| 233 | |
| 234 | // set the variables |
| 235 | $disable_all = isset($options['disabled-ads']['all']) ? 1 : 0; |
| 236 | $disable_404 = isset($options['disabled-ads']['404']) ? 1 : 0; |
| 237 | $disable_archives = isset($options['disabled-ads']['archives']) ? 1 : 0; |
| 238 | $disable_secondary = isset($options['disabled-ads']['secondary']) ? 1 : 0; |
| 239 | $disable_feed = ( ! isset( $options['disabled-ads']['feed'] ) || $options['disabled-ads']['feed'] ) ? 1 : 0; |
| 240 | |
| 241 | // load the template |
| 242 | include ADVADS_BASE_PATH . 'admin/views/settings-disable-ads.php'; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * render setting to hide ads from logged in users |
| 247 | * |
| 248 | * @since 1.1.1 |
| 249 | */ |
| 250 | public function render_settings_hide_for_users(){ |
| 251 | $options = Advanced_Ads::get_instance()->options(); |
| 252 | $current_capability_role = isset($options['hide-for-user-role']) ? $options['hide-for-user-role'] : 0; |
| 253 | |
| 254 | $capability_roles = array( |
| 255 | '' => __( '(display to all)', 'advanced-ads' ), |
| 256 | 'read' => __( 'Subscriber', 'advanced-ads' ), |
| 257 | 'delete_posts' => __( 'Contributor', 'advanced-ads' ), |
| 258 | 'edit_posts' => __( 'Author', 'advanced-ads' ), |
| 259 | 'edit_pages' => __( 'Editor', 'advanced-ads' ), |
| 260 | 'activate_plugins' => __( 'Admin', 'advanced-ads' ), |
| 261 | ); |
| 262 | echo '<select name="'.ADVADS_SLUG.'[hide-for-user-role]">'; |
| 263 | foreach ( $capability_roles as $_capability => $_role ) { |
| 264 | echo '<option value="'.$_capability.'" '.selected( $_capability, $current_capability_role, false ).'>'.$_role.'</option>'; |
| 265 | } |
| 266 | echo '</select>'; |
| 267 | |
| 268 | echo '<p class="description">'. __( 'Choose the lowest role a user must have in order to not see any ads.', 'advanced-ads' ) .'</p>'; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * render setting to display advanced js file |
| 273 | * |
| 274 | * @since 1.2.3 |
| 275 | */ |
| 276 | public function render_settings_advanced_js(){ |
| 277 | $options = Advanced_Ads::get_instance()->options(); |
| 278 | $checked = ( ! empty($options['advanced-js'])) ? 1 : 0; |
| 279 | |
| 280 | // display notice if js file was overridden |
| 281 | if( ! $checked && apply_filters( 'advanced-ads-activate-advanced-js', $checked ) ){ |
| 282 | echo '<p>' . __( '<strong>notice: </strong>the file is currently enabled by an add-on that needs it.', 'advanced-ads' ) . '</p>'; |
| 283 | } |
| 284 | echo '<input id="advanced-ads-advanced-js" type="checkbox" value="1" name="'.ADVADS_SLUG.'[advanced-js]" '.checked( $checked, 1, false ).'>'; |
| 285 | echo '<p class="description">'. sprintf( __( 'Enable advanced JavaScript functions (<a href="%s" target="_blank">here</a>). Some features and add-ons might override this setting if they need features from this file.', 'advanced-ads' ), ADVADS_URL . 'javascript-functions/#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings' ) .'</p>'; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * render setting for content injection protection |
| 290 | * |
| 291 | * @since 1.4.1 |
| 292 | */ |
| 293 | public function render_settings_content_injection_everywhere(){ |
| 294 | $options = Advanced_Ads::get_instance()->options(); |
| 295 | |
| 296 | if ( ! isset( $options['content-injection-everywhere'] ) ){ |
| 297 | $everywhere = 0; |
| 298 | } elseif ( $options['content-injection-everywhere'] === 'true') { |
| 299 | $everywhere = -1; |
| 300 | } else { |
| 301 | $everywhere = absint( $options['content-injection-everywhere'] ); |
| 302 | } |
| 303 | |
| 304 | echo '<input id="advanced-ads-injection-everywhere" type="number" value="' . $everywhere . '" min="-1" name="'.ADVADS_SLUG.'[content-injection-everywhere]">'; |
| 305 | echo '<p class="description">'. __( 'Some plugins and themes trigger ad injections where it shouldn’t happen. Therefore, Advanced Ads ignores injected placements on non-singular pages and outside the loop. However, this can cause problems with some themes. Set this option to -1 in order to enable unlimited ad injection at your own risk, set it to 0 to keep it disabled or choose a positive number to enable the injection only in the first x posts on your archive pages.', 'advanced-ads' ) .'</p>'; |
| 306 | |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * render setting for content injection priority |
| 311 | * |
| 312 | * @since 1.4.1 |
| 313 | */ |
| 314 | public function render_settings_content_injection_priority(){ |
| 315 | $options = Advanced_Ads::get_instance()->options(); |
| 316 | $priority = ( isset($options['content-injection-priority'])) ? intval( $options['content-injection-priority'] ) : 100; |
| 317 | |
| 318 | echo '<input id="advanced-ads-content-injection-priority" type="number" value="'.$priority.'" name="'.ADVADS_SLUG.'[content-injection-priority]" size="3"/>'; |
| 319 | echo '<p class="description">'; |
| 320 | if ( $priority < 11 ) { |
| 321 | echo '<span class="advads-error-message">' . __( 'Please check your post content. A priority of 10 and below might cause issues (wpautop function might run twice).', 'advanced-ads' ) . '</span><br />'; |
| 322 | } |
| 323 | _e( 'Play with this value in order to change the priority of the injected ads compared to other auto injected elements in the post content.', 'advanced-ads' ); |
| 324 | echo '</p>'; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * render setting to disable content injection level limitation |
| 329 | * |
| 330 | * @since 1.7.22 |
| 331 | */ |
| 332 | public function render_settings_content_injection_level_limitation(){ |
| 333 | $options = Advanced_Ads::get_instance()->options(); |
| 334 | $checked = ( ! empty($options['content-injection-level-disabled'])) ? 1 : 0; |
| 335 | |
| 336 | echo '<input id="advanced-ads-content-injection-level-disabled" type="checkbox" value="1" name="'.ADVADS_SLUG.'[content-injection-level-disabled]" '.checked( $checked, 1, false ).'>'; |
| 337 | echo '<p class="description">'. __( 'Advanced Ads ignores paragraphs and other elements in containers when injecting ads into the post content. Check this option to ignore this limitation and ads might show up again.', 'advanced-ads' ) . '</p>'; |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * render setting for blocking bots |
| 342 | * |
| 343 | * @since 1.4.9 |
| 344 | */ |
| 345 | public function render_settings_block_bots(){ |
| 346 | $options = Advanced_Ads::get_instance()->options(); |
| 347 | $checked = ( ! empty($options['block-bots'])) ? 1 : 0; |
| 348 | |
| 349 | echo '<input id="advanced-ads-block-bots" type="checkbox" value="1" name="'.ADVADS_SLUG.'[block-bots]" '.checked( $checked, 1, false ).'>'; |
| 350 | echo '<p class="description">'. sprintf( __( 'Hide ads from crawlers, bots and empty user agents. Also prevents counting impressions for bots when using the <a href="%s" target="_blank">Tracking Add-On</a>.', 'advanced-ads' ), ADVADS_URL . 'add-ons/tracking/#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings' ) .'<br/>' |
| 351 | . __( 'Disabling this option only makes sense if your ads contain content you want to display to bots (like search engines) or your site is cached and bots could create a cached version without the ads.', 'advanced-ads' ) . '</p>'; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * render setting to disable notices |
| 356 | * |
| 357 | * @since 1.5.3 |
| 358 | */ |
| 359 | public function render_settings_disabled_notices(){ |
| 360 | $options = Advanced_Ads::get_instance()->options(); |
| 361 | $checked = ( ! empty($options['disable-notices'])) ? 1 : 0; |
| 362 | |
| 363 | echo '<input id="advanced-ads-disabled-notices" type="checkbox" value="1" name="'.ADVADS_SLUG.'[disable-notices]" '.checked( $checked, 1, false ).'>'; |
| 364 | echo '<p class="description">'. __( 'Disable internal notices like tips, tutorials, email newsletters and update notices. Disabling notices is recommended if you run multiple blogs with Advanced Ads already.', 'advanced-ads' ) . '</p>'; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * render setting for frontend prefix |
| 369 | * |
| 370 | * @since 1.6.8 |
| 371 | */ |
| 372 | public function render_settings_front_prefix(){ |
| 373 | $options = Advanced_Ads::get_instance()->options(); |
| 374 | |
| 375 | $prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix(); |
| 376 | $old_prefix = ( isset($options['id-prefix'])) ? esc_attr( $options['id-prefix'] ) : ''; |
| 377 | |
| 378 | echo '<input id="advanced-ads-front-prefix" type="text" value="' .$prefix .'" name="'.ADVADS_SLUG.'[front-prefix]" />'; |
| 379 | // deprecated |
| 380 | echo '<input type="hidden" value="' .$old_prefix .'" name="'.ADVADS_SLUG.'[id-prefix]" />'; |
| 381 | echo '<p class="description">'. __( 'Prefix of class or id attributes in the frontend. Change it if you don’t want <strong>ad blockers</strong> to mark these blocks as ads.<br/>You might need to <strong>rewrite css rules afterwards</strong>.', 'advanced-ads' ) .'</p>'; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * render setting to remove the id from advanced ads widgets |
| 386 | * |
| 387 | * @since 1.6.8.2 |
| 388 | */ |
| 389 | public function render_settings_remove_widget_id(){ |
| 390 | $options = Advanced_Ads::get_instance()->options(); |
| 391 | |
| 392 | // is true by default if no options where previously set |
| 393 | if( ! isset($options['remove-widget-id']) && $options !== array() ){ |
| 394 | $remove = false; |
| 395 | } elseif( $options === array() ){ |
| 396 | $remove = true; |
| 397 | } else { |
| 398 | $remove = true; |
| 399 | } |
| 400 | |
| 401 | echo '<input id="advanced-ads-remove-widget-id" type="checkbox" ' . checked( $remove, true, false ) . ' name="'.ADVADS_SLUG.'[remove-widget-id]" />'; |
| 402 | echo '<p class="description">' . __( 'Remove the ID attribute from widgets in order to not make them an easy target of ad blockers.', 'advanced-ads' ); |
| 403 | |
| 404 | if ( class_exists( 'q2w3_fixed_widget', false ) ) { |
| 405 | echo '<br />' . __( 'If checked, the Advanced Ads Widget will not work with the fixed option of the <strong>Q2W3 Fixed Widget</strong> plugin.', 'advanced-ads' ); |
| 406 | } |
| 407 | |
| 408 | echo '</p>'; |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * render setting to allow editors to manage ads |
| 413 | * |
| 414 | * @since 1.6.14 |
| 415 | */ |
| 416 | public function render_settings_editors_manage_ads(){ |
| 417 | $options = Advanced_Ads::get_instance()->options(); |
| 418 | |
| 419 | // is false by default if no options where previously set |
| 420 | if( isset($options['editors-manage-ads']) && $options['editors-manage-ads'] ){ |
| 421 | $allow = true; |
| 422 | } else { |
| 423 | $allow = false; |
| 424 | } |
| 425 | |
| 426 | echo '<input id="advanced-ads-editors-manage-ads" type="checkbox" ' . checked( $allow, true, false ) . ' name="'.ADVADS_SLUG.'[editors-manage-ads]" />'; |
| 427 | echo '<p class="description">'. __( 'Allow editors to also manage and publish ads.', 'advanced-ads' ) . |
| 428 | ' ' . sprintf(__( 'You can assign different ad-related roles on a user basis with <a href="%s" target="_blank">Advanced Ads Pro</a>.', 'advanced-ads' ), ADVADS_URL . 'add-ons/advanced-ads-pro/#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings') . '</p>'; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * render setting to add an "Advertisement" label before ads |
| 433 | * |
| 434 | */ |
| 435 | public function render_settings_add_custom_label(){ |
| 436 | $options = Advanced_Ads::get_instance()->options(); |
| 437 | |
| 438 | $enabled = isset( $options['custom-label']['enabled'] ); |
| 439 | $label = ! empty ( $options['custom-label']['text'] ) ? esc_html( $options['custom-label']['text'] ) : _x( 'Advertisements', 'label before ads' ); |
| 440 | ?> |
| 441 | |
| 442 | <fieldset> |
| 443 | <input type="checkbox" <?php checked( $enabled, true ); ?> value="1" name="<?php echo ADVADS_SLUG . '[custom-label][enabled]'; ?>" /> |
| 444 | <input id="advads-custom-label" type="text" value="<?php echo $label; ?>" name="<?php echo ADVADS_SLUG . '[custom-label][text]'; ?>" /> |
| 445 | </fieldset> |
| 446 | <p class="description"><?php _e( 'Displayed above ads.', 'advanced-ads' ); ?> <a target="_blank" href="<?php echo ADVADS_URL . 'manual/advertisement-label/#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-advertisement-label'?>"><?php _e( 'Manual', 'advanced-ads' ); ?></a></p> |
| 447 | |
| 448 | <?php |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * render setting 'Delete data on uninstall" |
| 453 | * |
| 454 | */ |
| 455 | public function render_settings_uninstall_delete_data(){ |
| 456 | $options = Advanced_Ads::get_instance()->options(); |
| 457 | $enabled = ! empty( $options['uninstall-delete-data'] ); ?> |
| 458 | |
| 459 | <input type="checkbox" value="1" name="<?php echo ADVADS_SLUG; ?>[uninstall-delete-data]" <?php checked( $enabled, 1 ); ?>> |
| 460 | <p class="description"><?php _e( 'Clean up all data related to Advanced Ads when removing the plugin.', 'advanced-ads' ); ?></p> |
| 461 | <?php |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * Render setting to disable shortcode button. |
| 466 | */ |
| 467 | public function render_settings_disable_shortcode_button(){ |
| 468 | $options = Advanced_Ads::get_instance()->options(); |
| 469 | |
| 470 | $checked = ! empty( $options['disable-shortcode-button'] ); |
| 471 | |
| 472 | echo '<input id="advanced-ads-disable-shortcode-button" type="checkbox" ' . checked( $checked, true, false ) . ' name="' . ADVADS_SLUG . '[disable-shortcode-button]" />'; |
| 473 | echo '<p class="description">' . __( 'Disable shortcode button in visual editor.', 'advanced-ads' ) . '</p>'; |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * sanitize plugin settings |
| 478 | * |
| 479 | * @since 1.5.1 |
| 480 | * @param array $options all the options |
| 481 | */ |
| 482 | public function sanitize_settings($options){ |
| 483 | |
| 484 | // sanitize whatever option one wants to sanitize |
| 485 | |
| 486 | if ( isset( $options['front-prefix'] ) ) { |
| 487 | $options['front-prefix'] = sanitize_html_class( $options['front-prefix'], Advanced_Ads_Plugin::DEFAULT_FRONTEND_PREFIX ); |
| 488 | } |
| 489 | |
| 490 | $options = apply_filters( 'advanced-ads-sanitize-settings', $options ); |
| 491 | |
| 492 | // check if editors can edit ads now and set the rights |
| 493 | // else, remove that right |
| 494 | $editor_role = get_role( 'editor' ); |
| 495 | if( null == $editor_role ){ |
| 496 | return $options; |
| 497 | } |
| 498 | if( isset($options['editors-manage-ads']) && $options['editors-manage-ads'] ){ |
| 499 | $editor_role->add_cap( 'advanced_ads_see_interface' ); |
| 500 | $editor_role->add_cap( 'advanced_ads_edit_ads' ); |
| 501 | $editor_role->add_cap( 'advanced_ads_manage_placements' ); |
| 502 | $editor_role->add_cap( 'advanced_ads_place_ads' ); |
| 503 | } else { |
| 504 | $editor_role->remove_cap( 'advanced_ads_see_interface' ); |
| 505 | $editor_role->remove_cap( 'advanced_ads_edit_ads' ); |
| 506 | $editor_role->remove_cap( 'advanced_ads_manage_placements' ); |
| 507 | $editor_role->remove_cap( 'advanced_ads_place_ads' ); |
| 508 | } |
| 509 | |
| 510 | // we need 3 states: ! isset, 1, 0 |
| 511 | $options['disabled-ads']['feed'] = isset( $options['disabled-ads']['feed'] ) ? 1 : 0; |
| 512 | |
| 513 | if ( isset( $options['content-injection-everywhere'] ) ){ |
| 514 | if ( $options['content-injection-everywhere'] == 0 ){ |
| 515 | unset( $options['content-injection-everywhere'] ); |
| 516 | } elseif ( $options['content-injection-everywhere'] <= -1 ){ |
| 517 | $options['content-injection-everywhere'] = "true"; |
| 518 | } else { |
| 519 | $options['content-injection-everywhere'] = absint($options['content-injection-everywhere']); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | return $options; |
| 524 | } |
| 525 | |
| 526 | } |
| 527 |