class-activation.php
2 years ago
class-admin-columns-manager.php
2 years ago
class-admin-menu-organizer.php
2 years ago
class-auto-publish-posts-with-missed-schedule.php
2 years ago
class-avif-upload.php
2 years ago
class-change-login-url.php
2 years ago
class-cleanup-admin-bar.php
2 years ago
class-code-snippets-manager.php
2 years ago
class-common-methods.php
2 years ago
class-content-duplication.php
2 years ago
class-content-order.php
2 years ago
class-custom-admin-footer-text.php
2 years ago
class-custom-body-class.php
2 years ago
class-custom-content-types.php
2 years ago
class-custom-css.php
2 years ago
class-custom-nav-menu-items-in-new-tab.php
2 years ago
class-deactivation.php
2 years ago
class-disable-comments.php
2 years ago
class-disable-dashboard-widgets.php
2 years ago
class-disable-feeds.php
2 years ago
class-disable-gutenberg.php
2 years ago
class-disable-rest-api.php
2 years ago
class-disable-smaller-components.php
2 years ago
class-disable-updates.php
2 years ago
class-disable-xml-rpc.php
2 years ago
class-display-system-summary.php
2 years ago
class-email-address-obfuscator.php
2 years ago
class-email-delivery.php
2 years ago
class-enhance-list-tables.php
2 years ago
class-external-permalinks.php
2 years ago
class-heartbeat-control.php
2 years ago
class-hide-admin-bar.php
2 years ago
class-hide-admin-notices.php
2 years ago
class-image-sizes-panel.php
2 years ago
class-image-upload-control.php
2 years ago
class-insert-head-body-footer-code.php
2 years ago
class-last-login-column.php
2 years ago
class-limit-login-attempts.php
2 years ago
class-login-id-type.php
2 years ago
class-login-logout-menu.php
2 years ago
class-maintenance-mode.php
2 years ago
class-manage-ads-appads-txt.php
2 years ago
class-manage-robots-txt.php
2 years ago
class-media-replacement.php
2 years ago
class-multiple-user-roles.php
2 years ago
class-obfuscate-author-slugs.php
2 years ago
class-open-external-links-in-new-tab.php
2 years ago
class-password-protection.php
2 years ago
class-redirect-after-login.php
2 years ago
class-redirect-after-logout.php
2 years ago
class-redirect-fourofour.php
2 years ago
class-revisions-control.php
2 years ago
class-search-engines-visibility.php
2 years ago
class-settings-fields-render.php
2 years ago
class-settings-sanitization.php
2 years ago
class-settings-sections-fields.php
2 years ago
class-show-custom-taxonomy-filters.php
2 years ago
class-site-identity-on-login-page.php
2 years ago
class-svg-upload.php
2 years ago
class-various-admin-ui-enhancements.php
2 years ago
class-view-admin-as-role.php
2 years ago
class-wider-admin-menu.php
2 years ago
class-admin-columns-manager.php
254 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | use ArrayObject; |
| 6 | use NumberFormatter; |
| 7 | /** |
| 8 | * Class for Admin Columns Manager module |
| 9 | * |
| 10 | * @since 6.9.5 |
| 11 | */ |
| 12 | class Admin_Columns_Manager { |
| 13 | /** |
| 14 | * Get and set default columns |
| 15 | * |
| 16 | * @since 6.0.9 |
| 17 | */ |
| 18 | public function get_default_columns( $post_type ) { |
| 19 | global $taxonomy_slugs; |
| 20 | // indexed array of taxonomy slugs |
| 21 | $available_columns = array( |
| 22 | 'date_published' => 'Published', |
| 23 | 'postid' => 'ID', |
| 24 | 'modified' => 'Last Modified', |
| 25 | 'password_protected' => 'Password Protected', |
| 26 | 'permalink' => 'Permalink', |
| 27 | 'slug' => 'Slug', |
| 28 | 'status' => 'Status', |
| 29 | 'date' => 'Date', |
| 30 | 'post_parent' => 'Post Parent', |
| 31 | 'menu_order' => 'Menu Order', |
| 32 | ); |
| 33 | if ( 'post' == $post_type ) { |
| 34 | $available_columns['sticky'] = 'Sticky'; |
| 35 | } |
| 36 | if ( post_type_supports( $post_type, 'title' ) ) { |
| 37 | $available_columns['title'] = 'Title'; |
| 38 | // $available_columns['title_raw'] = 'Title Only'; |
| 39 | } |
| 40 | if ( post_type_supports( $post_type, 'editor' ) || post_type_supports( $post_type, 'excerpt' ) ) { |
| 41 | $available_columns['excerpt'] = 'Excerpt'; |
| 42 | } |
| 43 | if ( post_type_supports( $post_type, 'thumbnail' ) ) { |
| 44 | $available_columns['featured_image'] = 'Featured Image'; |
| 45 | } |
| 46 | if ( post_type_supports( $post_type, 'author' ) ) { |
| 47 | $available_columns['author'] = 'Author'; |
| 48 | // $available_columns['author_name'] = 'Author'; |
| 49 | // $available_columns['last_modified_author'] = 'Last Modified Author'; |
| 50 | } |
| 51 | if ( post_type_supports( $post_type, 'post-formats' ) ) { |
| 52 | $available_columns['post_formats'] = 'Post Format'; |
| 53 | } |
| 54 | if ( post_type_supports( $post_type, 'comments' ) ) { |
| 55 | $available_columns['comments'] = 'Comments'; |
| 56 | $available_columns['comment_count'] = 'Comment Count'; |
| 57 | $available_columns['comment_status'] = 'Allow Comment'; |
| 58 | } |
| 59 | if ( post_type_supports( $post_type, 'trackbacks' ) ) { |
| 60 | $available_columns['ping_status'] = 'Ping Status'; |
| 61 | } |
| 62 | // Already included by default |
| 63 | // if ( post_type_supports( $post_type, 'page-attributes' ) || is_post_type_hierarchical( $post_type ) ) { |
| 64 | // $available_columns['post_parent'] = 'Post Parent'; |
| 65 | // $available_columns['menu_order'] = 'Menu Order'; |
| 66 | // } |
| 67 | if ( 'wp_block' == $post_type ) { |
| 68 | $available_columns['wp_pattern_sync_status'] = 'Sync Status'; |
| 69 | } |
| 70 | if ( 'shop_order' == $post_type ) { |
| 71 | $available_columns['products_ordered'] = 'Products'; |
| 72 | } |
| 73 | // Add taxonomy columns according to the custom taxonomies assigned to each post type |
| 74 | $attached_taxonomies = get_object_taxonomies( $post_type ); |
| 75 | if ( !empty( $attached_taxonomies ) ) { |
| 76 | $taxonomy_slugs = array(); |
| 77 | foreach ( $attached_taxonomies as $taxonomy_slug ) { |
| 78 | $taxonomy_object = get_taxonomy( $taxonomy_slug ); |
| 79 | $taxonomy_label = $taxonomy_object->labels->name; |
| 80 | if ( 'category' == $taxonomy_slug ) { |
| 81 | $taxonomy_slug = 'categories'; |
| 82 | } elseif ( 'post_tag' == $taxonomy_slug ) { |
| 83 | $taxonomy_slug = 'tags'; |
| 84 | } |
| 85 | $taxonomy_slugs[] = $taxonomy_slug; |
| 86 | $available_columns[$taxonomy_slug] = $taxonomy_label; |
| 87 | } |
| 88 | } |
| 89 | // Sort by array value in ascending order, so they are displayed in that order in the 'Default' pane |
| 90 | asort( $available_columns ); |
| 91 | $options = get_option( ASENHA_SLUG_U . '_extra', array() ); |
| 92 | $options['admin_columns_available'][$post_type] = $available_columns; |
| 93 | update_option( ASENHA_SLUG_U . '_extra', $options, true ); |
| 94 | return $available_columns; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Get ACF field object data |
| 99 | * |
| 100 | * @since 6.3.0 |
| 101 | */ |
| 102 | public function get_acf_field_object( |
| 103 | $column_name = '', |
| 104 | $post_id = false, |
| 105 | $in_collection = false, |
| 106 | $parent_field = false, |
| 107 | $parent_type = '' |
| 108 | ) { |
| 109 | $field_data = array(); |
| 110 | if ( !$in_collection ) { |
| 111 | $field_data = get_field_object( $column_name, $post_id ); |
| 112 | } else { |
| 113 | $parent_field_data = get_field_object( $parent_field, $post_id ); |
| 114 | if ( 'group' == $parent_type || 'repeater' == $parent_type ) { |
| 115 | $sub_fields = $parent_field_data['sub_fields']; |
| 116 | foreach ( $sub_fields as $sub_field ) { |
| 117 | if ( $column_name == $sub_field['name'] ) { |
| 118 | $field_data = $sub_field; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | if ( 'flexible_content' == $parent_type ) { |
| 123 | $layouts = $parent_field_data['layouts']; |
| 124 | foreach ( $layouts as $layout ) { |
| 125 | $sub_fields = $layout['sub_fields']; |
| 126 | foreach ( $sub_fields as $sub_field ) { |
| 127 | if ( $column_name == $sub_field['name'] ) { |
| 128 | $field_data = $sub_field; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | return $field_data; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Reload list table after performing Quick Edit on post types with custom admin columns |
| 139 | * This is modified from wp_ajax_inline_save() by adding a script before wp_die() at the end |
| 140 | * |
| 141 | * @link https://github.com/WordPress/wordpress-develop/blob/6.3/src/wp-admin/includes/ajax-actions.php#L2049-L2159 |
| 142 | * @since 6.0.6 |
| 143 | */ |
| 144 | public function wp_ajax_inline_save_with_page_reload() { |
| 145 | global $mode; |
| 146 | check_ajax_referer( 'inlineeditnonce', '_inline_edit' ); |
| 147 | if ( !isset( $_POST['post_ID'] ) || !(int) $_POST['post_ID'] ) { |
| 148 | wp_die(); |
| 149 | } |
| 150 | $post_id = (int) $_POST['post_ID']; |
| 151 | if ( 'page' === $_POST['post_type'] ) { |
| 152 | if ( !current_user_can( 'edit_page', $post_id ) ) { |
| 153 | wp_die( esc_html( __( 'Sorry, you are not allowed to edit this page.' ) ) ); |
| 154 | } |
| 155 | } else { |
| 156 | if ( !current_user_can( 'edit_post', $post_id ) ) { |
| 157 | wp_die( esc_html( __( 'Sorry, you are not allowed to edit this post.' ) ) ); |
| 158 | } |
| 159 | } |
| 160 | $last = wp_check_post_lock( $post_id ); |
| 161 | if ( $last ) { |
| 162 | $last_user = get_userdata( $last ); |
| 163 | $last_user_name = ( $last_user ? $last_user->display_name : __( 'Someone' ) ); |
| 164 | /* translators: %s: User's display name. */ |
| 165 | $msg_template = __( 'Saving is disabled: %s is currently editing this post.' ); |
| 166 | if ( 'page' === $_POST['post_type'] ) { |
| 167 | /* translators: %s: User's display name. */ |
| 168 | $msg_template = __( 'Saving is disabled: %s is currently editing this page.' ); |
| 169 | } |
| 170 | printf( esc_html( $msg_template ), esc_html( $last_user_name ) ); |
| 171 | wp_die(); |
| 172 | } |
| 173 | $data =& $_POST; |
| 174 | $post = get_post( $post_id, ARRAY_A ); |
| 175 | // Since it's coming from the database. |
| 176 | $post = wp_slash( $post ); |
| 177 | $data['content'] = $post['post_content']; |
| 178 | $data['excerpt'] = $post['post_excerpt']; |
| 179 | // Rename. |
| 180 | $data['user_ID'] = get_current_user_id(); |
| 181 | if ( isset( $data['post_parent'] ) ) { |
| 182 | $data['parent_id'] = $data['post_parent']; |
| 183 | } |
| 184 | // Status. |
| 185 | if ( isset( $data['keep_private'] ) && 'private' === $data['keep_private'] ) { |
| 186 | $data['visibility'] = 'private'; |
| 187 | $data['post_status'] = 'private'; |
| 188 | } else { |
| 189 | $data['post_status'] = $data['_status']; |
| 190 | } |
| 191 | if ( empty( $data['comment_status'] ) ) { |
| 192 | $data['comment_status'] = 'closed'; |
| 193 | } |
| 194 | if ( empty( $data['ping_status'] ) ) { |
| 195 | $data['ping_status'] = 'closed'; |
| 196 | } |
| 197 | // Exclude terms from taxonomies that are not supposed to appear in Quick Edit. |
| 198 | if ( !empty( $data['tax_input'] ) ) { |
| 199 | foreach ( $data['tax_input'] as $taxonomy => $terms ) { |
| 200 | $tax_object = get_taxonomy( $taxonomy ); |
| 201 | /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */ |
| 202 | if ( !apply_filters( |
| 203 | 'quick_edit_show_taxonomy', |
| 204 | $tax_object->show_in_quick_edit, |
| 205 | $taxonomy, |
| 206 | $post['post_type'] |
| 207 | ) ) { |
| 208 | unset($data['tax_input'][$taxonomy]); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published. |
| 213 | if ( !empty( $data['post_name'] ) && in_array( $post['post_status'], array('draft', 'pending'), true ) ) { |
| 214 | $post['post_status'] = 'publish'; |
| 215 | $data['post_name'] = wp_unique_post_slug( |
| 216 | $data['post_name'], |
| 217 | $post['ID'], |
| 218 | $post['post_status'], |
| 219 | $post['post_type'], |
| 220 | $post['post_parent'] |
| 221 | ); |
| 222 | } |
| 223 | // Update the post. |
| 224 | edit_post(); |
| 225 | $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( |
| 226 | 'screen' => $_POST['screen'], |
| 227 | ) ); |
| 228 | $mode = ( 'excerpt' === $_POST['post_view'] ? 'excerpt' : 'list' ); |
| 229 | $level = 0; |
| 230 | if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) { |
| 231 | $request_post = array(get_post( $_POST['post_ID'] )); |
| 232 | $parent = $request_post[0]->post_parent; |
| 233 | while ( $parent > 0 ) { |
| 234 | $parent_post = get_post( $parent ); |
| 235 | $parent = $parent_post->post_parent; |
| 236 | $level++; |
| 237 | } |
| 238 | } |
| 239 | $wp_list_table->display_rows( array(get_post( $_POST['post_ID'] )), $level ); |
| 240 | // INTERCEPT: Add a script to reload the list table page |
| 241 | ?> |
| 242 | <script type="text/javascript"> |
| 243 | jQuery('#post-<?php |
| 244 | echo esc_attr( $_POST['post_ID'] ); |
| 245 | ?>').css('opacity','0.3'); |
| 246 | document.location.reload(true); |
| 247 | </script> |
| 248 | <?php |
| 249 | // end INTERCEPT |
| 250 | wp_die(); |
| 251 | } |
| 252 | |
| 253 | } |
| 254 |