• Sander

    (@sander-falise)


    I love you plugin, it works great on posts and pages. However, I would love to see support for custom post types. I’ve changed some of your code and added filters for the post-type checks and that seems to work. This kind of breaks your plugin as it no longed listens to the checkboxes on the settings page. A better solution would be to add checkbox lists for post types to show the css editor and another checkbox list for using code highlighting per post type.

    Changes made in post-page-specific-custom-css.php

    // line 113
    $post_types = apply_filters( 'ppsccss-post-types', array( 'post', 'page' ) );
    if ( in_array( $screen->id, $post_types )  && in_array( $screen->post_type, $post_types ) ) {
      $field = self::POST_ENABLE_HIGHLIGHTING;
    }
    
    // line 606
    $post_types = apply_filters( 'ppsccss-post-types', array( 'post', 'page' ) );
    if ( !in_array( $_POST['post_type'], $post_types ) ) {
      return;
    }
    
    // line 562
    public function add_meta_boxes() 
    {
      $post_types = apply_filters( 'ppsccss-post-types', array( 'post', 'page' ) );
      if ( $this->allowedToView() ) {
        add_meta_box( 'phylax_ppsccss', __( 'Custom CSS', 'postpage-specific-custom-css' ), [
          $this,
         'render_phylax_ppsccss',
          ], $post_types, 'advanced', 'high' );
      }
    }
    
    // line 637, remove the switch statement and replaced if with this
    $post_types = apply_filters( 'ppsccss-post-types', array( 'post', 'page' ) );
    if ( in_array( $post->post_type, $post_types ) )
    {
      $theField     = self::POST_ENABLE_HIGHLIGHTING;
      // Opted for post, could also be page
      $defaultField = self::OPT_DEFAULT_POST_CSS;
      // No need to specify post / page
      $screen       = __( 'Custom stylesheet', 'postpage-specific-custom-css' );
    }
    • This topic was modified 2 years, 11 months ago by Jan Dembowski. Reason: Formatting
Viewing 1 replies (of 1 total)
  • Plugin Author ?ukasz Nowicki

    (@lukasznowicki)

    Hello @sander-falise thank you for your message
    I know, of course, how to support custom post types, I plan this feature for version 0.3. I’m not sure if I will make it for existing, well known custom post types like Woocommerce, or all of them, I will see, because I planning pro version supporting JavaScript as well.
    Feel free to fork that code of course, if you need this feature now, however version 0.3 will be much more easier to handle all the setup and features for CPT
    Kind regards
    Lukasz

Viewing 1 replies (of 1 total)
  • The topic ‘Custom post type support’ is closed to new replies.