Skip to content
Snippets Groups Projects
Commit 4aee3b0d authored by Lucas García's avatar Lucas García
Browse files

Merge branch 'feature/use-dependency-checker' into 'main'

Use dependency checker plugin

See merge request coopdevs/website/wp/wp-plugins/wpct-odoo-connect!10
parents 5f0d9433 8a21995c
No related branches found
No related tags found
No related merge requests found
<?php
function wpct_oc_missing_dependencies()
{
$WPCT_OC_DEPENDENCIES = $GLOBALS['WPCT_OC_DEPENDENCIES'];
$missings = array();
foreach ($WPCT_OC_DEPENDENCIES as $name => $file) {
if (!wpct_oc_is_plugin_active($file)) {
$missings[] = $name;
}
}
return $missings;
}
function wpct_oc_is_plugin_active($plugin_main_file_path)
{
return in_array($plugin_main_file_path, wpct_oc_get_active_plugins());
}
function wpct_oc_get_active_plugins()
{
return apply_filters('active_plugins', get_option('active_plugins'));
}
function wpct_oc_admin_notices()
{
$missings = wpct_oc_missing_dependencies();
$list_items = array();
foreach ($missings as $missing) {
$list_items[] = '<li><b>' . $missing . '</b></li>';
}
$notice = '<div class="notice notice-warning" id="wpct-oc-warning">
<p><b>WARNING:</b> WPCT Odoo Connect missing dependencies:</p>
<ul style="list-style-type: decimal; padding-left: 1em;">' . implode(',', $list_items) . '</ul>
</div>';
echo $notice;
}
function wpct_oc_check_dependencies()
{
$missings = wpct_oc_missing_dependencies();
if (sizeof($missings) > 0) {
add_action('admin_notices', 'wpct_oc_admin_notices');
}
}
......@@ -23,17 +23,6 @@ define('WPCT_OC_DEFAULT_LOCALE', getenv('WPCT_OC_DEFAULT_LOCALE') ? getenv('WPCT
require_once "includes/options-page.php";
require_once 'includes/user-language.php';
// Dependency checker
require_once "includes/dependencies-checker.php";
// Define plugin dependencies
$GLOBALS['WPCT_OC_DEPENDENCIES'] = array(
'JWT Authentication' => 'jwt-authentication-for-wp-rest-api/jwt-auth.php'
);
// Plugin dependencies validation
wpct_oc_check_dependencies();
// Middleware headers setter
function wpct_oc_set_headers($request_headers, $feed, $entry, $form)
{
......@@ -41,3 +30,12 @@ function wpct_oc_set_headers($request_headers, $feed, $entry, $form)
$request_headers['Accept-Language'] = wpct_oc_accept_language_header();
return $request_headers;
}
add_action('admin_init', 'wpct_oc_init', 10);
function wpct_oc_init()
{
add_filter('wpct_dependencies_check', function ($dependencies) {
$dependencies['jwt-authentication-for-wp-rest-api/jwt-auth.php'] = '<a href="https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/">JWT Authentication</a>';
return $dependencies;
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment