| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
* PDA Menu and settings |
| 9 |
* |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Create Setting Menu |
| 14 |
*/ |
| 15 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 16 |
function pda_menu() { |
| 17 |
// phpcs:disable |
| 18 |
add_menu_page( |
| 19 |
__( 'Prevent Direct Access Plugin Settings', 'prevent-direct-access' ), |
| 20 |
__( 'Prevent Direct Access', 'prevent-direct-access' ), |
| 21 |
'manage_options', |
| 22 |
// phpcs:ignore |
| 23 |
__FILE__, |
| 24 |
'pda_settings', |
| 25 |
'dashicons-unlock' |
| 26 |
); |
| 27 |
// phpcs:enable |
| 28 |
} |
| 29 |
|
| 30 |
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals |
| 31 |
/** |
| 32 |
* Manage PDA Setting |
| 33 |
*/ |
| 34 |
function pda_settings() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 35 |
|
| 36 |
// Check current user role and access |
| 37 |
if(!current_user_can('manage_options')) { |
| 38 |
wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'prevent-direct-access') ); |
| 39 |
} |
| 40 |
?> |
| 41 |
|
| 42 |
<div class="wrap"> |
| 43 |
<style> |
| 44 |
.notice.pda-notice { |
| 45 |
border-left-color: #0194F3 !important; |
| 46 |
padding: 20px; |
| 47 |
} |
| 48 |
.rtl .notice.pda-notice { |
| 49 |
border-right-color: #0194F3 !important; |
| 50 |
} |
| 51 |
.notice.pda-notice .pda-notice-inner { |
| 52 |
display: table; |
| 53 |
width: 100%; |
| 54 |
} |
| 55 |
.notice.pda-notice .pda-notice-inner .pda-notice-icon, |
| 56 |
.notice.pda-notice .pda-notice-inner .pda-notice-content, |
| 57 |
.notice.pda-notice .pda-notice-inner .pda-install-now { |
| 58 |
display: table-cell; |
| 59 |
vertical-align: middle; |
| 60 |
} |
| 61 |
.notice.pda-notice .pda-notice-icon { |
| 62 |
color: #0194F3; |
| 63 |
font-size: 50px; |
| 64 |
width: 50px; |
| 65 |
} |
| 66 |
.notice.pda-notice .pda-notice-content { |
| 67 |
padding: 0 20px; |
| 68 |
} |
| 69 |
.notice.pda-notice p { |
| 70 |
padding: 0; |
| 71 |
margin: 0; |
| 72 |
} |
| 73 |
.notice.pda-notice h3 { |
| 74 |
margin: 0 0 5px; |
| 75 |
} |
| 76 |
.notice.pda-notice .pda-install-now { |
| 77 |
text-align: center; |
| 78 |
} |
| 79 |
.notice.pda-notice .pda-install-now .pda-install-button { |
| 80 |
background-color: #0194F3; |
| 81 |
color: #fff; |
| 82 |
border-color: #0da8f3; |
| 83 |
box-shadow: 0 1px 0 #0da8f3; |
| 84 |
padding: 5px 14px; |
| 85 |
height: auto; |
| 86 |
line-height: 20px; |
| 87 |
text-transform: capitalize; |
| 88 |
float: right; |
| 89 |
font-size: 1rem; |
| 90 |
} |
| 91 |
.notice.pda-notice .pda-install-now .pda-install-button i { |
| 92 |
padding-right: 5px; |
| 93 |
} |
| 94 |
.rtl .notice.pda-notice .pda-install-now .pda-install-button i { |
| 95 |
padding-right: 0; |
| 96 |
padding-left: 5px; |
| 97 |
} |
| 98 |
.notice.pda-notice .pda-install-now .pda-install-button:hover { |
| 99 |
background-color: #0da8f3; |
| 100 |
} |
| 101 |
.notice.pda-notice .pda-install-now .pda-install-button:active { |
| 102 |
box-shadow: inset 0 1px 0 #0da8f3; |
| 103 |
transform: translateY(1px); |
| 104 |
} |
| 105 |
@media (max-width: 767px) { |
| 106 |
.notice.pda-notice { |
| 107 |
padding: 10px; |
| 108 |
} |
| 109 |
.notice.pda-notice .pda-notice-inner { |
| 110 |
display: block; |
| 111 |
} |
| 112 |
.notice.pda-notice .pda-notice-inner .pda-notice-content { |
| 113 |
display: block; |
| 114 |
padding: 0; |
| 115 |
} |
| 116 |
.notice.pda-notice .pda-notice-inner .pda-notice-icon, |
| 117 |
.notice.pda-notice .pda-notice-inner .pda-install-now { |
| 118 |
display: none; |
| 119 |
} |
| 120 |
} |
| 121 |
</style> |
| 122 |
<div class="notice updated is-dismissible pda-notice pda-install-elementor"> |
| 123 |
<div class="pda-notice-inner"> |
| 124 |
<div class="pda-notice-icon"> |
| 125 |
<img width="64" height="64" src="<?php echo esc_url( plugin_dir_url( dirname( __FILE__ ) ) . 'public/assets/icon-128x128.jpg' ); ?>" alt="<?php esc_attr_e( 'PDA Logo', 'prevent-direct-access' ); ?>" /> |
| 126 |
</div> |
| 127 |
<div class="pda-notice-content"> |
| 128 |
<h3><?php esc_html_e( 'Do you like Prevent Direct Access? You\'ll love its Gold version!','prevent-direct-access'); ?></h3> |
| 129 |
<p><?php esc_html_e( 'Please upgrade to ','prevent-direct-access' ); ?> |
| 130 |
<a target="_blank" href="<?php echo esc_url( sprintf(constant( 'PDA_PRICING_PAGE' ), 'user-website' , "settings-notification-link") ); ?>" target="_blank"><?php esc_html_e( 'Gold version','prevent-direct-access' ); ?></a> to change default settings!</p> |
| 131 |
</div> |
| 132 |
<div class="pda-install-now"> |
| 133 |
<a class="button pda-install-button" target="_blank" href="<?php echo esc_url( sprintf(constant( 'PDA_PRICING_PAGE' ), 'user-website', 'settings-notification-cta') ); ?>"><i class="dashicons dashicons-download"></i><?php esc_html_e( 'Get it now!','prevent-direct-access' ); ?></a> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
<form method="post" action="options.php"> |
| 138 |
<?php |
| 139 |
settings_fields( 'pda_options' ); |
| 140 |
do_settings_sections( 'pda-settings' ); |
| 141 |
?> |
| 142 |
<p class="submit"> |
| 143 |
<input disabled type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes','prevent-direct-access') ?>" /> |
| 144 |
</p> |
| 145 |
</form> |
| 146 |
</div> |
| 147 |
<?php |
| 148 |
} |
| 149 |
|
| 150 |
//Comment due to change to new setting page |
| 151 |
//add_action('admin_init', 'register_pda_settings'); |
| 152 |
|
| 153 |
/** |
| 154 |
* Register PDA Setting |
| 155 |
*/ |
| 156 |
function register_pda_settings() { |
| 157 |
register_setting('pda_options', 'pda_options', 'pda_options_validate'); |
| 158 |
add_settings_section('pda_defaults', 'Default Settings', 'defaults_output', 'pda-settings'); |
| 159 |
add_settings_field('pda_enable_remote_log', 'Enable remote log?', 'pda_enable_remote_log', 'pda-settings', 'pda_defaults'); |
| 160 |
add_settings_field('pda_view_by_logged_user', 'Apply for logged users?', 'pda_view_by_logged_user', 'pda-settings', 'pda_defaults'); |
| 161 |
add_settings_field('pda_prefix_url', 'Prefix url', 'pda_prefix_url', 'pda-settings', 'pda_defaults'); |
| 162 |
add_settings_field('pda_auto_protect_new_files', 'Auto protect new uploaded files?', 'pda_enable_remote_log', 'pda-settings', 'pda_defaults'); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* PDA Prefic URL |
| 167 |
*/ |
| 168 |
function pda_prefix_url() { |
| 169 |
echo "<input id='prefix_url' name='prefix_url' type='text' value='private' />"; |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* PDA View by Logged user |
| 174 |
*/ |
| 175 |
function pda_view_by_logged_user() { |
| 176 |
echo "<input id='view_by_logged_user' name='pda_options[view_by_logged_user]' type='checkbox' />"; |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* PDA Enable remote log |
| 181 |
*/ |
| 182 |
function pda_enable_remote_log() { |
| 183 |
echo "<input id='pda_enable_remote_log' type='checkbox' />"; |
| 184 |
} |
| 185 |
|
| 186 |
/* Set defaults */ |
| 187 |
register_activation_hook(plugin_dir_path( __FILE__ ) . 'prevent-direct-access.php', 'pda_add_defaults_fn'); |
| 188 |
|
| 189 |
/** |
| 190 |
* PDA Add Default Function |
| 191 |
*/ |
| 192 |
function pda_add_defaults_fn() { |
| 193 |
$tmp = get_option('pda_options'); |
| 194 |
if(!is_array($tmp)) { |
| 195 |
$arr = array( |
| 196 |
"view_by_logged_user" => false |
| 197 |
); |
| 198 |
update_option('pda_options', $arr); |
| 199 |
} |
| 200 |
} |