array( // Shared helpers first: the files below call them. 'includes/helpers.php', 'includes/plugin.php', 'includes/cpt.php', 'includes/block.php', 'includes/actions/action-base.php', 'includes/protection.php', ), 'actions' => array( 'includes/actions/stacklar-action-send-mail.php', 'includes/actions/stacklar-action-form-config.php', ), 'rest' => array( 'includes/rest/register-action-handlers.php', 'includes/rest/stacklar-rest-actions.php', ), 'admin' => array( 'includes/admin/class-stacklar-duplicate.php', ), ) ); return is_array( $groups ) ? $groups : array(); } } if ( ! function_exists( 'stacklar_is_cli_request' ) ) { function stacklar_is_cli_request() { return ( defined( 'WP_CLI' ) && WP_CLI ) || 'cli' === PHP_SAPI; } } if ( ! function_exists( 'stacklar_is_rest_request' ) ) { function stacklar_is_rest_request() { return defined( 'REST_REQUEST' ) && REST_REQUEST; } } if ( ! function_exists( 'stacklar_should_load_dependency_group' ) ) { function stacklar_should_load_dependency_group( $group ) { $group = sanitize_key( (string) $group ); switch ( $group ) { case 'admin': $should_load = ( function_exists( 'is_admin' ) && is_admin() ) || stacklar_is_cli_request(); break; case 'rest': $should_load = stacklar_is_rest_request() || stacklar_is_cli_request(); break; default: $should_load = true; break; } return (bool) apply_filters( 'stacklar_should_load_dependency_group', $should_load, $group ); } } if ( ! function_exists( 'stacklar_load_dependency_group' ) ) { function stacklar_load_dependency_group( $group ) { static $loaded = array(); $group = sanitize_key( (string) $group ); if ( '' === $group || ! empty( $loaded[ $group ] ) ) { return; } $groups = stacklar_get_dependency_groups(); if ( empty( $groups[ $group ] ) || ! is_array( $groups[ $group ] ) ) { return; } $loaded[ $group ] = true; foreach ( $groups[ $group ] as $file ) { stacklar_require_file( $file ); } } } if ( ! function_exists( 'stacklar_load_rest_dependencies' ) ) { function stacklar_load_rest_dependencies() { stacklar_load_dependency_group( 'rest' ); } } if ( ! function_exists( 'stacklar_load_dependencies' ) ) { function stacklar_load_dependencies() { $groups = stacklar_get_dependency_groups(); foreach ( array_keys( $groups ) as $group ) { if ( stacklar_should_load_dependency_group( $group ) ) { stacklar_load_dependency_group( $group ); } } add_action( 'rest_api_init', 'stacklar_load_rest_dependencies', -100 ); } }