| 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're not on a Post Type Edit screen. |
| 38 |
if ( convertkit_get_current_screen( 'base' ) !== 'edit' ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
// Bail if the Post isn't a supported Post Type. |
| 43 |
if ( ! in_array( convertkit_get_current_screen( 'post_type' ), convertkit_get_supported_post_types(), true ) ) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
// Enqueue JS. |
| 48 |
wp_enqueue_script( 'convertkit-admin-quick-edit', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quick-edit.js', array(), CONVERTKIT_PLUGIN_VERSION, true ); |
| 49 |
|
| 50 |
// Enqueue CSS. |
| 51 |
wp_enqueue_style( 'convertkit-admin-bulk-quick-edit', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/bulk-quick-edit.css', array(), CONVERTKIT_PLUGIN_VERSION ); |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Outputs hidden inline data in each Post's Title column, which the Quick Edit |
| 57 |
* JS can read when the user clicks the Quick Edit link in a WP_List_Table. |
| 58 |
* |
| 59 |
* @since 1.9.8.0 |
| 60 |
* |
| 61 |
* @param WP_Post $post Post. |
| 62 |
*/ |
| 63 |
public function quick_edit_inline_data( $post ) { |
| 64 |
|
| 65 |
// Bail if the Post isn't a supported Post Type. |
| 66 |
if ( ! in_array( $post->post_type, convertkit_get_supported_post_types(), true ) ) { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
// Fetch Post's Settings. |
| 71 |
$settings = new ConvertKit_Post( $post->ID ); |
| 72 |
|
| 73 |
// Output the Post's ConvertKit settings as hidden data- attributes, which |
| 74 |
// the Quick Edit JS can read. |
| 75 |
foreach ( $settings->get() as $key => $value ) { |
| 76 |
// If the value is blank, set it to zero. |
| 77 |
// This allows Quick Edit's JS to select the correct <option> value. |
| 78 |
if ( $value === '' ) { |
| 79 |
$value = 0; |
| 80 |
} |
| 81 |
?> |
| 82 |
<div class="convertkit" data-setting="<?php echo esc_attr( $key ); ?>" data-value="<?php echo esc_attr( $value ); ?>"><?php echo esc_attr( $value ); ?></div> |
| 83 |
<?php |
| 84 |
} |
| 85 |
|
| 86 |
// Output Quick Edit fields in the footer of the Administration screen. |
| 87 |
add_action( 'in_admin_footer', array( $this, 'quick_edit_fields' ), 10 ); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Outputs Quick Edit settings fields in the footer of the administration screen. |
| 93 |
* |
| 94 |
* The Quick Edit JS will then move these hidden fields into the Quick Edit row |
| 95 |
* when the user clicks on a Quick Edit link in the WP_List_Table. |
| 96 |
* |
| 97 |
* @since 1.9.8.0 |
| 98 |
*/ |
| 99 |
public function quick_edit_fields() { |
| 100 |
|
| 101 |
// Don't output Quick Edit fields if the API settings have not been defined. |
| 102 |
$settings = new ConvertKit_Settings(); |
| 103 |
if ( ! $settings->has_access_and_refresh_token() ) { |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
// Initialize Restrict Content Settings class. |
| 108 |
$restrict_content_settings = new ConvertKit_Settings_Restrict_Content(); |
| 109 |
|
| 110 |
// Fetch Forms, Landing Pages, Products and Tags. |
| 111 |
$convertkit_forms = new ConvertKit_Resource_Forms(); |
| 112 |
$convertkit_landing_pages = new ConvertKit_Resource_Landing_Pages(); |
| 113 |
$convertkit_products = new ConvertKit_Resource_Products(); |
| 114 |
$convertkit_tags = new ConvertKit_Resource_Tags(); |
| 115 |
|
| 116 |
// Output view. |
| 117 |
require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/post/quick-edit.php'; |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
} |
| 122 |
|