true ) ); if ( $types && isset( $types['attachment'] ) ) { unset( $types['attachment'] ); $default[] = 'media'; } $types = apply_filters( 'acf/rest_api/types', array_merge( $types, array_combine( $default, $default ) ) ); if ( is_array( $types ) && count( $types ) > 0 ) { foreach( $types as $type ) { if ( 'term' == $type ) { $controller = new ACF_To_REST_API_Term_Controller( $type ); } elseif ( 'media' == $type ) { $controller = new ACF_To_REST_API_Attachment_Controller( $type ); } elseif ( 'option' == $type ) { $controller = new ACF_To_REST_API_Option_Controller( $type ); } else { $controller = new ACF_To_REST_API_Controller( $type ); } $controller->register_routes(); $controller->register_hooks(); } } } public static function is_plugin_active( $plugin ) { if ( ! function_exists( 'is_plugin_active' ) ) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } if ( 'rest-api' == $plugin ) { return is_plugin_active( 'rest-api/plugin.php' ); } elseif ( 'acf' == $plugin ) { return is_plugin_active( 'advanced-custom-fields/acf.php' ) || is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) || is_plugin_active( 'acf-pro/acf.php' ); } elseif ( 'all' == $plugin ) { return self::is_plugin_active( 'rest-api' ) && self::is_plugin_active( 'acf' ); } return false; } public static function is_plugin_installed( $plugin ) { if ( ! function_exists( 'get_plugins' ) ) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } $paths = false; if ( 'rest-api' == $plugin ) { $paths = array( 'rest-api/plugin.php' ); } elseif ( 'acf' == $plugin ) { $paths = array( 'advanced-custom-fields-pro/acf.php', 'acf-pro/acf.php', 'advanced-custom-fields/acf.php' ); } if ( $paths ) { $plugins = get_plugins(); if ( $plugins ) { foreach ( $paths as $path ) { if ( ! empty( $plugins[$path] ) ) { return $path; } } } } return false; } public static function missing_notice() { if ( ! self::is_plugin_active( 'rest-api' ) ) { include dirname( __FILE__ ) . '/includes/admin/views/html-notice-missing-rest-api.php'; } if ( ! self::is_plugin_active( 'acf' ) ) { include dirname( __FILE__ ) . '/includes/admin/views/html-notice-missing-acf.php'; } } } add_action( 'plugins_loaded', array( 'ACF_To_REST_API', 'init' ) ); }