PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.7.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.7.4
3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 All 195 releases
← All changes | admin/class-convertkit-admin-post.php +121 -5 2.3.22.7.4 View file →
@@ -22,8 +22,12 @@
22 22 * @since 1.9.6
23 23 */
24 24 public function __construct() {
25 25
26 + // Register "Add New" Kit button on Pages.
27 + add_filter( 'views_edit-page', array( $this, 'output_wp_list_table_buttons' ) );
28 +
29 + add_action( 'post_submitbox_misc_actions', array( $this, 'output_pre_publish_actions' ) );
26 30 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
27 31 add_action( 'save_post', array( $this, 'save_post_meta' ) );
28 32
29 33 }
@@ -28,8 +32,74 @@
28 32
29 33 }
30 34
31 35 /**
36 + * Registers 'Add New' buttons for the given Post Type's admin screen.
37 + *
38 + * If no options are registered, no button is displayed.
39 + *
40 + * JS will move this button to be displayed next to the "Add New" button when viewing the table of Pages or Posts,
41 + * as there is not a native WordPress action/filter for registering buttons next to the "Add New" button.
42 + *
43 + * @since 2.5.5
44 + *
45 + * @param array $views Views.
46 + * @return array Views
47 + */
48 + public function output_wp_list_table_buttons( $views ) {
49 +
50 + // Get current post type that we're viewing.
51 + $post_type = $this->get_current_post_type();
52 +
53 + // Don't output any buttons if we couldn't determine the current post type.
54 + if ( ! $post_type ) {
55 + return $views;
56 + }
57 +
58 + // Define a blank array of buttons to be filtered.
59 + $buttons = array();
60 +
61 + /**
62 + * Registers 'Add New' buttons for the given Post Type's admin screen.
63 + *
64 + * @since 2.5.5
65 + *
66 + * @param array $buttons Buttons.
67 + * @param string $post_type Post Type.
68 + */
69 + $buttons = apply_filters( 'convertkit_admin_post_register_add_new_buttons', $buttons, $post_type );
70 +
71 + // Bail if no buttons are registered for display.
72 + if ( ! count( $buttons ) ) {
73 + return $views;
74 + }
75 +
76 + // Enqueue JS and CSS.
77 + wp_enqueue_script( 'convertkit-admin-wp-list-table-buttons', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/wp-list-table-buttons.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
78 + wp_enqueue_style( 'convertkit-admin-wp-list-table-buttons', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/wp-list-table-buttons.css', array(), CONVERTKIT_PLUGIN_VERSION );
79 +
80 + // Build buttons HTML.
81 + $html = '';
82 + foreach ( $buttons as $button_name => $button ) {
83 + $html .= sprintf(
84 + '<a href="%s">%s</a>',
85 + esc_attr( $button['url'] ),
86 + esc_html( $button['label'] )
87 + );
88 + }
89 +
90 + // Register an 'Add New' dropdown button, with buttons HTML.
91 + $views['convertkit'] = sprintf(
92 + '<span class="convertkit-action page-title-action hidden">%s<span class="convertkit-actions hidden">%s</span></span>',
93 + __( 'Add New', 'convertkit' ),
94 + $html
95 + );
96 +
97 + return $views;
98 +
99 + }
100 +
101 + /**
32 102 * Enqueue JavaScript when editing a Page, Post or Custom Post Type that outputs
33 103 * ConvertKit Plugin settings.
34 104 *
35 105 * @since 1.9.6.4
@@ -63,9 +133,9 @@
63 133 // Enqueue Post CSS.
64 134 wp_enqueue_style( 'convertkit-post', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/post.css', array(), CONVERTKIT_PLUGIN_VERSION );
65 135
66 136 /**
67 - * Enqueue CSS for the Settings Screen at Settings > ConvertKit
137 + * Enqueue CSS for the Settings Screen at Settings > Kit
68 138 *
69 139 * @since 1.9.6.4
70 140 */
71 141 do_action( 'convertkit_admin_post_enqueue_styles' );
@@ -72,8 +142,39 @@
72 142
73 143 }
74 144
75 145 /**
146 + * Registers actions in the pre-publish actions section of the Publish metabox
147 + * in the Classic Editor.
148 + *
149 + * @since 2.4.0
150 + *
151 + * @param WP_Post $post WordPress Post.
152 + */
153 + public function output_pre_publish_actions( $post ) {
154 +
155 + // Bail if no actions registered.
156 + $pre_publish_actions = convertkit_get_pre_publish_actions();
157 + if ( ! count( $pre_publish_actions ) ) {
158 + return;
159 + }
160 +
161 + // Bail if Post is not a supported Post Type.
162 + if ( get_post_type( $post ) !== 'post' ) {
163 + return;
164 + }
165 +
166 + // Bail if Post is not a draft.
167 + if ( ! in_array( $post->post_status, array( 'draft', 'auto-draft' ), true ) ) {
168 + return;
169 + }
170 +
171 + // Load pre-publish actions view.
172 + include CONVERTKIT_PLUGIN_PATH . '/views/backend/post/pre-publish-actions.php';
173 +
174 + }
175 +
176 + /**
76 177 * Adds a meta box for the given Post Type.
77 178 *
78 179 * @since 1.9.6
79 180 *
@@ -87,9 +188,9 @@
87 188 return;
88 189 }
89 190
90 191 // Register Meta Box.
91 - add_meta_box( 'wp-convertkit-meta-box', __( 'ConvertKit', 'convertkit' ), array( $this, 'display_meta_box' ), $post_type, 'normal' );
192 + add_meta_box( 'wp-convertkit-meta-box', __( 'Kit', 'convertkit' ), array( $this, 'display_meta_box' ), $post_type, 'normal' );
92 193
93 194 // Enqueue JS and CSS.
94 195 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
95 196 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
@@ -111,10 +212,11 @@
111 212 }
112 213
113 214 // Show a warning if the API credentials haven't been set.
114 215 $settings = new ConvertKit_Settings();
115 - if ( ! $settings->has_api_key_and_secret() ) {
216 + if ( ! $settings->has_access_and_refresh_token() ) {
116 217 $post_type = get_post_type_object( $post->post_type );
218 + $api = new ConvertKit_API_V4( CONVERTKIT_OAUTH_CLIENT_ID, CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI );
117 219 include CONVERTKIT_PLUGIN_PATH . '/views/backend/post/no-api-key.php';
118 220 return;
119 221 }
120 222
@@ -121,10 +223,11 @@
121 223 // Initialize Restrict Content Settings class.
122 224 $restrict_content_settings = new ConvertKit_Settings_Restrict_Content();
123 225
124 226 // Fetch Post Settings, Forms, Landing Pages and Tags.
125 - $convertkit_post = new ConvertKit_Post( $post->ID );
126 - $convertkit_forms = new ConvertKit_Resource_Forms();
227 + $convertkit_post = new ConvertKit_Post( $post->ID );
228 + $convertkit_forms = new ConvertKit_Resource_Forms();
229 +
127 230 $convertkit_landing_pages = new ConvertKit_Resource_Landing_Pages();
128 231 $convertkit_products = new ConvertKit_Resource_Products();
129 232 $convertkit_tags = new ConvertKit_Resource_Tags();
130 233
@@ -222,8 +325,21 @@
222 325 // it is never displayed again.
223 326 if ( $meta['form'] || $meta['landing_page'] ) {
224 327 WP_ConvertKit()->get_class( 'review_request' )->request_review();
225 328 }
329 +
330 + }
331 +
332 + /**
333 + * Get the current post type based on the screen that is viewed.
334 + *
335 + * @since 2.5.5
336 + *
337 + * @return bool|string
338 + */
339 + private function get_current_post_type() {
340 +
341 + return convertkit_get_current_screen( 'post_type' );
226 342
227 343 }
228 344
229 345 }