helsingborg-stad / Municipio

A theme specifically made for municipalities.
MIT License
36 stars 13 forks source link
hacktoberfest php wordpress

Municipio 3

Download theme.

To download a complete out of the box working plugin without the need to compile or fetch dependencies. Go here and download the full-release.zip from the latest version.

Getting started

It is recommended to install the bundled version of municipio trough our build management repository. This can be found here.

To get started you'll need to install the required npm and composer packages. To install these components you will need to have Node.js and Composer installed on your system.

$ cd [THEME-DIR]
$ php build.php

Dependencies

Municipio requires ACF PRO.

Coding standards

For PHP, use PSR-2 and PSR-4 where applicable.

Gulp

You can use Gulp to compile, concatenate and minify SASS and JavaScript. The compiling of SASS will also automatically add vendor-prefixes where needed.

To compile both js and sass and start the "watch" task run the following command from the theme directory:

$ gulp

We added support for webpack

Webpack is a bit faster than gulp. So if you prefer to use webpack instead of gulp, just run the following command:

$ npm run watch

or just for a single build:

$ npm run build

NPM scripts

Composer

You can install composer dependencies with.

$ composer install

Composer scripts

composer run test # Run phpunit tests
composer run test:coverage # Run phpunit tests with code coverage
composer run lint # Run phpcs
composer run lint:changed # Run phpcs on changed files (Compares to main branch).
composer run fix # Run phpcbf to apply fixes to code.
composer run fix:changed # Run phpcbf to apply fixes to changed files (Compares to main branch).

Constants

Block author pages

Author pages is blocked by default. To "unblock" add the following constant to wp-config (or other suitable place).

define('MUNICIPIO_BLOCK_AUTHOR_PAGES', false);

Load styleguide from a different host

Constants for setting the base URI to the styleguide. Useful for third-party sites.

define('MUNICIPIO_STYLEGUIDE_URI', '//example.com/style/guide');

Load specific version of styleguide

Constants that lock version of the styleguide. Comes in handy when you want to enshure maximum stability of a site.

define('STYLEGUIDE_VERSION', 1.0.32);

Load specific developement version of styleguide

Constant that load local verrsion of the styleguide.

define('DEV_MODE', true);

CSS class in BEMIT style for theme name

Constant that contains the current theme name in BEM format. Usable when you wnat to connect component styling directly to the theme.You cannot change this.

MUNICIPIO_BEM_THEME_NAME

Actions

Municipio/blog/post_info

Blog post info header (single)

do_action('Municipio/author_display/name', $post);

Municipio/share_post/recipients

Do action on sharing post by email, e.g. send a notification

do_action('Municipio/share_post/recipients', $user, $recipients);

Municipio/comment/save_like

Do action on comment like

do_action('Municipio/comment/save_like', $comment, $userId, $create);

Filters

Municipio/Template/viewData

apply_filters('Municipio/Template/single/viewData', $viewData, $postType);
apply_filters('Municipio/Template/archive/viewData', $viewData, $postType, $template);
apply_filters("Municipio/Template/{$postType}/viewData", $viewData);
apply_filters("Municipio/Template/{$postType}/single/viewData", $viewData);
apply_filters("Municipio/Template/{$postType}/archive/viewData", $viewData, $template);

Deprecated:

Municipio/theme/key

Filters the theme/styleguide asset key.

apply_filters('Municipio/theme/key', $key);

Municipio/author_display/name

Set the name of the author display

apply_filters('Municipio/author_display/name', $name, $userId);

Municipio/author_display/title

Set the title label for the author name display

apply_filters('Municipio/author_display/title', $title);

Municipio/ajax_url_in_head

Set the ajax_url in the

apply_filters('Municipio/ajax_url_in_head', $ajax_url);

Municipio/favicon_sizes

Add sizes to theme options for favicon

apply_filters('Municipio/favicon_sizes', $sizes);

Municipio/favicon_tag

Add sizes to theme options for favicon

apply_filters('Municipio/favicon_tag', $tag, $icon);

Municipio/header_grid_size

Applied to classes string for header sizes.

apply_filters('Municipio/header_grid_size', $classes);

Municipio/mobile_menu_breakpoint

Applied to classes string for mobile hamburger menu breakpoint.

apply_filters('Municipio/mobile_menu_breakpoint', $classes);

Municipio/logotype_text

Applied to the text that displays as the logo when now logotype image is uploaded in theme options.

apply_filters('Municipio/logotype_text', $title);

Municipio/logotype_class

Applied to the logotype class attirbute

apply_filters('Municipio/logotype_class', $classes);

Municipio/logotype_tooltip

Applied to the logotype class attirbute

apply_filters('Municipio/logotype_tooltip', $tooltip);

Municipio/blade/template_types

Applied to the list of Blade template types.

apply_filters('Municipio/blade/template_types', $types);

Municipio/search_result/…

Multiple filters applied to the contents of a search result

apply_filters('Municipio/search_result/date', $date, $post);
apply_filters('Municipio/search_result/title', $title, $post);
apply_filters('Municipio/search_result/excerpt', $excerpt, $post);
apply_filters('Municipio/search_result/permalink_url', $permalink_url, $post);
apply_filters('Municipio/search_result/permalink_text', $permalink_text, $post);

Municipio/search_form/…

Filters applied to the search form

apply_filters('Municipio/search_form/action', $url);

Municipio/archive/sort_keys

Modify the avaiable sorting keys for archives

apply_filters('Municipio/archive/sort_keys', $keys, $postType);

Municipio/archive/date_filter

Modify the date filter WHERE clause

apply_filters('Municipio/archive/date_filter', $where, $from, $to);

Municipio/Breadcrumbs

Show/hide (true/false) breadcrumbs

