@@ -8,169 +8,169 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class General { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Holds class instance |
|
| 13 | - * |
|
| 14 | - * @since 1.0.0 |
|
| 15 | - * |
|
| 16 | - * @var object \lsx_health_plan\classes\frontend\General() |
|
| 17 | - */ |
|
| 18 | - protected static $instance = null; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Constructor |
|
| 22 | - */ |
|
| 23 | - public function __construct() { |
|
| 24 | - // Before Output. |
|
| 25 | - add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
|
| 26 | - add_filter( 'wp_kses_allowed_html', array( $this, 'allow_html_tags_attributes' ), 100, 2 ); |
|
| 27 | - |
|
| 28 | - // Output. |
|
| 29 | - add_action( 'body_class', array( $this, 'body_classes' ) ); |
|
| 30 | - add_filter( 'lsx_global_header_title', array( $this, 'single_title' ), 200, 1 ); |
|
| 31 | - add_action( 'wp_head', array( $this, 'remove_single_footer' ), 99 ); |
|
| 32 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 9 ); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Return an instance of this class. |
|
| 37 | - * |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * |
|
| 40 | - * @return object \lsx_health_plan\classes\frontend\General() A single instance of this class. |
|
| 41 | - */ |
|
| 42 | - public static function get_instance() { |
|
| 43 | - // If the single instance hasn't been set, set it now. |
|
| 44 | - if ( null === self::$instance ) { |
|
| 45 | - self::$instance = new self(); |
|
| 46 | - } |
|
| 47 | - return self::$instance; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Registers the plugin frontend assets |
|
| 52 | - * |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function assets() { |
|
| 56 | - |
|
| 57 | - if ( is_post_type_archive( 'plan' ) && false === \lsx_health_plan\functions\plan\is_filters_disabled() ) { |
|
| 58 | - wp_enqueue_script( 'isotope', LSX_HEALTH_PLAN_URL . 'assets/js/vendor/isotope.pkgd.min.js', array( 'jquery' ), null, LSX_HEALTH_PLAN_URL, true ); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - wp_enqueue_style( 'lsx-health-plan', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan.css', array(), LSX_HEALTH_PLAN_VER ); |
|
| 62 | - wp_style_add_data( 'lsx-health-plan', 'rtl', 'replace' ); |
|
| 63 | - wp_enqueue_script( 'lsx-health-plan-scripts', LSX_HEALTH_PLAN_URL . 'assets/js/src/lsx-health-plan-admin.js', array( 'jquery' ) ); |
|
| 64 | - |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Adds the iframe and the progress HTML tags to the allowed WordPress list. |
|
| 69 | - */ |
|
| 70 | - public function allow_html_tags_attributes( $tags, $context ) { |
|
| 71 | - if ( 'post' === $context ) { |
|
| 72 | - $tags['iframe'] = array( |
|
| 73 | - 'src' => true, |
|
| 74 | - 'height' => true, |
|
| 75 | - 'width' => true, |
|
| 76 | - 'frameborder' => true, |
|
| 77 | - 'allowfullscreen' => true, |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - $tags['progress'] = array( |
|
| 81 | - 'id' => true, |
|
| 82 | - 'value' => true, |
|
| 83 | - 'max' => true, |
|
| 84 | - ); |
|
| 85 | - return $tags; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Add body classes to body. |
|
| 90 | - * |
|
| 91 | - * @param array $classes |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function body_classes( $classes = array() ) { |
|
| 95 | - global $post; |
|
| 96 | - |
|
| 97 | - if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'lsx_health_plan_my_profile_block' ) ) { |
|
| 98 | - $classes[] = 'my-plan-shortcode'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ( is_single() && is_singular( 'plan' ) ) { |
|
| 102 | - $args = array( |
|
| 103 | - 'post_parent' => get_the_ID(), |
|
| 104 | - 'post_type' => 'plan', |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - $post_id = get_the_ID(); |
|
| 108 | - $has_children = get_children( $args ); |
|
| 109 | - $has_parent = wp_get_post_parent_id( $post_id ); |
|
| 110 | - |
|
| 111 | - if ( ! empty( $has_children ) ) { |
|
| 112 | - $plan_type_class = 'parent-plan-page'; |
|
| 113 | - if ( 0 !== $has_parent ) { |
|
| 114 | - $plan_type_class = 'parent-sub-plan-page'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - $plan_type_class = 'unique-plan-page'; |
|
| 118 | - if ( 0 !== $has_parent ) { |
|
| 119 | - $plan_type_class = 'child-plan-page'; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - $classes[] = $plan_type_class; |
|
| 123 | - } |
|
| 124 | - return $classes; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Remove the single recipe and exercise title |
|
| 129 | - */ |
|
| 130 | - public function single_title( $title ) { |
|
| 131 | - |
|
| 132 | - if ( is_single() && is_singular( 'recipe' ) ) { |
|
| 133 | - |
|
| 134 | - $title = __( 'Recipe', 'lsx-health-plan' ); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ( is_single() && is_singular( 'exercise' ) ) { |
|
| 138 | - |
|
| 139 | - $title = __( 'Exercise', 'lsx-health-plan' ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $title; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Removing footer for HP single pages. |
|
| 147 | - * |
|
| 148 | - * @return void |
|
| 149 | - */ |
|
| 150 | - public function remove_single_footer() { |
|
| 151 | - if ( is_single() && is_singular( array( 'exercise', 'recipe', 'workout', 'meal' ) ) ) { |
|
| 152 | - remove_action( 'lsx_footer_before', 'lsx_add_footer_sidebar_area' ); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - /** |
|
| 156 | - * Remove the "Archives:" from the post type recipes. |
|
| 157 | - * |
|
| 158 | - * @param string $title the term title. |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function get_the_archive_title( $title ) { |
|
| 162 | - if ( is_post_type_archive( 'recipe' ) ) { |
|
| 163 | - $title = __( 'Recipes', 'lsx-health-plan' ); |
|
| 164 | - } |
|
| 165 | - if ( is_post_type_archive( 'exercise' ) ) { |
|
| 166 | - $title = __( 'Exercises', 'lsx-health-plan' ); |
|
| 167 | - } |
|
| 168 | - if ( is_tax() ) { |
|
| 169 | - $queried_object = get_queried_object(); |
|
| 170 | - if ( isset( $queried_object->name ) ) { |
|
| 171 | - $title = $queried_object->name; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - return $title; |
|
| 175 | - } |
|
| 11 | + /** |
|
| 12 | + * Holds class instance |
|
| 13 | + * |
|
| 14 | + * @since 1.0.0 |
|
| 15 | + * |
|
| 16 | + * @var object \lsx_health_plan\classes\frontend\General() |
|
| 17 | + */ |
|
| 18 | + protected static $instance = null; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Constructor |
|
| 22 | + */ |
|
| 23 | + public function __construct() { |
|
| 24 | + // Before Output. |
|
| 25 | + add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
|
| 26 | + add_filter( 'wp_kses_allowed_html', array( $this, 'allow_html_tags_attributes' ), 100, 2 ); |
|
| 27 | + |
|
| 28 | + // Output. |
|
| 29 | + add_action( 'body_class', array( $this, 'body_classes' ) ); |
|
| 30 | + add_filter( 'lsx_global_header_title', array( $this, 'single_title' ), 200, 1 ); |
|
| 31 | + add_action( 'wp_head', array( $this, 'remove_single_footer' ), 99 ); |
|
| 32 | + add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 9 ); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Return an instance of this class. |
|
| 37 | + * |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * |
|
| 40 | + * @return object \lsx_health_plan\classes\frontend\General() A single instance of this class. |
|
| 41 | + */ |
|
| 42 | + public static function get_instance() { |
|
| 43 | + // If the single instance hasn't been set, set it now. |
|
| 44 | + if ( null === self::$instance ) { |
|
| 45 | + self::$instance = new self(); |
|
| 46 | + } |
|
| 47 | + return self::$instance; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Registers the plugin frontend assets |
|
| 52 | + * |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function assets() { |
|
| 56 | + |
|
| 57 | + if ( is_post_type_archive( 'plan' ) && false === \lsx_health_plan\functions\plan\is_filters_disabled() ) { |
|
| 58 | + wp_enqueue_script( 'isotope', LSX_HEALTH_PLAN_URL . 'assets/js/vendor/isotope.pkgd.min.js', array( 'jquery' ), null, LSX_HEALTH_PLAN_URL, true ); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + wp_enqueue_style( 'lsx-health-plan', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan.css', array(), LSX_HEALTH_PLAN_VER ); |
|
| 62 | + wp_style_add_data( 'lsx-health-plan', 'rtl', 'replace' ); |
|
| 63 | + wp_enqueue_script( 'lsx-health-plan-scripts', LSX_HEALTH_PLAN_URL . 'assets/js/src/lsx-health-plan-admin.js', array( 'jquery' ) ); |
|
| 64 | + |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Adds the iframe and the progress HTML tags to the allowed WordPress list. |
|
| 69 | + */ |
|
| 70 | + public function allow_html_tags_attributes( $tags, $context ) { |
|
| 71 | + if ( 'post' === $context ) { |
|
| 72 | + $tags['iframe'] = array( |
|
| 73 | + 'src' => true, |
|
| 74 | + 'height' => true, |
|
| 75 | + 'width' => true, |
|
| 76 | + 'frameborder' => true, |
|
| 77 | + 'allowfullscreen' => true, |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + $tags['progress'] = array( |
|
| 81 | + 'id' => true, |
|
| 82 | + 'value' => true, |
|
| 83 | + 'max' => true, |
|
| 84 | + ); |
|
| 85 | + return $tags; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Add body classes to body. |
|
| 90 | + * |
|
| 91 | + * @param array $classes |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function body_classes( $classes = array() ) { |
|
| 95 | + global $post; |
|
| 96 | + |
|
| 97 | + if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'lsx_health_plan_my_profile_block' ) ) { |
|
| 98 | + $classes[] = 'my-plan-shortcode'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ( is_single() && is_singular( 'plan' ) ) { |
|
| 102 | + $args = array( |
|
| 103 | + 'post_parent' => get_the_ID(), |
|
| 104 | + 'post_type' => 'plan', |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + $post_id = get_the_ID(); |
|
| 108 | + $has_children = get_children( $args ); |
|
| 109 | + $has_parent = wp_get_post_parent_id( $post_id ); |
|
| 110 | + |
|
| 111 | + if ( ! empty( $has_children ) ) { |
|
| 112 | + $plan_type_class = 'parent-plan-page'; |
|
| 113 | + if ( 0 !== $has_parent ) { |
|
| 114 | + $plan_type_class = 'parent-sub-plan-page'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + $plan_type_class = 'unique-plan-page'; |
|
| 118 | + if ( 0 !== $has_parent ) { |
|
| 119 | + $plan_type_class = 'child-plan-page'; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + $classes[] = $plan_type_class; |
|
| 123 | + } |
|
| 124 | + return $classes; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Remove the single recipe and exercise title |
|
| 129 | + */ |
|
| 130 | + public function single_title( $title ) { |
|
| 131 | + |
|
| 132 | + if ( is_single() && is_singular( 'recipe' ) ) { |
|
| 133 | + |
|
| 134 | + $title = __( 'Recipe', 'lsx-health-plan' ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ( is_single() && is_singular( 'exercise' ) ) { |
|
| 138 | + |
|
| 139 | + $title = __( 'Exercise', 'lsx-health-plan' ); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $title; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Removing footer for HP single pages. |
|
| 147 | + * |
|
| 148 | + * @return void |
|
| 149 | + */ |
|
| 150 | + public function remove_single_footer() { |
|
| 151 | + if ( is_single() && is_singular( array( 'exercise', 'recipe', 'workout', 'meal' ) ) ) { |
|
| 152 | + remove_action( 'lsx_footer_before', 'lsx_add_footer_sidebar_area' ); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + /** |
|
| 156 | + * Remove the "Archives:" from the post type recipes. |
|
| 157 | + * |
|
| 158 | + * @param string $title the term title. |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function get_the_archive_title( $title ) { |
|
| 162 | + if ( is_post_type_archive( 'recipe' ) ) { |
|
| 163 | + $title = __( 'Recipes', 'lsx-health-plan' ); |
|
| 164 | + } |
|
| 165 | + if ( is_post_type_archive( 'exercise' ) ) { |
|
| 166 | + $title = __( 'Exercises', 'lsx-health-plan' ); |
|
| 167 | + } |
|
| 168 | + if ( is_tax() ) { |
|
| 169 | + $queried_object = get_queried_object(); |
|
| 170 | + if ( isset( $queried_object->name ) ) { |
|
| 171 | + $title = $queried_object->name; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + return $title; |
|
| 175 | + } |
|
| 176 | 176 | } |