Skip to content

Commit

Permalink
New custom slug feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sfgarza committed Apr 2, 2020
1 parent 3d16a9a commit 570d45f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
32 changes: 32 additions & 0 deletions includes/class-link-in-bio-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ function register( $wp_customize ) {
'sanitize_callback' => 'esc_url_raw',
)
);

// Landing Page custom slug setting.
$wp_customize->add_setting(
'linkinbio_landing_page_custom_slug',
array(
'default' => '',
'type' => 'option',
'transport' => 'refresh',
'sanitize_callback' => 'sanitize_title_with_dashes',
)
);

// Landing Page Image Control.
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'linkinbio_page_image', array(
Expand All @@ -107,6 +118,9 @@ function register( $wp_customize ) {
'type' => 'text',
'section' => 'linkinbio_landing_page_section',
'settings' => 'linkinbio_landing_page_image_link',
'input_attrs' => array(
'placeholder' => __( 'https://example.com', 'linkinbio' ),
)
)
);

Expand All @@ -119,6 +133,24 @@ function register( $wp_customize ) {
'type' => 'text',
'section' => 'linkinbio_landing_page_section',
'settings' => 'linkinbio_landing_page_caption',
'input_attrs' => array(
'placeholder' => __( 'Tap photo for details', 'linkinbio' ),
)
)
);

// Landing Page Custom Slug Controls.
$wp_customize->add_control(
'linkinbio_page_custom_slug',
array(
'label' => __( 'Custom Slug', 'linkinbio' ),
'description' => sprintf( __( 'The default landing page url is %s. You can customize this url to anything you like.', 'linkinbio'), site_url('/links/') ),
'type' => 'text',
'section' => 'linkinbio_landing_page_section',
'settings' => 'linkinbio_landing_page_custom_slug',
'input_attrs' => array(
'placeholder' => __( 'i.e. instagram', 'linkinbio' ),
)
)
);

Expand Down
19 changes: 19 additions & 0 deletions link-in-bio-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,19 @@ private function init() {

add_action( 'init', array( $this, 'create_post_type' ) );
add_action( 'init', array( $this, 'register_post_meta' ) );
add_action( 'init', array( $this, 'add_rewrites' ) );
add_filter( 'template_include', array($this, 'include_template') );
add_filter( 'pre_get_posts', array( $this, 'posts_per_page' ) );

// No need to define metaboxes/save post function unless it's accessible.
if ( is_admin() ) {
add_filter( 'manage_edit-link-in-bio_columns', array( $this, 'columns_filter' ) );
add_action( 'manage_link-in-bio_posts_custom_column', array( $this, 'columns_data' ) );
add_action( 'add_meta_boxes', array( $this, 'register_meta_boxes' ) );
add_action( 'save_post_link-in-bio', array( $this, 'metabox_save' ), 1, 2 );
}

add_action('update_option_linkinbio_landing_page_custom_slug', array( $this, 'update_custom_slug'));
}

/**
Expand Down Expand Up @@ -209,6 +213,21 @@ public function register_post_meta(){
) );
}

public function add_rewrites(){
$slug = trim( get_option('linkinbio_landing_page_custom_slug') );
if( ! empty( $slug ) ){
add_rewrite_rule( sanitize_title_with_dashes( $slug ) . '?', 'index.php?post_type=link-in-bio', 'top' );

if( true === (bool)get_option( 'linkinbio_flush_rewrites' )){
flush_rewrite_rules();
}
}
}

public function update_custom_slug(){
update_option('linkinbio_flush_rewrites', true );
}

/**
* Register meta boxes.
*
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ The landing page can be found at https://yourdomain.com/links/. Anchor links on

=== Features ===
* Create a landing page that mirrors your instagram feed in order to link to outside content.
* Customize landing page link.
* Mobile first & Responsive layout.
* Infinite Scrolling built in.
* Easily customize landing page within the customizer.
* Built in hooks let developers customize the plugin even further.

== Changelog ==

-1.1.0
-- New customizer option lets you set a custom slug for the landing page.

- 1.0.0
-- First Release

Expand Down

0 comments on commit 570d45f

Please sign in to comment.