Skip to content

Commit

Permalink
Code changed to met the WordPress requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
webdeveloper committed Jun 17, 2021
1 parent be8c577 commit 1a72d20
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
50 changes: 15 additions & 35 deletions admin/sabs_admin_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,15 @@

<?php
$currFabOptions = get_option('sabs');
$errors = isset($_SESSION['sabsValidationErrors']) && !empty($_SESSION['sabsValidationErrors']) && is_array($_SESSION['sabsValidationErrors']) ? $_SESSION['sabsValidationErrors'] : [];
$sabsOldFormData = isset($_SESSION['sabsOldFormData']) && !empty($_SESSION['sabsOldFormData']) && is_array($_SESSION['sabsOldFormData']) ? $_SESSION['sabsOldFormData'] : [];

if(isset($_SESSION['sabsValidationErrors'])) {
unset($_SESSION['sabsValidationErrors']);
}

if(isset($_SESSION['sabsOldFormData'])) {
unset($_SESSION['sabsOldFormData']);
}

if(isset($_SESSION['saveSuccess'])) {
$saveSuccess = true;
unset($_SESSION['saveSuccess']);
}

if(isset($_SESSION['invalidDataAlert'])) {
$invalidDataAlert = true;
unset($_SESSION['invalidDataAlert']);
}
?>

<?php if(isset($saveSuccess)): ?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'All changes are saved!' ); ?></p>
<p><?php echo esc_html( 'All changes are saved!' ); ?></p>
</div>
<?php elseif(isset($invalidDataAlert)): ?>
<div class="notice notice-error is-dismissible">
<p><?php _e( 'Invalid data found. Please correct them all and continue.' ); ?></p>
<p><?php echo esc_html( 'Invalid data found. Please correct them all and continue.' ); ?></p>
</div>
<?php endif; ?>

