desc` */ function __construct() { $this->id = 'general'; $this->short_desc = __( 'General', 'woocommerce-jetpack' ); $this->desc = __( 'Custom roles tool. Shortcodes in WordPress text widgets.', 'woocommerce-jetpack' ); $this->link_slug = 'woocommerce-booster-general-tools'; parent::__construct(); $this->add_tools( array( 'products_atts' => array( 'title' => __( 'Products Attributes', 'woocommerce-jetpack' ), 'desc' => __( 'All Products and All Attributes.', 'woocommerce-jetpack' ), ), 'custom_roles' => array( 'title' => __( 'Add/Manage Custom Roles', 'woocommerce-jetpack' ), 'tab_title' => __( 'Custom Roles', 'woocommerce-jetpack' ), 'desc' => __( 'Manage Custom Roles.', 'woocommerce-jetpack' ), ), ) ); if ( $this->is_enabled() ) { // Recalculate cart totals if ( 'yes' === get_option( 'wcj_general_advanced_recalculate_cart_totals', 'no' ) ) { add_action( 'wp_loaded', array( $this, 'fix_mini_cart' ), PHP_INT_MAX ); } // Product revisions if ( 'yes' === get_option( 'wcj_product_revisions_enabled', 'no' ) ) { add_filter( 'woocommerce_register_post_type_product', array( $this, 'enable_product_revisions' ) ); } // Shortcodes in text widgets if ( 'yes' === get_option( 'wcj_general_shortcodes_in_text_widgets_enabled' ) ) { add_filter( 'widget_text', 'do_shortcode' ); } // PayPal email per product if ( 'yes' === get_option( 'wcj_paypal_email_per_product_enabled', 'no' ) ) { add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) ); add_action( 'save_post_product', array( $this, 'save_meta_box' ), PHP_INT_MAX, 2 ); add_filter( 'woocommerce_payment_gateways', array( $this, 'maybe_change_paypal_email' ) ); } // Session expiration if ( 'yes' === get_option( 'wcj_session_expiration_section_enabled', 'no' ) ) { add_filter( 'wc_session_expiring', array( $this, 'change_session_expiring' ), PHP_INT_MAX ); add_filter( 'wc_session_expiration', array( $this, 'change_session_expiration' ), PHP_INT_MAX ); } // Booster role user changer if ( wcj_is_booster_role_changer_enabled() ) { add_action( 'admin_bar_menu', array( $this, 'add_user_role_changer' ), PHP_INT_MAX ); add_action( 'init', array( $this, 'change_user_role_meta' ) ); } } } /** * change_user_role_meta. * * @version 2.9.0 * @since 2.9.0 * @todo (maybe) optionally via cookies */ function change_user_role_meta() { if ( isset( $_GET['wcj_booster_user_role'] ) ) { $current_user_id = get_current_user_id(); update_user_meta( $current_user_id, '_' . 'wcj_booster_user_role', $_GET['wcj_booster_user_role'] ); } } /** * add_user_role_changer. * * @version 2.9.0 * @since 2.9.0 */ function add_user_role_changer( $wp_admin_bar ) { $current_user_id = get_current_user_id(); $user_roles = wcj_get_user_roles_options(); if ( '' != ( $current_booster_user_role = get_user_meta( $current_user_id, '_' . 'wcj_booster_user_role', true ) ) ) { $current_booster_user_role = ( isset( $user_roles[ $current_booster_user_role ] ) ) ? $user_roles[ $current_booster_user_role ] : $current_booster_user_role; $current_booster_user_role = ' [' . $current_booster_user_role . ']'; } $args = array( 'parent' => false, 'id' => 'booster-user-role-changer', 'title' => __( 'Booster User Role', 'woocommerce-jetpack' ) . $current_booster_user_role, 'href' => false, ); $wp_admin_bar->add_node( $args ); foreach ( $user_roles as $user_role_key => $user_role_name ) { $args = array( 'parent' => 'booster-user-role-changer', 'id' => 'booster-user-role-changer-role-' . $user_role_key, 'title' => $user_role_name, 'href' => add_query_arg( 'wcj_booster_user_role', $user_role_key ), ); $wp_admin_bar->add_node( $args ); } } /** * fix_mini_cart. * * @version 2.5.2 * @since 2.5.2 * @todo this is only temporary solution! */ function fix_mini_cart() { if ( wcj_is_frontend() ) { if ( null !== ( $wc = WC() ) ) { if ( isset( $wc->cart ) ) { $wc->cart->calculate_totals(); } } } } /** * change_session_expiring. * * @version 2.5.7 * @since 2.5.7 */ function change_session_expiring( $the_time ) { return get_option( 'wcj_session_expiring', 47 * 60 * 60 ); } /** * change_session_expiration. * * @version 2.5.7 * @since 2.5.7 */ function change_session_expiration( $the_time ) { return get_option( 'wcj_session_expiration', 48 * 60 * 60 ); } /** * create_custom_roles_tool. * * @version 2.5.3 * @since 2.5.3 */ function create_custom_roles_tool() { if ( isset( $_POST['wcj_add_new_role'] ) ) { if ( ! isset( $_POST['wcj_custom_role_id'] ) || '' == $_POST['wcj_custom_role_id'] || ! isset( $_POST['wcj_custom_role_name'] ) || '' == $_POST['wcj_custom_role_name'] ) { echo '
' . __( 'Both fields are required!', 'woocommerce-jetpack') . '
'; } else { if ( is_numeric( $_POST['wcj_custom_role_id'] ) ) { echo '' . __( 'Role ID must not be numbers only!', 'woocommerce-jetpack') . '
'; } else { $result = add_role( $_POST['wcj_custom_role_id'], $_POST['wcj_custom_role_name'] ); if ( null !== $result ) { echo '' . __( 'Role successfully added!', 'woocommerce-jetpack') . '
'; } else { echo '' . __( 'Role already exists!', 'woocommerce-jetpack') . '
'; } } } } if ( isset( $_GET['wcj_delete_role'] ) && '' != $_GET['wcj_delete_role'] ) { remove_role( $_GET['wcj_delete_role'] ); echo '' . sprintf( __( 'Role %s successfully deleted!', 'woocommerce-jetpack'), $_GET['wcj_delete_role'] ) . '
'; } echo $this->get_tool_header_html( 'custom_roles' ); $table_data = array(); $table_data[] = array( __( 'ID', 'woocommerce-jetpack'), __( 'Name', 'woocommerce-jetpack'), __( 'Actions', 'woocommerce-jetpack'), ); $existing_roles = wcj_get_user_roles(); $default_wp_wc_roles = array( 'guest', 'administrator', 'editor', 'author', 'contributor', 'subscriber', 'customer', 'shop_manager', ); foreach ( $existing_roles as $role_key => $role_data ) { $delete_html = ( in_array( $role_key, $default_wp_wc_roles ) ) ? '' : '' . __( 'Delete', 'woocommerce-jetpack') . ''; $table_data[] = array( $role_key, $role_data['name'], $delete_html ); } echo '' . __( 'Total Products:', 'woocommerce-jetpack' ) . ' ' . $total_products . '
' . wcj_get_table_html( $table_data, array( 'table_class' => 'widefat striped' ) ); } } endif; return new WCJ_General();