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.

68 lines
1.9 KiB

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
  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. 'username' => '',
  39. 'duration' => ''
  40. ), $atts, 'planist');
  41. if (empty($atts['username']))
  42. return '';
  43. return $this->iframe($atts['username'], $atts['duration']);
  44. }
  45. private function iframe($username, $duration)
  46. {
  47. $url = 'https://app.planist.fr/' . $username;
  48. if (!empty($duration))
  49. $url .= '/' . $duration;
  50. $style = 'border: none;min-height: 500px;width: 100%;';
  51. $style = apply_filters('planist_iframe_style', $style, $username, $duration);
  52. return '<iframe src="' . $url . '" title="' . ucwords($username) . ' Booking Page" width="100%" height="100%" style="' . $style . '"></iframe>';
  53. }
  54. }
  55. new Planist();