Changeset 2944690
- Timestamp:
- 07/28/2023 03:10:28 PM (2 years ago)
- Location:
- custom-post-types
- Files:
-
- 71 added
- 29 deleted
- 2 edited
-
tags/4.0.6 (added)
-
tags/4.0.6/assets (added)
-
tags/4.0.6/assets/css (added)
-
tags/4.0.6/assets/css/backend.css (added)
-
tags/4.0.6/assets/icon-256x256.png (added)
-
tags/4.0.6/assets/icon.svg (added)
-
tags/4.0.6/assets/js (added)
-
tags/4.0.6/assets/js/backend.js (added)
-
tags/4.0.6/custom-post-types.php (added)
-
tags/4.0.6/includes (added)
-
tags/4.0.6/includes/classes (added)
-
tags/4.0.6/includes/classes/AdminNotices.php (added)
-
tags/4.0.6/includes/classes/AdminPages.php (added)
-
tags/4.0.6/includes/classes/Api.php (added)
-
tags/4.0.6/includes/classes/Core.php (added)
-
tags/4.0.6/includes/classes/FieldGroups.php (added)
-
tags/4.0.6/includes/classes/PostTypes.php (added)
-
tags/4.0.6/includes/classes/Taxonomies.php (added)
-
tags/4.0.6/includes/classes/Utils.php (added)
-
tags/4.0.6/includes/fields (added)
-
tags/4.0.6/includes/fields/checkbox.php (added)
-
tags/4.0.6/includes/fields/color.php (added)
-
tags/4.0.6/includes/fields/date.php (added)
-
tags/4.0.6/includes/fields/email.php (added)
-
tags/4.0.6/includes/fields/file.php (added)
-
tags/4.0.6/includes/fields/html.php (added)
-
tags/4.0.6/includes/fields/number.php (added)
-
tags/4.0.6/includes/fields/post_rel.php (added)
-
tags/4.0.6/includes/fields/pro-only.php (added)
-
tags/4.0.6/includes/fields/radio.php (added)
-
tags/4.0.6/includes/fields/repeater.php (added)
-
tags/4.0.6/includes/fields/select.php (added)
-
tags/4.0.6/includes/fields/tax_rel.php (added)
-
tags/4.0.6/includes/fields/tel.php (added)
-
tags/4.0.6/includes/fields/text.php (added)
-
tags/4.0.6/includes/fields/textarea.php (added)
-
tags/4.0.6/includes/fields/time.php (added)
-
tags/4.0.6/includes/fields/tinymce.php (added)
-
tags/4.0.6/includes/views (added)
-
tags/4.0.6/includes/views/tools.php (added)
-
tags/4.0.6/readme.txt (added)
-
trunk/custom-post-types.php (modified) (3 diffs)
-
trunk/includes/Api.php (deleted)
-
trunk/includes/Component.php (deleted)
-
trunk/includes/Fields.php (deleted)
-
trunk/includes/Notices.php (deleted)
-
trunk/includes/Pages.php (deleted)
-
trunk/includes/PostTypes.php (deleted)
-
trunk/includes/Taxonomies.php (deleted)
-
trunk/includes/Templates.php (deleted)
-
trunk/includes/classes (added)
-
trunk/includes/classes/AdminNotices.php (added)
-
trunk/includes/classes/AdminPages.php (added)
-
trunk/includes/classes/Api.php (added)
-
trunk/includes/classes/Core.php (added)
-
trunk/includes/classes/FieldGroups.php (added)
-
trunk/includes/classes/PostTypes.php (added)
-
trunk/includes/classes/Taxonomies.php (added)
-
trunk/includes/classes/Utils.php (added)
-
trunk/includes/fields (added)
-
trunk/includes/fields/checkbox.php (added)
-
trunk/includes/fields/color.php (added)
-
trunk/includes/fields/date.php (added)
-
trunk/includes/fields/email.php (added)
-
trunk/includes/fields/file.php (added)
-
trunk/includes/fields/html.php (added)
-
trunk/includes/fields/number.php (added)
-
trunk/includes/fields/post_rel.php (added)
-
trunk/includes/fields/pro-only.php (added)
-
trunk/includes/fields/radio.php (added)
-
trunk/includes/fields/repeater.php (added)
-
trunk/includes/fields/select.php (added)
-
trunk/includes/fields/tax_rel.php (added)
-
trunk/includes/fields/tel.php (added)
-
trunk/includes/fields/text.php (added)
-
trunk/includes/fields/textarea.php (added)
-
trunk/includes/fields/time.php (added)
-
trunk/includes/fields/tinymce.php (added)
-
trunk/includes/index.php (deleted)
-
trunk/includes/views (added)
-
trunk/includes/views/tools.php (added)
-
trunk/index.php (deleted)
-
trunk/parts/fields/checkbox.php (deleted)
-
trunk/parts/fields/color.php (deleted)
-
trunk/parts/fields/date.php (deleted)
-
trunk/parts/fields/email.php (deleted)
-
trunk/parts/fields/file.php (deleted)
-
trunk/parts/fields/html.php (deleted)
-
trunk/parts/fields/number.php (deleted)
-
trunk/parts/fields/post_rel.php (deleted)
-
trunk/parts/fields/pro-only.php (deleted)
-
trunk/parts/fields/radio.php (deleted)
-
trunk/parts/fields/repeater.php (deleted)
-
trunk/parts/fields/select.php (deleted)
-
trunk/parts/fields/tax_rel.php (deleted)
-
trunk/parts/fields/tel.php (deleted)
-
trunk/parts/fields/text.php (deleted)
-
trunk/parts/fields/textarea.php (deleted)
-
trunk/parts/fields/time.php (deleted)
-
trunk/parts/fields/tinymce.php (deleted)
-
trunk/parts/pages/tools.php (deleted)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
custom-post-types/trunk/custom-post-types.php
r2932737 r2944690 8 8 Text Domain: custom-post-types 9 9 Domain Path: /languages/ 10 Version: 4.0. 510 Version: 4.0.6 11 11 */ 12 12 13 namespace CustomPostTypesPlugin; 14 15 use CustomPostTypesPlugin\Includes\Component; 16 use CustomPostTypesPlugin\Includes\Fields; 17 use CustomPostTypesPlugin\Includes\Notices; 18 use CustomPostTypesPlugin\Includes\PostTypes; 19 use CustomPostTypesPlugin\Includes\Taxonomies; 20 use CustomPostTypesPlugin\Includes\Templates; 21 use CustomPostTypesPlugin\Includes\Pages; 13 use CustomPostTypes\includes\classes\Core; 22 14 23 15 if (!defined('ABSPATH')) { … … 45 37 foreach ( 46 38 array_merge( 47 glob(CPT_INFOS['path'] . "includes/ *.php"),48 glob(CPT_INFOS['path'] . " parts/fields/*.php")39 glob(CPT_INFOS['path'] . "includes/classes/*.php"), 40 glob(CPT_INFOS['path'] . "includes/fields/*.php") 49 41 ) as $filename 50 42 ) { … … 52 44 } 53 45 54 class Core extends Component 55 { 56 /** 57 * @var PostTypes 58 */ 59 private $postTypes; 46 $custom_post_types = new Core(); 60 47 61 /** 62 * @var Taxonomies 63 */ 64 private $taxonomies; 65 66 /** 67 * @var Fields 68 */ 69 private $fields; 70 71 /** 72 * @var Templates 73 */ 74 private $templates; 75 76 /** 77 * @var Pages 78 */ 79 private $adminPages; 80 81 /** 82 * @var Notices 83 */ 84 private $notices; 85 86 public function __construct() 87 { 88 // UI 89 $this->registerUiPostTypes(); 90 $this->manipulateUiPostTypeTitle(); 91 $this->registerUiPages(); 92 $this->registerUiFields(); 93 $this->registerWelcomeNotices(); 94 $this->enqueueUiAssets(); 95 $this->initPluginUi(); 96 // Utilities 97 $this->registerShortcodes(); 98 $this->ajaxAction(); 99 $this->applyUpdates(); 100 $this->pluginActions(); 101 // Lets go 102 $this->initRegisteredContents(); 103 } 104 105 /** 106 * @return PostTypes 107 */ 108 private function getPostTypes() 109 { 110 if ($this->postTypes instanceof PostTypes) { 111 return $this->postTypes; 112 } 113 114 $this->postTypes = new PostTypes(); 115 return $this->postTypes; 116 } 117 118 /** 119 * @return Taxonomies 120 */ 121 private function getTaxonomies() 122 { 123 if ($this->taxonomies instanceof Taxonomies) { 124 return $this->taxonomies; 125 } 126 127 $this->taxonomies = new Taxonomies(); 128 return $this->taxonomies; 129 } 130 131 /** 132 * @return Fields 133 */ 134 private function getFields() 135 { 136 if ($this->fields instanceof Fields) { 137 return $this->fields; 138 } 139 140 $this->fields = new Fields(); 141 return $this->fields; 142 } 143 144 /** 145 * @return Templates 146 */ 147 public function getTemplates() 148 { 149 if ($this->templates instanceof Templates) { 150 return $this->templates; 151 } 152 153 $this->templates = new Templates(); 154 return $this->templates; 155 } 156 157 /** 158 * @return Pages 159 */ 160 private function getAdminPages() 161 { 162 if ($this->adminPages instanceof Pages) { 163 return $this->adminPages; 164 } 165 166 $this->adminPages = new Pages(); 167 return $this->adminPages; 168 } 169 170 /** 171 * @return Notices 172 */ 173 public function getNotices() 174 { 175 if ($this->notices instanceof Notices) { 176 return $this->notices; 177 } 178 179 $this->notices = new Notices(); 180 return $this->notices; 181 } 182 183 /** 184 * @return void 185 */ 186 private function registerUiPostTypes() 187 { 188 // Register ui post types 189 add_filter($this->getHookName('register_post_types'), function ($args) { 190 $default_args = [ 191 'public' => false, 192 'publicly_queryable' => false, 193 'show_ui' => true, 194 'show_in_menu' => true, 195 'show_in_rest' => false, 196 'query_var' => false, 197 'rewrite' => false, 198 'capabilities' => [ 199 'edit_post' => 'update_core', 200 'read_post' => 'update_core', 201 'delete_post' => 'update_core', 202 'edit_posts' => 'update_core', 203 'edit_others_posts' => 'update_core', 204 'delete_posts' => 'update_core', 205 'publish_posts' => 'update_core', 206 'read_private_posts' => 'update_core' 207 ], 208 'has_archive' => false, 209 'hierarchical' => false, 210 'menu_position' => null, 211 'supports' => [''], 212 'menu_icon' => 'dashicons-index-card', 213 'can_export' => false, 214 ]; 215 // Create/edit new post type 216 $args[] = [ 217 'id' => $this->getInfo('ui_prefix'), 218 'singular' => __('Post type', 'custom-post-types'), 219 'plural' => __('Post types', 'custom-post-types'), 220 'labels' => [ 221 'name' => _x('Custom post types', 'Dashboard menu', 'custom-post-types'), 222 'singular_name' => __('Post type', 'custom-post-types'), 223 'menu_name' => __('Extend / Manage', 'custom-post-types'), 224 'name_admin_bar' => __('Post type', 'custom-post-types'), 225 'add_new' => __('Add post type', 'custom-post-types'), 226 'add_new_item' => __('Add new post type', 'custom-post-types'), 227 'new_item' => __('New post type', 'custom-post-types'), 228 'edit_item' => __('Edit post type', 'custom-post-types'), 229 'view_item' => __('View post type', 'custom-post-types'), 230 'item_updated' => __('Post type updated', 'custom-post-types'), 231 'all_items' => _x('Post types', 'Dashboard menu', 'custom-post-types'), 232 'search_items' => __('Search post type', 'custom-post-types'), 233 'not_found' => __('No post type available.', 'custom-post-types'), 234 'not_found_in_trash' => __('No post type in the trash.', 'custom-post-types') 235 ], 236 'args' => array_replace_recursive($default_args, [ 237 'description' => __('Create and manage custom post types.', 'custom-post-types'), 238 ]), 239 'columns' => [ 240 'title' => [ 241 'label' => __('Plural', 'custom-post-types'), 242 ], 243 'item_key' => [ 244 'label' => __('Key', 'custom-post-types'), 245 'callback' => function ($post_id) { 246 echo get_post_meta($post_id, 'id', true); 247 } 248 ], 249 'item_count' => [ 250 'label' => __('Count', 'custom-post-types'), 251 'callback' => function ($post_id) { 252 $key = get_post_meta($post_id, 'id', true); 253 if (empty($key) || !(isset(wp_count_posts($key)->publish) ? wp_count_posts($key)->publish : false)) { 254 echo "0"; 255 return; 256 } 257 printf( 258 '<a href="%s" title="%s">%s</a>', 259 admin_url('edit.php?post_type=' . $key), 260 __('View', 'custom-post-types'), 261 wp_count_posts($key)->publish 262 ); 263 } 264 ], 265 'date' => [], 266 ] 267 ]; 268 // Create/edit new tax 269 $args[] = [ 270 'id' => $this->getInfo('ui_prefix') . '_tax', 271 'singular' => __('Taxonomy', 'custom-post-types'), 272 'plural' => __('Taxonomies', 'custom-post-types'), 273 'labels' => [ 274 'name' => __('Custom taxonomies', 'custom-post-types'), 275 'singular_name' => __('Taxonomy', 'custom-post-types'), 276 'menu_name' => __('Taxonomy', 'custom-post-types'), 277 'name_admin_bar' => __('Taxonomy', 'custom-post-types'), 278 'add_new' => __('Add taxonomy', 'custom-post-types'), 279 'add_new_item' => __('Add new taxonomy', 'custom-post-types'), 280 'new_item' => __('New taxonomy', 'custom-post-types'), 281 'edit_item' => __('Edit taxonomy', 'custom-post-types'), 282 'view_item' => __('View taxonomy', 'custom-post-types'), 283 'item_updated' => __('Taxonomy updated', 'custom-post-types'), 284 'all_items' => __('Taxonomies', 'custom-post-types'), 285 'search_items' => __('Search taxonomy', 'custom-post-types'), 286 'not_found' => __('No taxonomy available.', 'custom-post-types'), 287 'not_found_in_trash' => __('No taxonomy in the trash.', 'custom-post-types') 288 ], 289 'args' => array_replace_recursive($default_args, [ 290 'description' => __('Create and manage custom taxonomies.', 'custom-post-types'), 291 'show_in_menu' => 'edit.php?post_type=' . $this->getInfo('ui_prefix') 292 ]), 293 'columns' => [ 294 'title' => [ 295 'label' => __('Plural', 'custom-post-types'), 296 ], 297 'item_key' => [ 298 'label' => __('Key', 'custom-post-types'), 299 'callback' => function ($post_id) { 300 echo get_post_meta($post_id, 'id', true); 301 } 302 ], 303 'item_count' => [ 304 'label' => __('Count', 'custom-post-types'), 305 'callback' => function ($post_id) { 306 $key = get_post_meta($post_id, 'id', true); 307 if (empty($key) || is_wp_error(wp_count_terms(['taxonomy' => $key]))) { 308 echo "0"; 309 return; 310 } 311 printf( 312 '<a href="%s" title="%s">%s</a>', 313 admin_url('edit-tags.php?taxonomy=' . $key), 314 __('View', 'custom-post-types'), 315 wp_count_terms(['taxonomy' => $key]) 316 ); 317 } 318 ], 319 'used_by' => [ 320 'label' => __('Used by', 'custom-post-types'), 321 'callback' => function ($post_id) { 322 $supports = get_post_meta($post_id, 'supports', true); 323 if (empty($supports)) return; 324 $output = []; 325 foreach ($supports as $post_type) { 326 if (!get_post_type_object($post_type)) continue; 327 $output[] = sprintf( 328 '<a href="%s" title="%s">%s</a>', 329 admin_url('edit.php?post_type=' . $post_type), 330 __('View', 'custom-post-types'), 331 get_post_type_object($post_type)->labels->name 332 ); 333 } 334 echo implode(', ', $output); 335 } 336 ], 337 'date' => [], 338 ] 339 ]; 340 // Create/edit new fieldsgroup 341 $args[] = [ 342 'id' => $this->getInfo('ui_prefix') . '_field', 343 'singular' => __('Field group', 'custom-post-types'), 344 'plural' => __('Field groups', 'custom-post-types'), 345 'labels' => [ 346 'name' => __('Custom field groups', 'custom-post-types'), 347 'singular_name' => __('Field group', 'custom-post-types'), 348 'menu_name' => __('Field group', 'custom-post-types'), 349 'name_admin_bar' => __('Field group', 'custom-post-types'), 350 'add_new' => __('Add field group', 'custom-post-types'), 351 'add_new_item' => __('Add new field group', 'custom-post-types'), 352 'new_item' => __('New field group', 'custom-post-types'), 353 'edit_item' => __('Edit field group', 'custom-post-types'), 354 'view_item' => __('View field group', 'custom-post-types'), 355 'item_updated' => __('Field group updated', 'custom-post-types'), 356 'all_items' => __('Field groups', 'custom-post-types'), 357 'search_items' => __('Search field group', 'custom-post-types'), 358 'not_found' => __('No field group available.', 'custom-post-types'), 359 'not_found_in_trash' => __('No field group in the trash.', 'custom-post-types') 360 ], 361 'args' => array_replace_recursive($default_args, [ 362 'description' => __('Create and manage custom field groups.', 'custom-post-types'), 363 'show_in_menu' => 'edit.php?post_type=' . $this->getInfo('ui_prefix'), 364 'supports' => ['title'] 365 ]), 366 'columns' => [ 367 'title' => [ 368 'label' => __('Field group name', 'custom-post-types'), 369 ], 370 'item_count' => [ 371 'label' => __('Fields', 'custom-post-types') . ' (' . __('Key', 'custom-post-types') . ')', 372 'callback' => function ($post_id) { 373 $fields = get_post_meta($post_id, 'fields', true); 374 if (empty($fields)) return; 375 $fields_labels_array = array_map( 376 function ($field) { 377 return $field['label'] . ' (' . $field['key'] . ')'; 378 }, 379 $fields 380 ); 381 echo implode(', ', $fields_labels_array); 382 } 383 ], 384 'item_position' => [ 385 'label' => __('Position', 'custom-post-types'), 386 'callback' => function ($post_id) { 387 $available = [ 388 '' => __('NORMAL', 'custom-post-types'), 389 'normal' => __('NORMAL', 'custom-post-types'), 390 'side' => __('SIDEBAR', 'custom-post-types'), 391 'advanced' => __('ADVANCED', 'custom-post-types'), 392 ]; 393 echo $available[get_post_meta($post_id, 'position', true)]; 394 } 395 ], 396 'used_by' => [ 397 'label' => __('Used by', 'custom-post-types'), 398 'callback' => function ($post_id) { 399 $supports = get_post_meta($post_id, 'supports', true); 400 if (empty($supports)) return; 401 $output = []; 402 foreach ($supports as $post_type) { 403 $content_type = 'cpt'; 404 $content = $post_type; 405 406 if (strpos($post_type, '/') !== false) { 407 $content_type = explode('/', $post_type)[0]; 408 $content = explode('/', $post_type)[1]; 409 } 410 411 switch ($content_type) { 412 case 'cpt': 413 if (get_post_type_object($content)) { 414 $output[] = sprintf( 415 '<a href="%s" title="%s">%s</a>', 416 admin_url('edit.php?post_type=' . $content), 417 __('View', 'custom-post-types'), 418 get_post_type_object($content)->labels->name 419 ); 420 } 421 break; 422 case 'tax': 423 if (get_taxonomy($content)) { 424 $output[] = sprintf( 425 '<a href="%s" title="%s">%s</a>', 426 admin_url('edit-tags.php?taxonomy=' . $content), 427 __('View', 'custom-post-types'), 428 get_taxonomy($content)->labels->name 429 ); 430 } 431 break; 432 case 'extra': 433 if ($content == 'users') { 434 $output[] = sprintf( 435 '<a href="%s" title="%s">%s</a>', 436 admin_url('users.php'), 437 __('View', 'custom-post-types'), 438 __('Users') 439 ); 440 } 441 break; 442 case 'options': 443 if (isset($this->getSettingsPagesOptions()[$content])) { 444 $pageUrl = !empty($this->getSettingsPagesOptions()[$content]['url']) ? admin_url($this->getSettingsPagesOptions()[$content]['url']) : menu_page_url($content, false); 445 $output[] = sprintf( 446 '<a href="%s" title="%s">%s</a>', 447 $pageUrl, 448 __('View', 'custom-post-types'), 449 $this->getSettingsPagesOptions()[$content]['title'] 450 ); 451 } 452 break; 453 } 454 } 455 echo implode(', ', $output); 456 } 457 ], 458 'date' => [], 459 ] 460 ]; 461 return $args; 462 }); 463 464 // Remove quick edit links 465 add_filter('post_row_actions', function ($actions, $post) { 466 $postType = $post->post_type; 467 if (stripos($postType, $this->getInfo('ui_prefix')) !== false) { 468 unset($actions['inline hide-if-no-js']); 469 } 470 return $actions; 471 }, 1, 2); 472 473 // Update ui notices 474 add_filter('post_updated_messages', function ($messages) { 475 $messages[$this->getInfo('ui_prefix')] = [ 476 1 => __('Post type updated', 'custom-post-types'), 477 4 => __('Post type updated', 'custom-post-types'), 478 6 => __('Post type published', 'custom-post-types'), 479 7 => __('Post type saved', 'custom-post-types'), 480 8 => __('Post type submitted', 'custom-post-types'), 481 9 => __('Post type scheduled', 'custom-post-types'), 482 10 => __('Post type draft updated', 'custom-post-types'), 483 ]; 484 $messages[$this->getInfo('ui_prefix') . '_tax'] = [ 485 1 => __('Taxonomy updated', 'custom-post-types'), 486 4 => __('Taxonomy updated', 'custom-post-types'), 487 6 => __('Taxonomy published', 'custom-post-types'), 488 7 => __('Taxonomy saved', 'custom-post-types'), 489 8 => __('Taxonomy submitted', 'custom-post-types'), 490 9 => __('Taxonomy scheduled', 'custom-post-types'), 491 10 => __('Taxonomy draft updated', 'custom-post-types'), 492 ]; 493 $messages[$this->getInfo('ui_prefix') . '_field'] = [ 494 1 => __('Field group updated', 'custom-post-types'), 495 4 => __('Field group updated', 'custom-post-types'), 496 6 => __('Field group published', 'custom-post-types'), 497 7 => __('Field group saved', 'custom-post-types'), 498 8 => __('Field group submitted', 'custom-post-types'), 499 9 => __('Field group scheduled', 'custom-post-types'), 500 10 => __('Field group draft updated', 'custom-post-types'), 501 ]; 502 $messages[$this->getInfo('ui_prefix') . '_template'] = [ 503 1 => __('Template updated', 'custom-post-types'), 504 4 => __('Template updated', 'custom-post-types'), 505 6 => __('Template published', 'custom-post-types'), 506 7 => __('Template saved', 'custom-post-types'), 507 8 => __('Template submitted', 'custom-post-types'), 508 9 => __('Template scheduled', 'custom-post-types'), 509 10 => __('Template draft updated', 'custom-post-types'), 510 ]; 511 $messages[$this->getInfo('ui_prefix') . '_page'] = [ 512 1 => __('Admin page updated', 'custom-post-types'), 513 4 => __('Admin page updated', 'custom-post-types'), 514 6 => __('Admin page published', 'custom-post-types'), 515 7 => __('Admin page saved', 'custom-post-types'), 516 8 => __('Admin page submitted', 'custom-post-types'), 517 9 => __('Admin page scheduled', 'custom-post-types'), 518 10 => __('Admin page draft updated', 'custom-post-types'), 519 ]; 520 return $messages; 521 }); 522 } 523 524 /** 525 * @return void 526 */ 527 private function manipulateUiPostTypeTitle() 528 { 529 $no_title_ui_cpts = [$this->getInfo('ui_prefix'), $this->getInfo('ui_prefix') . '_tax']; 530 531 // Override ui post title using singular label 532 add_action('save_post', function ($post_id) use ($no_title_ui_cpts) { 533 $post_type = get_post($post_id)->post_type; 534 $post_status = get_post($post_id)->post_status; 535 if (!in_array($post_type, $no_title_ui_cpts) || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || $post_status == 'trash') return $post_id; 536 $new_title = isset($_POST['meta-fields']['plural']) && !empty($_POST['meta-fields']['plural']) ? $_POST['meta-fields']['plural'] : 'CPT_' . $post_id; 537 global $wpdb; 538 $wpdb->update($wpdb->posts, ['post_title' => $new_title], ['ID' => $post_id]); 539 return $post_id; 540 }); 541 542 // Show on ui post types title 543 add_action('edit_form_after_title', function () use ($no_title_ui_cpts) { 544 $screen = get_current_screen(); 545 $post = isset($_GET['post']) && get_post($_GET['post']) ? get_post($_GET['post']) : false; 546 if (!in_array($screen->post_type, $no_title_ui_cpts) || !in_array($screen->id, $no_title_ui_cpts) || !$post) return; 547 printf('<h1 style="padding: 0;">%s</h1>', $post->post_title); 548 }); 549 } 550 551 /** 552 * @return void 553 */ 554 private function registerUiPages() 555 { 556 // Remove new post type menu 557 add_action('admin_menu', function () { 558 remove_submenu_page('edit.php?post_type=' . $this->getInfo('ui_prefix'), 'post-new.php?post_type=' . $this->getInfo('ui_prefix')); 559 }); 560 561 // Add settings page 562 add_filter($this->getHookName('register_admin_pages'), function ($args) { 563 564 if (!$this->isProVersionActive()) { 565 $args[] = [ 566 'id' => 'manage_template', 567 'parent' => 'edit.php?post_type=' . $this->getInfo('ui_prefix'), 568 'order' => null, 569 'menu_icon' => null, 570 'title' => __('Templates', 'custom-post-types'), 571 'content' => $this->getProBanner(), 572 'admin_only' => true 573 ]; 574 $args[] = [ 575 'id' => 'manage_admin_pages', 576 'parent' => 'edit.php?post_type=' . $this->getInfo('ui_prefix'), 577 'order' => null, 578 'menu_icon' => null, 579 'title' => __('Admin pages', 'custom-post-types'), 580 'content' => $this->getProBanner(), 581 'admin_only' => true 582 ]; 583 $args[] = [ 584 'id' => 'manage_admin_notices', 585 'parent' => 'edit.php?post_type=' . $this->getInfo('ui_prefix'), 586 'order' => null, 587 'menu_icon' => null, 588 'title' => __('Admin notices', 'custom-post-types'), 589 'content' => $this->getProBanner(), 590 'admin_only' => true 591 ]; 592 } 593 594 ob_start(); 595 require_once($this->getInfo('path') . 'parts/pages/tools.php'); 596 $template = ob_get_clean(); 597 598 $args[] = [ 599 'id' => 'tools', 600 'parent' => 'edit.php?post_type=' . $this->getInfo('ui_prefix'), 601 'order' => null, 602 'menu_icon' => null, 603 'title' => __('Tools & Infos', 'custom-post-types'), 604 'content' => $template, 605 'admin_only' => true 606 ]; 607 return $args; 608 }); 609 } 610 611 /** 612 * @return void 613 */ 614 private function registerUiFields() 615 { 616 // Register ui fields 617 add_filter($this->getHookName('register_fields'), function ($fields) { 618 $fields[] = $this->getFields()->getPostTypeFields(); 619 $fields[] = $this->getFields()->getTaxonomyFields(); 620 $fields[] = $this->getFields()->getNewFieldGroupFields(); 621 return $fields; 622 }); 623 } 624 625 /** 626 * @return void 627 */ 628 private function registerWelcomeNotices() 629 { 630 // Register welcome notices 631 add_filter($this->getHookName('register_notices'), function ($args) { 632 $buttons = [ 633 [ 634 'link' => $this->getInfo('plugin_review_url'), 635 'label' => __('Write a Review', 'custom-post-types'), 636 'target' => '_blank', 637 'cta' => true 638 ], 639 [ 640 'link' => $this->getInfo('plugin_donate_url'), 641 'label' => __('Make a Donation', 'custom-post-types'), 642 'target' => '_blank' 643 ] 644 ]; 645 if (!$this->isProVersionActive()) { 646 $buttons[] = [ 647 'link' => $this->getInfo('plugin_url'), 648 'label' => __('Get PRO version', 'custom-post-types'), 649 'target' => '_blank' 650 ]; 651 } 652 653 // After installation notice 654 $welcomeNotice = [ 655 'id' => 'welcome_notice_400', 656 'title' => $this->getNoticesTitle(), 657 'message' => __('Thanks for using this plugin! Do you want to help us grow to add new features?', 'custom-post-types') . '<br><br>' . sprintf(__('The new version %s introduces a lot of new features and improves the core of the plugin.<br>For any problems you can download the previous version %s from the official page of the plugin from WordPress.org (Advanced View > Previous version).', 'custom-post-types'), '<u>' . $this->getInfo('version') . '</u>', '<u>3.1.1</u>'), 658 'type' => 'success', 659 'dismissible' => true, 660 'buttons' => $buttons, 661 ]; 662 663 if (time() < 1688169599) { // 30-06-2023 23:59:59 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 } 666 667 $args[] = $welcomeNotice; 668 669 $installationTime = get_option($this->getOptionName('installation_time'), null); 670 if ($installationTime && strtotime("+7 day", $installationTime) < time()) { 671 // After 7 days notice 672 $args[] = [ 673 'id' => 'welcome_notice_400_1', 674 'title' => $this->getNoticesTitle(), 675 'message' => __('Wow! More than 7 days of using this amazing plugin. Your support is really important.', 'custom-post-types'), 676 'type' => 'success', 677 'dismissible' => true, 678 'buttons' => $buttons, 679 ]; 680 } 681 682 return $args; 683 }); 684 } 685 686 /** 687 * @return void 688 */ 689 private function enqueueUiAssets() 690 { 691 // Enqueue ui assets 692 add_action('admin_enqueue_scripts', function () { 693 wp_enqueue_style($this->getInfo('ui_prefix'), $this->getInfo('url') . 'assets/css/backend.css'); 694 if ($this->loadJs()) { 695 wp_enqueue_media(); 696 wp_enqueue_editor(); 697 wp_enqueue_script($this->getInfo('options_prefix'), $this->getInfo('url') . 'assets/js/backend.js', ['jquery', 'wp-i18n', 'wp-util', 'wp-hooks', 'wp-editor'], null, true); 698 wp_localize_script($this->getInfo('options_prefix'), 'cpt', $this->getJsVariables()); 699 wp_set_script_translations($this->getInfo('options_prefix'), 'custom-post-types'); 700 } 701 }); 702 } 703 704 /** 705 * @return void 706 */ 707 private function initPluginUi() 708 { 709 add_filter('plugin_action_links', function ($links, $file) { 710 if ($file == 'custom-post-types/custom-post-types.php') { 711 $links[] = sprintf( 712 '<a href="%1$s" target="_blank" aria-label="%2$s"> %2$s </a>', 713 $this->getInfo('plugin_support_url'), 714 __('Support', 'custom-post-types') 715 ); 716 if (!$this->isProVersionActive()) { 717 $links[] = sprintf( 718 '<a href="%1$s" target="_blank" aria-label="%2$s" style="font-weight: bold;"> %2$s </a>', 719 $this->getInfo('plugin_url'), 720 __('Get PRO', 'custom-post-types') 721 ); 722 } 723 } 724 return $links; 725 }, PHP_INT_MAX, 2); 726 } 727 728 /** 729 * @return void 730 */ 731 private function registerShortcodes() 732 { 733 // Shortcodes 734 add_action('wp', function () { 735 if (!is_admin() && !$this->isRest()) { 736 global $post; 737 add_shortcode('cpt-field', function ($atts) { 738 $a = shortcode_atts([ 739 'key' => false, 740 'post-id' => false 741 ], $atts); 742 $errors = false; 743 if (!$a['key']) { 744 $errors[] = __('Missing field "key".', 'custom-post-types'); 745 } 746 if ($errors) { 747 return current_user_can('edit_posts') ? "<pre>" . implode("</pre><pre>", $errors) . "</pre>" : ''; 748 } 749 return $this->getPostField($a['key'], $a['post-id']); 750 }); 751 add_shortcode('cpt-terms', function ($atts) use ($post) { 752 $a = shortcode_atts([ 753 'key' => false, 754 'post-id' => false 755 ], $atts); 756 $errors = false; 757 if (!$a['key']) { 758 $errors[] = __('Missing field "key".', 'custom-post-types'); 759 } 760 if ($errors) { 761 return current_user_can('edit_posts') ? "<pre>" . implode("</pre><pre>", $errors) . "</pre>" : ''; 762 } 763 $post = $a['post-id'] && get_post($a['post-id']) ? get_post($a['post-id']) : $post; 764 $get_terms = get_the_terms($post->ID, $a['key']); 765 $terms = []; 766 foreach ($get_terms as $term) { 767 $terms[] = sprintf('<a href="%1$s" title="%2$s" aria-title="%2$s">%2$s</a>', get_term_link($term->term_id), $term->name); 768 } 769 return implode(', ', $terms); 770 }); 771 add_shortcode('cpt-term-field', function ($atts) { 772 $a = shortcode_atts([ 773 'key' => false, 774 'term-id' => false 775 ], $atts); 776 $errors = false; 777 if (!$a['key']) { 778 $errors[] = __('Missing field "key".', 'custom-post-types'); 779 } 780 if (!$a['term-id']) { 781 $errors[] = __('Missing field "term-id".', 'custom-post-types'); 782 } 783 if ($errors) { 784 return current_user_can('edit_posts') ? "<pre>" . implode("</pre><pre>", $errors) . "</pre>" : ''; 785 } 786 return $this->getTermField($a['key'], $a['term-id']); 787 }); 788 add_shortcode('cpt-option-field', function ($atts) { 789 $a = shortcode_atts([ 790 'key' => false, 791 'option-id' => false 792 ], $atts); 793 $errors = false; 794 if (!$a['key']) { 795 $errors[] = __('Missing field "key".', 'custom-post-types'); 796 } 797 if (!$a['option-id']) { 798 $errors[] = __('Missing field "option-id".', 'custom-post-types'); 799 } 800 if ($errors) { 801 return current_user_can('edit_posts') ? "<pre>" . implode("</pre><pre>", $errors) . "</pre>" : ''; 802 } 803 return $this->getOptionField($a['key'], $a['option-id']); 804 }); 805 } 806 }); 807 } 808 809 /** 810 * @return void 811 */ 812 private function ajaxAction() 813 { 814 $this->getNotices()->ajaxAction(); 815 $this->getTemplates()->ajaxAction(); 816 817 $ajaxActions = (array)apply_filters($this->getHookName('register_ajax_actions'), []); 818 foreach ($ajaxActions as $action => $args) { 819 add_action('wp_ajax_' . $action, function () use ($args) { 820 $nonce = !empty($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], $this->getInfo('nonce_key')) ? true : false; 821 if (!$nonce) { 822 wp_send_json_error(); 823 } 824 foreach ($args['requiredParams'] as $param) { 825 if (empty($_REQUEST[$param])) { 826 wp_send_json_error(); 827 } 828 } 829 if (empty($args['callback']) || !is_callable($args['callback'])) { 830 wp_send_json_error(); 831 } 832 $result = $args['callback']($_REQUEST); 833 wp_send_json_success($result); 834 }); 835 } 836 } 837 838 /** 839 * @return void 840 */ 841 private function applyUpdates() 842 { 843 $installedVersion = get_option($this->getOptionName('version'), null); 844 $currentVersion = $this->getInfo('version'); 845 846 if (version_compare($installedVersion, $currentVersion, '=')) { 847 return; 848 } 849 850 if (version_compare($installedVersion, $currentVersion, '<')) { 851 // Apply updates 852 } 853 854 update_option($this->getOptionName('version'), $currentVersion); 855 update_option($this->getOptionName('installation_time'), time()); 856 857 if(!empty($installedVersion)){ 858 $request_url = add_query_arg( 859 ['id' => 92, 'action' => 'updated', 'domain' => md5(get_home_url()), 'v' => $currentVersion], 860 'https://totalpress.org/wp-json/totalpress/v1/plugin-growth' 861 ); 862 wp_remote_get($request_url); 863 } 864 } 865 866 private function pluginActions() 867 { 868 $currentVersion = $this->getInfo('version'); 869 register_activation_hook(__FILE__, function () use ($currentVersion) { 870 $request_url = add_query_arg( 871 ['id' => 92, 'action' => 'activate', 'domain' => md5(get_home_url()), 'v' => $currentVersion], 872 'https://totalpress.org/wp-json/totalpress/v1/plugin-growth' 873 ); 874 wp_remote_get($request_url); 875 }); 876 register_deactivation_hook(__FILE__, function () use ($currentVersion) { 877 $request_url = add_query_arg( 878 ['id' => 92, 'action' => 'deactivate', 'domain' => md5(get_home_url()), 'v' => $currentVersion], 879 'https://totalpress.org/wp-json/totalpress/v1/plugin-growth' 880 ); 881 wp_remote_get($request_url); 882 }); 883 } 884 885 /** 886 * @return void 887 */ 888 private function initRegisteredContents() 889 { 890 // Init registered content 891 add_action('init', function () { 892 $this->getPostTypes()->initRegisteredPostTypes(); 893 $this->getTaxonomies()->initRegisteredTaxonomies(); 894 $this->getFields()->initRegisteredGroups(); 895 $this->getAdminPages()->initRegisteredPages(); 896 $this->getNotices()->initRegisteredNotices(); 897 }); 898 } 899 900 /** 901 * @return bool 902 */ 903 public function loadJs() 904 { 905 $currentScreen = get_current_screen(); 906 if ( 907 (!empty($currentScreen->id) && 908 ( 909 in_array($currentScreen->id, $this->getFields()->screensWithFields) || 910 ( 911 explode('_page_', $currentScreen->id) && 912 !empty(explode('_page_', $currentScreen->id)[1]) && 913 in_array('_page_' . explode('_page_', $currentScreen->id)[1], $this->getFields()->screensWithFields) 914 ) 915 ) 916 ) || 917 $this->getNotices()->hasNotices 918 ) { 919 return true; 920 } 921 return false; 922 } 923 924 /** 925 * @param $value 926 * @param $key 927 * @param $type 928 * @param $content_type 929 * @param $content_id 930 * @return mixed 931 */ 932 private function applyFieldGetFilters($value, $key, $type, $content_type, $content_id) 933 { 934 $output = $value; 935 $type_get_callback = $this->getFields()->getAvailableFieldGetCallback($type); 936 if ($type_get_callback && !has_filter($this->getHookName("get_field_type_" . $type))) { 937 add_filter($this->getHookName("get_field_type_" . $type), $type_get_callback); 938 } 939 $output = apply_filters($this->getHookName("get_field_type_" . $type), $output, $value, $content_type, $content_id); 940 $output = apply_filters($this->getHookName("get_field_" . $key), $output, $value, $content_type, $content_id); 941 return $output; 942 } 943 944 /** 945 * @param $key 946 * @param $post_id 947 * @return string 948 */ 949 private function getPostField($key, $post_id = false) 950 { 951 global $post; 952 $post = $post_id && get_post($post_id) ? get_post($post_id) : $post; 953 $core_fields = [ 954 'title' => get_the_title($post->ID), 955 'content' => get_the_content($post->ID), 956 'excerpt' => get_the_excerpt($post->ID), 957 'thumbnail' => get_the_post_thumbnail($post->ID, 'full'), 958 'author' => sprintf('<a href="%1$s" title="%2$s" aria-title="%2$s">%2$s</a>', get_author_posts_url(get_the_author_meta('ID')), get_the_author()), 959 'written_date' => get_the_date(get_option('date_format', "d/m/Y"), $post->ID), 960 'modified_date' => get_the_modified_date(get_option('date_format', "d/m/Y"), $post->ID), 961 ]; 962 $value = isset($core_fields[$key]) ? $core_fields[$key] : get_post_meta($post->ID, $key, true); 963 $post_type_fields = $this->getFieldsByPostType($post->post_type); 964 $type = isset($post_type_fields[$key]['type']) ? $post_type_fields[$key]['type'] : $key; 965 $output = $this->applyFieldGetFilters($value, $key, $type, $post->post_type, $post_id); 966 $output = is_array($output) ? (current_user_can('edit_posts') ? '<pre>' . print_r($output, true) . '</pre>' : '') : $output; 967 return $output; 968 } 969 970 /** 971 * @param $key 972 * @param $term_id 973 * @return string 974 */ 975 private function getTermField($key, $term_id = false) 976 { 977 $term = $term_id && get_term($term_id) ? get_term($term_id) : false; 978 if (!$term) { 979 return ''; 980 } 981 $core_fields = [ 982 'name' => $term->name, 983 'description' => $term->description 984 ]; 985 $value = isset($core_fields[$key]) ? $core_fields[$key] : get_term_meta($term->term_id, $key, true); 986 $taxonomy_fields = $this->getFieldsByTaxonomy($term->taxonomy); 987 $type = isset($taxonomy_fields[$key]['type']) ? $taxonomy_fields[$key]['type'] : $key; 988 $output = $this->applyFieldGetFilters($value, $key, $type, $term->taxonomy, $term_id); 989 $output = is_array($output) ? (current_user_can('edit_posts') ? '<pre>' . print_r($output, true) . '</pre>' : '') : $output; 990 return $output; 991 } 992 993 /** 994 * @param $key 995 * @param $option_id 996 * @return string 997 */ 998 private function getOptionField($key, $option_id = false) 999 { 1000 $option = $option_id; 1001 if (!$option) { 1002 return ''; 1003 } 1004 $value = get_option("$option-$key"); 1005 $option_fields = $this->getFieldsByOption($option); 1006 $type = isset($option_fields[$key]['type']) ? $option_fields[$key]['type'] : $key; 1007 $output = $this->applyFieldGetFilters($value, $key, $type, 'option', $option); 1008 $output = is_array($output) ? (current_user_can('edit_posts') ? '<pre>' . print_r($output, true) . '</pre>' : '') : $output; 1009 return $output; 1010 } 1011 } 1012 1013 if (!in_array('custom-post-types-pro/custom-post-types-pro.php', apply_filters('active_plugins', get_option('active_plugins')))) { 1014 new Core(); 1015 } 48 do_action('custom_post_types_plugin_loaded'); -
custom-post-types/trunk/readme.txt
r2932737 r2944690 5 5 Requires at least: 4.0 6 6 Tested up to: 6.2 7 Stable tag: 4.0. 57 Stable tag: 4.0.6 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 199 199 == Changelog == 200 200 201 = 4.0.6 = 202 *2023-27-28* 203 * Performance improvments 204 201 205 = 4.0.5 = 202 206 *2023-06-30* 203 207 * Check if attachment.sizes.thumbnail.url exists on file field (@dealespaloit) 204 205 208 206 209 = 4.0.4 =
Note: See TracChangeset
for help on using the changeset viewer.