PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.4.3
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-quick-edit.php

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

128 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Admin Quick Edit class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Registers settings fields for output when using WordPress' Quick Edit functionality
11 * in a Post, Page or Custom Post Type WP_List_Table.
12 *
13 * @package ConvertKit
14 * @author ConvertKit
15 */
16 class ConvertKit_Admin_Quick_Edit {
17
18 /**
19 * Registers action and filter hooks.
20 *
21 * @since 1.9.8.0
22 */
23 public function __construct() {
24
25 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
26 add_action( 'add_inline_data', array( $this, 'quick_edit_inline_data' ) );
27
28 }
29
30 /**
31 * Enqueues scripts and CSS for Quick Edit functionality in the Post, Page and Custom Post WP_List_Tables
32 *
33 * @since 1.9.8.0
34 */
35 public function enqueue_assets() {
36
37 // Bail if we cannot determine the screen.
38 if ( ! function_exists( 'get_current_screen' ) ) {
39 return;
40 }
41
42 // Bail if we're not on a Post Type Edit screen.
43 $screen = get_current_screen();
44 if ( $screen->base !== 'edit' ) {
45 return;
46 }
47
48 // Bail if the Post isn't a supported Post Type.
49 if ( ! in_array( $screen->post_type, convertkit_get_supported_post_types(), true ) ) {
50 return;
51 }
52
53 // Enqueue JS.
54 wp_enqueue_script( 'convertkit-admin-quick-edit', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quick-edit.js', array(), CONVERTKIT_PLUGIN_VERSION, true );
55
56 // Enqueue CSS.
57 wp_enqueue_style( 'convertkit-admin-bulk-quick-edit', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/bulk-quick-edit.css', array(), CONVERTKIT_PLUGIN_VERSION );
58
59 }
60
61 /**
62 * Outputs hidden inline data in each Post's Title column, which the Quick Edit
63 * JS can read when the user clicks the Quick Edit link in a WP_List_Table.
64 *
65 * @since 1.9.8.0
66 *
67 * @param WP_Post $post Post.
68 */
69 public function quick_edit_inline_data( $post ) {
70
71 // Bail if the Post isn't a supported Post Type.
72 if ( ! in_array( $post->post_type, convertkit_get_supported_post_types(), true ) ) {
73 return;
74 }
75
76 // Fetch Post's Settings.
77 $settings = new ConvertKit_Post( $post->ID );
78
79 // Output the Post's ConvertKit settings as hidden data- attributes, which
80 // the Quick Edit JS can read.
81 foreach ( $settings->get() as $key => $value ) {
82 // If the value is blank, set it to zero.
83 // This allows Quick Edit's JS to select the correct <option> value.
84 if ( $value === '' ) {
85 $value = 0;
86 }
87 ?>
88 <div class="convertkit" data-setting="<?php echo esc_attr( $key ); ?>" data-value="<?php echo esc_attr( $value ); ?>"><?php echo esc_attr( $value ); ?></div>
89 <?php
90 }
91
92 // Output Quick Edit fields in the footer of the Administration screen.
93 add_action( 'in_admin_footer', array( $this, 'quick_edit_fields' ), 10 );
94
95 }
96
97 /**
98 * Outputs Quick Edit settings fields in the footer of the administration screen.
99 *
100 * The Quick Edit JS will then move these hidden fields into the Quick Edit row
101 * when the user clicks on a Quick Edit link in the WP_List_Table.
102 *
103 * @since 1.9.8.0
104 */
105 public function quick_edit_fields() {
106
107 // Don't output Quick Edit fields if the API settings have not been defined.
108 $settings = new ConvertKit_Settings();
109 if ( ! $settings->has_api_key_and_secret() ) {
110 return;
111 }
112
113 // Initialize Restrict Content Settings class.
114 $restrict_content_settings = new ConvertKit_Settings_Restrict_Content();
115
116 // Fetch Forms, Landing Pages, Products and Tags.
117 $convertkit_forms = new ConvertKit_Resource_Forms();
118 $convertkit_landing_pages = new ConvertKit_Resource_Landing_Pages();
119 $convertkit_products = new ConvertKit_Resource_Products();
120 $convertkit_tags = new ConvertKit_Resource_Tags();
121
122 // Output view.
123 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/post/quick-edit.php';
124
125 }
126
127 }
128