PluginProbe
Powerkit – Supercharge your WordPress Site / 3.0.4
Powerkit – Supercharge your WordPress Site v3.0.4
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 3.0.4, at modules/basic-elements/public/class-powerkit-basic-elements-public.php

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