Expand All @@ -43,7 +23,7 @@
<td colspan="2">
<fieldset>
<label for="sabs-enabled">
<input type="checkbox" name="sabs[enabled]" id="sabs-enabled" class="" value="yes" <?php if(($sabsOldFormData['enabled'] ?? ($currFabOptions['enabled'] ?? 'no')) == 'yes'): ?> checked <?php endif; ?>>
<input type="checkbox" name="sabsEnabled" id="sabs-enabled" class="" value="yes" <?php if((isset($oldEnabled) ? $oldEnabled : (isset($currFabOptions['enabled']) ? $currFabOptions['enabled'] : 'no')) == 'yes'): ?> checked <?php endif; ?>>
Enable the Buttons
</label>
</fieldset>
Expand All @@ -64,17 +44,17 @@
<td>
<fieldset>
<label for="sabs-whatsApp">
<input type="text" name="sabs[whatsApp]" id="sabs-whatsApp" class="<?php if(isset($errors['whatsApp'])): ?>invalid<?php endif; ?>" value="<?php _e($sabsOldFormData['whatsApp'] ?? ($currFabOptions['buttons']['whatsApp'] ?? '')); ?>" placeholder="Enter Your WhatsApp No">
<?php if(isset($errors['whatsApp'])): ?>
<input type="text" name="sabsWhatsApp" id="sabs-whatsApp" class="<?php if(isset($errWhatsApp)): ?>invalid<?php endif; ?>" value="<?php echo esc_attr(isset($oldWhatsApp) ? $oldWhatsApp :($currFabOptions['buttons']['whatsApp'] ?? '')); ?>" placeholder="Enter Your WhatsApp No">
<?php if(isset($errWhatsApp)): ?>
<span class="invalid"><i class="icofont-warning-alt"></i></span>
<?php endif; ?>
</label>
</fieldset>
<p class="description">
<i class="icofont-info-circle"></i> Mobile number should be in the format: <code>[+][Country Code][Your 10 Digit Mobile Number]</code>.<br>For example: +919876543210 (Without any spaces)
</p>
<?php if(isset($errors['whatsApp'])): ?>
<p class="description invalid-feedback"><?php _e($errors['whatsApp']); ?></p>
<?php if(isset($errWhatsApp)): ?>
<p class="description invalid-feedback"><?php echo esc_html($errWhatsApp); ?></p>
<?php endif; ?>
</td>
</tr>
Expand All @@ -90,17 +70,17 @@
<td>
<fieldset>
<label for="sabs-phone">
<input type="text" name="sabs[phone]" id="sabs-phone" class="<?php if(isset($errors['phone'])): ?>invalid<?php endif; ?>" value="<?php _e($sabsOldFormData['phone'] ?? ($currFabOptions['buttons']['phone'] ?? '')); ?>" placeholder="Enter Your Phone Number">
<?php if(isset($errors['phone'])): ?>
<input type="text" name="sabsPhone" id="sabs-phone" class="<?php if(isset($errPhone)): ?>invalid<?php endif; ?>" value="<?php echo esc_attr(isset($oldPhone) ? $oldPhone : ($currFabOptions['buttons']['phone'] ?? '')); ?>" placeholder="Enter Your Phone Number">
<?php if(isset($errPhone)): ?>
<span class="invalid"><i class="icofont-warning-alt"></i></span>
<?php endif; ?>
</label>
</fieldset>
<p class="description">
<i class="icofont-info-circle"></i> Mobile number should be in the format: <code>[+][Country Code][Your 10 Digit Mobile Number]</code>.<br>For example: +919876543210 (Without any spaces)
</p>
<?php if(isset($errors['phone'])): ?>
<p class="description invalid-feedback"><?php _e($errors['phone']); ?></p>
<?php if(isset($errPhone)): ?>
<p class="description invalid-feedback"><?php echo esc_html($errPhone); ?></p>
<?php endif; ?>
</td>
</tr>
Expand All @@ -116,14 +96,14 @@
<td>
<fieldset>
<label for="sabs-email">
<input type="email" name="sabs[email]" id="sabs-email" class="regular-text <?php if(isset($errors['email'])): ?>invalid<?php endif; ?>" value="<?php _e($sabsOldFormData['email'] ?? ($currFabOptions['buttons']['email'] ?? '')); ?>" placeholder="Enter Your E-mail Address">
<?php if(isset($errors['email'])): ?>
<input type="email" name="sabsEmail" id="sabs-email" class="regular-text <?php if(isset($errEmail)): ?>invalid<?php endif; ?>" value="<?php echo esc_attr(isset($oldEmail) ? $oldEmail : ($currFabOptions['buttons']['email'] ?? '')); ?>" placeholder="Enter Your E-mail Address">
<?php if(isset($errEmail)): ?>
<span class="invalid"><i class="icofont-warning-alt"></i></span>
<?php endif; ?>
</label>
</fieldset>
<?php if(isset($errors['email'])): ?>
<p class="description invalid-feedback"><?php _e($errors['email']); ?></p>
<?php if(isset($errEmail)): ?>
<p class="description invalid-feedback"><?php echo esc_html($errEmail); ?></p>
<?php endif; ?>
</td>
</tr>
Expand Down
6 changes: 3 additions & 3 deletions public/sabs_container.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

<div class="sabs-container">
<?php if(isset($sabsButtons['whatsApp'])): ?>
<a href="https://wa.me/<?php _e(str_replace(' ', '', $sabsButtons['whatsApp'])); ?>" class="fab sab-whatsapp sab-with-notification" tabindex="-1">
<a href="https://wa.me/<?php echo esc_attr(str_replace(' ', '', $sabsButtons['whatsApp'])); ?>" class="fab sab-whatsapp sab-with-notification" tabindex="-1">
<i class="icofont-whatsapp"></i>
</a>
<?php endif; ?>
<?php if(isset($sabsButtons['phone'])): ?>
<a href="tel:<?php _e($sabsButtons['phone']); ?>" class="fab sab-phone" tabindex="-1">
<a href="tel:<?php echo esc_attr($sabsButtons['phone']); ?>" class="fab sab-phone" tabindex="-1">
<i class="icofont-phone"></i>
</a>
<?php endif; ?>
<?php if(isset($sabsButtons['email'])): ?>
<a href="tel:<?php _e($sabsButtons['email']); ?>" class="fab sab-email" tabindex="-1">
<a href="mailto:<?php echo esc_attr($sabsButtons['email']); ?>" class="fab sab-email" tabindex="-1">
<i class="icofont-email"></i>
</a>
<?php endif; ?>
Expand Down
41 changes: 30 additions & 11 deletions sticky-action-buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

