*/ 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 '
'; echo '

' . esc_html__( 'Activities Options', 'activities' ) . '

'; echo '
'; echo Activities_Admin::get_messages(); echo ''; echo '
'; switch ($tab) { case 'general': activities_options_general(); break; case 'nice': activities_options_nice(); break; case 'woocommerce': activities_options_woocommerce(); break; default: activities_options_general(); break; } echo '
'; echo wp_nonce_field( 'activities_options', ACTIVITIES_ADMIN_OPTIONS_NONCE, true, false ); echo ''; echo '
'; } /** * Echoes activities options general tab page */ function activities_options_general() { global $wp_roles; $roles = $wp_roles->get_names(); $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 Participant', 'activities' ), ACTIVITIES_CAN_BE_RESPONSIBLE_KEY => esc_html__( 'Can be Responsible', 'activities' ) ); echo '
'; echo '
'; echo '

' . esc_html__( 'Permissions', 'activities' ) . '

'; echo ''; echo ''; echo ''; foreach ($permissions as $display) { echo ''; } echo ''; echo ''; foreach ($roles as $r_key => $r_name) { echo ''; echo ''; 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 ''; } echo ''; echo '
' . esc_html__( 'Roles', 'activities' ) . '' . esc_html( $display ) . '
' . translate_user_role( $r_name ) . '
'; echo '

' . esc_html__( 'Responsible Users', 'activities' ) . '

'; echo '
'; 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 '
'; $act_roles_options = array( ACTIVITIES_CAN_BE_MEMBER_KEY => Activities_Options::get_option( ACTIVITIES_CAN_BE_MEMBER_KEY ), ACTIVITIES_CAN_BE_RESPONSIBLE_KEY => Activities_Options::get_option( ACTIVITIES_CAN_BE_RESPONSIBLE_KEY ) ); echo '
'; echo '

' . esc_html__( 'Activity Roles', 'activities' ) . '

'; echo ''; echo ''; echo ''; foreach ($activity_roles as $display) { echo ''; } echo ''; echo ''; foreach ($roles as $r_key => $r_name) { echo ''; echo ''; foreach (array_keys( $activity_roles ) as $ar_key) { $checked = 'unchecked'; if ( in_array( $r_key, $act_roles_options[$ar_key] ) ) { $checked = 'checked'; } echo ''; } echo ''; } echo ''; echo '
' . esc_html__( 'Roles', 'activities' ) . '' . esc_html( $display ) . '
' . translate_user_role( $r_name ) . '
'; echo '
'; echo '
'; echo '

' . esc_html__( 'Activities Deletion', 'activities' ) . '

'; echo ' '; 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 '
'; echo '
'; echo '

' . esc_html__( 'Better user search', 'activities' ) . '

'; echo ' '; echo '
'; echo '

' . esc_html__( "Allows you to search users by their first name and last name.\nMight make searching slower.", 'activities' ); echo '

'; echo '
'; echo '
'; echo '

' . esc_html__( 'Quick edit types', 'activities' ) . '

'; $input_texts = array(); foreach (Activities_Options::get_option( ACTIVITIES_QUICK_EDIT_TYPES_KEY ) as $meta_key => $type) { if ( !isset( $input_texts[$type] ) ) { $input_texts[$type] = array(); } $input_texts[$type][] = $meta_key; } foreach (acts_get_quick_edit_types() as $type => $display) { echo ''; $val = ''; if ( isset( $input_texts[$type] ) ) { $val = implode( ',', $input_texts[$type] ); } echo ''; } echo '

'; echo esc_html__( 'Select special input types for quick user edit', 'activities' ); echo '

'; echo '
'; echo acts_nice_meta_key_set(); echo '
'; //activities-options } /** * Echoes activities options activity nice (report) tab page */ function activities_options_nice() { echo '
'; echo '

' . esc_html__( 'Activity Report Default Settings', 'activities' ) . '

'; $test_activity = array( 'activity_id' => -1, 'name' => esc_html__( 'Activity name', 'activities' ), 'start' => '1970-01-01', 'end' => date( 'Y-m-d' ), 'short_desc' => esc_html__( '(short description) This is a example activity', 'activities' ), 'long_desc' => esc_html__( '(long description) If a user does not some data, like an address, it will not be shown. In this general example, all data is shown where it would be with real users.', 'activities' ), 'responsible_id' => -1, 'location_id' => -1, 'members' => array( -1, -2, -3, -4, -5 ) ); echo acts_activity_nice_management( $test_activity ); echo '
'; //activity nice settings } /** * Echoes activities options WooCommerce tab page */ function activities_options_woocommerce() { echo '
'; echo '
'; echo '

' . esc_html__( 'WooCommerce Guest Customers', 'activities' ) . '

'; $checked = Activities_Options::get_option( ACTIVITIES_WOOCOMMERCE_CONVERT_KEY ) ? 'checked' : ''; echo '' . esc_html__( 'Enable Guest Coversion', 'activities' ) . '
'; echo '' . esc_html__( "Enables automatic conversion of guest customers to users.\nThis allows guests to be added to activities.", 'activities' ) . '

'; echo '
'; $coupons = get_posts( array( 'post_type' => 'shop_coupon', 'numberposts' => -1 ) ); if ( count( $coupons ) ) { $coupons_display = Activities_Options::get_option( ACTIVITIES_NICE_WC_COUPONS_KEY ); echo '
'; echo '

' . esc_html__( 'Coupons on activities report', 'activities' ) . '

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ($coupons as $coupon) { echo ''; $checked = isset( $coupons_display[$coupon->post_title] ) ? 'checked' : ''; echo ''; echo ''; } echo ''; echo '
' . esc_html__( 'Coupons', 'activities' ) . '' . esc_html__( 'Display on activity report', 'activities' ) . '
' . stripslashes( wp_filter_nohtml_kses( ucfirst( $coupon->post_title ) ) ) . '
'; echo '
'; } echo '
'; echo '

' . esc_html__( 'Actions', 'activities' ) . '

'; echo ' '; echo '
'; echo '

'; echo ' '; echo '
'; echo '

'; echo '
'; echo '
'; //activities-options } /** * Verifies options nonce * * @return bool True if its verified, false if not */ function activities_options_verify() { if ( isset( $_POST[ACTIVITIES_ADMIN_OPTIONS_NONCE] ) ) { return wp_verify_nonce( $_POST[ACTIVITIES_ADMIN_OPTIONS_NONCE], 'activities_options' ); } else { Activities_Admin::add_error_message( esc_html__( 'Could not verify options.', 'activities' ) ); return false; } } /** * Gets all the tabs for the options page * * @return array */ function acts_get_options_tabs() { $tabs = array( 'general' => esc_html__( 'General', 'activities' ), 'nice' => esc_html__( 'Activity Report', 'activities' ) ); if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) { $tabs['woocommerce'] = 'WooCommerce'; } return $tabs; } /** * Get all responsible options * * @return array */ function acts_get_responsible_options() { return array( ACTIVITIES_RESPONSIBLE_SAME => esc_html__( 'Same as their role permissions', 'activities' ), ACTIVITIES_RESPONSIBLE_VIEW => esc_html__( 'View assigned activities', 'activities' ), ACTIVITIES_RESPONSIBLE_EDIT => esc_html__( 'View and edit assigned activities', 'activities' ) ); } /** * Get quick edit types * * @return array */ function acts_get_quick_edit_types() { return array( 'textarea' => esc_html__( 'Textarea', 'activities' ), 'country' => esc_html__( 'Country', 'activities' ) ); }