Skip to content

Instantly share code, notes, and snippets.

@doekenorg
Created August 18, 2020 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doekenorg/6144f6096829a3717d66fd6fdd42a702 to your computer and use it in GitHub Desktop.
Save doekenorg/6144f6096829a3717d66fd6fdd42a702 to your computer and use it in GitHub Desktop.
Worksheet hook example
<?php
class Worksheet {
/**
* Holds the worksheet title.
* @var string
*/
private $title;
// Registers the filter hooks.
public function __construct(string $title)
{
// Set the title to the inner variable.
$this->title = $title;
// Register hook for form 3.
add_filter('gfexcel_renderer_worksheet_title_3', [$this, 'change_title'], 10, 2);
}
/**
* Method to listen to the worksheet title hook.
* @param string $current_title The current title.
* @param array $form The form object.
* @return string The new worksheet title. Will be capped off at 31 characters.
*/
public function change_title(string $current_title, array $form)
{
// You can also use the content of $form to assert what form you are currently on.
return $this->title; // return the new title.
}
}
// Trigger the class.
new Worksheet('Title');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment