Custom post types
-
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
-
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,
TobiasThis 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
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
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,
TobiasGreat, I will test this at once.
Per
Hi,
no problem, you are very welcome! π Good to hear that this helped!
Best wishes,
TobiasHi
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
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
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 toadd_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,
TobiasHi
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
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,
TobiasOk will change and test and report back asap how it goes.
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
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,
TobiasFound 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?
- The topic ‘Custom post types’ is closed to new replies.