Location Management Hooks & Filters

The following action hooks and filters are related to location management.

slp_action_box_3_content

Type: Filter
Parameters:
 string - the manage location screen action box #3 HTML string

Add or change the 3rd action box on the manage locations action bar.

slp_add_location_form_footer

Type: filter
    Params: 
       [0] - HTML for the additional add location form, default is blank.

Used to add HTML content with the add location form.

slp_addlocations_with_csv

Type: action
Default Priority: 10 
Parameters: none

Runs whenever the add locations processor gets a CSV file input.

slp_column_data

Parameters:
    the column data as a string
    the name of the database field
    the name of the column label
Default Priority: 10

Use this filter to tweak the data that is output on the manage locations screen.

The filter is passed three parameters representing the data that is about to be displayed, the name of the database field from which the data was obtained, and the column label. You can use these 3 elements to manipulate the data that is to be rendered.

Typically used in conjunction with the manage_location_columns filter to render new column data.

Example

This example prints out the sl_options_value contents in a formatted string, this will need further refinement for production output..

class SLPTagalong {
    function __construct() {
           add_filter('slp_column_data',
                    array($this, 'render_categories_column'),
                    90,
                    3
                    );
    }
        /**
         * Render the categories column in the view locations table.
         *
         * @param string $theData  - the option_value field data from the database
         * @param string $theField - the name of the field from the database (should be sl_option_value)
         * @param string $theLabel - the column label for this column (should be 'Categories')
         * @return type
         */
        function render_categories_column($theData,$theField,$theLabel) {
            if (
                ($theField === 'sl_option_value') &&
                ($theLabel === __('Categories'        ,SLPLUS_PREFIX))
               ) {

                // No Category selected
                //
                if ($theData != '') {
                    $theData = "
SL Option Value:
" . print_r($theData,true) . "
";
 }
 }
 return $theData;
 }
}

slp_deletelocation_starting

Type: action
Parameters:
    [0] - an array of strings that represent the integer location id to be deleted

This hook is fired when a location, or group of locations, is about to be deleted from the Store Locator Plus locations database.

slp_edit_location_left_column

Type: Filter  Default Priority: 10  Return: An HTML string for the complete left column of the edit location form.

Extends, modifies, or replaces the edit form that is presented on the Manage Locations page when “edit locations” is selected.  The form has a left and right column within a table cell.   This filter receives a single parameter which represents the HTML content of the left or right table cell, depending on which filter is being hooked.   The content can be modified accordingly before it is rendered in the browser window.

Example

// Search Functionality Hook

 //
 add_filter('slp_edit_location_right_column',
 array('SLPTagalong','extend_edit_fields'),
 90
 );
class SLPTagalong {
function extend_edit_fields($html) {
 return $html . 'New Field: <input type="text" name="slp_new_field" value="">';
 }
 }

slp_edit_location_right_column

Type: Filter
Default Priority: 10
Return: An HTML string for the complete right column of the edit location form.

  Extends, modifies, or replaces the edit form that is presented on the Manage Locations page when “edit locations” is selected. The form has a left and right column within a table cell. This filter receives a single parameter which represents the HTML content of the left or right table cell, depending on which filter is being hooked. The content can be modified accordingly before it is rendered in the browser window.

Example

// Search Functionality Hook
//
add_filter('slp_edit_location_right_column',
array('SLPTagalong','extend_edit_fields'),
90
);
class SLPTagalong {
function extend_edit_fields($html) {
return $html . 'New Field: <input type="text" name="slp_new_field" value="" />';
}
}

slp_location_page_attributes

Type: Filter Default Priority: 10 Parameters:
     [0] – mixed[] $slpNewListing – a named array with custom post type attributes Return: A valid custom post type attribute

  Modifies the store_page custom post type when it is created via the built-in SLP Admin UI getorcreate_PageID method.

Code Implementation v3.9.2

// Create a blank draft page for this location to store meta
//
$slpNewListing = array(
'ID'            => '',
'post_type'     => 'store_page',
'post_status'   => 'draft',
'post_title'    => $this->get_CurrentLocationVal('sl_store'),
'post_content'  => ''
);
$slpNewListing = apply_filters('slp_location_page_attributes',$slpNewListing);

slp_location_added

Type: Action Parameters:    [0] insert ID of most recently added record

  This action hook fires after the WordPress DB query is run to insert new location data.

Code Implementation (v3.8.19)

$wpdb->query("INSERT into ". $wpdb->prefix . "store_locator ($fields) VALUES ($sl_values);");
do_action('slp_location_added',$wpdb->insert_id());

slp_locationinfoform

Type: Filter
Parameters:
 string - the location form used on manage locations page

Use this to manipulate the location information form used to edit the location data.

slp_locations_subtabs

slp_locations_subpanels

