Created
August 2, 2024 14:03
-
-
Save jchristopher/e65636cfe0f6051d6c7121e092e6dbd5 to your computer and use it in GitHub Desktop.
Integrate TablePress into OrganizeWP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* NOTE: YOU WILL NEED TO ENABLE TABLEPRESS' CUSTOM POST TYPE | |
* IN ORGANIZEWP's SETTINGS SCREEN AFTER ADDING THESE SNIPPETS. | |
*/ | |
add_filter( 'organizewp/post_types', function( $post_types ) { | |
if ( class_exists( 'TablePress_Post_Model' ) ) { | |
$owp_tablepress = new \TablePress_Post_Model(); | |
$post_types[ $owp_tablepress->get_post_type() ] = $owp_tablepress->get_post_type(); | |
} | |
return $post_types; | |
} ); | |
add_filter( 'organizewp/post_type/current_user_can_edit', function( $can_edit, $post_type, $post_id ) { | |
if ( ! class_exists( 'TablePress_Post_Model' ) ) { | |
return $can_edit; | |
} | |
$owp_tablepress = new \TablePress_Post_Model(); | |
if ( $owp_tablepress->get_post_type() !== $post_type->name ) { | |
return $can_edit; | |
} | |
return ! empty( $post_id ) | |
? current_user_can( 'tablepress_edit_table', $post_id ) | |
: current_user_can( 'tablepress_edit_table' ); | |
}, 10, 3 ); | |
add_filter( 'organizewp/entry/edit_link', function( $edit_link, $params ) { | |
if ( ! class_exists( 'TablePress_Table_Model' ) ) { | |
return $edit_link; | |
} | |
$owp_tablepress = new \TablePress_Table_Model(); | |
$table_post = $owp_tablepress->_debug_get_tables()['table_post']; | |
foreach ( $table_post as $tablepress_table_id => $post_id ) { | |
if ( absint( $params['ID'] ) === absint( $post_id ) ) { | |
if ( current_user_can( 'tablepress_edit_table', $tablepress_table_id ) ) { | |
return TablePress::url( [ 'action' => 'edit', 'table_id' => $tablepress_table_id ] ); | |
} | |
} | |
} | |
return $edit_link; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment