PageRenderTime 34ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/bb-booster/bb-booster.php

https://bitbucket.org/madiha303/clickitplugins-web
PHP | 144 lines | 57 code | 47 blank | 40 comment | 12 complexity | d52efe128e66aa204d4b5376e14dcc1a MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin Name: Beaver Builder Booster
  4. * Plugin URI: http://www.wpbeaverbuilder.com
  5. * Description: Additional functionality for Beaver Builder lite.
  6. * Version: 1.0.6
  7. * Author: The Beaver Builder Team
  8. * Author URI: http://www.wpbeaverbuilder.com
  9. * Text Domain: bb-booster
  10. * Domain Path: /languages
  11. * Copyright: (c) 2016 Beaver Builder
  12. * License: GPL-2.0
  13. * License URI: https://www.gnu.org/licenses/gpl-2.0.html
  14. */
  15. define( 'FL_BUILDER_BOOSTER_DIR', plugin_dir_path( __FILE__ ) );
  16. define( 'FL_BUILDER_BOOSTER_URL', plugins_url( '/', __FILE__ ) );
  17. final class FLBuilderBooster {
  18. /**
  19. * Load languages
  20. *
  21. * @action plugins_loaded
  22. */
  23. public static function i18n() {
  24. load_plugin_textdomain( 'bb-booster', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
  25. }
  26. /**
  27. * Run booster after bb-plugin
  28. *
  29. * @action plugins_loaded
  30. */
  31. public static function init() {
  32. if ( ! class_exists( 'FLBuilder' ) || ! defined( 'FL_BUILDER_LITE' ) || ! FL_BUILDER_LITE ) {
  33. return;
  34. }
  35. if ( method_exists( 'FLBuilder', 'register_templates' ) ) {
  36. FLBuilder::register_templates( FL_BUILDER_BOOSTER_DIR . 'templates/templates.dat' );
  37. }
  38. if ( false === get_option( 'wpem_done' ) ) {
  39. add_action( 'admin_notices', array( __CLASS__, 'display_admin_notices' ) );
  40. return;
  41. }
  42. foreach ( glob( FL_BUILDER_BOOSTER_DIR . 'classes/class-fl-builder-booster-*.php' ) as $path ) {
  43. if ( is_readable( $path ) ) {
  44. require_once $path;
  45. }
  46. }
  47. add_action( 'wp_ajax_bb_booster_post_previewed_is_editable', array( __CLASS__, 'post_previewed_is_editable' ) );
  48. }
  49. /**
  50. * Display an admin notice
  51. *
  52. * @action admin_notices
  53. *
  54. * @return void
  55. */
  56. public static function display_admin_notices() {
  57. if ( defined( 'WPEM_DOING_STEPS' ) && WPEM_DOING_STEPS ) {
  58. return;
  59. }
  60. printf(
  61. '<div class="error"><p>%s</p></div>',
  62. __( 'The Beaver Builder Booster plugin is not compatible with your host.', 'bb-booster' )
  63. );
  64. }
  65. /**
  66. * Check is the currently previewed post is editable
  67. */
  68. public static function post_previewed_is_editable() {
  69. check_ajax_referer( 'bb_booster_post_previewed_is_editable' );
  70. $url = filter_input( INPUT_POST, 'url', FILTER_SANITIZE_STRING );
  71. $post_id = url_to_postid( $url );
  72. if ( static::is_post_editable( $post_id ) ) {
  73. wp_send_json_success();
  74. }
  75. wp_send_json_error();
  76. }
  77. /**
  78. * Check if the currently previewed page/post is editable
  79. *
  80. * @param int $post_id
  81. *
  82. * @return bool
  83. */
  84. public static function is_post_editable( $post_id ) {
  85. if ( 0 === $post_id ) {
  86. return false;
  87. }
  88. $post = get_post( absint( $post_id ) );
  89. $post_types = FLBuilderModel::get_post_types();
  90. $user_can = current_user_can( 'edit_post', $post->ID );
  91. if ( in_array( $post->post_type, $post_types ) && $user_can ) {
  92. return true;
  93. }
  94. }
  95. }
  96. add_action( 'plugins_loaded', array( 'FLBuilderBooster', 'i18n' ) );
  97. add_action( 'plugins_loaded', array( 'FLBuilderBooster', 'init' ) );