Making WordPress.org


Ignore:
Timestamp:
08/01/2023 10:11:00 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Admin: Display admin notice when publication of photo post failed due to one or more custom taxonomies not having a term assigned.

See #7171.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/admin.php

    r12769 r12772  
    5757                add_action( 'admin_notices',                           [ __CLASS__, 'add_notice_if_flagged_or_unflagged' ] );
    5858
     59                // Admin notice related to failed publication due to missing taxonomy values.
     60                add_action( 'admin_notices',                           [ __CLASS__, 'add_notice_if_publish_failed_due_to_missing_taxonomies' ] );
     61
    5962                // Modify admin menu links for photo posts.
    6063                add_action( 'admin_menu',                              [ __CLASS__, 'modify_admin_menu_links' ] );
    … …  
    7073
    7174        /**
    72          * Outputs admin notices.
     75         * Outputs admin notice if submissions are currently disabled due to the killswitch.
    7376         */
    7477        public static function add_notice_if_killswitch_enabled() {
    … …  
    8891
    8992        /**
    90          * Outputs admin notices.
     93         * Outputs admin notice indicating if a photo post is flagged or has been unflagged.
    9194         */
    9295        public static function add_notice_if_flagged_or_unflagged() {
    … …  
    145148                        )
    146149                );
     150        }
     151
     152        /**
     153         * Outputs admin notice if a photo post publication failed due to any custom
     154         * taxonomy not having a value assigned.
     155         */
     156        public static function add_notice_if_publish_failed_due_to_missing_taxonomies() {
     157                global $post;
     158
     159                $meta_key = Posts::META_KEY_MISSING_TAXONOMIES;
     160
     161                if ( isset( $post->ID ) ) {
     162                        $missing_taxonomies = get_post_meta( $post->ID, $meta_key, true );
     163
     164                        if ( $missing_taxonomies ) {
     165                                echo '<div class="notice notice-error is-dismissible notice-missing-taxonomies"><p>';
     166                                printf(
     167                                        __( '<strong>Error:</strong> Photo was not published because the following taxonomies are missing terms: %s', 'wporg-photos' ),
     168                                        '<strong>' . implode( '</strong>, <strong>', $missing_taxonomies ) . '</strong>'
     169                                );
     170
     171                                echo '</p></div>' . "\n";
     172                                delete_post_meta( $post->ID, $meta_key );
     173                        }
     174                }
    147175        }
    148176
Note: See TracChangeset for help on using the changeset viewer.