PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/advanced-custom-fields-pro/acf.php

https://gitlab.com/gabdark/aceit
PHP | 547 lines | 230 code | 137 blank | 180 comment | 13 complexity | 92226d4eef3cdb53d59283e937ea693f MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: Advanced Custom Fields PRO
  4. Plugin URI: https://www.advancedcustomfields.com/
  5. Description: Customise WordPress with powerful, professional and intuitive fields
  6. Version: 5.4.2
  7. Author: Elliot Condon
  8. Author URI: http://www.elliotcondon.com/
  9. Copyright: Elliot Condon
  10. Text Domain: acf
  11. Domain Path: /lang
  12. */
  13. if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  14. if( ! class_exists('acf') ) :
  15. class acf {
  16. /*
  17. * __construct
  18. *
  19. * A dummy constructor to ensure ACF is only initialized once
  20. *
  21. * @type function
  22. * @date 23/06/12
  23. * @since 5.0.0
  24. *
  25. * @param N/A
  26. * @return N/A
  27. */
  28. function __construct() {
  29. /* Do nothing here */
  30. }
  31. /*
  32. * initialize
  33. *
  34. * The real constructor to initialize ACF
  35. *
  36. * @type function
  37. * @date 28/09/13
  38. * @since 5.0.0
  39. *
  40. * @param $post_id (int)
  41. * @return $post_id (int)
  42. */
  43. function initialize() {
  44. // vars
  45. $this->settings = array(
  46. // basic
  47. 'name' => __('Advanced Custom Fields', 'acf'),
  48. 'version' => '5.4.2',
  49. // urls
  50. 'basename' => plugin_basename( __FILE__ ),
  51. 'path' => plugin_dir_path( __FILE__ ),
  52. 'dir' => plugin_dir_url( __FILE__ ),
  53. // options
  54. 'show_admin' => true,
  55. 'show_updates' => true,
  56. 'stripslashes' => false,
  57. 'local' => true,
  58. 'json' => true,
  59. 'save_json' => '',
  60. 'load_json' => array(),
  61. 'default_language' => '',
  62. 'current_language' => '',
  63. 'capability' => 'manage_options',
  64. 'uploader' => 'wp',
  65. 'autoload' => false,
  66. 'l10n' => true,
  67. 'l10n_textdomain' => '',
  68. 'google_api_key' => '',
  69. 'google_api_client' => ''
  70. );
  71. // include helpers
  72. include_once('api/api-helpers.php');
  73. // api
  74. acf_include('api/api-value.php');
  75. acf_include('api/api-field.php');
  76. acf_include('api/api-field-group.php');
  77. acf_include('api/api-template.php');
  78. // core
  79. acf_include('core/ajax.php');
  80. acf_include('core/cache.php');
  81. acf_include('core/fields.php');
  82. acf_include('core/field.php');
  83. acf_include('core/input.php');
  84. acf_include('core/validation.php');
  85. acf_include('core/json.php');
  86. acf_include('core/local.php');
  87. acf_include('core/location.php');
  88. acf_include('core/loop.php');
  89. acf_include('core/media.php');
  90. acf_include('core/revisions.php');
  91. acf_include('core/compatibility.php');
  92. acf_include('core/third_party.php');
  93. acf_include('core/updates.php');
  94. // forms
  95. acf_include('forms/attachment.php');
  96. acf_include('forms/comment.php');
  97. acf_include('forms/post.php');
  98. acf_include('forms/taxonomy.php');
  99. acf_include('forms/user.php');
  100. acf_include('forms/widget.php');
  101. // admin
  102. if( is_admin() ) {
  103. acf_include('admin/admin.php');
  104. acf_include('admin/field-group.php');
  105. acf_include('admin/field-groups.php');
  106. acf_include('admin/update.php');
  107. acf_include('admin/update-network.php');
  108. acf_include('admin/settings-tools.php');
  109. //acf_include('admin/settings-addons.php');
  110. acf_include('admin/settings-info.php');
  111. }
  112. // pro
  113. acf_include('pro/acf-pro.php');
  114. // actions
  115. add_action('init', array($this, 'init'), 5);
  116. add_action('init', array($this, 'register_post_types'), 5);
  117. add_action('init', array($this, 'register_post_status'), 5);
  118. add_action('init', array($this, 'register_assets'), 5);
  119. // filters
  120. add_filter('posts_where', array($this, 'posts_where'), 10, 2 );
  121. //add_filter('posts_request', array($this, 'posts_request'), 10, 1 );
  122. }
  123. /*
  124. * init
  125. *
  126. * This function will run after all plugins and theme functions have been included
  127. *
  128. * @type action (init)
  129. * @date 28/09/13
  130. * @since 5.0.0
  131. *
  132. * @param N/A
  133. * @return N/A
  134. */
  135. function init() {
  136. // bail early if a plugin called get_field early
  137. if( !did_action('plugins_loaded') ) return;
  138. // bail early if already init
  139. if( acf_get_setting('init') ) return;
  140. // only run once
  141. acf_update_setting('init', true);
  142. // vars
  143. $major = intval( acf_get_setting('version') );
  144. // redeclare dir
  145. // - allow another plugin to modify dir (maybe force SSL)
  146. acf_update_setting('dir', plugin_dir_url( __FILE__ ));
  147. // set text domain
  148. load_textdomain( 'acf', acf_get_path( 'lang/acf-' . get_locale() . '.mo' ) );
  149. // include wpml support
  150. if( defined('ICL_SITEPRESS_VERSION') ) {
  151. acf_include('core/wpml.php');
  152. }
  153. // field types
  154. acf_include('fields/text.php');
  155. acf_include('fields/textarea.php');
  156. acf_include('fields/number.php');
  157. acf_include('fields/email.php');
  158. acf_include('fields/url.php');
  159. acf_include('fields/password.php');
  160. acf_include('fields/wysiwyg.php');
  161. acf_include('fields/oembed.php');
  162. acf_include('fields/image.php');
  163. acf_include('fields/file.php');
  164. acf_include('fields/select.php');
  165. acf_include('fields/checkbox.php');
  166. acf_include('fields/radio.php');
  167. acf_include('fields/true_false.php');
  168. acf_include('fields/post_object.php');
  169. acf_include('fields/page_link.php');
  170. acf_include('fields/relationship.php');
  171. acf_include('fields/taxonomy.php');
  172. acf_include('fields/user.php');
  173. acf_include('fields/google-map.php');
  174. acf_include('fields/date_picker.php');
  175. acf_include('fields/date_time_picker.php');
  176. acf_include('fields/time_picker.php');
  177. acf_include('fields/color_picker.php');
  178. acf_include('fields/message.php');
  179. acf_include('fields/tab.php');
  180. // 3rd party field types
  181. do_action('acf/include_field_types', $major);
  182. // local fields
  183. do_action('acf/include_fields', $major);
  184. // action for 3rd party
  185. do_action('acf/init');
  186. }
  187. /*
  188. * register_post_types
  189. *
  190. * This function will register post types and statuses
  191. *
  192. * @type function
  193. * @date 22/10/2015
  194. * @since 5.3.2
  195. *
  196. * @param n/a
  197. * @return n/a
  198. */
  199. function register_post_types() {
  200. // vars
  201. $cap = acf_get_setting('capability');
  202. // register post type 'acf-field-group'
  203. register_post_type('acf-field-group', array(
  204. 'labels' => array(
  205. 'name' => __( 'Field Groups', 'acf' ),
  206. 'singular_name' => __( 'Field Group', 'acf' ),
  207. 'add_new' => __( 'Add New' , 'acf' ),
  208. 'add_new_item' => __( 'Add New Field Group' , 'acf' ),
  209. 'edit_item' => __( 'Edit Field Group' , 'acf' ),
  210. 'new_item' => __( 'New Field Group' , 'acf' ),
  211. 'view_item' => __( 'View Field Group', 'acf' ),
  212. 'search_items' => __( 'Search Field Groups', 'acf' ),
  213. 'not_found' => __( 'No Field Groups found', 'acf' ),
  214. 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ),
  215. ),
  216. 'public' => false,
  217. 'show_ui' => true,
  218. '_builtin' => false,
  219. 'capability_type' => 'post',
  220. 'capabilities' => array(
  221. 'edit_post' => $cap,
  222. 'delete_post' => $cap,
  223. 'edit_posts' => $cap,
  224. 'delete_posts' => $cap,
  225. ),
  226. 'hierarchical' => true,
  227. 'rewrite' => false,
  228. 'query_var' => false,
  229. 'supports' => array('title'),
  230. 'show_in_menu' => false,
  231. ));
  232. // register post type 'acf-field'
  233. register_post_type('acf-field', array(
  234. 'labels' => array(
  235. 'name' => __( 'Fields', 'acf' ),
  236. 'singular_name' => __( 'Field', 'acf' ),
  237. 'add_new' => __( 'Add New' , 'acf' ),
  238. 'add_new_item' => __( 'Add New Field' , 'acf' ),
  239. 'edit_item' => __( 'Edit Field' , 'acf' ),
  240. 'new_item' => __( 'New Field' , 'acf' ),
  241. 'view_item' => __( 'View Field', 'acf' ),
  242. 'search_items' => __( 'Search Fields', 'acf' ),
  243. 'not_found' => __( 'No Fields found', 'acf' ),
  244. 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ),
  245. ),
  246. 'public' => false,
  247. 'show_ui' => false,
  248. '_builtin' => false,
  249. 'capability_type' => 'post',
  250. 'capabilities' => array(
  251. 'edit_post' => $cap,
  252. 'delete_post' => $cap,
  253. 'edit_posts' => $cap,
  254. 'delete_posts' => $cap,
  255. ),
  256. 'hierarchical' => true,
  257. 'rewrite' => false,
  258. 'query_var' => false,
  259. 'supports' => array('title'),
  260. 'show_in_menu' => false,
  261. ));
  262. }
  263. /*
  264. * register_post_status
  265. *
  266. * This function will register custom post statuses
  267. *
  268. * @type function
  269. * @date 22/10/2015
  270. * @since 5.3.2
  271. *
  272. * @param $post_id (int)
  273. * @return $post_id (int)
  274. */
  275. function register_post_status() {
  276. // acf-disabled
  277. register_post_status('acf-disabled', array(
  278. 'label' => __( 'Disabled', 'acf' ),
  279. 'public' => true,
  280. 'exclude_from_search' => false,
  281. 'show_in_admin_all_list' => true,
  282. 'show_in_admin_status_list' => true,
  283. 'label_count' => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'acf' ),
  284. ));
  285. }
  286. /*
  287. * register_assets
  288. *
  289. * This function will register scripts and styles
  290. *
  291. * @type function
  292. * @date 22/10/2015
  293. * @since 5.3.2
  294. *
  295. * @param n/a
  296. * @return n/a
  297. */
  298. function register_assets() {
  299. // vars
  300. $version = acf_get_setting('version');
  301. $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
  302. // scripts
  303. wp_register_script('acf-input', acf_get_dir("assets/js/acf-input{$min}.js"), array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-resizable'), $version );
  304. wp_register_script('acf-field-group', acf_get_dir("assets/js/acf-field-group{$min}.js"), array('acf-input'), $version );
  305. // styles
  306. wp_register_style('acf-global', acf_get_dir('assets/css/acf-global.css'), array(), $version );
  307. wp_register_style('acf-input', acf_get_dir('assets/css/acf-input.css'), array('acf-global'), $version );
  308. wp_register_style('acf-field-group', acf_get_dir('assets/css/acf-field-group.css'), array('acf-input'), $version );
  309. }
  310. /*
  311. * posts_where
  312. *
  313. * This function will add in some new parameters to the WP_Query args allowing fields to be found via key / name
  314. *
  315. * @type filter
  316. * @date 5/12/2013
  317. * @since 5.0.0
  318. *
  319. * @param $where (string)
  320. * @param $wp_query (object)
  321. * @return $where (string)
  322. */
  323. function posts_where( $where, $wp_query ) {
  324. // global
  325. global $wpdb;
  326. // acf_field_key
  327. if( $field_key = $wp_query->get('acf_field_key') ) {
  328. $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $field_key );
  329. }
  330. // acf_field_name
  331. if( $field_name = $wp_query->get('acf_field_name') ) {
  332. $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_excerpt = %s", $field_name );
  333. }
  334. // acf_group_key
  335. if( $group_key = $wp_query->get('acf_group_key') ) {
  336. $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $group_key );
  337. }
  338. // return
  339. return $where;
  340. }
  341. /*
  342. * get_setting
  343. *
  344. * This function will return a value from the settings array found in the acf object
  345. *
  346. * @type function
  347. * @date 28/09/13
  348. * @since 5.0.0
  349. *
  350. * @param $name (string) the setting name to return
  351. * @param $value (mixed) default value
  352. * @return $value
  353. */
  354. function get_setting( $name, $value = null ) {
  355. // check settings
  356. if( isset($this->settings[ $name ]) ) {
  357. $value = $this->settings[ $name ];
  358. }
  359. // filter for 3rd party customization
  360. if( substr($name, 0, 1) !== '_' ) {
  361. $value = apply_filters( "acf/settings/{$name}", $value );
  362. }
  363. // return
  364. return $value;
  365. }
  366. /*
  367. * update_setting
  368. *
  369. * This function will update a value into the settings array found in the acf object
  370. *
  371. * @type function
  372. * @date 28/09/13
  373. * @since 5.0.0
  374. *
  375. * @param $name (string)
  376. * @param $value (mixed)
  377. * @return n/a
  378. */
  379. function update_setting( $name, $value ) {
  380. $this->settings[ $name ] = $value;
  381. return true;
  382. }
  383. }
  384. /*
  385. * acf
  386. *
  387. * The main function responsible for returning the one true acf Instance to functions everywhere.
  388. * Use this function like you would a global variable, except without needing to declare the global.
  389. *
  390. * Example: <?php $acf = acf(); ?>
  391. *
  392. * @type function
  393. * @date 4/09/13
  394. * @since 4.3.0
  395. *
  396. * @param N/A
  397. * @return (object)
  398. */
  399. function acf() {
  400. global $acf;
  401. if( !isset($acf) ) {
  402. $acf = new acf();
  403. $acf->initialize();
  404. }
  405. return $acf;
  406. }
  407. // initialize
  408. acf();
  409. endif; // class_exists check
  410. ?>