....................................../////.===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/www/wp-content/plugins/imagify/inc/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/thillelirn/www/wp-content/plugins/imagify/inc/classes//class-imagify-auto-optimization.php
<?php

use Imagify\Traits\InstanceGetterTrait;

defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );

/**
 * Class that handles the auto-optimization process.
 * This occurs when a new image is uploaded, and when an optimized image is worked with (resized, etc).
 * The process will work only if wp_generate_attachment_metadata() and wp_update_attachment_metadata() are used.
 *
 * @since 1.8.4
 */
class Imagify_Auto_Optimization extends Imagify_Auto_Optimization_Deprecated {
	use InstanceGetterTrait;

	/**
	 * An array containing all the "steps" an attachment is going through.
	 * This is used to decide the behavior of the automatic optimization.
	 *
	 * @var    array {
	 *     An array of arrays with attachment ID as keys.
	 *     Each array can contain the following:
	 *
	 *     @type $upload   int Set to 1 if the attachment is a new upload.
	 *     @type $generate int Set to 1 when going though wp_generate_attachment_metadata().
	 *     @type $update   int Set to 1 when going though wp_update_attachment_metadata().
	 * }
	 * @since 1.8.4
	 * @since 1.9.10 Private.
	 * @since 1.9.10 Items are arrays instead of 1s.
	 */
	private $attachments = [];

	/**
	 * Tell if we’re using WP 5.3+.
	 *
	 * @var   bool
	 * @since 1.9.10
	 */
	private $is_wp_53;

	/**
	 * The ID of the attachment that failed to be uploaded.
	 *
	 * @var   int
	 * @since 1.9.8
	 */
	protected $upload_failure_id = 0;

	/**
	 * Used to prevent an auto-optimization locally.
	 *
	 * @var   array
	 * @since 1.8.4
	 */
	private static $prevented = [];

	/**
	 * Used to prevent an auto-optimization internally.
	 *
	 * @var   array
	 * @since 1.9.8
	 */
	private static $prevented_internally = [];

	/**
	 * Init.
	 *
	 * @since 1.8.4
	 */
	public function init() {
		global $wp_version;

		$priority       = IMAGIFY_INT_MAX - 30;
		$this->is_wp_53 = version_compare( $wp_version, '5.3-alpha1' ) >= 0;

		// Automatic optimization tunel.
		add_action( 'add_attachment',                  [ $this, 'store_upload_ids' ], $priority );
		add_filter( 'wp_generate_attachment_metadata', [ $this, 'maybe_store_generate_step' ], $priority, 2 );
		add_filter( 'wp_update_attachment_metadata',   [ $this, 'store_ids_to_optimize' ], $priority, 2 );

		if ( $this->is_wp_53 ) {
			// WP 5.3+.
			add_action( 'imagify_after_auto_optimization_init', [ $this, 'do_auto_optimization' ], $priority, 2 );
			// Upload failure recovering.
			add_action( 'wp_ajax_media-create-image-subsizes', [ $this, 'prevent_auto_optimization_when_recovering_from_upload_failure' ], -5 ); // Before WP’s hook (priority 1).
		} else {
			add_action( 'updated_post_meta',             [ $this, 'do_auto_optimization_after_meta_update' ], $priority, 4 );
			add_action( 'added_post_meta',               [ $this, 'do_auto_optimization_after_meta_update' ], $priority, 4 );
		}

		add_action( 'deleted_post_meta', [ $this, 'unset_optimization' ], $priority, 3 );

		// Prevent to re-optimize when updating the image width and height (when resizing the full image).
		add_action( 'imagify_before_update_wp_media_data_dimensions', [ __CLASS__, 'prevent_optimization' ], 5 );
		add_action( 'imagify_after_update_wp_media_data_dimensions',  [ __CLASS__, 'allow_optimization' ], 5 );
	}

