Skip to content

Commit

Permalink
Add some extension/layout support
Browse files Browse the repository at this point in the history
For DataTables and Ratings & Reviews

See #2
zackkatz committed Nov 5, 2020
1 parent 06a92db commit 6fec22a
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions class-gravityview-admin-view.php
Original file line number Diff line number Diff line change
@@ -48,6 +48,27 @@ public function add_hooks() {

add_action( 'gravityview_before', array( $this, 'maybe_output_notices' ) );

// Ratings & Reviews relies on priority 15
add_action( 'gravityview_after', array( $this, 'set_post_global' ), -100 );
add_action( 'gravityview_after', array( $this, 'unset_post_global' ), 10000 );

if ( class_exists( 'GV_Extension_DataTables' ) ) {
// Support DataTables
add_action( 'gravityview/template/after', array( $this, 'set_post_global' ), -100 );
add_action( 'admin_enqueue_scripts', array( $this, 'set_post_global' ), -100 );
add_action( 'gravityview/template/after', array( $this, 'unset_post_global' ), 10000 );
add_action( 'admin_enqueue_scripts', array( $this, 'unset_post_global' ), 1000 );

$GV_Extension_DataTables = new GV_Extension_DataTables;

// load DataTables core logic
$GV_Extension_DataTables->core_actions();

$DT = new GV_Extension_DataTables_Data();
add_action( 'admin_enqueue_scripts', array( $DT, 'add_scripts_and_styles' ) );
}

}

/**
* Modify the links shown in the Connected Form links in the Data Source box
@@ -75,6 +96,43 @@ private function is_admin_view_request() {

return true;
}

/**
* Set the $post global in the admin screen
*
* @global \WP_Post|null $post
*
* @param int|\GV\View $view View being rendered
*/
public function set_post_global( $view = 0 ) {

if ( ! $this->is_admin_view_request() ) {
return;
}

global $post;

if ( $post ) {
return;
}

$backup_view_id = $view instanceof \GV\View ? $view->ID : $view;

$post = get_post( \GV\Utils::_GET( 'gvid', $backup_view_id ) );
}

/**
* @param int|\GV\View $view View being rendered
*/
public function unset_post_global( $view ) {

if ( ! $this->is_admin_view_request() ) {
return;
}

global $post;

$post = null;
}

/**

0 comments on commit 6fec22a

Please sign in to comment.