json_encode() public static method

Works like json_encode, but adds JSON_PRETTY_PRINT if the current php version supports it i.e. PHP is 5.4.0 or greated
public static json_encode ( $value )
$value array|object|string|whatever that is json_encode'able
コード例 #1
0
 /**
  * Saves info about all installed plugins to an option.
  * When we are done logging then we remove the option.
  */
 function save_versions_before_update($bool = null, $hook_extra = null)
 {
     $plugins = get_plugins();
     update_option($this->slug . "_plugin_info_before_update", SimpleHistory::json_encode($plugins));
     return $bool;
 }
コード例 #2
0
 /**
  * Check if request is an create or enable/disable redirection
  */
 function on_admin_init()
 {
     $referer = wp_get_raw_referer();
     // We only continue if referer contains page=redirection.php
     if (false === strpos($referer, "page=redirection.php")) {
         return;
     }
     $referer_parsed = parse_url($referer);
     error_log("-----");
     // error_log( SimpleHistory::json_encode( $referer_parsed ) );
     error_log(SimpleHistory::json_encode($_REQUEST));
     /*
     Create redirection
     {
     	"source": "source yo",
     	"match": "url",
     	"red_action": "url",
     	"target": "dest yo",
     	"group_id": "1",
     	"add": "Add Redirection",
     	"group": "0",
     	"action": "red_redirect_add",
     	"_wpnonce": "cdadb5a4ca",
     	"_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php"
     }
     */
     if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "red_redirect_add") {
         $this->log_redirection_add($_REQUEST);
         return;
     }
     /*
     Enable/disable single or multiple direction(s)
     {
     	"page": "redirection.php",
     	"_wpnonce": "290f261024",
     	"_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php",
     	"action": "enable", or "disable"
     	"id": "0",
     	"paged": "1",
     	"item": [
     		"3",
     		"2",
     		"1"
     	],
     	"action2": "-1"
     }
     */
     if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "enable" && empty($_REQUEST["sub"])) {
         $this->log_redirection_enable_or_disable($_REQUEST);
         return;
     } else {
         if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "disable" && empty($_REQUEST["sub"])) {
             $this->log_redirection_enable_or_disable($_REQUEST);
             return;
         }
     }
     /*
     Delete item(s)
     {
         "page": "redirection.php",
         "edit": "4",
         "_wpnonce": "290f261024",
         "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&edit=4",
         "action": "delete",
         "id": "0",
         "paged": "1",
         "item": [
             "6"
         ],
         "action2": "-1"
     }
     */
     if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "delete" && empty($_REQUEST["sub"])) {
         $this->log_redirection_delete($_REQUEST);
         return;
     }
     /*
     Options
     - delete all options and deactivate plugin
     {
         "page": "redirection.php",
         "sub": "options",
         "_wpnonce": "e2c008ca25",
         "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=options",
         "delete": "Delete"
     }
     */
     if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "options" && isset($_REQUEST["delete"]) && $_REQUEST["delete"] == "Delete") {
         $this->log_options_delete_all($_REQUEST);
         return;
     }
     /*
     Save options {
         "page": "redirection.php",
         "sub": "options",
         "_wpnonce": "8fe9b57662",
         "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=options",
         "support": "on",
         "expire_redirect": "7",
         "expire_404": "7",
         "monitor_post": "0",
         "token": "acf88715b12038e3aca1ae1b3d82132a",
         "auto_target": "",
         "update": "Update"
     }
     */
     if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "options" && isset($_REQUEST["update"]) && $_REQUEST["update"] == "Update") {
         $this->log_options_save($_REQUEST);
         return;
     }
     /*
     Add group
     {
     	"page": "redirection.php",
     	"sub": "groups",
     	"_wpnonce": "4cac237744",
     	"_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=groups",
     	"name": "new group yo",
     	"module_id": "1",
     	"add": "Add"
     }
     */
     if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "groups" && isset($_REQUEST["add"]) && $_REQUEST["add"] == "Add") {
         $this->log_group_add($_REQUEST);
         return;
     }
     /*
     Delete group(s)
     {
     	"page": "redirection.php",
     	"sub": "groups",
     	"_wpnonce": "290f261024",
     	"_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=groups",
     	"action": "-1",
     	"id": "0",
     	"paged": "1",
     	"item": [
     		"3",
     		"2"
     	],
     	"action2": "delete"
     }
     */
     if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "groups" && isset($_REQUEST["action"]) && $_REQUEST["action"] == "delete") {
         $this->log_group_delete($_REQUEST);
         return;
     }
     /*
     Disable group(s)
     {
     	"path": "\/wp-admin\/tools.php",
     	"query": "page=redirection.php&sub=groups"
     }
     {
     	"page": "redirection.php",
     	"sub": "groups",
     	"_wpnonce": "290f261024",
     	"_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=groups",
     	"action": "disable",
     	"id": "0",
     	"paged": "1",
     	"item": [
     		"1"
     	],
     	"action2": "-1"
     }
     */
     if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "groups" && isset($_REQUEST["action"]) && $_REQUEST["action"] == "enable") {
         $this->log_group_enable_or_disable($_REQUEST);
         return;
     } else {
         if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "groups" && isset($_REQUEST["action"]) && $_REQUEST["action"] == "disable") {
             $this->log_group_enable_or_disable($_REQUEST);
             return;
         }
     }
 }
コード例 #3
0
 /**
  * Log misc useful things to the system log. Useful when developing/testing/debuging etc.
  */
 function system_debug_log()
 {
     error_log('$_GET: ' . SimpleHistory::json_encode($_GET));
     error_log('$_POST: ' . SimpleHistory::json_encode($_POST));
     error_log('$_FILES: ' . SimpleHistory::json_encode($_FILES));
     error_log('$_SERVER: ' . SimpleHistory::json_encode($_SERVER));
     $args = func_get_args();
     $i = 0;
     foreach ($args as $arg) {
         error_log("\$arg {$i}: " . SimpleHistory::json_encode($arg));
         $i++;
     }
 }
コード例 #4
0
 /**
  * Saves info about all installed plugins to an option.
  * When we are done logging then we remove the option.
  */
 function save_versions_before_update($bool = null, $hook_extra = null)
 {
     $plugins = get_plugins();
     // does not work
     $option_name = $this->slug . "_plugin_info_before_update";
     $r = update_option($option_name, SimpleHistory::json_encode($plugins));
     return $bool;
 }