WC_GZD_Admin

The WooCommerce Germanized WC GZD Admin class.

Defined (1)

The class is defined in the following location(s).

/includes/admin/class-wc-gzd-admin.php  
  1. class WC_GZD_Admin { 
  2.  
  3. /** 
  4. * Single instance of WooCommerce Germanized Main Class 
  5. * @var object 
  6. */ 
  7. protected static $_instance = null; 
  8.  
  9. public static function instance() { 
  10. if ( is_null( self::$_instance ) ) { 
  11. self::$_instance = new self(); 
  12. return self::$_instance; 
  13.  
  14. /** 
  15. * Cloning is forbidden. 
  16. * @since 1.0 
  17. */ 
  18. public function __clone() { 
  19. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce-germanized' ), '1.0' ); 
  20.  
  21. /** 
  22. * Unserializing instances of this class is forbidden. 
  23. * @since 1.0 
  24. */ 
  25. public function __wakeup() { 
  26. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce-germanized' ), '1.0' ); 
  27.  
  28. public function __construct() { 
  29. add_action( 'add_meta_boxes', array( $this, 'add_legal_page_metabox' ) ); 
  30. add_action( 'add_meta_boxes', array( $this, 'add_product_mini_desc' ) ); 
  31. add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) ); 
  32. add_action( 'save_post', array( $this, 'save_legal_page_content' ), 10, 3 ); 
  33. add_action( 'admin_menu', array( $this, 'remove_status_page_hooks' ), 0 ); 
  34. add_action( 'admin_menu', array( $this, 'set_status_page' ), 1 ); 
  35. add_action( 'admin_init', array( $this, 'check_tour_hide' ) ); 
  36. add_action( 'admin_init', array( $this, 'check_language_install' ) ); 
  37. add_action( 'admin_init', array( $this, 'check_text_options_deletion' ) ); 
  38. add_action( 'admin_init', array( $this, 'check_complaints_shortcode_append' ) ); 
  39. add_filter( 'woocommerce_addons_section_data', array( $this, 'set_addon' ), 10, 2 ); 
  40.  
  41. public function set_addon( $products, $section_id ) { 
  42.  
  43. if ( $section_id !== 'featured' ) 
  44. return $products; 
  45.  
  46. array_unshift( $products, (object) array( 
  47. 'title' => 'Woo Germanized Pro',  
  48. 'excerpt' => 'Upgrade jetzt auf die Pro Version von WooCommerce Germanized und profitiere von weiteren ntzliche Funktionen speziell fr den deutschen Markt sowie professionellem Support.',  
  49. 'link' => 'https://vendidero.de/woocommerce-germanized#buy',  
  50. 'price' => '69, 95 *',  
  51. ) ); 
  52.  
  53. return $products; 
  54.  
  55. /** 
  56. * Manually remove hook (class WC_Admin_Menus is noch callable) 
  57. */ 
  58. public function remove_status_page_hooks() { 
  59. global $wp_filter; 
  60. if ( isset( $wp_filter[ 'admin_menu' ][60] ) ) { 
  61. foreach ( $wp_filter[ 'admin_menu' ][60] as $k => $f ) { 
  62. if ( isset( $f[ 'function' ][1] ) && $f[ 'function' ][1] == 'status_menu' ) 
  63. unset( $wp_filter[ 'admin_menu' ][60][$k] ); 
  64.  
  65. public function set_status_page() { 
  66. if ( ! is_ajax() ) { 
  67. include_once( 'class-wc-gzd-admin-status.php' ); 
  68. add_action( 'admin_menu', array( $this, 'status_menu' ), 60 ); 
  69.  
  70. public function status_menu() { 
  71. add_submenu_page( 'woocommerce', __( 'WooCommerce Status', 'woocommerce-germanized' ), __( 'System Status', 'woocommerce-germanized' ) , 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) ); 
  72. register_setting( 'woocommerce_status_settings_fields', 'woocommerce_status_options' ); 
  73.  
  74. public function status_page() { 
  75. WC_GZD_Admin_Status::output(); 
  76.  
  77. public function add_scripts() { 
  78.  
  79. $screen = get_current_screen(); 
  80. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  81. $assets_path = WC_germanized()->plugin_url() . '/assets/'; 
  82. $admin_script_path = $assets_path . 'js/admin/'; 
  83.  
  84. wp_register_style( 'woocommerce-gzd-admin', $assets_path . 'css/woocommerce-gzd-admin' . $suffix . '.css', false, WC_GERMANIZED_VERSION ); 
  85. wp_enqueue_style( 'woocommerce-gzd-admin' ); 
  86.  
  87. wp_register_style( 'tourbus', $assets_path . 'css/tourbus' . $suffix . '.css', false, WC_GERMANIZED_VERSION ); 
  88.  
  89. wp_register_script( 'wc-gzd-admin', $admin_script_path . 'settings' . $suffix . '.js', array( 'jquery', 'woocommerce_settings' ), WC_GERMANIZED_VERSION, true ); 
  90. wp_register_script( 'scrollto', $admin_script_path . 'scrollTo' . $suffix . '.js', array( 'jquery' ), WC_GERMANIZED_VERSION, true ); 
  91. wp_register_script( 'tourbus', $admin_script_path . 'tourbus' . $suffix . '.js', array( 'jquery', 'scrollto' ), WC_GERMANIZED_VERSION, true ); 
  92. wp_register_script( 'wc-gzd-admin-tour', $admin_script_path . 'tour' . $suffix . '.js', array( 'jquery', 'woocommerce_settings', 'tourbus' ), WC_GERMANIZED_VERSION, true ); 
  93. wp_register_script( 'wc-gzd-admin-product-variations', $admin_script_path . 'product-variations' . $suffix . '.js', array( 'wc-admin-variation-meta-boxes' ), WC_GERMANIZED_VERSION ); 
  94.  
  95. if ( isset( $_GET[ 'tab' ] ) && $_GET[ 'tab' ] == 'germanized' ) { 
  96.  
  97. wp_enqueue_script( 'wc-gzd-admin' ); 
  98.  
  99. $section = 'general'; 
  100.  
  101. if ( isset( $_GET[ 'section' ] ) ) 
  102. $section = sanitize_text_field( $_GET[ 'section' ] ); 
  103.  
  104. if ( $section === 'trusted_shops' ) 
  105. do_action( 'woocommerce_gzd_load_trusted_shops_script' ); 
  106.  
  107. if ( $this->is_tour_enabled( $section ) ) { 
  108.  
  109. wp_enqueue_script( 'scrollto' ); 
  110. wp_enqueue_script( 'tourbus' ); 
  111. wp_enqueue_script( 'wc-gzd-admin-tour' ); 
  112. wp_enqueue_style( 'tourbus' ); 
  113.  
  114.  
  115. if ( in_array( $screen->id, array( 'product', 'edit-product' ) ) ) 
  116. wp_enqueue_script( 'wc-gzd-admin-product-variations' ); 
  117.  
  118. // Hide delivery time and unit tagsdiv 
  119. if ( version_compare( WC()->version, '2.3', '>=' ) ) 
  120. wp_add_inline_style( 'woocommerce-gzd-admin', '#tagsdiv-product_delivery_time, #tagsdiv-product_unit {display: none}' ); 
  121.  
  122. public function add_legal_page_metabox() { 
  123. add_meta_box( 'wc-gzd-legal-page-email-content', __( 'Optional Email Content', 'woocommerce-germanized' ), array( $this, 'init_legal_page_metabox' ), 'page' ); 
  124.  
  125. public function init_legal_page_metabox( $post ) { 
  126. $legal_pages = array( wc_get_page_id( 'revocation' ), wc_get_page_id( 'data_security' ), wc_get_page_id( 'imprint' ), wc_get_page_id( 'terms' ) ); 
  127. if ( ! in_array( $post->ID, $legal_pages ) ) { 
  128. echo '<style type="text/css">#wc-gzd-legal-page-email-content { display: none; }</style>'; 
  129. return; 
  130. echo '<p class="small">' . __( 'Add content which will be replacing default page content within emails.', 'woocommerce-germanized' ) . '</p>'; 
  131. wp_editor( htmlspecialchars_decode( get_post_meta( $post->ID, '_legal_text', true ) ), 'legal_page_email_content', array( 'textarea_name' => '_legal_text', 'textarea_rows' => 5 ) ); 
  132.  
  133. public function add_product_mini_desc() { 
  134. global $post; 
  135.  
  136. if ( is_object( $post ) && $post->post_type === 'product' ) { 
  137. $product = wc_get_product( $post ); 
  138. if ( ! $product->is_type( 'variable' ) ) 
  139. add_meta_box( 'wc-gzd-product-mini-desc', __( 'Optional Mini Description', 'woocommerce-germanized' ), array( $this, 'init_product_mini_desc' ), 'product', 'advanced', 'high' ); 
  140.  
  141. public function save_legal_page_content( $post_id, $post, $update ) { 
  142.  
  143. if ( $post->post_type != 'page' ) 
  144. return; 
  145.  
  146. if ( isset( $_POST[ '_legal_text' ] ) && ! empty( $_POST[ '_legal_text' ] ) ) 
  147. update_post_meta( $post_id, '_legal_text', esc_html( $_POST[ '_legal_text' ] ) ); 
  148. else 
  149. delete_post_meta( $post_id, '_legal_text' ); 
  150.  
  151.  
  152. public function init_product_mini_desc( $post ) { 
  153. echo '<p class="small">' . __( 'This content will be shown as short product description within checkout and emails.', 'woocommerce-germanized' ) . '</p>'; 
  154. wp_editor( htmlspecialchars_decode( get_post_meta( $post->ID, '_mini_desc', true ) ), 'wc_gzd_product_mini_desc', array( 'textarea_name' => '_mini_desc', 'textarea_rows' => 5, 'media_buttons' => false ) ); 
  155.  
  156. public function disable_tour_link( $type ) { 
  157. return wp_nonce_url( add_query_arg( array( 'tour' => $type, 'hide' => true ) ), 'wc-gzd-tour-hide' ); 
  158.  
  159. public function is_tour_enabled( $type = '' ) { 
  160. return ( ! get_option( 'woocommerce_gzd_hide_tour' ) && ! get_option( 'woocommerce_gzd_hide_tour_' . $type ) ); 
  161.  
  162. public function check_tour_hide() { 
  163.  
  164. if ( isset( $_GET[ 'tour' ] ) && isset( $_GET[ 'hide' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-tour-hide' ) ) { 
  165.  
  166. if ( ! empty( $_GET[ 'tour' ] ) ) 
  167. update_option( 'woocommerce_gzd_hide_tour_' . sanitize_text_field( $_GET[ 'tour' ] ), true ); 
  168. else  
  169. update_option( 'woocommerce_gzd_hide_tour', true ); 
  170.  
  171. wp_safe_redirect( remove_query_arg( array( 'hide', 'tour', '_wpnonce' ) ) ); 
  172.  
  173. } else if ( isset( $_GET[ 'tour' ] ) && isset( $_GET[ 'enable' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-tour-enable' ) ) { 
  174.  
  175. $setting_sections = array_merge( array(  
  176. 'general' => '',  
  177. 'display' => '',  
  178. 'emails' => '' ),  
  179. apply_filters( 'woocommerce_gzd_settings_sections', array() ) ); 
  180.  
  181. delete_option( 'woocommerce_gzd_hide_tour' ); 
  182.  
  183. foreach ( $setting_sections as $section => $name ) 
  184. delete_option( 'woocommerce_gzd_hide_tour_' . $section ); 
  185.  
  186. public function check_language_install() { 
  187.  
  188. if ( isset( $_GET[ 'install-language' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-install-language' ) ) { 
  189.  
  190. require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 
  191. $language = sanitize_text_field( $_GET[ 'install-language' ] ); 
  192.  
  193. // Download language pack if possible 
  194. if ( wp_can_install_language_pack() ) 
  195. $loaded_language = wp_download_language_pack( $language ); 
  196.  
  197. update_option( 'WPLANG', $language ); 
  198. load_default_textdomain( $loaded_language ); 
  199.  
  200. // Redirect to check for updates 
  201. wp_safe_redirect( admin_url( 'update-core.php?force-check=1' ) ); 
  202.  
  203.  
  204.  
  205. public function check_text_options_deletion() { 
  206.  
  207. if ( isset( $_GET[ 'delete-text-options' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-delete-text-options' ) ) { 
  208.  
  209. global $wpdb; 
  210.  
  211. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", 'woocommerce_gzd_%_text' ) ); 
  212.  
  213. $options = array( 
  214. 'woocommerce_gzd_checkout_legal_text_digital',  
  215. 'woocommerce_gzd_checkout_legal_text_digital_error',  
  216. 'woocommerce_gzd_order_confirmation_legal_digital_notice',  
  217. 'woocommerce_gzd_checkout_legal_text_error',  
  218. ); 
  219.  
  220. foreach ( $options as $option_name ) { 
  221. delete_option( $option_name ); 
  222.  
  223. // Reinstall options 
  224. WC_GZD_Install::create_options(); 
  225.  
  226. do_action( 'woocommerce_gzd_deleted_text_options' ); 
  227.  
  228. // Redirect to check for updates 
  229. wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=germanized' ) ); 
  230.  
  231.  
  232.  
  233. public function check_complaints_shortcode_append() { 
  234. if ( isset( $_GET[ 'complaints' ] ) && 'add' === $_GET[ 'complaints' ] && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'append-complaints-shortcode' ) ) { 
  235.  
  236. if ( wc_get_page_id( 'imprint' ) != 1 ) { 
  237.  
  238. $page_id = wc_get_page_id( 'imprint' ); 
  239. $this->insert_complaints_shortcode( $page_id ); 
  240. wp_safe_redirect( admin_url( 'post.php?post=' . $page_id . '&action=edit' ) ); 
  241.  
  242.  
  243. public function is_complaints_shortcode_inserted() { 
  244. $imprint = wc_get_page_id( 'imprint' ); 
  245. if ( $imprint != -1 ) { 
  246. $post = get_post( $imprint ); 
  247. return ( strpos( $post->post_content, '[gzd_complaints]' ) !== false ? true : false ); 
  248. return false; 
  249.  
  250. public function insert_complaints_shortcode( $page_id ) { 
  251. $page = get_post( $page_id ); 
  252. wp_update_post( 
  253. array( 
  254. 'ID' => $page_id,  
  255. 'post_content' => $page->post_content . "\n<h3>" . __( 'Complaints Procedure', 'woocommerce-germanized' ) . "</h3>\n[gzd_complaints]",  
  256. ); 
  257.