Coder Social home page Coder Social logo

vinkla / wordplate Goto Github PK

View Code? Open in Web Editor NEW
2.1K 50.0 154.0 1.86 MB

WordPlate is a boilerplate for WordPress, built with Composer and designed with sensible defaults.

PHP 91.59% CSS 2.65% JavaScript 5.76%
wordplate php wordpress boilerplate composer wordpress-packagist vite

wordplate's Introduction

WordPlate

WordPlate

WordPlate is a boilerplate for WordPress, built with Composer and designed with sensible defaults.

Build Status Monthly Downloads Latest Version

Features

  • WordPress + Composer = ♥️

    WordPress can be installed and updated with ease using Composer. To update WordPress, simply run the command composer update.

  • Environment Files

    Similar to Laravel, WordPlate stores environment variables, such as database credentials, in an .env file.

  • WordPress Packagist

    WordPress Packagist enables the management of WordPress plugins and themes through Composer.

  • Must-use plugins

    Don't worry about clients deactivating plugins; must-use plugins are enabled by default.

  • Vite.js

    Using Vite, you can rapidly set up and begin building and minifying your CSS and JavaScript.

  • Debugging

    Familiar debugging helper functions are integrated such as dump() and dd().

  • Clean UI

    Enhance the WordPress dashboard and improves the user experience for clients.

  • Security

    We've replaced WordPress' outdated and insecure MD5-based password hashing with modern and secure bcrypt using the roots/wp-password-bcrypt package.

Installation

Before using WordPlate, make sure you have PHP 8.2 and MySQL 8.0 installed on your computer. You'll also need to have Composer, a package manager for PHP, installed on your computer.

To install WordPlate, open your terminal and enter the following command:

composer create-project --prefer-dist vinkla/wordplate example-app

After installing WordPlate, you'll need to update the database credentials in the .env file. This file is located in the root directory of your project. Open the file and update the following lines with your database credentials:

DB_NAME=database
DB_USER=username
DB_PASSWORD=password

To run your WordPlate application, you may serve it using PHP's built-in web server. Open your terminal and navigate to the public directory of your project. Then, enter the following command:

php -S 127.0.0.1:8000 -t public/

Finally, open your web browser and visit the following URLs to view your WordPlate application:

Configuration

Public Directory

After installing WordPlate, you'll need to configure your web server's document or web root to be the public directory. This is where the main entry point for your application, index.php, is located.

By setting the public directory as your web server's document root, you ensure that all HTTP requests are routed through the front controller, which handles the requests and returns the appropriate responses.

This configuration helps to improve the security and performance of your application by preventing direct access to files outside of the public directory.

Environment Configuration

WordPlate makes it easy to manage different configuration values based on the environment where your application is running. For example, you may need to use a different database locally than you do on your production server.

To accomplish this, WordPlate uses the vlucas/phpdotenv PHP package. When you install WordPlate, a .env.example file is included in the root directory of your application. If you installed WordPlate via Composer, this file will automatically be renamed to .env. Otherwise, you should rename the file manually.

It's important to note that your .env file should not be committed to your application's source control. This is because each developer or server using your application may require a different environment configuration. Additionally, committing your .env file to source control would be a security risk in the event that an intruder gains access to your repository, as any sensitive credentials would be exposed.

To learn more about managing environment variables in WordPlate, you can refer to Laravel's documentation on the topic:

Salt Keys

It's important to add salt keys to your environment file. These keys are used to encrypt sensitive data, such as user sessions, and help to ensure the security of your application.

If you don't set the salt keys, your user sessions and other encrypted data may be vulnerable to attacks. To make it easier to generate secure salt keys, we've created a salt key generator that you can use. If you haven't already done so, copy the .env.example file to a new file named .env. Then visit the generator and copy the randomly generated keys to your .env file.

Plugins

WordPress Packagist

WordPlate includes integration with WordPress Packagist, a Composer repository that mirrors the WordPress plugin and theme directories. With this integration, you can install and manage plugins using Composer.

