npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@geoffdusome/acf-meta-builder

v2.5.0

Published

A gulp task to create ACF json files by reading your project files and parsing out function calls.

Downloads

6

Readme

@geoffdusome/acf-meta-builder

GitHub stars GitHub issues GitHub license

A package that contains a gulp task to create ACF json files by reading your project files and parsing out specific function calls.

Installation

In order to use this gulp task, please include @geoffdusome/acf-meta-builder as a dependency in your package.json file. Otherwise, the package can be installed by running npm i @geoffdusome/acf-meta-builder on your command line.

Usage

  1. Require the package: const metaBuilder = require('@geoffdusome/acf-meta-builder');
  2. Create the task:
gulp.task('buildMeta', function( done ) {
	metaBuilder.createMeta(['functions.php', 'header.php', 'footer.php'])
		.then(function(result) {
			console.log(result);
			done();
		}, function(err) {
			console.log(err);
			done();
		});
});
  1. Watch files for changes: gulp.watch(['*.php'], gulp.series('buildMeta'));

createMeta( excludes )

The createMeta task will look for PHP function calls containing acfmb as the function name. acfmb accepts 4 total parameters, with the first 3 being required and the last optional (please see function call below for more information). The task will loop through all files that contain a mention of the acfmb function, and then parses out all instances of the acfmb function separately to create a JSON array, which is then written to a JSON file.

Please note that the "location" of the meta is based off of the file name. I have set conventions for file names that allow me to point the meta to the right place, so if these conventions are not followed, you will have issues.

page.php: page_template = default
page-home.php: page_template = page-home.php
post-template-blog-layout.php: post_template = post-template-blog-layout.php
{post-type}/views.php: post_type = {post-type}
single.php: post_type = post
archive.php: post_type = post
single-{post-type}.php: post_type = {post-type}
archive-{post-type}.php: post_type = {post-type}
option-pages/{option-page-name}.php: options_page = {option-page-name} blocks/{block-name}.php: block = acf/{block-name}

The builder does respect multi-level meta, it just involved a more complex function call, please see below.

acfmb('[meta type]', '[meta field name]', '[meta field group]', '[extra fields]');

The acfmb function has the follow parameters:

  • meta type: The type of meta (works with all ACF meta types, found here)
  • meta field name: The name of the field (ie. "Hero Headline"). The field name will be automatically slugified for use in ACF.
  • meta field ground: The goup of the field (ie. "Hero"). The group name will be automatically slugified for use in ACF.
  • [optional] extra fields: A JSON string containing the extra options you want to use for the field (ie. '{"placeholder", "Hero Headline Text", "maxlength": "50"}'). You can find more information regarding the options available here.

Simple Example

<?php acfmb('text', 'Hero Headline', 'Hero'); ?>

Complex Example

With the builder, there is never any need to create a key for your fields, all keys are generated on save. You can continually nest repeaters and etc with as many options as you want with this method.

<?php acfmb('repeater', 'Years', 'Calendar', '{"layout": "block", "sub_fields": [{"type": "text", "name": "year", "label": "Year"}, {"type": "repeater", "name": "months", "label": "Months", "layout": "block", "sub_fields": [{"type": "text", "name": "month", "label": "Month"}]}]}'); ?>