Support

Account

Home Forums General Issues Need Help for integrating ACF in custom plugin

Solved

Need Help for integrating ACF in custom plugin

  • Hello,

    since round about 12 months we are developing a plugin which uses ACF for generating the needed fields. All is working actually but now i decided to make the plugin “more object-orientated”…. The result is now that “adding normal taxonomy terms by hand” is not normal…the term is added but the page (the AJAX part) blocks and stays there. Only by reloading the page the term is present.

    I tried to find the error and its based on the ACF integration. Not ACF itself only my way of integration.

    I found a sample to integrate ACF within a helper class and do the complete integration in this class. I think that there is my error.

    In the documentation are only a few lines for that but i need a little bit more…..

    In my plugin (by using the object-orientated boilerplate way with the possibility to access all classes from every class) i added my helper class and there i did the init of ACF but i think that there is the error.

    Where i could find a sample for that?

    What i want?

    – in the final plugin ACF should be integrated
    – the complete ACF definitions/fields/filters and so on should be reside in a class
    – the class is initiated by the normal init procedure in the main plugin file (class-plugin-name.php) and there exist the part

    private function define_admin_hooks() {
    $this->acf		= new Picture_Frame_ACF( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    }
  • This is my main plugin class:

    <?php
    /**
     * The file that defines the core plugin class
     *
     * A class definition that includes attributes and functions used across both the
     * public-facing side of the site and the admin area.
     *
     * @link       https://example.com
     * @since      1.0.0
     *
     * @package    Plugin_Name
     * @subpackage Plugin_Name/includes
     */
    
    /**
     * The core plugin class.
     *
     * This is used to define internationalization, admin-specific hooks, and
     * public-facing site hooks.
     *
     * Also maintains the unique identifier of this plugin as well as the current
     * version of the plugin.
     *
     * @since      1.0.0
     * @package    Plugin_Name
     * @subpackage Plugin_Name/includes
     * @author     Your Name <[email protected]>
     */
    class Picture_Frame {
    
    	/**
    	 * Store plugin main class to allow public access.
    	 *
    	 * @since    1.0.0
    	 * @var object      The main class.
    	 */
    	public $main;
    	
    	/**
    	 * Store plugin admin class to allow public access.
    	 *
    	 * @since    20180622
    	 * @var object      The admin class.
    	 */
    	public $admin;
    	
    	/**
    	 * Store plugin public class to allow public access.
    	 *
    	 * @since    20180622
    	 * @var object      The admin class.
    	 */
    	public $shared;
    
    	/**
    	 * Store plugin public class to allow public access.
    	 *
    	 * @since    20180622
    	 * @var object      The admin class.
    	 */
    	public $public;
    	
    	/**
    	 * The loader that's responsible for maintaining and registering all hooks that power
    	 * the plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   protected
    	 * @var      Plugin_Name_Loader    $loader    Maintains and registers all hooks for the plugin.
    	 */
    	protected $loader;
    
    	/**
    	 * The unique identifier of this plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   protected
    	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
    	 */
    	protected $plugin_name;
    
    	/**
    	 * The unique prefix of this plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   protected
    	 * @var      string    $plugin_prefix    The string used to uniquely prefix technical functions of this plugin.
    	 */
    	protected $plugin_prefix;
    
    	/**
    	 * The current version of the plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   protected
    	 * @var      string    $version    The current version of the plugin.
    	 */
    	protected $version;
    
    	/**
    	 * Define the core functionality of the plugin.
    	 *
    	 * Set the plugin name and the plugin version that can be used throughout the plugin.
    	 * Load the dependencies, define the locale, and set the hooks for the admin area and
    	 * the public-facing side of the site.
    	 *
    	 * @since    1.0.0
    	 */
    	public function __construct() {
    
    		if ( defined( 'PICTURE_FRAME_VERSION' ) ) {
    
    			$this->version = PICTURE_FRAME_VERSION;
    
    		} else {
    
    			$this->version = '1.0.0';
    
    		}
    		
    		$this->main = $this;
    
    		$this->plugin_name = 'picture-frame';
    		$this->plugin_prefix = 'pfx_';
    
    		$this->load_dependencies();
    		$this->set_locale();
    		$this->define_admin_hooks();
    		$this->define_public_hooks();
    
    	}
    
    	/**
    	 * Load the required dependencies for this plugin.
    	 *
    	 * Include the following files that make up the plugin:
    	 *
    	 * - Plugin_Name_Loader. Orchestrates the hooks of the plugin.
    	 * - Plugin_Name_i18n. Defines internationalization functionality.
    	 * - Plugin_Name_Admin. Defines all hooks for the admin area.
    	 * - Plugin_Name_Public. Defines all hooks for the public side of the site.
    	 *
    	 * Create an instance of the loader which will be used to register the hooks
    	 * with WordPress.
    	 *
    	 * @since    1.0.0
    	 * @access   private
    	 */
    	private function load_dependencies() {
    		
    		/**
    		 * The class responsible for defining all actions that 
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-acf.php';
    
    		/**
    		 * The class responsible for orchestrating the actions and filters of the
    		 * core plugin.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-loader.php';
    
    		/**
    		 * The class responsible for defining internationalization functionality
    		 * of the plugin.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-i18n.php';
    		
    		/**
    		 * The class responsible for defining all actions that 
    		 */
    		 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-cpt.php';
    		
    		/**
    		 * The class for generating dropdowns in custom post types admin
    		 */
    		//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/libraries/walker.php';
    		
    		/**
    		 * Template Loader
    		 */
    		//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-template-loader.php';
    
    		/**
    		 * The class responsible for defining all actions that occur in the admin area.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-picture-frame-admin.php';
    
    		/**
    		 * The class responsible for defining all actions that occur in the public-facing
    		 * side of the site.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-picture-frame-public.php';
    		
    		/**
    		 * The class responsible for defining all actions that occur in admin and public area.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-shared.php';
    		
    		/**
    		 * The class responsible for generating the help sections.
    		 */
    		//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/libraries/class-contextual-help.php';
    		
    		/**
    		 * The class responsible for defining all help sections that occur in admin area.
    		 */
    		//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-help.php';
    
    		$this->loader = new Picture_Frame_Loader();
    
    	}
    
    	/**
    	 * Define the locale for this plugin for internationalization.
    	 *
    	 * Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
    	 * with WordPress.
    	 *
    	 * @since    1.0.0
    	 * @access   private
    	 */
    	private function set_locale() {
    
    		$plugin_i18n = new Picture_Frame_I18n();
    
    		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
    
    	}
    
    	/**
    	 * Register all of the hooks related to the admin area functionality
    	 * of the plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   private
    	 */
    	private function define_admin_hooks() {
    
    		$this->admin	= new Picture_Frame_Admin( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		$this->cpt		= new Picture_Frame_CPT( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		//$this->acf		= new Picture_Frame_ACF( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		$this->shared	= new Picture_Frame_Shared( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		//$this->help		= new Picture_Frame_Help( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    
    		//$this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_styles' );
    		//$this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_scripts' );
    		
    		$this->loader->add_action( 'admin_menu', $this->admin, 'pf_create_menu' );
    		
    		// add custom post types and taxonomies
    		$this->loader->add_action( 'init', $this->cpt, 'pf_create_cpt' );
    		
    		// create fake submenu to add other taxonomies
    		$this->loader->add_action( 'admin_menu', $this->cpt, 'pf_create_submenus' );
    		
    		// highlight correct menu for taxonomies
    		//$this->loader->add_action( 'parent_file', $this->cpt, 'pf_highlight_menu' );
    		
    		//$this->loader->add_action( 'submenu_file', $this->cpt, 'pf_highlight_submenu' );
    		
    		// add columns to cpt exhibition
    		//$this->loader->add_filter( 'manage_pf_exhibition_posts_columns', $this->cpt, 'pf_add_columns_to_exhibition' );
    		
    		// fill columns in cpt exhibition
    		//$this->loader->add_action( 'manage_pf_exhibition_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_exhibition', 10, 2 );
    		
    		// add columns to cpt work
    		//$this->loader->add_filter( 'manage_pf_work_posts_columns', $this->cpt, 'pf_add_columns_to_work' );
    		
    		// fill columns in cpt work
    		//$this->loader->add_action( 'manage_pf_work_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_work', 10, 2 );
    	
    		// add columns to taxonomy artist
    		//$this->loader->add_filter( 'manage_edit-pf_work_artist_columns', $this->cpt, 'pf_add_columns_to_taxonomy_artist' );
    		
    		// fill columns in artist taxonomy
    		//$this->loader->add_filter( 'manage_pf_work_artist_custom_column', $this->cpt, 'pf_add_columns_content_to_taxonomy_artist', 10, 3 );
    		
    		// add columns to taxonomy artist
    		//$this->loader->add_filter( 'manage_edit-pf_work_client_columns', $this->cpt, 'pf_add_columns_to_taxonomy_client' );
    		
    		// fill columns in artist taxonomy
    		//$this->loader->add_filter( 'manage_pf_work_client_custom_column', $this->cpt, 'pf_add_columns_content_to_taxonomy_client', 10, 3 );
    		
    		// add columns to cpt zone
    		//$this->loader->add_filter( 'manage_pf_zone_posts_columns', $this->cpt, 'pf_add_columns_to_zone' );
    		
    		// fill columns in cpt screen
    		//$this->loader->add_action( 'manage_pf_zone_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_zone', 10, 2 );
    		
    		// add columns to cpt screen
    		//$this->loader->add_filter( 'manage_pf_display_posts_columns', $this->cpt, 'pf_add_columns_to_display' );
    		
    		// fill columns in cpt screen
    		//$this->loader->add_action( 'manage_pf_display_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_display', 10, 2 );
    		
    		// add columns to cpt view
    		//$this->loader->add_filter( 'manage_pf_view_posts_columns', $this->cpt, 'pf_add_columns_to_view' );
    		
    		// fill columns in cpt screen
    		//$this->loader->add_action( 'manage_pf_view_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_view', 10, 2 );
    		
    		// register sortable columns / dropdowns for post type
    		//$this->loader->add_action( 'restrict_manage_posts', $this->cpt, 'pf_filter_post_type_by_taxonomy' );
    		
    		// hide taxonomies from quick edit
    		//$this->loader->add_action( 'quick_edit_show_taxonomy', $this->cpt, 'pf_hide_taxonomies_quick_edit', 10, 3 );
    		
    		// add custom image sizes
    		//$this->loader->add_action( 'after_setup_theme', $this->admin, 'pf_add_image_sizes' );
    		
    		// add styles to admin head for custom post types
    		//$this->loader->add_action( 'admin_head', $this->admin, 'pf_add_styles_to_admin_head' );
    		
    		// delete attachement
    		//$this->loader->add_action( 'deleted_post', $this->admin, 'pf_delete_transients' );
    		
    		// add custom post type works to doashboard
    		//$this->loader->add_action( 'dashboard_glance_items', $this->cpt, 'pf_add_glance_content' );
    		
    		// add help screens for all plugin pages
    		//$this->loader->add_action( 'init', $this->help, 'pf_add_help' );
    		
    	}
    
    	/**
    	 * Register all of the hooks related to the public-facing functionality
    	 * of the plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   private
    	 */
    	private function define_public_hooks() {
    
    		$this->public	= new Picture_Frame_Public( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		$this->shared	= new Picture_Frame_Shared( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    
    		$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'enqueue_styles' );
    		$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'enqueue_scripts' );
    		
    		$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'pf_enqueue_styles' );
    		$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'pf_enqueue_scripts' );
    
    		// Shortcode name must be the same as in shortcode_atts() third parameter.
    		//$this->loader->add_shortcode( $this->get_plugin_prefix() . 'shortcode', $this->public, 'pfx_shortcode_func' );
    		
    		// loads the custom template file for custom post type single public view
    		$this->loader->add_filter( 'single_template', $this->public, 'pf_get_template' );
    
    	}
    
    	/**
    	 * Run the loader to execute all of the hooks with WordPress.
    	 *
    	 * @since    1.0.0
    	 */
    	public function run() {
    		$this->loader->run();
    	}
    
    	/**
    	 * The name of the plugin used to uniquely identify it within the context of
    	 * WordPress and to define internationalization functionality.
    	 *
    	 * @since     1.0.0
    	 * @return    string    The name of the plugin.
    	 */
    	public function get_plugin_name() {
    		return $this->plugin_name;
    	}
    
    	/**
    	 * The unique prefix of the plugin used to uniquely prefix technical functions.
    	 *
    	 * @since     1.0.0
    	 * @return    string    The prefix of the plugin.
    	 */
    	public function get_plugin_prefix() {
    		return $this->plugin_prefix;
    	}
    
    	/**
    	 * The reference to the class that orchestrates the hooks with the plugin.
    	 *
    	 * @since     1.0.0
    	 * @return    Plugin_Name_Loader    Orchestrates the hooks of the plugin.
    	 */
    	public function get_loader() {
    		return $this->loader;
    	}
    
    	/**
    	 * Retrieve the version number of the plugin.
    	 *
    	 * @since     1.0.0
    	 * @return    string    The version number of the plugin.
    	 */
    	public function get_version() {
    		return $this->version;
    	}
    
    }
  • It was my fault !!!!!: By defining acf/save_post and NOT differentiating the ‘pages’ the WordPres AJAX goes into ‘the neverending search’. Now i switched to filter by pages/posttypes/categories and it works perfect.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.