PluginProbe
Powerkit – Supercharge your WordPress Site / 2.3.6
Powerkit – Supercharge your WordPress Site v2.3.6
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 / facebook / public / class-powerkit-facebook-public.php

class-powerkit-facebook-public.php in Powerkit – Supercharge your WordPress Site 2.3.6, at modules/facebook/public/class-powerkit-facebook-public.php

158 lines 4.1 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_Facebook_Public extends Powerkit_Module_Public {
16
17 /**
18 * Initialize
19 */
20 public function initialize() {
21 add_action( 'init', array( $this, 'facebook_load_sdk' ) );
22 add_action( 'current_screen', array( $this, 'facebook_load_sdk_gutenberg' ) );
23 add_action( 'init', array( $this, 'register_locations' ) );
24 add_filter( 'powerkit_facebook_comments_location', array( $this, 'location_default' ) );
25 }
26
27 /**
28 * Init Facebook
29 *
30 * @since 1.0.0
31 * @access private
32 */
33 public function facebook_load_sdk() {
34 add_action( 'wp_footer', 'powerkit_facebook_load_sdk' );
35 }
36
37 /**
38 * Init Facebook in Gutenberg editor
39 *
40 * @since 1.0.0
41 * @access private
42 */
43 public function facebook_load_sdk_gutenberg() {
44 global $current_screen;
45
46 $current_screen = get_current_screen();
47
48 // add on the editor page.
49 if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
50 add_action( 'admin_footer', 'powerkit_facebook_load_sdk' );
51 }
52 }
53
54 /**
55 * Facebook Register Locations
56 *
57 * @since 1.0.0
58 * @access private
59 */
60 public function register_locations() {
61
62 $locations = apply_filters( 'powerkit_facebook_comments_location', array() );
63
64 $powerkit_facebook_enable_comments = get_option( 'powerkit_facebook_enable_comments' );
65 $powerkit_facebook_location = get_option( 'powerkit_facebook_location' );
66
67 // Select location.
68 if ( isset( $locations[ $powerkit_facebook_location ] ) ) {
69
70 $location = $locations[ $powerkit_facebook_location ];
71
72 } elseif ( isset( $locations['default'] ) ) {
73
74 $location = $locations['default'];
75
76 } else {
77 $location = false;
78 }
79
80 if ( $powerkit_facebook_enable_comments && $location ) {
81 $priority = (int) isset( $location['priority'] ) ? $location['priority'] : 10;
82
83 if ( 'comments_template' === $location['action'] ) {
84
85 add_filter( 'comments_template', function () {
86 return plugin_dir_path( dirname( __FILE__ ) ) . 'public/facebook-comments-template.php';
87 }, $priority );
88
89 } elseif ( 'before_comments' === $location['action'] ) {
90
91 add_action( 'comments_template', function () {
92 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/facebook-comments-template.php';
93 }, $priority );
94
95 } elseif ( 'after_comments' === $location['action'] ) {
96 /**
97 * Filter After WordPress Comments
98 */
99 function powerkit_filter_comments_template() {
100 remove_filter( 'comments_template', 'powerkit_filter_comments_template' );
101
102 comments_template();
103
104 return plugin_dir_path( dirname( __FILE__ ) ) . 'public/facebook-comments-template.php';
105 }
106 add_filter( 'comments_template', 'powerkit_filter_comments_template' );
107
108 } else {
109
110 add_action( $location['action'], function () {
111 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/facebook-comments-template.php';
112 }, $priority );
113 }
114 }
115 }
116
117 /**
118 * Filter Register Locations
119 *
120 * @since 1.0.0
121 * @access private
122 *
123 * @param array $locations List of Locations.
124 */
125 public function location_default( $locations = array() ) {
126
127 $locations = array(
128 'before_comments' => array(
129 'name' => 'Before WordPress Comments',
130 'action' => 'before_comments',
131 'priority' => 10,
132 ),
133 'after_comments' => array(
134 'name' => 'After WordPress Comments',
135 'action' => 'after_comments',
136 'priority' => 10,
137 ),
138 'default' => array(
139 'name' => 'In place of WordPress Comments',
140 'action' => 'comments_template',
141 'priority' => 10,
142 ),
143 );
144
145 return $locations;
146 }
147
148 /**
149 * Register the stylesheets for the public-facing side of the site.
150 */
151 public function wp_enqueue_scripts() {
152 wp_enqueue_style( 'powerkit-facebook', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-facebook.css' ), array(), powerkit_get_setting( 'version' ), 'all' );
153
154 // Add RTL support.
155 wp_style_add_data( 'powerkit-facebook', 'rtl', 'replace' );
156 }
157 }
158