From 5bd50548ef8b8b0ba20489a3b68c023ef0b9b6b3 Mon Sep 17 00:00:00 2001 From: Brandon Hubbard Date: Sat, 19 Aug 2017 13:43:51 -0700 Subject: [PATCH 1/5] checking standards --- .codeclimate.yml | 66 ++++++++ .gitignore | 1 + composer.json | 5 + composer.lock | 150 +++++++++++++++++ object-cache.php | 426 +++++++++++++++++++++++++++++++++++++++++++++-- phpcs.xml | 24 +++ 6 files changed, 658 insertions(+), 14 deletions(-) create mode 100644 .codeclimate.yml create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 phpcs.xml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..2d62ef2 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,66 @@ +--- +engines: + csslint: + enabled: true + duplication: + enabled: true + config: + languages: + - javascript + - php + fixme: + enabled: true + phpcodesniffer: + enabled: true + config: + standard: "WordPress-Core,WordPress-Docs,WordPress-Extra" + phpmd: + enabled: true + checks: + Controversial/CamelCaseParameterName: + enabled: false + Controversial/CamelCaseMethodName: + enabled: false + Controversial/CamelCasePropertyName: + enabled: false + Controversial/CamelCaseVariableName: + enabled: false + CleanCode/ElseExpression: + enabled: false + eslint: + enabled: true + scss-lint: + enabled: true + markdownlint: + enabled: true +ratings: + paths: + - "**.scss" + - "**.inc" + - "**.js" + - "**.jsx" + - "**.module" + - "**.php" + - "**.md" + - "**.py" + - "**.rb" +exclude_paths: + - "**.png" + - "**.jpg" + - "**.gif" + - "**.css" + - "**.map" + - "gulpfile.js" + - "config.codekit" + - "composer.lock" + - "phpcs.xml" + - "**.json" + - "**.pot" + - "**.txt" + - "**-min.js" + - "**-min.css" + - "**.dist" + - "**.sh" + - "**.gif" + - "**.jpg" + - "**.jpeg" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..208a599 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor/* \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b3b6744 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "stevegrunwell/wp-enforcer": "^0.5.0" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..b918b97 --- /dev/null +++ b/composer.lock @@ -0,0 +1,150 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "81ff4fd6aed1d08f491e16f206291a67", + "packages": [], + "packages-dev": [ + { + "name": "squizlabs/php_codesniffer", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "c7594a88ae75401e8f8d0bd4deb8431b39045c51" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/c7594a88ae75401e8f8d0bd4deb8431b39045c51", + "reference": "c7594a88ae75401e8f8d0bd4deb8431b39045c51", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2017-07-18T01:12:32+00:00" + }, + { + "name": "stevegrunwell/wp-enforcer", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/stevegrunwell/wp-enforcer.git", + "reference": "6d583588d06346982b5819066f14675ddc8004d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stevegrunwell/wp-enforcer/zipball/6d583588d06346982b5819066f14675ddc8004d7", + "reference": "6d583588d06346982b5819066f14675ddc8004d7", + "shasum": "" + }, + "require": { + "wp-coding-standards/wpcs": "*" + }, + "bin": [ + "bin/wp-enforcer" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Steve Grunwell", + "email": "steve@stevegrunwell.com", + "homepage": "https://stevegrunwell.com" + } + ], + "description": "Git hooks to encourage well-written WordPress.", + "keywords": [ + "PHP_CodeSniffer", + "coding standards", + "git hooks", + "wordpress" + ], + "time": "2017-05-28T18:44:13+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "0.13.1", + "source": { + "type": "git", + "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", + "reference": "1f64b1a0b5b789822d0303436ee4e30e0135e4dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/1f64b1a0b5b789822d0303436ee4e30e0135e4dc", + "reference": "1f64b1a0b5b789822d0303436ee4e30e0135e4dc", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "time": "2017-08-05T16:08:58+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/object-cache.php b/object-cache.php index b7eca42..9d835d2 100644 --- a/object-cache.php +++ b/object-cache.php @@ -1,4 +1,8 @@ add( $key, $data, $group, $expire ); } +/** + * wp_cache_incr function. + * + * @access public + * @param mixed $key Key. + * @param int $n (default: 1) + * @param string $group (default: '') Group. + * @return void + */ function wp_cache_incr( $key, $n = 1, $group = '' ) { global $wp_object_cache; return $wp_object_cache->incr( $key, $n, $group ); } +/** + * wp_cache_decr function. + * + * @access public + * @param mixed $key + * @param int $n (default: 1) + * @param string $group (default: '') + * @return void + */ function wp_cache_decr( $key, $n = 1, $group = '' ) { global $wp_object_cache; return $wp_object_cache->decr( $key, $n, $group ); } +/** + * wp_cache_close function. + * + * @access public + * @return void + */ function wp_cache_close() { global $wp_object_cache; return $wp_object_cache->close(); } +/** + * wp_cache_delete function. + * + * @access public + * @param mixed $key + * @param string $group (default: '') + * @return void + */ function wp_cache_delete( $key, $group = '' ) { global $wp_object_cache; return $wp_object_cache->delete( $key, $group ); } +/** + * wp_cache_flush function. + * + * @access public + * @return void + */ function wp_cache_flush() { global $wp_object_cache; return $wp_object_cache->flush(); } +/** + * wp_cache_get function. + * + * @access public + * @param mixed $key + * @param string $group (default: '') + * @param bool $force (default: false) + * @return void + */ function wp_cache_get( $key, $group = '', $force = false ) { global $wp_object_cache; return $wp_object_cache->get( $key, $group, $force ); } +/** + * wp_cache_init function. + * + * @access public + * @return void + */ function wp_cache_init() { global $wp_object_cache; $wp_object_cache = new WP_Object_Cache(); } +/** + * wp_cache_replace function. + * + * @access public + * @param mixed $key + * @param mixed $data + * @param string $group (default: '') + * @param int $expire (default: 0) + * @return void + */ function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { global $wp_object_cache; return $wp_object_cache->replace( $key, $data, $group, $expire ); } +/** + * wp_cache_set function. + * + * @access public + * @param mixed $key + * @param mixed $data + * @param string $group (default: '') + * @param int $expire (default: 0) + * @return void + */ function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { global $wp_object_cache; @@ -80,45 +167,190 @@ function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { } } +/** + * wp_cache_switch_to_blog function. + * + * @access public + * @param mixed $blog_id + * @return void + */ function wp_cache_switch_to_blog( $blog_id ) { global $wp_object_cache; return $wp_object_cache->switch_to_blog( $blog_id ); } +/** + * wp_cache_add_global_groups function. + * + * @access public + * @param mixed $groups + * @return void + */ function wp_cache_add_global_groups( $groups ) { global $wp_object_cache; $wp_object_cache->add_global_groups( $groups ); } +/** + * wp_cache_add_non_persistent_groups function. + * + * @access public + * @param mixed $groups + * @return void + */ function wp_cache_add_non_persistent_groups( $groups ) { global $wp_object_cache; $wp_object_cache->add_non_persistent_groups( $groups ); } +/** + * WP_Object_Cache class. + */ class WP_Object_Cache { + + /** + * global_groups + * + * (default value: array( 'WP_Object_Cache_global' )) + * + * @var string + * @access public + */ var $global_groups = array( 'WP_Object_Cache_global' ); + /** + * no_mc_groups + * + * (default value: array()) + * + * @var array + * @access public + */ var $no_mc_groups = array(); - var $cache = array(); - var $mc = array(); - var $stats = array(); + /** + * cache + * + * (default value: array()) + * + * @var array + * @access public + */ + var $cache = array(); + + /** + * mc + * + * (default value: array()) + * + * @var array + * @access public + */ + var $mc = array(); + + /** + * stats + * + * (default value: array()) + * + * @var array + * @access public + */ + var $stats = array(); + + /** + * group_ops + * + * (default value: array()) + * + * @var array + * @access public + */ var $group_ops = array(); - var $flush_number = array(); + /** + * flush_number + * + * (default value: array()) + * + * @var array + * @access public + */ + var $flush_number = array(); + + /** + * global_flush_number + * + * (default value: null) + * + * @var mixed + * @access public + */ var $global_flush_number = null; - var $cache_enabled = true; + /** + * cache_enabled + * + * (default value: true) + * + * @var bool + * @access public + */ + var $cache_enabled = true; + + /** + * default_expiration + * + * (default value: 0) + * + * @var int + * @access public + */ var $default_expiration = 0; - var $max_expiration = 2592000; // 30 days + /** + * max_expiration + * + * (default value: 2592000) + * + * @var int + * @access public + */ + var $max_expiration = 2592000; // 30 days + + /** + * stats_callback + * + * (default value: null) + * + * @var mixed + * @access public + */ var $stats_callback = null; + /** + * connection_errors + * + * (default value: array()) + * + * @var array + * @access public + */ var $connection_errors = array(); + /** + * add function. + * + * @access public + * @param mixed $id + * @param mixed $data + * @param string $group (default: 'default') + * @param int $expire (default: 0) + * @return void + */ function add( $id, $data, $group = 'default', $expire = 0 ) { $key = $this->key( $id, $group ); @@ -148,18 +380,26 @@ function add( $id, $data, $group = 'default', $expire = 0 ) { $this->group_ops[ $group ][] = "add $id"; $this->cache[ $key ] = $data; - } else if ( false === $result && true === isset( $this->cache[$key] ) && false === $this->cache[$key] ) { + } elseif ( false === $result && true === isset( $this->cache[ $key ] ) && false === $this->cache[ $key ] ) { + /* * Here we unset local cache if remote add failed and local cache value is equal to `false` in order * to update the local cache anytime we get a new information from remote server. This way, the next * cache get will go to remote server and will fetch recent data. */ - unset( $this->cache[$key] ); + unset( $this->cache[ $key ] ); } return $result; } + /** + * add_global_groups function. + * + * @access public + * @param mixed $groups + * @return void + */ function add_global_groups( $groups ) { if ( ! is_array( $groups ) ) { $groups = (array) $groups; @@ -169,6 +409,13 @@ function add_global_groups( $groups ) { $this->global_groups = array_unique( $this->global_groups ); } + /** + * add_non_persistent_groups function. + * + * @access public + * @param mixed $groups + * @return void + */ function add_non_persistent_groups( $groups ) { if ( ! is_array( $groups ) ) { $groups = (array) $groups; @@ -178,6 +425,15 @@ function add_non_persistent_groups( $groups ) { $this->no_mc_groups = array_unique( $this->no_mc_groups ); } + /** + * incr function. + * + * @access public + * @param mixed $id + * @param int $n (default: 1) + * @param string $group (default: 'default') + * @return void + */ function incr( $id, $n = 1, $group = 'default' ) { $key = $this->key( $id, $group ); $mc =& $this->get_mc( $group ); @@ -187,6 +443,15 @@ function incr( $id, $n = 1, $group = 'default' ) { return $this->cache[ $key ]; } + /** + * decr function. + * + * @access public + * @param mixed $id + * @param int $n (default: 1) + * @param string $group (default: 'default') + * @return void + */ function decr( $id, $n = 1, $group = 'default' ) { $key = $this->key( $id, $group ); $mc =& $this->get_mc( $group ); @@ -196,12 +461,26 @@ function decr( $id, $n = 1, $group = 'default' ) { return $this->cache[ $key ]; } + /** + * close function. + * + * @access public + * @return void + */ function close() { foreach ( $this->mc as $bucket => $mc ) { $mc->close(); } } + /** + * delete function. + * + * @access public + * @param mixed $id + * @param string $group (default: 'default') + * @return void + */ function delete( $id, $group = 'default' ) { $key = $this->key( $id, $group ); @@ -226,6 +505,12 @@ function delete( $id, $group = 'default' ) { return $result; } + /** + * flush function. + * + * @access public + * @return void + */ function flush() { // Do not use the memcached flush method. It acts on an // entire memcached server, affecting all sites. @@ -241,18 +526,39 @@ function flush() { } } + /** + * rotate_site_keys function. + * + * @access public + * @return void + */ function rotate_site_keys() { $this->add( 'flush_number', intval( microtime( true ) * 1e6 ), 'WP_Object_Cache' ); $this->flush_number[ $this->blog_prefix ] = $this->incr( 'flush_number', 1, 'WP_Object_Cache' ); } + /** + * rotate_global_keys function. + * + * @access public + * @return void + */ function rotate_global_keys() { $this->add( 'flush_number', intval( microtime( true ) * 1e6 ), 'WP_Object_Cache_global' ); $this->global_flush_number = $this->incr( 'flush_number', 1, 'WP_Object_Cache_global' ); } + /** + * get function. + * + * @access public + * @param mixed $id + * @param string $group (default: 'default') + * @param bool $force (default: false) + * @return void + */ function get( $id, $group = 'default', $force = false ) { $key = $this->key( $id, $group ); $mc =& $this->get_mc( $group ); @@ -263,7 +569,7 @@ function get( $id, $group = 'default', $force = false ) { } else { $value = $this->cache[ $key ]; } - } else if ( in_array( $group, $this->no_mc_groups ) ) { + } elseif ( in_array( $group, $this->no_mc_groups ) ) { $this->cache[ $key ] = $value = false; } else { $value = $mc->get( $key ); @@ -288,6 +594,13 @@ function get( $id, $group = 'default', $force = false ) { return $value; } + /** + * get_multi function. + * + * @access public + * @param mixed $groups + * @return void + */ function get_multi( $groups ) { /* format: $get['group-name'] = array( 'key1', 'key2' ); @@ -308,7 +621,7 @@ function get_multi( $groups ) { } continue; - } else if ( in_array( $group, $this->no_mc_groups ) ) { + } elseif ( in_array( $group, $this->no_mc_groups ) ) { $return[ $key ] = false; continue; @@ -333,6 +646,13 @@ function get_multi( $groups ) { return $return; } + /** + * flush_prefix function. + * + * @access public + * @param mixed $group + * @return void + */ function flush_prefix( $group ) { if ( 'WP_Object_Cache' === $group || 'WP_Object_Cache_global' === $group ) { // Never flush the flush numbers. @@ -362,6 +682,14 @@ function flush_prefix( $group ) { return $number . ':'; } + /** + * key function. + * + * @access public + * @param mixed $key + * @param mixed $group + * @return void + */ function key( $key, $group ) { if ( empty( $group ) ) { $group = 'default'; @@ -380,6 +708,16 @@ function key( $key, $group ) { return preg_replace( '/\s+/', '', "$prefix:$group:$key" ); } + /** + * replace function. + * + * @access public + * @param mixed $id + * @param mixed $data + * @param string $group (default: 'default') + * @param int $expire (default: 0) + * @return void + */ function replace( $id, $data, $group = 'default', $expire = 0 ) { $key = $this->key( $id, $group ); @@ -403,6 +741,16 @@ function replace( $id, $data, $group = 'default', $expire = 0 ) { return $result; } + /** + * set function. + * + * @access public + * @param mixed $id + * @param mixed $data + * @param string $group (default: 'default') + * @param int $expire (default: 0) + * @return void + */ function set( $id, $data, $group = 'default', $expire = 0 ) { $key = $this->key( $id, $group ); @@ -428,12 +776,19 @@ function set( $id, $data, $group = 'default', $expire = 0 ) { $mc =& $this->get_mc( $group ); $result = $mc->set( $key, $data, false, $expire ); - ++$this->stats[ 'set' ]; - $this->group_ops[$group][] = "set $id"; + ++$this->stats['set']; + $this->group_ops[ $group ][] = "set $id"; return $result; } + /** + * switch_to_blog function. + * + * @access public + * @param mixed $blog_id + * @return void + */ function switch_to_blog( $blog_id ) { global $table_prefix; @@ -442,6 +797,13 @@ function switch_to_blog( $blog_id ) { $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ); } + /** + * colorize_debug_line function. + * + * @access public + * @param mixed $line + * @return void + */ function colorize_debug_line( $line ) { $colors = array( 'get' => 'green', @@ -457,6 +819,12 @@ function colorize_debug_line( $line ) { return $cmd2 . substr( $line, strlen( $cmd ) ) . "\n"; } + /** + * stats function. + * + * @access public + * @return void + */ function stats() { if ( $this->stats_callback && is_callable( $this->stats_callback ) ) { return call_user_func( $this->stats_callback ); @@ -493,6 +861,13 @@ function stats() { } } + /** + * get_mc function. + * + * @access public + * @param mixed $group + * @return void + */ function &get_mc( $group ) { if ( isset( $this->mc[ $group ] ) ) { return $this->mc[ $group ]; @@ -501,6 +876,14 @@ function &get_mc( $group ) { return $this->mc['default']; } + /** + * failure_callback function. + * + * @access public + * @param mixed $host + * @param mixed $port + * @return void + */ function failure_callback( $host, $port ) { $this->connection_errors[] = array( 'host' => $host, @@ -508,6 +891,13 @@ function failure_callback( $host, $port ) { ); } + /** + * salt_keys function. + * + * @access public + * @param mixed $key_salt + * @return void + */ function salt_keys( $key_salt ) { if ( strlen( $key_salt ) ) { $this->key_salt = $key_salt . ':'; @@ -516,6 +906,12 @@ function salt_keys( $key_salt ) { } } + /** + * __construct function. + * + * @access public + * @return void + */ function __construct() { $this->stats = array( 'get' => 0, @@ -536,13 +932,15 @@ function __construct() { reset( $buckets ); if ( is_int( key( $buckets ) ) ) { - $buckets = array( 'default' => $buckets ); + $buckets = array( + 'default' => $buckets, + ); } foreach ( $buckets as $bucket => $servers ) { $this->mc[ $bucket ] = new Memcache(); - foreach ( $servers as $server ) { + foreach ( $servers as $server ) { if ( 'unix://' == substr( $server, 0, 7 ) ) { $node = $server; $port = 0; diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..dbb6871 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,24 @@ + + + + Coding standards from WP Enforcer. + + + phpcs.xml + */tests/* + */vendor/* + + + + 0 + + + + + \ No newline at end of file From 466541f5e50629ec44c7b8ee36a03b85b48d3f15 Mon Sep 17 00:00:00 2001 From: Brandon Hubbard Date: Sat, 19 Aug 2017 14:10:39 -0700 Subject: [PATCH 2/5] Doc Blocks --- .editorconfig | 21 ++++ composer.json | 10 +- object-cache.php | 274 +++++++++++++++++++++-------------------------- 3 files changed, 151 insertions(+), 154 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c951f00 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +# WordPress Coding Standards +# https://make.wordpress.org/core/handbook/coding-standards/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab + +[{.jshintrc,*.json,*.yml}] +indent_style = space +indent_size = 2 + +[{*.txt,wp-config-sample.php}] +end_of_line = crlf \ No newline at end of file diff --git a/composer.json b/composer.json index b3b6744..1dff8e9 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,13 @@ { "require-dev": { "stevegrunwell/wp-enforcer": "^0.5.0" - } + }, + "scripts": { + "post-install-cmd": [ + "wp-enforcer" + ], + "post-update-cmd": [ + "wp-enforcer" + ] + } } diff --git a/object-cache.php b/object-cache.php index 9d835d2..1994df6 100644 --- a/object-cache.php +++ b/object-cache.php @@ -1,21 +1,26 @@ key( $id, $group ); @@ -381,7 +372,6 @@ function add( $id, $data, $group = 'default', $expire = 0 ) { $this->group_ops[ $group ][] = "add $id"; $this->cache[ $key ] = $data; } elseif ( false === $result && true === isset( $this->cache[ $key ] ) && false === $this->cache[ $key ] ) { - /* * Here we unset local cache if remote add failed and local cache value is equal to `false` in order * to update the local cache anytime we get a new information from remote server. This way, the next @@ -394,11 +384,10 @@ function add( $id, $data, $group = 'default', $expire = 0 ) { } /** - * add_global_groups function. + * Add Global Groups. * * @access public - * @param mixed $groups - * @return void + * @param mixed $groups Groups. */ function add_global_groups( $groups ) { if ( ! is_array( $groups ) ) { @@ -410,11 +399,10 @@ function add_global_groups( $groups ) { } /** - * add_non_persistent_groups function. + * Add Non Persistent Groups. * * @access public - * @param mixed $groups - * @return void + * @param mixed $groups Groups. */ function add_non_persistent_groups( $groups ) { if ( ! is_array( $groups ) ) { @@ -426,13 +414,12 @@ function add_non_persistent_groups( $groups ) { } /** - * incr function. + * Increment. * * @access public - * @param mixed $id - * @param int $n (default: 1) - * @param string $group (default: 'default') - * @return void + * @param mixed $id ID. + * @param int $n (default: 1) Numeric. + * @param string $group (default: 'default') Group. */ function incr( $id, $n = 1, $group = 'default' ) { $key = $this->key( $id, $group ); @@ -444,13 +431,12 @@ function incr( $id, $n = 1, $group = 'default' ) { } /** - * decr function. + * Decr. * * @access public - * @param mixed $id - * @param int $n (default: 1) - * @param string $group (default: 'default') - * @return void + * @param mixed $id ID. + * @param int $n (default: 1) Numeric. + * @param string $group (default: 'default') Group. */ function decr( $id, $n = 1, $group = 'default' ) { $key = $this->key( $id, $group ); @@ -462,10 +448,9 @@ function decr( $id, $n = 1, $group = 'default' ) { } /** - * close function. + * Close. * * @access public - * @return void */ function close() { foreach ( $this->mc as $bucket => $mc ) { @@ -474,12 +459,11 @@ function close() { } /** - * delete function. + * Delete. * * @access public - * @param mixed $id - * @param string $group (default: 'default') - * @return void + * @param mixed $id ID. + * @param string $group (default: 'default') Group. */ function delete( $id, $group = 'default' ) { $key = $this->key( $id, $group ); @@ -506,10 +490,9 @@ function delete( $id, $group = 'default' ) { } /** - * flush function. + * Flush. * * @access public - * @return void */ function flush() { // Do not use the memcached flush method. It acts on an @@ -527,10 +510,9 @@ function flush() { } /** - * rotate_site_keys function. + * Rotate Site Keys. * * @access public - * @return void */ function rotate_site_keys() { $this->add( 'flush_number', intval( microtime( true ) * 1e6 ), 'WP_Object_Cache' ); @@ -539,10 +521,9 @@ function rotate_site_keys() { } /** - * rotate_global_keys function. + * Rotate Global Keys. * * @access public - * @return void */ function rotate_global_keys() { $this->add( 'flush_number', intval( microtime( true ) * 1e6 ), 'WP_Object_Cache_global' ); @@ -551,13 +532,12 @@ function rotate_global_keys() { } /** - * get function. + * Get. * * @access public - * @param mixed $id - * @param string $group (default: 'default') - * @param bool $force (default: false) - * @return void + * @param mixed $id ID. + * @param string $group (default: 'default') Group. + * @param bool $force (default: false) Force. */ function get( $id, $group = 'default', $force = false ) { $key = $this->key( $id, $group ); @@ -595,15 +575,14 @@ function get( $id, $group = 'default', $force = false ) { } /** - * get_multi function. + * Get Mulit. * * @access public - * @param mixed $groups - * @return void + * @param mixed $groups Groups. */ function get_multi( $groups ) { /* - format: $get['group-name'] = array( 'key1', 'key2' ); + Format: $get['group-name'] = array( 'key1', 'key2' ); */ $return = array(); @@ -647,11 +626,10 @@ function get_multi( $groups ) { } /** - * flush_prefix function. + * Flush Prefix. * * @access public - * @param mixed $group - * @return void + * @param mixed $group Group. */ function flush_prefix( $group ) { if ( 'WP_Object_Cache' === $group || 'WP_Object_Cache_global' === $group ) { @@ -683,12 +661,11 @@ function flush_prefix( $group ) { } /** - * key function. + * Key. * * @access public - * @param mixed $key - * @param mixed $group - * @return void + * @param mixed $key Key. + * @param mixed $group Group. */ function key( $key, $group ) { if ( empty( $group ) ) { @@ -709,14 +686,13 @@ function key( $key, $group ) { } /** - * replace function. + * Replace. * * @access public - * @param mixed $id - * @param mixed $data - * @param string $group (default: 'default') - * @param int $expire (default: 0) - * @return void + * @param mixed $id ID. + * @param mixed $data Data. + * @param string $group (default: 'default') Group. + * @param int $expire (default: 0) Expire. */ function replace( $id, $data, $group = 'default', $expire = 0 ) { $key = $this->key( $id, $group ); @@ -742,14 +718,13 @@ function replace( $id, $data, $group = 'default', $expire = 0 ) { } /** - * set function. + * Set. * * @access public - * @param mixed $id - * @param mixed $data - * @param string $group (default: 'default') - * @param int $expire (default: 0) - * @return void + * @param mixed $id ID. + * @param mixed $data Data. + * @param string $group (default: 'default') Group. + * @param int $expire (default: 0) Expire. */ function set( $id, $data, $group = 'default', $expire = 0 ) { $key = $this->key( $id, $group ); @@ -783,11 +758,10 @@ function set( $id, $data, $group = 'default', $expire = 0 ) { } /** - * switch_to_blog function. + * Switch to Blog. * * @access public - * @param mixed $blog_id - * @return void + * @param mixed $blog_id Blog ID. */ function switch_to_blog( $blog_id ) { global $table_prefix; @@ -798,11 +772,10 @@ function switch_to_blog( $blog_id ) { } /** - * colorize_debug_line function. + * Colorize Debug Line. * * @access public - * @param mixed $line - * @return void + * @param mixed $line Line. */ function colorize_debug_line( $line ) { $colors = array( @@ -820,10 +793,9 @@ function colorize_debug_line( $line ) { } /** - * stats function. + * Stats. * * @access public - * @return void */ function stats() { if ( $this->stats_callback && is_callable( $this->stats_callback ) ) { @@ -862,11 +834,10 @@ function stats() { } /** - * get_mc function. + * Get MC. * * @access public - * @param mixed $group - * @return void + * @param mixed $group Group. */ function &get_mc( $group ) { if ( isset( $this->mc[ $group ] ) ) { @@ -877,12 +848,11 @@ function &get_mc( $group ) { } /** - * failure_callback function. + * Failure. * * @access public - * @param mixed $host - * @param mixed $port - * @return void + * @param mixed $host Host. + * @param mixed $port Port. */ function failure_callback( $host, $port ) { $this->connection_errors[] = array( @@ -892,11 +862,10 @@ function failure_callback( $host, $port ) { } /** - * salt_keys function. + * Salt Keys. * * @access public - * @param mixed $key_salt - * @return void + * @param mixed $key_salt Key Salt. */ function salt_keys( $key_salt ) { if ( strlen( $key_salt ) ) { @@ -910,7 +879,6 @@ function salt_keys( $key_salt ) { * __construct function. * * @access public - * @return void */ function __construct() { $this->stats = array( From 3f2fc46afa05030eb82e267e071e1d4f3b9a56d1 Mon Sep 17 00:00:00 2001 From: Brandon Hubbard Date: Sat, 19 Aug 2017 14:20:29 -0700 Subject: [PATCH 3/5] markdown version of readme --- readme.md | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..6be82f1 --- /dev/null +++ b/readme.md @@ -0,0 +1,97 @@ +# Memcached Object Cache + +Use memcached and the PECL memcache extension to provide a backing store for the WordPress object cache. + +## Description +Memcached Object Cache provides a persistent backend for the WordPress object cache. A memcached server and the PECL memcache extension are required. + +## Installation +1. Install [memcached](http://danga.com/memcached) on at least one server. Note the connection info. The default is `127.0.0.1:11211`. + +1. Install the [PECL memcache extension](http://pecl.php.net/package/memcache) + +1. Copy object-cache.php to wp-content + +## Frequently Asked Questions + +### How can I manually specify the memcached server(s)? = + +Add something similar to the following to wp-config.php above `/* That's all, stop editing! Happy blogging. */`: + +``` +$memcached_servers = array( + 'default' => array( + '10.10.10.20:11211', + '10.10.10.30:11211' + ) +); +``` + +The top level array keys, are cache groups, where 'default' corresponds to any cache group that is not explicitly defined. This allows for specifying memcached servers that only handle certain cache groups. The most common use is only specifying 'default'. + +Possible cache groups are: + +``` +{$taxonomy}_relationships +{$meta_type}_meta +{$taxonomy}_relationships +blog-details +blog-id-cache +blog-lookup +bookmark +calendar +category +comment +counts +general +global-posts +options +plugins +post_ancestors +post_meta +posts +rss +site-lookup +site-options +site-transient +terms +themes +timeinfo +transient +user_meta +useremail +userlogins +usermeta +users +userslugs +widget +``` + +## Changelog + +### 3.0.1 +* Fix key generation error in switch_to_blog() + +### 3.0.0 +* Flush site cache by rotating keys +* Flush global cache when flushing main site + +### 2.0.6 +* Flush the local cache on wp_cache_flush() + +### 2.0.5 +* Fix missing global in switch_to_blog + +### 2.0.4 +* Remove deprecated constructor + +### 2.0.3 +* Support for unix sockets + +### 2.0.2 +* Break references by cloning objects +* Keep local cache in sync with memcached when using incr and decr +* Handle limited environments where is_multisite() is not defined +* Fix setting and getting 0 +* PHP 5.2.4 is now required +* Use the WP_CACHE_KEY_SALT constant if available to gaurantee uniqueness of keys From e100b650cbe54a6883d35fbc8a073e5a9e44c6ae Mon Sep 17 00:00:00 2001 From: Brandon Hubbard Date: Sat, 19 Aug 2017 14:22:29 -0700 Subject: [PATCH 4/5] github url --- object-cache.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/object-cache.php b/object-cache.php index 1994df6..388321b 100644 --- a/object-cache.php +++ b/object-cache.php @@ -15,6 +15,8 @@ * License: GPLv3 or later * License URI: https://www.gnu.org/licenses/gpl-3.0.en.html * Version: 3.0.1 + * GitHub Plugin URI: https://github.com/Automattic/wp-memcached + * GitHub Branch: master * * Instructions: Install this file to wp-content/object-cache.php. */ From 8681c66d4335d3252d8143ec3568efb97846eb4a Mon Sep 17 00:00:00 2001 From: Brandon Hubbard Date: Sat, 19 Aug 2017 14:23:04 -0700 Subject: [PATCH 5/5] dont force wp enforcer yet --- composer.json | 10 +--------- composer.lock | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 1dff8e9..b3b6744 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,5 @@ { "require-dev": { "stevegrunwell/wp-enforcer": "^0.5.0" - }, - "scripts": { - "post-install-cmd": [ - "wp-enforcer" - ], - "post-update-cmd": [ - "wp-enforcer" - ] - } + } } diff --git a/composer.lock b/composer.lock index b918b97..443546b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "81ff4fd6aed1d08f491e16f206291a67", + "content-hash": "30d16e2aef30b09fea6c6c062175bcb2", "packages": [], "packages-dev": [ { @@ -138,6 +138,51 @@ "wordpress" ], "time": "2017-08-05T16:08:58+00:00" + }, + { + "name": "wpreadme2markdown/wpreadme2markdown", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/wpreadme2markdown/wp-readme-to-markdown.git", + "reference": "50c4a56503cd26b48c28fad19be281b948b8c2e0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wpreadme2markdown/wp-readme-to-markdown/zipball/50c4a56503cd26b48c28fad19be281b948b8c2e0", + "reference": "50c4a56503cd26b48c28fad19be281b948b8c2e0", + "shasum": "" + }, + "require": { + "php": ">= 5.3.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "WPReadme2Markdown\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Benjamin J. Balter" + }, + { + "name": "Christian Archer", + "email": "sunchaser@sunchaser.info" + } + ], + "description": "Convert WordPress Plugin readme.txt to Markdown", + "keywords": [ + "converter", + "markdown", + "readme", + "wordpress" + ], + "time": "2017-08-06T04:42:13+00:00" } ], "aliases": [],