Skip to content

Commit

Permalink
Add WP PHPCS and apply auto fixable changes (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
meszarosrob committed Jun 21, 2023
1 parent fb3edcb commit 69045ac
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
/vendor/
composer.lock
36 changes: 18 additions & 18 deletions comment-saver.php
Expand Up @@ -10,37 +10,37 @@
*/


add_action('comment_form', 'comment_saver_form');
add_filter('comment_post_redirect', 'comment_saver_cleanup', 10, 2);
add_action('wp', 'comment_saver_js');
add_action( 'comment_form', 'comment_saver_form' );
add_filter( 'comment_post_redirect', 'comment_saver_cleanup', 10, 2 );
add_action( 'wp', 'comment_saver_js' );


/**
* Get path for comment saver cookie.
/**
* Get path for comment saver cookie.
*/
function comment_saver_cookie_path() {
$parts = parse_url(get_option('home'));
$path = array_key_exists('path', $parts) ? $parts['path'] : '/';
$parts = parse_url( get_option( 'home' ) );
$path = array_key_exists( 'path', $parts ) ? $parts['path'] : '/';
return $path;
}


/**
* Setup require javascript.
/**
* Setup require javascript.
*/
function comment_saver_js() {
if (is_single() || is_comments_popup()) {
wp_enqueue_script('jquery.cookie', plugins_url('comment-saver/jquery.cookie.min.js'), array('jquery'), false, true);
if ( is_single() || is_comments_popup() ) {
wp_enqueue_script( 'jquery.cookie', plugins_url( 'comment-saver/jquery.cookie.min.js' ), array( 'jquery' ), false, true );
}
}


/**
* Add jQuery actions to save and restore comment.
/**
* Add jQuery actions to save and restore comment.
*/
function comment_saver_form($id) {
function comment_saver_form( $id ) {
$cookieName = 'comment_saver_post' . $id;
$path = comment_saver_cookie_path();
$path = comment_saver_cookie_path();

echo '
<script type="text/javascript">
Expand All @@ -62,10 +62,10 @@ function comment_saver_form($id) {
/**
* Cleanup comment saver cookie.
*/
function comment_saver_cleanup($location, $comment) {
function comment_saver_cleanup( $location, $comment ) {
$path = comment_saver_cookie_path();
setcookie('comment_saver_post' . $comment->comment_post_ID, null, -1, $path);
setcookie( 'comment_saver_post' . $comment->comment_post_ID, null, -1, $path );
return $location;
}

?>

28 changes: 28 additions & 0 deletions composer.json
@@ -0,0 +1,28 @@
{
"name": "willnorris/comment-saver",
"description": "Saves comment text in a temporary cookie before it is submitted.",
"license": "GPL-2.0-or-later",
"type": "wordpress-plugin",
"authors": [
{
"name": "Will Norris",
"email": "will@willnorris.com",
"homepage": "https://willnorris.com/",
"role": "Developer"
}
],
"homepage": "https://wordpress.org/plugins/comment-saver/",
"require": {
"php": "^5.6 || 7.* || >=8.0 <8.3"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"wp-coding-standards/wpcs": "^2.3"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
}
}
11 changes: 11 additions & 0 deletions phpcs.xml
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<ruleset>
<file>.</file>
<exclude-pattern>*/vendor/*</exclude-pattern>

<rule ref="WordPress"/>

<arg value="sp"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
</ruleset>

0 comments on commit 69045ac

Please sign in to comment.