PluginProbe
Sociality / 1.3.7
Sociality v1.3.7
1.3.7 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.1.0 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0
sociality / sociality.php

sociality.php in Sociality 1.3.7, at sociality.php

276 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Sociality
4 * Description: Social features for the theme authors
5 * Version: 1.3.7
6 * Author: nK
7 * Author URI: https://nkdev.info
8 * License: GPLv2 or later
9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 * Text Domain: sociality
11 *
12 * @package sociality
13 */
14
15 // Make sure we don't expose any info if called directly.
16 if ( ! function_exists( 'add_action' ) ) {
17 echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
18 exit;
19 }
20
21 if ( ! class_exists( 'Sociality' ) ) :
22 /**
23 * Sociality Class
24 */
25 class Sociality {
26 /**
27 * The single class instance.
28 *
29 * @var $instance
30 */
31 private static $instance = null;
32
33 /**
34 * Path to the plugin directory
35 *
36 * @var $plugin_path
37 */
38 public $plugin_path;
39
40 /**
41 * URL to the plugin directory
42 *
43 * @var $plugin_url
44 */
45 public $plugin_url;
46
47 /**
48 * Plugin name
49 *
50 * @var $plugin_name
51 */
52 public $plugin_name;
53
54 /**
55 * Plugin version
56 *
57 * @var $plugin_version
58 */
59 public $plugin_version;
60
61 /**
62 * Plugin slug
63 *
64 * @var $plugin_slug
65 */
66 public $plugin_slug;
67
68 /**
69 * Plugin name sanitized
70 *
71 * @var $plugin_name_sanitized
72 */
73 public $plugin_name_sanitized;
74
75 /**
76 * Main Instance
77 * Ensures only one instance of this class exists in memory at any one time.
78 */
79 public static function instance() {
80 if ( is_null( self::$instance ) ) {
81 self::$instance = new self();
82 self::$instance->init_options();
83 self::$instance->init_hooks();
84
85 // include helper files.
86 self::$instance->include_dependencies();
87
88 // run some classes.
89 self::$instance->settings();
90 self::$instance->author_bio();
91 self::$instance->likes();
92 self::$instance->sharing();
93 }
94 return self::$instance;
95 }
96
97 /**
98 * Sociality constructor.
99 */
100 public function __construct() {
101 /* We do nothing here! */
102 }
103
104 /**
105 * PHP translations.
106 */
107 public function init_text_domain() {
108 load_plugin_textdomain( 'sociality', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
109 }
110
111 /**
112 * Init options.
113 */
114 public function init_options() {
115 $this->plugin_path = plugin_dir_path( __FILE__ );
116 $this->plugin_url = plugin_dir_url( __FILE__ );
117 }
118
119 /**
120 * Init hooks.
121 */
122 public function init_hooks() {
123 add_action( 'init', array( $this, 'init_text_domain' ) );
124 add_action( 'admin_init', array( $this, 'admin_init' ) );
125 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
126 }
127
128 /**
129 * Init admin.
130 */
131 public function admin_init() {
132 // get current plugin data.
133 $data = get_plugin_data( __FILE__ );
134 $this->plugin_name = $data['Name'];
135 $this->plugin_version = $data['Version'];
136 $this->plugin_slug = plugin_basename( __FILE__ );
137 $this->plugin_name_sanitized = basename( __FILE__, '.php' );
138 }
139
140 /**
141 * Enqueue assets.
142 */
143 public function enqueue_assets() {
144 wp_enqueue_style( 'sociality', sociality()->plugin_url . 'assets/sociality.min.css', array(), '1.3.7' );
145 wp_style_add_data( 'sociality', 'rtl', 'replace' );
146 wp_style_add_data( 'sociality', 'suffix', '.min' );
147
148 wp_enqueue_script( 'sociality', sociality()->plugin_url . 'assets/sociality.min.js', array( 'jquery' ), '1.3.7', true );
149 wp_enqueue_script( 'sociality-share', sociality()->plugin_url . 'assets/sociality-share/sociality-share.min.js', array( 'jquery' ), '1.3.7', true );
150
151 wp_localize_script(
152 'sociality',
153 'socialityData',
154 array(
155 'site_url' => get_site_url(),
156 'ajax_url' => admin_url( 'admin-ajax.php' ),
157 'ajax_nonce' => wp_create_nonce( 'ajax-nonce' ),
158 )
159 );
160 }
161
162 /**
163 * Include template.
164 * print template file (first check for theme /sociality-templates/...php)
165 *
166 * @param string $template_name - template name.
167 * @param array $args - additional arguments for template.
168 */
169 public function include_template( $template_name, $args = array() ) {
170 if ( ! empty( $args ) && is_array( $args ) ) {
171 // phpcs:ignore
172 extract( $args );
173 }
174
175 // template in theme folder.
176 $template = locate_template( array( 'sociality/' . $template_name, $template_name ) );
177
178 // template from plugins folder.
179 if ( ! $template ) {
180 $template = locate_template( array( 'plugins/sociality/' . $template_name, $template_name ) );
181 }
182
183 // default template.
184 if ( ! $template ) {
185 $template = $this->plugin_path . 'templates/' . $template_name;
186 }
187
188 // Allow 3rd party plugin filter template file from their plugin.
189 $template = apply_filters( 'sociality_include_template', $template, $template_name, $args );
190
191 do_action( 'sociality_before_include_template', $template, $template_name, $args );
192
193 include $template;
194
195 do_action( 'sociality_after_include_template', $template, $template_name, $args );
196 }
197
198 /**
199 * Include dependencies.
200 */
201 private function include_dependencies() {
202 require_once $this->plugin_path . 'classes/class-svg-icons.php';
203 require_once $this->plugin_path . 'classes/class-settings-api.php';
204 require_once $this->plugin_path . 'classes/class-settings.php';
205 require_once $this->plugin_path . 'classes/class-author-bio.php';
206 require_once $this->plugin_path . 'classes/class-likes.php';
207 require_once $this->plugin_path . 'classes/class-sharing.php';
208 }
209
210 /**
211 * Class SVG Icons
212 */
213 public function svg_icons() {
214 return Sociality_SVG_Icons::instance();
215 }
216
217 /**
218 * Class Settings
219 */
220 public function settings() {
221 return Sociality_Settings::instance();
222 }
223
224 /**
225 * Class BIO
226 */
227 public function author_bio() {
228 return Sociality_Author_Bio::instance();
229 }
230
231 /**
232 * Class Likes
233 */
234 public function likes() {
235 return Sociality_Likes::instance();
236 }
237
238 /**
239 * Class Sharing
240 */
241 public function sharing() {
242 return Sociality_Sharing::instance();
243 }
244
245 /**
246 * Get used icons
247 */
248 public function get_icons_array() {
249 $icons = $this->svg_icons()->get_all_brands( true );
250 $result = array();
251
252 foreach ( $icons as $name => $data ) {
253 $result[] = array(
254 'title' => $name,
255 'svg' => $data['svg'],
256 'searchTerms' => array( $name ),
257 );
258 }
259
260 return apply_filters( 'sociality_icons_array', $result );
261 }
262 }
263 endif;
264
265 if ( ! function_exists( 'sociality' ) ) :
266 /**
267 * Function works with the Sociality class instance
268 *
269 * @return object Sociality
270 */
271 function sociality() {
272 return Sociality::instance();
273 }
274 endif;
275 add_action( 'plugins_loaded', 'sociality' );
276