%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /platform/misc/
Upload File :
Create Path :
Current File : //platform/misc/wp-cli-helper.php

<?php
if (!defined('WP_CLI') || !WP_CLI) {
    return;
}

require_once __DIR__ . '/wp-cli-helper-prefix.php';

$wpCliTimeout = max( (int) getenv('WP_CLI_COMMAND_TIMEOUT'), 0 ) ?: 600;
ini_set('max_execution_time', $wpCliTimeout);

define('WPAAS_MHP_CLI_HELPER_BOUNDARY_START', '////////WPAAS_MHP_START////////');
define('WPAAS_MHP_CLI_HELPER_BOUNDARY_END', '////////WPAAS_MHP_END////////');

/**
 * wp-cli cmds to add boundary to
 */
$boundaryWpCliCmds = [
    'cache',
    'cli',
    'config',
    'core',
    'cron',
    'db',
    'godaddy',
    'nux',
    'option',
    'plugin',
    'post',
    'rewrite',
    'search',
    'theme',
    'user',
    'wpaas',
];

// Get error key
function wpaas_mhp_cli_helper_get_error_key($errno, $errstr)
{
    // Maybe generalize the unserialize offset notices.
    if ((E_NOTICE === $errno || E_WARNING === $errno) && false !== strpos($errstr, 'unserialize(): Error at offset')) {
        $errstr = 'unserialize(): Error at offset X of Y bytes (generalized)';
    }

    return "{$errno}-{$errstr}";
}

