Skip to content

Ghepes/wordpress-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wordpress-pachet

Package preparation - Separation of all css and js scripts from all wordpress folders:

Generate files end copy wordpress-all - wordpress-pachet/ ├── composer.json ├── wordpress/

a. to composer.json = scripts

{
    "name": "ghepes/wordpress-pachet",
    "description": "Pachet WordPress complet, inclusiv CSS/JS.",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "require": {
        "php": ">=7.4"
    },
    "autoload": {
        "psr-4": {
            "Namespace\\WordPress\\": "wordpress/"
        }
    },
    "scripts": {
        "post-install-cmd": [
            "php copy-assets.php"
        ],
        "post-update-cmd": [
            "php copy-assets.php"
        ]
    }
}

b. Add Folder

assets

c. Add new files

copy-assets.php

post-install-cmd.php

Add all wordpress to wordpress folder

d. To copy-assets.php add scripts

<?php
$sourceDirs = [
    'wordpress/wp-admin', 
    'wordpress/wp-includes', 
    'wordpress/wp-content/plugins', 
    'wordpress/wp-content/themes'
];
$targetDir = 'assets/';

foreach ($sourceDirs as $dir) {
    if (!is_dir($dir)) {
        continue;
    }

    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
    foreach ($files as $file) {
        if ($file->isFile() && preg_match('/\.(css|js)$/', $file->getFilename())) {
            $relativePath = str_replace($dir . '/', '', $file->getPathname());
            $dest = $targetDir . $relativePath;

            if (!is_dir(dirname($dest))) {
                mkdir(dirname($dest), 0777, true);
            }
            copy($file->getPathname(), $dest);
        }
    }
}

e. To post-install-cmd.php add scripts

<?php
$sourceDirs = ['wp-content/themes', 'wp-content/plugins', 'wp-admin', 'wp-includes'];
$targetDir = 'assets/';

foreach ($sourceDirs as $dir) {
    $files = glob($dir . '/**/*.{css,js}', GLOB_BRACE);
    foreach ($files as $file) {
        $relativePath = str_replace($dir . '/', '', $file);
        $dest = $targetDir . $relativePath;
        if (!is_dir(dirname($dest))) {
            mkdir(dirname($dest), 0777, true);
        }
        copy($file, $dest);
    }
}

f. Bash commands

composer install

g. All css and js files in /assets will be extracted from the wordpress folder

/assets

h. After the final extraction of the css and js scripts, I change the composer entries. And we change to the /assets folder

/assets New Script:

{
    "name": "ghepes/wordpress-scripts",
    "description": "Private package for CSS and JS scripts used in WordPress.",
    "type": "library",
    "license": "proprietary",
    "require": {
        "php": ">=7.4"
    },
    "autoload": {
        "psr-4": {
            "Namespace\\WordPressScripts\\": "assets/"
        }
    }
}

Oder with phpunit

{
    "name": "ghepes/wordpress-scripts",
    "description": "Private package for CSS and JS scripts used in WordPress.",
    "type": "library",
    "license": "proprietary",
    "require": {
        "php": ">=7.4"
    },
    "autoload": {
        "psr-4": {
            "Namespace\\WordPressScripts\\": "assets/"
        }
    },
    "scripts": {
        "test": "vendor/bin/phpunit"
    }
}

i. If you want to change to a private pack, you must add:

"repositories": [
 {
 "type": "vcs",
 "url": "https://github.com/numele-tau/wordpress-scripts"
 }
]

j. Use in WordPress Projects

In another WordPress project, you can add this package as a dependency:

composer requires your-name/wordpress-scripts
  1. Sorting and installing css and js: wordpress-pachet/ ├── composer.json # Composer configuration for the project ├── composer.lock # File automatically generated by Composer ├── copy-assets.php # PHP script for copying CSS/JS files ├── post-install-cmd.php # (Optional) Other post-install commands ├── assets/ # Folder for CSS/JS (automatically generated) ├── vendor/ # Dependencies installed automatically by Composer └── wordpress/ # WordPress core, manually included ├── wp-admin/ ├── wp-content/ │ ├── plugins/ │ ├── themes/ ├── wp-includes/ ├── wp-config.php └── alte fișiere WP...

TO

  1. After installing and extracting js and css main core wordpress will be removed for security: wordpress-scripts/ ├── composer.json # Composer configuration without wordpress core ├── assets/ # Required CSS/JS files │ ├── custom.js │ ├── style.css └── README.md # Documentation (opțional)

Releases

No releases published

Packages

No packages published