GithubHelp home page GithubHelp logo

sumonst21 / acf-filters-and-functions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hube2/acf-filters-and-functions

0.0 2.0 0.0 88 KB

General filters and function for use with Advanced Custom Fields WP Plugin

PHP 100.00%

acf-filters-and-functions's Introduction

ACF Filters & Functions

General filters and function for use with Advanced Custom Fields WP Plugin

For examples of how to create dynamic loading fields based on other field selections, for example dynamically loading a select field based on a selection made in another select field see my other examples here.

Important Note

ACF In constantly changing. It is possible that any of the examples here may stop working with an update to ACF. I do not actively maintian these examples or continuously monitor them to make sure they are working. This repository was created to hold examples of some things that may help other. If you find that something is not working as expected you can open an issue, however, unless I have the free time the chances of me fixing the issue are small. This is why I will gladly take pull request for fixing problems with compatibility.

Contributing

If you would like to contribute to these examples, create a pull request with a new file and update the list below. I would like to avoid changing any of the existing examples in this repo unless the changes are to resolve bugs or to deal with any changes to ACF that cause the original examples to stop functioning.

File/Example List

File names basically tell you what the code does. See comments in individual files for more information.

Since this repo has started to grow, here is a list of what you'll find in the files.

This is a file that gives an example of creating custom location rules to match the posts in a custom post type similar to Post and Page.

This is an example of how to delete images from the media library when they are removed from a gallery field

This is an example of how to extend the ACF admin columns to show additional information. This example adds the menu order and the location rules for each group to the admin.

This is a group of custom functions for returning the labels of fields as well as the labels for choices in choice fields like radio, select and checkbox fields.

This file has a function for applying safely wp_kses_post() to all ACF fields. You can't apply this to repeaters and flexible content fields becuase these fields contain array values and the function deletes these arrays. This filter can also be used as an example of recursively applying any function to ACF fields and arrays in general.

Add image aspect ratio validation to image fields. Also an example of how to add multiple setting fields to a single setting row for an acf field type setting.

This file contains small class that will conditionally load ACF field groups from a theme parent. You add this to your parent theme. It looks at the files in the parent themes acf-json folder and if a field group in this folder does not already exist then it is loaded.

This is useful because it lets you work on the field groups in your development environment without needing to delete those field groups. When an update is applied to your parent theme any changes you've made to the field groups will be automatically applied to child themes.

Just as as side note, I also use this process when developming plugins, with a few modifications. It lets me keep a working copy of my plugin that uses ACF field groups that I edit using ACF. I can then copy the changes from tha theme folder to my plugin and the changes will be applied when the plugin is updated on a site.

This is an example of how to add a custom post type as a sub menu item to an ACF Options Page. The last I checked this cannot be done because ACF uses a priority > 9 for the admin_menu hook. For more information see the comment at the top of the file.

This is another custom location rule example. This custom location rule lets you choose to set a field group to be located on any page that is a descendant of the page selected.

This is another custom location rule example and it is similar to the ancestor location rule except that the field group will only be located on pages that have a particular grand parent, or the second ancestor.

This is another custom location rule example. This one sets a location based on category ancestor. It will actually work with any hierarchical taxonomy.

This file contains and example of how to create a reciprical or two way relationship field using either 1 or 2 relationship or post object fields. This file must be edited to match the field or fields that you wish to convert into a bidirectional relationship. See the comments in the file for more information.

Contributed By: PUncle

Like the acf-reciprocal-relationship.php example above, this function allows two different reltionship fields to reciprocate selections. The difference being that this function usues PHP closures to pass in field keys, avoiding the need to hard-code them inside the function; making this example reusable across multiple reciprocal relationships. This function requires PHP 5.3+.

This is an example of how you can make modification to an ACF Options Page to add additional content into the page that is generated by ACF, for example between the title and the ACF field groups.

ACF shows the menu_title as the choice in location rules. This can be confusing for those of use that create multiple options pages with the same menu title and different page titles. This filter alters the location display to show the page title instead.

Correct number field scrollwheel behavior

This is a simple example of how to add a default image setting to image fields. Note that this is only a bisic example and may require you to save the field group before you can select a default image. I have posted more information here on how to correct this situation

This is another custom location rule example. This rule lets you choose a field group to be used only in the in the admin or on a front end form.

This is another custom location rule example. This rule let's you choose to display a field group only on a specific level of a hierarchical post type. This rule should work with any hierarchical post type.

This is another custom location rule example. This one will let you choose a location based on whether or not the post type is a public post type.

This is like the public post type rule, but for taxonomies

This is an example or how to render additional information in a field. This particular example shows how to display an image when the URL for the image is from another site rather than an image in the media library.

A filter that can be used to check for unique repeater sub field values in any repeater.

acf-filters-and-functions's People

Contributors

bradbaris avatar edflips avatar guilima avatar hube2 avatar jordan-webdev avatar simonrcodrington avatar

Watchers

 avatar  avatar

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.