Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
vendor/
162 changes: 107 additions & 55 deletions acf-native-field-type.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,131 @@
<?php
if(!defined('ABSPATH')) exit;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

class acf_field_native extends acf_field {
function __construct() {
$this->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) {?>
<div class="acf-native-field" data-native-field="<?php echo esc_attr($field['native_field']); ?>"<?php echo (!empty($field['metabox_id']) ? ' data-metabox-id="' . esc_attr($field['metabox_id']) . '"' : ''); ?>>
<?php _e('Loading...', 'acf-native-fields'); ?>
</div><?php

function render_field( $field ) {?>
<div class="acf-native-field" data-native-field="<?php echo esc_attr( $field['native_field'] ); ?>"<?php echo ( ! empty( $field['metabox_id'] ) ? ' data-metabox-id="' . esc_attr( $field['metabox_id'] ) . '"' : '' ); ?>>
<?php esc_html_e( 'Loading…', 'acf-native-fields' ); ?>
</div>
<?php
}

function input_admin_enqueue_scripts() {
wp_enqueue_script('acf-native-fields', plugins_url('/js/acf-native-fields.js', __FILE__), array('jquery'), ACF_Native_Fields::instance()->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 );
}
}
}
63 changes: 33 additions & 30 deletions acf-native-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() { ?>
<div class="error"><p><?php _e('ACF Native Fields requires Advanced Custom Fields v5+ to be installed and activated.', 'acf-native-fields'); ?></p></div><?php
<div class="error"><p><?php esc_html_e( 'ACF Native Fields requires Advanced Custom Fields v5+ to be installed and activated.', 'acf-native-fields' ); ?></p></div>
<?php
}

public function include_native_field_type() {
require(dirname(__FILE__) . '/acf-native-field-type.php');
require dirname( __FILE__ ) . '/acf-native-field-type.php';

new acf_field_native();
}
static function &instance() {
if(false === self::$instance) {
self::$instance = new ACF_Native_Fields();

static function &instance() {
if ( false === self::$instance ) {
self::$instance = new ACF_Native_Fields();
}
return self::$instance;
}

return self::$instance;
}
}

new ACF_Native_Fields();
new ACF_Native_Fields();
Loading