notices
4 days ago
table-rate
4 days ago
tracker
4 days ago
views
4 days ago
Flexible_Shipping_Contextual_Info.php
4 days ago
class-flexible-shipping-plugin.php
4 days ago
Flexible_Shipping_Contextual_Info.php
92 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Contextual info. |
| 4 | * |
| 5 | * @package Contextual Info |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Can add contextual info script to admin footer. |
| 10 | */ |
| 11 | class Flexible_Shipping_Contextual_Info implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable { |
| 12 | |
| 13 | /** |
| 14 | * . |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | private $html_elements_ids; |
| 19 | |
| 20 | /** |
| 21 | * . |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | private $info_id; |
| 26 | |
| 27 | /** |
| 28 | * . |
| 29 | * |
| 30 | * @var string[] |
| 31 | */ |
| 32 | private $phrases_in; |
| 33 | |
| 34 | /** |
| 35 | * . |
| 36 | * |
| 37 | * @var string |
| 38 | */ |
| 39 | private $info_html; |
| 40 | |
| 41 | /** |
| 42 | * @var string[] |
| 43 | */ |
| 44 | private $phrases_not_in; |
| 45 | |
| 46 | /** |
| 47 | * Flexible_Shipping_Contextual_Info constructor. |
| 48 | * |
| 49 | * @param string $html_elements_ids Comma separated HTML element IDs to add contextual info. |
| 50 | * @param string $info_id Info element ID. |
| 51 | * @param array $phrases_in Phrases to display contextual info. |
| 52 | * @param string $info_html HTML code to display as info. |
| 53 | * @param array $phrases_not_in Phrases to not display contextual info. |
| 54 | */ |
| 55 | public function __construct( |
| 56 | $html_elements_ids, |
| 57 | $info_id, |
| 58 | array $phrases_in, |
| 59 | $info_html, |
| 60 | array $phrases_not_in = array() |
| 61 | ) { |
| 62 | $this->html_elements_ids = $html_elements_ids; |
| 63 | $this->info_id = $info_id; |
| 64 | $this->phrases_in = $phrases_in; |
| 65 | $this->info_html = $info_html; |
| 66 | $this->phrases_not_in = $phrases_not_in; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Hooks. |
| 71 | */ |
| 72 | public function hooks() { |
| 73 | add_action( 'admin_footer', array( $this, 'add_contextual_info_script' ) ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Add contextual info script. |
| 78 | */ |
| 79 | public function add_contextual_info_script() { |
| 80 | $current_screen = get_current_screen(); |
| 81 | if ( 'shop_order' === $current_screen->post_type || 'woocommerce_page_wc-settings' === $current_screen->id ) { |
| 82 | $html_elements_ids = '#' . implode( ',#', explode( ',', $this->html_elements_ids ) ); |
| 83 | $info_id = $this->info_id; |
| 84 | $phrases_in = $this->phrases_in; |
| 85 | $info_html = $this->info_html; |
| 86 | $phrases_not_in = $this->phrases_not_in; |
| 87 | include __DIR__ . '/views/contextual-info-script.php'; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | } |
| 92 |