JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
/**
* Represents a bundle of type "plugin"
*/
class Loco_package_Plugin extends Loco_package_Bundle {
/**
* {@inheritdoc}
*/
public function getSystemTargets(): array {
return [
trailingslashit( loco_constant('LOCO_LANG_DIR') ).'plugins',
trailingslashit( loco_constant('WP_LANG_DIR') ).'plugins',
];
}
/**
* {@inheritdoc}
*/
public function isPlugin(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function getType(): string {
return 'Plugin';
}
/**
* {@inheritDoc}
*/
public function getDirectoryUrl(): string {
return plugins_url('/',$this->getHandle());
}
/**
* {@inheritdoc}
*/
public function getSlug(): string {
// Fallback to first handle component
return explode( '/', parent::getSlug(), 2 )[0];
}
/**
* @return Loco_package_Plugin[]
*/
public static function getAll(): array {
$plugins = [];
foreach( self::get_plugins() as $handle => $data ){
try {
$plugins[] = Loco_package_Plugin::create($handle);
}
catch( Exception $e ){
// @codeCoverageIgnore
}
}
return $plugins;
}
/**
* Maintaining our own cache of full paths to available plugins, because get_mu_plugins doesn't get cached by WP
* @return array[]
*/
public static function get_plugins(): array {
$cached = wp_cache_get('plugins','loco');
if( ! is_array($cached) ){
$cached = [];
// regular plugins + mu plugins:
$search = [
'WP_PLUGIN_DIR' => 'get_plugins',
'WPMU_PLUGIN_DIR' => 'get_mu_plugins',
];
foreach( $search as $const => $getter ){
if( $list = call_user_func($getter) ){
$base = loco_constant($const);
foreach( $list as $handle => $data ){
if( isset($cached[$handle]) ){
Loco_error_AdminNotices::debug( sprintf('Plugin conflict on %s', $handle) );
continue;
}
// WordPress 4.6 introduced TextDomain header fallback @37562 see https://core.trac.wordpress.org/changeset/37562/
// if we don't force the original text domain header we can't know if a bundle is misconfigured. This leads to silent errors.
// this has a performance overhead, and also results in "unconfigured" messages that users may not have had in previous releases.
/*/ TODO perhaps implement a plugin setting that forces original headers
$file = new Loco_fs_File($base.'/'.$handle);
if( $file->exists() ){
$map = array( 'TextDomain' => 'Text Domain' );
$raw = get_file_data( $file->getPath(), $map, 'plugin' );
$data['TextDomain'] = $raw['TextDomain'];
}*/
// set resolved base directory before caching our copy of plugin data
$data['basedir'] = $base;
$cached[$handle] = $data;
}
}
}
$cached = apply_filters('loco_plugins_data', $cached );
uasort( $cached, '_sort_uname_callback' );
// Intended as in-memory cache so adding short expiry for object caching plugins that may persist it.
// All actions that invoke `wp_clean_plugins_cache` should purge this. See Loco_hooks_AdminHooks
wp_cache_set('plugins', $cached, 'loco', 3600 );
}
return $cached;
}
/**
* Get raw plugin data from WordPress registry, plus additional "basedir" field for resolving handle to actual file.
* @param string $handle Relative file path used as handle e.g. loco-translate/loco.php
*/
public static function get_plugin( string $handle ): ?array {
// plugin must be registered with WordPress
$search = self::get_plugins();
$data = $search[$handle] ?? null;
// else plugin is not known to WordPress
if( is_null($data) ){
$data = apply_filters( 'loco_missing_plugin', [], $handle );
}
// plugin not valid if name absent from raw data
if( empty($data['Name']) ){
return null;
}
// basedir is added by our get_plugins function, but filtered arrays could be broken
if( ! array_key_exists('basedir',$data) ){
Loco_error_AdminNotices::debug( sprintf('"basedir" property required to resolve %s',$handle) );
return null;
}
return $data;
}
/**
* {@inheritdoc}
*/
public function getHeaderInfo(): Loco_package_Header {
$handle = $this->getHandle();
$data = self::get_plugin($handle);
if( ! is_array($data) ){
// permitting direct file access if file exists (tests)
$path = $this->getBootstrapPath();
if( $path && file_exists($path) ){
$data = get_plugin_data( $path, false, false );
}
else {
$data = [];
}
}
return new Loco_package_Header( $data );
}
/**
* {@inheritdoc}
*/
public function getMetaTranslatable(): array {
return [
'Name' => 'Name of the plugin',
'Description' => 'Description of the plugin',
'PluginURI' => 'URI of the plugin',
'Author' => 'Author of the plugin',
'AuthorURI' => 'Author URI of the plugin',
// 'Tags' => 'Tags of the plugin',
];
}
/**
* {@inheritdoc}
*/
public function setHandle( string $handle ): Loco_package_Bundle {
// plugin handles are relative paths from plugin directory to bootstrap file
// so plugin is single file if its handle has no directory prefix
if( basename($handle) === $handle ){
$this->solo = true;
}
else {
$this->solo = false;
}
return parent::setHandle($handle);
}
/**
* {@inheritdoc}
*/
public function setDirectoryPath( string $path ): Loco_package_Bundle {
parent::setDirectoryPath($path);
// plugin bootstrap file can be inferred from base directory + handle
// e.g. if base is "/path/to/foo" and handle is "foo/bar.php" we can derive "/path/to/foo/bar.php"
if( ! $this->getBootstrapPath() ){
$handle = $this->getHandle();
if( '' !== $handle ) {
$file = new Loco_fs_File( basename($handle) );
$file->normalize( $path );
$this->setBootstrapPath( $file->getPath() );
}
}
return $this;
}
/**
* Create plugin bundle definition from WordPress plugin data.
*
* @param string $handle plugin handle relative to plugin directory
* @return Loco_package_Plugin
*/
public static function create( string $handle ): Loco_package_Plugin {
// plugin must be registered with at least a name and "basedir"
$data = self::get_plugin($handle);
if( ! $data ){
// translators: %s refers to the handle of a plugin, e.g. "loco-translate/loco.php"
throw new Loco_error_Exception( sprintf( __('Plugin not found: %s','loco-translate'),$handle) );
}
// lazy resolve of base directory from "basedir" property that we added
$file = new Loco_fs_File( $handle );
$file->normalize( $data['basedir'] );
$base = $file->dirname();
// handle and name is enough data to construct empty bundle
$bundle = new Loco_package_Plugin( $handle, $data['Name'] );
// check if listener heard the real text domain, but only use when none declared
// This will no longer happen since WP 4.6 header fallback, but we could warn about it
$listener = Loco_package_Listener::singleton();
if( $domain = $listener->getDomain($handle) ){
if( empty($data['TextDomain']) ){
$data['TextDomain'] = $domain;
if( empty($data['DomainPath']) ){
$data['DomainPath'] = $listener->getDomainPath($domain);
}
}
// ideally would only warn on certain pages, but unsure where to place this logic other than here
// TODO possibly allow bundle to hold errors/warnings as part of its config.
else if( $data['TextDomain'] !== $domain ){
Loco_error_AdminNotices::debug( sprintf("Plugin loaded text domain '%s' but WordPress knows it as '%s'",$domain, $data['TextDomain']) );
}
}
// do initial configuration of bundle from metadata
$bundle->configure( $base, $data );
return $bundle;
}
/**
* {@inheritDoc}
*/
public static function fromFile( Loco_fs_File $file ): ?Loco_package_Bundle {
$find = $file->getPath();
foreach( self::get_plugins() as $handle => $data ){
$boot = new Loco_fs_File( $handle );
$boot->normalize( $data['basedir'] );
// single file plugins can only match if given file is the plugin file itself.
if( basename($handle) === $handle ){
if( $boot->getPath() === $find ){
return self::create($handle);
}
}
// else check file is under plugin root.
else {
$base = $boot->dirname();
$path = $base.substr( $find, strlen($base) );
if( $path === $find ){
return self::create($handle);
}
}
}
return null;
}
}