You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <?php
  2. /**
  3. * Plugin Name: Planist
  4. * Plugin URI: https://planist.live
  5. * Description: Planist Shortcode and Block
  6. * Version: 1.0.0
  7. * Author: Parsa Kafi
  8. * Author URI: https://parsa.ws
  9. */
  10. class Planist
  11. {
  12. function __construct()
  13. {
  14. add_shortcode('planist', [$this, 'shortcode']);
  15. add_action('enqueue_block_editor_assets', [$this, 'gutenbergBlocks']);
  16. }
  17. function gutenbergBlocks()
  18. {
  19. wp_enqueue_style(
  20. 'planist-block-style',
  21. plugins_url('/assets/css/block-style.css', __FILE__),
  22. array(),
  23. '1.0'
  24. );
  25. $assetFile = include(dirname(__FILE__) . '/assets/planist-block/build/index.asset.php');
  26. wp_enqueue_script(
  27. 'planist-block-editor',
  28. plugins_url('assets/planist-block/build/index.js', __FILE__),
  29. $assetFile['dependencies'],
  30. $assetFile['version']
  31. );
  32. $data = array();
  33. wp_localize_script('planist-block-editor', 'planist', $data);
  34. }
  35. function shortcode($atts)
  36. {
  37. $atts = shortcode_atts(array(
  38. 'url' => ''
  39. ), $atts, 'planist');
  40. return $this->iframe($atts['url']);
  41. }
  42. private function iframe($url)
  43. {
  44. $path = parse_url($url)['path'];
  45. if (strpos($path, '/') !== 0) {
  46. $path = '/' . $path;
  47. }
  48. $username = explode('/', $path)[1];
  49. $url = 'https://app.planist.fr' . $path;
  50. $style = 'border: none;min-height: 500px;width: 100%;';
  51. $style = apply_filters('planist_iframe_style', $style, $url);
  52. return '<iframe src="' . esc_url($url) . '" title="' . esc_attr(ucwords($username)) . ' Booking Page" width="100%" height="100%" style="' . $style . '"></iframe>';
  53. }
  54. }
  55. new Planist();