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.  
  32. add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) ); 
  33. add_action( 'save_post', array( $this, 'save_legal_page_content' ), 10, 3 ); 
  34.  
  35. add_filter( 'woocommerce_admin_status_tabs', array( $this, 'set_gzd_status_tab' ) ); 
  36. add_action( 'woocommerce_admin_status_content_germanized', array( $this, 'status_tab' ) ); 
  37.  
  38. add_action( 'admin_init', array( $this, 'check_tour_hide' ) ); 
  39. add_action( 'admin_init', array( $this, 'check_language_install' ) ); 
  40. add_action( 'admin_init', array( $this, 'check_text_options_deletion' ) ); 
  41. add_action( 'admin_init', array( $this, 'check_complaints_shortcode_append' ) ); 
  42. add_action( 'admin_init', array( $this, 'check_version_cache_deletion' ) ); 
  43.  
  44. add_filter( 'woocommerce_addons_section_data', array( $this, 'set_addon' ), 10, 2 ); 
  45. add_action( 'woocommerce_admin_order_data_after_shipping_address', array( $this, 'set_order_parcel_delivery_opted_in' ), 10, 1 ); 
  46.  
  47.  
  48. public function status_tab() { 
  49. WC_GZD_Admin_Status::output(); 
  50.  
  51. public function set_gzd_status_tab( $tabs ) { 
  52. $tabs[ 'germanized' ] = __( 'Germanized', 'woocommerce-germanized' ); 
  53. return $tabs; 
  54.  
  55. public function set_order_parcel_delivery_opted_in( $order ) { 
  56.  
  57. if ( ! wc_gzd_get_crud_data( $order, 'parcel_delivery_opted_in' ) ) 
  58. return; 
  59.  
  60. ?> 
  61. <p><strong style="display: block;"><?php _e( 'Parcel Delivery Data Transfer:', 'woocommerce-germanized' ) ?></strong> 
  62. <span><?php echo ( wc_gzd_order_supports_parcel_delivery_reminder( wc_gzd_get_crud_data( $order, 'id' ) ) ? __( 'allowed', 'woocommerce-germanized' ) : __( 'not allowed', 'woocommerce-germanized' ) ); ?></span> 
  63. </p> 
  64. <?php 
  65.  
  66. public function set_addon( $products, $section_id ) { 
  67.  
  68. if ( $section_id !== 'featured' ) 
  69. return $products; 
  70.  
  71. array_unshift( $products, (object) array( 
  72. 'title' => 'Woo Germanized Pro',  
  73. 'excerpt' => 'Upgrade jetzt auf die Pro Version von WooCommerce Germanized und profitiere von weiteren ntzliche Funktionen speziell fr den deutschen Markt sowie professionellem Support.',  
  74. 'link' => 'https://vendidero.de/woocommerce-germanized#buy',  
  75. 'price' => '69, 95 *',  
  76. ) ); 
  77.  
  78. return $products; 
  79.  
  80. public function status_page() { 
  81. WC_GZD_Admin_Status::output(); 
  82.  
  83. public function add_scripts() { 
  84.  
  85. $screen = get_current_screen(); 
  86. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  87. $assets_path = WC_germanized()->plugin_url() . '/assets/'; 
  88. $admin_script_path = $assets_path . 'js/admin/'; 
  89.  
  90. wp_register_style( 'woocommerce-gzd-admin', $assets_path . 'css/woocommerce-gzd-admin' . $suffix . '.css', false, WC_GERMANIZED_VERSION ); 
  91. wp_enqueue_style( 'woocommerce-gzd-admin' ); 
  92.  
  93. wp_register_style( 'tourbus', $assets_path . 'css/tourbus' . $suffix . '.css', false, WC_GERMANIZED_VERSION ); 
  94.  
  95. wp_register_script( 'wc-gzd-admin', $admin_script_path . 'settings' . $suffix . '.js', array( 'jquery', 'woocommerce_settings' ), WC_GERMANIZED_VERSION, true ); 
  96. wp_register_script( 'scrollto', $admin_script_path . 'scrollTo' . $suffix . '.js', array( 'jquery' ), WC_GERMANIZED_VERSION, true ); 
  97. wp_register_script( 'tourbus', $admin_script_path . 'tourbus' . $suffix . '.js', array( 'jquery', 'scrollto' ), WC_GERMANIZED_VERSION, true ); 
  98. wp_register_script( 'wc-gzd-admin-tour', $admin_script_path . 'tour' . $suffix . '.js', array( 'jquery', 'woocommerce_settings', 'tourbus' ), WC_GERMANIZED_VERSION, true ); 
  99. wp_register_script( 'wc-gzd-admin-product-variations', $admin_script_path . 'product-variations' . $suffix . '.js', array( 'wc-admin-variation-meta-boxes' ), WC_GERMANIZED_VERSION ); 
  100.  
  101. if ( isset( $_GET[ 'tab' ] ) && $_GET[ 'tab' ] == 'germanized' ) { 
  102.  
  103. wp_enqueue_script( 'wc-gzd-admin' ); 
  104.  
  105. $section = 'general'; 
  106.  
  107. if ( isset( $_GET[ 'section' ] ) ) 
  108. $section = sanitize_text_field( $_GET[ 'section' ] ); 
  109.  
  110. if ( $section === 'trusted_shops' ) 
  111. do_action( 'woocommerce_gzd_load_trusted_shops_script' ); 
  112.  
  113. if ( $this->is_tour_enabled( $section ) ) { 
  114.  
  115. wp_enqueue_script( 'scrollto' ); 
  116. wp_enqueue_script( 'tourbus' ); 
  117. wp_enqueue_script( 'wc-gzd-admin-tour' ); 
  118. wp_enqueue_style( 'tourbus' ); 
  119.  
  120.  
  121. if ( in_array( $screen->id, array( 'product', 'edit-product' ) ) ) 
  122. wp_enqueue_script( 'wc-gzd-admin-product-variations' ); 
  123.  
  124. // Hide delivery time and unit tagsdiv 
  125. if ( version_compare( WC()->version, '2.3', '>=' ) ) 
  126. wp_add_inline_style( 'woocommerce-gzd-admin', '#tagsdiv-product_delivery_time, #tagsdiv-product_unit {display: none}' ); 
  127.  
  128. public function add_legal_page_metabox() { 
  129. add_meta_box( 'wc-gzd-legal-page-email-content', __( 'Optional Email Content', 'woocommerce-germanized' ), array( $this, 'init_legal_page_metabox' ), 'page' ); 
  130.  
  131. public function init_legal_page_metabox( $post ) { 
  132. $legal_pages = array( wc_get_page_id( 'revocation' ), wc_get_page_id( 'data_security' ), wc_get_page_id( 'imprint' ), wc_get_page_id( 'terms' ) ); 
  133. if ( ! in_array( $post->ID, $legal_pages ) ) { 
  134. echo '<style type="text/css">#wc-gzd-legal-page-email-content { display: none; }</style>'; 
  135. return; 
  136. echo '<p class="small">' . __( 'Add content which will be replacing default page content within emails.', 'woocommerce-germanized' ) . '</p>'; 
  137. wp_editor( htmlspecialchars_decode( get_post_meta( $post->ID, '_legal_text', true ) ), 'legal_page_email_content', array( 'textarea_name' => '_legal_text', 'textarea_rows' => 5 ) ); 
  138.  
  139. public function add_product_mini_desc() { 
  140. global $post; 
  141.  
  142. if ( is_object( $post ) && $post->post_type === 'product' ) { 
  143. $product = wc_get_product( $post ); 
  144. if ( ! $product->is_type( 'variable' ) ) 
  145. add_meta_box( 'wc-gzd-product-mini-desc', __( 'Optional Mini Description', 'woocommerce-germanized' ), array( $this, 'init_product_mini_desc' ), 'product', 'advanced', 'high' ); 
  146.  
  147. public function save_legal_page_content( $post_id, $post, $update ) { 
  148.  
  149. if ( $post->post_type != 'page' ) 
  150. return; 
  151.  
  152. if ( isset( $_POST[ '_legal_text' ] ) && ! empty( $_POST[ '_legal_text' ] ) ) 
  153. update_post_meta( $post_id, '_legal_text', esc_html( $_POST[ '_legal_text' ] ) ); 
  154. else 
  155. delete_post_meta( $post_id, '_legal_text' ); 
  156.  
  157.  
  158. public function init_product_mini_desc( $post ) { 
  159. echo '<p class="small">' . __( 'This content will be shown as short product description within checkout and emails.', 'woocommerce-germanized' ) . '</p>'; 
  160. 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 ) ); 
  161.  
  162. public function disable_tour_link( $type ) { 
  163. return wp_nonce_url( add_query_arg( array( 'tour' => $type, 'hide' => true ) ), 'wc-gzd-tour-hide' ); 
  164.  
  165. public function is_tour_enabled( $type = '' ) { 
  166. return ( ! get_option( 'woocommerce_gzd_hide_tour' ) && ! get_option( 'woocommerce_gzd_hide_tour_' . $type ) ); 
  167.  
  168. public function check_tour_hide() { 
  169.  
  170. if ( isset( $_GET[ 'tour' ] ) && isset( $_GET[ 'hide' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-tour-hide' ) ) { 
  171.  
  172. if ( ! empty( $_GET[ 'tour' ] ) ) 
  173. update_option( 'woocommerce_gzd_hide_tour_' . sanitize_text_field( $_GET[ 'tour' ] ), true ); 
  174. else  
  175. update_option( 'woocommerce_gzd_hide_tour', true ); 
  176.  
  177. wp_safe_redirect( remove_query_arg( array( 'hide', 'tour', '_wpnonce' ) ) ); 
  178.  
  179. } elseif ( isset( $_GET[ 'tour' ] ) && isset( $_GET[ 'enable' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-tour-enable' ) ) { 
  180.  
  181. $setting_sections = array_merge( array(  
  182. 'general' => '',  
  183. 'display' => '',  
  184. 'emails' => '' ),  
  185. apply_filters( 'woocommerce_gzd_settings_sections', array() ) ); 
  186.  
  187. delete_option( 'woocommerce_gzd_hide_tour' ); 
  188.  
  189. foreach ( $setting_sections as $section => $name ) 
  190. delete_option( 'woocommerce_gzd_hide_tour_' . $section ); 
  191.  
  192. public function check_language_install() { 
  193.  
  194. if ( isset( $_GET[ 'install-language' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-install-language' ) ) { 
  195.  
  196. require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 
  197. $language = sanitize_text_field( $_GET[ 'install-language' ] ); 
  198.  
  199. // Download language pack if possible 
  200. if ( wp_can_install_language_pack() ) 
  201. $loaded_language = wp_download_language_pack( $language ); 
  202.  
  203. update_option( 'WPLANG', $language ); 
  204. load_default_textdomain( $loaded_language ); 
  205.  
  206. // Redirect to check for updates 
  207. wp_safe_redirect( admin_url( 'update-core.php?force-check=1' ) ); 
  208.  
  209.  
  210.  
  211. public function check_text_options_deletion() { 
  212.  
  213. if ( isset( $_GET[ 'delete-text-options' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-delete-text-options' ) ) { 
  214.  
  215. global $wpdb; 
  216.  
  217. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", 'woocommerce_gzd_%_text' ) ); 
  218.  
  219. $options = array( 
  220. 'woocommerce_gzd_checkout_legal_text_digital',  
  221. 'woocommerce_gzd_checkout_legal_text_digital_error',  
  222. 'woocommerce_gzd_order_confirmation_legal_digital_notice',  
  223. 'woocommerce_gzd_checkout_legal_text_error',  
  224. ); 
  225.  
  226. foreach ( $options as $option_name ) { 
  227. delete_option( $option_name ); 
  228.  
  229. // Reinstall options 
  230. WC_GZD_Install::create_options(); 
  231.  
  232. do_action( 'woocommerce_gzd_deleted_text_options' ); 
  233.  
  234. // Redirect to check for updates 
  235. wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=germanized' ) ); 
  236.  
  237.  
  238.  
  239. public function check_version_cache_deletion() { 
  240.  
  241. if ( isset( $_GET[ 'delete-version-cache' ] ) && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'wc-gzd-delete-version-cache' ) ) { 
  242.  
  243. wc_gzd_get_dependencies()->delete_cached_plugin_header_data(); 
  244.  
  245. do_action( 'woocommerce_gzd_deleted_cached_plugin_header_data' ); 
  246.  
  247. public function get_complaints_shortcode_pages() { 
  248.  
  249. $pages = array( 
  250. 'imprint' => wc_get_page_id( 'imprint' ),  
  251. ); 
  252.  
  253. if ( wc_get_page_id( 'terms' ) && wc_get_page_id( 'terms' ) != -1 ) { 
  254. $pages[ 'terms' ] = wc_get_page_id( 'terms' ); 
  255.  
  256. return $pages; 
  257.  
  258. public function check_complaints_shortcode_append() { 
  259. if ( isset( $_GET[ 'complaints' ] ) && 'add' === $_GET[ 'complaints' ] && isset( $_GET[ '_wpnonce' ] ) && check_admin_referer( 'append-complaints-shortcode' ) ) { 
  260.  
  261. $pages = $this->get_complaints_shortcode_pages(); 
  262.  
  263. foreach( $pages as $page_name => $page_id ) { 
  264.  
  265. if ( $page_id != 1 ) { 
  266. $this->insert_complaints_shortcode( $page_id ); 
  267.  
  268. // Redirect to check for updates 
  269. wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=germanized' ) ); 
  270.  
  271. public function is_complaints_shortcode_inserted( $page_id ) { 
  272. $post = get_post( $page_id ); 
  273. if ( $post ) 
  274. return ( strpos( $post->post_content, '[gzd_complaints]' ) !== false ? true : false ); 
  275. return false; 
  276.  
  277. public function insert_complaints_shortcode( $page_id ) { 
  278. if ( $this->is_complaints_shortcode_inserted( $page_id ) ) 
  279. return; 
  280.  
  281. $page = get_post( $page_id ); 
  282. wp_update_post( 
  283. array( 
  284. 'ID' => $page_id,  
  285. 'post_content' => $page->post_content . "\n[gzd_complaints]",  
  286. ); 
  287.  
  288. public function get_shipping_method_instances() { 
  289.  
  290. if ( ! class_exists( 'WC_Shipping_Zones' ) ) { 
  291. $instances = WC()->shipping->get_shipping_methods(); 
  292. } else { 
  293. $zones = WC_Shipping_Zones::get_zones(); 
  294. $worldwide = new WC_Shipping_Zone( 0 ); 
  295.  
  296. $instances = $worldwide->get_shipping_methods( true ); 
  297.  
  298. foreach( $zones as $id => $zone ) { 
  299. $zone = new WC_Shipping_Zone( $id ); 
  300. $instances = $instances + $zone->get_shipping_methods( true ); 
  301.  
  302. return $instances; 
  303.  
  304. public function get_shipping_method_instances_options() { 
  305.  
  306. $methods = $this->get_shipping_method_instances(); 
  307. $shipping_methods_options = array(); 
  308.  
  309. foreach ( $methods as $key => $method ) { 
  310.  
  311. if ( method_exists( $method, 'get_rate_id' ) ) { 
  312. $key = $method->get_rate_id(); 
  313. } else { 
  314. $key = $method->id; 
  315.  
  316. $title = $method->get_title(); 
  317.  
  318. $shipping_methods_options[ $key ] = ( empty( $title ) ? $method->get_method_title() : $title ); 
  319.  
  320. return $shipping_methods_options; 
  321.