PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

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