| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Legacy plugin code |
| 5 |
*/ |
| 6 |
|
| 7 |
define('PZF_FILE', __FILE__); |
| 8 |
define('PZF_NAME', basename(PZF_FILE)); |
| 9 |
define('PZF_BASE_NAME', plugin_basename(PZF_FILE)); |
| 10 |
define('PZF_PATH', plugin_dir_path(PZF_FILE)); |
| 11 |
define('PZF_URL', plugin_dir_url(PZF_FILE)); |
| 12 |
|
| 13 |
if (! defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
function register_mysettings() |
| 18 |
{ |
| 19 |
// Group 1: Phone numbers and colors |
| 20 |
register_setting('pzf-settings-group', 'pzf_phone', [ |
| 21 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 22 |
]); |
| 23 |
register_setting('pzf-settings-group', 'pzf_phone2', [ |
| 24 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 25 |
]); |
| 26 |
register_setting('pzf-settings-group', 'pzf_phone3', [ |
| 27 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 28 |
]); |
| 29 |
register_setting('pzf-settings-group', 'pzf_color_phone', [ |
| 30 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 31 |
]); |
| 32 |
register_setting('pzf-settings-group', 'pzf_color_phone2', [ |
| 33 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 34 |
]); |
| 35 |
register_setting('pzf-settings-group', 'pzf_color_phone3', [ |
| 36 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 37 |
]); |
| 38 |
|
| 39 |
// Group 2: Social media links |
| 40 |
register_setting('pzf-settings-group', 'pzf_linkfanpage', [ |
| 41 |
'sanitize_callback' => 'esc_url_raw' |
| 42 |
]); |
| 43 |
register_setting('pzf-settings-group', 'pzf_linkmessenger', [ |
| 44 |
'sanitize_callback' => 'esc_url_raw' |
| 45 |
]); |
| 46 |
register_setting('pzf-settings-group', 'pzf_whatsapp', [ |
| 47 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 48 |
]); |
| 49 |
register_setting('pzf-settings-group', 'pzf_zalo', [ |
| 50 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 51 |
]); |
| 52 |
register_setting('pzf-settings-group', 'pzf_telegram', [ |
| 53 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 54 |
]); |
| 55 |
register_setting('pzf-settings-group', 'pzf_instagram', [ |
| 56 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 57 |
]); |
| 58 |
register_setting('pzf-settings-group', 'pzf_youtube', [ |
| 59 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 60 |
]); |
| 61 |
register_setting('pzf-settings-group', 'pzf_tiktok', [ |
| 62 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 63 |
]); |
| 64 |
register_setting('pzf-settings-group', 'pzf_viber', [ |
| 65 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 66 |
]); |
| 67 |
|
| 68 |
// Group 3: Contact link and colors |
| 69 |
register_setting('pzf-settings-group', 'pzf_contact_link', [ |
| 70 |
'sanitize_callback' => 'esc_url_raw' |
| 71 |
]); |
| 72 |
register_setting('pzf-settings-group', 'pzf_color_contact', [ |
| 73 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 74 |
]); |
| 75 |
register_setting('pzf-settings-group', 'pzf_linkggmap', [ |
| 76 |
'sanitize_callback' => 'esc_url_raw' |
| 77 |
]); |
| 78 |
register_setting('pzf-settings-group', 'pzf_color_linkggmap', [ |
| 79 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 80 |
]); |
| 81 |
|
| 82 |
// Group 4: Facebook integration |
| 83 |
register_setting('pzf-settings-group', 'pzf_id_fanpage', [ |
| 84 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 85 |
]); |
| 86 |
register_setting('pzf-settings-group', 'pzf_color_fb', [ |
| 87 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 88 |
]); |
| 89 |
|
| 90 |
// Group 5: Other settings |
| 91 |
register_setting('pzf-settings-group', 'pzf_phone_bar', [ |
| 92 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 93 |
]); |
| 94 |
register_setting('pzf-settings-group', 'logged_in_greeting', [ |
| 95 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 96 |
]); |
| 97 |
|
| 98 |
|
| 99 |
register_setting('pzf-settings-group-setting', 'setting_size', [ |
| 100 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 101 |
]); |
| 102 |
register_setting('pzf-settings-group-setting', 'pzf_location', [ |
| 103 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 104 |
]); |
| 105 |
register_setting('pzf-settings-group-setting', 'pzf_location_bottom', [ |
| 106 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 107 |
]); |
| 108 |
register_setting('pzf-settings-group-setting', 'pzf_hide_mobile', [ |
| 109 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 110 |
]); |
| 111 |
register_setting('pzf-settings-group-setting', 'pzf_hide_desktop', [ |
| 112 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 113 |
]); |
| 114 |
register_setting('pzf-settings-group-setting', 'pzf_off_effects', [ |
| 115 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 116 |
]); |
| 117 |
|
| 118 |
|
| 119 |
register_setting('pzf_settings_all_in_one', 'pzf_enable_all_in_one', [ |
| 120 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 121 |
]); |
| 122 |
register_setting('pzf_settings_all_in_one', 'pzf_note_all_in_one', [ |
| 123 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 124 |
]); |
| 125 |
register_setting('pzf_settings_all_in_one', 'pzf_note_bar_all_in_one', [ |
| 126 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 127 |
]); |
| 128 |
register_setting('pzf_settings_all_in_one', 'pzf_color_all_in_one', [ |
| 129 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 130 |
]); |
| 131 |
register_setting('pzf_settings_all_in_one', 'pzf_icon_all_in_one', [ |
| 132 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 133 |
]); |
| 134 |
register_setting('pzf_settings_all_in_one', 'pzf_hide_default_all_in_one', [ |
| 135 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 136 |
]); |
| 137 |
|
| 138 |
|
| 139 |
register_setting('pzf_settings_contact_form', 'pzf_enable_contact_form', [ |
| 140 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 141 |
]); |
| 142 |
register_setting('pzf_settings_contact_form', 'pzf_color_contact_form', [ |
| 143 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 144 |
]); |
| 145 |
register_setting('pzf_settings_contact_form', 'pzf_bg_contact_form', [ |
| 146 |
'sanitize_callback' => 'sanitize_hex_color_with_limit' |
| 147 |
]); |
| 148 |
register_setting('pzf_settings_contact_form', 'pzf_max_w_contact_form', [ |
| 149 |
'sanitize_callback' => 'sanitize_text_field_with_limit' |
| 150 |
]); |
| 151 |
} |
| 152 |
|
| 153 |
// Sanitize and limit the length of a text field |
| 154 |
function sanitize_text_field_with_limit($value) |
| 155 |
{ |
| 156 |
$value = wp_strip_all_tags($value); // Remove HTML tags |
| 157 |
return substr($value, 0, 255); // Limit to 255 characters |
| 158 |
} |
| 159 |
|
| 160 |
// Sanitize and limit the length of a hex color field |
| 161 |
function sanitize_hex_color_with_limit($value) |
| 162 |
{ |
| 163 |
$value = sanitize_hex_color($value); // Sanitize hex color |
| 164 |
return substr($value, 0, 7); // Limit to 7 characters |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
require_once PZF_PATH . '/inc/button-contact.php'; |
| 169 |
|
| 170 |
// add menu admin wp |
| 171 |
function pzf_create_menu() |
| 172 |
{ |
| 173 |
add_menu_page('Button contact VR', 'Button contact', 'administrator', 'contact_vr', 'pzf_settings_page', plugins_url('/img/icon.png', __FILE__), 100); |
| 174 |
add_action('admin_init', 'register_mysettings'); |
| 175 |
|
| 176 |
// add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null ) |
| 177 |
add_submenu_page('contact_vr', 'Contact form', 'Contact form', 'administrator', 'contact_vr_contact_form', 'pzf_settings_contact_form', 10); |
| 178 |
add_submenu_page('contact_vr', 'Showroom', 'Showroom', 'administrator', 'contact_vr_showroom', 'pzf_settings_showroom', 20); |
| 179 |
add_submenu_page('contact_vr', 'All in one', 'All in one', 'administrator', 'contact_vr_all_in_one', 'pzf_settings_all_in_one', 30); |
| 180 |
add_submenu_page('contact_vr', 'Setting', 'Setting', 'administrator', 'contact_vr_setting', 'pzf_settings_page_setting', 40); |
| 181 |
} |
| 182 |
add_action('admin_menu', 'pzf_create_menu'); |
| 183 |
|
| 184 |
// Try new version |
| 185 |
function try_new_version() |
| 186 |
{ |
| 187 |
// Go to new version |
| 188 |
if ( |
| 189 |
// Check correct permissions |
| 190 |
current_user_can(is_multisite() ? 'manage_options' : 'activate_plugins') && |
| 191 |
|
| 192 |
// Validate correct page |
| 193 |
(isset($_GET["page"]) && $_GET["page"] === "contact_vr_setting") && |
| 194 |
|
| 195 |
// Check try new version variable exists |
| 196 |
(isset($_GET["try_new_version"]) && $_GET["try_new_version"] === "yes") |
| 197 |
) { |
| 198 |
update_option("button_contact_legacy", "no"); |
| 199 |
|
| 200 |
// Redirect succesful |
| 201 |
wp_redirect(admin_url("admin.php?page=bz_button_contact")); |
| 202 |
exit; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
add_action('admin_init', 'try_new_version'); |
| 207 |
|
| 208 |
|
| 209 |
// add link setting - add setting: 4.2 |
| 210 |
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'add_action_links'); |
| 211 |
function add_action_links($actions) |
| 212 |
{ |
| 213 |
$mylinks = array( |
| 214 |
'<a href="' . admin_url('admin.php?page=contact_vr') . '">' . esc_html__('Settings', 'button-contact-vr') . '</a>', |
| 215 |
); |
| 216 |
$actions = array_merge($actions, $mylinks); |
| 217 |
return $actions; |
| 218 |
} |
| 219 |
// Register and enqueue custom admin CSS |
| 220 |
function custom_admin_css() |
| 221 |
{ |
| 222 |
wp_register_style('custom-admin', plugins_url('css/style-admin.css', __FILE__), [], 1); |
| 223 |
wp_enqueue_style('custom-admin'); |
| 224 |
} |
| 225 |
add_action('admin_enqueue_scripts', 'custom_admin_css'); |
| 226 |
|
| 227 |
// add backend |
| 228 |
function pzf_settings_page() |
| 229 |
{ |
| 230 |
include PZF_PATH . '/inc/admin.php'; |
| 231 |
} |
| 232 |
function pzf_settings_page_setting() |
| 233 |
{ |
| 234 |
include PZF_PATH . '/inc/setting.php'; |
| 235 |
} |
| 236 |
function pzf_settings_all_in_one() |
| 237 |
{ |
| 238 |
include PZF_PATH . '/inc/all-in-one.php'; |
| 239 |
} |
| 240 |
function pzf_settings_contact_form() |
| 241 |
{ |
| 242 |
include PZF_PATH . '/inc/contact-form.php'; |
| 243 |
} |
| 244 |
function pzf_settings_showroom() |
| 245 |
{ |
| 246 |
include PZF_PATH . '/inc/showroom.php'; |
| 247 |
} |
| 248 |
// end backend |
| 249 |
PZF::instance(); |
| 250 |
|