Skip to content

Commit

Permalink
fix: flush permalinks only after registering CPTs
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Oct 15, 2020
1 parent bb32751 commit 39d2912
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
9 changes: 9 additions & 0 deletions includes/class-newspack-listings-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function __construct() {
add_action( 'wp_enqueue_scripts', [ __CLASS__, 'custom_styles' ] );
add_filter( 'single_template', [ __CLASS__, 'set_default_template' ] );
add_action( 'save_post', [ __CLASS__, 'sync_post_meta' ], 10, 2 );
register_activation_hook( NEWSPACK_LISTINGS_FILE, [ __CLASS__, 'activation_hook' ] );
}

/**
Expand Down Expand Up @@ -590,6 +591,14 @@ function( $classes ) {

return $template;
}

/**
* Flush permalinks on plugin activation, ensuring that post types and taxonomies are registered first.
*/
public static function activation_hook() {
self::register_post_types();
flush_rewrite_rules(); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules
}
}

Newspack_Listings_Core::instance();
7 changes: 0 additions & 7 deletions includes/newspack-listings-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@

namespace Newspack_Listings\Utils;

/**
* On plugin activation, flush permalinks.
*/
function activate() {
flush_rewrite_rules(); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules
}

/**
* Sanitize an array of text values.
*
Expand Down
8 changes: 3 additions & 5 deletions newspack-listings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

// Define NEWSPACK_LISTINGS_PLUGIN_FILE.
if ( ! defined( 'NEWSPACK_LISTINGS_PLUGIN_FILE' ) ) {
define( 'NEWSPACK_LISTINGS_PLUGIN_FILE', plugin_dir_path( __FILE__ ) );
define( 'NEWSPACK_LISTINGS_URL', plugin_dir_url( __FILE__ ) );
define( 'NEWSPACK_LISTINGS_FILE', __FILE__ );
define( 'NEWSPACK_LISTINGS_PLUGIN_FILE', plugin_dir_path( NEWSPACK_LISTINGS_FILE ) );
define( 'NEWSPACK_LISTINGS_URL', plugin_dir_url( NEWSPACK_LISTINGS_FILE ) );
define( 'NEWSPACK_LISTINGS_VERSION', '0.0.1' );
}

Expand All @@ -28,6 +29,3 @@
require_once NEWSPACK_LISTINGS_PLUGIN_FILE . '/includes/class-newspack-listings-core.php';
require_once NEWSPACK_LISTINGS_PLUGIN_FILE . '/includes/class-newspack-listings-api.php';
require_once NEWSPACK_LISTINGS_PLUGIN_FILE . '/includes/class-newspack-listings-blocks.php';

// On plugin activation/deactivation.
register_activation_hook( __FILE__, '\Newspack_Listings\Utils\activate' );

0 comments on commit 39d2912

Please sign in to comment.