-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacf-to-post.php
134 lines (115 loc) · 2.67 KB
/
acf-to-post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/*
Plugin Name: ACF to Post
Plugin URI: https://thefancyrobot.com
Description: Automatically add ACF fields to the post object
Version: 0.1.0
Author: Matthew Schroeter
Author URI: https://mattschroeter.me
Text Domain: tfr
Domain Path: /lang
*/
namespace TFR\ACFToPost;
use TFR\ACFToPost\Groups\Page;
use TFR\ACFToPost\Layouts\Hero;
use TFR\ACFToPost\Repeaters\Modules;
use TFR\ACFToPost\Util\FormatFieldType;
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) exit;
/**
* Class Plugin
*
* @package TFR\ACFToPost
* @since 0.1.0
*/
class Plugin {
/**
* Define the version of the plugin
*
* @var string $version
* @since 0.1.0
*/
public $version = "0.1.1";
/**
* Path to root directory of plugin
*
* @var string $path
*/
public $path;
/**
* Plugin constructor
*
* @since 0.1.0
*/
function __construct() {
$this->path = dirname(__FILE__);
$this->autoload();
Fields::init();
FormatFieldType::init();
add_action( 'after_setup_theme', [$this, 'initLayouts'] );
add_action( 'after_setup_theme', [$this, 'initFields'] );
add_action( 'after_setup_theme', [$this, 'initGroups'] );
}
/**
* Load classes
*
* @since 0.1.0
*/
private function autoload() {
require_once $this->path . '/autoload.php';
}
/**
* Initialize ACF layouts
*
* The $layouts variable is an array of class names. Each class represents an
* ACF layout and must contain a method named init that adds the layout to an ACF group.
*
* @since 0.1.0
*/
public function initLayouts() {
$layouts = apply_filters( 'acf_to_post/init/layouts', [] );
if( ! empty( $layouts ) ) {
foreach( $layouts as $layout ) {
// Make sure the init method exists before calling it
if( method_exists( $layout, 'init' ) ) {
$obj = new $layout;
$obj->init();
}
}
}
}
public function initFields() {
$fields = apply_filters( 'acf_to_post/init/fields', [] );
if( ! empty( $fields ) ) {
foreach( $fields as $field ) {
// Make sure the init method exists before calling it
if( method_exists( $field, 'init' ) ) {
$obj = new $field;
$obj->init();
}
}
}
}
/**
* Initialize ACF groups
*
* The $groups variable is an array of class names. Each class represents an
* ACF group and must contain a method named init that adds the group.
*
* @since 0.1.0
*/
public function initGroups() {
$groups = apply_filters( 'acf_to_post/init/groups', [] );
if( ! empty( $groups ) ) {
foreach( $groups as $group ) {
// Make sure the init method exists before calling it
if( method_exists ( $group, 'init' ) ) {
$obj = new $group;
$obj->init();
}
}
}
}
}
// bootstrap the plugin
new Plugin();