/**
  * Retrieves data submitted on the screen, and prepares it for the appropriate context type
  *
  * @action load-theme-editor.php
  * @action load-plugin-editor.php
  * @return void
  */
 public static function get_edition_data()
 {
     if ('POST' !== $_SERVER['REQUEST_METHOD'] || 'update' !== wp_stream_filter_input(INPUT_POST, 'action')) {
         return;
     }
     if ($slug = wp_stream_filter_input(INPUT_POST, 'theme')) {
         self::$edited_file = self::get_theme_data($slug);
     }
     if ($slug = wp_stream_filter_input(INPUT_POST, 'plugin')) {
         self::$edited_file = self::get_plugin_data($slug);
     }
 }
Beispiel #2
0
 /**
  * @action load-theme-editor.php
  */
 public static function get_edition_data()
 {
     if ('POST' !== $_SERVER['REQUEST_METHOD']) {
         return;
     }
     if ('update' !== wp_stream_filter_input(INPUT_POST, 'action')) {
         return;
     }
     $theme_slug = wp_stream_filter_input(INPUT_POST, 'theme') ? wp_stream_filter_input(INPUT_POST, 'theme') : get_stylesheet();
     $theme = wp_get_theme($theme_slug);
     if (!$theme->exists() || $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code()) {
         return;
     }
     $allowed_files = $theme->get_files('php', 1);
     $style_files = $theme->get_files('css');
     $allowed_files['style.css'] = $style_files['style.css'];
     $file = wp_stream_filter_input(INPUT_POST, 'file');
     if (empty($file)) {
         $file_name = 'style.css';
         $file_path = $allowed_files['style.css'];
     } else {
         $file_name = $file;
         $file_path = sprintf('%s/%s', $theme->get_stylesheet_directory(), $file_name);
     }
     $file_contents_before = file_get_contents($file_path);
     self::$edited_file = compact('file_name', 'file_path', 'file_contents_before', 'theme');
 }
Beispiel #3
0
/**
 * @action   wp_stream_after_connectors_registration
 * @return string $current_version if updated correctly
 */
function wp_stream_update_migrate_installer_edits_to_theme_editor_connector()
{
    global $wpdb;
    $db_version = WP_Stream_Install::$db_version;
    $current_version = WP_Stream_Install::$current;
    $args = array('connector' => 'installer', 'context' => 'themes', 'action' => 'edited');
    $records = wp_stream_query($args);
    foreach ($records as $record) {
        $file_name = wp_stream_get_meta($record->ID, 'file', true);
        $theme_name = wp_stream_get_meta($record->ID, 'name', true);
        if ('' !== $theme_name) {
            $matched_themes = array_filter(wp_get_themes(), function ($theme) use($theme_name) {
                return (string) $theme === $theme_name;
            });
            $theme = array_shift($matched_themes);
            // `stream`
            $wpdb->update($wpdb->stream, array('summary' => sprintf(WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name)), array('ID' => $record->ID));
            // `stream_context`
            $wpdb->update($wpdb->streamcontext, array('connector' => 'editor', 'context' => is_object($theme) ? $theme->get_template() : $theme_name, 'action' => 'updated'), array('record_id' => $record->ID));
            wp_stream_update_meta($record->ID, 'theme_name', $theme_name);
            if (is_object($theme)) {
                wp_stream_update_meta($record->ID, 'theme_slug', $theme->get_template());
            }
        }
    }
    do_action('wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error);
    if ($wpdb->last_error) {
        return false;
    }
    return $current_version;
}