Execute PHP in WordPress post, page and Widget Sidebar

If you are still struggling on how to insert PHP Codes inside particular blog post, page or a widget sidebar for execution; the following tutorial is for you.

 

 

 

Executing PHP codes in WordPress Page/Post

 

Installation

 

  1. Download phpexec.txt
  2. Rename phpexec.txt to phpexec.php
  3. Upload to /wp-content/plugins/ directory
  4. Activate the plug-in from WordPress administration menu

 

Usage

 

Anywhere in your post/pages where you want to execute a PHP Codes, insert <phpcode> before your php codes and </phpcode> your php codes.

 

  1. <phpcode>
  2.     <?php
  3.         echo “Current date and time: “;
  4.         echo date(“l dS of F Y h:i:s A”);
  5.     ?>
  6. </phpcode>

 

Security

 

If you are running a blog with multiple users, you need to determine who can run this plug-in. Alter the settings in your Administration Menu. Options -> PHPExec

 

Executing PHP codes in WordPress widget sidebar

 

Installation

 

  1. Download the plugin.
  2. Rename execphp.txt to execphp.php
  3. Upload to /wp-content/plugins/ directory
  4. Activate the plug-in from WordPress administration menu

 

Usage

 

This plug-in work like a normal text widget except that it allows execution of PHP Codes. You can create up to 9 instances of this widget.

Posted in Uncategorized | Leave a comment

Posting Source Code

While WordPress.com doesn’t allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing. We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:

 

1
2
3
4
#button {
    font-weight: bold;
    border: 2px solid #fff;
}

 

To accomplish the above, just wrap your code in these tags:

 

 your code here
 

 

The language (or lang) parameter controls how the code is syntax highlighted. The following languages are supported:

 

  • actionscript3
  • bash
  • clojure
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • html
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • powershell
  • python
  • r
  • ruby
  • scala
  • sql
  • vb
  • xml

 

If the language parameter is not set, it will default to “text” (no syntax highlighting).

 

Code in between the source code tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

 

Configuration Parameters

 

The shortcodes also accept a variety of configuration parameters that you may use to customize the output. All are completely optional.

 

  • autolinks (true/false) — Makes all URLs in your posted code clickable. Defaults to true.
  • collapse (true/false) — If true, the code box will be collapsed when the page loads, requiring the visitor to click to expand it. Good for large code posts. Defaults to false.
  • firstline (number) — Use this to change what number the line numbering starts at. It defaults to 1.
  • gutter (true/false) — If false, the line numbering on the left side will be hidden. Defaults to true.
  • highlight (comma-seperated list of numbers) — You can list the line numbers you want to be highlighted. For example “4,7,19”.
  • htmlscript (true/false) — If true, any HTML/XML in your code will be highlighted. This is useful when you are mixing code into HTML, such as PHP inside of HTML. Defaults to false and will only work with certain code languages.
  • light (true/false) — If true, the gutter (line numbering) and toolbar (see below) will be hidden. This is helpful when posting only one or two lines of code. Defaults to false.
  • padlinenumbers (true/false/integer) — Allows you to control the line number padding. true will result in automatic padding, false will result in no padding, and entering a number will force a specific amount of padding.
  • title (string) — Set a label for your code block. Can be useful when combined with the collapse parameter.

 

Here’s some examples of the above parameters in action:

 

8
9
10
11
This line is not highlighted.
This line is highlighted.
This line is highlighted.
This line is not highlighted.

 

 

 

0001
<strong>This</strong> is a short snippit of <code>code</code> with padlinenumbers set to 4.

 

And here’s a larger code block to see it all in action. It is set to the PHP language with “htmlscript” enabled and line number 12 highlighted.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>WordPress.com Code Example</title>
</head>
<body>
    <h1>WordPress.com Code Example</h1>
    <p><?php echo 'Hello World!'; ?></p>
    <p>This line is highlighted.</p>
    <p>This line is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long.</p>
    <div class="foobar">
        This    is  an
        example of  smart
        tabs.
    </div>
    <p><a href="http://wordpress.com/">WordPress.com</a></p>
</body>
</html>

 

 

 

Posted in Uncategorized | Leave a comment

Enables superusers to copy existing sub blogs to new sub blogs.

A simple and effective approach to copying blogs within a multisite network.

  • Copy a blog including all its widgets, template settings and more.
  • Option to copy or not copy files.
  • GUIDs and urls in post contents are migrated automatically.

This plugin was derived from Ron Renneck’s awesome WP Replicator (http://wpebooks.com/replicator/) plugin, although it’s been 90% rewritten. Changes from the original include the following:

  • Improved performance on large scale blogs.
  • Improved file copy performance and an option in the admin to bypass copying altogether.
  • Removed limit of number of blogs that can be used as a copy source.
  • Encapsulated the code in a Class and renamed variables to be more readable.
  • Revised UI to keep it simple and easy to use.

Sadly the WordPress file management code is not idea for handling the copying of a large folder with subdirectories so we opted to stick with exec(‘cp’). On the flip side, we set up a filter (copy_blog_files_command) so that you can override it with your own custom copy code.

This plugin is actively supported and we will do our best to help you. In return we simply as 3 things:

  1. Help Out. If you see a question on the forum you can help with or have a great idea and want to code it up and submit a patch, that would be just plain awesome and we will shower your with praise. Might even be a good way to get to know us and lead to some paid work if you freelance. Also, we are happy to post translations if you provide them.
  2. Donate – if this is generating enough revenue to support our time it makes all the difference in the world https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TWM2GF6BQZGSN
  3. Support us by buying our Premium plugins. In particular, check out our Events Calendar Pro http://tri.be/wordpress-events-calendar-pro/
Posted in Uncategorized | Leave a comment