Sorry, but ACF Post Object Add-on requires either Advanced Custom Fields or Advanced Custom Fields PRO to be installed and active.
acf_version = acf_get_setting( 'version' );
$this->settings = (array) get_option( $this->settings_key );
}
function load_settings_page_options() {
$this->settings_page_options[] = array(
'name' => $this->plugin_name,
'menus' => array(
array(
'is_main' => true,
'type' => 'sub',
'parent' => 'edit.php?post_type=acf-field-group',
'title' => $this->plugin_name,
'capability' => 'manage_options',
'slug' => $this->plugin_key,
'icon' => $this->plugin_icon,
'position' => $this->plugin_menu_position,
),
),
);
}
function load_settings_fields() {
// Sections & Fields
$this->settings_fields = array(
'enable' => array(
'key' => 'enable',
'label' => __( 'Enable', $this->lang_domain ),
'type' => 'checkbox',
'required' => false,
'default' => 'checked',
'args' => array(
'value' => '1',
'validator' => '',
'toggle' => 'append_field',
'toggle_value' => '1',
),
),
'append_field' => array(
'key' => 'append_field',
'label' => __('Field To Append', $this->lang_domain ),
'type' => 'select',
'default' => array(),
'required' => 'conditional',
'args' => array(
'multiple' => false,
'options' => self::get_acf_append_field_options(),
'validator' => '',
'required_conditions' => array(
'operand' => 'and',
'conditions' => array(
array(
'key' => 'enable',
'value' => 1
),
),
),
'hint' => __( 'This field will be displayed after the post title.', $this->lang_domain ),
'toggled_by' => 'enable',
'class' => array(
'select2',
),
),
),
'append_field_format' => array(
'key' => 'append_field_format',
'label' => __( 'Append Field Formatting', $this->lang_domain ),
'type' => 'select',
'default' => '',
'required' => 'conditional',
'args' => array(
'multiple' => false,
'options' => self::get_acf_append_field_format_options(),
'validator' => '',
'required_conditions' => array(
'operand' => 'and',
'conditions' => array(
array(
'key' => 'enable',
'value' => 1
),
),
),
'hint' => __( 'This is how the append field will be formatted.', $this->lang_domain ),
'toggled_by' => 'enable',
'class' => array(
'select2',
),
),
),
);
}
function load_setting_sections() {
// Page settings
self::load_settings_fields();
// Sections & Fields
$this->sections['Settings'] = array(
'name' => __( 'Settings', $this->lang_domain ),
'description' => __( 'Settings for ACF Post Object Field Type plugin. This plugin is specfically for appending post data to each option for the "post object" field type. When enabled, the selected fields will be suffixed to each available option in "post object" selects.', $this->lang_domain ),
'id' => 'settings',
'fields' => $this->settings_fields,
);
}
function add_settings_pages_to_menus() {
// Page settings
self::load_settings_page_options();
foreach ($this->settings_page_options as $page) {
if ( is_array($page['menus']) ) {
foreach ($page['menus'] as $index => $page_menu) {
if ( $page_menu['type'] == 'sub' && $page_menu['parent'] !== false ) {
// parent_slug: The slug name for the parent menu, or the file name of a standard WordPress admin file
// page_title: Text that will go into the HTML page title for the page when the submenu is active.
// menu_title: The text to be displayed in the title tags of the page when the menu is selected.
// capability: The capability required for this menu to be displayed to the user.
// menu_slug: For existing WordPress menus, the PHP file that handles the display of the menu page content.
// function: The function that displays the page content for the menu page.
$this->settings_pages[] = add_submenu_page(
$page_menu['parent'],
__($page['name'], $this->lang_domain),
__($page_menu['title'], $this->lang_domain),
$page_menu['capability'],
$page_menu['slug'],
array( $this, 'options_page' ),
$page_menu['icon']
);
} else {
// page_title: The text to be displayed in the title tags of the page when the menu is selected.
// menu_title: The on-screen name text for the menu.
// capability : The capability required for this menu to be displayed to the user.
// menu_slug: The slug name to refer to this menu by (should be unique for this menu).
// function: The function that displays the page content for the menu page.
// icon_url: The url to the icon to be used for this menu. (optional).
// position: The position in the menu order this menu should appear. By default, is bottom. (optional)
$this->settings_pages[] = add_menu_page(
__($page['name'], $this->lang_domain),
__($page_menu['title'], $this->lang_domain),
$page_menu['capability'],
$page_menu['slug'],
array( $this, 'options_page' ),
$page_menu['icon'],
$page_menu['position']
);
}
}
}
}
}
function settings_init() {
// Sections & Fields
self::load_setting_sections();
$sections = apply_filters( 'de/acf-post-object-addon/alter_settings_sections', $this->sections) ;
register_setting( $this->settings_key, $this->settings_key );
foreach ($sections as $section) {
// Section
// id: String for use in the 'id' attribute of tags.
// title: Title of the section.
// callback: Function that fills the section with the desired content.
// page: The menu page on which to display this section.
$section_id = $section['id'];
$section_callback = $section['name'].'_section_callback';
add_settings_section(
$section_id,
__($section['name'], $this->lang_domain),
array( $this, $section_callback ),
$this->settings_key
);
if ($section['fields']) {
foreach ($section['fields'] as $field_key => $field_data) {
// id: String for use in the 'id' attribute of tags.
// title: Title of the field.
// callback: Function that fills the field with the desired inputs as part of the larger form. Passed $args array.
// page: The menu page on which to display this field.
// section: The section of the settings page in which to show the box (default or section added above)
// args: Additional arguments that are passed to the $callback function
$field_id = $field_key;
// Default field args
$field_data['label_for'] = $field_id;
add_settings_field(
$field_id,
__($field_data['label'], $this->lang_domain),
array( $this, 'settings_field_render' ),
$this->settings_key,
$section_id,
$field_data
);
}
}
}
}
function plugin_action_links( $links ) {
$links[] = '' . __( 'Settings', $this->lang_domain ) . '';
return $links;
}
function add_action_plugin( $actions, $plugin_file ) {
static $plugin;
if (!isset($plugin)) {
$plugin = plugin_basename(__FILE__);
}
if ($plugin == $plugin_file) {
$settings = array(
'settings' => '' . __( 'Settings', $this->lang_domain ) . ''
);
$actions = array_merge($settings, $actions);
$actions = array_merge($site_link, $actions);
}
return $actions;
}
function admin_enqueue($hook) {
$screen = get_current_screen();
if ( in_array($screen->id, $this->settings_pages) == false ) return;
wp_enqueue_style( 'de-acfpoftao-select2-style', plugins_url('de-acf-post-object-addon/assets/dist/vendor/select2/dist/css/select2.min.css'));
wp_enqueue_style( 'de-acfpoftao-checkbox-style', plugins_url('de-acf-post-object-addon/assets/dist/vendor/iCheck/skins/flat/grey.css'));
wp_enqueue_style( 'de-acfpoftao-settings-style', plugins_url('de-acf-post-object-addon/assets/dist/css/style.css'));
wp_register_script( 'de-acfpoftao-select2-js', plugins_url('de-acf-post-object-addon/assets/dist/vendor/select2/dist/js/select2.min.js'), array('jquery'), NULL );
wp_register_script( 'de-acfpoftao-checkbox-js', plugins_url('de-acf-post-object-addon/assets/dist/vendor/iCheck/icheck.min.js'), array('jquery'), NULL );
wp_register_script( 'de-acfpoftao-settings-js', plugins_url('de-acf-post-object-addon/assets/dist/js/settings.js'), array('jquery', 'de-acfpoftao-select2-js'), NULL );
wp_enqueue_script( 'de-acfpoftao-select2-js' );
wp_enqueue_script( 'de-acfpoftao-checkbox-js' );
wp_enqueue_script( 'de-acfpoftao-settings-js' );
}
function settings_field_render($field_data) {
$html = '';
$classes = array();
if (is_array($field_data) && !empty($field_data)) {
$field_key = $field_data['key'];
$field_name = $this->settings_key.'['.$field_key.']';
$field_id = $this->plugin_key.'-'.$field_data['key'];
$field_value = isset($this->settings[$field_key]) ? $this->settings[$field_key] : '';
$field_params = $field_data['args'];
$field_attrs = '';
if (is_array($field_params) && !empty($field_params)) {
if (isset($field_params['attrs']) && is_array($field_params['attrs']) && !empty($field_params['attrs'])) {
foreach ($field_params['attrs'] as $attr_key => $attr_val) {
$field_attrs .= ' '.$attr_key.'="'.esc_attr($attr_val).'"';
}
}
if (isset($field_params['toggle']) && !empty($field_params['toggle'])) {
$field_attrs .= ' data-toggle="'.$this->plugin_key.'-'.$field_params['toggle'].'" data-toggle-value="'.$field_params['toggle_value'].'"';
}
if (isset($field_params['toggled_by']) && !empty($field_params['toggled_by'])) {
$field_attrs .= ' data-toggled-by="'.$this->plugin_key.'-'.$field_params['toggled_by'].'"';
$toggler_value = $this->settings[$field_params['toggled_by']];
if ($toggler_value != $this->sections['Settings']['fields'][$field_params['toggled_by']]['args']['toggle_value']) {
$classes[] = ' conditional-hidden';
}
}
if (isset($field_params['class']) && !empty($field_params['class'])) {
foreach ($field_params['class'] as $class) {
$classes[] = $class;
}
}
if (!empty($classes)) {
$field_attrs .= ' class="'.implode(" ", $classes).'"';
}
}
switch ($field_data['type']) {
case 'text':
case 'hidden':
case 'password':
case 'number':
case 'email':
case 'tel':
case 'url':
case 'search':
case 'range':
case 'date':
case 'datetime':
case 'datetime-local':
case 'month':
case 'week':
case 'time':
$html .= '';
break;
case 'checkbox':
$checked = $field_value == $field_params['value'];
$input = '';
if (isset($field_params['wrap_label']) && false !== $field_params['wrap_label']) {
$input = ' ';
}
$html .= $input;
break;
case 'checkbox_multi':
if (is_array($field_params) && isset($field_params['options']) && !empty($field_params['options'])) {
foreach ($field_params['options'] as $value => $label) {
$checked = false;
$checked = is_array($field_value) && in_array($value, $field_value);
$input = '';
if ($field_params['wrap_label']) {
$input = ' ';
}
$html .= $input;
}
}
break;
case 'radio':
if (is_array($field_params) && isset($field_params['options']) && !empty($field_params['options'])) {
foreach ($field_params['options'] as $value => $label) {
$checked = false;
$checked = $value == $field_value;
$input = '';
if ($field_params['wrap_label']) {
$input = ' ';
}
$html .= $input;
}
}
break;
case 'select':
$is_multiple = false;
$select_name = esc_attr($field_name);
if (is_array($field_params) && isset($field_params['multiple']) && $field_params['multiple'] !== false) {
$is_multiple = true;
$select_name .= '[]';
}
$html .= '