Changeset 2917815
- Timestamp:
- 05/26/2023 12:56:39 PM (3 years ago)
- Location:
- custom-post-types
- Files:
-
- 41 added
- 3 edited
-
tags/4.0.1 (added)
-
tags/4.0.1/assets (added)
-
tags/4.0.1/assets/css (added)
-
tags/4.0.1/assets/css/backend.css (added)
-
tags/4.0.1/assets/icon-256x256.png (added)
-
tags/4.0.1/assets/icon.svg (added)
-
tags/4.0.1/assets/js (added)
-
tags/4.0.1/assets/js/backend.js (added)
-
tags/4.0.1/custom-post-types.php (added)
-
tags/4.0.1/includes (added)
-
tags/4.0.1/includes/Component.php (added)
-
tags/4.0.1/includes/Fields.php (added)
-
tags/4.0.1/includes/Notices.php (added)
-
tags/4.0.1/includes/Pages.php (added)
-
tags/4.0.1/includes/PostTypes.php (added)
-
tags/4.0.1/includes/Taxonomies.php (added)
-
tags/4.0.1/includes/Templates.php (added)
-
tags/4.0.1/includes/index.php (added)
-
tags/4.0.1/index.php (added)
-
tags/4.0.1/parts (added)
-
tags/4.0.1/parts/fields (added)
-
tags/4.0.1/parts/fields/checkbox.php (added)
-
tags/4.0.1/parts/fields/color.php (added)
-
tags/4.0.1/parts/fields/date.php (added)
-
tags/4.0.1/parts/fields/email.php (added)
-
tags/4.0.1/parts/fields/file.php (added)
-
tags/4.0.1/parts/fields/html.php (added)
-
tags/4.0.1/parts/fields/number.php (added)
-
tags/4.0.1/parts/fields/post_rel.php (added)
-
tags/4.0.1/parts/fields/radio.php (added)
-
tags/4.0.1/parts/fields/repeater.php (added)
-
tags/4.0.1/parts/fields/select.php (added)
-
tags/4.0.1/parts/fields/tax_rel.php (added)
-
tags/4.0.1/parts/fields/tel.php (added)
-
tags/4.0.1/parts/fields/text.php (added)
-
tags/4.0.1/parts/fields/textarea.php (added)
-
tags/4.0.1/parts/fields/time.php (added)
-
tags/4.0.1/parts/fields/tinymce.php (added)
-
tags/4.0.1/parts/pages (added)
-
tags/4.0.1/parts/pages/tools.php (added)
-
tags/4.0.1/readme.txt (added)
-
trunk/custom-post-types.php (modified) (9 diffs)
-
trunk/includes/Component.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
custom-post-types/trunk/custom-post-types.php
r2915886 r2917815 8 8 Text Domain: custom-post-types 9 9 Domain Path: /languages/ 10 Version: 4.0. 010 Version: 4.0.1 11 11 */ 12 12 … … 661 661 ]; 662 662 663 if (time() < 1688169599){ // 30-06-2023 23:59:59663 if (time() < 1688169599) { // 30-06-2023 23:59:59 664 664 $welcomeNotice['message'] = $welcomeNotice['message'] . '<br><br>' . sprintf('Use the coupon <strong><u>%s</u></strong> and get the PRO version with special discount until %s.', 'WELCOME-CPT-4', '30/06/2023'); 665 665 } … … 740 740 if (!is_admin() && !$this->isRest()) { 741 741 global $post; 742 add_shortcode('custom-field', function ($atts) { // 2.x Compatibility743 $a = shortcode_atts([744 'id' => false,745 ], $atts);746 return do_shortcode(sprintf('[cpt-field key="%s"]', $a['id']));747 });748 742 add_shortcode('cpt-field', function ($atts) { 749 743 $a = shortcode_atts([ … … 759 753 } 760 754 return $this->getPostField($a['key'], $a['post-id']); 761 });762 add_shortcode('custom-tax', function ($atts) { // 2.x Compatibility763 $a = shortcode_atts([764 'id' => false,765 ], $atts);766 return do_shortcode(sprintf('[cpt-terms key="%s"]', $a['id']));767 755 }); 768 756 add_shortcode('cpt-terms', function ($atts) use ($post) { … … 785 773 } 786 774 return implode(', ', $terms); 775 }); 776 add_shortcode('cpt-term-field', function ($atts) { 777 $a = shortcode_atts([ 778 'key' => false, 779 'term-id' => false 780 ], $atts); 781 $errors = false; 782 if (!$a['key']) { 783 $errors[] = __('Missing field "key".', 'custom-post-types'); 784 } 785 if (!$a['term-id']) { 786 $errors[] = __('Missing field "term-id".', 'custom-post-types'); 787 } 788 if ($errors) { 789 return current_user_can('edit_posts') ? "<pre>" . implode("</pre><pre>", $errors) . "</pre>" : ''; 790 } 791 return $this->getTermField($a['key'], $a['term-id']); 792 }); 793 add_shortcode('cpt-option-field', function ($atts) { 794 $a = shortcode_atts([ 795 'key' => false, 796 'option-id' => false 797 ], $atts); 798 $errors = false; 799 if (!$a['key']) { 800 $errors[] = __('Missing field "key".', 'custom-post-types'); 801 } 802 if (!$a['option-id']) { 803 $errors[] = __('Missing field "option-id".', 'custom-post-types'); 804 } 805 if ($errors) { 806 return current_user_can('edit_posts') ? "<pre>" . implode("</pre><pre>", $errors) . "</pre>" : ''; 807 } 808 return $this->getOptionField($a['key'], $a['option-id']); 787 809 }); 788 810 } … … 837 859 update_option($this->getOptionName('version'), $currentVersion); 838 860 update_option($this->getOptionName('installation_time'), time()); 839 } 840 841 private function pluginActions(){ 842 register_activation_hook( __FILE__, function(){ 861 862 $request_url = add_query_arg( 863 ['id' => 92, 'action' => 'updated', 'domain' => md5(get_home_url())], 864 'https://totalpress.org/wp-json/totalpress/v1/plugin-growth' 865 ); 866 wp_remote_get($request_url); 867 } 868 869 private function pluginActions() 870 { 871 register_activation_hook(__FILE__, function () { 843 872 $request_url = add_query_arg( 844 873 ['id' => 92, 'action' => 'activate', 'domain' => md5(get_home_url())], … … 847 876 wp_remote_get($request_url); 848 877 }); 849 register_deactivation_hook( __FILE__, function(){878 register_deactivation_hook(__FILE__, function () { 850 879 $request_url = add_query_arg( 851 880 ['id' => 92, 'action' => 'deactivate', 'domain' => md5(get_home_url())], … … 896 925 897 926 /** 927 * @param $value 928 * @param $key 929 * @param $type 930 * @param $content_type 931 * @param $content_id 932 * @return mixed 933 */ 934 private function applyFieldGetFilters($value, $key, $type, $content_type, $content_id) 935 { 936 $output = $value; 937 $type_get_callback = $this->getFields()->getAvailableFieldGetCallback($type); 938 if ($type_get_callback) { 939 add_filter($this->getHookName("get_field_type_" . $type), $type_get_callback); 940 } 941 $output = apply_filters($this->getHookName("get_field_type_" . $type), $output, $value, $content_type, $content_id); 942 $output = apply_filters($this->getHookName("get_field_" . $key), $output, $value, $content_type, $content_id); 943 return $output; 944 } 945 946 /** 898 947 * @param $key 899 948 * @param $post_id … … 916 965 $post_type_fields = $this->getFieldsByPostType($post->post_type); 917 966 $type = isset($post_type_fields[$key]['type']) ? $post_type_fields[$key]['type'] : $key; 918 $output = $value; 919 $type_get_callback = $this->getFields()->getAvailableFieldGetCallback($type); 920 if ($type_get_callback) { 921 add_filter($this->getHookName("get_field_type_" . $type), $type_get_callback); 922 } 923 $output = apply_filters($this->getHookName("get_field_type_" . $type), $output, $value, $post->post_type, $post->ID); 924 $output = apply_filters($this->getHookName("get_field_" . $key), $output, $value, $post->post_type, $post->ID); 967 $output = $this->applyFieldGetFilters($value, $key, $type, $post->post_type, $post_id); 968 $output = is_array($output) ? (current_user_can('edit_posts') ? '<pre>' . print_r($output, true) . '</pre>' : '') : $output; 969 return $output; 970 } 971 972 /** 973 * @param $key 974 * @param $term_id 975 * @return string 976 */ 977 private function getTermField($key, $term_id = false) 978 { 979 $term = $term_id && get_term($term_id) ? get_term($term_id) : false; 980 if (!$term) { 981 return ''; 982 } 983 $core_fields = [ 984 'name' => $term->name, 985 'description' => $term->description 986 ]; 987 $value = isset($core_fields[$key]) ? $core_fields[$key] : get_term_meta($term->term_id, $key, true); 988 $taxonomy_fields = $this->getFieldsByTaxonomy($term->taxonomy); 989 $type = isset($taxonomy_fields[$key]['type']) ? $taxonomy_fields[$key]['type'] : $key; 990 $output = $this->applyFieldGetFilters($value, $key, $type, $term->taxonomy, $term_id); 991 $output = is_array($output) ? (current_user_can('edit_posts') ? '<pre>' . print_r($output, true) . '</pre>' : '') : $output; 992 return $output; 993 } 994 995 /** 996 * @param $key 997 * @param $option_id 998 * @return string 999 */ 1000 private function getOptionField($key, $option_id = false) 1001 { 1002 $option = $option_id; 1003 if (!$option) { 1004 return ''; 1005 } 1006 $value = get_option("$option-$key"); 1007 $option_fields = $this->getFieldsByOption($option); 1008 $type = isset($option_fields[$key]['type']) ? $option_fields[$key]['type'] : $key; 1009 $output = $this->applyFieldGetFilters($value, $key, $type, 'option', $option); 925 1010 $output = is_array($output) ? (current_user_can('edit_posts') ? '<pre>' . print_r($output, true) . '</pre>' : '') : $output; 926 1011 return $output; -
custom-post-types/trunk/includes/Component.php
r2915886 r2917815 255 255 { 256 256 if (!$post_type || !post_type_exists($post_type)) return []; 257 $created_fields_groups = get_posts([258 'posts_per_page' => -1,259 'post_type' => $this->getInfo('ui_prefix') . "_field",260 'meta_query' => [[261 'key' => 'supports',262 'value' => $post_type,263 'compare' => 'LIKE'264 ]]265 ]);266 257 $fields = []; 267 258 if (post_type_supports($post_type, 'title')) $fields['title'] = ['label' => __('Post title', 'custom-post-types')]; … … 272 263 $fields['written_date'] = ['label' => __('Post date', 'custom-post-types')]; 273 264 $fields['modified_date'] = ['label' => __('Post modified date', 'custom-post-types')]; 265 $registered_fields = $this->getFieldsBySupports("cpt/$post_type"); 266 $fields = array_merge($fields, $registered_fields); 267 return $fields; 268 } 269 270 /** 271 * @param $taxonomy 272 * @return array 273 */ 274 public function getFieldsByTaxonomy($taxonomy = false) 275 { 276 if (!$taxonomy || !taxonomy_exists($taxonomy)) return []; 277 $fields = []; 278 $fields['name'] = ['label' => __('Term name', 'custom-post-types')]; 279 $fields['description'] = ['label' => __('Term description', 'custom-post-types')]; 280 $registered_fields = $this->getFieldsBySupports("tax/$taxonomy"); 281 $fields = array_merge($fields, $registered_fields); 282 return $fields; 283 } 284 285 /** 286 * @param $option 287 * @return array 288 */ 289 public function getFieldsByOption($option = false) 290 { 291 if (!$option) return []; 292 $fields = $this->getFieldsBySupports("options/$option"); 293 return $fields; 294 } 295 296 /** 297 * @param $support 298 * @return array 299 */ 300 public function getFieldsBySupports($support){ 301 $created_fields_groups = get_posts([ 302 'posts_per_page' => -1, 303 'post_type' => $this->getInfo('ui_prefix') . "_field", 304 'meta_query' => [[ 305 'key' => 'supports', 306 'value' => $support, 307 'compare' => 'LIKE' 308 ]] 309 ]); 310 $fields = []; 274 311 foreach ($created_fields_groups as $created_fields_group) { 275 312 $fields_group_fields = get_post_meta($created_fields_group->ID, 'fields', true); -
custom-post-types/trunk/readme.txt
r2915886 r2917815 5 5 Requires at least: 4.0 6 6 Tested up to: 6.2 7 Stable tag: 4.0. 07 Stable tag: 4.0.1 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 240 240 == Changelog == 241 241 242 = 4.0.1 = 243 * Add shortcodes for term and option fields 244 242 245 = 4.0.0 = 243 246 * New major release … … 508 511 == Upgrade Notice == 509 512 513 = 4.0.1 = 514 Add shortcodes for term and option fields 515 510 516 = 4.0.0 = 511 517 New major release
Note: See TracChangeset
for help on using the changeset viewer.