@@ -8,119 +8,119 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Integrations { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Holds class instance |
|
| 13 | - * |
|
| 14 | - * @since 1.0.0 |
|
| 15 | - * |
|
| 16 | - * @var object \lsx_health_plan\classes\Integrations() |
|
| 17 | - */ |
|
| 18 | - protected static $instance = null; |
|
| 11 | + /** |
|
| 12 | + * Holds class instance |
|
| 13 | + * |
|
| 14 | + * @since 1.0.0 |
|
| 15 | + * |
|
| 16 | + * @var object \lsx_health_plan\classes\Integrations() |
|
| 17 | + */ |
|
| 18 | + protected static $instance = null; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Holds class instance |
|
| 22 | - * |
|
| 23 | - * @since 1.0.0 |
|
| 24 | - * |
|
| 25 | - * @var object \MAG_CMB2_Field_Post_Search_Ajax() |
|
| 26 | - */ |
|
| 27 | - public $cmb2_post_search_ajax = false; |
|
| 20 | + /** |
|
| 21 | + * Holds class instance |
|
| 22 | + * |
|
| 23 | + * @since 1.0.0 |
|
| 24 | + * |
|
| 25 | + * @var object \MAG_CMB2_Field_Post_Search_Ajax() |
|
| 26 | + */ |
|
| 27 | + public $cmb2_post_search_ajax = false; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Holds class instance |
|
| 31 | - * |
|
| 32 | - * @since 1.0.0 |
|
| 33 | - * |
|
| 34 | - * @var object \lsx_health_plan\classes\Download_Monitor() |
|
| 35 | - */ |
|
| 36 | - public $download_monitor = false; |
|
| 29 | + /** |
|
| 30 | + * Holds class instance |
|
| 31 | + * |
|
| 32 | + * @since 1.0.0 |
|
| 33 | + * |
|
| 34 | + * @var object \lsx_health_plan\classes\Download_Monitor() |
|
| 35 | + */ |
|
| 36 | + public $download_monitor = false; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Holds class instance |
|
| 40 | - * |
|
| 41 | - * @since 1.0.0 |
|
| 42 | - * |
|
| 43 | - * @var object \lsx_health_plan\classes\Woocommerce() |
|
| 44 | - */ |
|
| 45 | - public $woocommerce = false; |
|
| 38 | + /** |
|
| 39 | + * Holds class instance |
|
| 40 | + * |
|
| 41 | + * @since 1.0.0 |
|
| 42 | + * |
|
| 43 | + * @var object \lsx_health_plan\classes\Woocommerce() |
|
| 44 | + */ |
|
| 45 | + public $woocommerce = false; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Holds class instance |
|
| 49 | - * |
|
| 50 | - * @since 1.0.0 |
|
| 51 | - * |
|
| 52 | - * @var object \lsx_health_plan\classes\WP_User_Avatar() |
|
| 53 | - */ |
|
| 54 | - public $wp_user_avatar = false; |
|
| 47 | + /** |
|
| 48 | + * Holds class instance |
|
| 49 | + * |
|
| 50 | + * @since 1.0.0 |
|
| 51 | + * |
|
| 52 | + * @var object \lsx_health_plan\classes\WP_User_Avatar() |
|
| 53 | + */ |
|
| 54 | + public $wp_user_avatar = false; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Contructor |
|
| 58 | - */ |
|
| 59 | - public function __construct() { |
|
| 60 | - add_action( 'init', array( $this, 'cmb2_post_search_ajax' ) ); |
|
| 61 | - add_action( 'init', array( $this, 'download_monitor_init' ) ); |
|
| 62 | - add_action( 'init', array( $this, 'woocommerce_init' ) ); |
|
| 63 | - add_action( 'init', array( $this, 'wp_user_avatar_init' ) ); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Contructor |
|
| 58 | + */ |
|
| 59 | + public function __construct() { |
|
| 60 | + add_action( 'init', array( $this, 'cmb2_post_search_ajax' ) ); |
|
| 61 | + add_action( 'init', array( $this, 'download_monitor_init' ) ); |
|
| 62 | + add_action( 'init', array( $this, 'woocommerce_init' ) ); |
|
| 63 | + add_action( 'init', array( $this, 'wp_user_avatar_init' ) ); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Return an instance of this class. |
|
| 68 | - * |
|
| 69 | - * @since 1.0.0 |
|
| 70 | - * |
|
| 71 | - * @return object \lsx_health_plan\classes\Integrations() A single instance of this class. |
|
| 72 | - */ |
|
| 73 | - public static function get_instance() { |
|
| 74 | - // If the single instance hasn't been set, set it now. |
|
| 75 | - if ( null === self::$instance ) { |
|
| 76 | - self::$instance = new self(); |
|
| 77 | - } |
|
| 78 | - return self::$instance; |
|
| 79 | - } |
|
| 66 | + /** |
|
| 67 | + * Return an instance of this class. |
|
| 68 | + * |
|
| 69 | + * @since 1.0.0 |
|
| 70 | + * |
|
| 71 | + * @return object \lsx_health_plan\classes\Integrations() A single instance of this class. |
|
| 72 | + */ |
|
| 73 | + public static function get_instance() { |
|
| 74 | + // If the single instance hasn't been set, set it now. |
|
| 75 | + if ( null === self::$instance ) { |
|
| 76 | + self::$instance = new self(); |
|
| 77 | + } |
|
| 78 | + return self::$instance; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Includes the Post Search Ajax if it is there. |
|
| 83 | - * |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public function cmb2_post_search_ajax() { |
|
| 87 | - require_once LSX_HEALTH_PLAN_PATH . 'vendor/lsx-field-post-search-ajax/cmb-field-post-search-ajax.php'; |
|
| 88 | - $this->cmb2_post_search_ajax = new \MAG_CMB2_Field_Post_Search_Ajax(); |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * Includes the Post Search Ajax if it is there. |
|
| 83 | + * |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public function cmb2_post_search_ajax() { |
|
| 87 | + require_once LSX_HEALTH_PLAN_PATH . 'vendor/lsx-field-post-search-ajax/cmb-field-post-search-ajax.php'; |
|
| 88 | + $this->cmb2_post_search_ajax = new \MAG_CMB2_Field_Post_Search_Ajax(); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Includes the Post Search Ajax if it is there. |
|
| 93 | - * |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - public function download_monitor_init() { |
|
| 97 | - if ( function_exists( 'download_monitor' ) ) { |
|
| 98 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/integrations/class-download-monitor.php'; |
|
| 99 | - $this->download_monitor = Download_Monitor::get_instance(); |
|
| 100 | - } |
|
| 101 | - } |
|
| 91 | + /** |
|
| 92 | + * Includes the Post Search Ajax if it is there. |
|
| 93 | + * |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + public function download_monitor_init() { |
|
| 97 | + if ( function_exists( 'download_monitor' ) ) { |
|
| 98 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/integrations/class-download-monitor.php'; |
|
| 99 | + $this->download_monitor = Download_Monitor::get_instance(); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Includes the Woocommerce functions. |
|
| 105 | - * |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public function woocommerce_init() { |
|
| 109 | - if ( function_exists( 'WC' ) ) { |
|
| 110 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/integrations/class-woocommerce.php'; |
|
| 111 | - $this->woocommerce = Woocommerce::get_instance(); |
|
| 112 | - } |
|
| 113 | - } |
|
| 103 | + /** |
|
| 104 | + * Includes the Woocommerce functions. |
|
| 105 | + * |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public function woocommerce_init() { |
|
| 109 | + if ( function_exists( 'WC' ) ) { |
|
| 110 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/integrations/class-woocommerce.php'; |
|
| 111 | + $this->woocommerce = Woocommerce::get_instance(); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Includes the Woocommerce functions. |
|
| 117 | - * |
|
| 118 | - * @return void |
|
| 119 | - */ |
|
| 120 | - public function wp_user_avatar_init() { |
|
| 121 | - if ( class_exists( 'WP_User_Avatar_Setup' ) ) { |
|
| 122 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/integrations/class-wp-user-avatar.php'; |
|
| 123 | - $this->wp_user_avatar = WP_User_Avatar::get_instance(); |
|
| 124 | - } |
|
| 125 | - } |
|
| 115 | + /** |
|
| 116 | + * Includes the Woocommerce functions. |
|
| 117 | + * |
|
| 118 | + * @return void |
|
| 119 | + */ |
|
| 120 | + public function wp_user_avatar_init() { |
|
| 121 | + if ( class_exists( 'WP_User_Avatar_Setup' ) ) { |
|
| 122 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/integrations/class-wp-user-avatar.php'; |
|
| 123 | + $this->wp_user_avatar = WP_User_Avatar::get_instance(); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -8,343 +8,343 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Admin { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Holds class instance |
|
| 13 | - * |
|
| 14 | - * @since 1.0.0 |
|
| 15 | - * |
|
| 16 | - * @var object \lsx_health_plan\classes\Admin() |
|
| 17 | - */ |
|
| 18 | - protected static $instance = null; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The post relation fields |
|
| 22 | - * |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $connections = array(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Stores the previous values needed to remove the post relations |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - public $previous_values = array(); |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var object \lsx_health_plan\classes\admin\Settings(); |
|
| 36 | - */ |
|
| 37 | - public $settings; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var object \lsx_health_plan\classes\admin\Help_Page(); |
|
| 41 | - */ |
|
| 42 | - public $help; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Holds the settings page theme functions |
|
| 46 | - * |
|
| 47 | - * @var object \lsx_health_plan\classes\admin\Settings_Theme(); |
|
| 48 | - */ |
|
| 49 | - public $settings_theme; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Contructor |
|
| 53 | - */ |
|
| 54 | - public function __construct() { |
|
| 55 | - $this->load_classes(); |
|
| 56 | - add_action( 'admin_menu', array( $this, 'order_menus' ), 200 ); |
|
| 57 | - add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
| 58 | - add_filter( 'cmb2_override_meta_save', array( $this, 'save_previous_values' ), 20, 4 ); |
|
| 59 | - add_filter( 'cmb2_override_meta_remove', array( $this, 'save_previous_values' ), 20, 4 ); |
|
| 60 | - add_action( 'cmb2_save_field', array( $this, 'post_relations' ), 20, 4 ); |
|
| 61 | - add_action( 'before_delete_post', array( $this, 'delete_post_meta_connections' ), 20, 1 ); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Return an instance of this class. |
|
| 66 | - * |
|
| 67 | - * @return object \lsx\member_directory\classes\Admin() A single instance of this class. |
|
| 68 | - */ |
|
| 69 | - public static function get_instance() { |
|
| 70 | - // If the single instance hasn't been set, set it now. |
|
| 71 | - if ( null === self::$instance ) { |
|
| 72 | - self::$instance = new self(); |
|
| 73 | - } |
|
| 74 | - return self::$instance; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Loads the admin subclasses |
|
| 79 | - */ |
|
| 80 | - private function load_classes() { |
|
| 81 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-settings.php'; |
|
| 82 | - $this->settings = admin\Settings::get_instance(); |
|
| 83 | - |
|
| 84 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-help-page.php'; |
|
| 85 | - $this->help = admin\Help_Page::get_instance(); |
|
| 86 | - |
|
| 87 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-settings-theme.php'; |
|
| 88 | - $this->settings_theme = admin\Settings_Theme::get_instance(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Orders the HP menu Items |
|
| 93 | - * |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - public function order_menus() { |
|
| 97 | - global $menu, $submenu; |
|
| 98 | - if ( ! empty( $submenu ) ) { |
|
| 99 | - $parent_check = array( |
|
| 100 | - 'edit.php?post_type=plan', |
|
| 101 | - 'edit.php?post_type=workout', |
|
| 102 | - 'edit.php?post_type=meal', |
|
| 103 | - ); |
|
| 104 | - foreach ( $submenu as $menu_id => $menu_values ) { |
|
| 105 | - if ( in_array( $menu_id, $parent_check ) ) { |
|
| 106 | - foreach ( $menu_values as $sub_menu_key => $sub_menu_values ) { |
|
| 107 | - switch ( $sub_menu_values[0] ) { |
|
| 108 | - |
|
| 109 | - case __( 'Add New', 'lsx-health-plan' ): |
|
| 110 | - unset( $submenu[ $menu_id ][ $sub_menu_key ] ); |
|
| 111 | - break; |
|
| 112 | - |
|
| 113 | - case __( 'All', 'lsx-health-plan' ): |
|
| 114 | - $title = $sub_menu_values[0]; |
|
| 115 | - // Check and change the label. |
|
| 116 | - switch ( $sub_menu_values[2] ) { |
|
| 117 | - case 'edit.php?post_type=meal': |
|
| 118 | - $title = esc_attr__( 'Meals', 'lsx-health-plan' ); |
|
| 119 | - break; |
|
| 120 | - |
|
| 121 | - case 'edit.php?post_type=recipe': |
|
| 122 | - $title = esc_attr__( 'Recipes', 'lsx-health-plan' ); |
|
| 123 | - break; |
|
| 124 | - |
|
| 125 | - case 'edit.php?post_type=workout': |
|
| 126 | - $title = esc_attr__( 'Workouts', 'lsx-health-plan' ); |
|
| 127 | - break; |
|
| 128 | - |
|
| 129 | - case 'edit.php?post_type=plan': |
|
| 130 | - $title = esc_attr__( 'Plans', 'lsx-health-plan' ); |
|
| 131 | - break; |
|
| 132 | - |
|
| 133 | - case 'edit.php?post_type=video': |
|
| 134 | - $title = esc_attr__( 'Videos', 'lsx-health-plan' ); |
|
| 135 | - break; |
|
| 136 | - |
|
| 137 | - case 'edit.php?post_type=exercise': |
|
| 138 | - $title = esc_attr__( 'Exercises', 'lsx-health-plan' ); |
|
| 139 | - break; |
|
| 140 | - |
|
| 141 | - case 'edit.php?post_type=tip': |
|
| 142 | - $title = esc_attr__( 'Tips', 'lsx-health-plan' ); |
|
| 143 | - break; |
|
| 144 | - |
|
| 145 | - default: |
|
| 146 | - break; |
|
| 147 | - } |
|
| 148 | - $submenu[ $menu_id ][ $sub_menu_key ][0] = $title; // @codingStandardsIgnoreLine |
|
| 149 | - break; |
|
| 150 | - |
|
| 151 | - default: |
|
| 152 | - break; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Undocumented function |
|
| 162 | - * |
|
| 163 | - * @return void |
|
| 164 | - */ |
|
| 165 | - public function assets() { |
|
| 166 | - wp_enqueue_script( 'media-upload' ); |
|
| 167 | - wp_enqueue_script( 'thickbox' ); |
|
| 168 | - wp_enqueue_style( 'thickbox' ); |
|
| 169 | - |
|
| 170 | - wp_enqueue_script( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/js/lsx-health-plan-admin.min.js', array( 'jquery' ), LSX_HEALTH_PLAN_VER, true ); |
|
| 171 | - wp_enqueue_style( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan-admin.css', array(), LSX_HEALTH_PLAN_VER ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Returns the registered connections. |
|
| 176 | - * |
|
| 177 | - * @return void |
|
| 178 | - */ |
|
| 179 | - public function get_connections() { |
|
| 180 | - return apply_filters( 'lsx_health_plan_connections', $this->connections ); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Saves the previous values before they are overwritten by the new ones. |
|
| 185 | - * |
|
| 186 | - * @param [type] $value_to_save |
|
| 187 | - * @param [type] $a |
|
| 188 | - * @param [type] $args |
|
| 189 | - * @param [type] $cmb2 |
|
| 190 | - * @return void |
|
| 191 | - */ |
|
| 192 | - public function save_previous_values( $value_to_save, $a, $args, $cmb2 ) { |
|
| 193 | - if ( isset( $cmb2->data_to_save['ID'] ) ) { |
|
| 194 | - $connections = $this->get_connections(); |
|
| 195 | - $post_type = get_post_type( $cmb2->data_to_save['ID'] ); |
|
| 196 | - if ( isset( $connections[ $post_type ] ) && array_key_exists( $a['field_id'], $connections[ $post_type ] ) ) { |
|
| 197 | - // Get the previous values if the field, so we can run through them and remove the current ID from them later. |
|
| 198 | - $this->previous_values = get_post_meta( $a['id'], $a['field_id'], true ); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - return $value_to_save; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Sets up the "post relations" |
|
| 206 | - * |
|
| 207 | - * @return void |
|
| 208 | - */ |
|
| 209 | - public function post_relations( $field_id, $updated, $action, $cmb2 ) { |
|
| 210 | - // If the connections are empty then skip this function. |
|
| 211 | - $connections = $this->get_connections(); |
|
| 212 | - if ( empty( $connections ) ) { |
|
| 213 | - return; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // If the field has been updated. |
|
| 217 | - if ( isset( $cmb2->data_to_save['ID'] ) ) { |
|
| 218 | - $post_type = get_post_type( $cmb2->data_to_save['ID'] ); |
|
| 219 | - if ( isset( $connections[ $post_type ] ) && array_key_exists( $field_id, $connections[ $post_type ] ) ) { |
|
| 220 | - $saved_values = get_post_meta( $cmb2->data_to_save['ID'], $field_id, true ); |
|
| 221 | - |
|
| 222 | - if ( 'updated' === $action ) { |
|
| 223 | - $this->add_connected_posts( $saved_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] ); |
|
| 224 | - // Check if any posts have been removed. |
|
| 225 | - if ( count( $this->previous_values ) > count( $saved_values ) ) { |
|
| 226 | - $posts_to_remove = array_diff( $this->previous_values, $saved_values ); |
|
| 227 | - if ( ! empty( $posts_to_remove ) ) { |
|
| 228 | - $this->remove_connected_posts( $posts_to_remove, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] ); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } else if ( 'removed' === $action && ! empty( $this->previous_values ) ) { |
|
| 232 | - $this->remove_connected_posts( $this->previous_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] ); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Updates the connected posts witht he current post ID |
|
| 240 | - * |
|
| 241 | - * @param [type] $values |
|
| 242 | - * @param [type] $current_id |
|
| 243 | - * @param [type] $connected_key |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - public function add_connected_posts( $values, $current_id, $connected_key ) { |
|
| 247 | - foreach ( $values as $value ) { |
|
| 248 | - $current_post_array = get_post_meta( $value, $connected_key, true ); |
|
| 249 | - $previous_values = $current_post_array; |
|
| 250 | - |
|
| 251 | - if ( ! empty( $current_post_array ) ) { |
|
| 252 | - $current_post_array = array_map( 'strval', $current_post_array ); |
|
| 253 | - array_unique( $current_post_array ); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // If the current connected post has no saved connections then we create it. |
|
| 257 | - if ( false === $current_post_array || empty( $current_post_array ) ) { |
|
| 258 | - $current_post_array = array( $current_id ); |
|
| 259 | - } elseif ( ! in_array( (string) $current_id, $current_post_array, true ) ) { |
|
| 260 | - $current_post_array[] = $current_id; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - // Check if the values are empty, if not update them. |
|
| 264 | - if ( ! empty( $current_post_array ) ) { |
|
| 265 | - update_post_meta( $value, $connected_key, $current_post_array, $previous_values ); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Removes the post ID from the connected posts. |
|
| 272 | - * |
|
| 273 | - * @param [type] $values |
|
| 274 | - * @param [type] $current_ID |
|
| 275 | - * @param [type] $connected_key |
|
| 276 | - * @return void |
|
| 277 | - */ |
|
| 278 | - public function remove_connected_posts( $values, $current_ID, $connected_key ) { |
|
| 279 | - foreach ( $values as $value ) { |
|
| 280 | - $current_post_array = get_post_meta( $value, $connected_key, true ); |
|
| 281 | - $new_array = array(); |
|
| 282 | - // Loop through only if the current ID has been saved against the post. |
|
| 283 | - if ( in_array( $current_ID, $current_post_array, false ) ) { |
|
| 284 | - |
|
| 285 | - // Loop through all the connected saved IDS. |
|
| 286 | - foreach ( $current_post_array as $cpa ) { |
|
| 287 | - if ( (int) $cpa !== (int) $current_ID ) { |
|
| 288 | - $new_array[] = $cpa; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - if ( ! empty( $new_array ) ) { |
|
| 292 | - $new_array = array_unique( $new_array ); |
|
| 293 | - delete_post_meta( $value, $connected_key ); |
|
| 294 | - add_post_meta( $value, $connected_key, $new_array, true ); |
|
| 295 | - } else { |
|
| 296 | - delete_post_meta( $value, $connected_key ); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Runs on 'before_delete_post' to run through and remove this post ID from its connected values. |
|
| 304 | - * |
|
| 305 | - * @param string $item_id |
|
| 306 | - * @return void |
|
| 307 | - */ |
|
| 308 | - public function delete_post_meta_connections( $item_id = '' ) { |
|
| 309 | - if ( '' !== $item_id ) { |
|
| 310 | - $post_type = get_post_type( $item_id ); |
|
| 311 | - $connections = $this->get_connections(); |
|
| 312 | - if ( isset( $connections[ $post_type ] ) && ! empty( $connections[ $post_type ] ) && is_array( $connections[ $post_type ] ) ) { |
|
| 313 | - foreach ( $connections[ $post_type ] as $this_key => $connected_key ) { |
|
| 314 | - $this->delete_connected_items( $item_id, $this_key, $connected_key ); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * This function will remvoe the post id fomr its connected posts. |
|
| 322 | - * |
|
| 323 | - * @param string $item_id |
|
| 324 | - * @param string $this_key |
|
| 325 | - * @param string $connected_key |
|
| 326 | - * @return void |
|
| 327 | - */ |
|
| 328 | - public function delete_connected_items( $item_id = '', $this_key, $connected_key ) { |
|
| 329 | - if ( '' !== $item_id ) { |
|
| 330 | - $connected_items = get_post_meta( $item_id, $this_key, true ); |
|
| 331 | - if ( ! empty( $connected_items ) ) { |
|
| 332 | - foreach ( $connected_items as $con_id ) { |
|
| 333 | - // Get the connected item array from the connected item. |
|
| 334 | - $their_connections = get_post_meta( $con_id, $connected_key, true ); |
|
| 335 | - if ( ! empty( $their_connections ) ) { |
|
| 336 | - $new_connections = $their_connections; |
|
| 337 | - // Run through the array and remove the post to be deleteds ID. |
|
| 338 | - foreach ( $their_connections as $ckey => $cvalue ) { |
|
| 339 | - if ( (int) $item_id === (int) $cvalue ) { |
|
| 340 | - unset( $new_connections[ $ckey ] ); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - // Now we save the field. |
|
| 344 | - update_post_meta( $con_id, $connected_key, $new_connections, $their_connections ); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 11 | + /** |
|
| 12 | + * Holds class instance |
|
| 13 | + * |
|
| 14 | + * @since 1.0.0 |
|
| 15 | + * |
|
| 16 | + * @var object \lsx_health_plan\classes\Admin() |
|
| 17 | + */ |
|
| 18 | + protected static $instance = null; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The post relation fields |
|
| 22 | + * |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $connections = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Stores the previous values needed to remove the post relations |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + public $previous_values = array(); |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var object \lsx_health_plan\classes\admin\Settings(); |
|
| 36 | + */ |
|
| 37 | + public $settings; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var object \lsx_health_plan\classes\admin\Help_Page(); |
|
| 41 | + */ |
|
| 42 | + public $help; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Holds the settings page theme functions |
|
| 46 | + * |
|
| 47 | + * @var object \lsx_health_plan\classes\admin\Settings_Theme(); |
|
| 48 | + */ |
|
| 49 | + public $settings_theme; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Contructor |
|
| 53 | + */ |
|
| 54 | + public function __construct() { |
|
| 55 | + $this->load_classes(); |
|
| 56 | + add_action( 'admin_menu', array( $this, 'order_menus' ), 200 ); |
|
| 57 | + add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); |
|
| 58 | + add_filter( 'cmb2_override_meta_save', array( $this, 'save_previous_values' ), 20, 4 ); |
|
| 59 | + add_filter( 'cmb2_override_meta_remove', array( $this, 'save_previous_values' ), 20, 4 ); |
|
| 60 | + add_action( 'cmb2_save_field', array( $this, 'post_relations' ), 20, 4 ); |
|
| 61 | + add_action( 'before_delete_post', array( $this, 'delete_post_meta_connections' ), 20, 1 ); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Return an instance of this class. |
|
| 66 | + * |
|
| 67 | + * @return object \lsx\member_directory\classes\Admin() A single instance of this class. |
|
| 68 | + */ |
|
| 69 | + public static function get_instance() { |
|
| 70 | + // If the single instance hasn't been set, set it now. |
|
| 71 | + if ( null === self::$instance ) { |
|
| 72 | + self::$instance = new self(); |
|
| 73 | + } |
|
| 74 | + return self::$instance; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Loads the admin subclasses |
|
| 79 | + */ |
|
| 80 | + private function load_classes() { |
|
| 81 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-settings.php'; |
|
| 82 | + $this->settings = admin\Settings::get_instance(); |
|
| 83 | + |
|
| 84 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-help-page.php'; |
|
| 85 | + $this->help = admin\Help_Page::get_instance(); |
|
| 86 | + |
|
| 87 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/class-settings-theme.php'; |
|
| 88 | + $this->settings_theme = admin\Settings_Theme::get_instance(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Orders the HP menu Items |
|
| 93 | + * |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + public function order_menus() { |
|
| 97 | + global $menu, $submenu; |
|
| 98 | + if ( ! empty( $submenu ) ) { |
|
| 99 | + $parent_check = array( |
|
| 100 | + 'edit.php?post_type=plan', |
|
| 101 | + 'edit.php?post_type=workout', |
|
| 102 | + 'edit.php?post_type=meal', |
|
| 103 | + ); |
|
| 104 | + foreach ( $submenu as $menu_id => $menu_values ) { |
|
| 105 | + if ( in_array( $menu_id, $parent_check ) ) { |
|
| 106 | + foreach ( $menu_values as $sub_menu_key => $sub_menu_values ) { |
|
| 107 | + switch ( $sub_menu_values[0] ) { |
|
| 108 | + |
|
| 109 | + case __( 'Add New', 'lsx-health-plan' ): |
|
| 110 | + unset( $submenu[ $menu_id ][ $sub_menu_key ] ); |
|
| 111 | + break; |
|
| 112 | + |
|
| 113 | + case __( 'All', 'lsx-health-plan' ): |
|
| 114 | + $title = $sub_menu_values[0]; |
|
| 115 | + // Check and change the label. |
|
| 116 | + switch ( $sub_menu_values[2] ) { |
|
| 117 | + case 'edit.php?post_type=meal': |
|
| 118 | + $title = esc_attr__( 'Meals', 'lsx-health-plan' ); |
|
| 119 | + break; |
|
| 120 | + |
|
| 121 | + case 'edit.php?post_type=recipe': |
|
| 122 | + $title = esc_attr__( 'Recipes', 'lsx-health-plan' ); |
|
| 123 | + break; |
|
| 124 | + |
|
| 125 | + case 'edit.php?post_type=workout': |
|
| 126 | + $title = esc_attr__( 'Workouts', 'lsx-health-plan' ); |
|
| 127 | + break; |
|
| 128 | + |
|
| 129 | + case 'edit.php?post_type=plan': |
|
| 130 | + $title = esc_attr__( 'Plans', 'lsx-health-plan' ); |
|
| 131 | + break; |
|
| 132 | + |
|
| 133 | + case 'edit.php?post_type=video': |
|
| 134 | + $title = esc_attr__( 'Videos', 'lsx-health-plan' ); |
|
| 135 | + break; |
|
| 136 | + |
|
| 137 | + case 'edit.php?post_type=exercise': |
|
| 138 | + $title = esc_attr__( 'Exercises', 'lsx-health-plan' ); |
|
| 139 | + break; |
|
| 140 | + |
|
| 141 | + case 'edit.php?post_type=tip': |
|
| 142 | + $title = esc_attr__( 'Tips', 'lsx-health-plan' ); |
|
| 143 | + break; |
|
| 144 | + |
|
| 145 | + default: |
|
| 146 | + break; |
|
| 147 | + } |
|
| 148 | + $submenu[ $menu_id ][ $sub_menu_key ][0] = $title; // @codingStandardsIgnoreLine |
|
| 149 | + break; |
|
| 150 | + |
|
| 151 | + default: |
|
| 152 | + break; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Undocumented function |
|
| 162 | + * |
|
| 163 | + * @return void |
|
| 164 | + */ |
|
| 165 | + public function assets() { |
|
| 166 | + wp_enqueue_script( 'media-upload' ); |
|
| 167 | + wp_enqueue_script( 'thickbox' ); |
|
| 168 | + wp_enqueue_style( 'thickbox' ); |
|
| 169 | + |
|
| 170 | + wp_enqueue_script( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/js/lsx-health-plan-admin.min.js', array( 'jquery' ), LSX_HEALTH_PLAN_VER, true ); |
|
| 171 | + wp_enqueue_style( 'lsx-health-plan-admin', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan-admin.css', array(), LSX_HEALTH_PLAN_VER ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Returns the registered connections. |
|
| 176 | + * |
|
| 177 | + * @return void |
|
| 178 | + */ |
|
| 179 | + public function get_connections() { |
|
| 180 | + return apply_filters( 'lsx_health_plan_connections', $this->connections ); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Saves the previous values before they are overwritten by the new ones. |
|
| 185 | + * |
|
| 186 | + * @param [type] $value_to_save |
|
| 187 | + * @param [type] $a |
|
| 188 | + * @param [type] $args |
|
| 189 | + * @param [type] $cmb2 |
|
| 190 | + * @return void |
|
| 191 | + */ |
|
| 192 | + public function save_previous_values( $value_to_save, $a, $args, $cmb2 ) { |
|
| 193 | + if ( isset( $cmb2->data_to_save['ID'] ) ) { |
|
| 194 | + $connections = $this->get_connections(); |
|
| 195 | + $post_type = get_post_type( $cmb2->data_to_save['ID'] ); |
|
| 196 | + if ( isset( $connections[ $post_type ] ) && array_key_exists( $a['field_id'], $connections[ $post_type ] ) ) { |
|
| 197 | + // Get the previous values if the field, so we can run through them and remove the current ID from them later. |
|
| 198 | + $this->previous_values = get_post_meta( $a['id'], $a['field_id'], true ); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + return $value_to_save; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Sets up the "post relations" |
|
| 206 | + * |
|
| 207 | + * @return void |
|
| 208 | + */ |
|
| 209 | + public function post_relations( $field_id, $updated, $action, $cmb2 ) { |
|
| 210 | + // If the connections are empty then skip this function. |
|
| 211 | + $connections = $this->get_connections(); |
|
| 212 | + if ( empty( $connections ) ) { |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // If the field has been updated. |
|
| 217 | + if ( isset( $cmb2->data_to_save['ID'] ) ) { |
|
| 218 | + $post_type = get_post_type( $cmb2->data_to_save['ID'] ); |
|
| 219 | + if ( isset( $connections[ $post_type ] ) && array_key_exists( $field_id, $connections[ $post_type ] ) ) { |
|
| 220 | + $saved_values = get_post_meta( $cmb2->data_to_save['ID'], $field_id, true ); |
|
| 221 | + |
|
| 222 | + if ( 'updated' === $action ) { |
|
| 223 | + $this->add_connected_posts( $saved_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] ); |
|
| 224 | + // Check if any posts have been removed. |
|
| 225 | + if ( count( $this->previous_values ) > count( $saved_values ) ) { |
|
| 226 | + $posts_to_remove = array_diff( $this->previous_values, $saved_values ); |
|
| 227 | + if ( ! empty( $posts_to_remove ) ) { |
|
| 228 | + $this->remove_connected_posts( $posts_to_remove, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } else if ( 'removed' === $action && ! empty( $this->previous_values ) ) { |
|
| 232 | + $this->remove_connected_posts( $this->previous_values, $cmb2->data_to_save['ID'], $connections[ $post_type ][ $field_id ] ); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Updates the connected posts witht he current post ID |
|
| 240 | + * |
|
| 241 | + * @param [type] $values |
|
| 242 | + * @param [type] $current_id |
|
| 243 | + * @param [type] $connected_key |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + public function add_connected_posts( $values, $current_id, $connected_key ) { |
|
| 247 | + foreach ( $values as $value ) { |
|
| 248 | + $current_post_array = get_post_meta( $value, $connected_key, true ); |
|
| 249 | + $previous_values = $current_post_array; |
|
| 250 | + |
|
| 251 | + if ( ! empty( $current_post_array ) ) { |
|
| 252 | + $current_post_array = array_map( 'strval', $current_post_array ); |
|
| 253 | + array_unique( $current_post_array ); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // If the current connected post has no saved connections then we create it. |
|
| 257 | + if ( false === $current_post_array || empty( $current_post_array ) ) { |
|
| 258 | + $current_post_array = array( $current_id ); |
|
| 259 | + } elseif ( ! in_array( (string) $current_id, $current_post_array, true ) ) { |
|
| 260 | + $current_post_array[] = $current_id; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + // Check if the values are empty, if not update them. |
|
| 264 | + if ( ! empty( $current_post_array ) ) { |
|
| 265 | + update_post_meta( $value, $connected_key, $current_post_array, $previous_values ); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Removes the post ID from the connected posts. |
|
| 272 | + * |
|
| 273 | + * @param [type] $values |
|
| 274 | + * @param [type] $current_ID |
|
| 275 | + * @param [type] $connected_key |
|
| 276 | + * @return void |
|
| 277 | + */ |
|
| 278 | + public function remove_connected_posts( $values, $current_ID, $connected_key ) { |
|
| 279 | + foreach ( $values as $value ) { |
|
| 280 | + $current_post_array = get_post_meta( $value, $connected_key, true ); |
|
| 281 | + $new_array = array(); |
|
| 282 | + // Loop through only if the current ID has been saved against the post. |
|
| 283 | + if ( in_array( $current_ID, $current_post_array, false ) ) { |
|
| 284 | + |
|
| 285 | + // Loop through all the connected saved IDS. |
|
| 286 | + foreach ( $current_post_array as $cpa ) { |
|
| 287 | + if ( (int) $cpa !== (int) $current_ID ) { |
|
| 288 | + $new_array[] = $cpa; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + if ( ! empty( $new_array ) ) { |
|
| 292 | + $new_array = array_unique( $new_array ); |
|
| 293 | + delete_post_meta( $value, $connected_key ); |
|
| 294 | + add_post_meta( $value, $connected_key, $new_array, true ); |
|
| 295 | + } else { |
|
| 296 | + delete_post_meta( $value, $connected_key ); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Runs on 'before_delete_post' to run through and remove this post ID from its connected values. |
|
| 304 | + * |
|
| 305 | + * @param string $item_id |
|
| 306 | + * @return void |
|
| 307 | + */ |
|
| 308 | + public function delete_post_meta_connections( $item_id = '' ) { |
|
| 309 | + if ( '' !== $item_id ) { |
|
| 310 | + $post_type = get_post_type( $item_id ); |
|
| 311 | + $connections = $this->get_connections(); |
|
| 312 | + if ( isset( $connections[ $post_type ] ) && ! empty( $connections[ $post_type ] ) && is_array( $connections[ $post_type ] ) ) { |
|
| 313 | + foreach ( $connections[ $post_type ] as $this_key => $connected_key ) { |
|
| 314 | + $this->delete_connected_items( $item_id, $this_key, $connected_key ); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * This function will remvoe the post id fomr its connected posts. |
|
| 322 | + * |
|
| 323 | + * @param string $item_id |
|
| 324 | + * @param string $this_key |
|
| 325 | + * @param string $connected_key |
|
| 326 | + * @return void |
|
| 327 | + */ |
|
| 328 | + public function delete_connected_items( $item_id = '', $this_key, $connected_key ) { |
|
| 329 | + if ( '' !== $item_id ) { |
|
| 330 | + $connected_items = get_post_meta( $item_id, $this_key, true ); |
|
| 331 | + if ( ! empty( $connected_items ) ) { |
|
| 332 | + foreach ( $connected_items as $con_id ) { |
|
| 333 | + // Get the connected item array from the connected item. |
|
| 334 | + $their_connections = get_post_meta( $con_id, $connected_key, true ); |
|
| 335 | + if ( ! empty( $their_connections ) ) { |
|
| 336 | + $new_connections = $their_connections; |
|
| 337 | + // Run through the array and remove the post to be deleteds ID. |
|
| 338 | + foreach ( $their_connections as $ckey => $cvalue ) { |
|
| 339 | + if ( (int) $item_id === (int) $cvalue ) { |
|
| 340 | + unset( $new_connections[ $ckey ] ); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + // Now we save the field. |
|
| 344 | + update_post_meta( $con_id, $connected_key, $new_connections, $their_connections ); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | 350 | } |
@@ -9,83 +9,83 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Post_Type { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * Holds class instance |
|
| 14 | - * |
|
| 15 | - * @since 1.0.0 |
|
| 16 | - * |
|
| 17 | - * @var object \lsx_health_plan\classes\Post_Type() |
|
| 18 | - */ |
|
| 19 | - protected static $instance = null; |
|
| 12 | + /** |
|
| 13 | + * Holds class instance |
|
| 14 | + * |
|
| 15 | + * @since 1.0.0 |
|
| 16 | + * |
|
| 17 | + * @var object \lsx_health_plan\classes\Post_Type() |
|
| 18 | + */ |
|
| 19 | + protected static $instance = null; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The post types available |
|
| 23 | - * |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - public $post_types = array(); |
|
| 21 | + /** |
|
| 22 | + * The post types available |
|
| 23 | + * |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + public $post_types = array(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The related post type connections |
|
| 30 | - * |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - public $connections = array(); |
|
| 28 | + /** |
|
| 29 | + * The related post type connections |
|
| 30 | + * |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + public $connections = array(); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Contructor |
|
| 37 | - */ |
|
| 38 | - public function __construct() { |
|
| 39 | - $this->enable_post_types(); |
|
| 40 | - add_filter( 'lsx_health_plan_post_types', array( $this, 'enable_post_types' ) ); |
|
| 41 | - foreach ( $this->post_types as $index => $post_type ) { |
|
| 42 | - $is_disabled = \lsx_health_plan\functions\get_option( $post_type . '_disabled', false ); |
|
| 43 | - // Check if exercises is enabled, if so disable the videos. |
|
| 44 | - if ( 'video' === $post_type && false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
| 45 | - $is_disabled = true; |
|
| 46 | - } |
|
| 35 | + /** |
|
| 36 | + * Contructor |
|
| 37 | + */ |
|
| 38 | + public function __construct() { |
|
| 39 | + $this->enable_post_types(); |
|
| 40 | + add_filter( 'lsx_health_plan_post_types', array( $this, 'enable_post_types' ) ); |
|
| 41 | + foreach ( $this->post_types as $index => $post_type ) { |
|
| 42 | + $is_disabled = \lsx_health_plan\functions\get_option( $post_type . '_disabled', false ); |
|
| 43 | + // Check if exercises is enabled, if so disable the videos. |
|
| 44 | + if ( 'video' === $post_type && false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
| 45 | + $is_disabled = true; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - if ( true === $is_disabled || 1 === $is_disabled || 'on' === $is_disabled ) { |
|
| 49 | - unset( $this->post_types[ $index ] ); |
|
| 50 | - } else { |
|
| 51 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/post-types/class-' . $post_type . '.php'; |
|
| 52 | - $classname = ucwords( $post_type ); |
|
| 53 | - $this->$post_type = call_user_func_array( '\\lsx_health_plan\classes\\' . $classname . '::get_instance', array() ); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - } |
|
| 48 | + if ( true === $is_disabled || 1 === $is_disabled || 'on' === $is_disabled ) { |
|
| 49 | + unset( $this->post_types[ $index ] ); |
|
| 50 | + } else { |
|
| 51 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/post-types/class-' . $post_type . '.php'; |
|
| 52 | + $classname = ucwords( $post_type ); |
|
| 53 | + $this->$post_type = call_user_func_array( '\\lsx_health_plan\classes\\' . $classname . '::get_instance', array() ); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Return an instance of this class. |
|
| 60 | - * |
|
| 61 | - * @since 1.0.0 |
|
| 62 | - * |
|
| 63 | - * @return object \lsx_health_plan\classes\Post_Type() A single instance of this class. |
|
| 64 | - */ |
|
| 65 | - public static function get_instance() { |
|
| 66 | - // If the single instance hasn't been set, set it now. |
|
| 67 | - if ( null === self::$instance ) { |
|
| 68 | - self::$instance = new self(); |
|
| 69 | - } |
|
| 70 | - return self::$instance; |
|
| 71 | - } |
|
| 58 | + /** |
|
| 59 | + * Return an instance of this class. |
|
| 60 | + * |
|
| 61 | + * @since 1.0.0 |
|
| 62 | + * |
|
| 63 | + * @return object \lsx_health_plan\classes\Post_Type() A single instance of this class. |
|
| 64 | + */ |
|
| 65 | + public static function get_instance() { |
|
| 66 | + // If the single instance hasn't been set, set it now. |
|
| 67 | + if ( null === self::$instance ) { |
|
| 68 | + self::$instance = new self(); |
|
| 69 | + } |
|
| 70 | + return self::$instance; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Enable our post types |
|
| 75 | - * |
|
| 76 | - * @return void |
|
| 77 | - */ |
|
| 78 | - public function enable_post_types( $post_types = array() ) { |
|
| 79 | - $post_types = array( |
|
| 80 | - 'plan', |
|
| 81 | - 'workout', |
|
| 82 | - 'meal', |
|
| 83 | - 'recipe', |
|
| 84 | - 'tip', |
|
| 85 | - 'video', |
|
| 86 | - 'exercise', |
|
| 87 | - ); |
|
| 88 | - $this->post_types = $post_types; |
|
| 89 | - return $post_types; |
|
| 90 | - } |
|
| 73 | + /** |
|
| 74 | + * Enable our post types |
|
| 75 | + * |
|
| 76 | + * @return void |
|
| 77 | + */ |
|
| 78 | + public function enable_post_types( $post_types = array() ) { |
|
| 79 | + $post_types = array( |
|
| 80 | + 'plan', |
|
| 81 | + 'workout', |
|
| 82 | + 'meal', |
|
| 83 | + 'recipe', |
|
| 84 | + 'tip', |
|
| 85 | + 'video', |
|
| 86 | + 'exercise', |
|
| 87 | + ); |
|
| 88 | + $this->post_types = $post_types; |
|
| 89 | + return $post_types; |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -8,85 +8,85 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Setup { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Holds class instance |
|
| 13 | - * |
|
| 14 | - * @since 1.0.0 |
|
| 15 | - * |
|
| 16 | - * @var object \lsx_health_plan\classes\Setup() |
|
| 17 | - */ |
|
| 18 | - protected static $instance = null; |
|
| 11 | + /** |
|
| 12 | + * Holds class instance |
|
| 13 | + * |
|
| 14 | + * @since 1.0.0 |
|
| 15 | + * |
|
| 16 | + * @var object \lsx_health_plan\classes\Setup() |
|
| 17 | + */ |
|
| 18 | + protected static $instance = null; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var object \lsx_health_plan\classes\Post_Type(); |
|
| 22 | - */ |
|
| 23 | - public $post_types; |
|
| 20 | + /** |
|
| 21 | + * @var object \lsx_health_plan\classes\Post_Type(); |
|
| 22 | + */ |
|
| 23 | + public $post_types; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Contructor |
|
| 27 | - */ |
|
| 28 | - public function __construct() { |
|
| 29 | - add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
| 30 | - add_action( 'wp_head', array( $this, 'load_shortcodes' ) ); |
|
| 31 | - $this->load_classes(); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * Contructor |
|
| 27 | + */ |
|
| 28 | + public function __construct() { |
|
| 29 | + add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
|
| 30 | + add_action( 'wp_head', array( $this, 'load_shortcodes' ) ); |
|
| 31 | + $this->load_classes(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Return an instance of this class. |
|
| 36 | - * |
|
| 37 | - * @since 1.0.0 |
|
| 38 | - * |
|
| 39 | - * @return object \lsx_health_plan\classes\Setup() A single instance of this class. |
|
| 40 | - */ |
|
| 41 | - public static function get_instance() { |
|
| 34 | + /** |
|
| 35 | + * Return an instance of this class. |
|
| 36 | + * |
|
| 37 | + * @since 1.0.0 |
|
| 38 | + * |
|
| 39 | + * @return object \lsx_health_plan\classes\Setup() A single instance of this class. |
|
| 40 | + */ |
|
| 41 | + public static function get_instance() { |
|
| 42 | 42 | |
| 43 | - // If the single instance hasn't been set, set it now. |
|
| 44 | - if ( null === self::$instance ) { |
|
| 45 | - self::$instance = new self(); |
|
| 46 | - } |
|
| 43 | + // If the single instance hasn't been set, set it now. |
|
| 44 | + if ( null === self::$instance ) { |
|
| 45 | + self::$instance = new self(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - return self::$instance; |
|
| 48 | + return self::$instance; |
|
| 49 | 49 | |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Adds text domain. |
|
| 54 | - */ |
|
| 55 | - public function load_plugin_textdomain() { |
|
| 56 | - load_plugin_textdomain( 'lsx-health-plan', false, basename( LSX_HEALTH_PLAN_PATH ) . '/languages' ); |
|
| 57 | - } |
|
| 52 | + /** |
|
| 53 | + * Adds text domain. |
|
| 54 | + */ |
|
| 55 | + public function load_plugin_textdomain() { |
|
| 56 | + load_plugin_textdomain( 'lsx-health-plan', false, basename( LSX_HEALTH_PLAN_PATH ) . '/languages' ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Registers our shortcodes. |
|
| 61 | - * |
|
| 62 | - * @return void |
|
| 63 | - */ |
|
| 64 | - public function load_classes() { |
|
| 65 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/class-post-type.php'; |
|
| 66 | - $this->post_types = Post_Type::get_instance(); |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * Registers our shortcodes. |
|
| 61 | + * |
|
| 62 | + * @return void |
|
| 63 | + */ |
|
| 64 | + public function load_classes() { |
|
| 65 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/class-post-type.php'; |
|
| 66 | + $this->post_types = Post_Type::get_instance(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Registers our shortcodes. |
|
| 71 | - * |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - public function load_shortcodes() { |
|
| 75 | - add_shortcode( 'lsx_health_plan_restricted_content', '\lsx_health_plan\shortcodes\restricted_content' ); |
|
| 76 | - add_shortcode( 'lsx_health_plan_my_profile_tabs', '\lsx_health_plan\shortcodes\my_profile_tabs' ); |
|
| 77 | - add_shortcode( 'lsx_health_plan_my_profile_block', '\lsx_health_plan\shortcodes\my_profile_box' ); |
|
| 78 | - add_shortcode( 'lsx_health_plan_day_plan_block', '\lsx_health_plan\shortcodes\day_plan_box' ); |
|
| 79 | - add_shortcode( 'lsx_health_plan_account_notices', '\lsx_health_plan\shortcodes\account_notices' ); |
|
| 69 | + /** |
|
| 70 | + * Registers our shortcodes. |
|
| 71 | + * |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + public function load_shortcodes() { |
|
| 75 | + add_shortcode( 'lsx_health_plan_restricted_content', '\lsx_health_plan\shortcodes\restricted_content' ); |
|
| 76 | + add_shortcode( 'lsx_health_plan_my_profile_tabs', '\lsx_health_plan\shortcodes\my_profile_tabs' ); |
|
| 77 | + add_shortcode( 'lsx_health_plan_my_profile_block', '\lsx_health_plan\shortcodes\my_profile_box' ); |
|
| 78 | + add_shortcode( 'lsx_health_plan_day_plan_block', '\lsx_health_plan\shortcodes\day_plan_box' ); |
|
| 79 | + add_shortcode( 'lsx_health_plan_account_notices', '\lsx_health_plan\shortcodes\account_notices' ); |
|
| 80 | 80 | |
| 81 | - if ( post_type_exists( 'video' ) ) { |
|
| 82 | - add_shortcode( 'lsx_health_plan_featured_video_block', '\lsx_health_plan\shortcodes\feature_video_box' ); |
|
| 83 | - } |
|
| 84 | - if ( post_type_exists( 'recipe' ) ) { |
|
| 85 | - add_shortcode( 'lsx_health_plan_featured_recipes_block', '\lsx_health_plan\shortcodes\feature_recipes_box' ); |
|
| 86 | - } |
|
| 87 | - if ( post_type_exists( 'tip' ) ) { |
|
| 88 | - add_shortcode( 'lsx_health_plan_featured_tips_block', '\lsx_health_plan\shortcodes\feature_tips_box' ); |
|
| 89 | - } |
|
| 90 | - add_shortcode( 'lsx_health_plan_items', '\lsx_health_plan\shortcodes\exercise_box' ); |
|
| 91 | - } |
|
| 81 | + if ( post_type_exists( 'video' ) ) { |
|
| 82 | + add_shortcode( 'lsx_health_plan_featured_video_block', '\lsx_health_plan\shortcodes\feature_video_box' ); |
|
| 83 | + } |
|
| 84 | + if ( post_type_exists( 'recipe' ) ) { |
|
| 85 | + add_shortcode( 'lsx_health_plan_featured_recipes_block', '\lsx_health_plan\shortcodes\feature_recipes_box' ); |
|
| 86 | + } |
|
| 87 | + if ( post_type_exists( 'tip' ) ) { |
|
| 88 | + add_shortcode( 'lsx_health_plan_featured_tips_block', '\lsx_health_plan\shortcodes\feature_tips_box' ); |
|
| 89 | + } |
|
| 90 | + add_shortcode( 'lsx_health_plan_items', '\lsx_health_plan\shortcodes\exercise_box' ); |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // If this file is called directly, abort. |
| 15 | 15 | if ( ! defined( 'WPINC' ) ) { |
| 16 | - die; |
|
| 16 | + die; |
|
| 17 | 17 | } |
| 18 | 18 | define( 'LSX_HEALTH_PLAN_PATH', plugin_dir_path( __FILE__ ) ); |
| 19 | 19 | define( 'LSX_HEALTH_PLAN_CORE', __FILE__ ); |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | * @return void |
| 31 | 31 | */ |
| 32 | 32 | function lsx_remove_extra_meta_box() { |
| 33 | - global $wp_meta_boxes; |
|
| 34 | - $all_post_types = [ 'plan', 'video', 'workout', 'tip', 'recipe', 'meal' ]; |
|
| 35 | - //remove_meta_box( 'wpseo_meta', $all_post_types, 'normal' ); |
|
| 36 | - remove_meta_box( 'commentsdiv', $all_post_types, 'normal' ); |
|
| 37 | - remove_meta_box( 'commentstatusdiv', $all_post_types, 'normal' ); |
|
| 38 | - remove_meta_box( 'lsx_blocks_title_meta', $all_post_types, 'side' ); |
|
| 33 | + global $wp_meta_boxes; |
|
| 34 | + $all_post_types = [ 'plan', 'video', 'workout', 'tip', 'recipe', 'meal' ]; |
|
| 35 | + //remove_meta_box( 'wpseo_meta', $all_post_types, 'normal' ); |
|
| 36 | + remove_meta_box( 'commentsdiv', $all_post_types, 'normal' ); |
|
| 37 | + remove_meta_box( 'commentstatusdiv', $all_post_types, 'normal' ); |
|
| 38 | + remove_meta_box( 'lsx_blocks_title_meta', $all_post_types, 'side' ); |
|
| 39 | 39 | } |
| 40 | 40 | add_action( 'add_meta_boxes', 'lsx_remove_extra_meta_box', 100 ); |
| 41 | 41 | |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | if ( ( isset( $_GET['activated'] ) && function_exists( 'wp_verify_nonce' ) && wp_verify_nonce( sanitize_key( $_GET['activated'] ) ) ) && is_admin() ) { |
| 46 | 46 | |
| 47 | - $new_page_title = 'Login'; |
|
| 48 | - // Content to add spacing and woocommerce login shortcode |
|
| 49 | - $new_page_content = '<!-- wp:lsx-blocks/lsx-container {"containerMaxWidth":600} --> |
|
| 47 | + $new_page_title = 'Login'; |
|
| 48 | + // Content to add spacing and woocommerce login shortcode |
|
| 49 | + $new_page_content = '<!-- wp:lsx-blocks/lsx-container {"containerMaxWidth":600} --> |
|
| 50 | 50 | <div style="background-color:transparent;padding-left:3%;padding-right:3%;padding-bottom:3%;padding-top:3%;margin-top:3%;margin-bottom:3%" class="wp-block-lsx-blocks-lsx-container aligncenter lsx-block-container"><div class="lsx-container-inside"><div class="lsx-container-content" style="max-width:600px"><!-- wp:paragraph --> |
| 51 | 51 | <p></p> |
| 52 | 52 | <!-- /wp:paragraph --> |
@@ -55,22 +55,22 @@ discard block |
||
| 55 | 55 | [woocommerce_my_account] |
| 56 | 56 | <!-- /wp:shortcode --></div></div></div> |
| 57 | 57 | <!-- /wp:lsx-blocks/lsx-container -->'; |
| 58 | - $new_page_template = ''; |
|
| 58 | + $new_page_template = ''; |
|
| 59 | 59 | |
| 60 | - $page_check = get_page_by_title( $new_page_title ); |
|
| 61 | - $new_page = array( |
|
| 62 | - 'post_type' => 'page', |
|
| 63 | - 'post_title' => $new_page_title, |
|
| 64 | - 'post_content' => $new_page_content, |
|
| 65 | - 'post_status' => 'publish', |
|
| 66 | - 'post_author' => 1, |
|
| 67 | - ); |
|
| 68 | - if ( ! isset( $page_check->ID ) ) { |
|
| 69 | - $new_page_id = wp_insert_post( $new_page ); |
|
| 70 | - if ( ! empty( $new_page_template ) ) { |
|
| 71 | - update_post_meta( $new_page_id, '_wp_page_template', $new_page_template ); |
|
| 72 | - } |
|
| 73 | - } |
|
| 60 | + $page_check = get_page_by_title( $new_page_title ); |
|
| 61 | + $new_page = array( |
|
| 62 | + 'post_type' => 'page', |
|
| 63 | + 'post_title' => $new_page_title, |
|
| 64 | + 'post_content' => $new_page_content, |
|
| 65 | + 'post_status' => 'publish', |
|
| 66 | + 'post_author' => 1, |
|
| 67 | + ); |
|
| 68 | + if ( ! isset( $page_check->ID ) ) { |
|
| 69 | + $new_page_id = wp_insert_post( $new_page ); |
|
| 70 | + if ( ! empty( $new_page_template ) ) { |
|
| 71 | + update_post_meta( $new_page_id, '_wp_page_template', $new_page_template ); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -81,24 +81,24 @@ discard block |
||
| 81 | 81 | * @return void |
| 82 | 82 | */ |
| 83 | 83 | function lsx_add_login_logout_register_menu( $items, $args ) { |
| 84 | - if ( 'primary' === $args->theme_location ) { |
|
| 85 | - ob_start(); |
|
| 86 | - wp_loginout( get_permalink() ); |
|
| 87 | - $loginoutlink = ob_get_contents(); |
|
| 88 | - ob_end_clean(); |
|
| 89 | - if ( ! is_user_logged_in() ) { |
|
| 90 | - $login_slug = \lsx_health_plan\functions\get_option( 'login_slug', false ); |
|
| 91 | - if ( false === $login_slug ) { |
|
| 92 | - $login_slug = 'login'; |
|
| 93 | - } |
|
| 94 | - $items .= '<li class="my-login menu-item"><a rel="nofollow" href="/' . $login_slug . '/">' . __( 'Login', 'lsx-health-plan' ) . '</a></li>'; |
|
| 95 | - } else { |
|
| 96 | - $items .= '<li class="my-login menu-item">' . $loginoutlink . '</li>'; |
|
| 97 | - } |
|
| 98 | - return $items; |
|
| 99 | - } else { |
|
| 100 | - return $items; |
|
| 101 | - } |
|
| 84 | + if ( 'primary' === $args->theme_location ) { |
|
| 85 | + ob_start(); |
|
| 86 | + wp_loginout( get_permalink() ); |
|
| 87 | + $loginoutlink = ob_get_contents(); |
|
| 88 | + ob_end_clean(); |
|
| 89 | + if ( ! is_user_logged_in() ) { |
|
| 90 | + $login_slug = \lsx_health_plan\functions\get_option( 'login_slug', false ); |
|
| 91 | + if ( false === $login_slug ) { |
|
| 92 | + $login_slug = 'login'; |
|
| 93 | + } |
|
| 94 | + $items .= '<li class="my-login menu-item"><a rel="nofollow" href="/' . $login_slug . '/">' . __( 'Login', 'lsx-health-plan' ) . '</a></li>'; |
|
| 95 | + } else { |
|
| 96 | + $items .= '<li class="my-login menu-item">' . $loginoutlink . '</li>'; |
|
| 97 | + } |
|
| 98 | + return $items; |
|
| 99 | + } else { |
|
| 100 | + return $items; |
|
| 101 | + } |
|
| 102 | 102 | } |
| 103 | 103 | add_filter( 'wp_nav_menu_items', 'lsx_add_login_logout_register_menu', 199, 2 ); |
| 104 | 104 | |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | 110 | function lsx_login_redirect() { |
| 111 | - $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
|
| 112 | - if ( false === $plan_slug ) { |
|
| 113 | - $plan_slug = 'my-plan'; |
|
| 114 | - } |
|
| 115 | - return home_url( $plan_slug ); |
|
| 111 | + $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
|
| 112 | + if ( false === $plan_slug ) { |
|
| 113 | + $plan_slug = 'my-plan'; |
|
| 114 | + } |
|
| 115 | + return home_url( $plan_slug ); |
|
| 116 | 116 | } |
| 117 | 117 | add_filter( 'woocommerce_login_redirect', 'lsx_login_redirect' ); |
| 118 | 118 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @return object lsx_health_plan\classes\Core::get_instance(); |
| 123 | 123 | */ |
| 124 | 124 | function lsx_health_plan() { |
| 125 | - return \lsx_health_plan\classes\Core::get_instance(); |
|
| 125 | + return \lsx_health_plan\classes\Core::get_instance(); |
|
| 126 | 126 | } |
| 127 | 127 | lsx_health_plan(); |
| 128 | 128 | |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | * @return void |
| 133 | 133 | */ |
| 134 | 134 | function lsx_get_svg_icon( $icon ) { |
| 135 | - $path = '/assets/images/'; |
|
| 135 | + $path = '/assets/images/'; |
|
| 136 | 136 | |
| 137 | - if ( file_exists( LSX_HEALTH_PLAN_PATH . $path . $icon ) ) { |
|
| 138 | - // Load and return the contents of the file |
|
| 139 | - return include LSX_HEALTH_PLAN_PATH . $path . $icon; |
|
| 140 | - } |
|
| 137 | + if ( file_exists( LSX_HEALTH_PLAN_PATH . $path . $icon ) ) { |
|
| 138 | + // Load and return the contents of the file |
|
| 139 | + return include LSX_HEALTH_PLAN_PATH . $path . $icon; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - // Return a blank string if we can't find the file. |
|
| 143 | - return ''; |
|
| 142 | + // Return a blank string if we can't find the file. |
|
| 143 | + return ''; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -149,26 +149,26 @@ discard block |
||
| 149 | 149 | * @return void |
| 150 | 150 | */ |
| 151 | 151 | function lsx_workout_snacks( $snack ) { |
| 152 | - $workout_snack = get_post_meta( get_the_ID(), $snack . '_workout_snack', true ); |
|
| 153 | - if ( ! empty( $workout_snack ) ) { |
|
| 154 | - ?> |
|
| 152 | + $workout_snack = get_post_meta( get_the_ID(), $snack . '_workout_snack', true ); |
|
| 153 | + if ( ! empty( $workout_snack ) ) { |
|
| 154 | + ?> |
|
| 155 | 155 | <div class="<?php echo esc_html( $snack ); ?>-workout workout-snacks"> |
| 156 | 156 | <div class="content-box"> |
| 157 | 157 | <?php |
| 158 | - $snack_title = ucfirst( $snack ); |
|
| 159 | - if ( 'pre' === $snack ) { |
|
| 160 | - /* Translators: %s: snack */ |
|
| 161 | - $title_text = esc_attr_x( 'Pre-Workout Snack', 'pre workout', 'lsx-health-plan' ); |
|
| 162 | - } else { |
|
| 163 | - /* Translators: %s: snack */ |
|
| 164 | - $title_text = esc_attr_x( 'Post-Workout Snack', 'post workout', 'lsx-health-plan' ); |
|
| 165 | - } |
|
| 166 | - $title = sprintf( $title_text, $snack_title ); |
|
| 167 | - ?> |
|
| 158 | + $snack_title = ucfirst( $snack ); |
|
| 159 | + if ( 'pre' === $snack ) { |
|
| 160 | + /* Translators: %s: snack */ |
|
| 161 | + $title_text = esc_attr_x( 'Pre-Workout Snack', 'pre workout', 'lsx-health-plan' ); |
|
| 162 | + } else { |
|
| 163 | + /* Translators: %s: snack */ |
|
| 164 | + $title_text = esc_attr_x( 'Post-Workout Snack', 'post workout', 'lsx-health-plan' ); |
|
| 165 | + } |
|
| 166 | + $title = sprintf( $title_text, $snack_title ); |
|
| 167 | + ?> |
|
| 168 | 168 | <h3 class="title-lined"><?php echo esc_html( $title ); ?></h3> |
| 169 | 169 | <?php echo wp_kses_post( apply_filters( 'the_content', $workout_snack ) ); ?> |
| 170 | 170 | </div> |
| 171 | 171 | </div> |
| 172 | 172 | <?php |
| 173 | - } |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | <?php lsx_content_wrap_before(); ?> |
| 11 | 11 | |
| 12 | 12 | <?php |
| 13 | - $page_id = get_the_ID(); |
|
| 14 | - $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
| 13 | + $page_id = get_the_ID(); |
|
| 14 | + $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
| 15 | 15 | ?> |
| 16 | 16 | |
| 17 | 17 | <div id="primary" class="content-area <?php echo esc_attr( lsx_main_class() ); ?>"> |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | <!-- Begining restricted content --> |
| 22 | 22 | <?php |
| 23 | - if ( current_user_can( 'wc_memberships_view_restricted_post_content', $post_id ) ) { |
|
| 24 | - ?> |
|
| 23 | + if ( current_user_can( 'wc_memberships_view_restricted_post_content', $post_id ) ) { |
|
| 24 | + ?> |
|
| 25 | 25 | <main id="main" role="main"> |
| 26 | 26 | |
| 27 | 27 | <?php lsx_content_top(); ?> |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | <div class="row"> |
| 31 | 31 | <?php if ( have_posts() ) : ?> |
| 32 | 32 | <?php |
| 33 | - while ( have_posts() ) : |
|
| 34 | - the_post(); |
|
| 35 | - ?> |
|
| 33 | + while ( have_posts() ) : |
|
| 34 | + the_post(); |
|
| 35 | + ?> |
|
| 36 | 36 | |
| 37 | 37 | <?php include LSX_HEALTH_PLAN_PATH . '/templates/content-archive-exercise.php'; ?> |
| 38 | 38 | |
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | </main><!-- #main --> |
| 52 | 52 | |
| 53 | 53 | <?php |
| 54 | - } else { |
|
| 55 | - wp_redirect( $redirect ); |
|
| 56 | - exit; |
|
| 57 | - } |
|
| 58 | - ?> |
|
| 54 | + } else { |
|
| 55 | + wp_redirect( $redirect ); |
|
| 56 | + exit; |
|
| 57 | + } |
|
| 58 | + ?> |
|
| 59 | 59 | |
| 60 | 60 | <?php lsx_content_after(); ?> |
| 61 | 61 | |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | <?php lsx_content_wrap_before(); ?> |
| 11 | 11 | |
| 12 | 12 | <?php |
| 13 | - $page_id = get_the_ID(); |
|
| 14 | - $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
| 13 | + $page_id = get_the_ID(); |
|
| 14 | + $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
| 15 | 15 | ?> |
| 16 | 16 | |
| 17 | 17 | <div id="primary" class="content-area <?php echo esc_attr( lsx_main_class() ); ?>"> |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | <!-- Begining restricted content --> |
| 22 | 22 | <?php |
| 23 | - if ( current_user_can( 'wc_memberships_view_restricted_post_content', $post_id ) ) { |
|
| 24 | - ?> |
|
| 23 | + if ( current_user_can( 'wc_memberships_view_restricted_post_content', $post_id ) ) { |
|
| 24 | + ?> |
|
| 25 | 25 | <main id="main" role="main"> |
| 26 | 26 | |
| 27 | 27 | <?php lsx_content_top(); ?> |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | <div class="row"> |
| 31 | 31 | <?php if ( have_posts() ) : ?> |
| 32 | 32 | <?php |
| 33 | - while ( have_posts() ) : |
|
| 34 | - the_post(); |
|
| 35 | - ?> |
|
| 33 | + while ( have_posts() ) : |
|
| 34 | + the_post(); |
|
| 35 | + ?> |
|
| 36 | 36 | |
| 37 | 37 | <?php include LSX_HEALTH_PLAN_PATH . '/templates/content-archive-exercise.php'; ?> |
| 38 | 38 | |
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | </main><!-- #main --> |
| 52 | 52 | |
| 53 | 53 | <?php |
| 54 | - } else { |
|
| 55 | - wp_redirect( $redirect ); |
|
| 56 | - exit; |
|
| 57 | - } |
|
| 58 | - ?> |
|
| 54 | + } else { |
|
| 55 | + wp_redirect( $redirect ); |
|
| 56 | + exit; |
|
| 57 | + } |
|
| 58 | + ?> |
|
| 59 | 59 | |
| 60 | 60 | <?php lsx_content_after(); ?> |
| 61 | 61 | |
@@ -8,87 +8,87 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | class Frontend { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Holds class instance |
|
| 13 | - * |
|
| 14 | - * @since 1.0.0 |
|
| 15 | - * |
|
| 16 | - * @var object \lsx_health_plan\classes\Frontend() |
|
| 17 | - */ |
|
| 18 | - protected static $instance = null; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var object \lsx_health_plan\classes\Endpoints(); |
|
| 22 | - */ |
|
| 23 | - public $endpoints; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var object \lsx_health_plan\classes\Modals(); |
|
| 27 | - */ |
|
| 28 | - public $modals; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Contructor |
|
| 32 | - */ |
|
| 33 | - public function __construct() { |
|
| 34 | - add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
|
| 35 | - |
|
| 36 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-endpoints.php'; |
|
| 37 | - $this->endpoints = Endpoints::get_instance(); |
|
| 38 | - |
|
| 39 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-modals.php'; |
|
| 40 | - $this->modals = Modals::get_instance(); |
|
| 41 | - |
|
| 42 | - require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-gallery.php'; |
|
| 43 | - $this->gallery = frontend\Gallery::get_instance(); |
|
| 44 | - |
|
| 45 | - if ( is_admin() ) { |
|
| 46 | - add_filter( 'lsx_customizer_colour_selectors_body', array( $this, 'customizer_body_colours_handler' ), 15, 2 ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // Handle the template redirects. |
|
| 50 | - add_filter( 'template_include', array( $this, 'archive_template_include' ), 99 ); |
|
| 51 | - add_filter( 'template_include', array( $this, 'single_template_include' ), 99 ); |
|
| 52 | - add_filter( 'template_include', array( $this, 'taxonomy_template_include' ), 99 ); |
|
| 53 | - add_action( 'template_redirect', array( $this, 'redirect' ) ); |
|
| 54 | - |
|
| 55 | - add_action( 'init', array( $this, 'handle_day_action' ), 100 ); |
|
| 56 | - add_filter( 'wp_kses_allowed_html', array( $this, 'wpkses_post_tags' ), 100, 2 ); |
|
| 57 | - |
|
| 58 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 99, 1 ); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Return an instance of this class. |
|
| 63 | - * |
|
| 64 | - * @since 1.0.0 |
|
| 65 | - * |
|
| 66 | - * @return object \lsx_health_plan\classes\Frontend() A single instance of this class. |
|
| 67 | - */ |
|
| 68 | - public static function get_instance() { |
|
| 69 | - // If the single instance hasn't been set, set it now. |
|
| 70 | - if ( null === self::$instance ) { |
|
| 71 | - self::$instance = new self(); |
|
| 72 | - } |
|
| 73 | - return self::$instance; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Registers the plugin frontend assets |
|
| 78 | - * |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public function assets() { |
|
| 82 | - wp_enqueue_style( 'lsx-health-plan', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan.css', array(), LSX_HEALTH_PLAN_VER ); |
|
| 83 | - wp_style_add_data( 'lsx-health-plan', 'rtl', 'replace' ); |
|
| 84 | - wp_enqueue_script( 'lsx-health-plan-scripts', LSX_HEALTH_PLAN_URL . 'assets/js/src/lsx-health-plan-admin.js', array( 'jquery' ) ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Handle body colours that might be change by LSX Customizer. |
|
| 89 | - */ |
|
| 90 | - public function customizer_body_colours_handler( $css, $colors ) { |
|
| 91 | - $css .= ' |
|
| 11 | + /** |
|
| 12 | + * Holds class instance |
|
| 13 | + * |
|
| 14 | + * @since 1.0.0 |
|
| 15 | + * |
|
| 16 | + * @var object \lsx_health_plan\classes\Frontend() |
|
| 17 | + */ |
|
| 18 | + protected static $instance = null; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var object \lsx_health_plan\classes\Endpoints(); |
|
| 22 | + */ |
|
| 23 | + public $endpoints; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var object \lsx_health_plan\classes\Modals(); |
|
| 27 | + */ |
|
| 28 | + public $modals; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Contructor |
|
| 32 | + */ |
|
| 33 | + public function __construct() { |
|
| 34 | + add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
|
| 35 | + |
|
| 36 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-endpoints.php'; |
|
| 37 | + $this->endpoints = Endpoints::get_instance(); |
|
| 38 | + |
|
| 39 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-modals.php'; |
|
| 40 | + $this->modals = Modals::get_instance(); |
|
| 41 | + |
|
| 42 | + require_once LSX_HEALTH_PLAN_PATH . 'classes/frontend/class-gallery.php'; |
|
| 43 | + $this->gallery = frontend\Gallery::get_instance(); |
|
| 44 | + |
|
| 45 | + if ( is_admin() ) { |
|
| 46 | + add_filter( 'lsx_customizer_colour_selectors_body', array( $this, 'customizer_body_colours_handler' ), 15, 2 ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // Handle the template redirects. |
|
| 50 | + add_filter( 'template_include', array( $this, 'archive_template_include' ), 99 ); |
|
| 51 | + add_filter( 'template_include', array( $this, 'single_template_include' ), 99 ); |
|
| 52 | + add_filter( 'template_include', array( $this, 'taxonomy_template_include' ), 99 ); |
|
| 53 | + add_action( 'template_redirect', array( $this, 'redirect' ) ); |
|
| 54 | + |
|
| 55 | + add_action( 'init', array( $this, 'handle_day_action' ), 100 ); |
|
| 56 | + add_filter( 'wp_kses_allowed_html', array( $this, 'wpkses_post_tags' ), 100, 2 ); |
|
| 57 | + |
|
| 58 | + add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 99, 1 ); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Return an instance of this class. |
|
| 63 | + * |
|
| 64 | + * @since 1.0.0 |
|
| 65 | + * |
|
| 66 | + * @return object \lsx_health_plan\classes\Frontend() A single instance of this class. |
|
| 67 | + */ |
|
| 68 | + public static function get_instance() { |
|
| 69 | + // If the single instance hasn't been set, set it now. |
|
| 70 | + if ( null === self::$instance ) { |
|
| 71 | + self::$instance = new self(); |
|
| 72 | + } |
|
| 73 | + return self::$instance; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Registers the plugin frontend assets |
|
| 78 | + * |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public function assets() { |
|
| 82 | + wp_enqueue_style( 'lsx-health-plan', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan.css', array(), LSX_HEALTH_PLAN_VER ); |
|
| 83 | + wp_style_add_data( 'lsx-health-plan', 'rtl', 'replace' ); |
|
| 84 | + wp_enqueue_script( 'lsx-health-plan-scripts', LSX_HEALTH_PLAN_URL . 'assets/js/src/lsx-health-plan-admin.js', array( 'jquery' ) ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Handle body colours that might be change by LSX Customizer. |
|
| 89 | + */ |
|
| 90 | + public function customizer_body_colours_handler( $css, $colors ) { |
|
| 91 | + $css .= ' |
|
| 92 | 92 | @import "' . LSX_HEALTH_PLAN_PATH . '/assets/css/scss/partials/customizer-health-plan-body-colours"; |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -104,117 +104,117 @@ discard block |
||
| 104 | 104 | ); |
| 105 | 105 | '; |
| 106 | 106 | |
| 107 | - return $css; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Archive template. |
|
| 112 | - */ |
|
| 113 | - public function archive_template_include( $template ) { |
|
| 114 | - $applicable_post_types = apply_filters( 'lsx_health_plan_archive_template', array() ); |
|
| 115 | - if ( ! empty( $applicable_post_types ) && is_main_query() && is_post_type_archive( $applicable_post_types ) ) { |
|
| 116 | - $post_type = get_post_type(); |
|
| 117 | - if ( empty( locate_template( array( 'archive-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php' ) ) { |
|
| 118 | - $template = LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php'; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - return $template; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Single template. |
|
| 126 | - */ |
|
| 127 | - public function single_template_include( $template ) { |
|
| 128 | - $applicable_post_types = apply_filters( 'lsx_health_plan_single_template', array() ); |
|
| 129 | - if ( ! empty( $applicable_post_types ) && is_main_query() && is_singular( $applicable_post_types ) ) { |
|
| 130 | - $post_type = get_post_type(); |
|
| 131 | - if ( empty( locate_template( array( 'single-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php' ) ) { |
|
| 132 | - $template = LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php'; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - return $template; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Redirect WordPress to the taxonomy located in the plugin |
|
| 140 | - * |
|
| 141 | - * @param $template string |
|
| 142 | - * @return string |
|
| 143 | - */ |
|
| 144 | - public function taxonomy_template_include( $template ) { |
|
| 145 | - $applicable_taxonomies = apply_filters( 'lsx_health_plan_taxonomies_template', array() ); |
|
| 146 | - if ( is_main_query() && is_tax( $applicable_taxonomies ) ) { |
|
| 147 | - $current_taxonomy = get_query_var( 'taxonomy' ); |
|
| 148 | - if ( '' === locate_template( array( 'taxonomy-' . $current_taxonomy . '.php' ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php' ) ) { |
|
| 149 | - $template = LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php'; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - return $template; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Redirect the user from the cart or checkout page if they have purchased the product already. |
|
| 157 | - * |
|
| 158 | - * @return void |
|
| 159 | - */ |
|
| 160 | - public function redirect() { |
|
| 161 | - if ( ! is_user_logged_in() || ! function_exists( 'wc_get_page_id' ) || is_home() ) { |
|
| 162 | - return; |
|
| 163 | - } |
|
| 164 | - if ( lsx_health_plan_user_has_purchase() && ( is_page( wc_get_page_id( 'cart' ) ) || is_page( wc_get_page_id( 'checkout' ) ) ) ) { |
|
| 165 | - wp_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) ); |
|
| 166 | - die; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $product_id = \lsx_health_plan\functions\get_option( 'membership_product', false ); |
|
| 170 | - if ( false !== $product_id && is_single( $product_id ) ) { |
|
| 171 | - wp_redirect( home_url() ); |
|
| 172 | - die; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Registers the rewrites. |
|
| 178 | - */ |
|
| 179 | - public function handle_day_action() { |
|
| 180 | - if ( isset( $_POST['lsx-health-plan-actions'] ) && wp_verify_nonce( $_POST['lsx-health-plan-actions'], 'complete' ) ) { |
|
| 181 | - update_user_meta( get_current_user_id(), 'day_' . sanitize_key( $_POST['lsx-health-plan-id'] ) . '_complete', true ); |
|
| 182 | - wp_safe_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) ); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if ( isset( $_POST['lsx-health-plan-actions'] ) && wp_verify_nonce( $_POST['lsx-health-plan-actions'], 'unlock' ) ) { |
|
| 186 | - delete_user_meta( get_current_user_id(), 'day_' . sanitize_key( $_POST['lsx-health-plan-id'] ) . '_complete' ); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Registers the rewrites. |
|
| 192 | - */ |
|
| 193 | - public function wpkses_post_tags( $tags, $context ) { |
|
| 194 | - if ( 'post' === $context ) { |
|
| 195 | - $tags['iframe'] = array( |
|
| 196 | - 'src' => true, |
|
| 197 | - 'height' => true, |
|
| 198 | - 'width' => true, |
|
| 199 | - 'frameborder' => true, |
|
| 200 | - 'allowfullscreen' => true, |
|
| 201 | - ); |
|
| 202 | - } |
|
| 203 | - return $tags; |
|
| 204 | - } |
|
| 205 | - /** |
|
| 206 | - * Remove the "Archives:" from the post type recipes. |
|
| 207 | - * |
|
| 208 | - * @param string $title the term title. |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - public function get_the_archive_title( $title ) { |
|
| 212 | - if ( is_tax() ) { |
|
| 213 | - $queried_object = get_queried_object(); |
|
| 214 | - if ( isset( $queried_object->name ) ) { |
|
| 215 | - $title = $queried_object->name; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - return $title; |
|
| 219 | - } |
|
| 107 | + return $css; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Archive template. |
|
| 112 | + */ |
|
| 113 | + public function archive_template_include( $template ) { |
|
| 114 | + $applicable_post_types = apply_filters( 'lsx_health_plan_archive_template', array() ); |
|
| 115 | + if ( ! empty( $applicable_post_types ) && is_main_query() && is_post_type_archive( $applicable_post_types ) ) { |
|
| 116 | + $post_type = get_post_type(); |
|
| 117 | + if ( empty( locate_template( array( 'archive-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php' ) ) { |
|
| 118 | + $template = LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php'; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + return $template; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Single template. |
|
| 126 | + */ |
|
| 127 | + public function single_template_include( $template ) { |
|
| 128 | + $applicable_post_types = apply_filters( 'lsx_health_plan_single_template', array() ); |
|
| 129 | + if ( ! empty( $applicable_post_types ) && is_main_query() && is_singular( $applicable_post_types ) ) { |
|
| 130 | + $post_type = get_post_type(); |
|
| 131 | + if ( empty( locate_template( array( 'single-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php' ) ) { |
|
| 132 | + $template = LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php'; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + return $template; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Redirect WordPress to the taxonomy located in the plugin |
|
| 140 | + * |
|
| 141 | + * @param $template string |
|
| 142 | + * @return string |
|
| 143 | + */ |
|
| 144 | + public function taxonomy_template_include( $template ) { |
|
| 145 | + $applicable_taxonomies = apply_filters( 'lsx_health_plan_taxonomies_template', array() ); |
|
| 146 | + if ( is_main_query() && is_tax( $applicable_taxonomies ) ) { |
|
| 147 | + $current_taxonomy = get_query_var( 'taxonomy' ); |
|
| 148 | + if ( '' === locate_template( array( 'taxonomy-' . $current_taxonomy . '.php' ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php' ) ) { |
|
| 149 | + $template = LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php'; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + return $template; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Redirect the user from the cart or checkout page if they have purchased the product already. |
|
| 157 | + * |
|
| 158 | + * @return void |
|
| 159 | + */ |
|
| 160 | + public function redirect() { |
|
| 161 | + if ( ! is_user_logged_in() || ! function_exists( 'wc_get_page_id' ) || is_home() ) { |
|
| 162 | + return; |
|
| 163 | + } |
|
| 164 | + if ( lsx_health_plan_user_has_purchase() && ( is_page( wc_get_page_id( 'cart' ) ) || is_page( wc_get_page_id( 'checkout' ) ) ) ) { |
|
| 165 | + wp_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) ); |
|
| 166 | + die; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $product_id = \lsx_health_plan\functions\get_option( 'membership_product', false ); |
|
| 170 | + if ( false !== $product_id && is_single( $product_id ) ) { |
|
| 171 | + wp_redirect( home_url() ); |
|
| 172 | + die; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Registers the rewrites. |
|
| 178 | + */ |
|
| 179 | + public function handle_day_action() { |
|
| 180 | + if ( isset( $_POST['lsx-health-plan-actions'] ) && wp_verify_nonce( $_POST['lsx-health-plan-actions'], 'complete' ) ) { |
|
| 181 | + update_user_meta( get_current_user_id(), 'day_' . sanitize_key( $_POST['lsx-health-plan-id'] ) . '_complete', true ); |
|
| 182 | + wp_safe_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) ); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if ( isset( $_POST['lsx-health-plan-actions'] ) && wp_verify_nonce( $_POST['lsx-health-plan-actions'], 'unlock' ) ) { |
|
| 186 | + delete_user_meta( get_current_user_id(), 'day_' . sanitize_key( $_POST['lsx-health-plan-id'] ) . '_complete' ); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Registers the rewrites. |
|
| 192 | + */ |
|
| 193 | + public function wpkses_post_tags( $tags, $context ) { |
|
| 194 | + if ( 'post' === $context ) { |
|
| 195 | + $tags['iframe'] = array( |
|
| 196 | + 'src' => true, |
|
| 197 | + 'height' => true, |
|
| 198 | + 'width' => true, |
|
| 199 | + 'frameborder' => true, |
|
| 200 | + 'allowfullscreen' => true, |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | + return $tags; |
|
| 204 | + } |
|
| 205 | + /** |
|
| 206 | + * Remove the "Archives:" from the post type recipes. |
|
| 207 | + * |
|
| 208 | + * @param string $title the term title. |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + public function get_the_archive_title( $title ) { |
|
| 212 | + if ( is_tax() ) { |
|
| 213 | + $queried_object = get_queried_object(); |
|
| 214 | + if ( isset( $queried_object->name ) ) { |
|
| 215 | + $title = $queried_object->name; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + return $title; |
|
| 219 | + } |
|
| 220 | 220 | } |