Support Forum » User Profile

Forum Replies Created

Viewing 15 posts - 16 through 30 (of 35 total)
  • Author
    Posts
  • in reply to: get PHP code button does seem to do anything #19063
    hartsook@gmail.com[email protected]
    Participant

    ok, thank you. If you need admin access to the website I can provide that for you.

    in reply to: get PHP code button does seem to do anything #19061
    hartsook@gmail.com[email protected]
    Participant

    Metabox 5.2.8 and AIO 1.11.2 WordPress 5.4 Genesis theme

    in reply to: post Excerpt #18764
    hartsook@gmail.com[email protected]
    Participant

    getting very close 🙂

    Since I prefer to use the MB Builder to create the CPT and Custom Fields, I removed that part of the php code you put in pastebin so I'm left with something that works great except for one problem using Beaver Themer to layout the front end. Here is the code I'm using:

    /**
    * In MB Builder I have a custom field replace the post <strong>content</strong> by setting custom field "Reason for Snippet", wysiwyg field ID to content
    * I removed the custom post excerpt field from code snippets custom post type <strong>done through unchecking box in CPT setting </strong>
    * I removed the custom post content editor field from code snippets CPT <strong>done through unchecking box in CPT setting </strong>
    **/
    // what I'm left with is:
    // This is for content
    add_filter( 'rwmb_content_field_meta', function() {
        $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
        return get_post_field( 'post_content', $post_id );
    } );
    add_filter( 'rwmb_content_value', '__return_empty_string' );

    The custom field "Reason for Snippet" field content now shows up on the front end in Beaver Builder layouts that display posts where the excerpt would be. It turns out this is better than making that field the Excerpt because the manual excerpt field overrides controls on the front end like how many words are displayed. The Post modules in Beaver Builder for example will grab the post content and use it as an excerpt and you can set it to display say the first 25 words of the content if you want. If the custom field becomes the Excerpt then the whole field content is displayed instead regardless of the excerpt length setting. Also RSS feeds will grab part of the content when the Excerpt field is empty. So it's better to use the custom field as the content instead of the excerpt for my usage. But an advantage is a manual Excerpt field can have html which gets stripped out when grabbing the first n words of the content.

    Now for the problem I ran into with Beaver Themer. The wysiwyg field with ID set to content allows text formatting in both the visual and text tabs including Add Media, etc. But trying to display the MB custom field on the front end doesn't work.

    Using the Themer connector in a text or html module if I select a metabox field I see the Reason for Snippet field, and when I insert it I get: [wpbb post:meta_box field='content'] but nothing shows on the front end even if there is content in that custom field. The workaround is to connect with the Post Content [wpbb post:content]. Then everyting shows up ok fully formatted with and the images too. It's confusing not to be able to select the MB field, but not the end of the world if you know to use the Post Content connector instead.

    in reply to: post Excerpt #18740
    hartsook@gmail.com[email protected]
    Participant

    here's the code in pastebin, maybe it's easier to read?
    https://pastebin.com/7tmTTPU1

    in reply to: post Excerpt #18738
    hartsook@gmail.com[email protected]
    Participant

    Here's how I tried to adapt your wysiwyg field to post content example to fit my wysiwyg field to post excerpt. Not working, it removes excerpt field from CPT, but does not return the wysiwyg field content to the post_excerpt in a loop.

    
    // Remove the editor. Change 'post' to your custom post type.
    add_action( 'init', function () {
        remove_post_type_support( 'code-snippet', 'excerpt' , 'post_content' ); // also tried to remove the post_content editor for the CPT, but it still shows
    } );
    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
    // was not sure if the following 3 lines were necessary so commented them out, did not work either way
        // Get the current post content and set as the default value for the wysiwyg field.
        // $post_id = filter_input( INPUT_GET, 'code-snippet', FILTER_SANITIZE_NUMBER_INT );
       //  $post_content = get_post_field( 'post_excerpt', $post_id );
        $meta_boxes[] = [
            'title'      => 'Code Snippet Before', // this is the Field Group Title
            'post_types' => 'code-snippet', // Change 'post' to your custom post type.- done
            'fields'     => [
                // Register a wysiwyg field of which the content is saved as post content.
                [
                    'type' => 'wysiwyg',
                    'id'   => 'excerpt', // This is the must!
                    'name' => 'Reason for snippet', // label for the custom field
                    'std'  => $post_excerpt, // was not sure what to put here
                ],
                // Custom style to overwrite the editor style set by WordPress.
                [
                    'type' => 'custom_html',
                    'std'  => '<style>#wp-content-editor-tools{background:none;padding-top:0;}</style>',
                ],
            ],
        ];
        return $meta_boxes;
    } );
    // Set the value for the 'excerpt' field.
    add_filter( 'rwmb_content_field_meta', function() {
        $post_id = filter_input( INPUT_GET, 'code-snippet', FILTER_SANITIZE_NUMBER_INT ); //assumed I should use code-snippet the CPT instead of 'post' here
        return get_post_field( 'post_excerpt', $post_id ); // assumed I should use 'post_excerpt instead of 'post_content here
    } );
    // did not think the following were necessary in this case so commented them out
    // Do not save 'content' field to post meta.
    // add_filter( 'rwmb_content_value', '__return_empty_string' );
    
    in reply to: post Excerpt #18737
    hartsook@gmail.com[email protected]
    Participant

    hmmm, almost...
    I'm actually using a wysiwyg field instead of a textarea field, so I tried to adapt your sample code to incorporate the wysiwyg field replacing the Post Content example. But I'm missing something, it's not working

    So to simplify, I tried to conform to your example by adding a textarea field to the CPT called "Snippet Excerpt", snippet-excerpt

    • The CPT singular is called Code Snippet code-snippet
    • the field group is "Code Snippet before" code-snippet-before
    • The wysiwyg field is called "Reason for snippet" reason-for-snippet
    • The textarea field is called "Snippet Excerpt" snippet-excerpt

    The code below does indeed remove the excerpt field from the Code Snippet CPT, but does leave it for standard posts which is what I want.

    But text entered in the textarea custom field does not display as the post_excerpt in the loop even though text that was entered in the standard Excerpt field in older posts still shows even though the excerpt metabox is no longer displayed when editing those posts.

    It's probably something simple, but I can't find it. Here's the code that's not working:

    /**
    * using custom field for Code Snippet CPT excerpt
    **/
    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
        $meta_boxes[] = [
            'title'      => 'Code Snippet Before',
            'post_types' => 'code-snippet',
            'fields'     => [
                [
                    'type' => 'textarea',
                    'id'   => 'excerpt', // This is the must!
                    'name' => 'Snippet Excerpt',
                ],
            ],
        ];
    
    return $meta_boxes;
    } );
    
    add_filter( 'rwmb_excerpt_field_meta', function() {
        $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
        return get_post_field( 'post_excerpt', $post_id );
    } );
    add_filter( 'rwmb_excerpt_value', '__return_empty_string' );

    What am I missing?

    It would be terrific if you could also show how to modify the code so that we could use a wysiwyg field instead of a textarea field -- since we would want html-formatted text displaying as the excerpt. In my particular case the wysiwyg custom field would be "Reason for snippet" reason-for-snippet in the Code Snippet Before field group.

    in reply to: post Excerpt #18731
    hartsook@gmail.com[email protected]
    Participant

    I think what is wanted here is something I was going to ask as well.

    I have several textarea MB fields (actually in a custom post type, but could also apply to a standard post).

    What I want is for the MB textarea field to automatically be linked to the standard WP Excerpt field in much the same way that you linked a custom image field to the User Profile image.

    The reason for this in my case is that the custom post type only has the custom fields displayed through a Beaver Themer template, I don't use the standard post content area at all. As a result on post archive pages when the loop is trying to get the excerpt (or the first n words of the post content) it doesn't find anything. To avoid having to copy the text from one of the textarea custom fields and paste it into the post excerpt field it would be great to have the excerpt field automatically get populated with that custom field.

    Can this be done similar to the way you did the User Profile image?

    in reply to: storing javascript in text area #18664
    hartsook@gmail.com[email protected]
    Participant

    That’s perfect +1

    I made a blog post about it on my website too

    https://wp-website-coach.com/code-snippet/storing-javascript-in-a-metabox-io-custom-field-textarea/

    in reply to: storing javascript in text area #18627
    hartsook@gmail.com[email protected]
    Participant

    That’s a little more clear, but what’s missing is the screenshot showing how you can apply the sanitize_callback none so easily in a custom field advanced tab UI.

    You say this:

    Bypass The Sanitization

    If you don’t want to sanitize the input value for a specific field (we don’t encourage this, obviously), then simply set the sanitize_callback to none:

    And then you show the resulting code, but you never show where or how you set the sanitize_callback to none!

    For me at least, I had no idea you could do that, and nowhere in the docs that I could find was a suggestion to use the advance tab attributes to do this. Maybe this is obvious to you, but I participate in a weekly WordPress support group that has PHP and JavaScript engineers, WordPress experts, and nobody could figure out how to do it. One of the reasons I use metabox and beaver builder and beaver Thiemer is to avoid hand coding. The actual solution is so simple and elegant, but it is not intuitive.

    Thanks again for making such a great product.

    in reply to: storing javascript in text area #18619
    hartsook@gmail.com[email protected]
    Participant

    Wow! That was so simple!!

    In reviewing the documentation regarding sanitization it was not clear that you can override the sanitization on any custom field you create by simply adding a "sanitize_callback" Attribute with the value= "none" in the Advanced tab on that field.

    No coding necessary, nothing to add to the functions.php file, etc.

    Could you somehow make this solution more visible in the documentation?

    Thank you very much for staying with me on this and showing me how to solve my problem.

    Hope you and everyone close are healthy and continue to stay healthy.

    Pieter

    in reply to: storing javascript in text area #18595
    hartsook@gmail.com[email protected]
    Participant

    another example that doesn't work:

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $meta_boxes[] = [
            'title' => 'Story Field Group',
            'fields' => [
                [
                    'type'              => 'textarea',
                    'id'                => 'textarea_6dgymvsrfq5',
                    'name'              => 'Full code snippet',
                    'sanitize_callback' => 'none',
                ]
            ],
        ];
        return $meta_boxes;
    } );

    how textarea field is set up in field group

    in reply to: storing javascript in text area #18594
    hartsook@gmail.com[email protected]
    Participant

    disable sanatize for textarea code that's not working

    in reply to: storing javascript in text area #18593
    hartsook@gmail.com[email protected]
    Participant

    I looked at the documentation but I'm still having disabling sanitize for textarea field using the following code, can you point out what I'm doing wrong?

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $meta_boxes[] = [
            'title' => 'Team Field Group',
            'fields' => [
                [
                    'type'              => 'textarea',
                    'id'                => 'embed_code',
                    'name'              => 'Widget Embed Code',
                    'sanitize_callback' => 'none',
                ]
            ],
        ];
        return $meta_boxes;
    } ); 
    hartsook@gmail.com[email protected]
    Participant

    tried that, it's working...

    Thanks,

    Pieter

    in reply to: Sanitization of Fields input #18005
    hartsook@gmail.com[email protected]
    Participant

    I was able to bypass the sanitization of the textarea field in the sanatize.php file

    /**
    'textarea' => 'wp_kses_post',
    */

    but of course when the metabox plugin gets updated that file will be overwriten.

    I'm not a coder, could you provide me a code snippet I can paste into the child theme functions.php file to disable sanitization for the textarea field?

    Thanks, love your plugin and the support you provide.

    Pieter

Viewing 15 posts - 16 through 30 (of 35 total)