First, you have to initiate the class, something like:
add_action( 'init', function() {
$CsvImporter = new CsvImporter;
} );
Also, you are using extract()
wrong; extract()
won’t build $attributes
as an array. Anyway, extract()
is not recommended any more and you should avoid using it. Also, note taht if ($attributes['mods'])
should be if ($attributes['type'] == 'mods')
as mods
is not a valid index in $attributes
array but the value of type
index. Additionally you need to return
a value int he shortcode callback.
I’ve tested this shortcode [priceguide file="test.csv" type="mods"]
and it is working with the code bellow (note also that I’ve change ’
character in the shortcode, not sure if ’
is a valid value delimiter).
add_action( 'init', function() {
$CsvImporter = new CsvImporter;
} );
class CsvImporter {
private $parse_header;
private $header;
private $delimiter;
private $length;
function __construct($parse_header=false, $delimiter="\t", $length=8000) {
add_shortcode( 'priceguide', array( $this, 'shortcode' ) );
$this->parse_header = $parse_header;
$this->delimiter = $delimiter;
$this->length = $length;
}
public function shortcode($atts) {
$attributes = shortcode_atts( array(
'file' => '',
'type' => '',
), $atts );
if ( $attributes['type'] == "mods" ) {
return $this->OpenMods($attributes['file']);
}
}
function OpenMods($file) {
return "test";
}
}
PD: While developing you should have WP_DEBUG
set to on and display errors set to on also; this way you would had seen a warning message saying that $attributes['mods']
is not set.