| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace Jet_Form_Builder\Shortcodes; |
| 5 |
|
| 6 |
|
| 7 |
abstract class Shortcode { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
add_shortcode( $this->get_name(), array( $this, 'add_shortcode_callback' ) ); |
| 11 |
} |
| 12 |
|
| 13 |
abstract public function get_name(); |
| 14 |
|
| 15 |
abstract public function generate( $settings ); |
| 16 |
|
| 17 |
protected function default_args() { |
| 18 |
return array(); |
| 19 |
} |
| 20 |
|
| 21 |
protected function prepare_attributes( $attrs ) { |
| 22 |
$result = array(); |
| 23 |
|
| 24 |
foreach ( $attrs as $name => $attr ) { |
| 25 |
$result[ $name ] = $attr['default']; |
| 26 |
} |
| 27 |
|
| 28 |
return $result; |
| 29 |
} |
| 30 |
|
| 31 |
public function add_shortcode_callback( $atts ) { |
| 32 |
$settings = shortcode_atts( $this->default_args(), $atts, $this->get_name() ); |
| 33 |
|
| 34 |
return $this->generate( $settings ); |
| 35 |
} |
| 36 |
|
| 37 |
} |