Making WordPress.org

Changeset 12780


Ignore:
Timestamp:
08/01/2023 10:29:31 PM (19 months ago)
Author:
coffee2code
Message:

Photo Directory, Admin: Force use of the text editor.

There is no need to facilitate making use of visual elements since no markup should be used.

See #7171.

File:
1 edited

Legend:

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

    r12776 r12780  
    7373        // Add class(es) to body tag.
    7474        add_filter( 'admin_body_class',                        [ __CLASS__, 'add_body_class' ] );
     75
     76        // Disable visual editor.
     77            // Prevent the visual editor from being loaded.
     78            add_filter( 'user_can_richedit',                   [ __CLASS__, 'disable_rich_editing' ] );
     79            // Force the default editor to be the HTML editor.
     80            add_filter( 'wp_default_editor',                   [ __CLASS__, 'force_text_editor' ], 99 );
    7581    }
    7682
     
    12731279    }
    12741280
     1281    /**
     1282     * Disables rich editor for photo posts.
     1283     *
     1284     * @param bool $user_can Can the user rich edit?
     1285     * @return bool
     1286     */
     1287    public static function disable_rich_editing( $user_can ) {
     1288        $post = get_post();
     1289        if ( $user_can && $post && get_post_type( $post ) === Registrations::get_post_type() ) {
     1290            $user_can = false;
     1291        }
     1292
     1293        return $user_can;
     1294    }
     1295
     1296    /**
     1297     * Forces use of the text editor for photo posts.
     1298     *
     1299     * @param string $default The default editor as chosen by user or defaulted by WP.
     1300     * @return string 'html'
     1301     */
     1302    public static function force_text_editor( $default ) {
     1303        $post = get_post();
     1304        if ( $post && get_post_type( $post ) === Registrations::get_post_type() ) {
     1305            $default = 'html';
     1306        }
     1307
     1308        return $default;
     1309    }
     1310
    12751311}
    12761312
Note: See TracChangeset for help on using the changeset viewer.