GithubHelp home page GithubHelp logo

iamntz / carbon-fields-urlpicker Goto Github PK

View Code? Open in Web Editor NEW
13.0 5.0 18.0 708 KB

Add an URL Picker field to Carbon

JavaScript 64.81% PHP 31.90% SCSS 3.29%
carbon-fields carbon-fields-field wordpress wordpress-plugin

carbon-fields-urlpicker's Introduction

Carbon Field: urlpicker

(this is an extension of Carbon Fields plugin)

You can install it via composer:

composer require iamntz/carbon-fields-urlpicker --prefer-dist

If you install it from the source, you need to make sure that you also run npm install and npm run production in order to have assets compiled.

Return values:

The field will return an associative array with the following values:

url: the actual URL
anchor: the text anchor (might be blank)
blank: wether the link should open in a new window or not

Example

Registering A Field

This goes in your functions.php as with other Carbon Fields fields. The only difference is that the type is urlpicker.

use Carbon_Fields\Container;
use Carbon_Fields\Field;

add_action( 'carbon_fields_register_fields', 'crb_url_picker_test' );

function crb_url_picker_test() {
  Container::make( 'post_meta', 'URL Picker Test' )
    ->add_fields( array(
      Field::make( 'urlpicker', 'crb_my_link', 'URL Picker Test' )
      ->set_help_text( "This is a test of the URL picker." )
    ));
}

Using Field Values

<?php $my_link = carbon_get_the_post_meta( 'crb_my_link' ); ?>
<a href="<?= $my_link[url] ?>"<?= ( $my_link[blank] ? ' target="_blank"' : '') ?>><?= $my_link[anchor] ?></a>

Note that the blank field will return 0 or 1, depending on whether the checkbox is ticked next to "Open link in a new tab".

Found this useful?

You can get hosting (and receive $10 credit!), donate or buy me a gift.

carbon-fields-urlpicker's People

Contributors

drdogbot7 avatar iamntz avatar josecoelhomelo avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

carbon-fields-urlpicker's Issues

Release tag

Will you consider adding a release tag to your current commit?

Possibility to 'set_header_template' for urlpicker fields within complex field?

This isn't an issue so much as a feature request. I've got a list of links using the urlpicker field, and it would be great to have the anchor listed on the tab for each link. I know Carbon Fields supports ->set_header_template('<%- name %>') for example, but I haven't been able to get it to work with urlpicker fields. If this is already possible, but I'm just not doing something right, I'd love to know. Love the urlpicker!

v3.x-dev conflict with Wordpress v5.6.2, Sage theme v9.0.10

Hello,

after installing v3.x-dev version had this error:

Fatal error: Uncaught Error: Call to undefined function add_action() in [...]/vendor/iamntz/carbon-fields-urlpicker/field.php:7 Stack trace: #0 [...]/vendor/composer/autoload_real.php(71): require() #1 [...]/vendor/composer/autoload_real.php(61): composerRequire511ba04db4f2f6968fdac33800344033('c36202a7ae4f6da...', '[...]...') #2 [...]/vendor/autoload.php(7): ComposerAutoloaderInit511ba04db4f2f6968fdac33800344033::getLoader() #3 [...]/vendor/kylekatarnls/update-helper/src/UpdateHelper/UpdateHelper.php(143): include_once('...') #4 phar:///usr/local/bin/composer/src/Composer/Plugin/PluginManager.php(213) : eval()'d code(45): UpdateHelper\UpdateHelper::check(Object(Composer\Script\Event)) #5 [internal function]: UpdateHelper\ComposerPlugin_composer_tmp0->onAut in [...]/vendor/iamntz/carbon-fields-urlpicker/field.php on line 7

to resole i had to make a workaround wrapping add_action in a if(function_exists('add_action')){ ... } in order to make it work.
Can you verify that?

thanks.

Page editor Broken in last two commits

In the page editor I get this error in javascript console:

Uncaught Error: Could not find the component for type "urlpicker".

