slug = $args['slug'] ?? '';
$this->label = $args['label'] ?? '';
$this->description = $args['description'] ?? '';
$this->options = $args['options'] ?? [];
$this->current_base = \SureCart::settings()->permalinks()->getBase( "{$this->slug}_page" );
$this->sample_preview_text = $args['sample_preview_text'] ?? 'sample-product';
}
/**
* Boostrap settings.
*
* @return void
*/
public function bootstrap() {
add_action( 'admin_init', [ $this, 'settingsInit' ] );
}
/**
* Add translations.
*
* @return void
*/
public function addTranslations() {
$translations['surecart.settings.permalinks.product'] = [
'slug' => 'product',
'label' => __( 'SureCart Product Permalinks', 'surecart' ),
/* translators: %s: Home URL */
'description' => sprintf( __( 'If you like, you may enter custom structures for your product page URLs here. For example, using products would make your product buy links like %sproducts/sample-product/.', 'surecart' ), esc_url( home_url( '/' ) ) ),
'options' => [
[
'value' => 'products',
'label' => __( 'Default', 'surecart' ),
],
[
'value' => 'shop',
'label' => __( 'Shop', 'surecart' ),
],
],
];
$translations['surecart.settings.permalinks.buy'] = [
'slug' => 'buy',
'label' => __( 'SureCart Instant Checkout Permalinks', 'surecart' ),
/* translators: %s: Home URL */
'description' => sprintf( __( 'If you like, you may enter custom structures for your instant checkout URLs here. For example, using buy would make your product buy links like %sbuy/sample-product/.', 'surecart' ), esc_url( home_url( '/' ) ) ),
'options' => [
[
'value' => 'buy',
'label' => __( 'Default', 'surecart' ),
],
[
'value' => 'purchase',
'label' => __( 'Purchase', 'surecart' ),
],
[
'value' => 'shop/%sc_collection%',
'label' => __( 'Shop base with collection', 'surecart' ),
],
],
];
$translations['surecart.settings.permalinks.buy'] = [
'slug' => 'buy',
'label' => __( 'SureCart Instant Checkout Permalinks', 'surecart' ),
/* translators: %s: Home URL */
'description' => sprintf( __( 'If you like, you may enter custom structures for your instant checkout URLs here. For example, using buy would make your product buy links like %sbuy/sample-product/.', 'surecart' ), esc_url( home_url( '/' ) ) ),
'options' => [
[
'value' => 'buy',
'label' => __( 'Default', 'surecart' ),
],
[
'value' => 'purchase',
'label' => __( 'Purchase', 'surecart' ),
],
],
];
$translations['surecart.settings.permalinks.collection'] = [
'slug' => 'collection',
'label' => __( 'SureCart Product Collection Permalinks', 'surecart' ),
/* translators: %s: Home URL */
'description' => sprintf( __( 'If you like, you may enter custom structures for your product page URLs here. For example, using collections would make your product collection links like %scollections/sample-collection/.', 'surecart' ), esc_url( home_url( '/' ) ) ),
'options' => [
[
'value' => 'collections',
'label' => __( 'Default', 'surecart' ),
],
[
'value' => 'product-collections',
'label' => __( 'Product Collections', 'surecart' ),
],
],
'sample_preview_text' => 'sample-collection',
];
$translations['surecart.settings.permalinks.upsell'] = [
'slug' => 'upsell',
'label' => __( 'SureCart Upsell Permalinks', 'surecart' ),
/* translators: %s: Home URL */
'description' => sprintf( __( 'If you like, you may enter custom structures for your upsell URLs here. For example, using offers would make your upsell\'s links like %soffers/upsell-id/.', 'surecart' ), esc_url( home_url( '/' ) ) ),
'options' => [
[
'value' => 'offer',
'label' => __( 'Default', 'surecart' ),
],
[
'value' => 'special-offer',
'label' => __( 'Special Offer', 'surecart' ),
],
],
];
}
/**
* Initialize settings.
*/
public function settingsInit() {
$this->addTranslations();
$this->addSettingsSection();
$this->maybeSaveSettings();
}
/**
* Add sections to permalinks page.
*/
public function addSettingsSection() {
add_settings_section( "surecart-$this->slug-permalink", $this->label, [ $this, 'settings' ], 'permalink' );
}
/**
* Display the settings.
*/
public function settings() {
echo wp_kses_post( wpautop( $this->description ) );
$values = array_values(
array_map(
function ( $permalink ) {
return trailingslashit( $permalink['value'] );
},
$this->options
)
);
?>
sample_preview_text ); ?> |
|