• Resolved psn

    (@psn)


    Hi Tobias,

    I’m using another plugin called Better Notifications for WordPress and this plugin use now public custom post types. For some reason Tablepress custom post types seems not be public. is there any reason to have these set as private?

    If not can it be changed to get this as public?

    Per

    https://wordpress.org/plugins/tablepress/

Viewing 15 replies - 1 through 15 (of 63 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    TablePress only uses CPTs as the data storage, where the table is stored as a JSON-encoded string. Making those public is not useful for TablePress, and could actually confuse people (as they would suddenly see the JSON code).

    Can you explain why you want the TablePress CPT to be public? (If you really want this, you could achieve it by using the tablepress_post_type_args filter hook from the model-post.php file.)

    Regards,
    Tobias

    Thread Starter psn

    (@psn)

    This question is coming from the author of mentioned notification plugin as he collect the public ones. I will ask him to contact you if he need.

    Per

    Thread Starter psn

    (@psn)

    Reason for this is that I want to find a way to get mail notifications sent to certain users when I have updated table in tablepress. The mentioned plugin worked until recently as the author of it changed to only collect the public custom post types and not the private as this created some other issues in his plugin.

    I think I have asked you earlier if it would be possible to get tablepress to handle mail notifications as an extra plugin?

    Either way is to follow your suggested way but I dont know where and how the code should look like to grab tablepress custom post types. Can you help me here?

    Per

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi Per,

    thanks for the explanation. I don’t think that changing the visibility of the TablePress CPT will help for that.

    Instead, to get a notification when a TablePress table is saved, you could simply use some PHP code like this

    add_action( 'tablepress_event_saved_table', 'pabrady_tablepress_save_notification', 10, 1 );
    function pabrady_tablepress_save_notification( $table_id ) {
      wp_mail(
        'recipient@example.com',
        'TablePress table was saved',
        "The table with the ID {$table_id} was saved."
      );
    }

    (e.g. in your theme’s functions.php or in a small custom plugin.)

    Regards,
    Tobias

    Thread Starter psn

    (@psn)

    Great, I will test this at once.

    Per

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! πŸ™‚ Good to hear that this helped!

    Best wishes,
    Tobias

    Thread Starter psn

    (@psn)

    Hi

    Have some question:
    1. Is it possible to add in the data which was updated? If so how should the code for this look like?
    2. Can I add in public short codes?

    Per

    Thread Starter psn

    (@psn)

    Hi

    To be added to quest no 1-2:

    Can we add in tablepress short codes inside the mentioned code above to get the table presented in mail?

    Per

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi Per,

    1. No, this is not possible. TablePress does not keep records about the modifications, so that it can not present them here πŸ™

    2. Using Shortcodes in the mail text should be possible, but you might have to add a wrapping do_shortcode() function call around the email text. This will however not work for the [table] Shortcode as it’s not registered in this context. To do that, you could modify the code to

    add_action( 'tablepress_event_saved_table', 'pabrady_tablepress_save_notification', 10, 1 );
    function pabrady_tablepress_save_notification( $table_id ) {
      $frontend_controller = $TablePress::load_controller( 'frontend' );
      $frontend_controller->init_shortcodes();
    
      $table_html = do_shortcode( "[table id={$table_id} /]" );
      $mail_text = "The table with the ID {$table_id} was saved: {$table_html}.";
    
      wp_mail(
        'recipient@example.com',
        'TablePress table was saved',
        $mail_text
      );
    }

    Regards,
    Tobias

    Thread Starter psn

    (@psn)

    Hi

    Tested the above code but then I get this error in Tablepress:

    Saving failed: AJAX call failed: error – Internal Server Error. Try again while holding down the β€œShift” key.

    I even tried to save again with Shift down but then I got a blank page.

    Per

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ah, there’s a typo in my code, sorry.
    Please replace

    $frontend_controller = $TablePress::load_controller( 'frontend' );

    with

    $frontend_controller = TablePress::load_controller( 'frontend' );

    Regards,
    Tobias

    Thread Starter psn

    (@psn)

    Ok will change and test and report back asap how it goes.

    Thread Starter psn

    (@psn)

    Hi

    Its nearly working, I now get the mail but the content is with raw html codes. Is it possible to get this content presented as its shown in page with tables?

    Per

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi Per,

    no, showing the table as on the website is not really possible, as that needs HTML code πŸ™
    The alternative would be to send the email as an HTML email instead of as a text email, but unfortunately, I can’t help with the modifications of the code for that, as I haven’t done that before.

    Regards,
    Tobias

    Thread Starter psn

    (@psn)

    Found solution with headers then mail actually present with correct table and not raw html codes:

    add_action( 'tablepress_event_saved_table', 'pabrady_tablepress_save_notification', 10, 1 );
    function pabrady_tablepress_save_notification( $table_id ) {
      $frontend_controller = TablePress::load_controller( 'frontend' );
      $frontend_controller->init_shortcodes();
    
      $table_html = do_shortcode( "[table id={$table_id} /]" );
      $mail_text = "The table with the ID {$table_id} was saved: {$table_html}.";
      $headers = array('Content-Type: text/html; charset=UTF-8');
    
      wp_mail(
        'per.soderman@gmail.com',
        'TablePress table was saved',
        $mail_text,
        $headers
      );
    }

    Only thing which I havent been able to solve is that even Edit-link (<a href="http://www.test.se/wp-admin/admin.php?page=tablepress&action=edit&table_id=18">Edit</a>) is present in mailtext so any idea how to get ride of that?

Viewing 15 replies - 1 through 15 (of 63 total)
  • The topic ‘Custom post types’ is closed to new replies.