Skip to content

Instantly share code, notes, and snippets.

@mklasen
Last active October 15, 2021 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mklasen/d220147bcce069e242a5e1b4fcd1aaa3 to your computer and use it in GitHub Desktop.
Save mklasen/d220147bcce069e242a5e1b4fcd1aaa3 to your computer and use it in GitHub Desktop.
Include ACF (Pro) in a premium WordPress plugin
<?php
/**
* An example for including Advanced Custom Fields in your plugin
* Made for Premia (getpremia.com)
* WordPress premium plugins made easy!
*/
class Your_Plugin {
public function __construct() {
$this->setup_acf();
}
public function setup_acf() {
if ( ! class_exists( 'ACF' ) ) {
include_once 'libs/acf/acf.php';
add_filter( 'acf/settings/url', array( $this, 'acf_url' ) );
add_filter( 'acf/settings/show_admin', '__return_false' );
add_action( 'acf/init', array( $this, 'add_options_page' ) );
add_action( 'acf/init', array( $this, 'add_fields' ) );
}
}
public function acf_url() {
return plugin_dir_url( __FILE__ ) . 'libs/acf/';
}
public function add_options_page() {
if ( function_exists( 'acf_add_options_page' ) ) {
acf_add_options_page(
array(
'page_title' => 'Custom Per Product Thank You Pages',
'menu_title' => 'CustomPP',
'menu_slug' => 'custom-thank-you',
'capability' => 'edit_posts',
'redirect' => false,
)
);
}
}
public function add_fields() {
// Paste the PHP export from ACF here (ACF -> Tools -> Export)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment