Skip to content

Commit

Permalink
fix default values
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Parziale committed Mar 30, 2020
1 parent 1990874 commit 0096d5f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 81 deletions.
16 changes: 9 additions & 7 deletions MaliniAeria/Accessors/AeriaAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@

class AeriaAccessor implements AccessorInterface
{

protected static $aeria_posts_fields_cache = [];

public static function getPostFields($wp_post) {
$key = 'post_' . $wp_post->ID;
public static function getPostFields($wp_post)
{
$key = 'post_'.$wp_post->ID;
if (!isset(static::$aeria_posts_fields_cache[$key])) {
static::$aeria_posts_fields_cache[$key] = \get_aeria_fields($wp_post);
}

return static::$aeria_posts_fields_cache[$key];
}

public function retrieve(Post $post, ...$arguments) {
public function retrieve(Post $post, ...$arguments)
{
$wp_post = $post->wp_post;

$metabox = isset($arguments[0]) ? $arguments[0] : null;
Expand All @@ -40,9 +42,9 @@ public function retrieve(Post $post, ...$arguments) {
$target = isset($post_aeria_fields[$metabox])
? $post_aeria_fields[$metabox]
: [];
return isset($target[$metafield]) && !empty($target[$metafield])

return isset($target[$metafield])
? $target[$metafield]
: $default;
}

}
}
146 changes: 72 additions & 74 deletions malini_aeria.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
/**
* Malini Aeria
* Malini Aeria.
*
* @package Malini Aeria
* @author Caffeina
* @copyright 2019 Caffeina
* @license MIT
Expand All @@ -11,102 +10,101 @@
* Plugin Name: Malini Aeria
* Plugin URI: https://github.com/caffeinalab/malini_aeria
* Description: Malini Aeria is a Malini plugin to quickly decorate content with Aeria defined data.
* Version: 0.1.2
* Version: 1.0.0
* Author: Caffeina
* Author URI: https://caffeina.com
* Text Domain: malini
* License: MIT
*/
defined('ABSPATH') or die('No script kiddies please!');

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
require_once __DIR__.'/vendor/autoload.php';

require_once __DIR__ . '/vendor/autoload.php';

add_action('malini_register_decorators', function() {
malini_add_decorator('aeria', \MaliniAeria\Decorators\WithAeria::class);
add_action('malini_register_decorators', function () {
malini_add_decorator('aeria', \MaliniAeria\Decorators\WithAeria::class);
});

add_action(
'malini_register_accessors',
function() {
function () {
malini_add_accessor('aeria', \MaliniAeria\Accessors\AeriaAccessor::class);
}
);

$malini_aeria = [
'name' => 'Malini Aeria',
'reference' => 'malini_aeria/malini_aeria.php',
'requirements' => [
'Malini' => 'malini/malini.php',
'Aeria' => 'aeria/aeria.php',
]
'name' => 'Malini Aeria',
'reference' => 'malini_aeria/malini_aeria.php',
'requirements' => [
'Malini' => 'malini/malini.php',
'Aeria' => 'aeria/aeria.php',
],
];

add_action('admin_init', function() use ($malini_aeria) {
$config = $malini_aeria;

$plugin_name = $config['name'];
$plugin_reference = $config['reference'];
$requires = $config['requirements'];

$plugins_needed = [];
foreach ($requires as $requirement_name => $requirement_reference) {
if (!is_plugin_active($requirement_reference) && is_plugin_active($plugin_reference)) {
$plugins_needed[] = $requirement_name;
}
}
add_action('admin_init', function () use ($malini_aeria) {
$config = $malini_aeria;

if (!empty($plugins_needed)) {
deactivate_plugins($plugin_reference);
$plugin_name = $config['name'];
$plugin_reference = $config['reference'];
$requires = $config['requirements'];

$dependencies = implode(', ', $plugins_needed);
if (count($plugins_needed) == 1) {
$message = "<b>{$plugin_name}</b> was deactivated because <b>{$dependencies}</b> plugin is not active.";
} else {
$message = "<b>{$plugin_name}</b> was deactivated because <b>{$dependencies}</b> plugin are not active.";
}
$plugins_needed = [];
foreach ($requires as $requirement_name => $requirement_reference) {
if (!is_plugin_active($requirement_reference) && is_plugin_active($plugin_reference)) {
$plugins_needed[] = $requirement_name;
}
}

add_action('admin_notices', function() use($message) {
?>
<div class="notice updated is-dismissible">
<p><?= $message ?></p>
</div>
<?php
});
}
if (!empty($plugins_needed)) {
deactivate_plugins($plugin_reference);

$dependencies = implode(', ', $plugins_needed);
if (count($plugins_needed) == 1) {
$message = "<b>{$plugin_name}</b> was deactivated because <b>{$dependencies}</b> plugin is not active.";
} else {
$message = "<b>{$plugin_name}</b> was deactivated because <b>{$dependencies}</b> plugin are not active.";
}

add_action('admin_notices', function () use ($message) {
?>
<div class="notice updated is-dismissible">
<p><?= $message; ?></p>
</div>
<?php
});
}
});

register_activation_hook(
__FILE__,
function() use($malini_aeria) {
if (!function_exists('is_plugin_active_for_network')) {
include_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}

$requires = $malini_aeria['requirements'];

$plugins_needed = [];
foreach ($requires as $requirement_name => $requirement_reference) {
if (!is_plugin_active($requirement_reference)) {
$plugins_needed[] = $requirement_name;
}
}

if (!empty($plugins_needed)) {
$dependencies = implode(', ', $plugins_needed);
deactivate_plugins(plugin_basename(__FILE__));
// Throw an error in the WordPress admin console.
wp_die(
"Please activate <b>{$dependencies}</b> before.",
"Plugin dependency check",
[
"back_link" => true
]
);
}
}
__FILE__,
function () use ($malini_aeria) {
if (!function_exists('is_plugin_active_for_network')) {
include_once ABSPATH.'/wp-admin/includes/plugin.php';
}

$requires = $malini_aeria['requirements'];

$plugins_needed = [];
foreach ($requires as $requirement_name => $requirement_reference) {
if (!is_plugin_active($requirement_reference)) {
$plugins_needed[] = $requirement_name;
}
}

if (!empty($plugins_needed)) {
$dependencies = implode(', ', $plugins_needed);
deactivate_plugins(plugin_basename(__FILE__));
// Throw an error in the WordPress admin console.
wp_die(
"Please activate <b>{$dependencies}</b> before.",
'Plugin dependency check',
[
'back_link' => true,
]
);
}
}
);

add_action('init', function() {
add_action('init', function () {
\MaliniAeria\Updater::updateService();
});
});

0 comments on commit 0096d5f

Please sign in to comment.