Нема описа

class-acf-field-relationship.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. <?php
  2. if ( ! class_exists( 'acf_field_relationship' ) ) :
  3. class acf_field_relationship extends acf_field {
  4. /*
  5. * __construct
  6. *
  7. * This function will setup the field type data
  8. *
  9. * @type function
  10. * @date 5/03/2014
  11. * @since 5.0.0
  12. *
  13. * @param n/a
  14. * @return n/a
  15. */
  16. function initialize() {
  17. // vars
  18. $this->name = 'relationship';
  19. $this->label = __( 'Relationship', 'acf' );
  20. $this->category = 'relational';
  21. $this->defaults = array(
  22. 'post_type' => array(),
  23. 'taxonomy' => array(),
  24. 'min' => 0,
  25. 'max' => 0,
  26. 'filters' => array( 'search', 'post_type', 'taxonomy' ),
  27. 'elements' => array(),
  28. 'return_format' => 'object',
  29. );
  30. // extra
  31. add_action( 'wp_ajax_acf/fields/relationship/query', array( $this, 'ajax_query' ) );
  32. add_action( 'wp_ajax_nopriv_acf/fields/relationship/query', array( $this, 'ajax_query' ) );
  33. }
  34. /*
  35. * input_admin_enqueue_scripts
  36. *
  37. * description
  38. *
  39. * @type function
  40. * @date 16/12/2015
  41. * @since 5.3.2
  42. *
  43. * @param $post_id (int)
  44. * @return $post_id (int)
  45. */
  46. function input_admin_enqueue_scripts() {
  47. // localize
  48. acf_localize_text(
  49. array(
  50. // 'Minimum values reached ( {min} values )' => __('Minimum values reached ( {min} values )', 'acf'),
  51. 'Maximum values reached ( {max} values )' => __( 'Maximum values reached ( {max} values )', 'acf' ),
  52. 'Loading' => __( 'Loading', 'acf' ),
  53. 'No matches found' => __( 'No matches found', 'acf' ),
  54. )
  55. );
  56. }
  57. /*
  58. * ajax_query
  59. *
  60. * description
  61. *
  62. * @type function
  63. * @date 24/10/13
  64. * @since 5.0.0
  65. *
  66. * @param $post_id (int)
  67. * @return $post_id (int)
  68. */
  69. function ajax_query() {
  70. // validate
  71. if ( ! acf_verify_ajax() ) {
  72. die();
  73. }
  74. // get choices
  75. $response = $this->get_ajax_query( $_POST );
  76. // return
  77. acf_send_ajax_results( $response );
  78. }
  79. /*
  80. * get_ajax_query
  81. *
  82. * This function will return an array of data formatted for use in a select2 AJAX response
  83. *
  84. * @type function
  85. * @date 15/10/2014
  86. * @since 5.0.9
  87. *
  88. * @param $options (array)
  89. * @return (array)
  90. */
  91. function get_ajax_query( $options = array() ) {
  92. // defaults
  93. $options = wp_parse_args(
  94. $options,
  95. array(
  96. 'post_id' => 0,
  97. 's' => '',
  98. 'field_key' => '',
  99. 'paged' => 1,
  100. 'post_type' => '',
  101. 'taxonomy' => '',
  102. )
  103. );
  104. // load field
  105. $field = acf_get_field( $options['field_key'] );
  106. if ( ! $field ) {
  107. return false;
  108. }
  109. // vars
  110. $results = array();
  111. $args = array();
  112. $s = false;
  113. $is_search = false;
  114. // paged
  115. $args['posts_per_page'] = 20;
  116. $args['paged'] = intval( $options['paged'] );
  117. // search
  118. if ( $options['s'] !== '' ) {
  119. // strip slashes (search may be integer)
  120. $s = wp_unslash( strval( $options['s'] ) );
  121. // update vars
  122. $args['s'] = $s;
  123. $is_search = true;
  124. }
  125. // post_type
  126. if ( ! empty( $options['post_type'] ) ) {
  127. $args['post_type'] = acf_get_array( $options['post_type'] );
  128. } elseif ( ! empty( $field['post_type'] ) ) {
  129. $args['post_type'] = acf_get_array( $field['post_type'] );
  130. } else {
  131. $args['post_type'] = acf_get_post_types();
  132. }
  133. // taxonomy
  134. if ( ! empty( $options['taxonomy'] ) ) {
  135. // vars
  136. $term = acf_decode_taxonomy_term( $options['taxonomy'] );
  137. // tax query
  138. $args['tax_query'] = array();
  139. // append
  140. $args['tax_query'][] = array(
  141. 'taxonomy' => $term['taxonomy'],
  142. 'field' => 'slug',
  143. 'terms' => $term['term'],
  144. );
  145. } elseif ( ! empty( $field['taxonomy'] ) ) {
  146. // vars
  147. $terms = acf_decode_taxonomy_terms( $field['taxonomy'] );
  148. // append to $args
  149. $args['tax_query'] = array(
  150. 'relation' => 'OR',
  151. );
  152. // now create the tax queries
  153. foreach ( $terms as $k => $v ) {
  154. $args['tax_query'][] = array(
  155. 'taxonomy' => $k,
  156. 'field' => 'slug',
  157. 'terms' => $v,
  158. );
  159. }
  160. }
  161. // filters
  162. $args = apply_filters( 'acf/fields/relationship/query', $args, $field, $options['post_id'] );
  163. $args = apply_filters( 'acf/fields/relationship/query/name=' . $field['name'], $args, $field, $options['post_id'] );
  164. $args = apply_filters( 'acf/fields/relationship/query/key=' . $field['key'], $args, $field, $options['post_id'] );
  165. // get posts grouped by post type
  166. $groups = acf_get_grouped_posts( $args );
  167. // bail early if no posts
  168. if ( empty( $groups ) ) {
  169. return false;
  170. }
  171. // loop
  172. foreach ( array_keys( $groups ) as $group_title ) {
  173. // vars
  174. $posts = acf_extract_var( $groups, $group_title );
  175. // data
  176. $data = array(
  177. 'text' => $group_title,
  178. 'children' => array(),
  179. );
  180. // convert post objects to post titles
  181. foreach ( array_keys( $posts ) as $post_id ) {
  182. $posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] );
  183. }
  184. // order posts by search
  185. if ( $is_search && empty( $args['orderby'] ) && isset( $args['s'] ) ) {
  186. $posts = acf_order_by_search( $posts, $args['s'] );
  187. }
  188. // append to $data
  189. foreach ( array_keys( $posts ) as $post_id ) {
  190. $data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ] );
  191. }
  192. // append to $results
  193. $results[] = $data;
  194. }
  195. // add as optgroup or results
  196. if ( count( $args['post_type'] ) == 1 ) {
  197. $results = $results[0]['children'];
  198. }
  199. // vars
  200. $response = array(
  201. 'results' => $results,
  202. 'limit' => $args['posts_per_page'],
  203. );
  204. // return
  205. return $response;
  206. }
  207. /*
  208. * get_post_result
  209. *
  210. * This function will return an array containing id, text and maybe description data
  211. *
  212. * @type function
  213. * @date 7/07/2016
  214. * @since 5.4.0
  215. *
  216. * @param $id (mixed)
  217. * @param $text (string)
  218. * @return (array)
  219. */
  220. function get_post_result( $id, $text ) {
  221. // vars
  222. $result = array(
  223. 'id' => $id,
  224. 'text' => $text,
  225. );
  226. // return
  227. return $result;
  228. }
  229. /*
  230. * get_post_title
  231. *
  232. * This function returns the HTML for a result
  233. *
  234. * @type function
  235. * @date 1/11/2013
  236. * @since 5.0.0
  237. *
  238. * @param $post (object)
  239. * @param $field (array)
  240. * @param $post_id (int) the post_id to which this value is saved to
  241. * @return (string)
  242. */
  243. function get_post_title( $post, $field, $post_id = 0, $is_search = 0 ) {
  244. // get post_id
  245. if ( ! $post_id ) {
  246. $post_id = acf_get_form_data( 'post_id' );
  247. }
  248. // vars
  249. $title = acf_get_post_title( $post, $is_search );
  250. // featured_image
  251. if ( acf_in_array( 'featured_image', $field['elements'] ) ) {
  252. // vars
  253. $class = 'thumbnail';
  254. $thumbnail = acf_get_post_thumbnail( $post->ID, array( 17, 17 ) );
  255. // icon
  256. if ( $thumbnail['type'] == 'icon' ) {
  257. $class .= ' -' . $thumbnail['type'];
  258. }
  259. // append
  260. $title = '<div class="' . $class . '">' . $thumbnail['html'] . '</div>' . $title;
  261. }
  262. // filters
  263. $title = apply_filters( 'acf/fields/relationship/result', $title, $post, $field, $post_id );
  264. $title = apply_filters( 'acf/fields/relationship/result/name=' . $field['_name'], $title, $post, $field, $post_id );
  265. $title = apply_filters( 'acf/fields/relationship/result/key=' . $field['key'], $title, $post, $field, $post_id );
  266. // return
  267. return $title;
  268. }
  269. /*
  270. * render_field()
  271. *
  272. * Create the HTML interface for your field
  273. *
  274. * @param $field - an array holding all the field's data
  275. *
  276. * @type action
  277. * @since 3.6
  278. * @date 23/01/13
  279. */
  280. function render_field( $field ) {
  281. // vars
  282. $post_type = acf_get_array( $field['post_type'] );
  283. $taxonomy = acf_get_array( $field['taxonomy'] );
  284. $filters = acf_get_array( $field['filters'] );
  285. // filters
  286. $filter_count = count( $filters );
  287. $filter_post_type_choices = array();
  288. $filter_taxonomy_choices = array();
  289. // post_type filter
  290. if ( in_array( 'post_type', $filters ) ) {
  291. $filter_post_type_choices = array(
  292. '' => __( 'Select post type', 'acf' ),
  293. ) + acf_get_pretty_post_types( $post_type );
  294. }
  295. // taxonomy filter
  296. if ( in_array( 'taxonomy', $filters ) ) {
  297. $term_choices = array();
  298. $filter_taxonomy_choices = array(
  299. '' => __( 'Select taxonomy', 'acf' ),
  300. );
  301. // check for specific taxonomy setting
  302. if ( $taxonomy ) {
  303. $terms = acf_get_encoded_terms( $taxonomy );
  304. $term_choices = acf_get_choices_from_terms( $terms, 'slug' );
  305. // if no terms were specified, find all terms
  306. } else {
  307. // restrict taxonomies by the post_type selected
  308. $term_args = array();
  309. if ( $post_type ) {
  310. $term_args['taxonomy'] = acf_get_taxonomies(
  311. array(
  312. 'post_type' => $post_type,
  313. )
  314. );
  315. }
  316. // get terms
  317. $terms = acf_get_grouped_terms( $term_args );
  318. $term_choices = acf_get_choices_from_grouped_terms( $terms, 'slug' );
  319. }
  320. // append term choices
  321. $filter_taxonomy_choices = $filter_taxonomy_choices + $term_choices;
  322. }
  323. // div attributes
  324. $atts = array(
  325. 'id' => $field['id'],
  326. 'class' => "acf-relationship {$field['class']}",
  327. 'data-min' => $field['min'],
  328. 'data-max' => $field['max'],
  329. 'data-s' => '',
  330. 'data-paged' => 1,
  331. 'data-post_type' => '',
  332. 'data-taxonomy' => '',
  333. );
  334. ?>
  335. <div <?php acf_esc_attr_e( $atts ); ?>>
  336. <?php
  337. acf_hidden_input(
  338. array(
  339. 'name' => $field['name'],
  340. 'value' => '',
  341. )
  342. );
  343. ?>
  344. <?php
  345. /* filters */
  346. if ( $filter_count ) :
  347. ?>
  348. <div class="filters -f<?php echo esc_attr( $filter_count ); ?>">
  349. <?php
  350. /* search */
  351. if ( in_array( 'search', $filters ) ) :
  352. ?>
  353. <div class="filter -search">
  354. <?php
  355. acf_text_input(
  356. array(
  357. 'placeholder' => __( 'Search...', 'acf' ),
  358. 'data-filter' => 's',
  359. )
  360. );
  361. ?>
  362. </div>
  363. <?php
  364. endif;
  365. /* post_type */
  366. if ( in_array( 'post_type', $filters ) ) :
  367. ?>
  368. <div class="filter -post_type">
  369. <?php
  370. acf_select_input(
  371. array(
  372. 'choices' => $filter_post_type_choices,
  373. 'data-filter' => 'post_type',
  374. )
  375. );
  376. ?>
  377. </div>
  378. <?php
  379. endif;
  380. /* post_type */
  381. if ( in_array( 'taxonomy', $filters ) ) :
  382. ?>
  383. <div class="filter -taxonomy">
  384. <?php
  385. acf_select_input(
  386. array(
  387. 'choices' => $filter_taxonomy_choices,
  388. 'data-filter' => 'taxonomy',
  389. )
  390. );
  391. ?>
  392. </div>
  393. <?php endif; ?>
  394. </div>
  395. <?php endif; ?>
  396. <div class="selection">
  397. <div class="choices">
  398. <ul class="acf-bl list choices-list"></ul>
  399. </div>
  400. <div class="values">
  401. <ul class="acf-bl list values-list">
  402. <?php
  403. if ( ! empty( $field['value'] ) ) :
  404. // get posts
  405. $posts = acf_get_posts(
  406. array(
  407. 'post__in' => $field['value'],
  408. 'post_type' => $field['post_type'],
  409. )
  410. );
  411. // loop
  412. foreach ( $posts as $post ) :
  413. ?>
  414. <li>
  415. <?php
  416. acf_hidden_input(
  417. array(
  418. 'name' => $field['name'] . '[]',
  419. 'value' => $post->ID,
  420. )
  421. );
  422. ?>
  423. <span data-id="<?php echo esc_attr( $post->ID ); ?>" class="acf-rel-item">
  424. <?php echo acf_esc_html( $this->get_post_title( $post, $field ) ); ?>
  425. <a href="#" class="acf-icon -minus small dark" data-name="remove_item"></a>
  426. </span>
  427. </li>
  428. <?php endforeach; ?>
  429. <?php endif; ?>
  430. </ul>
  431. </div>
  432. </div>
  433. </div>
  434. <?php
  435. }
  436. /*
  437. * render_field_settings()
  438. *
  439. * Create extra options for your field. This is rendered when editing a field.
  440. * The value of $field['name'] can be used (like bellow) to save extra data to the $field
  441. *
  442. * @type action
  443. * @since 3.6
  444. * @date 23/01/13
  445. *
  446. * @param $field - an array holding all the field's data
  447. */
  448. function render_field_settings( $field ) {
  449. // vars
  450. $field['min'] = empty( $field['min'] ) ? '' : $field['min'];
  451. $field['max'] = empty( $field['max'] ) ? '' : $field['max'];
  452. // post_type
  453. acf_render_field_setting(
  454. $field,
  455. array(
  456. 'label' => __( 'Filter by Post Type', 'acf' ),
  457. 'instructions' => '',
  458. 'type' => 'select',
  459. 'name' => 'post_type',
  460. 'choices' => acf_get_pretty_post_types(),
  461. 'multiple' => 1,
  462. 'ui' => 1,
  463. 'allow_null' => 1,
  464. 'placeholder' => __( 'All post types', 'acf' ),
  465. )
  466. );
  467. // taxonomy
  468. acf_render_field_setting(
  469. $field,
  470. array(
  471. 'label' => __( 'Filter by Taxonomy', 'acf' ),
  472. 'instructions' => '',
  473. 'type' => 'select',
  474. 'name' => 'taxonomy',
  475. 'choices' => acf_get_taxonomy_terms(),
  476. 'multiple' => 1,
  477. 'ui' => 1,
  478. 'allow_null' => 1,
  479. 'placeholder' => __( 'All taxonomies', 'acf' ),
  480. )
  481. );
  482. // filters
  483. acf_render_field_setting(
  484. $field,
  485. array(
  486. 'label' => __( 'Filters', 'acf' ),
  487. 'instructions' => '',
  488. 'type' => 'checkbox',
  489. 'name' => 'filters',
  490. 'choices' => array(
  491. 'search' => __( 'Search', 'acf' ),
  492. 'post_type' => __( 'Post Type', 'acf' ),
  493. 'taxonomy' => __( 'Taxonomy', 'acf' ),
  494. ),
  495. )
  496. );
  497. // filters
  498. acf_render_field_setting(
  499. $field,
  500. array(
  501. 'label' => __( 'Elements', 'acf' ),
  502. 'instructions' => __( 'Selected elements will be displayed in each result', 'acf' ),
  503. 'type' => 'checkbox',
  504. 'name' => 'elements',
  505. 'choices' => array(
  506. 'featured_image' => __( 'Featured Image', 'acf' ),
  507. ),
  508. )
  509. );
  510. // min
  511. acf_render_field_setting(
  512. $field,
  513. array(
  514. 'label' => __( 'Minimum posts', 'acf' ),
  515. 'instructions' => '',
  516. 'type' => 'number',
  517. 'name' => 'min',
  518. )
  519. );
  520. // max
  521. acf_render_field_setting(
  522. $field,
  523. array(
  524. 'label' => __( 'Maximum posts', 'acf' ),
  525. 'instructions' => '',
  526. 'type' => 'number',
  527. 'name' => 'max',
  528. )
  529. );
  530. // return_format
  531. acf_render_field_setting(
  532. $field,
  533. array(
  534. 'label' => __( 'Return Format', 'acf' ),
  535. 'instructions' => '',
  536. 'type' => 'radio',
  537. 'name' => 'return_format',
  538. 'choices' => array(
  539. 'object' => __( 'Post Object', 'acf' ),
  540. 'id' => __( 'Post ID', 'acf' ),
  541. ),
  542. 'layout' => 'horizontal',
  543. )
  544. );
  545. }
  546. /*
  547. * format_value()
  548. *
  549. * This filter is applied to the $value after it is loaded from the db and before it is returned to the template
  550. *
  551. * @type filter
  552. * @since 3.6
  553. * @date 23/01/13
  554. *
  555. * @param $value (mixed) the value which was loaded from the database
  556. * @param $post_id (mixed) the $post_id from which the value was loaded
  557. * @param $field (array) the field array holding all the field options
  558. *
  559. * @return $value (mixed) the modified value
  560. */
  561. function format_value( $value, $post_id, $field ) {
  562. // bail early if no value
  563. if ( empty( $value ) ) {
  564. return $value;
  565. }
  566. // force value to array
  567. $value = acf_get_array( $value );
  568. // convert to int
  569. $value = array_map( 'intval', $value );
  570. // load posts if needed
  571. if ( $field['return_format'] == 'object' ) {
  572. // get posts
  573. $value = acf_get_posts(
  574. array(
  575. 'post__in' => $value,
  576. 'post_type' => $field['post_type'],
  577. )
  578. );
  579. }
  580. // return
  581. return $value;
  582. }
  583. /*
  584. * validate_value
  585. *
  586. * description
  587. *
  588. * @type function
  589. * @date 11/02/2014
  590. * @since 5.0.0
  591. *
  592. * @param $post_id (int)
  593. * @return $post_id (int)
  594. */
  595. function validate_value( $valid, $value, $field, $input ) {
  596. // default
  597. if ( empty( $value ) || ! is_array( $value ) ) {
  598. $value = array();
  599. }
  600. // min
  601. if ( count( $value ) < $field['min'] ) {
  602. $valid = _n( '%1$s requires at least %2$s selection', '%1$s requires at least %2$s selections', $field['min'], 'acf' );
  603. $valid = sprintf( $valid, $field['label'], $field['min'] );
  604. }
  605. // return
  606. return $valid;
  607. }
  608. /**
  609. * update_value()
  610. *
  611. * This filter is applied to the $value before it is updated in the db
  612. *
  613. * @type filter
  614. * @since 3.6
  615. * @date 23/01/13
  616. *
  617. * @param $value - the value which will be saved in the database
  618. * @param $post_id - the $post_id of which the value will be saved
  619. * @param $field - the field array holding all the field options
  620. *
  621. * @return $value - the modified value
  622. */
  623. function update_value( $value, $post_id, $field ) {
  624. // Bail early if no value.
  625. if ( empty( $value ) ) {
  626. return $value;
  627. }
  628. // Format array of values.
  629. // - ensure each value is an id.
  630. // - Parse each id as string for SQL LIKE queries.
  631. if ( acf_is_sequential_array( $value ) ) {
  632. $value = array_map( 'acf_idval', $value );
  633. $value = array_map( 'strval', $value );
  634. // Parse single value for id.
  635. } else {
  636. $value = acf_idval( $value );
  637. }
  638. // Return value.
  639. return $value;
  640. }
  641. /**
  642. * Validates relationship fields updated via the REST API.
  643. *
  644. * @param bool $valid
  645. * @param int $value
  646. * @param array $field
  647. *
  648. * @return bool|WP_Error
  649. */
  650. public function validate_rest_value( $valid, $value, $field ) {
  651. return acf_get_field_type( 'post_object' )->validate_rest_value( $valid, $value, $field );
  652. }
  653. /**
  654. * Return the schema array for the REST API.
  655. *
  656. * @param array $field
  657. * @return array
  658. */
  659. public function get_rest_schema( array $field ) {
  660. $schema = array(
  661. 'type' => array( 'integer', 'array', 'null' ),
  662. 'required' => ! empty( $field['required'] ),
  663. 'items' => array(
  664. 'type' => 'integer',
  665. ),
  666. );
  667. if ( empty( $field['allow_null'] ) ) {
  668. $schema['minItems'] = 1;
  669. }
  670. if ( ! empty( $field['min'] ) ) {
  671. $schema['minItems'] = (int) $field['min'];
  672. }
  673. if ( ! empty( $field['max'] ) ) {
  674. $schema['maxItems'] = (int) $field['max'];
  675. }
  676. return $schema;
  677. }
  678. /**
  679. * @see \acf_field::get_rest_links()
  680. * @param mixed $value The raw (unformatted) field value.
  681. * @param int|string $post_id
  682. * @param array $field
  683. * @return array
  684. */
  685. public function get_rest_links( $value, $post_id, array $field ) {
  686. $links = array();
  687. if ( empty( $value ) ) {
  688. return $links;
  689. }
  690. foreach ( (array) $value as $object_id ) {
  691. if ( ! $post_type = get_post_type( $object_id ) or ! $post_type = get_post_type_object( $post_type ) ) {
  692. continue;
  693. }
  694. $rest_base = acf_get_object_type_rest_base( $post_type );
  695. $links[] = array(
  696. 'rel' => $post_type->name === 'attachment' ? 'acf:attachment' : 'acf:post',
  697. 'href' => rest_url( sprintf( '/wp/v2/%s/%s', $rest_base, $object_id ) ),
  698. 'embeddable' => true,
  699. );
  700. }
  701. return $links;
  702. }
  703. /**
  704. * Apply basic formatting to prepare the value for default REST output.
  705. *
  706. * @param mixed $value
  707. * @param string|int $post_id
  708. * @param array $field
  709. * @return mixed
  710. */
  711. public function format_value_for_rest( $value, $post_id, array $field ) {
  712. return acf_format_numerics( $value );
  713. }
  714. }
  715. // initialize
  716. acf_register_field_type( 'acf_field_relationship' );
  717. endif; // class_exists check
  718. ?>