| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Simple Like Page |
| 4 |
* Plugin URI: https://topdevs.net/simple-like-page-plugin/ |
| 5 |
* Description: A lightweight, privacy-friendly way to embed Facebook Page feeds on WordPress with performance and consent in mind. |
| 6 |
* Version: 2.0.1 |
| 7 |
* Requires at least: 5.8 |
| 8 |
* Requires PHP: 7.2 |
| 9 |
* Author: topdevs.net |
| 10 |
* Author URI: https://topdevs.net |
| 11 |
* License: GPL v2 or later |
| 12 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 |
* Text Domain: simple-like-page-plugin |
| 14 |
* |
| 15 |
* This plugin is not affiliated with, endorsed by, or sponsored by Meta Platforms, Inc. |
| 16 |
* All trademarks belong to their respective owners. |
| 17 |
*/ |
| 18 |
|
| 19 |
define( "SFP_VERSION", '2.0.1' ); |
| 20 |
|
| 21 |
function sfp_is_pro_active() { |
| 22 |
return class_exists( 'SSP_Pro' ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Main SF Plugin Class |
| 27 |
* |
| 28 |
* Contains the main functions for SF and stores variables |
| 29 |
* |
| 30 |
* @since SF Plugin 1.2 |
| 31 |
* @author Ilya K. |
| 32 |
*/ |
| 33 |
|
| 34 |
// Check if class already exist |
| 35 |
if ( !class_exists( 'SFPlugin' ) ) { |
| 36 |
|
| 37 |
// Main plugin class |
| 38 |
class SFPlugin { |
| 39 |
|
| 40 |
public $pluginPath; |
| 41 |
public $pluginUrl; |
| 42 |
public $pluginName; |
| 43 |
public $optionName; |
| 44 |
public $frontendAssetsEnqueued = false; |
| 45 |
|
| 46 |
public $facebookLocalesUrl = "http://www.facebook.com/translations/FacebookLocales.xml"; |
| 47 |
public $locales; |
| 48 |
|
| 49 |
/** |
| 50 |
* SF Plugin Constructor |
| 51 |
* |
| 52 |
* Gets things started |
| 53 |
*/ |
| 54 |
public function __construct( ) { |
| 55 |
$this->pluginPath = plugin_dir_path(__FILE__); |
| 56 |
$this->pluginUrl = plugin_dir_url(__FILE__); |
| 57 |
|
| 58 |
$this->optionName = "simple_facebook_plugin_options"; |
| 59 |
|
| 60 |
$this->locales = $this->parseLocales($this->facebookLocalesUrl); |
| 61 |
|
| 62 |
$this->loadFiles(); |
| 63 |
$this->addActions(); |
| 64 |
$this->addShortcodes(); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Load all the required files. |
| 69 |
*/ |
| 70 |
protected function loadFiles() { |
| 71 |
// Include social plugins files |
| 72 |
require_once( $this->pluginPath . 'lib/sfp-page-plugin.php' ); |
| 73 |
|
| 74 |
// Allow addons load files |
| 75 |
do_action('sfp_load_files'); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Add all the required actions. |
| 80 |
*/ |
| 81 |
protected function addActions() { |
| 82 |
|
| 83 |
add_action( 'admin_menu', array( $this, 'pluginMenu') ); |
| 84 |
add_action( 'admin_notices', array( $this, 'adminNotice') ); |
| 85 |
add_action( 'widgets_init', array( $this, 'addWidgets') ); |
| 86 |
//add_action( 'wp_footer', array( $this, 'addJavaScriptSDK') ); |
| 87 |
add_action( 'admin_init', array( $this, 'saveOptions' ) ); |
| 88 |
add_action( 'admin_init', array( $this, 'ignoreNotices' ) ); |
| 89 |
add_action( 'admin_init', array( $this, 'registerSettings' ) ); |
| 90 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueueScriptsAdmin') ); |
| 91 |
add_action( 'init', array( $this, 'registerBlock' ) ); |
| 92 |
|
| 93 |
// Add settings links on Plugins page |
| 94 |
$plugin = plugin_basename( __FILE__ ); |
| 95 |
add_filter( 'plugin_row_meta', array( $this, 'pluginRowMeta' ), 10, 2 ); |
| 96 |
|
| 97 |
// Allow addons add actions |
| 98 |
do_action( 'sfp_add_actions', $this ); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Register all widgets |
| 103 |
*/ |
| 104 |
public function addWidgets() { |
| 105 |
|
| 106 |
register_widget('SFPPagePluginWidget'); |
| 107 |
|
| 108 |
// Allow addons add widgets |
| 109 |
do_action('sfp_add_widgets'); |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Register all shortcodes |
| 114 |
*/ |
| 115 |
public function addShortcodes() { |
| 116 |
|
| 117 |
add_shortcode('sfp-page-plugin', 'sfp_page_plugin_shortcode'); |
| 118 |
|
| 119 |
// Allow addons add shortcodes |
| 120 |
do_action('sfp_add_shortcodes'); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Get remote XML file by URL |
| 125 |
* |
| 126 |
* @param string $url |
| 127 |
* @return array |
| 128 |
* @since 1.3 |
| 129 |
*/ |
| 130 |
public function parseLocales ( $url = "" ) { |
| 131 |
|
| 132 |
if ( file_exists( $url ) && function_exists( "simplexml_load_file" ) ) { |
| 133 |
|
| 134 |
$locales = array(); |
| 135 |
$xml = simplexml_load_file( $url ); |
| 136 |
|
| 137 |
foreach ( $xml as $key => $locale ) { |
| 138 |
|
| 139 |
$name = (array) $locale->englishName; |
| 140 |
$name = $name[0]; |
| 141 |
|
| 142 |
$code = (array) $locale->codes->code->standard->representation; |
| 143 |
$code = $code[0]; |
| 144 |
|
| 145 |
$locales[$code] = $name; |
| 146 |
}; |
| 147 |
} |
| 148 |
else |
| 149 |
$locales = array( |
| 150 |
"af_ZA"=> "Afrikaans", |
| 151 |
"ar_AR"=> "Arabic", |
| 152 |
"az_AZ"=> "Azerbaijani", |
| 153 |
"be_BY"=> "Belarusian", |
| 154 |
"bg_BG"=> "Bulgarian", |
| 155 |
"bn_IN"=> "Bengali", |
| 156 |
"bs_BA"=> "Bosnian", |
| 157 |
"ca_ES"=> "Catalan", |
| 158 |
"cs_CZ"=> "Czech", |
| 159 |
"cy_GB"=> "Welsh", |
| 160 |
"da_DK"=> "Danish", |
| 161 |
"de_DE"=> "German", |
| 162 |
"el_GR"=> "Greek", |
| 163 |
"en_GB"=> "English (UK)", |
| 164 |
"en_PI"=> "English (Pirate)", |
| 165 |
"en_UD"=> "English (Upside Down)", |
| 166 |
"en_US"=> "English (US)", |
| 167 |
"eo_EO"=> "Esperanto", |
| 168 |
"es_ES"=> "Spanish (Spain)", |
| 169 |
"es_LA"=> "Spanish", |
| 170 |
"et_EE"=> "Estonian", |
| 171 |
"eu_ES"=> "Basque", |
| 172 |
"fa_IR"=> "Persian", |
| 173 |
"fb_LT"=> "Leet Speak", |
| 174 |
"fi_FI"=> "Finnish", |
| 175 |
"fo_FO"=> "Faroese", |
| 176 |
"fr_CA"=> "French (Canada)", |
| 177 |
"fr_FR"=> "French (France)", |
| 178 |
"fy_NL"=> "Frisian", |
| 179 |
"ga_IE"=> "Irish", |
| 180 |
"gl_ES"=> "Galician", |
| 181 |
"he_IL"=> "Hebrew", |
| 182 |
"hi_IN"=> "Hindi", |
| 183 |
"hr_HR"=> "Croatian", |
| 184 |
"hu_HU"=> "Hungarian", |
| 185 |
"hy_AM"=> "Armenian", |
| 186 |
"id_ID"=> "Indonesian", |
| 187 |
"is_IS"=> "Icelandic", |
| 188 |
"it_IT"=> "Italian", |
| 189 |
"ja_JP"=> "Japanese", |
| 190 |
"ka_GE"=> "Georgian", |
| 191 |
"km_KH"=> "Khmer", |
| 192 |
"ko_KR"=> "Korean", |
| 193 |
"ku_TR"=> "Kurdish", |
| 194 |
"la_VA"=> "Latin", |
| 195 |
"lt_LT"=> "Lithuanian", |
| 196 |
"lv_LV"=> "Latvian", |
| 197 |
"mk_MK"=> "Macedonian", |
| 198 |
"ml_IN"=> "Malayalam", |
| 199 |
"ms_MY"=> "Malay", |
| 200 |
"nb_NO"=> "Norwegian (bokmal)", |
| 201 |
"ne_NP"=> "Nepali", |
| 202 |
"nl_NL"=> "Dutch", |
| 203 |
"nn_NO"=> "Norwegian (nynorsk)", |
| 204 |
"pa_IN"=> "Punjabi", |
| 205 |
"pl_PL"=> "Polish", |
| 206 |
"ps_AF"=> "Pashto", |
| 207 |
"pt_BR"=> "Portuguese (Brazil)", |
| 208 |
"pt_PT"=> "Portuguese (Portugal)", |
| 209 |
"ro_RO"=> "Romanian", |
| 210 |
"ru_RU"=> "Russian", |
| 211 |
"sk_SK"=> "Slovak", |
| 212 |
"sl_SI"=> "Slovenian", |
| 213 |
"sq_AL"=> "Albanian", |
| 214 |
"sr_RS"=> "Serbian", |
| 215 |
"sv_SE"=> "Swedish", |
| 216 |
"sw_KE"=> "Swahili", |
| 217 |
"ta_IN"=> "Tamil", |
| 218 |
"te_IN"=> "Telugu", |
| 219 |
"th_TH"=> "Thai", |
| 220 |
"tl_PH"=> "Filipino", |
| 221 |
"tr_TR"=> "Turkish", |
| 222 |
"uk_UA"=> "Ukrainian", |
| 223 |
"vi_VN"=> "Vietnamese", |
| 224 |
"zh_CN"=> "Simplified Chinese (China)", |
| 225 |
"zh_HK"=> "Traditional Chinese (Hong Kong)", |
| 226 |
"zh_TW"=> "Traditional Chinese (Taiwan)" |
| 227 |
); |
| 228 |
|
| 229 |
return $locales; |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Load styles for dashboard |
| 234 |
* |
| 235 |
* @since 1.3.1 |
| 236 |
*/ |
| 237 |
|
| 238 |
static function enqueueScriptsAdmin() { |
| 239 |
|
| 240 |
// add custom css |
| 241 |
wp_register_style( 'sfp-admin-style', plugin_dir_url(__FILE__) . '/lib/css/sfp-admin-style.css' ); |
| 242 |
wp_enqueue_style( 'sfp-admin-style' ); |
| 243 |
|
| 244 |
wp_enqueue_style( 'wp-color-picker' ); |
| 245 |
wp_enqueue_script( 'wp-color-picker' ); |
| 246 |
wp_add_inline_script( |
| 247 |
'wp-color-picker', |
| 248 |
'jQuery(function($){function initSfpColors(context){$(context).find(".sfp-color-field").wpColorPicker();}initSfpColors(document);$(document).on("widget-added widget-updated",function(e,widget){initSfpColors(widget);});});' |
| 249 |
); |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* Load Facebook JavaScript SDK |
| 254 |
* |
| 255 |
* @since 1.3 |
| 256 |
*/ |
| 257 |
|
| 258 |
public function addJavaScriptSDK() { |
| 259 |
$this->enqueueFrontendAssets(); |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Add Dashboard > Plugins Menu Page |
| 264 |
* |
| 265 |
* @since 1.3 |
| 266 |
*/ |
| 267 |
|
| 268 |
public function pluginMenu() { |
| 269 |
|
| 270 |
add_options_page( 'Simple Like Page', 'Simple Like Page', 'manage_options', 'sfp_plugin', array( $this, "pluginMenuView" ) ); |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* Show Menu Page View |
| 275 |
* |
| 276 |
* @since 1.3 |
| 277 |
*/ |
| 278 |
|
| 279 |
public function pluginMenuView() { |
| 280 |
|
| 281 |
$options = $this->getPluginOptions(); |
| 282 |
|
| 283 |
// include Like Box view |
| 284 |
include( $this->pluginPath . 'views/view-menu.php' ); |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Show admin notice |
| 290 |
* |
| 291 |
* @since 1.3 |
| 292 |
*/ |
| 293 |
|
| 294 |
public function adminNotice() { |
| 295 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 296 |
return; |
| 297 |
} |
| 298 |
|
| 299 |
if ( sfp_is_pro_active() ) { |
| 300 |
return; |
| 301 |
} |
| 302 |
|
| 303 |
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; |
| 304 |
if ( ! $screen || 'settings_page_sfp_plugin' !== $screen->id ) { |
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
if ( isset( $_GET['sfp_hide_pro_notice'] ) && check_admin_referer( 'sfp_hide_pro_notice' ) ) { |
| 309 |
update_user_meta( get_current_user_id(), 'sfp_hide_pro_notice', 1 ); |
| 310 |
} |
| 311 |
|
| 312 |
if ( get_user_meta( get_current_user_id(), 'sfp_hide_pro_notice', true ) ) { |
| 313 |
return; |
| 314 |
} |
| 315 |
|
| 316 |
$upgrade_url = esc_url( add_query_arg( array( |
| 317 |
'utm_source' => 'wp-admin', |
| 318 |
'utm_medium' => 'notice', |
| 319 |
'utm_campaign' => 'sfp-upgrade', |
| 320 |
), apply_filters( 'sfp_pro_upgrade_url', 'https://topdevs.net/simple-social-pro/' ) ) ); |
| 321 |
$dismiss_url = wp_nonce_url( |
| 322 |
add_query_arg( 'sfp_hide_pro_notice', '1' ), |
| 323 |
'sfp_hide_pro_notice' |
| 324 |
); |
| 325 |
|
| 326 |
echo '<div class="notice notice-info is-dismissible"><p>'; |
| 327 |
echo wp_kses_post( |
| 328 |
sprintf( |
| 329 |
'Need popup triggers, floating follow button, and display rules? <a href="%1$s" target="_blank" rel="noopener noreferrer">Upgrade to Pro</a>. <a href="%2$s">Dismiss</a>', |
| 330 |
$upgrade_url, |
| 331 |
esc_url( $dismiss_url ) |
| 332 |
) |
| 333 |
); |
| 334 |
echo '</p></div>'; |
| 335 |
} |
| 336 |
|
| 337 |
public function ignoreNotices() { |
| 338 |
|
| 339 |
global $current_user; |
| 340 |
$user_id = $current_user->ID; |
| 341 |
|
| 342 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 343 |
return; |
| 344 |
} |
| 345 |
|
| 346 |
/* If user clicks to ignore the notice, add that to their user meta */ |
| 347 |
if ( isset( $_GET['sfp_ignore_4'] ) && '0' == $_GET['sfp_ignore_4'] ) { |
| 348 |
add_user_meta( $user_id, 'sfp_ignore_notice_4', 'true', true); |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
/** |
| 353 |
* Add status link on plugins page |
| 354 |
* |
| 355 |
* @since 1.3 |
| 356 |
*/ |
| 357 |
|
| 358 |
public function pluginRowMeta( $links, $file ) { |
| 359 |
|
| 360 |
if ( $file !== plugin_basename( __FILE__ ) ) { |
| 361 |
return $links; |
| 362 |
} |
| 363 |
|
| 364 |
$extra_links = array( '<a href="' . menu_page_url( "sfp_plugin", false ) . '">Settings</a>' ); |
| 365 |
|
| 366 |
if ( ! sfp_is_pro_active() ) { |
| 367 |
$upgrade_url = esc_url( add_query_arg( array( |
| 368 |
'utm_source' => 'wp-admin', |
| 369 |
'utm_medium' => 'plugin-row', |
| 370 |
'utm_campaign' => 'sfp-upgrade', |
| 371 |
), apply_filters( 'sfp_pro_upgrade_url', 'https://topdevs.net/simple-social-pro/' ) ) ); |
| 372 |
$extra_links[] = '<a href="' . $upgrade_url . '" target="_blank" rel="noopener noreferrer">Upgrade to Pro</a>'; |
| 373 |
} |
| 374 |
|
| 375 |
$inserted = false; |
| 376 |
$updated_links = array(); |
| 377 |
foreach ( $links as $link ) { |
| 378 |
$updated_links[] = $link; |
| 379 |
if ( stripos( $link, 'Visit plugin site' ) !== false ) { |
| 380 |
array_push( $updated_links, ...$extra_links ); |
| 381 |
$inserted = true; |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
if ( ! $inserted ) { |
| 386 |
array_push( $updated_links, ...$extra_links ); |
| 387 |
} |
| 388 |
|
| 389 |
return $updated_links; |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Get plugin options |
| 394 |
* |
| 395 |
* @since 1.3 |
| 396 |
*/ |
| 397 |
|
| 398 |
public function getPluginOptions() { |
| 399 |
|
| 400 |
$defaults = array( |
| 401 |
'url' => 'https://www.facebook.com/WordPress/', |
| 402 |
'locale' => "en_US", |
| 403 |
'click_to_load' => 0, |
| 404 |
'lazy_load' => 1, |
| 405 |
'placeholder_text' => 'Click to load Facebook content', |
| 406 |
'placeholder_bg_color' => '#e7f3ff', |
| 407 |
'placeholder_text_color' => '#1877f2' |
| 408 |
); |
| 409 |
|
| 410 |
$defaults = apply_filters( "sfp_default_options", $defaults ); |
| 411 |
|
| 412 |
$options = get_option( $this->optionName, array() ); |
| 413 |
$options = wp_parse_args( $options, $defaults ); |
| 414 |
|
| 415 |
return $options; |
| 416 |
} |
| 417 |
|
| 418 |
/** |
| 419 |
* Save plugin options |
| 420 |
* |
| 421 |
* @since 1.3 |
| 422 |
*/ |
| 423 |
|
| 424 |
public function savePluginOptions( $options = array() ) { |
| 425 |
|
| 426 |
update_option( $this->optionName, $options ); |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* Trigger when settings page form submitted |
| 431 |
* |
| 432 |
* @since 1.3 |
| 433 |
*/ |
| 434 |
|
| 435 |
public function saveOptions() { |
| 436 |
|
| 437 |
//delete_option( $this->optionName ); |
| 438 |
|
| 439 |
// If submit button pressed |
| 440 |
if ( isset( $_POST['sfp_options_saved'] ) ) { |
| 441 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 442 |
return; |
| 443 |
} |
| 444 |
|
| 445 |
$options = $this->getPluginOptions(); |
| 446 |
|
| 447 |
if ( isset( $_POST['locale'] ) && !empty( $_POST['locale'] ) ) { |
| 448 |
|
| 449 |
$options['locale'] = $_POST['locale']; |
| 450 |
} |
| 451 |
|
| 452 |
if ( isset( $_POST['url'] ) && ! empty( $_POST['url'] ) ) { |
| 453 |
$options['url'] = esc_url_raw( $_POST['url'] ); |
| 454 |
} |
| 455 |
|
| 456 |
if ( isset( $_POST['click_to_load'] ) ) { |
| 457 |
$options['click_to_load'] = (int) (bool) $_POST['click_to_load']; |
| 458 |
} |
| 459 |
|
| 460 |
if ( isset( $_POST['lazy_load'] ) ) { |
| 461 |
$options['lazy_load'] = (int) (bool) $_POST['lazy_load']; |
| 462 |
} |
| 463 |
|
| 464 |
if ( isset( $_POST['placeholder_text'] ) ) { |
| 465 |
$options['placeholder_text'] = sanitize_text_field( $_POST['placeholder_text'] ); |
| 466 |
} |
| 467 |
|
| 468 |
if ( isset( $_POST['placeholder_bg_color'] ) ) { |
| 469 |
$options['placeholder_bg_color'] = sanitize_hex_color( $_POST['placeholder_bg_color'] ); |
| 470 |
} |
| 471 |
|
| 472 |
if ( isset( $_POST['placeholder_text_color'] ) ) { |
| 473 |
$options['placeholder_text_color'] = sanitize_hex_color( $_POST['placeholder_text_color'] ); |
| 474 |
} |
| 475 |
|
| 476 |
$this->savePluginOptions( $options ); |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
public function registerSettings() { |
| 481 |
|
| 482 |
register_setting( |
| 483 |
'sfp_options', |
| 484 |
$this->optionName, |
| 485 |
array( $this, 'sanitizeOptions' ) |
| 486 |
); |
| 487 |
|
| 488 |
add_settings_section( |
| 489 |
'sfp_performance_privacy', |
| 490 |
'Performance & Privacy', |
| 491 |
array( $this, 'renderPerformancePrivacySection' ), |
| 492 |
'sfp_plugin' |
| 493 |
); |
| 494 |
|
| 495 |
add_settings_field( |
| 496 |
'sfp_click_to_load', |
| 497 |
'Enable click-to-load', |
| 498 |
array( $this, 'renderClickToLoadField' ), |
| 499 |
'sfp_plugin', |
| 500 |
'sfp_performance_privacy' |
| 501 |
); |
| 502 |
|
| 503 |
add_settings_field( |
| 504 |
'sfp_lazy_load', |
| 505 |
'Enable lazy loading', |
| 506 |
array( $this, 'renderLazyLoadField' ), |
| 507 |
'sfp_plugin', |
| 508 |
'sfp_performance_privacy' |
| 509 |
); |
| 510 |
|
| 511 |
add_settings_section( |
| 512 |
'sfp_placeholder', |
| 513 |
'Placeholder', |
| 514 |
array( $this, 'renderPlaceholderSection' ), |
| 515 |
'sfp_plugin' |
| 516 |
); |
| 517 |
|
| 518 |
add_settings_field( |
| 519 |
'sfp_placeholder_text', |
| 520 |
'Placeholder text', |
| 521 |
array( $this, 'renderPlaceholderTextField' ), |
| 522 |
'sfp_plugin', |
| 523 |
'sfp_placeholder' |
| 524 |
); |
| 525 |
|
| 526 |
add_settings_field( |
| 527 |
'sfp_placeholder_bg_color', |
| 528 |
'Placeholder background color', |
| 529 |
array( $this, 'renderPlaceholderBgField' ), |
| 530 |
'sfp_plugin', |
| 531 |
'sfp_placeholder' |
| 532 |
); |
| 533 |
|
| 534 |
add_settings_field( |
| 535 |
'sfp_placeholder_text_color', |
| 536 |
'Placeholder text color', |
| 537 |
array( $this, 'renderPlaceholderTextColorField' ), |
| 538 |
'sfp_plugin', |
| 539 |
'sfp_placeholder' |
| 540 |
); |
| 541 |
|
| 542 |
add_settings_section( |
| 543 |
'sfp_locale', |
| 544 |
'Localization', |
| 545 |
array( $this, 'renderLocaleSection' ), |
| 546 |
'sfp_plugin' |
| 547 |
); |
| 548 |
|
| 549 |
add_settings_field( |
| 550 |
'sfp_url_field', |
| 551 |
'Default Facebook Page URL', |
| 552 |
array( $this, 'renderUrlField' ), |
| 553 |
'sfp_plugin', |
| 554 |
'sfp_locale' |
| 555 |
); |
| 556 |
|
| 557 |
add_settings_field( |
| 558 |
'sfp_locale_field', |
| 559 |
'Language', |
| 560 |
array( $this, 'renderLocaleField' ), |
| 561 |
'sfp_plugin', |
| 562 |
'sfp_locale' |
| 563 |
); |
| 564 |
} |
| 565 |
|
| 566 |
public function sanitizeOptions( $options ) { |
| 567 |
|
| 568 |
$defaults = $this->getPluginOptions(); |
| 569 |
|
| 570 |
$clean = array(); |
| 571 |
$clean['url'] = isset( $options['url'] ) ? esc_url_raw( $options['url'] ) : $defaults['url']; |
| 572 |
$clean['locale'] = isset( $options['locale'] ) ? sanitize_text_field( $options['locale'] ) : $defaults['locale']; |
| 573 |
$clean['click_to_load'] = ! empty( $options['click_to_load'] ) ? 1 : 0; |
| 574 |
$clean['lazy_load'] = ! empty( $options['lazy_load'] ) ? 1 : 0; |
| 575 |
$clean['placeholder_text'] = isset( $options['placeholder_text'] ) ? sanitize_text_field( $options['placeholder_text'] ) : $defaults['placeholder_text']; |
| 576 |
$clean['placeholder_bg_color'] = isset( $options['placeholder_bg_color'] ) ? sanitize_hex_color( $options['placeholder_bg_color'] ) : $defaults['placeholder_bg_color']; |
| 577 |
$clean['placeholder_text_color'] = isset( $options['placeholder_text_color'] ) ? sanitize_hex_color( $options['placeholder_text_color'] ) : $defaults['placeholder_text_color']; |
| 578 |
|
| 579 |
return $clean; |
| 580 |
} |
| 581 |
|
| 582 |
public function renderPerformancePrivacySection() { |
| 583 |
echo '<p>Delays Facebook loading until interaction or when the embed is in view to reduce unnecessary third-party requests.</p>'; |
| 584 |
} |
| 585 |
|
| 586 |
public function renderLocaleSection() { |
| 587 |
echo '<p>Select the Facebook SDK locale used when loading embeds.</p>'; |
| 588 |
} |
| 589 |
|
| 590 |
public function renderPlaceholderSection() { |
| 591 |
echo '<p>Customize the text and colors shown before the embed loads.</p>'; |
| 592 |
} |
| 593 |
|
| 594 |
public function renderUrlField() { |
| 595 |
$options = $this->getPluginOptions(); |
| 596 |
?> |
| 597 |
<input type="url" class="regular-text" name="<?php echo esc_attr( $this->optionName ); ?>[url]" value="<?php echo esc_attr( $options['url'] ); ?>" /> |
| 598 |
<p class="description">Used when a widget, shortcode, or block does not specify a URL.</p> |
| 599 |
<?php |
| 600 |
} |
| 601 |
|
| 602 |
public function renderClickToLoadField() { |
| 603 |
$options = $this->getPluginOptions(); |
| 604 |
?> |
| 605 |
<label> |
| 606 |
<input type="checkbox" name="<?php echo esc_attr( $this->optionName ); ?>[click_to_load]" value="1" <?php checked( 1, (int) $options['click_to_load'] ); ?> /> |
| 607 |
<span>Requires a click before Facebook loads.</span> |
| 608 |
</label> |
| 609 |
<?php |
| 610 |
} |
| 611 |
|
| 612 |
public function renderLazyLoadField() { |
| 613 |
$options = $this->getPluginOptions(); |
| 614 |
?> |
| 615 |
<label> |
| 616 |
<input type="checkbox" name="<?php echo esc_attr( $this->optionName ); ?>[lazy_load]" value="1" <?php checked( 1, (int) $options['lazy_load'] ); ?> /> |
| 617 |
<span>Loads the embed only when it enters the viewport.</span> |
| 618 |
</label> |
| 619 |
<?php |
| 620 |
} |
| 621 |
|
| 622 |
public function renderPlaceholderTextField() { |
| 623 |
$options = $this->getPluginOptions(); |
| 624 |
?> |
| 625 |
<input type="text" class="regular-text" name="<?php echo esc_attr( $this->optionName ); ?>[placeholder_text]" value="<?php echo esc_attr( $options['placeholder_text'] ); ?>" /> |
| 626 |
<p class="description">Displayed before the embed loads.</p> |
| 627 |
<?php |
| 628 |
} |
| 629 |
|
| 630 |
public function renderPlaceholderBgField() { |
| 631 |
$options = $this->getPluginOptions(); |
| 632 |
?> |
| 633 |
<input type="text" class="sfp-color-field" name="<?php echo esc_attr( $this->optionName ); ?>[placeholder_bg_color]" value="<?php echo esc_attr( $options['placeholder_bg_color'] ); ?>" data-default-color="#e7f3ff" /> |
| 634 |
<p class="description">Background color for the placeholder.</p> |
| 635 |
<?php |
| 636 |
} |
| 637 |
|
| 638 |
public function renderPlaceholderTextColorField() { |
| 639 |
$options = $this->getPluginOptions(); |
| 640 |
?> |
| 641 |
<input type="text" class="sfp-color-field" name="<?php echo esc_attr( $this->optionName ); ?>[placeholder_text_color]" value="<?php echo esc_attr( $options['placeholder_text_color'] ); ?>" data-default-color="#1877f2" /> |
| 642 |
<p class="description">Text color for the placeholder.</p> |
| 643 |
<?php |
| 644 |
} |
| 645 |
|
| 646 |
public function renderLocaleField() { |
| 647 |
$options = $this->getPluginOptions(); |
| 648 |
?> |
| 649 |
<select name="<?php echo esc_attr( $this->optionName ); ?>[locale]"> |
| 650 |
<?php foreach ( $this->locales as $code => $name ) : ?> |
| 651 |
<option <?php selected( ( $options['locale'] == $code ) ? 1 : 0 ); ?> value="<?php echo esc_attr( $code ); ?>" ><?php echo esc_html( $name ); ?></option> |
| 652 |
<?php endforeach; ?> |
| 653 |
</select> |
| 654 |
<?php |
| 655 |
} |
| 656 |
|
| 657 |
public function enqueueFrontendAssets() { |
| 658 |
|
| 659 |
if ( $this->frontendAssetsEnqueued ) { |
| 660 |
return; |
| 661 |
} |
| 662 |
|
| 663 |
$this->frontendAssetsEnqueued = true; |
| 664 |
|
| 665 |
$options = $this->getPluginOptions(); |
| 666 |
$should_load = apply_filters( 'sfp_should_load', true ); |
| 667 |
$has_consent = apply_filters( 'sfp_has_consent', true ); |
| 668 |
|
| 669 |
// Hooks for future Pro add-on consent logic. |
| 670 |
do_action( 'sfp_before_load', $should_load, $has_consent ); |
| 671 |
|
| 672 |
wp_enqueue_style( |
| 673 |
'sfp-frontend-style', |
| 674 |
$this->pluginUrl . 'assets/css/simple-facebook-plugin.css', |
| 675 |
array(), |
| 676 |
SFP_VERSION |
| 677 |
); |
| 678 |
|
| 679 |
wp_enqueue_script( |
| 680 |
'sfp-frontend-script', |
| 681 |
$this->pluginUrl . 'assets/js/simple-facebook-plugin.js', |
| 682 |
array(), |
| 683 |
SFP_VERSION, |
| 684 |
true |
| 685 |
); |
| 686 |
|
| 687 |
$settings = array( |
| 688 |
'locale' => isset( $options['locale'] ) ? $options['locale'] : 'en_US', |
| 689 |
'clickToLoadEnabled' => (bool) $options['click_to_load'], |
| 690 |
'lazyLoadEnabled' => (bool) $options['lazy_load'], |
| 691 |
'placeholderText' => isset( $options['placeholder_text'] ) ? $options['placeholder_text'] : 'Click to load Facebook content', |
| 692 |
'shouldLoad' => (bool) $should_load, |
| 693 |
'hasConsent' => (bool) $has_consent, |
| 694 |
); |
| 695 |
|
| 696 |
$settings_json = wp_json_encode( $settings ); |
| 697 |
|
| 698 |
wp_add_inline_script( |
| 699 |
'sfp-frontend-script', |
| 700 |
'window.sfpSettings = window.sfpSettings || {}; window.sfpSettings = Object.assign(window.sfpSettings, ' . $settings_json . ');', |
| 701 |
'before' |
| 702 |
); |
| 703 |
|
| 704 |
// Hook for future Pro add-on to react after loader setup. |
| 705 |
do_action( 'sfp_after_load', $should_load, $has_consent ); |
| 706 |
} |
| 707 |
|
| 708 |
public function registerBlock() { |
| 709 |
|
| 710 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 711 |
return; |
| 712 |
} |
| 713 |
|
| 714 |
$defaults = function_exists( 'sfp_get_page_plugin_defaults' ) |
| 715 |
? sfp_get_page_plugin_defaults() |
| 716 |
: array(); |
| 717 |
|
| 718 |
$url_default = isset( $defaults['url'] ) ? $defaults['url'] : ''; |
| 719 |
$width_default = isset( $defaults['width'] ) ? $defaults['width'] : ''; |
| 720 |
$height_default = isset( $defaults['height'] ) ? $defaults['height'] : ''; |
| 721 |
$hide_cover_default = isset( $defaults['hide_cover'] ) ? (bool) $defaults['hide_cover'] : false; |
| 722 |
$show_facepile_default = isset( $defaults['show_facepile'] ) ? (bool) $defaults['show_facepile'] : true; |
| 723 |
$small_header_default = isset( $defaults['small_header'] ) ? (bool) $defaults['small_header'] : false; |
| 724 |
$timeline_default = isset( $defaults['timeline'] ) ? (bool) $defaults['timeline'] : false; |
| 725 |
$events_default = isset( $defaults['events'] ) ? (bool) $defaults['events'] : false; |
| 726 |
$messages_default = isset( $defaults['messages'] ) ? (bool) $defaults['messages'] : false; |
| 727 |
$locale_default = isset( $defaults['locale'] ) ? $defaults['locale'] : 'en_US'; |
| 728 |
$placeholder_default = isset( $defaults['placeholder_text'] ) ? $defaults['placeholder_text'] : ''; |
| 729 |
$placeholder_bg_default = isset( $defaults['placeholder_bg_color'] ) ? $defaults['placeholder_bg_color'] : ''; |
| 730 |
$placeholder_text_color_default = isset( $defaults['placeholder_text_color'] ) ? $defaults['placeholder_text_color'] : ''; |
| 731 |
|
| 732 |
wp_register_script( |
| 733 |
'sfp-block-editor', |
| 734 |
$this->pluginUrl . 'assets/js/sfp-block.js', |
| 735 |
array( 'wp-blocks', 'wp-element', 'wp-editor', 'wp-components', 'wp-i18n' ), |
| 736 |
SFP_VERSION, |
| 737 |
true |
| 738 |
); |
| 739 |
|
| 740 |
$block_defaults = array( |
| 741 |
'url' => $url_default, |
| 742 |
'width' => $width_default, |
| 743 |
'height' => $height_default, |
| 744 |
'hideCover' => $hide_cover_default, |
| 745 |
'showFacepile' => $show_facepile_default, |
| 746 |
'smallHeader' => $small_header_default, |
| 747 |
'timeline' => $timeline_default, |
| 748 |
'events' => $events_default, |
| 749 |
'messages' => $messages_default, |
| 750 |
'locale' => $locale_default, |
| 751 |
'placeholderText' => $placeholder_default, |
| 752 |
'placeholderBgColor' => $placeholder_bg_default, |
| 753 |
'placeholderTextColor' => $placeholder_text_color_default, |
| 754 |
'isPro' => sfp_is_pro_active(), |
| 755 |
'upgradeUrl' => add_query_arg( array( |
| 756 |
'utm_source' => 'wp-admin', |
| 757 |
'utm_medium' => 'block-editor', |
| 758 |
'utm_campaign' => 'sfp-upgrade', |
| 759 |
), apply_filters( 'sfp_pro_upgrade_url', 'https://topdevs.net/simple-social-pro/' ) ), |
| 760 |
); |
| 761 |
|
| 762 |
wp_add_inline_script( |
| 763 |
'sfp-block-editor', |
| 764 |
'window.sfpBlockDefaults = ' . wp_json_encode( $block_defaults ) . ';', |
| 765 |
'before' |
| 766 |
); |
| 767 |
|
| 768 |
register_block_type( 'simple-facebook-plugin/page', array( |
| 769 |
'editor_script' => 'sfp-block-editor', |
| 770 |
'render_callback' => array( $this, 'renderBlock' ), |
| 771 |
'attributes' => array( |
| 772 |
'url' => array( 'type' => 'string', 'default' => $url_default ), |
| 773 |
'width' => array( 'type' => 'string', 'default' => $width_default ), |
| 774 |
'height' => array( 'type' => 'string', 'default' => $height_default ), |
| 775 |
'hideCover' => array( 'type' => 'boolean', 'default' => $hide_cover_default ), |
| 776 |
'showFacepile' => array( 'type' => 'boolean', 'default' => $show_facepile_default ), |
| 777 |
'smallHeader' => array( 'type' => 'boolean', 'default' => $small_header_default ), |
| 778 |
'timeline' => array( 'type' => 'boolean', 'default' => $timeline_default ), |
| 779 |
'events' => array( 'type' => 'boolean', 'default' => $events_default ), |
| 780 |
'messages' => array( 'type' => 'boolean', 'default' => $messages_default ), |
| 781 |
'locale' => array( 'type' => 'string', 'default' => $locale_default ), |
| 782 |
'clickToLoad' => array( 'type' => 'boolean' ), |
| 783 |
'placeholderText' => array( 'type' => 'string', 'default' => $placeholder_default ), |
| 784 |
'placeholderBgColor' => array( 'type' => 'string', 'default' => $placeholder_bg_default ), |
| 785 |
'placeholderTextColor' => array( 'type' => 'string', 'default' => $placeholder_text_color_default ), |
| 786 |
), |
| 787 |
) ); |
| 788 |
} |
| 789 |
|
| 790 |
public function renderBlock( $attributes ) { |
| 791 |
|
| 792 |
$instance = array( |
| 793 |
'url' => isset( $attributes['url'] ) ? $attributes['url'] : '', |
| 794 |
'width' => isset( $attributes['width'] ) ? $attributes['width'] : '', |
| 795 |
'height' => isset( $attributes['height'] ) ? $attributes['height'] : '', |
| 796 |
'hide_cover' => isset( $attributes['hideCover'] ) ? (bool) $attributes['hideCover'] : false, |
| 797 |
'show_facepile' => isset( $attributes['showFacepile'] ) ? (bool) $attributes['showFacepile'] : true, |
| 798 |
'small_header' => isset( $attributes['smallHeader'] ) ? (bool) $attributes['smallHeader'] : false, |
| 799 |
'timeline' => isset( $attributes['timeline'] ) ? (bool) $attributes['timeline'] : false, |
| 800 |
'events' => isset( $attributes['events'] ) ? (bool) $attributes['events'] : false, |
| 801 |
'messages' => isset( $attributes['messages'] ) ? (bool) $attributes['messages'] : false, |
| 802 |
'locale' => isset( $attributes['locale'] ) ? $attributes['locale'] : 'en_US', |
| 803 |
); |
| 804 |
|
| 805 |
if ( array_key_exists( 'clickToLoad', $attributes ) ) { |
| 806 |
$instance['click_to_load'] = (bool) $attributes['clickToLoad']; |
| 807 |
} |
| 808 |
|
| 809 |
if ( ! empty( $attributes['placeholderText'] ) ) { |
| 810 |
$instance['placeholder_text'] = $attributes['placeholderText']; |
| 811 |
} |
| 812 |
|
| 813 |
if ( ! empty( $attributes['placeholderBgColor'] ) ) { |
| 814 |
$instance['placeholder_bg_color'] = $attributes['placeholderBgColor']; |
| 815 |
} |
| 816 |
|
| 817 |
if ( ! empty( $attributes['placeholderTextColor'] ) ) { |
| 818 |
$instance['placeholder_text_color'] = $attributes['placeholderTextColor']; |
| 819 |
} |
| 820 |
|
| 821 |
$instance = apply_filters( 'sfp_block_instance', $instance, $attributes ); |
| 822 |
|
| 823 |
if ( function_exists( 'sfp_render_page_plugin_html' ) ) { |
| 824 |
return sfp_render_page_plugin_html( $instance ); |
| 825 |
} |
| 826 |
|
| 827 |
return ''; |
| 828 |
} |
| 829 |
|
| 830 |
} // end SFPlugin class |
| 831 |
|
| 832 |
} // end if !class_exists |
| 833 |
|
| 834 |
// Create new SFPlugin instance |
| 835 |
$GLOBALS["sfplugin"] = new SFPlugin(); |
| 836 |
|
| 837 |
?> |
| 838 |
|