• Resolved ImageKingsley Felix

    (@iamkingsleyf)


    Hi,

    I have custom post types on a site which i want the plugin to work with, but by default it is enabled on post and pages, how do i disable the plugin from affecting the post/page editor and only work for my custom post type?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ImagePierre-Henri Lavigne

    (@peter202202)

    Hi @iamkingsleyf

    And thank you for using Markup Markdown. 🤝

    The information you are looking for is available from the following tutorial :
    https://www.markup-markdown.com/wordpress-tutorials/setting-custom-post-type/

    You should be able to disable the editor with the default posts / pages with the following snippet :

    add_action('init', function() {
    remove_post_type_support('post', 'markup_markdown');
    remove_post_type_support('page', 'markup_markdown');
    });

    You can either directly edit the functions.php file inside your child theme by yourself if you are familiar with web development, or add the snippet through a plugin like Code Snippets. (I haven’t tested them all by the way neither is an affiliate)

    Feel free to test and tell me if that works for you 🤲

    Thread Starter ImageKingsley Felix

    (@iamkingsleyf)

    Thanks

    Thread Starter ImageKingsley Felix

    (@iamkingsleyf)

    Activating other plugins somehow turns it backon for post and pages.

    Thread Starter ImageKingsley Felix

    (@iamkingsleyf)

    This is the code we are using, for some reason the editor does not disable for normal post and pages...



    /**

     * Remove Markup Markdown support from standard post and page post types.

     *

     * KSM INTERNAL NOTE: Markup Markdown automatically adds support to ALL public post types.

     * We only want Markdown editing for IDB custom post types (idb_movie, idb_tv_show, idb_game, idb_spec, idb_book).

     * This filter removes support from the default 'post' and 'page' types so they continue using Gutenberg.

     *

     * ISSUE: Markup Markdown re-adds support when plugins activate/deactivate or post types re-register.

     * SOLUTION: Use multiple approaches - remove support AND filter the support check to ensure it stays disabled.

     *

     * @since 7.29.0

     * @since 7.32.4 - Enhanced to prevent re-activation on plugin activation/deactivation

     * @since 7.32.5 - Added filter-based approach to intercept support checks

     */

    function idb_remove_markdown_from_post_page()

    {

        // Only run if Markup Markdown is active

        if (!defined('MMD_PLUGIN_ACTIVATED') || !MMD_PLUGIN_ACTIVATED) {

            return;

        }

        // Remove Markup Markdown support from standard post types

        // Remove both variations (with hyphen and underscore) that Markup Markdown checks

        remove_post_type_support('post', 'markup_markdown');

        remove_post_type_support('post', 'markup-markdown');

        remove_post_type_support('page', 'markup_markdown');

        remove_post_type_support('page', 'markup-markdown');

    }

    /**

     * Filter Markup Markdown's mmd_disable_gutenberg to disable markdown editor for post/page.

     *

     * This uses Markup Markdown's actual filter hook to disable the markdown editor

     * for standard post and page types. When this returns false, the markdown editor

     * is NOT loaded and Gutenberg/Classic editor works normally.

     *

     * @since 7.32.5

     * @since 7.32.6 - Fixed: Use actual MMD filter instead of non-existent post_type_supports filter

     * @param bool $disable_gutenberg Whether to disable Gutenberg (true = use markdown editor).

     * @return bool False to use Gutenberg/Classic, true to use Markdown editor.

     */

    function idb_filter_mmd_disable_gutenberg($disable_gutenberg)

    {

        // Get current post type

        global $post, $typenow, $current_screen;

        $post_type = null;

        if ($post && $post->post_type) {

            $post_type = $post->post_type;

        } elseif ($typenow) {

            $post_type = $typenow;

        } elseif ($current_screen && $current_screen->post_type) {

            $post_type = $current_screen->post_type;

        } else {

            // Check GET/POST parameters

            $post_type = isset($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : null;

            if (!$post_type) {

                $post_type = isset($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : null;

            }

            if (!$post_type && isset($_GET['post'])) {

                $post_type = get_post_type((int) $_GET['post']);

            }

            if (!$post_type && isset($_POST['post'])) {

                $post_type = get_post_type((int) $_POST['post']);

            }

        }

        // Disable markdown editor for post and page (return false = don't disable Gutenberg = use normal editor)

        if ($post_type === 'post' || $post_type === 'page') {

            return false;

        }

        return $disable_gutenberg;

    }

    // Remove support on multiple hooks with very high priority

    add_action('init', 'idb_remove_markdown_from_post_page', 999);

    add_action('wp_loaded', 'idb_remove_markdown_from_post_page', 999);

    add_action('admin_init', 'idb_remove_markdown_from_post_page', 999);

    add_action('current_screen', 'idb_remove_markdown_from_post_page', 999);

    add_action('activated_plugin', 'idb_remove_markdown_from_post_page', 999);

    add_action('deactivated_plugin', 'idb_remove_markdown_from_post_page', 999);

    // Use Markup Markdown's actual filter to disable markdown editor for post/page

    // This filter is called in prepare_markdown_editor() at priority 9999

    // When this returns false, the markdown editor is disabled and normal editor is used

    add_filter('mmd_disable_gutenberg', 'idb_filter_mmd_disable_gutenberg', 20);
Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.