	/**
	 * Remove the hooks.
	 *
	 * @since 1.8.4
	 */
	public function remove_hooks() {
		$priority = IMAGIFY_INT_MAX - 30;

		// Automatic optimization tunel.
		remove_action( 'add_attachment',                  [ $this, 'store_upload_ids' ], $priority );
		remove_filter( 'wp_generate_attachment_metadata', [ $this, 'maybe_store_generate_step' ], $priority );
		remove_filter( 'wp_update_attachment_metadata',   [ $this, 'store_ids_to_optimize' ], $priority );

		if ( $this->is_wp_53 ) {
			// WP 5.3+.
			remove_action( 'imagify_after_auto_optimization_init', [ $this, 'do_auto_optimization' ], $priority );
			// Upload failure recovering.
			remove_action( 'wp_ajax_media-create-image-subsizes', [ $this, 'prevent_auto_optimization_when_recovering_from_upload_failure' ], -5 );
		} else {
			remove_action( 'updated_post_meta',             [ $this, 'do_auto_optimization_after_meta_update' ], $priority );
			remove_action( 'added_post_meta',               [ $this, 'do_auto_optimization_after_meta_update' ], $priority );
		}

		remove_action( 'deleted_post_meta', [ $this, 'unset_optimization' ], $priority );

		// Prevent to re-optimize when updating the image width and height (when resizing the full image).
		remove_action( 'imagify_before_update_wp_media_data_dimensions', [ __CLASS__, 'prevent_optimization' ], 5 );
		remove_action( 'imagify_after_update_wp_media_data_dimensions',  [ __CLASS__, 'allow_optimization' ], 5 );
	}


	/** ----------------------------------------------------------------------------------------- */
	/** HOOKS =================================================================================== */
	/** ----------------------------------------------------------------------------------------- */

	/**
	 * Store the "upload step" when an attachment has just been uploaded.
	 *
	 * @since 1.8.4
	 * @see   $this->store_ids_to_optimize()
	 *
	 * @param int $attachment_id Current attachment ID.
	 */
	public function store_upload_ids( $attachment_id ) {
		if ( ! self::is_optimization_prevented( $attachment_id ) && imagify_is_attachment_mime_type_supported( $attachment_id ) ) {
			$this->set_step( $attachment_id, 'upload' );
		}
	}

	/**
	 * Store the "generate step" when wp_generate_attachment_metadata() is used.
	 *
	 * @since 1.9.10
	 *
	 * @param  array $metadata      An array of attachment meta data.
	 * @param  int   $attachment_id Current attachment ID.
	 * @return array
	 */
	public function maybe_store_generate_step( $metadata, $attachment_id ) {
		if ( self::is_optimization_prevented( $attachment_id ) ) {
			return $metadata;
		}

		if ( empty( $metadata ) || ! imagify_is_attachment_mime_type_supported( $attachment_id ) ) {
			$this->unset_steps( $attachment_id );
			return $metadata;
		}

		$this->set_step( $attachment_id, 'generate' );

		return $metadata;
	}

	/**
	 * After the attachment meta data has been generated (partially, since WP 5.3), init the auto-optimization.
	 * Two cases are possible to trigger the optimization:
	 * - It's a new upload and auto-optimization is enabled.
	 * - It's not a new upload (it is regenerated) and the attachment is already optimized.
	 *
	 * @since 1.8.4
	 *
	 * @param  array $metadata      An array of attachment meta data.
	 * @param  int   $attachment_id Current attachment ID.
	 * @return array
	 */
	public function store_ids_to_optimize( $metadata, $attachment_id ) {
		static $auto_optimize;

		if ( self::is_optimization_prevented( $attachment_id ) ) {
			return $metadata;
		}

		if ( empty( $metadata ) || ! imagify_is_attachment_mime_type_supported( $attachment_id ) ) {
			$this->unset_steps( $attachment_id );
			return $metadata;
		}

		if ( ! $this->has_step( $attachment_id, 'generate' ) ) {
			return $metadata;
		}

		$is_new_upload = $this->has_step( $attachment_id, 'upload' );

		if ( $is_new_upload ) {
			// It's a new upload.
			if ( ! isset( $auto_optimize ) ) {
				$auto_optimize = get_imagify_option( 'auto_optimize' );
			}

			if ( ! $auto_optimize ) {
				/**
				 * Fires when a new attachment is uploaded but auto-optimization is disabled.
				 *
				 * @since 1.8.4
				 *
				 * @param int   $attachment_id Attachment ID.
				 * @param array $metadata      An array of attachment meta data.
				 */
				do_action( 'imagify_new_attachment_auto_optimization_disabled', $attachment_id, $metadata );

				return $metadata;
			}

			/**
			 * Allow to prevent automatic optimization for a specific attachment.
			 *
			 * @since 1.6.12
			 *
			 * @param bool  $optimize      True to optimize, false otherwise.
			 * @param int   $attachment_id Attachment ID.
			 * @param array $metadata      An array of attachment meta data.
			 */
			$optimize = apply_filters( 'imagify_auto_optimize_attachment', true, $attachment_id, $metadata );

			if ( ! $optimize ) {
				return $metadata;
			}

			/**
			 * It's a new upload and auto-optimization is enabled.
			 */
		}

		if ( ! $is_new_upload ) {
			// An existing attachment being regenerated (or something).
			$process = imagify_get_optimization_process( $attachment_id, 'wp' );

			if ( ! $process->is_valid() ) {
				// Uh?
				return $metadata;
			}

			if ( ! $process->get_data()->get_optimization_status() ) {
				/**
				 * Fires when an attachment is updated but not optimized yet.
				 *
				 * @since 1.8.4
				 *
				 * @param int   $attachment_id Attachment ID.
				 * @param array $metadata      An array of attachment meta data.
				 */
				do_action( 'imagify_not_optimized_attachment_updated', $attachment_id, $metadata );

				return $metadata;
			}

			/**
			 * Allow to prevent automatic reoptimization for a specific attachment.
			 *
			 * @since 1.8.4
			 *
			 * @param bool  $optimize      True to optimize, false otherwise.
			 * @param int   $attachment_id Attachment ID.
			 * @param array $metadata      An array of attachment meta data.
			 */
			$optimize = apply_filters( 'imagify_auto_optimize_optimized_attachment', true, $attachment_id, $metadata );

			if ( ! $optimize ) {
				return $metadata;
			}

			/**
			 * The attachment already exists and was already optimized.
			 */
		}

		// Ready for the next step.
		$this->set_step( $attachment_id, 'update' );

		/**
		 * Triggered after a media auto-optimization init.
		 *
		 * @since 1.9.8
		 *
		 * @param int  $attachment_id The media ID.
		 * @param bool $is_new_upload True if it's a new upload. False otherwize.
		 */
		do_action( 'imagify_after_auto_optimization_init', $attachment_id, $is_new_upload );

		return $metadata;
	}

