shortcode.php
45 lines
| 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 | if ( in_array( $name, array( |
| 26 | 'form_id', |
| 27 | 'submit_type', |
| 28 | 'required_mark', |
| 29 | 'fields_layout', |
| 30 | 'enable_progress' |
| 31 | ) ) ) { |
| 32 | $result[ $name ] = $attr['default']; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return $result; |
| 37 | } |
| 38 | |
| 39 | public function add_shortcode_callback( $atts ) { |
| 40 | $settings = shortcode_atts( $this->default_args(), $atts, $this->get_name() ); |
| 41 | |
| 42 | return $this->generate( $settings ); |
| 43 | } |
| 44 | |
| 45 | } |