PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 5.2.0
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v5.2.0
5.5.3 3.1.0 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.6.0 3.7.0 3.8.0 3.8.1 3.8.2 3.8.3 4.0.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 All 78 releases
copy-the-code / includes / class-post-types.php

class-post-types.php in Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code 5.2.0, at includes/class-post-types.php

153 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post Types Registration
4 *
5 * Handles registration of custom post types for the plugin.
6 *
7 * @package CTC
8 * @since 5.1.0
9 */
10
11 namespace CTC;
12
13 /**
14 * Post_Types Class
15 *
16 * Registers custom post types.
17 */
18 class Post_Types {
19
20 /**
21 * Instance
22 *
23 * @var Post_Types|null
24 */
25 private static $instance = null;
26
27 /**
28 * Get instance.
29 *
30 * @return Post_Types
31 */
32 public static function get() {
33 if ( null === self::$instance ) {
34 self::$instance = new self();
35 }
36 return self::$instance;
37 }
38
39 /**
40 * Constructor.
41 */
42 private function __construct() {
43 add_action( 'init', [ $this, 'register' ] );
44
45 /*
46 * Remove these redirects once the legacy post type editor is fully deprecated.
47 * These redirect the "Add New" button and edit links to the Global Injector page.
48 */
49 add_filter( 'admin_url', [ $this, 'redirect_add_new_to_global_injector' ], 10, 2 );
50 add_action( 'current_screen', [ $this, 'maybe_add_edit_link_filter' ] );
51 }
52
53 /**
54 * Redirect "Add New" button to Global Injector page.
55 *
56 * Remove this method once the legacy post type editor is fully deprecated.
57 *
58 * @since 5.1.0
59 *
60 * @param string $url The complete admin area URL including scheme and path.
61 * @param string $path Path relative to the admin area URL.
62 * @return string Modified URL.
63 */
64 public function redirect_add_new_to_global_injector( $url, $path ) {
65 if ( 'post-new.php?post_type=copy-to-clipboard' === $path ) {
66 return admin_url( 'options-general.php?page=ctc-global-injector' );
67 }
68
69 return $url;
70 }
71
72 /**
73 * Conditionally add edit link filter only on copy-to-clipboard list table.
74 *
75 * Remove this method once the legacy post type editor is fully deprecated.
76 *
77 * @since 5.1.0
78 *
79 * @param \WP_Screen $screen Current admin screen object.
80 */
81 public function maybe_add_edit_link_filter( $screen ) {
82 if ( 'copy-to-clipboard' === $screen->post_type && 'edit' === $screen->base ) {
83 add_filter( 'get_edit_post_link', [ $this, 'redirect_edit_link_to_global_injector' ], 10, 2 );
84 }
85 }
86
87 /**
88 * Redirect edit post links to Global Injector page.
89 *
90 * This filter is only added on the copy-to-clipboard list table screen,
91 * so we don't need to check post type here.
92 *
93 * Remove this method once the legacy post type editor is fully deprecated.
94 *
95 * @since 5.1.0
96 *
97 * @param string $link The edit link.
98 * @param int $post_id Post ID.
99 * @return string Modified URL.
100 */
101 public function redirect_edit_link_to_global_injector( $link, $post_id ) {
102 return admin_url( 'options-general.php?page=ctc-global-injector&rule=' . $post_id );
103 }
104
105 /**
106 * Register custom post types.
107 *
108 * @since 5.1.0
109 */
110 public function register() {
111 $labels = [
112 'name' => __( 'Copy to Clipboard', 'ctc' ),
113 'singular_name' => __( 'Copy to Clipboard', 'ctc' ),
114 'add_new' => _x( 'Add New', 'ctc', 'ctc' ),
115 'add_new_item' => __( 'Add New', 'ctc' ),
116 'edit_item' => __( 'Edit Copy to Clipboard', 'ctc' ),
117 'new_item' => __( 'New Copy to Clipboard', 'ctc' ),
118 'view_item' => __( 'View Copy to Clipboard', 'ctc' ),
119 'search_items' => __( 'Search Copy to Clipboard', 'ctc' ),
120 'not_found' => __( 'No Copy to Clipboard found', 'ctc' ),
121 'not_found_in_trash' => __( 'No Copy to Clipboard found in Trash', 'ctc' ),
122 'parent_item_colon' => __( 'Parent Copy to Clipboard:', 'ctc' ),
123 'menu_name' => __( 'Copy to Clipboard', 'ctc' ),
124 ];
125
126 $args = [
127 'labels' => $labels,
128 'hierarchical' => false,
129 'description' => 'description',
130 'taxonomies' => [],
131 'public' => false,
132 'show_ui' => true,
133 'show_in_menu' => false,
134 'show_in_admin_bar' => false,
135 'menu_position' => null,
136 'menu_icon' => 'dashicons-clipboard',
137 'show_in_nav_menus' => true,
138 'publicly_queryable' => false,
139 'exclude_from_search' => false,
140 'has_archive' => false,
141 'query_var' => false,
142 'can_export' => true,
143 'rewrite' => false,
144 'capability_type' => 'post',
145 'supports' => [
146 'title',
147 ],
148 ];
149
150 register_post_type( 'copy-to-clipboard', $args );
151 }
152 }
153