To install a plugin, use wpackagist-plugin as the vendor name and the plugin slug as the package name. For example, to install the clean-image-filenames plugin, you would use the following command:

composer require wpackagist-plugin/clean-image-filenames

The installed packages will be located in the public/plugins directory.

Here's an example of what your composer.json file might look like:

"require": {
    "wpackagist-plugin/clean-image-filenames": "^1.4"
}

For more information and examples, please visit the WordPress Packagist website.

Must Use Plugins

Must-use plugins (also known as mu-plugins) are a type of WordPress plugin that is installed in a special directory inside the content folder. These plugins are automatically enabled on all sites in the WordPress installation.

To install plugins into the mu-plugins directory, add the plugin name to the installer-paths of your composer.json file:

"installer-paths": {
    "public/mu-plugins/{$name}": [
        "type:wordpress-muplugin",
        "wpackagist-plugin/clean-image-filenames",
    ]
}

To install the plugin, use wpackagist-plugin as the vendor name and the plugin slug as the package name:

composer require wpackagist-plugin/clean-image-filenames

The plugin will be installed in the public/mu-plugins directory.

For more information on the must-use plugin autoloader, please refer to the Bedrock documentation.

Included Plugins

An easy-to-swallow painkiller plugin for WordPress. It is included by default in WordPlate. It removes a lot of default WordPress stuff you just can't wait to get rid of. It removes meta tags such as feeds, version numbers and emojis.

The plugin automatically converts language accent characters in filenames when uploading to the media library. Characters are converted into browser and server friendly, non-accent characters.

  • Räksmörgås.jpg → raksmorgas.jpg
  • Æblegrød_FTW!.gif → aeblegrod-ftw.gif
  • Château de Ferrières.png → chateau-de-ferrieres.png

Vite.js

Vite is a build tool that aims to provide a faster and leaner development experience for modern web projects. Vite is opinionated and comes with sensible defaults out of the box, but is also highly extensible via its Plugin API and JavaScript API with full typing support.

# Start the dev server...
npm run dev

# Build for production...
npm run build

To get started with Vite, please visit the documentation.

Mail

To set up custom SMTP credentials for sending emails in your WordPlate application, you need to configure the required environment variables in your .env file.

MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="Example"

If you're using a local email service like Mailpit, you need to disable encryption by setting the MAIL_ENCRYPTION environment variable to null.

FAQ

Can I add WordPress constants to the environment file?

This is possible by updating the public/wp-config.php file after the WordPlate application have been created.

define('WP_DISABLE_FATAL_ERROR_HANDLER', env('WP_DISABLE_FATAL_ERROR_HANDLER', false));

+define('WP_ALLOW_MULTISITE', env('WP_ALLOW_MULTISITE', true));

Then you may add the constant to the .env file.

WP_DEFAULT_THEME=wordplate
+WP_ALLOW_MULTISITE=true
Can I install languages with Composer?

If you want to install language packs using Composer, we recommend looking at the WP Languages project.

Can I rename the public directory?

Update your .gitignore, composer.json, .vite.config.js, and wp-cli.yml files with the new path to the public directory. Then, run composer update in the root of your project.

Can I rename the WordPress directory?

By default WordPlate will put the WordPress in public/wordpress. If you want to change this there are a couple of steps you need to go through. Let's say you want to change the default WordPress location to public/wp:

  1. Update the wordpress-install-dir path in your composer.json file.

  2. Update wordpress to wp in wordplate/public/.gitignore.

  3. Update the last line in the public/index.php file to:

    require __DIR__.'/wp/wp-blog-header.php';
  4. Update the WP_DIR environment variable in the .env file to wp.

  5. If you're using WP-CLI, update the path in the wp-cli.yml file to public/wp.

  6. Remove the public/wordpress directory if it exist and then run composer update.

Can I rename the theme directory?

For most applications you may leave the theme directory as it is. If you want to rename the wordplate theme to something else you'll also need to update the WP_DEFAULT_THEME environment variable in the .env file.

