Пример #1
0
/**
 * Activates the plugin from a WordPress point of view. Note that for VersionPress
 * to become fully active, the Initializer needs to be run.
 *
 * @see Initializer
 */
function vp_activate()
{
    WpConfigSplitter::split(WordPressMissingFunctions::getWpConfigPath());
    set_transient('vp_just_activated', '1', 10);
}
Пример #2
0
    <div class="welcome-panel-content">

        <h3>VersionPress Activation</h3>


        <p class="about-description">Setting things up for you. It may take a while, please be patient.</p>

        <div class="initialization-progress">
            <?php 
// Set the env name in wp-config.php
if (isset($_GET['envname']) && \VersionPress\Utils\WorkflowUtils::isCloneNameValid($_GET['envname'])) {
    $envName = $_GET['envname'];
} else {
    $envName = 'default';
}
$wpConfigPath = \VersionPress\Utils\WordPressMissingFunctions::getWpConfigPath();
$wpConfigEditor = new \VersionPress\Utils\WpConfigEditor($wpConfigPath, false);
$wpConfigEditor->updateConfigConstant('VP_ENVIRONMENT', $envName);
_vp_show_progress_message("Environment set to '{$envName}'", true);
// Do the initialization
global $versionPressContainer;
/** @var Initializer $initializer */
$initializer = $versionPressContainer->resolve(VersionPressServices::INITIALIZER);
$initializer->onProgressChanged[] = '_vp_show_progress_message';
$initializer->initializeVersionPress();
$successfullyInitialized = VersionPress::isActive();
?>
        </div>

        <?php 
if ($successfullyInitialized) {
Пример #3
0
 private function createCommonConfig()
 {
     $configPath = WordPressMissingFunctions::getWpConfigPath();
     WpConfigSplitter::split($configPath);
 }
Пример #4
0
 /**
  * Sets or updates constant or variable in wp-config.php
  *
  * ## OPTIONS
  *
  * <constant>
  * : Name of constant or variable that will be changed.
  *
  * <value>
  * : Desired value. Supported types are: string, int, float and bool.
  *
  * [--plain]
  * : The value will be used as is - without type detection, quoting etc.
  *
  * [--variable]
  * : Will set a variable instead of constant. Useful for $table_prefix.
  *
  * [--common]
  * : The constant / variable will be set in wp-config.common.php.
  *
  * @subcommand update-config
  *
  *
  * @when before_wp_load
  */
 public function updateConfig($args = [], $assoc_args = [])
 {
     require_once __DIR__ . '/VPCommandUtils.php';
     require_once __DIR__ . '/../Initialization/WpConfigSplitter.php';
     require_once __DIR__ . '/../Utils/WpConfigEditor.php';
     require_once __DIR__ . '/../Utils/WordPressMissingFunctions.php';
     $wpConfigPath = WordPressMissingFunctions::getWpConfigPath();
     $updateCommonConfig = isset($assoc_args['common']);
     if ($updateCommonConfig) {
         $wpConfigPath = dirname($wpConfigPath) . '/' . WpConfigSplitter::COMMON_CONFIG_NAME;
     }
     if ($wpConfigPath === false) {
         WP_CLI::error('Config file does not exist. Please run `wp core config` first.');
     }
     $constantOrVariableName = $args[0];
     $isVariable = isset($assoc_args['variable']);
     $usePlainValue = isset($assoc_args['plain']);
     $value = $usePlainValue ? $args[1] : VPCommandUtils::fixTypeOfValue($args[1]);
     $wpConfigEditor = new WpConfigEditor($wpConfigPath, $updateCommonConfig);
     try {
         if ($isVariable) {
             $wpConfigEditor->updateConfigVariable($constantOrVariableName, $value, $usePlainValue);
         } else {
             $wpConfigEditor->updateConfigConstant($constantOrVariableName, $value, $usePlainValue);
         }
     } catch (\Exception $e) {
         WP_CLI::error('Cannot find place for defining the ' . ($isVariable ? 'variable' : 'constant') . '. Config was probably edited manually.');
     }
 }
 private function createReplaceCallback($idProvider)
 {
     $shortcodesInfo = $this->shortcodesInfo;
     return function ($m) use($shortcodesInfo, $idProvider) {
         // allow [[foo]] syntax for escaping a tag - code adopted from WP function `do_shortcode_tag`
         if ($m[1] == '[' && $m[6] == ']') {
             return substr($m[0], 1, -1);
         }
         $shortcodeTag = $m[2];
         $shortcodeInfo = $shortcodesInfo->getShortcodeInfo($shortcodeTag);
         $attributes = shortcode_parse_atts($m[3]);
         foreach ($attributes as $attribute => $value) {
             if (isset($shortcodeInfo[$attribute])) {
                 $ids = explode(',', $value);
                 $entityName = $shortcodeInfo[$attribute];
                 $attributes[$attribute] = join(',', array_map(function ($id) use($entityName, $idProvider) {
                     return $idProvider($entityName, $id);
                 }, $ids));
             }
         }
         return WordPressMissingFunctions::renderShortcode($shortcodeTag, $attributes);
     };
 }
 private function createPostWithShortcode()
 {
     $author = EntityUtils::prepareUser();
     self::$authorVpId = $author['vp_id'];
     $this->userStorage->save($author);
     $post = EntityUtils::preparePost(null, self::$authorVpId);
     self::$vpId = $post['vp_id'];
     $post['post_content'] = WordPressMissingFunctions::renderShortcode('gallery', ['id' => self::$vpId]);
     $this->storage->save($post);
     return [['vp_id' => self::$authorVpId, 'parent' => self::$authorVpId], ['vp_id' => self::$vpId, 'parent' => self::$vpId]];
 }