| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Admin\Options; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Admin\AdminSettingsModel; |
| 7 |
|
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
die; |
| 11 |
} // Cannot access directly. |
| 12 |
|
| 13 |
if ( ! class_exists( 'Security' ) ) { |
| 14 |
class Security extends AdminSettingsModel { |
| 15 |
|
| 16 |
public $defaults = []; |
| 17 |
|
| 18 |
public function __construct() { |
| 19 |
$this->tweak_settings(); |
| 20 |
add_action('admin_footer', [$this, 'redirect_url_auto_fill_script']); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Auto-fill New Register URL placeholder based on New Login URL |
| 25 |
*/ |
| 26 |
public function redirect_url_auto_fill_script() { |
| 27 |
$screen = get_current_screen(); |
| 28 |
if (!$screen || strpos($screen->id, 'wp-adminify') === false) { |
| 29 |
return; |
| 30 |
} |
| 31 |
?> |
| 32 |
<script> |
| 33 |
jQuery(document).ready(function($) { |
| 34 |
// Find the login URL and register URL fields |
| 35 |
var $loginField = $('input[data-depend-id="new_login_url"]'); |
| 36 |
var $registerField = $('input[data-depend-id="new_register_url"]'); |
| 37 |
|
| 38 |
if ($loginField.length && $registerField.length) { |
| 39 |
// Update placeholder when login URL changes (not actual value) |
| 40 |
$loginField.on('input change', function() { |
| 41 |
var loginValue = $(this).val().trim(); |
| 42 |
|
| 43 |
if (loginValue) { |
| 44 |
// Update placeholder to suggest the register URL format |
| 45 |
$registerField.attr('placeholder', loginValue + '/?action=register'); |
| 46 |
} else { |
| 47 |
// Reset to default placeholder |
| 48 |
$registerField.attr('placeholder', 'wp-login.php?action=register'); |
| 49 |
} |
| 50 |
}); |
| 51 |
|
| 52 |
// Also update placeholder on page load if login has value |
| 53 |
var initialLogin = $loginField.val().trim(); |
| 54 |
if (initialLogin) { |
| 55 |
$registerField.attr('placeholder', initialLogin + '/?action=register'); |
| 56 |
} |
| 57 |
} |
| 58 |
}); |
| 59 |
</script> |
| 60 |
<?php |
| 61 |
} |
| 62 |
|
| 63 |
protected function get_defaults() { |
| 64 |
return [ |
| 65 |
'security_head' => [ |
| 66 |
'enable_security_head' => false, |
| 67 |
'security_head_data' => [ |
| 68 |
'generator_wp_version' |
| 69 |
], |
| 70 |
'self_ping_sites' => '' |
| 71 |
], |
| 72 |
'security_rest_api' => [ |
| 73 |
'security_rest_api_enable' => false, |
| 74 |
'security_rest_api_data' => [] |
| 75 |
], |
| 76 |
'disable_comments' => [ |
| 77 |
'enable_disable_comments' => false, |
| 78 |
'post_types' => [], |
| 79 |
'apply_for' => [], |
| 80 |
], |
| 81 |
'custom_gravatar' => [ |
| 82 |
'enable', |
| 83 |
'image' => [ |
| 84 |
[ |
| 85 |
'avatar_image' => '', |
| 86 |
'avatar_name' => 'Avatar Name', |
| 87 |
], |
| 88 |
], |
| 89 |
], |
| 90 |
'post_archives' => [ |
| 91 |
'post_archives_enable' => false, |
| 92 |
'post_archives_data' => [], |
| 93 |
], |
| 94 |
'security_feed' => false, |
| 95 |
'users_security' => [ |
| 96 |
'limit_logins' => false, |
| 97 |
'change_username' => false, |
| 98 |
], |
| 99 |
'disable_automatic_emails' => false, |
| 100 |
'disable_language_switcher_login' => false, |
| 101 |
|
| 102 |
// Redirect URLs |
| 103 |
'redirect_urls_fields' => [ |
| 104 |
'enable_redirect_urls' => false, |
| 105 |
'redirect_urls_options' => [ |
| 106 |
'redirect_urls_tabs' => [ |
| 107 |
'new_login_url' => '', |
| 108 |
'redirect_admin_url' => '', |
| 109 |
'new_register_url' => '', |
| 110 |
'new_logout_url' => '', |
| 111 |
'login_redirects' => [ |
| 112 |
'user_types' => '', |
| 113 |
'redirect_user' => '', |
| 114 |
'redirect_role' => '', |
| 115 |
'redirect_cap' => '', |
| 116 |
'redirect_url' => '', |
| 117 |
], |
| 118 |
'logout_redirects' => [ |
| 119 |
'user_types' => '', |
| 120 |
'redirect_user' => '', |
| 121 |
'redirect_role' => '', |
| 122 |
'redirect_cap' => '', |
| 123 |
'redirect_url' => '', |
| 124 |
] |
| 125 |
], |
| 126 |
], |
| 127 |
] |
| 128 |
]; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
/** |
| 133 |
* Security: Head Fields |
| 134 |
* |
| 135 |
* @return void |
| 136 |
*/ |
| 137 |
public function security_head_fields( &$head_fields ) { |
| 138 |
$security_head = [ |
| 139 |
'xmlrpc' => __( 'Disable XML-RPC', 'adminify' ), |
| 140 |
'generator_wp_version' => __( 'Remove WordPress Generator Version from front end', 'adminify' ), |
| 141 |
'rsd' => __( 'Remove "<link rel=\'EditURI\'..." from head section', 'adminify' ), |
| 142 |
'shortlink' => __( 'Remove "<link rel=\'shortlink\'..." from head section', 'adminify' ), |
| 143 |
'canonical' => __( 'Remove <link rel="canonical" href="https://www.site.com/some-url" /> from head section', 'adminify' ), |
| 144 |
'self_ping' => __('Disable self-ping, i.e., from your site to your site when writing posts.', 'adminify'), |
| 145 |
]; |
| 146 |
|
| 147 |
$third_party_security_head = []; |
| 148 |
if ( Utils::is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 149 |
$third_party_security_head['wc_generator'] = __( 'Remove WooCommerce Generator Meta', 'adminify' ); |
| 150 |
} |
| 151 |
|
| 152 |
if ( Utils::is_plugin_active( 'revslider/revslider.php' ) ) { |
| 153 |
$third_party_security_head['revslider_generator'] = __( 'Remove Revolution Slider Generator Meta', 'adminify' ); |
| 154 |
} |
| 155 |
|
| 156 |
if ( Utils::is_plugin_active( 'js_composer/js_composer.php' ) ) { |
| 157 |
$third_party_security_head['js_composer_generator'] = __( 'Remove Visual Composer Generator Meta', 'adminify' ); |
| 158 |
} |
| 159 |
|
| 160 |
if ( Utils::is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) { |
| 161 |
$third_party_security_head['wpml_generator'] = __( 'Remove WPML Generator Meta', 'adminify' ); |
| 162 |
} |
| 163 |
|
| 164 |
if ( Utils::is_plugin_active( 'wordpress-seo/wp-seo.php' ) ) { |
| 165 |
$third_party_security_head['yoast_generator'] = __( 'Remove All Yoast HTML Comments', 'adminify' ); |
| 166 |
} |
| 167 |
|
| 168 |
$security_head = array_merge($security_head, $third_party_security_head); |
| 169 |
|
| 170 |
|
| 171 |
$head_fields[] = [ |
| 172 |
'id' => 'security_head', |
| 173 |
'title' => __('Header Security', 'adminify'), |
| 174 |
'subtitle' => __('WordPress Frontend Head Tags Security ', 'adminify'), |
| 175 |
'type' => 'fieldset', |
| 176 |
'fields' => [ |
| 177 |
[ |
| 178 |
'id' => 'enable_security_head', |
| 179 |
'type' => 'switcher', |
| 180 |
'title' => __('', 'adminify'), |
| 181 |
'class' => 'adminify-pl-0 adminify-pt-0', |
| 182 |
'text_on' => __('Show', 'adminify'), |
| 183 |
'text_off' => __('Hide', 'adminify'), |
| 184 |
'text_width' => 80, |
| 185 |
'default' => $this->get_default_field('security_head')['enable_security_head'], |
| 186 |
], |
| 187 |
[ |
| 188 |
'id' => 'security_head_data', |
| 189 |
'type' => 'checkbox', |
| 190 |
'class' => 'adminify-one-col', |
| 191 |
'title' => __('', 'adminify'), |
| 192 |
'options' => $security_head, |
| 193 |
'default' => $this->get_default_field('security_head')['security_head_data'], |
| 194 |
'dependency' => ['enable_security_head', '==', 'true', 'true'] |
| 195 |
], |
| 196 |
[ |
| 197 |
'id' => 'self_ping_sites', |
| 198 |
'type' => 'textarea', |
| 199 |
'subtitle' => __('Additional URLs to disable Self Ping', 'adminify'), |
| 200 |
'placeholder' => __('Each URLs in new line', 'adminify'), |
| 201 |
'title' => 'Additional Self-Ping URLs', |
| 202 |
'default' => $this->get_default_field('self_ping_sites'), |
| 203 |
'dependency' => ['security_head_data|enable_security_head', 'any|==', 'self_ping|true', 'true'], |
| 204 |
] |
| 205 |
] |
| 206 |
]; |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
/** |
| 212 |
* Security: Feed Fields |
| 213 |
* |
| 214 |
* @param [type] $security_feed |
| 215 |
* |
| 216 |
* @return void |
| 217 |
*/ |
| 218 |
public function security_feed_fields( &$security_feed ) { |
| 219 |
$security_feed[] = [ |
| 220 |
'id' => 'security_feed', |
| 221 |
'type' => 'switcher', |
| 222 |
'title' => __('Feed Links', 'adminify'), |
| 223 |
'text_on' => __('Yes', 'adminify'), |
| 224 |
'text_off' => __('No', 'adminify'), |
| 225 |
'text_width' => 80, |
| 226 |
'subtitle' => __('Disable all RSS, Atom, and RDF feeds, including posts, categories, tags, comments, authors, and search. Also redirect all feed URLs.', 'adminify'), |
| 227 |
'default' => $this->get_default_field('security_feed'), |
| 228 |
]; |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* Change Username Module |
| 233 |
*/ |
| 234 |
public function security_redirect_urls(&$redirect_urls){ |
| 235 |
$settings_fields = []; |
| 236 |
$login_redirects = []; |
| 237 |
// $logout_redirects = []; |
| 238 |
$this->login_register_url_fields($settings_fields); |
| 239 |
$this->roles_redirect_tabs($login_redirects); |
| 240 |
|
| 241 |
$redirect_urls = [ |
| 242 |
[ |
| 243 |
'id' => 'redirect_urls_fields', |
| 244 |
'title' => sprintf(__('Redirect URLs %s', 'adminify'), Utils::adminify_upgrade_pro_badge()), |
| 245 |
'class' => 'adminify-pro-fieldset', |
| 246 |
'subtitle' => __('Login and logout redirects based on user roles. Customize URLs for administrators, editors, or subscribers etc.', 'adminify'), |
| 247 |
'type' => 'fieldset', |
| 248 |
'fields' => [ |
| 249 |
[ |
| 250 |
'id' => 'enable_redirect_urls', |
| 251 |
'type' => 'switcher', |
| 252 |
'class' => 'adminify-pl-0', |
| 253 |
'text_on' => __('Show', 'adminify'), |
| 254 |
'text_off' => __('Hide', 'adminify'), |
| 255 |
'text_width' => 80, |
| 256 |
'default' => $this->get_default_field('redirect_urls_fields')['enable_redirect_urls'], |
| 257 |
], |
| 258 |
[ |
| 259 |
'id' => 'redirect_urls_options', |
| 260 |
'type' => 'fieldset', |
| 261 |
'title' => __(' ', 'adminify'), |
| 262 |
'class' => 'adminify-pt-0 adminify-pl-0 adminify-one-col adminify-tabs-content adminify-pro-notice', |
| 263 |
'fields' => [ |
| 264 |
[ |
| 265 |
'id' => 'redirect_urls_tabs', |
| 266 |
'type' => 'tabbed', |
| 267 |
'title' => '', |
| 268 |
'tabs' => [ |
| 269 |
[ |
| 270 |
'title' => __('Login/Register URL', 'adminify'), |
| 271 |
'fields' => $settings_fields, |
| 272 |
], |
| 273 |
[ |
| 274 |
'title' => __('Roles Redirect', 'adminify'), |
| 275 |
'fields' => $login_redirects, |
| 276 |
], |
| 277 |
], |
| 278 |
] |
| 279 |
], |
| 280 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options'], |
| 281 |
'dependency' => ['enable_redirect_urls', '==', 'true', true], |
| 282 |
] |
| 283 |
] |
| 284 |
] |
| 285 |
]; |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
public function login_register_url_fields(&$settings_fields) |
| 291 |
{ |
| 292 |
$settings_fields[] = [ |
| 293 |
'id' => 'new_login_url', |
| 294 |
'type' => 'text', |
| 295 |
'class' => 'new-login-url', |
| 296 |
'title' => __('New Login URL', 'adminify'), |
| 297 |
'desc' => __('Change the login URL and prevent access to the wp-admin and <code>' . wp_login_url() . '</code> page directly.', 'adminify'), |
| 298 |
'placeholder' => 'login', |
| 299 |
'before' => \get_site_url() . '/', |
| 300 |
// 'after' => '/', |
| 301 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['new_login_url'], |
| 302 |
]; |
| 303 |
|
| 304 |
$settings_fields[] = [ |
| 305 |
'id' => 'redirect_admin_url', |
| 306 |
'type' => 'text', |
| 307 |
'class' => 'new-login-url redirect-admin-url', |
| 308 |
'title' => __('Redirect Admin', 'adminify'), |
| 309 |
'desc' => __('Redirect users those are not logged in and trying to access <code>' . get_admin_url() . '</code>', 'adminify'), |
| 310 |
'placeholder' => '404', |
| 311 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['redirect_admin_url'], |
| 312 |
'before' => \get_site_url() . '/', |
| 313 |
// 'after' => '/', |
| 314 |
]; |
| 315 |
|
| 316 |
$settings_fields[] = [ |
| 317 |
'id' => 'new_register_url', |
| 318 |
'type' => 'text', |
| 319 |
'class' => 'new-login-url new-register-url', |
| 320 |
'title' => __('New Register URL', 'adminify'), |
| 321 |
'subtitle' => __('Use default registration: leave empty.', 'adminify'), |
| 322 |
'desc' => __('For default enable <strong>"Membership: Anyone can register"</strong> in <a href="' . admin_url('options-general.php#users_can_register') . '" style="color: var(--adminify-primary);">Settings → General.</a> To use custom registration: Create a Page, then paste its permalink here (e.g. /register).', 'adminify'), |
| 323 |
'placeholder' => 'wp-login.php?action=register', |
| 324 |
'before' => \get_site_url() . '/', |
| 325 |
// 'after' => '/', |
| 326 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['new_register_url'], |
| 327 |
]; |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* Settings Fields |
| 332 |
* |
| 333 |
* @return void |
| 334 |
*/ |
| 335 |
public function roles_redirect_tabs(&$roles_redirect) |
| 336 |
{ |
| 337 |
$login_redirect_fields = []; |
| 338 |
$logout_redirect_fields = []; |
| 339 |
$this->login_redirect_tab_fields($login_redirect_fields); |
| 340 |
$this->logout_redirect_tab_fields($logout_redirect_fields); |
| 341 |
|
| 342 |
$roles_redirect[] = [ |
| 343 |
'id' => 'roles_redirect_tabs', |
| 344 |
'type' => 'button_set', |
| 345 |
'title' => __('Redirect Rules Type', 'adminify'), |
| 346 |
'options' => array( |
| 347 |
'login' => __('Login Redirect ', 'adminify'), |
| 348 |
'logout' => __('Logout Redirect ', 'adminify'), |
| 349 |
), |
| 350 |
'default' => 'login', |
| 351 |
]; |
| 352 |
|
| 353 |
// Heading |
| 354 |
$roles_redirect[] = [ |
| 355 |
'type' => 'submessage', |
| 356 |
'style' => 'info', |
| 357 |
'class' => 'adminify-one-col', |
| 358 |
'content' => __('Add Login conditions to redirect users to different pages based on their user names, roles & capabilities', 'adminify'), |
| 359 |
'dependency' => ['roles_redirect_tabs', '==', 'login'], |
| 360 |
]; |
| 361 |
$roles_redirect[] = [ |
| 362 |
'id' => 'login_redirects', |
| 363 |
'type' => 'group', |
| 364 |
'title' => '', |
| 365 |
'accordion_title_prefix' => __('Login Redirect: ', 'adminify'), |
| 366 |
'accordion_title_number' => true, |
| 367 |
'accordion_title_auto' => true, |
| 368 |
'button_title' => __('Add New Login Redirect', 'adminify'), |
| 369 |
'fields' => $login_redirect_fields, |
| 370 |
'dependency' => ['roles_redirect_tabs', '==', 'login'], |
| 371 |
]; |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
// Logout Heading |
| 376 |
$roles_redirect[] = [ |
| 377 |
'type' => 'submessage', |
| 378 |
'style' => 'info', |
| 379 |
'class' => 'adminify-one-col', |
| 380 |
'content' => __('Add Logout conditions to redirect users to different pages based on their user names, roles & capabilities', 'adminify'), |
| 381 |
'dependency' => ['roles_redirect_tabs', '==', 'logout'], |
| 382 |
]; |
| 383 |
$roles_redirect[] = [ |
| 384 |
'id' => 'logout_redirects', |
| 385 |
'type' => 'group', |
| 386 |
'title' => '', |
| 387 |
'accordion_title_prefix' => __('Logout Redirect: ', 'adminify'), |
| 388 |
'accordion_title_number' => true, |
| 389 |
'accordion_title_auto' => true, |
| 390 |
'button_title' => __('Add New Logout Redirect', 'adminify'), |
| 391 |
'fields' => $logout_redirect_fields, |
| 392 |
'dependency' => ['roles_redirect_tabs', '==', 'logout'], |
| 393 |
]; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
/** |
| 398 |
* Login Redirect Fields |
| 399 |
* |
| 400 |
* @param [type] $login_redirect_fields |
| 401 |
* |
| 402 |
* @return void |
| 403 |
*/ |
| 404 |
public function login_redirect_tab_fields(&$login_redirect_fields) |
| 405 |
{ |
| 406 |
$login_redirect_fields[] = [ |
| 407 |
'id' => 'user_types', |
| 408 |
'type' => 'button_set', |
| 409 |
'title' => __('User Types', 'adminify'), |
| 410 |
'placeholder' => __('Select User Types', 'adminify'), |
| 411 |
'options' => array( |
| 412 |
'user_role' => __('User Role', 'adminify'), |
| 413 |
'user_name' => __('User Name', 'adminify'), |
| 414 |
'user_cap' => __('User Capability', 'adminify'), |
| 415 |
), |
| 416 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['login_redirects']['user_types'], |
| 417 |
]; |
| 418 |
|
| 419 |
// Select User Names |
| 420 |
$login_redirect_fields[] = [ |
| 421 |
'id' => 'redirect_user', |
| 422 |
'type' => 'select', |
| 423 |
'title' => __('User', 'adminify'), |
| 424 |
'placeholder' => __('Select a user', 'adminify'), |
| 425 |
'options' => 'users', |
| 426 |
'dependency' => ['user_types', '==', 'user_name'], |
| 427 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['login_redirects']['redirect_user'], |
| 428 |
]; |
| 429 |
|
| 430 |
// Select User Roles |
| 431 |
$login_redirect_fields[] = [ |
| 432 |
'id' => 'redirect_role', |
| 433 |
'type' => 'select', |
| 434 |
'title' => __('Role', 'adminify'), |
| 435 |
'placeholder' => __('Select a Role', 'adminify'), |
| 436 |
'options' => 'roles', |
| 437 |
'dependency' => ['user_types', '==', 'user_role'], |
| 438 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['login_redirects']['redirect_role'], |
| 439 |
]; |
| 440 |
|
| 441 |
// Select User Capability |
| 442 |
$login_redirect_fields[] = [ |
| 443 |
'id' => 'redirect_cap', |
| 444 |
'type' => 'select', |
| 445 |
'title' => __('Capability', 'adminify'), |
| 446 |
'placeholder' => __('Select a Capability', 'adminify'), |
| 447 |
'options' => '\WPAdminify\Inc\Classes\Helper::get_capability_options', |
| 448 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['login_redirects']['redirect_cap'], |
| 449 |
'dependency' => ['user_types', '==', 'user_cap'], |
| 450 |
]; |
| 451 |
|
| 452 |
|
| 453 |
// Redirect URL |
| 454 |
$login_redirect_fields[] = [ |
| 455 |
'id' => 'redirect_url', |
| 456 |
'type' => 'text', |
| 457 |
'class' => 'new-login-url', |
| 458 |
'title' => __('Redirect URL', 'adminify'), |
| 459 |
'placeholder' => __('e.g., my-dashboard or https://example.com/page', 'adminify'), |
| 460 |
'desc' => __('Enter a page slug (e.g., my-dashboard) or full URL. For multisite, use full URLs for cross-site redirects.', 'adminify'), |
| 461 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['login_redirects']['redirect_url'], |
| 462 |
]; |
| 463 |
|
| 464 |
// // Redirect Order |
| 465 |
// $login_redirect_fields[] = [ |
| 466 |
// 'id' => 'redirect_order', |
| 467 |
// 'type' => 'number', |
| 468 |
// 'title' => __('Order', 'adminify'), |
| 469 |
// 'default' => $this->get_default_field('redirect_urls_options')['login_redirects']['redirect_order'], |
| 470 |
// ]; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
/** |
| 477 |
* Logout Settings Fields |
| 478 |
* |
| 479 |
* @return void |
| 480 |
*/ |
| 481 |
public function logout_redirect_tab_fields(&$logout_redirect_fields) |
| 482 |
{ |
| 483 |
$logout_redirect_fields[] = [ |
| 484 |
'id' => 'user_types', |
| 485 |
'type' => 'button_set', |
| 486 |
'title' => __('User Types', 'adminify'), |
| 487 |
'placeholder' => __('Select User Types', 'adminify'), |
| 488 |
'options' => array( |
| 489 |
'user_role' => __('User Role', 'adminify'), |
| 490 |
'user_name' => __('User Name', 'adminify'), |
| 491 |
'user_cap' => __('User Capability', 'adminify'), |
| 492 |
), |
| 493 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['logout_redirects']['user_types'], |
| 494 |
]; |
| 495 |
|
| 496 |
// Select User Names |
| 497 |
$logout_redirect_fields[] = [ |
| 498 |
'id' => 'redirect_user', |
| 499 |
'type' => 'select', |
| 500 |
'title' => __('User', 'adminify'), |
| 501 |
'placeholder' => __('Select a user', 'adminify'), |
| 502 |
'options' => 'users', |
| 503 |
'dependency' => ['user_types', '==', 'user_name'], |
| 504 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['logout_redirects']['redirect_user'], |
| 505 |
]; |
| 506 |
|
| 507 |
// Select User Roles |
| 508 |
$logout_redirect_fields[] = [ |
| 509 |
'id' => 'redirect_role', |
| 510 |
'type' => 'select', |
| 511 |
'title' => __('Role', 'adminify'), |
| 512 |
'placeholder' => __('Select a Role', 'adminify'), |
| 513 |
'options' => 'roles', |
| 514 |
'dependency' => ['user_types', '==', 'user_role'], |
| 515 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['logout_redirects']['redirect_role'], |
| 516 |
]; |
| 517 |
|
| 518 |
// Select User Capability |
| 519 |
$logout_redirect_fields[] = [ |
| 520 |
'id' => 'redirect_cap', |
| 521 |
'type' => 'select', |
| 522 |
'title' => __('Capability', 'adminify'), |
| 523 |
'placeholder' => __('Select a Capability', 'adminify'), |
| 524 |
'options' => '\WPAdminify\Inc\Classes\Helper::get_capability_options', |
| 525 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['logout_redirects']['redirect_cap'], |
| 526 |
'dependency' => ['user_types', '==', 'user_cap'], |
| 527 |
]; |
| 528 |
|
| 529 |
|
| 530 |
// Redirect URL |
| 531 |
$logout_redirect_fields[] = [ |
| 532 |
'id' => 'redirect_url', |
| 533 |
'type' => 'text', |
| 534 |
'class' => 'new-login-url', |
| 535 |
'title' => __('Redirect URL', 'adminify'), |
| 536 |
'placeholder' => __('e.g., goodbye or https://example.com/page', 'adminify'), |
| 537 |
'desc' => __('Enter a page slug (e.g., goodbye) or full URL. For multisite, use full URLs for cross-site redirects.', 'adminify'), |
| 538 |
'default' => $this->get_default_field('redirect_urls_fields')['redirect_urls_options']['redirect_urls_tabs']['logout_redirects']['redirect_url'], |
| 539 |
]; |
| 540 |
|
| 541 |
// Redirect Order |
| 542 |
// $logout_redirect_fields[] = [ |
| 543 |
// 'id' => 'redirect_order', |
| 544 |
// 'type' => 'number', |
| 545 |
// 'title' => __('Order', 'adminify'), |
| 546 |
// 'default' => $this->get_default_field('redirect_urls_options')['logout_redirects']['redirect_order'], |
| 547 |
// ]; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
/** |
| 552 |
* Change Username Module |
| 553 |
*/ |
| 554 |
public function security_user_security(&$users){ |
| 555 |
|
| 556 |
$users_settings[] = [ |
| 557 |
'id' => 'change_username', |
| 558 |
'type' => 'switcher', |
| 559 |
'text_on' => __('Show', 'adminify'), |
| 560 |
'text_off' => __('Hide', 'adminify'), |
| 561 |
'text_width' => 80, |
| 562 |
'title' => __('Username Change', 'adminify'), |
| 563 |
'subtitle' => sprintf(__('Remove Comments for Media attachment Template <a href="%s">More Details</a> ', 'adminify'), esc_url('https://wpadminify.com/docs')), |
| 564 |
'default' => $this->get_default_field('users_security')['change_username'], |
| 565 |
]; |
| 566 |
$users_settings[] = [ |
| 567 |
'id' => 'limit_logins', |
| 568 |
'type' => 'switcher', |
| 569 |
'text_on' => __('Show', 'adminify'), |
| 570 |
'text_off' => __('Hide', 'adminify'), |
| 571 |
'text_width' => 80, |
| 572 |
'title' => __('Limit Login Attempts', 'adminify'), |
| 573 |
'subtitle' => sprintf(__('Prevent brute force attacks by limiting the number of failed login attempts per IP address. <a href="%s">More Details</a> ', 'adminify'), esc_url('https://wpadminify.com/docs')), |
| 574 |
'default' => $this->get_default_field('users_security')['limit_logins'], |
| 575 |
]; |
| 576 |
|
| 577 |
$users[] = array( |
| 578 |
'id' => 'users_security', |
| 579 |
'type' => 'fieldset', |
| 580 |
'title' => __('Users Security', 'adminify'), |
| 581 |
'subtitle' => __('Security for Users, Login/Logout etc.', 'adminify'), |
| 582 |
'fields' => $users_settings, |
| 583 |
'default' => $this->get_default_field('users_security'), |
| 584 |
); |
| 585 |
} |
| 586 |
|
| 587 |
/** |
| 588 |
* Security: WP JSON API's |
| 589 |
* |
| 590 |
* @param [type] $json_api_fields |
| 591 |
* |
| 592 |
* @return void |
| 593 |
*/ |
| 594 |
public function security_rest_api_fields( &$json_api_fieldset ) { |
| 595 |
|
| 596 |
$json_api_fields_data = [ |
| 597 |
'rest_api' => __('Disable REST API', 'adminify'), |
| 598 |
'powered' => __('Remove "X-Powered-By:..." from Server Response HTTP headers', 'adminify'), |
| 599 |
]; |
| 600 |
|
| 601 |
$json_api_fields = [ |
| 602 |
[ |
| 603 |
'id' => 'security_rest_api_enable', |
| 604 |
'type' => 'switcher', |
| 605 |
'class' => 'adminify-pl-0 adminify-pt-0', |
| 606 |
'title' => __('', 'adminify'), |
| 607 |
'text_on' => __('Show', 'adminify'), |
| 608 |
'text_off' => __('Hide', 'adminify'), |
| 609 |
'text_width' => 80, |
| 610 |
'default' => $this->get_default_field('security_rest_api')['security_rest_api_enable'], |
| 611 |
], |
| 612 |
[ |
| 613 |
'id' => 'security_rest_api_data', |
| 614 |
'type' => 'checkbox', |
| 615 |
'title' => __('', 'adminify'), |
| 616 |
'class' => 'adminify-one-col', |
| 617 |
'options' => $json_api_fields_data, |
| 618 |
'default' => $this->get_default_field('security_rest_api')['security_rest_api_data'], |
| 619 |
'dependency' => ['security_rest_api_enable', '==', 'true', true], |
| 620 |
] |
| 621 |
]; |
| 622 |
|
| 623 |
$json_api_fieldset[] = array( |
| 624 |
'id' => 'security_rest_api', |
| 625 |
'type' => 'fieldset', |
| 626 |
'title' => __('REST API', 'adminify'), |
| 627 |
'subtitle' => __('Disable REST API access for non-authenticated users and remove URL traces from <head>, HTTP headers and WP RSD endpoint.', 'adminify'), |
| 628 |
'fields' => $json_api_fields, |
| 629 |
'default' => $this->get_default_field('security_rest_api'), |
| 630 |
); |
| 631 |
|
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
/** |
| 636 |
* Security: Post & Archives |
| 637 |
*/ |
| 638 |
public function security_archive_fields( &$archive_fields ) { |
| 639 |
$archive_fields_data = [ |
| 640 |
'last_modified_date' => __('Display Last Post Updated Date', 'adminify' ), |
| 641 |
'capital_p_dangit' => __('Remove Capital "P" Dangit', 'adminify' ), |
| 642 |
'archives_date' => __('Redirect "Date Archives" Template to Homepage', 'adminify' ), |
| 643 |
'archives_author' => __('Redirect "Author Archives" Template to Homepage', 'adminify' ), |
| 644 |
'archives_tag' => __('Redirect "Tag Archives" Template to Homepage', 'adminify' ), |
| 645 |
'archives_category' => __('Redirect "Category Archives" Template to Homepage', 'adminify' ), |
| 646 |
'archives_postformat' => __('Redirect "Post Format Archives" Template to Homepage', 'adminify' ), |
| 647 |
'archives_search' => __('Redirect "Search Template" to Homepage', 'adminify' ), |
| 648 |
]; |
| 649 |
|
| 650 |
$archive_fields[] = [ |
| 651 |
'id' => 'post_archives', |
| 652 |
'title' => __('Post & Archives', 'adminify'), |
| 653 |
'subtitle' => __('Redirect unused Archives pages to homepage', 'adminify'), |
| 654 |
'type' => 'fieldset', |
| 655 |
'fields' => [ |
| 656 |
[ |
| 657 |
'id' => 'post_archives_enable', |
| 658 |
'type' => 'switcher', |
| 659 |
'title' => __('', 'adminify'), |
| 660 |
'text_on' => __('Show', 'adminify'), |
| 661 |
'text_off' => __('Hide', 'adminify'), |
| 662 |
'text_width' => 80, |
| 663 |
'class' => 'adminify-pl-0 adminify-pt-0', |
| 664 |
'default' => $this->get_default_field('post_archives')['post_archives_enable'], |
| 665 |
], |
| 666 |
[ |
| 667 |
'id' => 'post_archives_data', |
| 668 |
'type' => 'checkbox', |
| 669 |
'class' => 'adminify-one-col', |
| 670 |
'title' => __('', 'adminify'), |
| 671 |
'options' => $archive_fields_data, |
| 672 |
'default' => $this->get_default_field('post_archives')['post_archives_data'], |
| 673 |
'dependency' => ['post_archives_enable', '==', 'true', true], |
| 674 |
], |
| 675 |
] |
| 676 |
]; |
| 677 |
|
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
/** |
| 682 |
* Custom Gravatar Image |
| 683 |
* |
| 684 |
* @param [type] $fields |
| 685 |
* |
| 686 |
* @return void |
| 687 |
*/ |
| 688 |
public function security_custom_gravatar( &$gravatar_image ){ |
| 689 |
|
| 690 |
// Comments Avatar |
| 691 |
$custom_gravatar_settings = [ |
| 692 |
[ |
| 693 |
'id' => 'enable', |
| 694 |
'type' => 'switcher', |
| 695 |
'title' => '', |
| 696 |
'class' => 'adminify-pt-0 adminify-pl-0 adminify-col-fit', |
| 697 |
'label' => sprintf(__('Add your Custom Gravatar Images for Comments. Select Avatar Image from <a href="%s">Settings>Discussion>Default Avatar</a>.', 'adminify'), esc_url(admin_url('options-discussion.php'))), |
| 698 |
'text_on' => __('Yes', 'adminify'), |
| 699 |
'text_off' => __('No', 'adminify'), |
| 700 |
'text_width' => 80, |
| 701 |
'default' => $this->get_default_field('enable'), |
| 702 |
], |
| 703 |
[ |
| 704 |
'id' => 'image', |
| 705 |
'type' => 'repeater', |
| 706 |
'title' => __('Add Avatar Image', 'adminify'), |
| 707 |
'fields' => [ |
| 708 |
[ |
| 709 |
'id' => 'avatar_image', |
| 710 |
'type' => 'media', |
| 711 |
'title' => __('Image', 'adminify'), |
| 712 |
'library' => 'image', |
| 713 |
], |
| 714 |
[ |
| 715 |
'id' => 'avatar_name', |
| 716 |
'type' => 'text', |
| 717 |
'title' => __('Name', 'adminify'), |
| 718 |
], |
| 719 |
], |
| 720 |
'default' => $this->get_default_field('image'), |
| 721 |
'dependency' => ['enable', '==', 'true'], |
| 722 |
] |
| 723 |
]; |
| 724 |
|
| 725 |
$gravatar_image[] = [ |
| 726 |
'id' => 'custom_gravatar', |
| 727 |
'type' => 'fieldset', |
| 728 |
'title' => __('Custom Gravatar Images', 'adminify'), |
| 729 |
'fields' => $custom_gravatar_settings, |
| 730 |
]; |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
/** |
| 735 |
* Disable Comments |
| 736 |
* |
| 737 |
* @param [type] $fields |
| 738 |
* |
| 739 |
* @return void |
| 740 |
*/ |
| 741 |
public function security_others( &$fields ){ |
| 742 |
$fields[] = [ |
| 743 |
'id' => 'disable_automatic_emails', |
| 744 |
'type' => 'switcher', |
| 745 |
'class' => 'adminify-pro-fieldset adminify-pro-notice', |
| 746 |
'title' => sprintf(__('Disable Automatic Updates Emails %s', 'adminify'), Utils::adminify_upgrade_pro_badge()), |
| 747 |
'subtitle' => __('Stop getting emails about automatic updates on your WordPress site.', 'adminify'), |
| 748 |
'text_on' => __('Yes', 'adminify'), |
| 749 |
'text_off' => __('No', 'adminify'), |
| 750 |
'text_width' => 80, |
| 751 |
'default' => $this->get_default_field('disable_automatic_emails'), |
| 752 |
]; |
| 753 |
|
| 754 |
$fields[] = [ |
| 755 |
'id' => 'disable_language_switcher_login', |
| 756 |
'type' => 'switcher', |
| 757 |
'class' => 'adminify-pro-fieldset adminify-pro-notice', |
| 758 |
'title' => sprintf(__('Disable Login Screen Language Switcher %s', 'adminify'), Utils::adminify_upgrade_pro_badge()), |
| 759 |
'subtitle' => __('Hide the Language Switcher on the default WordPress login screen.', 'adminify'), |
| 760 |
'text_on' => __('Yes', 'adminify'), |
| 761 |
'text_off' => __('No', 'adminify'), |
| 762 |
'text_width' => 80, |
| 763 |
'default' => $this->get_default_field('disable_language_switcher_login'), |
| 764 |
]; |
| 765 |
} |
| 766 |
|
| 767 |
/** |
| 768 |
* Disable Comments |
| 769 |
* |
| 770 |
* @param [type] $fields |
| 771 |
* |
| 772 |
* @return void |
| 773 |
*/ |
| 774 |
public function security_disable_comments( &$fields ){ |
| 775 |
|
| 776 |
// Disable Comments |
| 777 |
$disable_comments_for = [ |
| 778 |
'admin_bar' => __('Remove "Comments" from Admin Bar', 'adminify'), |
| 779 |
'menu_redirect' => __('Admin Menu "Comments" Redirect to "wp-admin"', 'adminify'), |
| 780 |
'admin_menu' => __('Remove Admin Menu "Comments"', 'adminify'), |
| 781 |
'discussion_menu' => __('Remove Discussion Menu from "Settings>Discussion" Sub Menu', 'adminify'), |
| 782 |
'close_front' => __('Close Comments from front-end', 'adminify'), |
| 783 |
'comments_notes' => __('Remove "Your email address will not be published..." from comment form template', 'adminify'), |
| 784 |
'comments_url_field' => __('Remove website Field (URL) from comment form template', 'adminify'), |
| 785 |
'replace_author_link' => sprintf(__('Remove Link from comment "Author Name" & replace to JavaScript? %s'), Utils::adminify_upgrade_pro_class()), |
| 786 |
'replace_comment_link' => sprintf(__('Comments Content disable auto linking, display comments links as plain text, replace Comment Links to JavaScript? %s', 'adminify'), Utils::adminify_upgrade_pro_class()), |
| 787 |
'hide_existing' => sprintf(__('Hide Existing Comments from Frontend? %s', 'adminify'), Utils::adminify_upgrade_pro_class()), |
| 788 |
]; |
| 789 |
|
| 790 |
// check if WP_Widget_Recent_Comments is used |
| 791 |
// $recentcomments = []; |
| 792 |
if ( !is_active_widget(false, false, 'WP_Widget_Recent_Comments', true) ) { |
| 793 |
$disable_comments_for['recentcomments'] = __('Remove Hardcoded ".recentcomments" CSS for default "Recent Comments" widget. i.e ', 'adminify'); |
| 794 |
$disable_comments_for = array_merge($disable_comments_for, $disable_comments_for); |
| 795 |
} |
| 796 |
|
| 797 |
$fields[] = [ |
| 798 |
'id' => 'disable_comments', |
| 799 |
'title' => __('Disable Comments', 'adminify'), |
| 800 |
'subtitle' => __('Disable comments for some or all public post types. When disabled, existing comments will also be hidden on the frontend.', 'adminify'), |
| 801 |
'type' => 'fieldset', |
| 802 |
'fields' => [ |
| 803 |
[ |
| 804 |
'id' => 'enable_disable_comments', |
| 805 |
'type' => 'switcher', |
| 806 |
'title' => __('', 'adminify'), |
| 807 |
'class' => 'adminify-pl-0 adminify-pt-0', |
| 808 |
'text_on' => __('Show', 'adminify'), |
| 809 |
'text_off' => __('Hide', 'adminify'), |
| 810 |
'text_width' => 80, |
| 811 |
'default' => $this->get_default_field('disable_comments')['enable_disable_comments'], |
| 812 |
], |
| 813 |
[ |
| 814 |
'id' => 'post_types', |
| 815 |
'type' => 'checkbox', |
| 816 |
'title' => __('for Post Types', 'adminify'), |
| 817 |
'subtitle' => __('Check for enable Post Types', 'adminify'), |
| 818 |
'options' => 'WPAdminify\Inc\Admin\Options\Productivity::get_all_post_types', |
| 819 |
'default' => $this->get_default_field('disable_comments')['post_types'], |
| 820 |
'dependency' => ['enable_disable_comments', '==', 'true', true], |
| 821 |
], |
| 822 |
// [ |
| 823 |
// 'id' => 'disable_comments_post_types', |
| 824 |
// 'type' => 'notice', |
| 825 |
// 'style' => 'warning', |
| 826 |
// 'content' => Utils::adminify_upgrade_pro(), |
| 827 |
// 'dependency' => [ |
| 828 |
// [ 'post_types', 'not-any', 'post,page', 'true' ], |
| 829 |
// [ 'post_types', '!=', '', 'true' ], |
| 830 |
// ], |
| 831 |
// ], |
| 832 |
[ |
| 833 |
'id' => 'apply_for', |
| 834 |
'type' => 'checkbox', |
| 835 |
'title' => __('', 'adminify'), |
| 836 |
'class' => 'adminify-one-col', |
| 837 |
'options' => $disable_comments_for, |
| 838 |
'default' => $this->get_default_field('disable_comments')['apply_for'], |
| 839 |
'dependency' => ['enable_disable_comments', '==', 'true', true], |
| 840 |
] |
| 841 |
] |
| 842 |
]; |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
public function tweak_settings() { |
| 847 |
if ( ! class_exists( 'ADMINIFY' ) ) { |
| 848 |
return; |
| 849 |
} |
| 850 |
|
| 851 |
|
| 852 |
$fields = []; |
| 853 |
|
| 854 |
$fields[] = [ |
| 855 |
'id' => 'security_subheading', |
| 856 |
'type' => 'subheading', |
| 857 |
'content' => Utils::adminfiy_help_urls( |
| 858 |
__('"WordPress" White Label Settings', 'adminify'), |
| 859 |
'https://wpadminify.com/docs/security/', |
| 860 |
'', |
| 861 |
'https://www.facebook.com/groups/jeweltheme', |
| 862 |
\WPAdminify\Inc\Admin\AdminSettings::support_url() |
| 863 |
) |
| 864 |
]; |
| 865 |
|
| 866 |
$this->security_redirect_urls( $fields ); |
| 867 |
// $this->security_user_security( $fields ); |
| 868 |
$this->security_head_fields( $fields ); |
| 869 |
$this->security_feed_fields( $fields ); |
| 870 |
$this->security_rest_api_fields( $fields ); |
| 871 |
$this->security_disable_comments( $fields ); |
| 872 |
$this->security_archive_fields( $fields ); |
| 873 |
// $this->security_others( $fields ); |
| 874 |
|
| 875 |
$this->security_custom_gravatar( $fields ); |
| 876 |
|
| 877 |
$fields = apply_filters('adminify_settings/security', $fields, $this); |
| 878 |
|
| 879 |
// Tweaks Section |
| 880 |
\ADMINIFY::createSection( |
| 881 |
$this->prefix, |
| 882 |
[ |
| 883 |
'title' => __( 'Security', 'adminify' ), |
| 884 |
'id' => 'security', |
| 885 |
'icon' => 'fas fa-shield-alt', |
| 886 |
'fields' => $fields, |
| 887 |
] |
| 888 |
); |
| 889 |
} |
| 890 |
} |
| 891 |
} |
| 892 |
|