Files
Econgood-CIVI-Wordpress/wp-content/plugins/econgood_civi/econgood_civi.php
2025-09-25 13:03:24 +02:00

58 lines
1.8 KiB
PHP

<?php
/*
* Plugin Name: Econgood CiviCRM Integration
* Description: Handle custom Econgood CIVI and Wordpress modifications
* Version: 1.0.0
* Author: Gerrit Elbrink
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
//redirect to wp-admin
add_action('init', 'redirect_to_backend');
function redirect_to_backend() {
if(
!is_admin() &&
!is_wplogin() &&
!is_rest()
) {
wp_redirect( site_url('wp-admin') . '/admin.php?page=CiviCRM' );
exit();
}
}
if (!function_exists('is_rest')) {
/**
* Checks if the current request is a WP REST API request.
*
* Case #1: After WP_REST_Request initialisation
* Case #2: Support "plain" permalink settings
* Case #3: URL Path begins with wp-json/ (your REST prefix)
* Also supports WP installations in subfolders
*
* @returns boolean
* @author matzeeable
*/
function is_rest() {
$prefix = rest_get_url_prefix( );
if (defined('REST_REQUEST') && REST_REQUEST // (#1)
|| isset($_GET['rest_route']) // (#2)
&& strpos( trim( $_GET['rest_route'], '\\/' ), $prefix , 0 ) === 0)
return true;
// (#3)
$rest_url = wp_parse_url( site_url( $prefix ) );
$current_url = wp_parse_url( add_query_arg( array( ) ) );
return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
}
}
function is_wplogin(){
$ABSPATH_MY = str_replace(array('\\','/'), DIRECTORY_SEPARATOR, ABSPATH);
return ((in_array($ABSPATH_MY.'wp-login.php', get_included_files()) || in_array($ABSPATH_MY.'wp-register.php', get_included_files()) ) || (isset($_GLOBALS['pagenow']) && $GLOBALS['pagenow'] === 'wp-login.php') || $_SERVER['PHP_SELF']== '/wp-login.php');
}
?>