PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 1.9.6.2
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v1.9.6.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 2.3.3 All 194 releases
convertkit / admin / class-convertkit-admin-post.php

class-convertkit-admin-post.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 1.9.6.2, at admin/class-convertkit-admin-post.php

135 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Admin Post class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Registers a metabox on Posts, Pages and public facing Custom Post Types
11 * and saves its settings when the Post is saved in the WordPress Administration
12 * interface.
13 *
14 * @package ConvertKit
15 * @author ConvertKit
16 */
17 class ConvertKit_Admin_Post {
18
19 /**
20 * Registers action and filter hooks.
21 *
22 * @since 1.9.6
23 */
24 public function __construct() {
25
26 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
27 add_action( 'save_post', array( $this, 'save_post_meta' ) );
28
29 }
30
31 /**
32 * Adds a meta box for the given Post Type.
33 *
34 * @since 1.9.6
35 *
36 * @param string $post_type Post Type.
37 */
38 public function add_meta_boxes( $post_type ) {
39
40 // Don't register the meta box if this Post Type isn't supported.
41 $supported_post_types = convertkit_get_supported_post_types();
42 if ( ! in_array( $post_type, $supported_post_types, true ) ) {
43 return;
44 }
45
46 // Registe Meta Box.
47 add_meta_box( 'wp-convertkit-meta-box', __( 'ConvertKit', 'convertkit' ), array( $this, 'display_meta_box' ), $post_type, 'normal' );
48
49 }
50
51 /**
52 * Outputs the meta box.
53 *
54 * @since 1.9.6
55 *
56 * @param WP_Post $post The Post being edited.
57 */
58 public function display_meta_box( $post ) {
59
60 // Don't register the meta box if this Post is the blog archive page.
61 if ( $post->ID === get_option( 'page_for_posts' ) ) {
62 return;
63 }
64
65 // Show a warning if the API credentials haven't been set.
66 $settings = new ConvertKit_Settings();
67 if ( ! $settings->has_api_key_and_secret() ) {
68 $post_type = get_post_type_object( $post->post_type );
69 include CONVERTKIT_PLUGIN_PATH . '/views/backend/post/no-api-key.php';
70 return;
71 }
72
73 // Fetch Post Settings, Forms, Landing Pages and Tags.
74 $convertkit_post = new ConvertKit_Post( $post->ID );
75 $convertkit_forms = new ConvertKit_Resource_Forms();
76 $convertkit_landing_pages = new ConvertKit_Resource_Landing_Pages();
77 $convertkit_tags = new ConvertKit_Resource_Tags();
78
79 // Get settings page link.
80 $settings_link = convertkit_get_settings_link();
81
82 // Load metabox view.
83 include CONVERTKIT_PLUGIN_PATH . '/views/backend/post/meta-box.php';
84
85 }
86
87 /**
88 * Save Post Settings.
89 *
90 * @since 1.9.6
91 *
92 * @param int $post_id Post ID.
93 */
94 public function save_post_meta( $post_id ) {
95
96 // Bail if this is an autosave.
97 if ( wp_is_post_autosave( $post_id ) ) {
98 return;
99 }
100
101 // Bail if this is a post revision.
102 if ( wp_is_post_revision( $post_id ) ) {
103 return;
104 }
105
106 // Bail if no nonce field exists.
107 if ( ! isset( $_POST['wp-convertkit-save-meta-nonce'] ) ) {
108 return;
109 }
110
111 // Bail if the nonce verification fails.
112 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wp-convertkit-save-meta-nonce'] ) ), 'wp-convertkit-save-meta' ) ) {
113 return;
114 }
115
116 // Bail if no ConvertKit settings were posted.
117 if ( ! isset( $_POST['wp-convertkit'] ) ) {
118 return;
119 }
120
121 // Build metadata.
122 $meta = array(
123 'form' => ( isset( $_POST['wp-convertkit']['form'] ) ? sanitize_text_field( wp_unslash( $_POST['wp-convertkit']['form'] ) ) : '-1' ),
124 'landing_page' => ( isset( $_POST['wp-convertkit']['landing_page'] ) ? sanitize_text_field( wp_unslash( $_POST['wp-convertkit']['landing_page'] ) ) : '' ),
125 'tag' => ( isset( $_POST['wp-convertkit']['tag'] ) ? sanitize_text_field( wp_unslash( $_POST['wp-convertkit']['tag'] ) ) : '' ),
126 );
127
128 // Save metadata.
129 $convertkit_post = new ConvertKit_Post( $post_id );
130 return $convertkit_post->save( $meta );
131
132 }
133
134 }
135