	/**
	 * Launch auto optimization immediately after the post meta '_wp_attachment_metadata' is added or updated.
	 *
	 * @since 1.9
	 * @since 1.9 Previously named do_auto_optimization().
	 *
	 * @param int    $meta_id       ID of the metadata entry.
	 * @param int    $attachment_id Current attachment ID.
	 * @param string $meta_key      Meta key.
	 * @param mixed  $metadata      Meta value.
	 */
	public function do_auto_optimization_after_meta_update( $meta_id, $attachment_id, $meta_key, $metadata ) {
		if ( '_wp_attachment_metadata' !== $meta_key ) {
			return;
		}

		if ( self::is_optimization_prevented( $attachment_id ) ) {
			return;
		}

		if ( ! $this->has_step( $attachment_id, 'update' ) ) {
			return;
		}

		$this->do_auto_optimization( $attachment_id, $this->has_step( $attachment_id, 'upload' ) );
	}

	/**
	 * Launch auto optimization immediately after the post meta '_wp_attachment_metadata' is added or updated.
	 *
	 * @since 1.8.4
	 * @since 1.9.8 Changed signature.
	 *
	 * @param int  $attachment_id The media ID.
	 * @param bool $is_new_upload True if it's a new upload. False otherwize.
	 */
	public function do_auto_optimization( $attachment_id, $is_new_upload ) {
		$this->unset_steps( $attachment_id );

		$process = imagify_get_optimization_process( $attachment_id, 'wp' );

		/**
		 * Fires before an attachment auto-optimization is triggered.
		 *
		 * @since 1.8.4
		 *
		 * @param int  $attachment_id The attachment ID.
		 * @param bool $is_new_upload True if it's a new upload. False otherwize.
		 */
		do_action_deprecated( 'imagify_before_auto_optimization_launch', [ $attachment_id, $is_new_upload ], '1.9', 'imagify_before_auto_optimization' );

		/**
		 * Triggered before a media is auto-optimized.
		 *
		 * @since 1.8.4
		 *
		 * @param int  $attachment_id The media ID.
		 * @param bool $is_new_upload True if it's a new upload. False otherwize.
		 */
		do_action( 'imagify_before_auto_optimization', $attachment_id, $is_new_upload );

		if ( $is_new_upload ) {
			/**
			 * It's a new upload.
			 */
			// Optimize.
			$process->optimize( null, [ 'is_new_upload' => 1 ] );
		} else {
			/**
			 * The media has already been optimized (or at least it has been tried).
			 */
			$process_data = $process->get_data();

			// Get the optimization level before deleting the optimization data.
			$optimization_level = $process_data->get_optimization_level();

			// Some specifics for the image editor.
			if ( isset( $_POST['action'], $_POST['do'], $_POST['postid'] ) && 'image-editor' === $_POST['action'] && (int) $_POST['postid'] === $attachment_id ) { // WPCS: CSRF ok.
				check_ajax_referer( 'image_editor-' . $attachment_id );

				if ( ! current_user_can( 'edit_post', $attachment_id ) ) {
					imagify_die();
				}

				// Restore the backup file.
				$result = $process->restore();

				if ( is_wp_error( $result ) ) {
					// Restoration failed, there is no good way to handle this case.
					$process_data->delete_optimization_data();
				}
			} else {
				// Remove old optimization data.
				$process_data->delete_optimization_data();
			}

			// Optimize.
			$process->optimize( $optimization_level );
		}

		/**
		 * Triggered after a media auto-optimization is launched.
		 *
		 * @since 1.8.4
		 *
		 * @param int  $attachment_id The media ID.
		 * @param bool $is_new_upload True if it's a new upload. False otherwize.
		 */
		do_action( 'imagify_after_auto_optimization', $attachment_id, $is_new_upload );
	}

