Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
primogenial
/
languages
/
wp-content
/
plugins
/
elementor
/
app
/
modules
/
import-export
/
assets
/
js
/
hooks
:
use-plugins-data.js
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
import { useMemo } from 'react'; export const PLUGINS_KEYS = Object.freeze( { ELEMENTOR: 'Elementor', ELEMENTOR_PRO: 'Elementor Pro', } ); export default function usePluginsData( plugins ) { const getPluginsData = () => { if ( ! plugins ) { return []; } const elementorPlugins = [], generalPlugins = []; plugins.forEach( ( plugin ) => { switch ( plugin.name ) { case PLUGINS_KEYS.ELEMENTOR: // Making sure that the core plugin is always first. elementorPlugins.unshift( plugin ); break; case PLUGINS_KEYS.ELEMENTOR_PRO: // Making sure that the pro plugin is always second. elementorPlugins.push( plugin ); break; default: generalPlugins.push( plugin ); } } ); // Making sure that the elementor plugins are always first. return elementorPlugins.concat( generalPlugins ); }; return { pluginsData: useMemo( () => getPluginsData(), [ plugins ] ), }; }