migrate_legacy_keys(); $this->set_default_options(); } /** * Run on plugin deactivation. * * @since 1.0.0 */ public function deactivate() { } /** * Set default plugin options. * * @since 1.0.0 */ private function set_default_options() { $defaults = array( 'global_restrictions' => array( 'enabled' => false, 'visibility' => 'all', 'allowed_roles' => array(), 'redirect_url' => '', 'exclude_admins' => true, ), 'post_type_restrictions' => array(), 'redirect_settings' => array( 'default_url' => get_option( 'siteurl' ) . '/wp-login.php', 'message' => __( 'You do not have permission to view this content.', 'lumo-access-studio' ), 'return_after_login' => true, ), 'advanced' => array( 'hide_restricted_posts' => false, 'show_excerpt' => false, ), ); add_option( 'lumocr_settings', $defaults ); add_option( 'lumocr_version', LUMOCR_VERSION ); add_option( 'lumocr_installed_date', current_time( 'mysql' ) ); } /** * Copy settings and post meta from the previous prefix when present. * * @since 2.10.2 */ private function migrate_legacy_keys() { if ( get_option( 'lumocr_prefix_migrated' ) ) { return; } $options = array( 'ncr_settings' => 'lumocr_settings', 'ncr_version' => 'lumocr_version', 'ncr_installed_date' => 'lumocr_installed_date', 'ncr_welcome_shown' => 'lumocr_welcome_shown', ); foreach ( $options as $old_key => $new_key ) { $legacy = get_option( $old_key, null ); if ( null === $legacy || false !== get_option( $new_key, false ) ) { continue; } update_option( $new_key, $legacy ); } $meta_keys = array( '_ncr_visibility' => '_lumocr_visibility', '_ncr_allowed_roles' => '_lumocr_allowed_roles', '_ncr_allowed_users' => '_lumocr_allowed_users', '_ncr_redirect_url' => '_lumocr_redirect_url', ); foreach ( $meta_keys as $old_key => $new_key ) { $post_ids = get_posts( array( 'post_type' => array_values( get_post_types() ), 'post_status' => array_values( get_post_stati() ), 'posts_per_page' => -1, 'fields' => 'ids', 'meta_key' => $old_key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- One-time migration of this plugin's legacy metadata. ) ); foreach ( $post_ids as $post_id ) { if ( ! metadata_exists( 'post', $post_id, $new_key ) ) { add_post_meta( $post_id, $new_key, get_post_meta( $post_id, $old_key, true ), true ); } } } update_option( 'lumocr_prefix_migrated', LUMOCR_VERSION, false ); } }