Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from RostiMelk/development
Browse files Browse the repository at this point in the history
Version 2.3.0
  • Loading branch information
RostiMelk authored Mar 31, 2020
2 parents 3df60b8 + 0a4b1f4 commit 159cd8d
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 120 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This is a Chrome extension for Advanced Custom Fields to help with developing si
### Features

- Copy code for field with the matching selected setting and field name ([video demo here](https://youtu.be/_gyqUem8jKo))
- Quickly copy an ACF field name
- Quickly open documentation for field
- Quickly copy an ACF field name by just clicking the field name
- Quickly open documentation for field by just clicking the field type

### Installation

Expand All @@ -26,4 +26,4 @@ You can also [find the extension on the Chrome web store](https://chrome.google.

---

_View more of my work on [rosti.no](https://rosti.no)_
_View more of my work on [rosti.no](https://rosti.no)_
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "ACF Tools",
"version": "2.2.3",
"version": "2.3.0",
"description": "This is a Chrome extension for Advanced Custom Fields to help with developing sites faster.",
"icons": {
"16": "icons/icon16.png",
Expand Down
55 changes: 32 additions & 23 deletions scripts/fields.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function acf_field(fieldName, typeOfField, returnType, seniority, place) {
function acf_field(appendCode, fieldName, typeOfField, returnType, seniority, place, subFields) {
switch (typeOfField) {
// Basic
case "text":
Expand Down Expand Up @@ -49,13 +49,13 @@ function acf_field(fieldName, typeOfField, returnType, seniority, place) {
case "file":
switch (returnType) {
case "array":
var fieldCode = "<?php\n" + "$file = get_field('" + fieldName + "');\n" + "if ($file): ?>;\n" + "\t<a href=\"<? php echo $file['url']; ?>\"><?php echo $file['filename']; ?></a>\n" + "<?php endif; ?>";
var fieldCode = "<?php\n" + "$file = get_field('" + fieldName + "');\n" + "if ($file): ?>;\n" + "\t<a href=\"<?php echo $file['url']; ?>\"><?php echo $file['filename']; ?></a>\n" + "<?php endif; ?>";
break;
case "url":
var fieldCode = "<?php if( get_field('file') ): ?>\n" + "\t<a href=\"<?php the_field('" + fieldName + "'); ?>'>Download File</a>\n" + "<?php endif; ?>\n";
break;
case "id":
var fieldCode = "<?php\n" + "$file = get_field('" + fieldName + "');\n" + "if( $file ):\n" + "\t$url = wp_get_attachment_url( $file ); ?>\n" + "\t<a href=\"<? php echo esc_html($url); ?>\">Download File</a>\n" + "<?php endif; ?>";
var fieldCode = "<?php\n" + "$file = get_field('" + fieldName + "');\n" + "if( $file ):\n" + "\t$url = wp_get_attachment_url( $file ); ?>\n" + "\t<a href=\"<?php echo esc_html($url); ?>\">Download File</a>\n" + "<?php endif; ?>";
break;
default:
fieldError();
Expand All @@ -73,7 +73,7 @@ function acf_field(fieldName, typeOfField, returnType, seniority, place) {
case "gallery":
switch (returnType) {
case "array":
var fieldCode = "<?php\n" + "$images = get_field('" + fieldName + "');\n" + "if( $images ): ?>\n" + "\t<?php foreach( $images as $image ): ?>\n" + "\t\t<a href=\"<? php echo esc_url($image['url']); ?>\">\n" + "\t\t\t<img src=\"<? php echo esc_url($image['sizes']['thumbnail']); ?>\" alt=\"<? php echo esc_attr($image['alt']); ?>\"/>\n" + "\t\t</a>\n" + "\t<?php endforeach; ?>\n" + "<?php endif; ?>";
var fieldCode = "<?php\n" + "$images = get_field('" + fieldName + "');\n" + "if( $images ): ?>\n" + "\t<?php foreach( $images as $image ): ?>\n" + "\t\t<a href=\"<?php echo esc_url($image['url']); ?>\">\n" + "\t\t\t<img src=\"<?php echo esc_url($image['sizes']['thumbnail']); ?>\" alt=\"<?php echo esc_attr($image['alt']); ?>\"/>\n" + "\t\t</a>\n" + "\t<?php endforeach; ?>\n" + "<?php endif; ?>";
break;
case "url":
var fieldCode = "<?php the_field('" + fieldName + "'); ?>";
Expand Down Expand Up @@ -126,7 +126,7 @@ function acf_field(fieldName, typeOfField, returnType, seniority, place) {
break;

case "page_link":
var fieldCode = "<?php\n" + "$urls = get_field('" + fieldName + "');\n" + "if( $urls ): ?>\n" + "\t<?php foreach( $urls as $url ): ?>\n" + "\t\t<a href=\"<? php echo esc_url($url); ?>\" ><?php echo esc_html( $url ); ?></a>\n" + "\t<?php endforeach; ?>\n" + "<?php endif; ?>";
var fieldCode = "<?php\n" + "$urls = get_field('" + fieldName + "');\n" + "if( $urls ): ?>\n" + "\t<?php foreach( $urls as $url ): ?>\n" + "\t\t<a href=\"<?php echo esc_url($url); ?>\" ><?php echo esc_html( $url ); ?></a>\n" + "\t<?php endforeach; ?>\n" + "<?php endif; ?>";
break;

case "relationship":
Expand Down Expand Up @@ -188,11 +188,11 @@ function acf_field(fieldName, typeOfField, returnType, seniority, place) {

// Layout
case "group":
var fieldCode = "<?php if( have_rows('" + fieldName + "') ): ?>\n" + "\t<?php while( have_rows('" + fieldName + "') ): the_row(); ?>\n" + "\t\t\n" + "\t<?php endwhile; ?>\n" + "<?php endif; ?>";
var fieldCode = "<?php if( have_rows('" + fieldName + "') ): ?>\n" + "\t<?php while( have_rows('" + fieldName + "') ): the_row(); ?>\n" + "\t\t" + subFields + "\n" + "\t<?php endwhile; ?>\n" + "<?php endif; ?>";
break;

case "repeater":
var fieldCode = "<?php if( have_rows('" + fieldName + "') ): ?>\n" + "\t<?php while( have_rows('" + fieldName + "') ): the_row(); ?>\n" + "\t\t\n" + "\t<?php endwhile; ?>\n" + "<?php endif; ?>";
var fieldCode = "<?php if( have_rows('" + fieldName + "') ): ?>\n" + "\t<?php while( have_rows('" + fieldName + "') ): the_row(); ?>\n" + "\t\t" + subFields + "\n" + "\t<?php endwhile; ?>\n" + "<?php endif; ?>";
break;

case "flexible_content":
Expand All @@ -204,23 +204,32 @@ function acf_field(fieldName, typeOfField, returnType, seniority, place) {
break;

default:
fieldError()
fieldError();
}

// Change to sub field if sub field
if (seniority == 'sub') {
fieldCode = fieldCode.replace('get_field', 'get_sub_field');
fieldCode = fieldCode.replace('the_field', 'the_sub_field');
}
// Add options if options page
if (place == 'options_page') {
var fieldNameRe = new RegExp("'" + fieldName + "'", 'g');
fieldCode = fieldCode.replace(fieldNameRe, "'" + fieldName + "', 'options'");
}

// Adjust tabs for appended sub fields
if(appendCode) {
fieldCode = fieldCode.replace(/\n/g, '\n\t\t')
}

// Copy to clipboard
sessionStorage.removeItem('fieldcode');
sessionStorage.setItem('fieldcode', '\n\t\t' + fieldCode + '\n');



if (typeof typeOfField != "undefined") {
// Change to sub field if sub field
if (seniority == 'sub') {
fieldCode = fieldCode.replace('get_field', 'get_sub_field');
fieldCode = fieldCode.replace('the_field', 'the_sub_field');
}
// Add options if options page
if (place == 'options_page') {
var fieldNameRe = new RegExp("'" + fieldName + "'", 'g');
fieldCode = fieldCode.replace(fieldNameRe, "'" + fieldName + "', 'options'");
}

// Copy to clipboard
copyCodeToClipboard(fieldCode);
if(!appendCode) {
copyCodeToClipboard(fieldCode, subFields);
}
}
}
Loading

0 comments on commit 159cd8d

Please sign in to comment.