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

154 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 if ( $screen->id !== 'edit-category' ) {
53 return;
54 }
55
56 // Bail if the API hasn't been configured.
57 $settings = new ConvertKit_Settings();
58 if ( ! $settings->has_api_key_and_secret() ) {
59 return;
60 }
61
62 // Enqueue Select2 JS.
63 convertkit_select2_enqueue_scripts();
64
65 /**
66 * Enqueue JavaScript when editing a Category that outputs
67 * ConvertKit Plugin settings.
68 *
69 * @since 1.9.6.4
70 */
71 do_action( 'convertkit_admin_category_enqueue_scripts' );
72
73 }
74
75 /**
76 * Enqueue CSS when editing a Category that outputs
77 * ConvertKit Plugin settings.
78 *
79 * @since 1.9.6.4
80 */
81 public function enqueue_styles() {
82
83 // Enqueue Select2 CSS.
84 convertkit_select2_enqueue_styles();
85
86 /**
87 * Enqueue CSS when editing a Category that outputs
88 * ConvertKit Plugin settings.
89 *
90 * @since 1.9.6.4
91 */
92 do_action( 'convertkit_admin_category_enqueue_styles' );
93
94 }
95
96 /**
97 * Display the ConvertKit Forms dropdown when editing a Category
98 *
99 * @since 1.9.6
100 *
101 * @param WP_Term $term Category.
102 */
103 public function category_form_fields( $term ) {
104
105 // Don't show the form fields if the API hasn't been configured.
106 $settings = new ConvertKit_Settings();
107 if ( ! $settings->has_api_key_and_secret() ) {
108 return;
109 }
110
111 // Fetch Category Settings and Forms.
112 $convertkit_term = new ConvertKit_Term( $term->term_id );
113 $convertkit_forms = new ConvertKit_Resource_Forms();
114
115 // Load metabox view.
116 include CONVERTKIT_PLUGIN_PATH . '/views/backend/term/fields.php';
117
118 }
119
120 /**
121 * Save Term Settings.
122 *
123 * @since 1.9.6
124 *
125 * @param int $term_id Term ID.
126 */
127 public function save_category_fields( $term_id ) {
128
129 // Bail if no nonce field exists.
130 if ( ! isset( $_POST['wp-convertkit-save-meta-nonce'] ) ) {
131 return;
132 }
133
134 // Bail if the nonce verification fails.
135 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wp-convertkit-save-meta-nonce'] ) ), 'wp-convertkit-save-meta' ) ) {
136 return;
137 }
138
139 // Bail if no ConvertKit settings were posted.
140 if ( ! isset( $_POST['wp-convertkit'] ) ) {
141 return;
142 }
143
144 // Build metadata.
145 $meta = ( isset( $_POST['wp-convertkit']['form'] ) ? intval( $_POST['wp-convertkit']['form'] ) : '' );
146
147 // Save metadata.
148 $convertkit_term = new ConvertKit_Term( $term_id );
149 return $convertkit_term->save( $meta );
150
151 }
152
153 }
154