Can I use WordPlate with Laravel Herd or Valet?

If you're using Laravel Herd or Valet together with WordPlate, you may use our custom driver:

<?php

namespace Valet\Drivers\Custom;

use Valet\Drivers\BasicValetDriver;

class WordPlateValetDriver extends BasicValetDriver
{
    public function serves(string $sitePath, string $siteName, string $uri): bool
    {
        return is_dir($sitePath . '/public/wordpress');
    }

    public function isStaticFile(string $sitePath, string $siteName, string $url)
    {
        $staticFilePath = $sitePath . '/public' . $url;

        if ($this->isActualFile($staticFilePath)) {
            return $staticFilePath;
        }

        return false;
    }

    public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
    {
        return parent::frontControllerPath(
            $sitePath . '/public',
            $siteName,
            $this->forceTrailingSlash($uri)
        );
    }

    private function forceTrailingSlash(string $uri)
    {
        if (substr($uri, -1 * strlen('/wordpress/wp-admin')) === '/wordpress/wp-admin') {
            header('Location: ' . $uri . '/');
            exit;
        }

        return $uri;
    }
}
Can I use WordPlate with Tinkerwell?

If you're using Tinkerwell together with WordPlate, you may use our custom driver:

<?php

final class WordPlateTinkerwellDriver extends WordpressTinkerwellDriver
{
    public function canBootstrap($projectPath)
    {
        return file_exists($projectPath . '/public/wordpress/wp-load.php');
    }

    public function bootstrap($projectPath)
    {
        require $projectPath . '/public/wordpress/wp-load.php';
    }

    public function appVersion()
    {
        return 'WordPlate ' . get_bloginfo('version');
    }
}

Upgrade Guide

Upgrading from 11 to 12
  1. The wordplate/framework package has been archived. Update the composer.json file:

    "require": {
    -   "wordplate/framework": "^11.1",
    +   "composer/installers": "^2.1",
    +   "johnpbloch/wordpress-core-installer": "^2.0",
    +   "johnpbloch/wordpress-core": "^6.0",
    +   "roots/bedrock-autoloader": "^1.0",
    +   "roots/wp-password-bcrypt": "^1.1",
    +   "symfony/http-foundation": "^6.0",
    +   "symfony/var-dumper": "^6.0",
    +   "vlucas/phpdotenv": "^5.4"
    }
  2. Replace your public/wp-config.php file with the one in this repository. Remember to save any custom constants defined in your wp-config.php file.

  3. Add the src/helpers.php file from this repository and autoload it in the composer.json file:

    +"autoload": {
    +    "files": [
    +        "src/helpers.php"
    +    ]
    +}
  4. Run composer update in the root of your project.

Upgrading from 10 to 11
  1. WordPlate now requires PHP 8.0 or later.

  2. Bump the version number in the composer.json file to ^11.0.

  3. Run composer update in the root of your project.

Upgrading from 9 to 10
  1. WordPlate now requires PHP 7.4 or later.

  2. Bump the version number in the composer.json file to ^10.0.

  3. Rename WP_ENV to WP_ENVIRONMENT_TYPE in the environment file.

  4. Rename WP_THEME to WP_DEFAULT_THEME in the environment file.

  5. Rename WP_URL to WP_HOME in the environment file (if it exists).

  6. If you're using the WP_CACHE environment variable you'll need to define it in the public/wp-config.php file:

    $application->run();
    
    +define('WP_CACHE', env('WP_CACHE', false));
    
    $table_prefix = env('DB_TABLE_PREFIX', 'wp_');
  7. Optional: Rename WP_PREFIX to DB_TABLE_PREFIX in the following files:

    • .env
    • .env.example
    • public/wp-config.php
  8. Run composer update in the root of your project.

