| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\TestData\Factories; |
| 4 |
|
| 5 |
use Give\TestData\Framework\Factory; |
| 6 |
|
| 7 |
/** |
| 8 |
* Class PageFactory |
| 9 |
* @package Give\TestData\Factories |
| 10 |
*/ |
| 11 |
class PageFactory extends Factory |
| 12 |
{ |
| 13 |
|
| 14 |
/** |
| 15 |
* Donor definition |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
* @return array |
| 19 |
*/ |
| 20 |
public function definition() |
| 21 |
{ |
| 22 |
return [ |
| 23 |
'post_title' => 'GiveWP Demonstration page', |
| 24 |
'post_content' => $this->getContent(), |
| 25 |
'post_status' => 'publish', |
| 26 |
'post_author' => $this->randomAuthor(), |
| 27 |
'post_type' => 'page', |
| 28 |
]; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Page content |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
public function getContent() |
| 38 |
{ |
| 39 |
$giveShortcodes = $this->getGiveShortcodes(); |
| 40 |
|
| 41 |
$content = ''; |
| 42 |
|
| 43 |
foreach ($giveShortcodes as $shortcode) { |
| 44 |
$content .= "<h3>[{$shortcode}]</h3>"; |
| 45 |
$content .= "[{$shortcode}]"; |
| 46 |
} |
| 47 |
|
| 48 |
return $content; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Get GiveWP shortcodes |
| 53 |
* |
| 54 |
* @return array |
| 55 |
*/ |
| 56 |
private function getGiveShortcodes() |
| 57 |
{ |
| 58 |
$shortcodes = []; |
| 59 |
|
| 60 |
foreach ($GLOBALS['shortcode_tags'] as $shortcode => $action) { |
| 61 |
if (false !== strpos($shortcode, 'give_')) { |
| 62 |
$shortcodes[] = $shortcode; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
return $shortcodes; |
| 67 |
} |
| 68 |
} |
| 69 |
|