	/**
	 * Remove the attachment ID from the $attachments property if the post meta '_wp_attachment_metadata' is deleted.
	 *
	 * @since 1.8.4
	 *
	 * @param int    $meta_ids      An array of deleted metadata entry IDs.
	 * @param int    $attachment_id Current attachment ID.
	 * @param string $meta_key      Meta key.
	 */
	public function unset_optimization( $meta_ids, $attachment_id, $meta_key ) {
		if ( '_wp_attachment_metadata' !== $meta_key ) {
			return;
		}

		$this->unset_steps( $attachment_id );
	}


	/** ----------------------------------------------------------------------------------------- */
	/** HOOKS FOR WP 5.3+’S UPLOAD FAILURE RECOVERING =========================================== */
	/** ----------------------------------------------------------------------------------------- */

	/**
	 * With WP 5.3+, prevent auto-optimization when WP tries to create thumbnails after an upload error, because it triggers wp_update_attachment_metadata() for each thumbnail size.
	 *
	 * @since 1.9.8
	 * @see   wp_ajax_media_create_image_subsizes()
	 * @see   wp_update_image_subsizes()
	 */
	public function prevent_auto_optimization_when_recovering_from_upload_failure() {
		if ( ! check_ajax_referer( 'media-form', false, false ) ) {
			return;
		}

		if ( ! current_user_can( 'upload_files' ) ) {
			return;
		}

		if ( ! imagify_get_context( 'wp' )->current_user_can( 'auto-optimize' ) ) {
			return;
		}

		$attachment_id = ! empty( $_POST['attachment_id'] ) ? (int) $_POST['attachment_id'] : 0;

		if ( empty( $attachment_id ) ) {
			return;
		}

		if ( ! imagify_is_attachment_mime_type_supported( $attachment_id ) ) {
			return;
		}

		$this->upload_failure_id = $attachment_id;

		// Auto-optimization will be done on shutdown.
		ob_start( [ $this, 'maybe_do_auto_optimization_after_recovering_from_upload_failure' ] );
	}

	/**
	 * Maybe launch auto-optimization after recovering from an upload failure, when all thumbnails are created.
	 *
	 * @since 1.9.8
	 * @see   wp_ajax_media_create_image_subsizes()
	 *
	 * @param  string $content Buffer’s content.
	 * @return string          Buffer’s content.
	 */
	public function maybe_do_auto_optimization_after_recovering_from_upload_failure( $content ) {
		if ( empty( $content ) ) {
			return $content;
		}

		if ( empty( $this->upload_failure_id ) ) {
			// Uh?
			return $content;
		}

		if ( ! get_post( $this->upload_failure_id ) ) {
			return $content;
		}

		$json = @json_decode( $content );

		if ( empty( $json->success ) ) {
			return $content;
		}

		$attachment_id = $this->upload_failure_id;
		$metadata      = wp_get_attachment_metadata( $attachment_id );

		// Launch the process.
		$this->upload_failure_id = 0;
		$this->set_step( $attachment_id, 'generate' );
		$this->store_ids_to_optimize( $metadata, $attachment_id );

		return $content;
	}


	/** ----------------------------------------------------------------------------------------- */
	/** TOOLS =================================================================================== */
	/** ----------------------------------------------------------------------------------------- */

	/**
	 * Set a "step" for an attachment.
	 *
	 * @since 1.9.10
	 * @see   $this->attachments
	 *
	 * @param int    $attachment_id Current attachment ID.
	 * @param string $step          The step to add.
	 */
	public function set_step( $attachment_id, $step ) {
		if ( empty( $this->attachments[ $attachment_id ] ) ) {
			$this->attachments[ $attachment_id ] = [];
		}

		$this->attachments[ $attachment_id ][ $step ] = 1;
	}

	/**
	 * Unset a "step" for an attachment.
	 *
	 * @since 1.9.10
	 * @see   $this->attachments
	 *
	 * @param int    $attachment_id Current attachment ID.
	 * @param string $step          The step to add.
	 */
	public function unset_step( $attachment_id, $step ) {
		unset( $this->attachments[ $attachment_id ][ $step ] );

		if ( empty( $this->attachments[ $attachment_id ] ) ) {
			$this->unset_steps( $attachment_id );
		}
	}

	/**
	 * Unset all "steps" for an attachment.
	 *
	 * @since 1.9.10
	 * @see   $this->attachments
	 *
	 * @param int $attachment_id Current attachment ID.
	 */
	public function unset_steps( $attachment_id ) {
		unset( $this->attachments[ $attachment_id ] );
	}

	/**
	 * Tell if a "step" for an attachment exists.
	 *
	 * @since 1.9.10
	 * @see   $this->attachments
	 *
	 * @param  int    $attachment_id Current attachment ID.
	 * @param  string $step          The step to add.
	 * @return bool
	 */
	public function has_step( $attachment_id, $step ) {
		return ! empty( $this->attachments[ $attachment_id ][ $step ] );
	}

	/**
	 * Prevent an auto-optimization locally.
	 * How to use it:
	 *     Imagify_Auto_Optimization::prevent_optimization( $attachment_id );
	 *     wp_update_attachment_metadata( $attachment_id );
	 *     Imagify_Auto_Optimization::allow_optimization( $attachment_id );
	 *
	 * @since 1.8.4
	 * @since 1.9.8 Prevents/Allows can stack.
	 *
	 * @param int $attachment_id Current attachment ID.
	 */
	public static function prevent_optimization( $attachment_id ) {
		if ( ! isset( self::$prevented[ $attachment_id ] ) ) {
			self::$prevented[ $attachment_id ] = 1;
		} else {
			++self::$prevented[ $attachment_id ];
		}
	}

	/**
	 * Allow an auto-optimization locally.
	 * How to use it:
	 *     Imagify_Auto_Optimization::prevent_optimization( $attachment_id );
	 *     wp_update_attachment_metadata( $attachment_id );
	 *     Imagify_Auto_Optimization::allow_optimization( $attachment_id );
	 *
	 * @since 1.8.4
	 * @since 1.9.8 Prevents/Allows can stack.
	 *
	 * @param int $attachment_id Current attachment ID.
	 */
	public static function allow_optimization( $attachment_id ) {
		if ( ! isset( self::$prevented[ $attachment_id ] ) ) {
			return;
		}
		--self::$prevented[ $attachment_id ];

		if ( self::$prevented[ $attachment_id ] <= 0 ) {
			unset( self::$prevented[ $attachment_id ] );
		}
	}

	/**
	 * Tell if an auto-optimization is prevented locally.
	 *
	 * @since 1.8.4
	 *
	 * @param  int $attachment_id Current attachment ID.
	 * @return bool
	 */
	public static function is_optimization_prevented( $attachment_id ) {
		return ! empty( self::$prevented[ $attachment_id ] ) || ! empty( self::$prevented_internally[ $attachment_id ] );
	}

	/**
	 * Prevent an auto-optimization internally.
	 *
	 * @since 1.9.8
	 *
	 * @param int $attachment_id Current attachment ID.
	 */
	protected static function prevent_optimization_internally( $attachment_id ) {
		self::$prevented_internally[ $attachment_id ] = 1;
	}

	/**
	 * Allow an auto-optimization internally.
	 *
	 * @since 1.9.8
	 *
	 * @param int $attachment_id Current attachment ID.
	 */
	protected static function allow_optimization_internally( $attachment_id ) {
		unset( self::$prevented_internally[ $attachment_id ] );
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit