This commit is contained in:
2026-04-26 23:47:49 +02:00
parent 1b95f03d1e
commit b073e009d8
5288 changed files with 1112699 additions and 55536 deletions

View File

@@ -0,0 +1,122 @@
/**
* All of the CSS for your admin-specific functionality should be
* included in this file.
*/
.pda-pwd-tools {
margin-bottom: 0.5rem;
}
.pda-pwd-tools input[type=radio].disabled, .pda-pwd-tools input[type=radio].disabled:checked:before, .pda-pwd-tools input[type=radio]:disabled, .pda-pwd-tools input[type=radio]:disabled:checked:before, .pda-pwd-tools input[type=checkbox].disabled, .pda-pwd-tools input[type=checkbox].disabled:checked:before, .pda-pwd-tools input[type=checkbox]:disabled, .pda-pwd-tools input[type=checkbox]:disabled:checked:before {
opacity: 1;
cursor: inherit;
}
.pda-pwd-tbl-actions {
cursor: pointer;
}
/**
Metabox css
*/
textarea[name="wpp_multiple_password"] {
width: 94%;
}
#all_roles_select {
margin-top: 0;
margin-bottom: 5px;
}
#all_roles_select span {
border-radius: 6px 0;
padding: 0rem 0.2rem;
background: #FFFF00;
cursor: pointer;
transition: 0.4s;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
max-width: 100%;
display: inline-block;
}
div#passwords-roles-map label {
display: block;
}
.pda-selected-role-select2,
input.post-protection-password,
textarea[name="wpp_multiple_password"] {
width: 100%;
}
.ppwp_set_password_type {
width: 70%;
}
#ppwp_set_password_metabox .ppwp_apply_password {
display: block;
margin-bottom: 5px;
}
#ppwp_set_password_metabox .ppwp_show_hide_password_roles {
margin-top: 5px;
}
#ppwp_set_password_metabox .ppwp_input_set_type_password {
margin-top: 5px;
}
#ppwp_set_password_metabox .ppwp_default_hide_checkbox_roles {
display: none;
}
.ppwp-button-hide {
float: right;
padding: 0;
cursor: pointer;
text-decoration: underline;
}
.ppwp-button-submit {
color: #555;
border-color: #ccc;
background: #f7f7f7;
box-shadow: 0 1px 0 #ccc;
vertical-align: top;
display: inline-block;
text-decoration: none;
font-size: 13px;
line-height: 26px;
height: 28px;
margin: 0;
padding: 0 10px 1px;
cursor: pointer;
border-width: 1px;
border-style: solid;
-webkit-appearance: none;
border-radius: 3px;
white-space: nowrap;
box-sizing: border-box;
}
.ppwp-button-submit:hover {
background: #fafafa;
border-color: #999;
color: #23282d;
}
#passwords-roles-map .ppwp-wrap-submit-hide {
margin-top: 13px;
}
.ppwp_multiple_password {
width: 100%;
}
.ppwp_wrap_role_password {
margin-top: 5px;
}
.pda-selected-role-select2 {
box-sizing: border-box;
}

View File

@@ -0,0 +1,190 @@
(function (window, $) {
$(function () {
setDefaultPassword();
handleChangeElement();
$("#save_password").click(function (evt) {
evt.preventDefault();
const passwords = $('.ppwp_multiple_password').val().split("\n").map(pass => pass.trim()).filter(pass => pass !== "");
const rolePassword = $(".post-protection-password").val().trim();
const roleSelected = $("#is_role_selected").val();
if (isErrorPassword(passwords)) {
return;
}
savePassword({
save_password: rolePassword,
is_role_selected: roleSelected,
id_page_post: $("#id_page_post").val(),
ppwp_multiple_password: passwords.length <= 0 ? '' : passwords,
}, function (result, error) {
$('#save_password').text('Submit');
$('#save_password').prop("disabled", false);
const pluginName = 'PPWP Lite';
if (result) {
changeValueRoles(result);
if (roleSelected === 'global') {
$('#ppwp_multiple_password').val(passwords.join('\n'));
} else {
$('#post-protection-password').val(rolePassword);
}
toastr.success('Great! Youve updated the password successfully.', pluginName);
}
if (error) {
if (400 === error.status) {
toastr.error(error.responseJSON.message, pluginName);
} else {
toastr.error('Opps! Something went wrong. Please try again.', pluginName);
}
console.log('Data error', error);
}
});
});
});
function checkPasswordNoSpace(password) {
return password.indexOf(" ") === -1
}
function handleChangeElement() {
$("#post-protection-password").change(function () {
if ($(this).val().trim().indexOf(" ") !== -1) {
toastr.error(save_password_data.error_message.space_password, 'Password Protect WordPress');
$('#save_password').prop("disabled", true);
} else {
$('#save_password').prop("disabled", false);
}
});
$(".ppwp_multiple_password").change(function () {
const passwords = $(this).val().split("\n").map(pass => pass.trim()).filter(pass => pass !== "");
if ((new Set(passwords)).size !== passwords.length) {
toastr.error(save_password_data.error_message.duplicate_password, 'Password Protect WordPress');
$('#save_password').prop("disabled", true);
return;
} else {
$('#save_password').prop("disabled", false);
}
if (!passwords.every(checkPasswordNoSpace)) {
toastr.error(save_password_data.error_message.space_password, 'Password Protect WordPress');
$('#save_password').prop("disabled", true);
return;
} else {
$('#save_password').prop("disabled", false);
}
});
let arrayPassword = {};
$('.pda-selected-role-select2').on('focus', function () {
let role = this.value;
// Add Value to MAP
arrayPassword[role] = $('#post-protection-password').val();
$('#' + role).val($('#post-protection-password').val());
}).change(function () {
let role = $('.pda-selected-role-select2').val();
let value;
if (typeof (arrayPassword[role]) !== 'undefined') {
value = arrayPassword[role];
} else {
value = $('#post-protection-password-' + role).text() === "" ? "" : $('#post-protection-password-' + role).text();
}
if (role === 'global') {
$('#post-protection-password').hide();
$('#ppwp_multiple_password').show();
} else {
$('#post-protection-password').show();
$('#ppwp_multiple_password').hide();
}
$('#post-protection-password').val(value);
if ($("#is_role_selected").val() === 'global') {
$("#label-password-post").text("Passwords")
} else {
$("#label-password-post").text("Password")
}
});
$('.pda-selected-role-select2').trigger('change');
$('.edit-post-protection').click(function () {
$('#post-protection').show();
$(this).hide();
});
$('.button-cancel').click(function () {
$('#post-protection').hide();
$('.edit-post-protection').show();
});
}
function setDefaultPassword() {
const role = $('.pda-selected-role-select2').val();
if (role) {
const value = $('#post-protection-password-' + role).text() === "" ? "" : $('#post-protection-password-' + role).text();
$('#post-protection-password').val(value);
}
}
function isErrorPassword(passwords) {
const roleSelected = $('.pda-selected-role-select2').val();
if (roleSelected !== 'global') {
return false;
}
if (!passwords.every(checkPasswordNoSpace)) {
toastr.error(save_password_data.error_message.space_password, 'Password Protect WordPress');
$('#save_password').prop("disabled", true);
return true;
}
if ((new Set(passwords)).size !== passwords.length) {
toastr.error(save_password_data.error_message.duplicate_password, 'Password Protect WordPress');
$('#save_password').prop("disabled", true);
return true;
}
}
function savePassword(settings, cb) {
const _data = {
action: 'ppw_free_set_password',
settings: settings,
security_check: $('#ppw_meta_box_nonce').val(),
}
$('#save_password').text('Submitting');
$('#save_password').prop("disabled", true);
$.ajax({
url: save_password_data.ajax_url,
type: 'POST',
data: _data,
success: function (data) {
cb(data, null);
},
error: function (error) {
cb(null, error);
},
timeout: 5000
});
}
function changeValueRoles(data) {
const rolesFiltered = Object.keys(data)
.filter(function (role) {
return '' !== data[role];
});
const roles = rolesFiltered.map(function (role) {
return "<span>" + role + "</span>";
}).join(' ');
const rolesText = rolesFiltered.length > 1 ? rolesFiltered.length + ' roles' : rolesFiltered.length + ' role';
$("#all_roles_select").html(roles);
$("#number_roles").text(rolesText);
}
})(window, jQuery);

View File

@@ -0,0 +1,100 @@
<?php
add_meta_box(
'ppw_add_meta_box',
__( 'Password Protect WordPress', PPW_Constants::DOMAIN ),
apply_filters( PPW_Constants::HOOK_FUNCTION_HANDLE_META_BOX, 'ppw_free_feature_set_password_in_meta_box' ),
apply_filters( PPW_Constants::HOOK_META_BOX_POSITION, array( 'page', 'post' ) ),
'side',
'high'
);
/**
* Function to render meta box set password for pages, posts in free version
*
* @param $post
*/
function ppw_free_feature_set_password_in_meta_box( $post ) {
$raw_data = get_post_meta( $post->ID, PPW_Constants::POST_PROTECTION_ROLES, true );
$protected_roles = ppw_free_fix_serialize_data( $raw_data );
$multiple_passwords = get_post_meta( $post->ID, PPW_Constants::GLOBAL_PASSWORDS, true );
$password = '';
if ( ! empty( $multiple_passwords ) && is_array( $multiple_passwords ) ) {
$password = esc_textarea( implode( "\n", $multiple_passwords ) );
$global_password = implode( ' ', $multiple_passwords );
$protected_roles['global'] = $global_password;
}
$have_password_roles = array_keys( array_filter( $protected_roles, function ( $val ) {
return $val !== '';
} ) );
$no_have_password_roles = sizeof( $have_password_roles );
$no_roles = $no_have_password_roles > 1 ? $no_have_password_roles . ' roles' : $no_have_password_roles . ' role';
$roles = get_editable_roles();
?>
<div id="passwords-roles-map" class="ppwp-post-protection">
<input type="hidden" id="ppw_meta_box_nonce"
value="<?php echo esc_attr( wp_create_nonce( PPW_Constants::META_BOX_NONCE ) ); ?>">
<span id="post-protection-status"> Password protected by
<span id="number_roles"><?php echo esc_html( $no_roles ); ?></span>
</span><a href="#protection" class="edit-post-protection hide-if-no-js pup-tooltip" role="button"
style="display: inline;">
<span class="roles" aria-hidden="true">Edit</span>
</a>
<div style="display: none" id="post-protection">
<p id="all_roles_select">
<?php foreach ( $have_password_roles as $key => $role ): ?>
<span><?php echo esc_html( $role ); ?></span>
<?php endforeach; ?>
</p>
<div>
<?php foreach ( $protected_roles as $key => $value ): ?>
<span style="display: none"
id="post-protection-password-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></span>
<?php endforeach; ?>
</div>
<div>
<label for="post-protection-role">Role</label>
<select class="pda-selected-role-select2" name="post-protection-role" id="is_role_selected">
<option value="global">global</option>
<?php foreach ( $roles as $role_name => $role_info ): ?>
<option <?php echo esc_attr( in_array( $role_name, array() ) ? 'selected="selected"' : '' ); ?>" value="<?php echo esc_attr( $role_name ); ?>">
<?php echo esc_html( $role_name ); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<!-- Region Data Save in HTML Tag START-->
<?php foreach ( $roles as $role_name => $role_info ): ?>
<?php $value = array_key_exists( $role_name, $protected_roles ) ? $protected_roles[ $role_name ] : ""; ?>
<input type="hidden" id="<?php echo esc_attr( $role_name ); ?>"
name="data[<?php echo esc_attr( $role_name ); ?>]"
value="<?php echo esc_attr( $value ); ?>"/>
<?php endforeach; ?>
<!-- Region Data Save in HTML Tag END-->
<div class="ppwp_wrap_role_password">
<label id="label-password-post">Passwords</label>
<input autocomplete="off" type="text" class="password post-protection-password"
placeholder="Enter password"
name="post-protection-password"
id="post-protection-password"/>
<textarea rows="3" id="ppwp_multiple_password" class="ppwp_multiple_password"
placeholder="<?php echo esc_attr( 'Enter one password per line', 'wp-protect-password' ); ?>"><?php echo esc_html( $password, 'wp-protect-password' ) ?></textarea>
</div>
<p class="ppwp-wrap-submit-hide">
<input type="hidden" value="<?php echo esc_attr( $post->ID ); ?>" id="id_page_post">
<button href="#protection" id="save_password" class="ppwp-button-submit">Submit</button>
<a class="cancel-pda-protection-map button-cancel ppwp-button-hide">Hide</a>
</p>
</div>
</div>
<?php
$asset_services = new PPW_Asset_Services( '', '' );
$asset_services->load_assets_for_meta_box();
}