function wpaas_mhp_cli_helper_error_handler($errno, $errstr, $errfile = null, $errline = null) {
    static $errorCounter = [];
    static $errorTypeCounter = [];

    $errorKey = wpaas_mhp_cli_helper_get_error_key($errno, $errstr);

    if (!isset($errorCounter[$errorKey])) {
        $errorCounter[$errorKey] = 0;
    }

    if (!isset($errorTypeCounter[$errno])) {
        $errorTypeCounter[$errno] = 0;
    }

    // Swallow the error if there are large numbers of the same one.
    if (20 < $errorCounter[$errorKey]) {
        return;
    }

    // Swallow the error if there are large numbers of the same type.
    if (100 < $errorTypeCounter[$errno]) {
        return;
    }

    $errorCounter[$errorKey]++;
    $errorTypeCounter[$errno]++;

    $formattedError = wpaas_mhp_cli_helper_format_error($errno, $errstr, $errfile, $errline);

    fwrite(STDERR, $formattedError);

    $isFatal = $errno & (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
    if ($isFatal) {
        exit(1);
    }
}

set_error_handler('wpaas_mhp_cli_helper_error_handler');

foreach ($boundaryWpCliCmds as $cmd) {
    WP_CLI::add_hook('before_invoke:' . $cmd, static function () {
        fwrite(STDOUT, WPAAS_MHP_CLI_HELPER_BOUNDARY_START . PHP_EOL);
    });
    WP_CLI::add_hook('after_invoke:' . $cmd, static function () {
        fwrite(STDOUT, PHP_EOL . WPAAS_MHP_CLI_HELPER_BOUNDARY_END);
    });
}

function wpaas_mhp_cli_helper_format_error($errno, $errstr, $errfile = null, $errline = null)
{
    $errType = wpaas_mhp_cli_helper_error_type($errno);

    return "{$errType}({$errno}): {$errstr} {$errfile}#{$errline}" . PHP_EOL;
}

function wpaas_mhp_cli_helper_error_type($errno)
{
    switch ($errno) {
        case E_ERROR:
            return 'Error';
        case E_WARNING:
            return 'Warning';
        case E_PARSE:
            return 'Parse';
        case E_NOTICE:
            return 'Notice';
        case E_CORE_ERROR:
            return 'Core Error';
        case E_CORE_WARNING:
            return 'Core Warning';
        case E_COMPILE_ERROR:
            return 'Compile Error';
        case E_COMPILE_WARNING:
            return 'Compile Warning';
        case E_DEPRECATED:
            return 'Deprecated';
        case E_USER_ERROR:
            return 'User Error';
        case E_USER_WARNING:
            return 'User Warning';
        case E_USER_NOTICE:
            return 'User Notice';
        case E_USER_DEPRECATED:
            return 'User Deprecated';
        case E_STRICT:
            return 'Strict';
        default:
            return 'Unknown';
    }
}

/**
 * Backup Prime Mover constants file (WPVTWO-6946).
 *
 * The Prime Mover plugin creates wp-content/mu-plugins/000-prime-mover-constants.php
 * with hardcoded paths that cause breakage during domain modifications.
 * This function backs up the file before domain changes.
 *
 * @return array Status information with keys: success, message, backup_filename (optional)
 */
function wpaas_mhp_cli_helper_backup_prime_mover_constants()
{
    $filename = '000-prime-mover-constants.php';
    $file = ABSPATH . 'wp-content/mu-plugins/' . $filename;
    $timestamp = time();
    $backup_filename = $filename . '.' . $timestamp . '.bak';
    $backup_file = ABSPATH . 'wp-content/mu-plugins/' . $backup_filename;

    if (file_exists($file)) {
        if (@rename($file, $backup_file)) {
            return [
                'success' => true,
                'message' => "Backed up $filename to $backup_filename",
                'backup_filename' => $backup_filename,
            ];
        } else {
            $error = error_get_last();
            $errorMessage = (is_array($error) && isset($error['message'])) ? $error['message'] : 'Unknown error';

            return [
                'success' => false,
                'message' => "Failed to backup $filename",
                'error' => $errorMessage,
            ];
        }
    }

    return [
        'success' => true,
        'message' => "File $filename does not exist, no action needed",
    ];
}

/**
 * Restore Prime Mover constants file from backup (WPVTWO-6946).
 *
 * Restores the Prime Mover constants file from its backup after domain modifications.
 *
 * @param string $backup_filename Filename only (no path) of the backup file to restore (e.g., 000-prime-mover-constants.php.1234567890.bak)
 * @return array Status information with keys: success, message
 */
function wpaas_mhp_cli_helper_restore_prime_mover_constants($backup_filename)
{
    if (empty($backup_filename)) {
        return [
            'success' => false,
            'message' => 'No backup filename specified',
        ];
    }

    // Sanitize: ensure it only contains the filename, no path separators
    if (strpos($backup_filename, '/') !== false || strpos($backup_filename, '\\') !== false || strpos($backup_filename, '..') !== false) {
        return [
            'success' => false,
            'message' => 'Invalid backup filename: must not contain path separators',
        ];
    }

    // Validate filename format: should be 000-prime-mover-constants.php.{timestamp}.bak
    if (!preg_match('/^000-prime-mover-constants\.php\.\d+\.bak$/', $backup_filename)) {
        return [
            'success' => false,
            'message' => 'Invalid backup filename format',
        ];
    }

    $original_filename = '000-prime-mover-constants.php';
    $original_file = ABSPATH . 'wp-content/mu-plugins/' . $original_filename;
    $backup_file = ABSPATH . 'wp-content/mu-plugins/' . $backup_filename;

    if (!file_exists($backup_file)) {
        return [
            'success' => false,
            'message' => "Backup file $backup_filename does not exist",
        ];
    }

    if (@rename($backup_file, $original_file)) {
        return [
            'success' => true,
            'message' => "Restored $original_filename from $backup_filename",
        ];
    } else {
        $error = error_get_last();
        $errorMessage = (is_array($error) && isset($error['message'])) ? $error['message'] : 'Unknown error';

        return [
            'success' => false,
            'message' => "Failed to restore $original_filename from $backup_filename",
            'error' => $errorMessage,
        ];
    }
}

Zerion Mini Shell 1.0
Sarah Provancher – Jefferson County Republican Party Skip to content
  • Home
  • About
    • News
  • Elected Officials
  • Monthly Meetings & Volunteer Opportunities
  • Voting Info 2026
  • Events
  • Gallery
  • Contact
  • Donate

SarahP

10 items

  • Election Night Victory Party! Nov. 3, 6-9pm

    All are Welcome! Free to Attend!

    Continue reading
  • Non-Partisan GOP Endorsed Candidates

    Continue reading
  • Jefferson County Republican Party Condemns Morgan McGarvey’s Repeated Failures to Denounce Socialism

      For the second time in less than a year, Morgan McGarvey voted against a straightforward resolution denouncing an ideology that has consistently resulted in oppression, economic devastation, and the erosion of individual liberties. By voting against HR 1490, McGarvey totally ignores the historic failures of socialist regimes, including the Soviet Union, Venezuela, and Cuba,

    Continue reading
  • Learn More About Lincoln Day Dinner Guest Speaker, Alina Fernández

    Continue reading
  • Congratulations to Jeff. Cty’s Republican Primary Election Winners

    Continue reading
  • Primary Election Voting Information

    Important Links to Vote in This Year’s Primary Where Can I Find a List of Republican Candidates in Jefferson County on This Year’s Ballot? Republican Candidates in 2026 Elections – Jefferson County Republican Party Where is My In-Person Voting Location? (May 19, 2026) Where Do I Vote? Where Can I Get an Absentee Ballot to

    Continue reading
  • Louisville GOP Hosts First Statewide Kentucky U.S. Senate Debate

    JCRP Hosts First Statewide Republican U.S. Senate Debate  The Jefferson County Republican Party (JCRP) hosted the first statewide Kentucky Republican U.S. Senate Debate on Monday, March 16 at 7pm. Candidates Andy Barr, Daniel Cameron and Nate Morris participated. The debate was moderated by WDRB Anchors Lindsey Allen and Gil Corsey, as well as WLEX Political

    Continue reading
  • Louisville Republicans are closer than ever to gaining a majority on Louisville Metro Council

    Louisville Republicans hope to gain Metro Council majority for the first time Louisville Public Media | By Roberto Roldan Published January 22, 2026 at 6:00 AM EST Louisville Republicans are hoping to flip three more seats on Metro Council in this year’s elections. If successful, it would put Republicans squarely in the majority on the legislative body

    Continue reading
  • Louisville GOP Honors Sen. Mitch McConnell

    JCRP was pleased to recognize the more than 50 years of service of Sen. Mitch McConnell to Louisville and the Commonwealth of Kentucky, as well as his service as Chairman of Jefferson County Republican Party in 1973-74. The honorary event took place at the Sons of the American Revolution HQ in early December in downtown

    Continue reading
  • Rep. Brett Guthrie to Speak at JCRP Lincoln Day Dinner

    Second Congressional District U.S. Rep Brett Guthrie has been confirmed as a speaker for the JCRP Lincoln Day Dinner on Wed., August 20. Rep. Guthrie will join Keynote Speaker, Riley Gaines, U.S. Senate Candidates from Kentucky, Rep. Andy Barr, Daniel Cameron and Nate Morris, as well as local Jefferson County leaders. Rep. Guthrie is Chairman

    Continue reading
Subscribe to Our Email List
(502) 584-7111
louisville_gop@icloud.com
© 2023 - 2026 • by ThemeFusion • All Rights Reserved • Powered by WordPress
Page load link
Go to Top