*/ if ( !defined( 'WPINC' ) ) { die; } /** * Echoes activities options page and handles saving options */ function activities_admin_options_page() { if ( !current_user_can( ACTIVITIES_ADMINISTER_OPTIONS ) ) { wp_die( esc_html__( 'Access Denied', 'activities' ) ); } global $wpdb, $wp_roles; $tab = 'general'; $all_tabs = acts_get_options_tabs(); if ( isset( $_GET['tab'] ) ) { $tab = sanitize_key( $_GET['tab'] ); if ( !array_key_exists( $tab, $all_tabs ) ) { $tab = 'general'; } } $permissions = array( ACTIVITIES_ACCESS_ACTIVITIES => esc_html__( 'View Activities', 'activities' ), ACTIVITIES_ADMINISTER_ACTIVITIES => esc_html__( 'Administer Activities', 'activities' ), ACTIVITIES_ADMINISTER_OPTIONS => esc_html__( 'Administer Activities Options', 'activities' ), ); $activity_roles = array( ACTIVITIES_CAN_BE_MEMBER_KEY => esc_html__( 'Can be Member', 'activities' ), ACTIVITIES_CAN_BE_RESPONSIBLE_KEY => esc_html__( 'Can be Responsible', 'activities' ) ); $roles = $wp_roles->get_names(); if ( isset( $_POST['save_options']) ) { if ( activities_options_verify() ) { switch ($tab) { case 'general': foreach (array_keys( $permissions ) as $p_key) { foreach (array_keys( $roles ) as $r_key) { if ( $r_key === 'administrator' ) { continue; } if ( isset( $_POST[$p_key] ) && !is_array( $_POST[$p_key] ) ) { continue; } if ( isset( $_POST[$p_key][$r_key] ) ) { $wp_roles->get_role( $r_key )->add_cap( $p_key ); if ( $p_key === ACTIVITIES_ADMINISTER_ACTIVITIES && !isset( $_POST[ACTIVITIES_ACCESS_ACTIVITIES][$r_key] ) ) { $wp_roles->get_role( $r_key )->add_cap( ACTIVITIES_ACCESS_ACTIVITIES ); } } else { $wp_roles->get_role( $r_key )->remove_cap( $p_key ); } } } $res_per = sanitize_key( $_POST['responsible_permission'] ); if ( array_key_exists( $res_per, acts_get_responsible_options() ) ) { Activities_Options::update_option( ACTIVITIES_RESPONSIBLE_KEY, $res_per ); } foreach ( array_keys( $activity_roles ) as $ar_key ) { if ( !is_array( $_POST[$ar_key] ) ) { continue; } $roles_list = array(); foreach ( array_keys( $roles ) as $r_key ) { if ( isset( $_POST[$ar_key][$r_key] ) ) { $roles_list[] = $r_key; } } Activities_Options::update_option( $ar_key, $roles_list ); } Activities_Responsible::update_all_users_responsiblity(); Activities_Options::update_option( ACTIVITIES_DELETE_DATA_KEY, isset( $_POST['delete_data'] ) ); Activities_Options::update_option( ACTIVITIES_USER_SEARCH_KEY, isset( $_POST['bus'] ) ); $types_map = array(); $types = acts_get_quick_edit_types(); if (isset( $_POST['edit_types'] ) && is_array( $_POST['edit_types'] ) ) { foreach ($_POST['edit_types'] as $key => $value) { $key = sanitize_key( $key ); if ( isset( $types[$key] ) ) { $values = explode( ',', sanitize_text_field( $value ) ); foreach ($values as $meta_key) { $meta_key = sanitize_key( $meta_key ); if ( $meta_key != '') { $types_map[$meta_key] = $key; } } } } } Activities_Options::update_option( ACTIVITIES_QUICK_EDIT_TYPES_KEY, $types_map ); break; case 'nice': $ns = Activities_Admin_Utility::get_activity_nice_settings(); unset( $ns['activity_id'] ); Activities_Options::update_option( ACTIVITIES_NICE_SETTINGS_KEY, $ns ); break; case 'woocommerce': Activities_Options::update_option( ACTIVITIES_WOOCOMMERCE_CONVERT_KEY, isset( $_POST[ACTIVITIES_WOOCOMMERCE_CONVERT_KEY] ) ); $coupons_display = array(); if ( isset( $_POST[ACTIVITIES_NICE_WC_COUPONS_KEY] ) && is_array( $_POST[ACTIVITIES_NICE_WC_COUPONS_KEY] ) ) { foreach ($_POST[ACTIVITIES_NICE_WC_COUPONS_KEY] as $coupon => $value) { $coupons_display[$coupon] = true; } } Activities_Options::update_option( ACTIVITIES_NICE_WC_COUPONS_KEY, $coupons_display ); break; } Activities_Admin::add_success_message( esc_html__( 'Options has been updated.', 'activities' ) ); } } elseif ( isset( $_POST['convert_guests'] ) ) { Activities_WooCommerce::create_users_from_past_orders(); return; } elseif ( isset( $_POST['delete_guests'] ) ) { Activities_WooCommerce::flush_created_users(); return; } $current_url = ( isset($_SERVER['HTTPS'] ) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; global $wpdb; echo '
| ' . esc_html__( 'Roles', 'activities' ) . ' | '; foreach ($permissions as $display) { echo '' . esc_html( $display ) . ' | '; } echo '
| ' . translate_user_role( $r_name ) . ' | '; foreach (array_keys( $permissions ) as $p_key) { $checked = 'unchecked'; if ( $r_key === 'administrator' || $wp_roles->get_role($r_key)->has_cap($p_key) ) { $checked = 'checked'; } echo ''; } echo ' |
' . esc_html__( "This will be in addtion to role permissions.\nAn admin will always be able to view and edit their assigned activities,\nwhatever the responsible permission setting is set to.", 'activities' ) . '
'; echo '| ' . esc_html__( 'Roles', 'activities' ) . ' | '; foreach ($activity_roles as $display) { echo '' . esc_html( $display ) . ' | '; } echo '
| ' . translate_user_role( $r_name ) . ' | '; foreach (array_keys( $activity_roles ) as $ar_key) { $checked = 'unchecked'; if ( in_array( $r_key, $act_roles_options[$ar_key] ) ) { $checked = 'checked'; } echo ''; } echo ' |
' . esc_html__( 'Makes the plugin delete all off it\'s data on uninstall, only the current blog.', 'activities' ); if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) { echo '' . sprintf( esc_html__( 'With the exception of user created from %s guest customers.', 'activities' ), 'WooCommerce' ) . '' . sprintf( esc_html__( 'You can delete those with the button in the %s tab.', 'activities' ), 'WooCommerce' ); } echo '
'; echo '' . esc_html__( "Allows you to search users by their first name and last name.\nMight make searching slower.", 'activities' ); echo '
'; echo '| ' . esc_html__( 'Coupons', 'activities' ) . ' | ' . esc_html__( 'Display on activity report', 'activities' ) . ' | '; echo '
| ' . stripslashes( wp_filter_nohtml_kses( ucfirst( $coupon->post_title ) ) ) . ' | '; echo ' |