Changeset 2704186
- Timestamp:
- 04/04/2022 08:54:37 AM (4 years ago)
- Location:
- integromat-connector/trunk
- Files:
-
- 2 added
- 6 edited
-
class/RestResponse.php (modified) (3 diffs)
-
index.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
settings/Controller.php (modified) (4 diffs)
-
settings/ObjectTypes/PostMeta.php (modified) (8 diffs)
-
settings/ObjectTypes/custom_taxonomy.php (added)
-
settings/render.php (modified) (1 diff)
-
settings/template/custom_taxonomies.phtml (added)
Legend:
- Unmodified
- Added
- Removed
-
integromat-connector/trunk/class/RestResponse.php
r2476182 r2704186 3 3 namespace Integromat; 4 4 5 Class RestResponse5 class RestResponse 6 6 { 7 8 7 /** 9 8 * Includes users Custom fields into the REST API response payload … … 11 10 public static function includeCustomFields() 12 11 { 13 $mainObjectTypes = ['post', 'comment', 'user', 'term']; 14 $metaPostTypes = self::getMetafieldsWithPostTypes(); 12 $content_types = ['post', 'comment', 'user', 'term']; 13 $args = array( 14 'show_in_rest' => true 15 ); 16 $post_types = get_post_types($args); 15 17 16 foreach ($mainObjectTypes as $mainObjectType) { 17 $mainObjectTypeMetaItems = get_option('integromat_api_options_' . $mainObjectType); 18 foreach ($content_types as $object_type) { 18 19 19 if (!empty($mainObjectTypeMetaItems)) { 20 foreach ($mainObjectTypeMetaItems as $metaItemFull => $val) { 20 $options = get_option('integromat_api_options_' . $object_type); 21 21 22 $metaItem = str_replace(IWC_FIELD_PREFIX, '', $metaItemFull);22 foreach ($options as $option => $val) { 23 23 24 if ($mainObjectType == 'post') { 25 if (isset($metaPostTypes[$metaItem])) { 26 foreach ($metaPostTypes[$metaItem] as $postTypeOfTheMetafield) { 27 register_rest_field( 28 $postTypeOfTheMetafield, 29 $metaItem, 30 [ 31 'get_callback' => function ($object, $fieldName, $request) use ($mainObjectType) { 32 return get_metadata($mainObjectType, $object['id'], $fieldName, true); 33 }, 34 ] 35 ); 36 } 37 } 38 } else { 24 $meta_key = str_replace(IWC_FIELD_PREFIX, '', $option); 25 26 if ($object_type == 'post') { 27 foreach ($post_types as $post_type) { 39 28 register_rest_field( 40 $ mainObjectType,41 $meta Item,29 $post_type, 30 $meta_key, 42 31 [ 43 'get_callback' => function ($object, $fieldName, $request) use ($mainObjectType) { 44 return get_metadata($mainObjectType, $object['id'], $fieldName, true); 32 'get_callback' => function ($object, $fieldName) use ($object_type) { 33 $post_meta_keys = get_post_meta($object['id']); 34 // see if the field to register belongs to the post type 35 if (!isset($post_meta_keys[$fieldName])) { 36 return; 37 } 38 return get_metadata($object_type, $object['id'], $fieldName, true); 45 39 }, 46 40 ] 47 41 ); 48 42 } 43 } else { 44 register_rest_field( 45 $object_type, 46 $meta_key, 47 [ 48 'get_callback' => function ($object, $fieldName) use ($object_type) { 49 return get_metadata($object_type, $object['id'], $fieldName, true); 50 }, 51 ] 52 ); 49 53 } 50 54 } 51 55 } 52 56 } 53 54 55 /**56 * Gets all metafields with array of post types it is related to57 * @return array58 */59 private static function getMetafieldsWithPostTypes()60 {61 global $wpdb;62 $query = "63 SELECT64 p.post_type,65 m.meta_key66 FROM " . $wpdb->base_prefix . "postmeta m67 INNER JOIN " . $wpdb->base_prefix . "posts p ON p.ID = m.post_id68 ORDER BY69 post_type,70 meta_key71 ";72 $metaItems = $wpdb->get_results($query);73 74 $out = [];75 if (!empty($metaItems)) {76 foreach ($metaItems as $metaItem) {77 if (!isset($out[$metaItem->meta_key]) || !in_array($metaItem->post_type, $out[$metaItem->meta_key])) {78 $out[$metaItem->meta_key][] = $metaItem->post_type;79 }80 }81 }82 return $out;83 }84 85 57 86 58 /** … … 102 74 die(trim($out)); 103 75 } 104 105 76 } -
integromat-connector/trunk/index.php
r2552625 r2704186 3 3 /** 4 4 * @package Integromat_Connector 5 * @version 1. 4.35 * @version 1.5 6 6 */ 7 7 … … 11 11 Author: Integromat 12 12 Author URI: https://www.integromat.com/ 13 Version: 1. 4.313 Version: 1.5 14 14 */ 15 15 -
integromat-connector/trunk/readme.txt
r2552625 r2704186 3 3 Tags: rest, api, rest api, integromat, endpoint, endpoints, meta, data, meta_data 4 4 Requires at least: 5.0 5 Tested up to: 5.75 Tested up to: 5.9.2 6 6 Requires PHP: 5.6 7 Stable tag: 1. 4.37 Stable tag: 1.5 8 8 License: GPLv2 or later 9 9 … … 23 23 24 24 == Changelog == 25 26 = 1.5 = 27 * Add custom taxonomies 28 * Fix plugin slow down 25 29 26 30 = 1.4 = -
integromat-connector/trunk/settings/Controller.php
r2518111 r2704186 3 3 namespace Integromat; 4 4 5 Class Controller5 class Controller 6 6 { 7 8 7 public function init() 9 8 { … … 14 13 global $pagenow; 15 14 if ($pagenow == 'options.php' || $pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == IWC_MENUITEM_IDENTIFIER) { 16 17 15 // Posts 18 16 require_once __DIR__ . '/ObjectTypes/PostMeta.php'; … … 35 33 $TermsMeta->init(); 36 34 } 35 36 if ($pagenow == 'options.php' || $pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'integromat_custom_toxonomies') { 37 // Taxonomies 38 require_once __DIR__ . '/ObjectTypes/custom_taxonomy.php'; 39 add_taxonomies(); 40 } 37 41 }); 38 42 … … 46 50 } 47 51 52 add_filter( 53 'register_taxonomy_args', 54 function ($args, $taxonomy_name) { 55 $o = get_option('integromat_api_options_taxonomy'); 56 // option doesn't exist, run with default params 57 $not_exists = is_bool($o) && $o == false; 58 // otherwise run with settings 59 if ($not_exists == false) { 60 $enabled_taxonomies = empty($o) ? [] : array_keys($o); 61 if (in_array($taxonomy_name, $enabled_taxonomies)) { 62 $args['show_in_rest'] = true; 63 } else { 64 $args['show_in_rest'] = false; 65 } 66 } 67 return $args; 68 }, 69 10, 70 2 71 ); -
integromat-connector/trunk/settings/ObjectTypes/PostMeta.php
r2476182 r2704186 3 3 namespace Integromat; 4 4 5 Class PostsMeta extends MetaObject { 6 7 5 class PostsMeta extends MetaObject 6 { 8 7 private $metaItemKeys = []; 9 8 … … 12 11 private $universalMetas = []; 13 12 14 15 13 public function init() 16 14 { 17 global $wpdb;18 15 $this->metaItemKeys = $this->getPostMetaItems(); 19 16 register_setting('integromat_api_post', 'integromat_api_options_post'); … … 22 19 'integromat_api_section_posts', 23 20 __('', 'integromat_api_post'), // h1 title as the first argument 24 function () {25 ?>26 <p><?php esc_html_e('Select posts metadata to include in REST API response', 'integromat_api_post'); ?></p>27 <p><a class="uncheck_all" data-status="0">Un/check all</a></p>28 <?php21 function () { 22 ?> 23 <p><?php esc_html_e('Select posts metadata to include in REST API response', 'integromat_api_post'); ?></p> 24 <p><a class="uncheck_all" data-status="0">Un/check all</a></p> 25 <?php 29 26 }, 30 27 'integromat_api_post' 31 28 ); 32 33 29 34 30 if ($this->useUniversalMetas) { … … 58 54 IWC_FIELD_PREFIX . '_post_sub_section_' . $objectType, 59 55 "<h3>$objectType</h3>", // Sub-section label 60 function ($args) use ($metaItem, $objectType, $lastObjectType) {56 function ($args) use ($metaItem, $objectType, $lastObjectType) { 61 57 echo ''; 62 58 }, … … 78 74 IWC_FIELD_PREFIX . $metaItem, 79 75 __($metaItem, 'integromat_api_post'), 80 function ($args) use ($metaItem, $objectType, $lastObjectType) {76 function ($args) use ($metaItem, $objectType, $lastObjectType) { 81 77 $options = get_option('integromat_api_options_post'); 82 ?>83 <input type="checkbox" name="integromat_api_options_post[<?php echo esc_attr($args['label_for']); ?>]" value="1" <?php if (isset($options[$args['label_for']]) && $options[$args['label_for']] == 1) echo 'checked' ?> id="<?php echo IWC_FIELD_PREFIX . $metaItem ?>">84 <?php78 ?> 79 <input type="checkbox" name="integromat_api_options_post[<?php echo esc_attr($args['label_for']); ?>]" value="1" <?php if (isset($options[$args['label_for']]) && $options[$args['label_for']] == 1) echo 'checked' ?> id="<?php echo IWC_FIELD_PREFIX . $metaItem ?>"> 80 <?php 85 81 }, 86 82 'integromat_api_post', … … 94 90 $lastObjectType = $objectType; 95 91 } 96 97 92 98 93 if ($this->useUniversalMetas) { … … 118 113 IWC_FIELD_PREFIX . $metaItem, 119 114 __($metaItem, 'integromat_api_post'), 120 function ($args) use ($metaItem) {115 function ($args) use ($metaItem) { 121 116 $options = get_option('integromat_api_options_post'); 122 ?>123 <input type="checkbox" name="integromat_api_options_post[<?php echo esc_attr($args['label_for']); ?>]" value="1" <?php if (isset($options[$args['label_for']]) && $options[$args['label_for']] == 1) echo 'checked' ?> id="<?php echo IWC_FIELD_PREFIX . $metaItem ?>">124 <?php117 ?> 118 <input type="checkbox" name="integromat_api_options_post[<?php echo esc_attr($args['label_for']); ?>]" value="1" <?php if (isset($options[$args['label_for']]) && $options[$args['label_for']] == 1) echo 'checked' ?> id="<?php echo IWC_FIELD_PREFIX . $metaItem ?>"> 119 <?php 125 120 }, 126 121 'integromat_api_post', … … 146 141 $query = " 147 142 SELECT 148 p.post_type, 149 m.meta_key 150 FROM ". $wpdb->base_prefix ."postmeta m 151 INNER JOIN ". $wpdb->base_prefix ."posts p ON p.ID = m.post_id 152 ORDER BY 153 post_type, 154 meta_key 143 DISTINCT(m.meta_key), 144 p.post_type 145 FROM " . $wpdb->base_prefix . "postmeta m 146 INNER JOIN " . $wpdb->base_prefix . "posts p ON p.ID = m.post_id 155 147 "; 156 148 $meta_keys = $wpdb->get_results($query); 157 149 return $meta_keys; 158 150 } 159 160 151 } 161 -
integromat-connector/trunk/settings/render.php
r2522576 r2704186 36 36 } 37 37 ); 38 39 add_submenu_page( 40 'integromat', 41 'Custom Taxonomies', 42 'Custom Taxonomies', 43 'manage_options', 44 'integromat_custom_toxonomies', 45 function () { 46 if (!current_user_can('manage_options')) { 47 return; 48 } 49 settings_errors('integromat_api_messages'); 50 include_once __DIR__ . '/template/custom_taxonomies.phtml'; 51 } 52 ); 38 53 }); 39
Note: See TracChangeset
for help on using the changeset viewer.