Type: Filter
Params: 
   [0] - named array of panels, key=label, value=content

Provides a mechanism to add panels to the locations admin UI that tie into the subtabs.

Version 4.0 Implementation

        // Render the content panels
        // FILTER: slp_locations_subpanels
        //
        $contentPanels = apply_filters('slp_locations_subpanels',
                    array(
                        'manage' =>
                            $content['top_pagination']      .
                            $content['form_start']          .
                            $content['actionbar']           .
                            $content['locationstable']      .
                            $content['form_end']            .
                            $content['bottom_pagination']   ,
                        'add'   => $this->create_LocationAddEditForm(array(), true)
                    )
                );
        $display = 'block';
        foreach ($contentPanels as $label=>$content) {
            print $this->create_SubContentPanel($label,$content,$display);
            if ($display==='block') { $display = 'none'; }
        }

slp_manage_expanded_location_columns

Type: Filter
Parameters:
     [0] named array, key is field name, value is column label
Default Priority: 10

  Use this filter to add columns to the Manage Locations table in expanded view only, at the end of the expanded view but before the slp_manage_location_columns is executed.   See slp_manage_location_columns for examples.

slp_manage_location_columns

Type: Filter
Parameters:
     [0] named array, key is field name, value is column label
Default Priority: 10

  Use this filter to add columns to the Manage Locations table.   The filter is passed a single parameter which is a named array that represents the existing columns.   The key is the name of the Store Locator Plus field in the locations table.   The value is the label to render on the top of the column.

Example

This example adds the “category ID” column to the table, which has been added to the locations table during an activation hook.

class SLPTagalong {
    function __construct() {
  add_filter(
     'slp_manage_location_columns',
     array($this,'add_catid_column'),
     90
  );
}
 function add_catid_column($theColumns) {
     return array_merge(
         $theColumns,
         array(
            'category_id'   => 'Category #'
          )
       );
    }
}

slp_manage_priority_location_columns

Type: Filter
Parameters:
     [0] named array, key is field name, value is column label
Default Priority: 10

  Use this filter to add columns to the Manage Locations table in normal and expended view in a priority position, immediately after the country column output.   See slp_manage_location_columns for examples.

slp_manage_locations_action

Type: Action Parameters: none

  Processes a form action from the manage locations page.  Runs after the built-in SLP actions have run.   Replaces the defunct “slp_managelocations_action”.

Code Implementation (v3.9)

if ($_REQUEST['act']) {
     do_action('slp_manage_locations_action');
}

Example

<span style="font-size: 12px; line-height: 18px;">// Manage Locations : categorize locations in bulk // add_action('slp_managelocations_action', array($this,'categorize_locations') );</span>
/**
 * Perform the manage locations action for bulk categorization.
 */
 function categorize_locations() {
 foreach ($_REQUEST['sl_id'] as $location) {
 $this->setLocationCategory($location, $_REQUEST['tax_input']['stores']);
 }
 }

slp_manage_locations_actionbuttons

Type: Filter
Default Priority: 10
Parameters:
     [0] - the existing action buttons HTML
     [1] - the current location record values in a named array
Return: An the complete action buttons HTML string

Extends, modifies, or replaces the action buttons on a per-location basis.

Code Implementation (v3.9)

$actionButtonsHTML = apply_filters('slp_manage_locations_actionbuttons',$actionButtonsHTML, $sl_value);

Example

add_filter(*'slp_manage_locations_actionbuttons',array($this,'add_manage_locations_actionbuttons),15,2);

/**
* Add a location action button.
*
* @param string $theHTML - the HTML of the original buttons in place
* @param array $locationValues
* @return string - the augmented HTML
*/
function add_manage_locations_actionbuttons($theHTML,$locationValues) {
if (!$this->setPlugin())            { return 'a' . $theHTML;  }
if (!isset($locationValues['sl_id'])) { return 'c' . $theHTML; }
if ($locationValues['sl_id'] < 0)   { return 'b' . $theHTML;  }

// Set the URL
//
$shortSPurl = preg_replace('/^.*?store_page=/','',$locationValues['sl_pages_url']);
$locationValues['sl_pages_url'] = "<a href="$locationValues[sl_pages_url]" target="cybersprocket">$shortSPurl</a>";

$pageClass = (($locationValues['sl_linked_postid']>0)?'haspage_icon' : 'createpage_icon');
$pageURL  = preg_replace(
'/&createpage=/'.(isset($_GET['createpage'])?$_GET['createpage']:''),
'',
$_SERVER['REQUEST_URI']
).
'&act=createpage'.
'&sl_id='.$locationValues['sl_id'].
'&slp_pageid='.$locationValues['sl_linked_postid'].
'#a'.$locationValues['sl_id']
;
return $theHTML .
""
;
}