Shortcode.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * AAM custom shortcodes service |
| 12 | * |
| 13 | * @since 6.6.0 https://github.com/aamplugin/advanced-access-manager/issues/90 |
| 14 | * @since 6.0.0 Initial implementation of the method |
| 15 | * |
| 16 | * @package AAM |
| 17 | * @version 6.6.0 |
| 18 | */ |
| 19 | class AAM_Service_Shortcode |
| 20 | { |
| 21 | use AAM_Core_Contract_ServiceTrait; |
| 22 | |
| 23 | /** |
| 24 | * AAM configuration setting that is associated with the service |
| 25 | * |
| 26 | * @version 6.0.0 |
| 27 | */ |
| 28 | const FEATURE_FLAG = 'core.service.shortcode.enabled'; |
| 29 | |
| 30 | /** |
| 31 | * Constructor |
| 32 | * |
| 33 | * @return void |
| 34 | * |
| 35 | * @access protected |
| 36 | * @version 6.0.0 |
| 37 | */ |
| 38 | protected function __construct() |
| 39 | { |
| 40 | if (is_admin()) { |
| 41 | // Hook that returns the detailed information about the nature of the |
| 42 | // service. This is used to display information about service on the |
| 43 | // Settings->Services tab |
| 44 | add_filter('aam_service_list_filter', function ($services) { |
| 45 | $services[] = array( |
| 46 | 'title' => __('Shortcodes', AAM_KEY), |
| 47 | 'description' => __('Classic WordPress shortcodes that allow to manage access to parts of a frontent content as well as some UI helpers.', AAM_KEY), |
| 48 | 'setting' => self::FEATURE_FLAG |
| 49 | ); |
| 50 | |
| 51 | return $services; |
| 52 | }, 25); |
| 53 | } |
| 54 | |
| 55 | if (AAM_Core_Config::get(self::FEATURE_FLAG, true)) { |
| 56 | $this->initializeHooks(); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Initialize Shortcode service hooks |
| 62 | * |
| 63 | * @return void |
| 64 | * |
| 65 | * @since 6.6.0 https://github.com/aamplugin/advanced-access-manager/issues/90 |
| 66 | * @since 6.0.0 Initial implementation of the method |
| 67 | * |
| 68 | * @access protected |
| 69 | * @version 6.6.0 |
| 70 | */ |
| 71 | protected function initializeHooks() |
| 72 | { |
| 73 | if (!is_admin()) { |
| 74 | add_shortcode('aam', function ($args, $content) { |
| 75 | $shortcode = new AAM_Service_Shortcode_Factory($args, $content); |
| 76 | |
| 77 | return $shortcode->process(); |
| 78 | }); |
| 79 | add_shortcode('aam-login', function($args, $content) { |
| 80 | $shortcode = new AAM_Service_Shortcode_Handler_LoginForm($args, $content); |
| 81 | |
| 82 | return $shortcode->run(); |
| 83 | }); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | |
| 89 | if (defined('AAM_KEY')) { |
| 90 | AAM_Service_Shortcode::bootstrap(); |
| 91 | } |