# force-refresh/2.10.1/includes/actions/admin/inc.release-notes.php

Force Refresh, version 2.10.1. 138 lines.

- Page: https://pluginprobe.com/plugins/force-refresh/2.10.1/code/includes/actions/admin/inc.release-notes.php
- Raw: https://pluginprobe.com/plugins/force-refresh/2.10.1/raw/includes/actions/admin/inc.release-notes.php
- Modified: 2023-12-09T13:27:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/force-refresh/2.10.1/code/includes/actions/admin/inc.release-notes.php#L10-L20`.

```php
<?php
/**
 * Our action that enqueues all required admin scripts.
 *
 * @package ForceRefresh
 */

namespace JordanLeven\Plugins\ForceRefresh;

require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';

/**
 * Function to get the contents of the plugin's README file.
 *
 * @return  mixed   String if file is located.
 */
function get_plugin_readme() {
    $readme_file_location = dirname( get_main_plugin_file() ) . '/README.txt';

    if ( ! file_exists( $readme_file_location ) ) {
        return null;
    }

    $filesystem = new \WP_Filesystem_Direct( true );
    return $filesystem->get_contents( $readme_file_location );
}

/**
 * Function to get the parsed array of release notes.
 *
 * @param string $readme The readme contents.
 *
 * @return array An array of release notes.
 */
function get_release_notes_from_plugin_readme( string $readme ): array {
    // Remove the "== Changelog ==" string and everything before.
    $release_notes                = preg_replace( '/.* Changelog \=\=/s', '', $readme );
    $release_notes_split          = explode( "\n", $release_notes );
    $release_notes_split_filtered = array_filter( $release_notes_split );

    return $release_notes_split_filtered;
}

/**
 * Function to modify the current version index and notes based on a specific release note.
 *
 * @param string $current_plugin_version The currently-loaded version of Force Refresh.
 * @param int    $current_version_i      The index of the current release version.
 * @param array  $notes_formatted        The key/value pairs of release notes.
 * @param string $note                   The note to parse.
 *
 * @return  void
 */
function assign_release_note_based_on_role( string $current_plugin_version, &$current_version_i, &$notes_formatted, $note ): void {
    switch ( true ) {
        // If the line is a version number.
        case preg_match( '/#### [0-9].*/', $note ):
            $version_number                     = str_replace( array( '#', ' ' ), '', $note );
            $notes_formatted[ $version_number ] = array(
                'date'             => null,
                'isCurrentVersion' => $current_plugin_version === $version_number,
                'notes'            => array(),
            );

            $current_version_i = $version_number;
            break;

        // Release dates.
        case preg_match( '/^\_/', $note ):
            $release_date_formatted = str_replace( array( '_', '' ), '', $note );

            $notes_formatted[ $current_version_i ]['date'] = $release_date_formatted;
            break;

        // Release headers.
        case preg_match( '/^##### .*/', $note ):
            $release_header = str_replace( array( '#', '*' ), '', $note );

            array_push(
                $notes_formatted[ $current_version_i ]['notes'],
                array(
                    'sectionHeader' => $release_header,
                    'sectionNotes'  => array(),
                ),
            );
            break;

        // If the line is a release note.
        default:
            $release_note         = str_replace( array( '#', '*' ), '', $note );
            $all_notes            = &$notes_formatted[ $current_version_i ]['notes'];
            $release_notes_length = count( $all_notes );

            array_push(
                $all_notes[ $release_notes_length - 1 ]['sectionNotes'],
                trim( $release_note ),
            );
            break;
    }
}

/**
 * Function to get release notes as formatted JSON.
 *
 * @param string $current_plugin_version The currently-loaded version of Force Refresh.
 *
 * @return  array  An array of release notes.
 */
function get_release_notes_json( string $current_plugin_version ) {
    $readme_contents = get_plugin_readme();
    if ( ! $readme_contents ) {
        return null;
    }

    $release_notes = get_release_notes_from_plugin_readme( $readme_contents );

    $notes_formatted       = array();
    $current_version_index = null;

    foreach ( $release_notes as $k => $v ) {
        assign_release_note_based_on_role( $current_plugin_version, $current_version_index, $notes_formatted, $v );
    }

    return $notes_formatted;
}

/**
 * Function to get the release notes.
 *
 * @param string $current_plugin_version The currently-loaded version of Force Refresh.
 *
 * @return array Array of release notes.
 */
function get_release_notes( string $current_plugin_version ) {
    return get_release_notes_json( $current_plugin_version );
}

```