apply_filters('Municipio/Breadcrumbs', $bool, get_queried_object())

Municipio/Breadcrumbs/Items

Filter the items/links in the breadcrumb

apply_filters('Municipio/Breadcrumbs/Items', $items, get_queried_object());

Municipio/admin/editor_stylesheet

Change custom editor stylesheet

apply_filters('Municipio/admin/editor_stylesheet', $url);

Municipio/oembed/should_filter_markup

Decide if oembed markup should be filtered to HbgPrime video player (youtube and vimeo) or not.

apply_filters('Municipio/oembed/should_filter_markup', true, $url, $postId);

Municipio/Menu/Vertical/EnabledSidebars

Dictates what sidebars that sould be active on the current page to show the vertical menu. Simple array containing the sidebar id's.

apply_filters('Municipio/Menu/Vertical/EnabledSidebars', $sidebars);

Municipio/archive/tax_query

Additional taxonomy queries.

apply_filters('Municipio/archive/tax_query', $taxQuery, $query);

Municipio/taxonomy/tag_style

Adds custom style to taxonomy labels.

apply_filters('Municipio/taxonomy/tag_style', $style, $term, $taxonomy);

Municipio/Menu/Vertical/Items

Items that should be visible in the vertical navigation menus. Represented as dots with hover-labels.

apply_filters('Municipio/Menu/Vertical/EnabledSidebars', array(array('title' => 'Page section title', 'link' => '#anchorlink'));

Municipio/ContentType/schemaParams

Modify the schema parameters for a content type. This filter is applied to the array of schema parameters associated with a content type, allowing for the extension or modification of the structured data (schema.org) attributes for that content type.

add_filter('Municipio/ContentType/schemaParams', function($schemaParams, $contentTypeKey) {
    if ($contentTypeKey === 'yourContentTypeKey') {
        $schemaParams['newParameter'] = [
            'schemaType' => 'Text',
            'value' => 'Custom Value'
        ];
    }

    return $schemaParams;
}, 10, 2);

Municipio/Controller/SingularContentType/listing

Modifies the listing array for the Place content type by appending location-related list items. This allows for the inclusion of additional information such as street name or a Google Maps link directly within the listing display.

add_filter('Municipio/Controller/SingularContentType/listing', function($listing, $fields) {
    // Example modification to the listing array
    if (!empty($fields['custom_field'])) {
        $listing['custom_field'] = $fields['custom_field'];
    }

    return $listing;
}, 10, 2);

REST routes

The following REST API routes are available from the theme.

[GET] municipio/v1/view/render/{view}

Returns html for the

Example usage

fetch('/wp-json/municipio/v1/view/render/partials/preloader')
    .then((response) => console.log(response))

Dev mode

To load assets from local styleguide. Set contant DEV_MODE to "true"

define('DEV_MODE', true);

Theme fonts

Municipio is integrated with google web-fonts. It enables smart loading of fonts preventing invisible fonts using Google & Adobe webfont loader.

define('WEB_FONT', 'Roboto'); //The google fonts name (without weights)
define('WEB_FONT_REMOTE', true); //Load font kit from cdn

Version 2.0

The goal of version 2.0 is to restructure the theme frontend and move towards the BEM (IT) standard for markup. More filters will be added in a automatic manner, mutch like ACF doe's it. These will for now, be documented below.

Deprecated functionality (notice phase)

Version 2.0 will introduce some warnings aboute the removal of some prevoius functionality. According to plan, this functionality will be actually be removed in version 3.0. Functions that will be removed in 3.0 are.

Filters

Deprecated filters

Blade view filter

All variables sent (created) in a controller will automatically go trough a filter named with the variable key.

apply_filters('Municipio/{{KEY}}', $var);

Global view filter

You may prefer to get a full array of everything sent to a view. After the filter above has run, a global filter will be applied. This replaces the old filter.

apply_filters('Municipio/viewData', $var);

Constants

MUNICIPIO_FRAGMENT_CACHE - Set to false to remove fragment cache.

Theme view structure

bem-views
│   [Main folder for  theme views, containing WordPress templates like page.blade.php]
│
└───components
│   │   [Components for the theme like card.blade.php]
│   │
└───partials
│   │   [Big chunks that are reused in templates footer.blade.php]
│   │
└───templates
    │   [General templates that are included in main WordPress views like master.blade.php]
│   │
└───utilities
    │   [Small pieces used by components like button.blade.php]
│   │
└───widgets
    │   [Widgetized components]
    │

PHP Tests

Municipio uses PHPUnit for unit testing. For mocking and stubbing we use WP_Mock. This means that you can use WP_Mock, Mockery(since this is a wrapper for WP_Mock) and PHPUnit_MockObject for mocking and stubbing.

PHPUnit Tests file structure

All tests are stored in the tests/phpunit/tests folder. The file structure should mirror the file structure of the theme. The file name should be the same as the file you want to test. For example, if you want to test the file src/Controller/Base.php you should create the file tests/phpunit/tests/Controller/Base.php. To avoid having too large test files, you can instead create a folder with the same name as the file you want to test and put the test files inside. Please note that for separating files by which class function you are testing, you should name the file e.g. Base.functionName.php.

Running PHPUnit tests

Run composer test in the terminal.

Running PHPUnit tests with code coverage

Run composer test:coverage in the terminal. This will generate a code coverage report in the tests/phpunit/.coverage folder.

Image compression

Municipio supports image compression with shortpixel. This will enque a cronjob with a slight delay to compress newly uploaded images. Simpley define SHORTPIXEL_API_KEY constant in your config file and that's it!

Compression level will be medium/glossy for high quality photos.

Tested with support from BrowserStack

This software is tested with the awesome tools from Browserstack.