| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tableberg\Patterns; |
| 4 |
|
| 5 |
class RegisterPatterns |
| 6 |
{ |
| 7 |
|
| 8 |
public static function from_dir($dir) |
| 9 |
{ |
| 10 |
if (!file_exists($dir)) { |
| 11 |
return; |
| 12 |
} |
| 13 |
$files = scandir($dir); |
| 14 |
foreach ($files as $file) { |
| 15 |
if ($file == '.' || $file == '..') { |
| 16 |
continue; |
| 17 |
} |
| 18 |
$content = json_decode(file_get_contents($dir . '/' . $file), true); |
| 19 |
register_block_pattern('tableberg/' . str_replace('.json', '', $file), $content); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public static function upsells() |
| 24 |
{ |
| 25 |
$dir = __DIR__ . '/upsells'; |
| 26 |
if (!file_exists($dir)) { |
| 27 |
return; |
| 28 |
} |
| 29 |
$files = scandir($dir); |
| 30 |
foreach ($files as $file) { |
| 31 |
if ($file == '.' || $file == '..') { |
| 32 |
continue; |
| 33 |
} |
| 34 |
$content = json_decode(file_get_contents($dir . '/' . $file), true); |
| 35 |
$content['content'] = str_replace('::PLUGIN_URL::', TABLEBERG_URL, $content['content']); |
| 36 |
register_block_pattern('tableberg/' . str_replace('.json', '', $file), $content); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
public static function categories() |
| 41 |
{ |
| 42 |
register_block_pattern_category('tableberg', array('label' => 'Tableberg')); |
| 43 |
|
| 44 |
register_block_pattern_category('comparison-table', array('label' => 'Comparison Table')); |
| 45 |
register_block_pattern_category('featured-box', array('label' => 'Featured Box')); |
| 46 |
register_block_pattern_category('pricing-table', array('label' => 'Pricing Table')); |
| 47 |
register_block_pattern_category('pros-cons', array('label' => 'Pros & Cons')); |
| 48 |
|
| 49 |
register_block_pattern_category('other', array('label' => 'Other')); |
| 50 |
} |
| 51 |
} |