if ( !function_exists( 'add_action' ) ) {
_e('Hi there! I\'m just a plugin, not much I can do when called directly.');
echo esc_html('Hi there! I\'m just a plugin, not much I can do when called directly.');
exit;
}

Expand Down Expand Up @@ -83,6 +83,22 @@ function sabs_user_access_check()

function sabs_admin_options_form()
{
if(isset($_SESSION['sabsValidationErrors'])) {
extract($_SESSION['sabsValidationErrors']);
}

if(isset($_SESSION['sabsOldFormData'])) {
extract($_SESSION['sabsOldFormData']);
}

if(isset($_SESSION['saveSuccess'])) {
$saveSuccess = true;
}

if(isset($_SESSION['invalidDataAlert'])) {
$invalidDataAlert = true;
}

require_once plugin_dir_path(__FILE__) . 'admin/sabs_admin_options.php';
}

Expand All @@ -98,12 +114,10 @@ function is_phone_no($no)
}

if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit'])) {
$sabs = isset($_POST['sabs']) && !empty($_POST['sabs']) && is_array($_POST['sabs']) ? $_POST['sabs'] : [];

$enabled = (isset($sabs['enabled']) && !empty($sabs['enabled']) ? sanitize_text_field($sabs['enabled']) : null);
$whatsAppNo = (isset($sabs['whatsApp']) && !empty($sabs['whatsApp']) ? sanitize_text_field($sabs['whatsApp']) : null);
$phone = (isset($sabs['phone']) && !empty($sabs['phone']) ? sanitize_text_field($sabs['phone']) : null);
$email = (isset($sabs['email']) && !empty($sabs['email']) ? sanitize_text_field($sabs['email']) : null);
$enabled = (isset($_POST['sabsEnabled']) && !empty($_POST['sabsEnabled']) ? sanitize_text_field($_POST['sabsEnabled']) : null);
$whatsAppNo = (isset($_POST['sabsWhatsApp']) && !empty($_POST['sabsWhatsApp']) ? sanitize_text_field($_POST['sabsWhatsApp']) : null);
$phone = (isset($_POST['sabsPhone']) && !empty($_POST['sabsPhone']) ? sanitize_text_field($_POST['sabsPhone']) : null);
$email = (isset($_POST['sabsEmail']) && !empty($_POST['sabsEmail']) ? sanitize_text_field($_POST['sabsEmail']) : null);

$sabsButtons = [];
$errors = [];
Expand All @@ -112,23 +126,23 @@ function is_phone_no($no)
if(is_phone_no($whatsAppNo)) {
$sabsButtons['whatsApp'] = $whatsAppNo;
} else {
$errors['whatsApp'] = "Invalid input";
$errors['errWhatsApp'] = "Invalid input";
}
}

if(!empty($phone)) {
if(is_phone_no($phone)) {
$sabsButtons['phone'] = $phone;
} else {
$errors['phone'] = "Invalid input";
$errors['errPhone'] = "Invalid input";
}
}

if(!empty($email)) {
if(is_email($email)) {
$sabsButtons['email'] = $email;
} else {
$errors['email'] = "Invalid input";
$errors['errEmail'] = "Invalid input";
}
}

Expand All @@ -146,7 +160,12 @@ function is_phone_no($no)
$_SESSION['invalidDataAlert'] = true;

$_SESSION['sabsValidationErrors'] = $errors;
$_SESSION['sabsOldFormData'] = $sabs;
$_SESSION['sabsOldFormData'] = [
"oldEnabled" => $enabled,
"oldWhatsApp" => $whatsAppNo,
"oldPhone" => $phone,
"oldEmail" => $email,
];
}
}
}
Expand Down

0 comments on commit 1a72d20

Please sign in to comment.