Upgrading from 8 to 9
  1. Bump the version number in the composer.json file to ^9.0.

  2. Copy the public/mu-plugins/mu-plugins.php file into your project.

  3. Update the public/.gitignore file to allow the new mu-plugins.php file:

    -mu-plugins/
    +mu-plugins/*
    +!mu-plugins/mu-plugins.php
  4. Run composer update in the root of your project.

Upgrading from 7 to 8
  1. WordPlate now requires PHP 7.2 or later.

  2. Bump the version number in the composer.json file to ^8.0.

    [!Note]
    WordPlate 8.0 requires WordPress 5.3 or later.

  3. Laravel's helper functions is now optional in WordPlate. If you want to use the functions, install the laravel/helpers package, with Composer, in the root of your project:

    composer require laravel/helpers
  4. Laravel's collections are now optional in WordPlate. If you want to use collections, install the tightenco/collect package, with Composer, in the root of your project:

    composer require tightenco/collect
  5. The mix helper function is now optional in WordPlate. If you want to use the function, install the ibox/mix-function package, with Composer, in the root of your project:

    composer require ibox/mix-function
  6. Replace any usage of asset, stylesheet_url and template_url functions with WordPress's get_theme_file_uri function.

  7. Replace any usage of stylesheet_path and template_path functions with WordPress's get_theme_file_path function .

  8. The base_path and template_slug functions have been removed.

  9. Run composer update in the root of your project.

Upgrading from 6 to 7
  1. Bump the version number in the composer.json file to ^7.0.

    [!Note]
    WordPlate 7.0 requires WordPress 5.0 or later.

  2. Update the realpath(__DIR__) to realpath(__DIR__.'/../') in the wp-config.php file.

  3. If your public directory isn't named public, add the following line to the wp-config.php file:

    $application->setPublicPath(realpath(__DIR__));
  4. Run composer update in the root of your project.

Upgrading from 5 to 6
  1. Bump the version number in the composer.json file to ^6.0.

  2. Update the realpath(__DIR__.'/../') to realpath(__DIR__) in the wp-config.php file.

  3. Run composer update in the root of your project.

Upgrading from 4 to 5
  1. Bump the version number in the composer.json file to ^5.0.

  2. Copy and paste the contents of the wp-config.php file into your application.

    [!Note]
    Make sure you don't overwrite any of your custom constants.

  3. Run composer update in the root of your project.

Acknowledgements

WordPlate wouldn't be possible without these amazing open-source projects.

License

The WordPlate package is open-sourced software licensed under the MIT license.

wordplate's People

Contributors

aaemnnosttv avatar adamlindqvist avatar dependabot-preview[bot] avatar dependabot[bot] avatar fiskhandlarn avatar frozzare avatar guicapanema avatar helit avatar kexhest avatar ligne13 avatar martinbmnt avatar mikaelmattsson avatar pakito83 avatar palpalani avatar puredazzle avatar qwp6t avatar svenluijten avatar tditlu avatar ttskch avatar vguerrerobosch avatar vinkla avatar wolfiezero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wordplate's Issues

WP_HTTP_BLOCK_EXTERNAL set to true causes error

WP_HTTP_BLOCK_EXTERNAL set to true causes error, is this function necessary for the bootstrap?

PHP Warning: An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.) in /(path)/wp-admin/includes/update.php on line 117

Tested on PHP Version 5.5.10.

Delete Hello World Post and Page

It would be cool to delete the default Hello World page and post by default when the theme is activated.

Why doesn't WordPress offer this by default? Does anyone know any downside to this?

Cleanup Configuration Files

I think we should make the configuration files simpler. Some of the options we shouldn't care about since they make WordPress better.

  • Remove shortcodes from widgets.php (c3645a4)
  • Remove default pages from pages.php (05b79f1)
  • Remove soil-jquery-cdn option from soil.features array (0d8a543)
  • Remove app.php and add the keys to theme.php (22efae8)
  • Make image_path and image_width into an array (74c3b8c)
  • Make tinymce_blockformats and tinymce_disabled into an array (039789e)
  • Rename remove_dashboard_widgets to widgets (c4001a2)
  • Rename remove_menu_items to items (dd73706)
  • Rename remove_menu_bar_links to links (dd73706)
  • Rename panel_tabs to tabs (dd73706)

Add Google Analytics To Config

Google Analytics key currently exists within the .env.example file. It would be cool to move it to either the config/app.php or config/theme.app.

Add Image Optimization Plugin

Wouldn't it be good to integrate a good image optimizer by default? Maybe tiny-compress?

"wpackagist-plugin/tiny-compress": "~1.0"

@puredazzle @magnus-bergman do you guys have any thoughts about this topic? Does is belong in the boilerplate?

Add support for environment check and dotenv files.

It would be great an environment check and dotenv files to the project.

Something similar to how Laravel handle this in start.php.

$env = $app->detectEnvironment(array(
    'local' => ['homestead'],
    'production' => ['example.com', '*.com']
));

This piece of code will look for a .env.production.php and a .env.local.php file in the project root.

An example of a dotenv file would look something like this:

return [
    'DB_HOST' => 'localhost',
    'DB_USERNAME' => 'homestead',
    'DB_PASSWORD' => 'secret',
    'DB_NAME' => 'wordpress'
];

Add Default Pages

Add default pages through the configuration files. The example below will create default pages in WordPress when the theme is activated.

'pages' => [
    [
        'title' => 'Start',
        'type' => 'home',
    ],
    [
        'title' => 'About',
        'template' => 'pages/about.php',
    ],
    [
        'title' => 'Archive',
        'type' => 'blog',
        'parent' => 'About',
    ],
]

Test remove_menu_page()

Test if remove_menu_page() is less buggy in newer versions of WordPress. We've had problems with it in the past. For example, the media button stopped working when the Media menu item is removed. Menu items is currently hidden with CSS.

wp_enqueue_scripts doesn't work as expected

Because of the structure of the project, the function wp_enqueue_scripts, in functions.php doesn't link to the right file.

/**
 * Enqueue and register scripts the right way.
 *
 * @return  void
 */
