PluginProbe
Powerkit – Supercharge your WordPress Site / trunk
Powerkit – Supercharge your WordPress Site vtrunk
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / modules / basic-elements / public / class-powerkit-basic-elements-public.php

class-powerkit-basic-elements-public.php in Powerkit – Supercharge your WordPress Site trunk, at modules/basic-elements/public/class-powerkit-basic-elements-public.php

145 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The public-facing functionality of the module.
4 *
5 * @link https://codesupply.co
6 * @since 1.0.0
7 *
8 * @package Powerkit
9 * @subpackage Modules/public
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * The public-facing functionality of the module.
19 */
20 class Powerkit_Basic_Elements_Public extends Powerkit_Module_Public {
21
22 /**
23 * Initialize
24 */
25 public function initialize() {
26 add_action( 'init', array( $this, 'register_shortcodes' ) );
27 add_action( 'init', array( $this, 'register_custom_shortcodes' ) );
28 }
29
30 /**
31 * Shortcodes custom.
32 *
33 * @since 1.0.0
34 * @access public
35 */
36 public function register_custom_shortcodes() {
37
38 $dir_path = apply_filters( 'powerkit_basic_shortcodes_autoload_path', 'shortcodes' );
39
40 $custom_path = wp_normalize_path( get_template_directory() . '/' . $dir_path );
41
42 if ( file_exists( $custom_path ) ) {
43 powerkit_basic_shortcodes_autoload( $custom_path );
44 }
45 }
46
47 /**
48 * Register Shortcodes
49 *
50 * @since 1.0.0
51 * @access private
52 */
53 public function register_shortcodes() {
54
55 // Get all shortcodes.
56 $sections = apply_filters( 'powerkit_basic_shortcodes_ui_args', array() );
57
58 // Add shortcodes.
59 foreach ( $sections as $section ) {
60 if ( true === $section['autoregister'] ) {
61 add_shortcode( $section['base'], array( $this, 'shortcode_display' ) );
62 }
63
64 // Repeat Shortcodes.
65 if ( ! empty( $section['fields'] ) ) {
66 foreach ( $section['fields'] as $field ) {
67 if ( 'repeater' === $field['type'] && true === $field['autoregister'] ) {
68 add_shortcode( $field['base'], array( $this, 'shortcode_display' ) );
69 }
70 }
71 }
72 }
73 }
74
75 /**
76 * Shortcode Public Display
77 *
78 * @param array $atts User defined attributes in shortcode tag.
79 * @param string $content Shorcode Content.
80 * @param string $shortcode The name of the shortcode.
81 * @return string Shortcode result HTML.
82 */
83 public function shortcode_display( $atts, $content = false, $shortcode = '' ) {
84 // Get all shortcodes.
85 $sections = apply_filters( 'powerkit_basic_shortcodes_ui_args', array() );
86
87 // Get Default Attrs.
88 $default_attrs = array();
89 foreach ( $sections as $section ) {
90 if ( isset( $section['fields'] ) && is_array( $section['fields'] ) ) {
91 foreach ( $section['fields'] as $field ) {
92 switch ( $field['type'] ) {
93 case 'section':
94 break;
95 case 'repeater':
96 if ( $field['base'] === $shortcode ) {
97 foreach ( $field['fields'] as $repeater_field ) {
98 $default_attrs[ $repeater_field['name'] ] = $repeater_field['default'] ? $repeater_field['default'] : '';
99 }
100 }
101 break;
102 default:
103 if ( $section['base'] === $shortcode ) {
104 $default_attrs[ $field['name'] ] = $field['default'] ? $field['default'] : '';
105 }
106 break;
107 }
108 }
109 }
110 }
111
112 // Merge Attrs.
113 $atts = shortcode_atts( $default_attrs, $atts );
114
115 // Content.
116 $content = do_shortcode( $content );
117
118 /**
119 * Filters a shortcode's HTML.
120 *
121 * @param array $output Shortcode HTML.
122 * @param array $atts User defined attributes in shortcode tag.
123 * @param string $content Shorcode tag content.
124 * @return string Shortcode result HTML.
125 */
126 $output = apply_filters( $shortcode . '_shortcode', '', $atts, $content );
127
128 return $output;
129 }
130
131 /**
132 * Register the stylesheets for the public-facing side of the site.
133 */
134 public function wp_enqueue_scripts() {
135 // Styles.
136 wp_enqueue_style( 'powerkit-basic-elements', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-basic-elements.css' ), false, powerkit_get_setting( 'version' ), 'screen' );
137
138 // Add RTL support.
139 wp_style_add_data( 'powerkit-basic-elements', 'rtl', 'replace' );
140
141 // Scripts.
142 wp_enqueue_script( 'powerkit-basic-elements', plugin_dir_url( __FILE__ ) . 'js/public-powerkit-basic-elements.js', array( 'jquery' ), '4.0.0', true );
143 }
144 }
145