Created
August 18, 2020 07:33
-
-
Save doekenorg/6144f6096829a3717d66fd6fdd42a702 to your computer and use it in GitHub Desktop.
Worksheet hook example
This file contains 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 | |
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