add_action('wp_enqueue_scripts', function()
{

    // style
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );

    // scripts
    wp_deregister_script('jquery');
    wp_enqueue_script('main', get_template_directory_uri().'/assets/scripts/main.js', '', '', true);
});

This creates links in the footer and the header for scripts and styles. But because of the structure of this project it links to the wrong URL. For example:

http://localhost/wp-content/themes/boilerplate/assets/scripts/main.js?ver=3.9.2

Add WP_HOME and WP_SITEURL

We should site home and siteurl columns in the options table from our config file.

/** Set the home url to the current domain. */
define('WP_HOME', env('WP_URL', 'http://'.$_SERVER['HTTP_HOST']));

/** Custom WordPress directory. */
define('WP_SITEURL', WP_HOME .'/wordpress');

/** Custom content directory. */
define('WP_CONTENT_DIR', __DIR__.'/wp-content');
define('WP_CONTENT_URL', WP_HOME.'/wp-content');

Add Rename Command

It would be cool if we added a rename command to rename the current theme.

Add Theme Color to Theme

We should add Android theme color to the header.php as a default.

<meta name="theme-color" content="#464646">

Add HTML5 Markup

Add HTML5 markup to WordPress. This should be default and not included within the config files.

Currently supported values: search-form, comment-form, comment-list, gallery, caption, widgets.

Move Theme To Root

It would be cool if we could have the theme in within the root directory.

Update Header HTML

The header.php should be updated.

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width">

Add Title Tag Support To Theme

Add title tag support to the functions.php in the default boilerplate theme. I don't think this shouldn't be added within the framework. If of course anyone else has any other input I haven't thought of.

Add .htaccess with wp-admin redirect.

Add a .htaccess file to the webroot. The user currently needs to go through /wordpress/wp-admin to visit the admin area. Lets add a .htaccess file that redirects the user to the correct URL.

Remove ACF Simple Editor

I do agree this is a great feature. Though, it doesn't belong in core. Since it is plugin specific. I think it will be best if we remove it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.