PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/hschoenburg/tlworks2
PHP | 487 lines | 210 code | 120 blank | 157 comment | 11 complexity | d22e0375e5933c6ada2e2201f1b83dc5 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: Advanced Custom Fields Pro
  4. Plugin URI: http://www.advancedcustomfields.com/
  5. Description: Customise WordPress with powerful, professional and intuitive fields
  6. Version: 5.3.6.1
  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.3.6.1',
  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. );
  69. // include helpers
  70. include_once('api/api-helpers.php');
  71. // api
  72. acf_include('api/api-value.php');
  73. acf_include('api/api-field.php');
  74. acf_include('api/api-field-group.php');
  75. acf_include('api/api-template.php');
  76. // core
  77. acf_include('core/ajax.php');
  78. acf_include('core/field.php');
  79. acf_include('core/input.php');
  80. acf_include('core/validation.php');
  81. acf_include('core/json.php');
  82. acf_include('core/local.php');
  83. acf_include('core/location.php');
  84. acf_include('core/loop.php');
  85. acf_include('core/media.php');
  86. acf_include('core/revisions.php');
  87. acf_include('core/compatibility.php');
  88. acf_include('core/third_party.php');
  89. // forms
  90. acf_include('forms/attachment.php');
  91. acf_include('forms/comment.php');
  92. acf_include('forms/post.php');
  93. acf_include('forms/taxonomy.php');
  94. acf_include('forms/user.php');
  95. acf_include('forms/widget.php');
  96. // admin
  97. if( is_admin() ) {
  98. acf_include('admin/admin.php');
  99. acf_include('admin/field-group.php');
  100. acf_include('admin/field-groups.php');
  101. acf_include('admin/update.php');
  102. acf_include('admin/settings-tools.php');
  103. //acf_include('admin/settings-addons.php');
  104. acf_include('admin/settings-info.php');
  105. }
  106. // pro
  107. acf_include('pro/acf-pro.php');
  108. // actions
  109. add_action('init', array($this, 'init'), 5);
  110. add_action('init', array($this, 'register_post_types'), 5);
  111. add_action('init', array($this, 'register_post_status'), 5);
  112. add_action('init', array($this, 'register_assets'), 5);
  113. // filters
  114. add_filter('posts_where', array($this, 'posts_where'), 10, 2 );
  115. //add_filter('posts_request', array($this, 'posts_request'), 10, 1 );
  116. }
  117. /*
  118. * init
  119. *
  120. * This function will run after all plugins and theme functions have been included
  121. *
  122. * @type action (init)
  123. * @date 28/09/13
  124. * @since 5.0.0
  125. *
  126. * @param N/A
  127. * @return N/A
  128. */
  129. function init() {
  130. // bail early if a plugin called get_field early
  131. if( !did_action('plugins_loaded') ) return;
  132. // bail early if already init
  133. if( acf_get_setting('init') ) return;
  134. // only run once
  135. acf_update_setting('init', true);
  136. // vars
  137. $major = intval( acf_get_setting('version') );
  138. // redeclare dir
  139. // - allow another plugin to modify dir (maybe force SSL)
  140. acf_update_setting('dir', plugin_dir_url( __FILE__ ));
  141. // set text domain
  142. load_textdomain( 'acf', acf_get_path( 'lang/acf-' . get_locale() . '.mo' ) );
  143. // include wpml support
  144. if( defined('ICL_SITEPRESS_VERSION') ) {
  145. acf_include('core/wpml.php');
  146. }
  147. // field types
  148. acf_include('fields/text.php');
  149. acf_include('fields/textarea.php');
  150. acf_include('fields/number.php');
  151. acf_include('fields/email.php');
  152. acf_include('fields/url.php');
  153. acf_include('fields/password.php');
  154. acf_include('fields/wysiwyg.php');
  155. acf_include('fields/oembed.php');
  156. acf_include('fields/image.php');
  157. acf_include('fields/file.php');
  158. acf_include('fields/select.php');
  159. acf_include('fields/checkbox.php');
  160. acf_include('fields/radio.php');
  161. acf_include('fields/true_false.php');
  162. acf_include('fields/post_object.php');
  163. acf_include('fields/page_link.php');
  164. acf_include('fields/relationship.php');
  165. acf_include('fields/taxonomy.php');
  166. acf_include('fields/user.php');
  167. acf_include('fields/google-map.php');
  168. acf_include('fields/date_picker.php');
  169. acf_include('fields/color_picker.php');
  170. acf_include('fields/message.php');
  171. acf_include('fields/tab.php');
  172. // 3rd party field types
  173. do_action('acf/include_field_types', $major);
  174. // local fields
  175. do_action('acf/include_fields', $major);
  176. // action for 3rd party
  177. do_action('acf/init');
  178. }
  179. /*
  180. * register_post_types
  181. *
  182. * This function will register post types and statuses
  183. *
  184. * @type function
  185. * @date 22/10/2015
  186. * @since 5.3.2
  187. *
  188. * @param n/a
  189. * @return n/a
  190. */
  191. function register_post_types() {
  192. // vars
  193. $cap = acf_get_setting('capability');
  194. // register post type 'acf-field-group'
  195. register_post_type('acf-field-group', array(
  196. 'labels' => array(
  197. 'name' => __( 'Field Groups', 'acf' ),
  198. 'singular_name' => __( 'Field Group', 'acf' ),
  199. 'add_new' => __( 'Add New' , 'acf' ),
  200. 'add_new_item' => __( 'Add New Field Group' , 'acf' ),
  201. 'edit_item' => __( 'Edit Field Group' , 'acf' ),
  202. 'new_item' => __( 'New Field Group' , 'acf' ),
  203. 'view_item' => __( 'View Field Group', 'acf' ),
  204. 'search_items' => __( 'Search Field Groups', 'acf' ),
  205. 'not_found' => __( 'No Field Groups found', 'acf' ),
  206. 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ),
  207. ),
  208. 'public' => false,
  209. 'show_ui' => true,
  210. '_builtin' => false,
  211. 'capability_type' => 'post',
  212. 'capabilities' => array(
  213. 'edit_post' => $cap,
  214. 'delete_post' => $cap,
  215. 'edit_posts' => $cap,
  216. 'delete_posts' => $cap,
  217. ),
  218. 'hierarchical' => true,
  219. 'rewrite' => false,
  220. 'query_var' => false,
  221. 'supports' => array('title'),
  222. 'show_in_menu' => false,
  223. ));
  224. // register post type 'acf-field'
  225. register_post_type('acf-field', array(
  226. 'labels' => array(
  227. 'name' => __( 'Fields', 'acf' ),
  228. 'singular_name' => __( 'Field', 'acf' ),
  229. 'add_new' => __( 'Add New' , 'acf' ),
  230. 'add_new_item' => __( 'Add New Field' , 'acf' ),
  231. 'edit_item' => __( 'Edit Field' , 'acf' ),
  232. 'new_item' => __( 'New Field' , 'acf' ),
  233. 'view_item' => __( 'View Field', 'acf' ),
  234. 'search_items' => __( 'Search Fields', 'acf' ),
  235. 'not_found' => __( 'No Fields found', 'acf' ),
  236. 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ),
  237. ),
  238. 'public' => false,
  239. 'show_ui' => false,
  240. '_builtin' => false,
  241. 'capability_type' => 'post',
  242. 'capabilities' => array(
  243. 'edit_post' => $cap,
  244. 'delete_post' => $cap,
  245. 'edit_posts' => $cap,
  246. 'delete_posts' => $cap,
  247. ),
  248. 'hierarchical' => true,
  249. 'rewrite' => false,
  250. 'query_var' => false,
  251. 'supports' => array('title'),
  252. 'show_in_menu' => false,
  253. ));
  254. }
  255. /*
  256. * register_post_status
  257. *
  258. * This function will register custom post statuses
  259. *
  260. * @type function
  261. * @date 22/10/2015
  262. * @since 5.3.2
  263. *
  264. * @param $post_id (int)
  265. * @return $post_id (int)
  266. */
  267. function register_post_status() {
  268. // acf-disabled
  269. register_post_status('acf-disabled', array(
  270. 'label' => __( 'Disabled', 'acf' ),
  271. 'public' => true,
  272. 'exclude_from_search' => false,
  273. 'show_in_admin_all_list' => true,
  274. 'show_in_admin_status_list' => true,
  275. 'label_count' => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'acf' ),
  276. ));
  277. }
  278. /*
  279. * register_assets
  280. *
  281. * This function will register scripts and styles
  282. *
  283. * @type function
  284. * @date 22/10/2015
  285. * @since 5.3.2
  286. *
  287. * @param n/a
  288. * @return n/a
  289. */
  290. function register_assets() {
  291. // vars
  292. $version = acf_get_setting('version');
  293. $lang = get_locale();
  294. $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
  295. // scripts
  296. 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 );
  297. wp_register_script('acf-field-group', acf_get_dir("assets/js/acf-field-group{$min}.js"), array('acf-input'), $version );
  298. // styles
  299. wp_register_style('acf-global', acf_get_dir('assets/css/acf-global.css'), array(), $version );
  300. wp_register_style('acf-input', acf_get_dir('assets/css/acf-input.css'), array('acf-global'), $version );
  301. wp_register_style('acf-field-group', acf_get_dir('assets/css/acf-field-group.css'), array('acf-input'), $version );
  302. }
  303. /*
  304. * posts_where
  305. *
  306. * This function will add in some new parameters to the WP_Query args allowing fields to be found via key / name
  307. *
  308. * @type filter
  309. * @date 5/12/2013
  310. * @since 5.0.0
  311. *
  312. * @param $where (string)
  313. * @param $wp_query (object)
  314. * @return $where (string)
  315. */
  316. function posts_where( $where, $wp_query ) {
  317. // global
  318. global $wpdb;
  319. // acf_field_key
  320. if( $field_key = $wp_query->get('acf_field_key') ) {
  321. $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $field_key );
  322. }
  323. // acf_field_name
  324. if( $field_name = $wp_query->get('acf_field_name') ) {
  325. $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_excerpt = %s", $field_name );
  326. }
  327. // acf_group_key
  328. if( $group_key = $wp_query->get('acf_group_key') ) {
  329. $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $group_key );
  330. }
  331. // return
  332. return $where;
  333. }
  334. /*
  335. function posts_request( $thing ) {
  336. return $thing;
  337. }
  338. */
  339. }
  340. /*
  341. * acf
  342. *
  343. * The main function responsible for returning the one true acf Instance to functions everywhere.
  344. * Use this function like you would a global variable, except without needing to declare the global.
  345. *
  346. * Example: <?php $acf = acf(); ?>
  347. *
  348. * @type function
  349. * @date 4/09/13
  350. * @since 4.3.0
  351. *
  352. * @param N/A
  353. * @return (object)
  354. */
  355. function acf() {
  356. global $acf;
  357. if( !isset($acf) ) {
  358. $acf = new acf();
  359. $acf->initialize();
  360. }
  361. return $acf;
  362. }
  363. // initialize
  364. acf();
  365. endif; // class_exists check
  366. ?>