From 0096d5f017ba957ba3f7a1f9d72b3deea7b707bd Mon Sep 17 00:00:00 2001 From: Alberto Parziale Date: Mon, 30 Mar 2020 15:04:10 +0200 Subject: [PATCH] fix default values --- MaliniAeria/Accessors/AeriaAccessor.php | 16 +-- malini_aeria.php | 146 ++++++++++++------------ 2 files changed, 81 insertions(+), 81 deletions(-) diff --git a/MaliniAeria/Accessors/AeriaAccessor.php b/MaliniAeria/Accessors/AeriaAccessor.php index ae17891..55b36dd 100644 --- a/MaliniAeria/Accessors/AeriaAccessor.php +++ b/MaliniAeria/Accessors/AeriaAccessor.php @@ -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; @@ -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; } - -} \ No newline at end of file +} diff --git a/malini_aeria.php b/malini_aeria.php index ca95cd6..4c89b74 100644 --- a/malini_aeria.php +++ b/malini_aeria.php @@ -1,8 +1,7 @@ '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 = "{$plugin_name} was deactivated because {$dependencies} plugin is not active."; - } else { - $message = "{$plugin_name} was deactivated because {$dependencies} 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) { -?> -
-

-
-{$plugin_name} was deactivated because {$dependencies} plugin is not active."; + } else { + $message = "{$plugin_name} was deactivated because {$dependencies} plugin are not active."; + } + + add_action('admin_notices', function () use ($message) { + ?> +
+

+
+ $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 {$dependencies} 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 {$dependencies} before.", + 'Plugin dependency check', + [ + 'back_link' => true, + ] + ); + } + } ); -add_action('init', function() { +add_action('init', function () { \MaliniAeria\Updater::updateService(); -}); \ No newline at end of file +});