When I add a 'urlpicker' field to a container then that container won't load. Data that's already in the database loads fine.

Using Carbonfields 2.1.1, WP 4.9.1.

Closing the insert/edit link popup without adding a link adds a blank text field

I'm not sure what all information would be helpful, but I'm happy to provide more if you need it.

WP 4.9.8
Carbon Fields 2.2
URLpicker commit 5150de5
Chrome 68.0.3440.106

If I click the Select Link button, but then click Cancel instead of adding a link, a blank text field appears. Repeating this causes additional text fields to appear. These fields appear right beneath the button. Prior to this current commit, this behavior still happened but it happened at the bottom of the browser window.

Link is not saved (CF 3)

Hi there,

Firstly, thank you for the plugin! I'm trying to use it with the latest version of Carbon Fields but the link is not saved nor selected after clicking on "Add Link".

Kind regards,

Unknown field type "urlpicker".

So I'm trying to use this along with Carbon Fields as a library in a plugin. I'm getting errors that Carbon Fields can find the Field typo of urlpicker. What is odd is that this appears to work in our plugin's local development WordPress instance as well as in a local environment of our test site. However, this error is happening in our Pantheon testing environment and also in PHPUnit tests, and it's a wp_die() failure being thrown by Carbon Fields. I'm unclear on why this is occurring and why Carbon Fields can't find the library in these cases. I've even gone so far as trying to specifically include the field in a use statement in our plugin where the fields setup is happening as well as specifically including the package file as a require statement in our plugin startup and neither of these resolved the issue.

Open Link in New Tab bug, box resets to checked

I'm having an issue with the URLpicker changing "Open link in a new tab" back to checked after unchecking the box. It initially works, save the page and view the page and it opens in a new tab. However, then I come back later and they've reset themselves to open in a new tab.

  • I'm using the URLpicker as a field within a complex fields
  • Wordpress v 6.2.2
  • Carbon Fields ^3.3 installed with Composer
  • Classic Editor

Can't install w/ composer

I think there needs to be a tagged release?

Problem 1
- The requested package iamntz/carbon-fields-urlpicker could not be found in any version, there may be a typo in the package name.

CarbonFields 3.0 Support

Doesn't appear to work in CarbonFields 3.0. I've tried with and without Gutenberg enabled.

The javascript error Field urlpicker isn't registered. is thrown.

[Feature] - Associate the field to page/post ID

Hi there,

First of all, I just want to say thanks for this nice addition to CF.

Anyway, I'm just having a little issue when updating a slug, and I thought it would be a nice feature :
When searching for a page/post, it could be nice to associate the field to the post by its ID.
That way, instead of just getting the URL as a plain text at this specific moment, we could retrieve the post URL by its ID.
So if we update a post slugs, we don't break the link.

I made a little graphic example just to show what I have in mind :

feature

What do you think about that?

Regards,

complex field inside gutenberg reusable block support

Block::make( __( 'About: Year reports' ) )
        ->add_fields( array(
            Field::make( 'complex', 'about_reports', __('Year reports', 'tt' ) )
                ->add_fields( array(
                    Field::make( 'image', 'report_image', 'image' )->set_width( 50 ),
                    ...
                    Field::make( 'urlpicker', 'report_url', 'URL' )->set_help_text( 'help text' ),
                ))
        ))
    ->set_description( __( 'Year reports' ) )
    ->set_render_callback( function ( $fields, $attributes, $inner_blocks ) {});

causes
"This block has encountered an error and cannot be previewed." in admin page

file.php relying on WP functions

This package has a file (file.php) which is being autoloaded.

This causes issues with setups that run composer's autoload before WP's actions are booted. Bedrock's an example, as mentioned here, but in my particular case I'm not even using Bedrock.

I just need to run composer's autoload in wp-config.php in order to use another package there. And I'm getting fatal errors.

I'd sort of solved the problem commenting all the code in file.php and pasting it in my functions.php. My site so far seems to be running well.

Is there any hope that will be changed in any future release?

Thank you

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.