| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Advanced Forms |
| 4 |
* Plugin URI: https://wordpress.org/plugins/advanced-forms/ |
| 5 |
* Description: Flexible and developer-friendly forms with the power of Advanced Custom Fields. |
| 6 |
* Version: 1.9.3.8 |
| 7 |
* Author: Phil Kurth (Hookturn) |
| 8 |
* Author URI: http://hookturn.io |
| 9 |
* Copyright: Hookturn Digital |
| 10 |
* Text Domain: advanced-forms |
| 11 |
* Domain Path: /language |
| 12 |
* Requires PHP: 7.1 |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! class_exists( 'AF' ) ) : |
| 16 |
|
| 17 |
class AF { |
| 18 |
|
| 19 |
/** |
| 20 |
* Plugin version |
| 21 |
* |
| 22 |
* @since 1.2.0 |
| 23 |
*/ |
| 24 |
public $version = '1.9.3.8'; |
| 25 |
|
| 26 |
/** |
| 27 |
* Array to hold data about the previous submission |
| 28 |
* |
| 29 |
* @since 1.1 |
| 30 |
*/ |
| 31 |
public $submission; |
| 32 |
|
| 33 |
/** |
| 34 |
* Boolean indicating whether Pro version is installed |
| 35 |
* |
| 36 |
* @since 1.5.0 |
| 37 |
*/ |
| 38 |
public $pro; |
| 39 |
|
| 40 |
/** |
| 41 |
* @var mixed|null |
| 42 |
*/ |
| 43 |
public $show_admin; |
| 44 |
|
| 45 |
/** |
| 46 |
* @var string |
| 47 |
*/ |
| 48 |
public $path; |
| 49 |
|
| 50 |
/** |
| 51 |
* @var string |
| 52 |
*/ |
| 53 |
public $url; |
| 54 |
|
| 55 |
/** |
| 56 |
* @var array |
| 57 |
*/ |
| 58 |
public $classes; |
| 59 |
|
| 60 |
function __construct() { |
| 61 |
add_action( 'plugins_loaded', array( $this, 'setup_plugin' ), 1, 0 ); |
| 62 |
add_action( 'acf/init', array( $this, 'load_plugin' ), 1, 0 ); |
| 63 |
add_action( 'admin_notices', array( $this, 'missing_acf_notice' ), 10, 0 ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Set up global constants and load textdomain. |
| 68 |
* This needs to be called separately from acf/init to enable integration with translate.wordpress.org. |
| 69 |
* |
| 70 |
* @since 1.4.0 |
| 71 |
*/ |
| 72 |
function setup_plugin() { |
| 73 |
// Setup global plugin defaults |
| 74 |
$this->submission = null; |
| 75 |
$this->pro = false; |
| 76 |
$this->show_admin = apply_filters( 'af/settings/show_admin', true ); |
| 77 |
$this->path = trailingslashit( apply_filters( 'af/settings/path', plugin_dir_path( __FILE__ ) ) ); |
| 78 |
$this->url = trailingslashit( apply_filters( 'af/settings/url', plugin_dir_url( __FILE__ ) ) ); |
| 79 |
|
| 80 |
load_plugin_textdomain( 'advanced-forms', false, basename( dirname( __FILE__ ) ) . '/language' ); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Ensure ACF is available and load plugin files |
| 85 |
* |
| 86 |
* @since 1.0.0 |
| 87 |
*/ |
| 88 |
function load_plugin() { |
| 89 |
if ( ! $this->has_acf() ) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
$this->classes = array(); |
| 94 |
|
| 95 |
// API functions |
| 96 |
include( $this->path . 'api/api-submissions.php' ); |
| 97 |
include( $this->path . 'api/api-helpers.php' ); |
| 98 |
include( $this->path . 'api/api-forms.php' ); |
| 99 |
include( $this->path . 'api/api-entries.php' ); |
| 100 |
include( $this->path . 'api/api-import-export.php' ); |
| 101 |
|
| 102 |
// Core functionality |
| 103 |
$this->classes['core_forms_rendering'] = include( $this->path . 'core/forms/forms-rendering.php' ); |
| 104 |
$this->classes['core_forms_submissions'] = include( $this->path . 'core/forms/forms-submissions.php' ); |
| 105 |
$this->classes['core_restrictions'] = include( $this->path . 'core/core-restrictions.php' ); |
| 106 |
$this->classes['core_emails'] = include( $this->path . 'core/core-emails.php' ); |
| 107 |
$this->classes['core_entries'] = include( $this->path . 'core/core-entries.php' ); |
| 108 |
$this->classes['core_merge_tags'] = include( $this->path . 'core/core-merge-tags.php' ); |
| 109 |
$this->classes['core_gutenberg'] = include( $this->path . 'core/core-gutenberg.php' ); |
| 110 |
$this->classes['core_migrations'] = include( $this->path . 'core/core-migrations.php' ); |
| 111 |
|
| 112 |
// ACF additions (fields, location rules, etc.) |
| 113 |
$this->classes['acf_additions'] = include( $this->path . 'acf/acf-additions.php' ); |
| 114 |
include( $this->path . 'acf/fields/af-render-content-field.php' ); |
| 115 |
include( $this->path . 'acf/fields/field_select.php' ); |
| 116 |
include( $this->path . 'acf/fields/divider.php' ); |
| 117 |
include( $this->path . 'acf/fields/page.php' ); |
| 118 |
|
| 119 |
// Admin |
| 120 |
$this->classes['admin_forms'] = include( $this->path . 'admin/admin-forms.php' ); |
| 121 |
$this->classes['admin_forms_preview'] = include( $this->path . 'admin/forms/forms-preview.php' ); |
| 122 |
$this->classes['admin_forms_export'] = include( $this->path . 'admin/forms/forms-export.php' ); |
| 123 |
$this->classes['admin_forms_import'] = include( $this->path . 'admin/forms/forms-import.php' ); |
| 124 |
$this->classes['admin_restrictions'] = include( $this->path . 'admin/admin-restrictions.php' ); |
| 125 |
$this->classes['admin_entries'] = include( $this->path . 'admin/admin-entries.php' ); |
| 126 |
$this->classes['admin_emails'] = include( $this->path . 'admin/admin-emails.php' ); |
| 127 |
|
| 128 |
if ( file_exists( $this->path . 'pro/advanced-forms-pro.php' ) ) { |
| 129 |
$this->classes['pro'] = include( $this->path . 'pro/advanced-forms-pro.php' ); |
| 130 |
} |
| 131 |
|
| 132 |
// Enqueue admin assets |
| 133 |
if ( $this->show_admin ) { |
| 134 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ), 10, 0 ); |
| 135 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 10, 0 ); |
| 136 |
} |
| 137 |
|
| 138 |
// Register basic post types |
| 139 |
add_action( 'init', array( $this, 'register_post_types' ), 10, 0 ); |
| 140 |
|
| 141 |
// Action used to register forms |
| 142 |
do_action( 'af/register_forms' ); |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Check if ACF Pro is installed |
| 148 |
* |
| 149 |
* @since 1.3.1 |
| 150 |
*/ |
| 151 |
function has_acf() { |
| 152 |
return class_exists( 'acf_pro' ); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Display notice if ACF Pro is missing |
| 157 |
* |
| 158 |
* @since 1.0.0 |
| 159 |
*/ |
| 160 |
function missing_acf_notice() { |
| 161 |
if ( ! $this->has_acf() ) { |
| 162 |
echo sprintf( |
| 163 |
'<div class="notice notice-error is-dismissible"><p>%s</p></div>', |
| 164 |
__( "Couldn't find ACF PRO. Advanced Forms requires the PRO version of ACF (version 5 or greater) to function.", 'advanced-forms' ) |
| 165 |
); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Enqueues admin scripts |
| 171 |
* |
| 172 |
* @since 1.0.1 |
| 173 |
*/ |
| 174 |
function enqueue_admin_scripts() { |
| 175 |
wp_enqueue_script( 'jquery' ); |
| 176 |
wp_enqueue_script( 'af-admin-script', $this->url . 'assets/dist/js/admin.js', array( |
| 177 |
'jquery', |
| 178 |
'acf-input' |
| 179 |
) ); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Enqueues admin styles |
| 184 |
* |
| 185 |
* @since 1.0.0 |
| 186 |
*/ |
| 187 |
function enqueue_admin_styles() { |
| 188 |
wp_enqueue_style( 'af-admin-style', $this->url . 'assets/dist/css/admin.css' ); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* Register custom post types, forms and entries |
| 193 |
* |
| 194 |
* @since 1.0.0 |
| 195 |
*/ |
| 196 |
function register_post_types() { |
| 197 |
// Form post type |
| 198 |
$labels = array( |
| 199 |
'name' => _x( 'Forms', 'Post Type General Name', 'advanced-forms' ), |
| 200 |
'singular_name' => _x( 'Form', 'Post Type Singular Name', 'advanced-forms' ), |
| 201 |
'menu_name' => __( 'Forms', 'advanced-forms' ), |
| 202 |
'name_admin_bar' => __( 'Form', 'advanced-forms' ), |
| 203 |
'archives' => __( 'Form Archives', 'advanced-forms' ), |
| 204 |
'parent_item_colon' => __( 'Parent Form:', 'advanced-forms' ), |
| 205 |
'all_items' => __( 'Forms', 'advanced-forms' ), |
| 206 |
'add_new_item' => __( 'Add New Form', 'advanced-forms' ), |
| 207 |
'add_new' => __( 'Add New', 'advanced-forms' ), |
| 208 |
'new_item' => __( 'New Form', 'advanced-forms' ), |
| 209 |
'edit_item' => __( 'Edit Form', 'advanced-forms' ), |
| 210 |
'update_item' => __( 'Update Form', 'advanced-forms' ), |
| 211 |
'view_item' => __( 'View Form', 'advanced-forms' ), |
| 212 |
'search_items' => __( 'Search Form', 'advanced-forms' ), |
| 213 |
'not_found' => __( 'Not found', 'advanced-forms' ), |
| 214 |
'not_found_in_trash' => __( 'Not found in Trash', 'advanced-forms' ), |
| 215 |
'featured_image' => __( 'Featured Image', 'advanced-forms' ), |
| 216 |
'set_featured_image' => __( 'Set featured image', 'advanced-forms' ), |
| 217 |
'remove_featured_image' => __( 'Remove featured image', 'advanced-forms' ), |
| 218 |
'use_featured_image' => __( 'Use as featured image', 'advanced-forms' ), |
| 219 |
'insert_into_item' => __( 'Insert into form', 'advanced-forms' ), |
| 220 |
'uploaded_to_this_item' => __( 'Uploaded to this form', 'advanced-forms' ), |
| 221 |
'items_list' => __( 'Forms list', 'advanced-forms' ), |
| 222 |
'items_list_navigation' => __( 'Forms list navigation', 'advanced-forms' ), |
| 223 |
'filter_items_list' => __( 'Filter forms list', 'advanced-forms' ), |
| 224 |
); |
| 225 |
$args = array( |
| 226 |
'label' => __( 'Form', 'advanced-forms' ), |
| 227 |
'description' => __( 'Form', 'advanced-forms' ), |
| 228 |
'labels' => $labels, |
| 229 |
'supports' => array( 'title', ), |
| 230 |
'hierarchical' => false, |
| 231 |
'public' => false, |
| 232 |
'show_ui' => $this->show_admin, |
| 233 |
'show_in_menu' => $this->show_admin, |
| 234 |
'menu_icon' => 'dashicons-list-view', |
| 235 |
'menu_position' => 80, |
| 236 |
'show_in_admin_bar' => false, |
| 237 |
'can_export' => true, |
| 238 |
'rewrite' => false, |
| 239 |
'capability_type' => 'page', |
| 240 |
'query_var' => false, |
| 241 |
); |
| 242 |
register_post_type( 'af_form', $args ); |
| 243 |
|
| 244 |
// Entry post type |
| 245 |
$labels = array( |
| 246 |
'name' => _x( 'Entries', 'Post Type General Name', 'advanced-forms' ), |
| 247 |
'singular_name' => _x( 'Entry', 'Post Type Singular Name', 'advanced-forms' ), |
| 248 |
'menu_name' => __( 'Entries', 'advanced-forms' ), |
| 249 |
'name_admin_bar' => __( 'Entry', 'advanced-forms' ), |
| 250 |
'archives' => __( 'Entry Archives', 'advanced-forms' ), |
| 251 |
'parent_item_colon' => __( 'Parent Entry:', 'advanced-forms' ), |
| 252 |
'all_items' => __( 'Entries', 'advanced-forms' ), |
| 253 |
'add_new_item' => __( 'Add New Entry', 'advanced-forms' ), |
| 254 |
'add_new' => __( 'Add New', 'advanced-forms' ), |
| 255 |
'new_item' => __( 'New Entry', 'advanced-forms' ), |
| 256 |
'edit_item' => __( 'Edit Entry', 'advanced-forms' ), |
| 257 |
'update_item' => __( 'Update Entry', 'advanced-forms' ), |
| 258 |
'view_item' => __( 'View Entry', 'advanced-forms' ), |
| 259 |
'search_items' => __( 'Search Entry', 'advanced-forms' ), |
| 260 |
'not_found' => __( 'Not found', 'advanced-forms' ), |
| 261 |
'not_found_in_trash' => __( 'Not found in Trash', 'advanced-forms' ), |
| 262 |
'featured_image' => __( 'Featured Image', 'advanced-forms' ), |
| 263 |
'set_featured_image' => __( 'Set featured image', 'advanced-forms' ), |
| 264 |
'remove_featured_image' => __( 'Remove featured image', 'advanced-forms' ), |
| 265 |
'use_featured_image' => __( 'Use as featured image', 'advanced-forms' ), |
| 266 |
'insert_into_item' => __( 'Insert into entry', 'advanced-forms' ), |
| 267 |
'uploaded_to_this_item' => __( 'Uploaded to this entry', 'advanced-forms' ), |
| 268 |
'items_list' => __( 'Entries list', 'advanced-forms' ), |
| 269 |
'items_list_navigation' => __( 'Entries list navigation', 'advanced-forms' ), |
| 270 |
'filter_items_list' => __( 'Filter entries list', 'advanced-forms' ), |
| 271 |
); |
| 272 |
$args = array( |
| 273 |
'label' => __( 'Entry', 'advanced-forms' ), |
| 274 |
'description' => __( 'Entry', 'advanced-forms' ), |
| 275 |
'labels' => $labels, |
| 276 |
'supports' => array( 'title', ), |
| 277 |
'hierarchical' => false, |
| 278 |
'public' => false, |
| 279 |
'show_ui' => $this->show_admin, |
| 280 |
'show_in_menu' => 'edit.php?post_type=af_form', |
| 281 |
'menu_icon' => 'dashicons-list-view', |
| 282 |
'menu_position' => 80, |
| 283 |
'show_in_admin_bar' => false, |
| 284 |
'can_export' => true, |
| 285 |
'rewrite' => false, |
| 286 |
'capability_type' => 'page', |
| 287 |
'query_var' => false, |
| 288 |
); |
| 289 |
register_post_type( 'af_entry', $args ); |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* Helper function to access the global AF object |
| 295 |
* |
| 296 |
* @since 1.1 |
| 297 |
*/ |
| 298 |
function AF() { |
| 299 |
global $af; |
| 300 |
|
| 301 |
if ( ! isset( $af ) ) { |
| 302 |
$af = new AF(); |
| 303 |
} |
| 304 |
|
| 305 |
return $af; |
| 306 |
} |
| 307 |
|
| 308 |
// Initalize plugin |
| 309 |
AF(); |
| 310 |
|
| 311 |
endif; |
| 312 |
|