diff --git a/.gitignore b/.gitignore index 485dee6..f2ecd3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +vendor/ diff --git a/acf-native-field-type.php b/acf-native-field-type.php index 16f759d..43e8b7f 100644 --- a/acf-native-field-type.php +++ b/acf-native-field-type.php @@ -1,79 +1,131 @@ 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 ) { + $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); + $is_active = function ( $plugin ) use ( $active_plugins ) { + return in_array( $plugin, $active_plugins, true ); + }; + + 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_filter( + array( + 'Core' => array( + 'content' => __( 'Content Editor', 'acf-native-fields' ), + 'excerpt' => __( 'Excerpt', 'acf-native-fields' ), + 'publish_box' => __( 'Publish Box', 'acf-native-fields' ), + 'page_attributes' => __( 'Page Attributes', 'acf-native-fields' ), + 'featured_image' => __( 'Featured Image', 'acf-native-fields' ), + + 'permalink' => __( 'Permalink', 'acf-native-fields' ), + 'author' => __( 'Author', 'acf-native-fields' ), + + 'categories' => __( 'Categories', 'acf-native-fields' ), + 'tags' => __( 'Tags', 'acf-native-fields' ), + 'format' => __( 'Format', 'acf-native-fields' ), + + 'revisions' => __( 'Revisions', 'acf-native-fields' ), + 'comments' => __( 'Comments', 'acf-native-fields' ), + 'discussion' => __( 'Discussion', 'acf-native-fields' ), + 'trackbacks' => __( 'Trackbacks', 'acf-native-fields' ), + ), + + 'WooCommerce' => $is_active( 'woocommerce/woocommerce.php' ) ? array( + 'all' => __( 'All', 'acf-native-fields' ), + 'product_categories' => __( 'Product Categories', 'acf-native-fields' ), + 'product_tags' => __( 'Product Tags', 'acf-native-fields' ), + 'product_image' => __( 'Product Image', 'acf-native-fields' ), + 'product_gallery' => __( 'Product Gallery', 'acf-native-fields' ), + 'product_data' => __( 'Product Data', 'acf-native-fields' ), + 'product_short_description' => __( 'Product Short Description', 'acf-native-fields' ), + 'reviews' => __( 'Reviews', 'acf-native-fields' ), + ) : false, + + 'Plugins' => array_filter( + array( + 'yoast_seo' => $is_active( 'wordpress-seo/wp-seo.php' ) ? __( 'Yoast SEO', 'acf-native-fields' ) : false, + 'seo_framework' => $is_active( 'autodescription/autodescription.php' ) ? __( 'SEO Framework', 'acf-native-fields' ) : false, + 'classic_editor' => $is_active( 'classic-editor/classic-editor.php' ) ? __( 'Classic Editor (Editor Switcher)', 'acf-native-fields' ) : false, + 'laygridder' => $is_active( 'laygridder/laygridder.php' ) ? __( 'LayGridder', 'acf-native-fields' ) : false, + ) + ), + + 'Other' => array( + 'custom' => __( 'Custom', 'acf-native-fields' ), + ), + ) + ), + ) + ); + + acf_render_field_setting( + $field, + array( + 'label' => __( 'Custom Meta Box', 'acf-native-fields' ), + 'instructions' => __( 'A valid CSS selector to target your desired meta box.', 'acf-native-fields' ), + 'type' => 'text', + 'name' => 'metabox_id', + '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() { ?> -

+