PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.0.2
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.0.2
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
convertkit / admin / class-convertkit-admin-category.php

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

155 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Admin Category class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Registers fields on Categories and saves its settings when the Category
11 * is saved in the WordPress Administration interface.
12 *
13 * @package ConvertKit
14 * @author ConvertKit
15 */
16 class ConvertKit_Admin_Category {
17
18 /**
19 * Registers action and filter hooks.
20 *
21 * @since 1.9.6
22 */
23 public function __construct() {
24
25 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
26 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
27 add_action( 'category_edit_form_fields', array( $this, 'category_form_fields' ), 20 );
28 add_action( 'edited_category', array( $this, 'save_category_fields' ), 20 );
29
30 }
31
32 /**
33 * Enqueue JavaScript when editing a Category that outputs
34 * ConvertKit Plugin settings.
35 *
36 * @since 1.9.6.4
37 *
38 * @param string $hook Hook.
39 */
40 public function enqueue_scripts( $hook ) {
41
42 // Bail if we are not editing a Term.
43 if ( $hook !== 'term.php' ) {
44 return;
45 }
46
47 // Bail if we are not editing a Category.
48 if ( ! function_exists( 'get_current_screen' ) ) {
49 return;
50 }
51 $screen = get_current_screen();
52
53 if ( $screen->id !== 'edit-category' ) {
54 return;
55 }
56
57 // Bail if the API hasn't been configured.
58 $settings = new ConvertKit_Settings();
59 if ( ! $settings->has_api_key_and_secret() ) {
60 return;
61 }
62
63 // Enqueue Select2 JS.
64 convertkit_select2_enqueue_scripts();
65
66 /**
67 * Enqueue JavaScript when editing a Category that outputs
68 * ConvertKit Plugin settings.
69 *
70 * @since 1.9.6.4
71 */
72 do_action( 'convertkit_admin_category_enqueue_scripts' );
73
74 }
75
76 /**
77 * Enqueue CSS when editing a Category that outputs
78 * ConvertKit Plugin settings.
79 *
80 * @since 1.9.6.4
81 */
82 public function enqueue_styles() {
83
84 // Enqueue Select2 CSS.
85 convertkit_select2_enqueue_styles();
86
87 /**
88 * Enqueue CSS when editing a Category that outputs
89 * ConvertKit Plugin settings.
90 *
91 * @since 1.9.6.4
92 */
93 do_action( 'convertkit_admin_category_enqueue_styles' );
94
95 }
96
97 /**
98 * Display the ConvertKit Forms dropdown when editing a Category
99 *
100 * @since 1.9.6
101 *
102 * @param WP_Term $term Category.
103 */
104 public function category_form_fields( $term ) {
105
106 // Don't show the form fields if the API hasn't been configured.
107 $settings = new ConvertKit_Settings();
108 if ( ! $settings->has_api_key_and_secret() ) {
109 return;
110 }
111
112 // Fetch Category Settings and Forms.
113 $convertkit_term = new ConvertKit_Term( $term->term_id );
114 $convertkit_forms = new ConvertKit_Resource_Forms();
115
116 // Load metabox view.
117 include CONVERTKIT_PLUGIN_PATH . '/views/backend/term/fields.php';
118
119 }
120
121 /**
122 * Save Term Settings.
123 *
124 * @since 1.9.6
125 *
126 * @param int $term_id Term ID.
127 */
128 public function save_category_fields( $term_id ) {
129
130 // Bail if no nonce field exists.
131 if ( ! isset( $_POST['wp-convertkit-save-meta-nonce'] ) ) {
132 return;
133 }
134
135 // Bail if the nonce verification fails.
136 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['wp-convertkit-save-meta-nonce'] ) ), 'wp-convertkit-save-meta' ) ) {
137 return;
138 }
139
140 // Bail if no ConvertKit settings were posted.
141 if ( ! isset( $_POST['wp-convertkit'] ) ) {
142 return;
143 }
144
145 // Build metadata.
146 $meta = ( isset( $_POST['wp-convertkit']['form'] ) ? intval( $_POST['wp-convertkit']['form'] ) : '' );
147
148 // Save metadata.
149 $convertkit_term = new ConvertKit_Term( $term_id );
150 return $convertkit_term->save( $meta );
151
152 }
153
154 }
155