From bf7c60a367c7ab447f7ade2ca7cbdf0b5ae9c0f4 Mon Sep 17 00:00:00 2001 From: Nestor Vera Date: Tue, 19 Feb 2019 20:41:55 +0100 Subject: [PATCH 1/3] Update .gitignore to ignore Composer's vendor directory --- .gitignore | 1 + composer.lock | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index 485dee6..f2ecd3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +vendor/ diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..77ad99d --- /dev/null +++ b/composer.lock @@ -0,0 +1,138 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "b17a2a17da67c2c2c397c6de7e91ec23", + "packages": [ + { + "name": "composer/installers", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/composer/installers.git", + "reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/installers/zipball/cfcca6b1b60bc4974324efb5783c13dca6932b5b", + "reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0" + }, + "replace": { + "roundcube/plugin-installer": "*", + "shama/baton": "*" + }, + "require-dev": { + "composer/composer": "1.0.*@dev", + "phpunit/phpunit": "^4.8.36" + }, + "type": "composer-plugin", + "extra": { + "class": "Composer\\Installers\\Plugin", + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Installers\\": "src/Composer/Installers" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kyle Robinson Young", + "email": "kyle@dontkry.com", + "homepage": "https://github.com/shama" + } + ], + "description": "A multi-framework Composer library installer", + "homepage": "https://composer.github.io/installers/", + "keywords": [ + "Craft", + "Dolibarr", + "Eliasis", + "Hurad", + "ImageCMS", + "Kanboard", + "Lan Management System", + "MODX Evo", + "Mautic", + "Maya", + "OXID", + "Plentymarkets", + "Porto", + "RadPHP", + "SMF", + "Thelia", + "WolfCMS", + "agl", + "aimeos", + "annotatecms", + "attogram", + "bitrix", + "cakephp", + "chef", + "cockpit", + "codeigniter", + "concrete5", + "croogo", + "dokuwiki", + "drupal", + "eZ Platform", + "elgg", + "expressionengine", + "fuelphp", + "grav", + "installer", + "itop", + "joomla", + "kohana", + "laravel", + "lavalite", + "lithium", + "magento", + "majima", + "mako", + "mediawiki", + "modulework", + "modx", + "moodle", + "osclass", + "phpbb", + "piwik", + "ppi", + "puppet", + "pxcms", + "reindex", + "roundcube", + "shopware", + "silverstripe", + "sydes", + "symfony", + "typo3", + "wordpress", + "yawik", + "zend", + "zikula" + ], + "time": "2018-08-27T06:10:37+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} From cbf011c85874a5c2a35ab50c7d45eb6b4afd6463 Mon Sep 17 00:00:00 2001 From: Nestor Vera Date: Tue, 19 Feb 2019 20:47:25 +0100 Subject: [PATCH 2/3] Fix minor linting issues --- acf-native-field-type.php | 122 ++++++++++++++++++-------------- acf-native-fields.php | 63 +++++++++-------- css/acf-native-fields-admin.css | 7 +- css/acf-native-fields.css | 28 ++++---- 4 files changed, 119 insertions(+), 101 deletions(-) diff --git a/acf-native-field-type.php b/acf-native-field-type.php index 16f759d..5857085 100644 --- a/acf-native-field-type.php +++ b/acf-native-field-type.php @@ -1,79 +1,93 @@ name = 'native_field'; - $this->label = __('Native Field', 'acf-native-fields'); + $this->label = __( 'Native Field', 'acf-native-fields' ); $this->defaults = array( - 'value' => false, // prevents acf_render_fields() from attempting to load value + 'value' => false, // prevents acf_render_fields() from attempting to load value ); - + $this->category = 'layout'; - + $this->l10n = array( - 'not_implemented' => __('Native Field not implemented yet.', 'acf-native-fields'), + 'not_implemented' => __( 'Native Field not implemented yet.', 'acf-native-fields' ), ); - parent::__construct(); + parent::__construct(); } - - function render_field_settings($field) { - acf_render_field_setting($field, array( - 'label' => __('Native Field', 'acf-native-fields'), - 'instructions' => __('The native WordPress field to move into this placeholder.', 'acf-native-fields'), - 'type' => 'select', - 'name' => 'native_field', - 'required' => 1, - // TODO: Implement backend and frontend functionality for custom native fields (hooks) - 'choices' => array( - 'content' => __('Content Editor', 'acf-native-fields'), - 'excerpt' => __('Excerpt', 'acf-native-fields'), - 'featured_image' => __('Featured Image', 'acf-native-fields'), - 'yoast_seo' => __('SEO (Yoast or SEO framework)', 'acf-native-fields'), - 'publish_box' => __('Publish Box', 'acf-native-fields'), - 'permalink' => __('Permalink', 'acf-native-fields'), - 'discussion' => __('Discussion', 'acf-native-fields'), - 'trackbacks' => __('Trackbacks', 'acf-native-fields'), - 'format' => __('Format', 'acf-native-fields'), - 'page_attributes' => __('Page Attributes', 'acf-native-fields'), - 'custom' => __('Custom', 'acf-native-fields'), - ), - )); - acf_render_field_setting($field, array( - 'label' => __('Custom Meta Box ID', 'acf-native-fields'), - 'instructions' => __('The ID of the custom metabox to target.', 'acf-native-fields'), - 'type' => 'text', - 'name' => 'metabox_id', - 'prefix' => '#', - 'conditional_logic' => array( - array( + function render_field_settings( $field ) { + acf_render_field_setting( + $field, + array( + 'label' => __( 'Native Field', 'acf-native-fields' ), + 'instructions' => __( 'The native WordPress field to move into this placeholder.', 'acf-native-fields' ), + 'type' => 'select', + 'name' => 'native_field', + 'required' => 1, + // TODO: Implement backend and frontend functionality for custom native fields (hooks) + 'choices' => array( + 'content' => __( 'Content Editor', 'acf-native-fields' ), + 'excerpt' => __( 'Excerpt', 'acf-native-fields' ), + 'featured_image' => __( 'Featured Image', 'acf-native-fields' ), + 'yoast_seo' => __( 'SEO (Yoast or SEO framework)', 'acf-native-fields' ), + 'publish_box' => __( 'Publish Box', 'acf-native-fields' ), + 'permalink' => __( 'Permalink', 'acf-native-fields' ), + 'discussion' => __( 'Discussion', 'acf-native-fields' ), + 'trackbacks' => __( 'Trackbacks', 'acf-native-fields' ), + 'format' => __( 'Format', 'acf-native-fields' ), + 'page_attributes' => __( 'Page Attributes', 'acf-native-fields' ), + 'custom' => __( 'Custom', 'acf-native-fields' ), + ), + ) + ); + + acf_render_field_setting( + $field, + array( + 'label' => __( 'Custom Meta Box ID', 'acf-native-fields' ), + 'instructions' => __( 'The ID of the custom metabox to target.', 'acf-native-fields' ), + 'type' => 'text', + 'name' => 'metabox_id', + 'prefix' => '#', + 'conditional_logic' => array( array( - 'field' => 'native_field', - 'operator' => '==', - 'value' => 'custom', + array( + 'field' => 'native_field', + 'operator' => '==', + 'value' => 'custom', + ), ), ), - ), - )); + ) + ); } - - function render_field($field) {?> -
> - -
+
> + +
+ plugin_data['Version']); - wp_enqueue_style('acf-native-fields', plugins_url('/css/acf-native-fields.css', __FILE__), array(), ACF_Native_Fields::instance()->plugin_data['Version']); + $plugin_version = ACF_Native_Fields::instance()->plugin_data['Version']; + + wp_enqueue_script( 'acf-native-fields', plugins_url( '/js/acf-native-fields.js', __FILE__ ), array( 'jquery' ), $plugin_version, false ); + wp_enqueue_style( 'acf-native-fields', plugins_url( '/css/acf-native-fields.css', __FILE__ ), array(), $plugin_version ); } function field_group_admin_enqueue_scripts() { - wp_enqueue_script('acf-native-fields-admin', plugins_url('/js/acf-native-fields-admin.js', __FILE__), array('jquery'), ACF_Native_Fields::instance()->plugin_data['Version']); - wp_enqueue_style('acf-native-fields-admin', plugins_url('/css/acf-native-fields-admin.css', __FILE__), array(), ACF_Native_Fields::instance()->plugin_data['Version']); + $plugin_version = ACF_Native_Fields::instance()->plugin_data['Version']; + + wp_enqueue_script( 'acf-native-fields-admin', plugins_url( '/js/acf-native-fields-admin.js', __FILE__ ), array( 'jquery' ), $plugin_version, false ); + wp_enqueue_style( 'acf-native-fields-admin', plugins_url( '/css/acf-native-fields-admin.css', __FILE__ ), array(), $plugin_version ); } -} \ No newline at end of file +} diff --git a/acf-native-fields.php b/acf-native-fields.php index 0fed45a..daff4fb 100644 --- a/acf-native-fields.php +++ b/acf-native-fields.php @@ -10,54 +10,57 @@ License URI: http://www.gnu.org/licenses/gpl-3.0.en.html */ -if(!defined('ABSPATH')) exit; +if ( ! defined( 'ABSPATH' ) ) { + exit; +} class ACF_Native_Fields { - static $instance = false; - + static $instance = false; + public $plugin_data = null; - + function __construct() { // Init plugin (check requirements etc) - add_action('admin_init', array($this, 'admin_init')); - + add_action( 'admin_init', array( $this, 'admin_init' ) ); + // Add native field type to ACF - add_action('acf/include_field_types', array($this, 'include_native_field_type')); + add_action( 'acf/include_field_types', array( $this, 'include_native_field_type' ) ); } - + public function admin_init() { - load_plugin_textdomain('acf-native-fields', false, dirname(plugin_basename(__FILE__)) . '/lang/'); - - $this->plugin_data = get_plugin_data(dirname(__FILE__)); - + load_plugin_textdomain( 'acf-native-fields', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); + + $this->plugin_data = get_plugin_data( dirname( __FILE__ ) ); + // Require ACF - if (current_user_can('activate_plugins') && !is_plugin_active('advanced-custom-fields/acf.php') && !is_plugin_active('advanced-custom-fields-pro/acf.php')) { - add_action('admin_notices', array($this, 'require_acf')); - deactivate_plugins(plugin_basename( __FILE__ )); + if ( current_user_can( 'activate_plugins' ) && ! is_plugin_active( 'advanced-custom-fields/acf.php' ) && ! is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) { + add_action( 'admin_notices', array( $this, 'require_acf' ) ); + deactivate_plugins( plugin_basename( __FILE__ ) ); - if(isset($_GET['activate'])) { - unset($_GET['activate']); + if ( isset( $_GET['activate'] ) ) { + unset( $_GET['activate'] ); } } } - + public function require_acf() { ?> -

+ Date: Fri, 22 Mar 2019 13:09:11 +0100 Subject: [PATCH 3/3] Add support for the new block editor aka Gutenberg --- js/acf-native-fields.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/js/acf-native-fields.js b/js/acf-native-fields.js index 1dfcfe4..9e4fc52 100644 --- a/js/acf-native-fields.js +++ b/js/acf-native-fields.js @@ -7,9 +7,11 @@ * Initialize the ACF Native Fields plugin */ init: function() { - ACF_Native_Fields.editor_container = $('#post-body'); - ACF_Native_Fields.native_fields = ACF_Native_Fields.editor_container.find('.acf-native-field'); - + var isGutenberg = document.body.classList.contains( 'block-editor-page' ); + + ACF_Native_Fields.editor_container = isGutenberg ? $('#post-body, #metaboxes') : $('#post-body'); + ACF_Native_Fields.native_fields = isGutenberg ? $('.acf-native-field') : ACF_Native_Fields.editor_container.find('.acf-native-field'); + // Move all native fields into their placeholders ACF_Native_Fields.moveNativeFields(); }, @@ -155,4 +157,4 @@ }; $(document).ready(ACF_Native_Fields.init); -})(jQuery); \ No newline at end of file +})(jQuery);