if (is_writeable($real_file)) {
            $f = fopen($real_file, 'w+');
            fwrite($f, $newcontent);
            fclose($f);
            wp_redirect("plugin-editor.php?file={$file}&a=te");
        } else {
            wp_redirect("plugin-editor.php?file={$file}");
        }
        exit;
        break;
    default:
        require_once 'admin-header.php';
        if (!current_user_can('edit_plugins')) {
            die('<p>' . __('You have do not have sufficient permissions to edit plugins for this blog.') . '</p>');
        }
        update_recently_edited("wp-content/plugins/{$file}");
        if (!is_file($real_file)) {
            $error = 1;
        }
        if (!$error) {
            $f = fopen($real_file, 'r');
            $content = fread($f, filesize($real_file));
            $content = htmlspecialchars($content);
        }
        if (isset($_GET['a'])) {
            ?>
 <div id="message" class="updated fade"><p><?php 
            _e('File edited successfully.');
            ?>
</p></div>
<?php 
Example #2
0
             $location = "theme-editor.php?file={$file}&theme={$theme}&a=te&scrollto={$scrollto}";
         } else {
             $location = "theme-editor.php?file={$file}&theme={$theme}&scrollto={$scrollto}";
         }
     } else {
         $location = "theme-editor.php?file={$file}&theme={$theme}&scrollto={$scrollto}";
     }
     $location = wp_kses_no_null($location);
     $strip = array('%0d', '%0a', '%0D', '%0A');
     $location = _deep_replace($strip, $location);
     header("Location: {$location}");
     exit;
     break;
 default:
     require_once 'admin-header.php';
     update_recently_edited($file);
     if (!is_file($file)) {
         $error = 1;
     }
     if (!$error && filesize($file) > 0) {
         $f = fopen($file, 'r');
         $content = fread($f, filesize($file));
         if ('.php' == substr($file, strrpos($file, '.'))) {
             $functions = wp_doc_link_parse($content);
             $docs_select = '<select name="docs-list" id="docs-list">';
             $docs_select .= '<option value="">' . esc_attr__('Function Name...') . '</option>';
             foreach ($functions as $function) {
                 $docs_select .= '<option value="' . esc_attr(urlencode($function)) . '">' . htmlspecialchars($function) . '()</option>';
             }
             $docs_select .= '</select>';
         }
Example #3
0
 $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
 if (!is_file($real_file)) {
     wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
 } else {
     // Get the extension of the file
     if (preg_match('/\\.([^.]+)$/', $real_file, $matches)) {
         $ext = strtolower($matches[1]);
         // If extension is not in the acceptable list, skip it
         if (!in_array($ext, $editable_extensions)) {
             wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
         }
     }
 }
 add_contextual_help($current_screen, '<p>' . __('You can use the editor to make changes to any of your plugins&#8217; individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.') . '</p>' . '<p>' . __('Choose a plugin to edit from the menu in the upper right and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don&#8217;t forget to save your changes (Update File) when you&#8217;re finished.') . '</p>' . '<p>' . __('The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Lookup takes you to a web page about that particular function.') . '</p>' . '<p>' . __('If you want to make changes but don&#8217;t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.') . '</p>' . (is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>' : '') . '<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Plugins_Editor_Screen" target="_blank">Documentation on Editing Plugins</a>') . '</p>' . '<p>' . __('<a href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">Documentation on Writing Plugins</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>');
 require_once ABSPATH . 'wp-admin/admin-header.php';
 update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
 $content = file_get_contents($real_file);
 if ('.php' == substr($real_file, strrpos($real_file, '.'))) {
     $functions = wp_doc_link_parse($content);
     if (!empty($functions)) {
         $docs_select = '<select name="docs-list" id="docs-list">';
         $docs_select .= '<option value="">' . __('Function Name&hellip;') . '</option>';
         foreach ($functions as $function) {
             $docs_select .= '<option value="' . esc_attr($function) . '">' . esc_html($function) . '()</option>';
         }
         $docs_select .= '</select>';
     }
 }
 $content = esc_textarea($content);
 if (isset($_GET['a'])) {
     ?>
        }
        if (isset($_GET['liveupdate'])) {
            check_admin_referer('edit-plugin-test_' . $file);
            $error = validate_plugin($file);
            if (is_wp_error($error)) {
                wp_die($error);
            }
            if (!is_plugin_active($file)) {
                activate_plugin($file, "plugin-editor.php?file={$file}&phperror=1");
            }
            // we'll override this later if the plugin can be included without fatal error
            wp_redirect("plugin-editor.php?file={$file}&a=te");
            exit;
        }
        require_once 'admin-header.php';
        update_recently_edited(PLUGINDIR . "/{$file}");
        if (!is_file($real_file)) {
            $error = 1;
        }
        if (!$error) {
            $content = htmlspecialchars(file_get_contents($real_file));
        }
        if (isset($_GET['a'])) {
            ?>
 <div id="message" class="updated fade"><p><?php 
            _e('File edited successfully.');
            ?>
</p></div>
<?php 
        } elseif (isset($_GET['phperror'])) {
            ?>
	} else {
		wp_redirect("plugin-editor.php?file=$file");
	}

	exit();

break;

default:

	if ( !current_user_can('edit_plugins') )
		wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');

	require_once('admin-header.php');

	update_recently_edited(PLUGINDIR . "/$file");

	if (!is_file($real_file))
		$error = 1;

	if (!$error) {
		$f = fopen($real_file, 'r');
		$content = fread($f, filesize($real_file));
		$content = htmlspecialchars($content);
	}

	?>
<?php if (isset($_GET['a'])) : ?>
 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
<?php endif; ?>
 <div class="wrap">
    function bws_custom_code_tab()
    {
        if (!current_user_can('edit_plugins')) {
            wp_die(__('You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft'));
        }
        global $bstwbsftwppdtplgns_options;
        $message = $content = '';
        $is_css_active = $is_php_active = false;
        $upload_dir = wp_upload_dir();
        $folder = $upload_dir['basedir'] . '/bws-custom-code';
        if (!$upload_dir["error"]) {
            if (!is_dir($folder)) {
                wp_mkdir_p($folder, 0755);
            }
            $index_file = $upload_dir['basedir'] . '/bws-custom-code/index.php';
            if (!file_exists($index_file)) {
                if ($f = fopen($index_file, 'w+')) {
                    fclose($f);
                }
            }
        }
        $css_file = 'bws-custom-code.css';
        $real_css_file = $folder . '/' . $css_file;
        $php_file = 'bws-custom-code.php';
        $real_php_file = $folder . '/' . $php_file;
        $is_multisite = is_multisite();
        if ($is_multisite) {
            $blog_id = get_current_blog_id();
        }
        if (isset($_REQUEST['bws_update_custom_code']) && check_admin_referer('bws_update_' . $css_file)) {
            /* CSS */
            $newcontent_css = wp_unslash($_POST['bws_newcontent_css']);
            if (!empty($newcontent_css) && isset($_REQUEST['bws_custom_css_active'])) {
                if ($is_multisite) {
                    $bstwbsftwppdtplgns_options['custom_code'][$blog_id][$css_file] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file;
                } else {
                    $bstwbsftwppdtplgns_options['custom_code'][$css_file] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file;
                }
            } else {
                if ($is_multisite) {
                    if (isset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$css_file])) {
                        unset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$css_file]);
                    }
                } else {
                    if (isset($bstwbsftwppdtplgns_options['custom_code'][$css_file])) {
                        unset($bstwbsftwppdtplgns_options['custom_code'][$css_file]);
                    }
                }
            }
            if ($f = fopen($real_css_file, 'w+')) {
                fwrite($f, $newcontent_css);
                fclose($f);
                $message .= sprintf(__('File %s edited successfully.', 'bestwebsoft'), '<i>' . $css_file . '</i>') . ' ';
            } else {
                $error .= __('Not enough permissions to create or update the file', 'bestwebsoft') . ' ' . $real_css_file . '. ';
            }
            /* PHP */
            $newcontent_php = wp_unslash(trim($_POST['bws_newcontent_php']));
            if (file_exists($index_file)) {
                if (!empty($newcontent_php) && isset($_REQUEST['bws_custom_php_active'])) {
                    if ($is_multisite) {
                        $bstwbsftwppdtplgns_options['custom_code'][$blog_id][$php_file] = $real_php_file;
                    } else {
                        $bstwbsftwppdtplgns_options['custom_code'][$php_file] = $real_php_file;
                    }
                } else {
                    if ($is_multisite) {
                        if (isset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$php_file])) {
                            unset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$php_file]);
                        }
                    } else {
                        if (isset($bstwbsftwppdtplgns_options['custom_code'][$php_file])) {
                            unset($bstwbsftwppdtplgns_options['custom_code'][$php_file]);
                        }
                    }
                }
                if ($f = fopen($real_php_file, 'w+')) {
                    $newcontent_php = $newcontent_php;
                    fwrite($f, $newcontent_php);
                    fclose($f);
                    $message .= sprintf(__('File %s edited successfully.', 'bestwebsoft'), '<i>' . $php_file . '</i>');
                } else {
                    $error .= __('Not enough permissions to create or update the file', 'bestwebsoft') . ' ' . $real_php_file . '. ';
                }
            } else {
                $error .= __('Not enough permissions to create the file', 'bestwebsoft') . ' ' . $index_file . '. ';
            }
            if (!empty($error)) {
                $error .= ' <a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">' . __('Learn more', 'bestwebsoft') . '</a>';
            }
            if ($is_multisite) {
                update_site_option('bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options);
            } else {
                update_option('bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options);
            }
        }
        if (file_exists($real_css_file)) {
            update_recently_edited($real_css_file);
            $content_css = esc_textarea(file_get_contents($real_css_file));
            if ($is_multisite && isset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$css_file]) || !$is_multisite && isset($bstwbsftwppdtplgns_options['custom_code'][$css_file])) {
                $is_css_active = true;
            }
        }
        if (file_exists($real_php_file)) {
            update_recently_edited($real_php_file);
            $content_php = esc_textarea(file_get_contents($real_php_file));
            if ($is_multisite && isset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$php_file]) || !$is_multisite && isset($bstwbsftwppdtplgns_options['custom_code'][$php_file])) {
                $is_php_active = true;
            }
        } else {
            $content_php = "<?php" . "\n" . "if ( ! defined( 'ABSPATH' ) ) exit;" . "\n" . "if ( ! defined( 'BWS_GLOBAL' ) ) exit;" . "\n\n" . "/* Start your code here */" . "\n";
        }
        if (!empty($message)) {
            ?>
			<div id="message" class="below-h2 updated notice is-dismissible"><p><?php 
            echo $message;
            ?>
</p></div>
		<?php 
        }
        ?>
		
		<form action="" method="post">
			<?php 
        foreach (array('css', 'php') as $extension) {
            ?>
				
				<p>
					<?php 
            if ('css' == $extension) {
                _e('These styles will be added to the header on all pages of your site.', 'bestwebsoft');
            } else {
                printf(__('This PHP code will be hooked to the %s action and will be printed on front end only.', 'bestwebsoft'), '<a href="http://codex.wordpress.org/Plugin_API/Action_Reference/init" target="_blank"><code>init</code></a>');
            }
            ?>
				</p>
				<p><big>
					<?php 
            if (!file_exists(${"real_{$extension}_file"}) || is_writeable(${"real_{$extension}_file"})) {
                echo __('Editing', 'bestwebsoft') . ' <strong>' . ${"{$extension}_file"} . '</strong>';
            } else {
                echo __('Browsing', 'bestwebsoft') . ' <strong>' . ${"{$extension}_file"} . '</strong>';
            }
            ?>
				</big></p>
				<p><label><input type="checkbox" name="bws_custom_<?php 
            echo $extension;
            ?>
_active" value="1" <?php 
            if (${"is_{$extension}_active"}) {
                echo "checked";
            }
            ?>
 />	<?php 
            _e('Activate', 'bestwebsoft');
            ?>
</label></p>
				<textarea cols="70" rows="25" name="bws_newcontent_<?php 
            echo $extension;
            ?>
" id="bws_newcontent_<?php 
            echo $extension;
            ?>
"><?php 
            if (isset(${"content_{$extension}"})) {
                echo ${"content_{$extension}"};
            }
            ?>
</textarea>
				<p class="description">
					<a href="<?php 
            echo 'css' == $extension ? 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started' : 'http://php.net/';
            ?>
" target="_blank">
						<?php 
            printf(__('Learn more about %s', 'bestwebsoft'), strtoupper($extension));
            ?>
						
					</a>
				</p>				
			<?php 
        }
        if ((!file_exists($real_css_file) || is_writeable($real_css_file)) && (!file_exists($real_php_file) || is_writeable($real_php_file))) {
            ?>
				<p class="submit">
					<input type="hidden" name="bws_update_custom_code" value="submit" />					
					<?php 
            submit_button(__('Save Changes', 'bestwebsoft'), 'primary', 'submit', false);
            wp_nonce_field('bws_update_' . $css_file);
            ?>
				</p>
			<?php 
        } else {
            ?>
				<p><em><?php 
            printf(__('You need to make this files writable before you can save your changes. See %s the Codex %s for more information.', 'bestwebsoft'), '<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">', '</a>');
            ?>
</em></p>
			<?php 
        }
        ?>
		</form>
	<?php 
    }
    function bws_custom_code_tab()
    {
        if (!current_user_can('edit_plugins')) {
            wp_die(__('You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft'));
        }
        global $bstwbsftwppdtplgns_options;
        $message = $content = '';
        $is_active = false;
        $upload_dir = wp_upload_dir();
        $folder = $upload_dir['basedir'] . '/bws-custom-code';
        if (!$upload_dir["error"]) {
            if (!is_dir($folder)) {
                wp_mkdir_p($folder, 0755);
            }
        }
        $file = 'bws-custom-code.css';
        $real_file = $folder . '/' . $file;
        $is_multisite = is_multisite();
        if ($is_multisite) {
            $blog_id = get_current_blog_id();
        }
        if (isset($_REQUEST['bws_update_custom_code']) && check_admin_referer('bws_update_' . $file)) {
            $newcontent = wp_unslash($_POST['bws_newcontent_css']);
            if (!empty($newcontent) && isset($_REQUEST['bws_custom_css_active'])) {
                if ($is_multisite) {
                    $bstwbsftwppdtplgns_options['custom_code'][$blog_id][$file] = $upload_dir['baseurl'] . '/bws-custom-code/' . $file;
                } else {
                    $bstwbsftwppdtplgns_options['custom_code'][$file] = $upload_dir['baseurl'] . '/bws-custom-code/' . $file;
                }
            } else {
                if ($is_multisite) {
                    if (isset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$file])) {
                        unset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$file]);
                    }
                } else {
                    if (isset($bstwbsftwppdtplgns_options['custom_code'][$file])) {
                        unset($bstwbsftwppdtplgns_options['custom_code'][$file]);
                    }
                }
            }
            if ($f = fopen($real_file, 'w+')) {
                fwrite($f, $newcontent);
                fclose($f);
                $message = __('File edited successfully.', 'bestwebsoft');
            } else {
                $error = __('Not enough permissions to create or update the file', 'bestwebsoft') . ' ' . $real_file . '. <a href="https://codex.wordpress.org/Changing_File_Permissions">' . __('Learn more', 'bestwebsoft') . '</a>';
            }
            if ($is_multisite) {
                update_site_option('bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options);
            } else {
                update_option('bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options);
            }
        }
        if (file_exists($real_file)) {
            update_recently_edited($real_file);
            $content = file_get_contents($real_file);
            $content = esc_textarea($content);
            if ($is_multisite && isset($bstwbsftwppdtplgns_options['custom_code'][$blog_id][$file]) || !$is_multisite && isset($bstwbsftwppdtplgns_options['custom_code'][$file])) {
                $is_active = true;
            }
        }
        if (!empty($message)) {
            ?>
			<div id="message" class="below-h2 updated notice is-dismissible"><p><?php 
            echo $message;
            ?>
</p></div>
		<?php 
        }
        ?>
		<p><?php 
        _e('These styles will be added to the header on all pages of your site.', 'bestwebsoft');
        ?>
</p>
		<p><big>
			<?php 
        if (!file_exists($real_file) || is_writeable($real_file)) {
            echo __('Editing', 'bestwebsoft') . ' <strong>' . $file . '</strong>';
        } else {
            echo __('Browsing', 'bestwebsoft') . ' <strong>' . $file . '</strong>';
        }
        ?>
		</big></p>
		<form action="" method="post">
			<?php 
        wp_nonce_field('bws_update_' . $file);
        ?>
			<p><label><input type="checkbox" name="bws_custom_css_active" value="1" <?php 
        if ($is_active) {
            echo "checked";
        }
        ?>
 />	<?php 
        _e('Activate', 'bestwebsoft');
        ?>
</label></p>
			<textarea cols="70" rows="25" name="bws_newcontent_css" id="bws_newcontent_css"><?php 
        echo $content;
        ?>
</textarea>
			<p class="description">
				<a href="https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started" target="_blank"><?php 
        _e('Learn more about CSS', 'bestwebsoft');
        ?>
</a>
			</p>
			<?php 
        if (!file_exists($real_file) || is_writeable($real_file)) {
            ?>
				<p class="submit">
					<input type="hidden" name="bws_update_custom_code" value="submit" />					
					<?php 
            submit_button(__('Save Changes', 'bestwebsoft'), 'primary', 'submit', false);
            ?>
				</p>
			<?php 
        } else {
            ?>
				<p><em><?php 
            printf(__('You need to make this file writable before you can save your changes. See %s the Codex %s for more information.', 'bestwebsoft'), '<a href="https://codex.wordpress.org/Changing_File_Permissions">', '</a>');
            ?>
</em></p>
			<?php 
        }
        ?>
		</form>
	<?php 
    }