__('Property Name'), 'custom_dimension_name'=>__('Custom Dimension Name'), 'custom_dimension_index'=>__('Index') ); } public function get_sortable_columns() { return $sortable = array( 'property_name'=> array('property_name',true), 'custom_dimension_index'=> array('custom_dimension_index',true) ); } public function prepare_items() { $result = Pipeline::process(); if(!$result){ return; } $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns()); $results = array(); $ga_service = new Fiftyonedegrees_Google_Analytics(); $ga_service->get_custom_dimensions(); $currCustDimIndex = get_option("fiftyonedegrees_ga_max_cust_dim_index", 0); $passedDims = get_option("fiftyonedegrees_passed_dimensions"); foreach ($result["properties"] as $dataKey => $properties) { foreach ($properties as $property) { if ( strpos(strtolower($property["name"]), "javascript") === false && strpos(strtolower($property["name"]), "setheader") === false) { // Get the property name. $propertyName = strtolower($property["name"]); // Get the Custom Dimension Name Listbox for the property. $custom_dimension_name = $this->get_custom_dimension_name($dataKey, $property["name"]); $custom_dimension_list = $this->get_custom_dimension_listbox($custom_dimension_name); // Get Custom Dimension Index for the property. $custom_dimension_index = -2; $actual_custom_dimension_name = $custom_dimension_name; if( isset($passedDims[$propertyName]) ) { $actual_custom_dimension_name = $passedDims[$propertyName]; } $ga_custom_dimension_index = $this->get_ga_custom_dimension_index( $actual_custom_dimension_name ); if( $ga_custom_dimension_index > -1 ) { $custom_dimension_index = $ga_custom_dimension_index; } else { $currCustDimIndex = $currCustDimIndex + 1; $custom_dimension_index = $currCustDimIndex; } // Prepare table results $results[] = array( "property_name" => $propertyName, "custom_dimension_name" => $custom_dimension_list, "custom_dimension_index" => $custom_dimension_index ); $ga_results[] = array( "property_name" => strtolower($property["name"]), "custom_dimension_index" => $custom_dimension_index, "custom_dimension_name" => $actual_custom_dimension_name, "custom_dimension_ga_index" => $ga_custom_dimension_index, "custom_dimension_datakey" => $dataKey ); } } } usort($results, function ($a, $b) { $orderby = ( !empty( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'custom_dimension_index'; $order = ( !empty( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'asc'; $result = 0; if ( $a[$orderby] > $b[$orderby] ) { $result = 1; } else if ( $a[$orderby] < $b[$orderby] ) { $result = -1; } return ( $order === 'asc' ) ? $result : -$result; }); update_option( "fiftyonedegrees_ga_cust_dims_map", $ga_results ); $this->items = $results; } public function display_rows() { $records = $this->items; foreach ( $records as $i => $rec ) { echo '