Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/packages #22

Merged
merged 4 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

21 changes: 0 additions & 21 deletions .eslintrc.json

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/plugin-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Plugin Check'

on:
pull_request:
push:
branches:
- main
- master

jobs:
pcp:
name: PCP
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Build plugin
run: pnpm run deploy

- name: Run plugin check
uses: wordpress/plugin-check-action@v1
with:
build-dir: './deploy/ns-featured-posts'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ build/
deploy/
docs/
node_modules/

# Vendor
vendor/
devtools/vendor/
devtools/composer.lock
98 changes: 98 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for plugin">
<description>Apply WordPress Coding Standards</description>

<!--
Prevent errors caused by WordPress Coding Standards not supporting PHP 8.0+.
See https://github.com/WordPress/WordPress-Coding-Standards/issues/2035
-->
<ini name="error_reporting" value="E_ALL &#38; ~E_DEPRECATED" />

<!-- What to scan -->
<file>.</file>

<!-- Exclude files and folders -->
<exclude-pattern>*/build/*</exclude-pattern>
<exclude-pattern>*/deploy/*</exclude-pattern>
<exclude-pattern>*/languages/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*\.(css|js)</exclude-pattern>

<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->

<!-- Minimum support WP Version. -->
<config name="minimum_supported_wp_version" value="4.9"/>

<!-- Don't worry about files that don't contain any code -->
<rule ref="Internal.NoCodeFound">
<severity>0</severity>
</rule>

<!-- For CI, don't fail on warnings -->
<config name="ignore_warnings_on_exit" value="1"/>

<!-- Include the WordPress rulesets. -->
<rule ref="WordPress">
<exclude name="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents"/>
</rule>

<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<properties>
<property name="blank_line_check" value="true"/>
</properties>
</rule>

<rule ref="WordPress-Extra">
<!-- Forget about file names -->
<exclude name="WordPress.Files.FileName"/>

<!-- Allow WP global modification -->
<exclude name="WordPress.WP.GlobalVariablesOverride.Prohibited"/>

<!-- This nonce sniff almost never works right -->
<exclude name="WordPress.Security.NonceVerification.Missing"/>

<!-- Remove nonce notice -->
<exclude name="WordPress.Security.NonceVerification.Recommended"/>
</rule>

<!-- Make missing translator comment a warning. -->
<rule ref="WordPress.WP.I18n.MissingTranslatorsComment">
<type>warning</type>
</rule>

<!-- Sometimes we need to override globals -->
<rule ref="WordPress.WP.GlobalVariablesOverride.OverrideProhibited">
<type>warning</type>
</rule>

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array" value="ns-featured-posts" />
</properties>
</rule>

<rule ref="WordPress.Utils.I18nTextDomainFixer">
<properties>
<property name="old_text_domain" type="array">
<element value="" />
</property>
<property name="new_text_domain" value="ns-featured-posts" />
</properties>
</rule>

<!-- Loads the PHP Compatibility ruleset. -->
<rule ref="PHPCompatibilityWP" />

<!-- PHP version check. -->
<config name="testVersion" value="5.6-"/>
</ruleset>
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
composer.json
deploy
node_modules
vendor
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@wordpress/prettier-config"
42 changes: 20 additions & 22 deletions .wordpress-org/blueprints/blueprint.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "\/wp-admin\/options-general.php?page=ns-featured-posts",
"phpExtensionBundles": [
"kitchen-sink"
],
"steps": [
{
"step": "login",
"username": "admin",
"password": "password"
},
{
"step": "installPlugin",
"pluginZipFile": {
"resource": "wordpress.org\/plugins",
"slug": "ns-featured-posts"
},
"options": {
"activate": true
}
}
]
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "/wp-admin/options-general.php?page=ns-featured-posts",
"phpExtensionBundles": [ "kitchen-sink" ],
"steps": [
{
"step": "login",
"username": "admin",
"password": "password"
},
{
"step": "installPlugin",
"pluginZipFile": {
"resource": "wordpress.org/plugins",
"slug": "ns-featured-posts"
},
"options": {
"activate": true
}
}
]
}
25 changes: 14 additions & 11 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
( function( $ ) {
( function ( $ ) {
'use strict';

$( document ).ready( function() {
$( '.ns_featured_posts_icon' ).on( 'click', function() {
$( document ).ready( function () {
$( '.ns_featured_posts_icon' ).on( 'click', function () {
var $this = $( this );
var $table = $( '#posts-filter' );

var $postId = $this.data( 'post_id' );
var $postType = $this.data( 'post_type' );
var $maxPosts = $this.data( 'max_posts' );

var $targetStatus = ( $this.hasClass( 'selected' ) ) ? 'no' : 'yes';
var $unoStatus = ( typeof $this.data( 'uno' ) !== 'undefined' ) ? 1 : 0;
var $maxStatus = ( typeof $this.data( 'max_status' ) !== 'undefined' ) ? 1 : 0;
var $targetStatus = $this.hasClass( 'selected' ) ? 'no' : 'yes';
var $unoStatus = typeof $this.data( 'uno' ) !== 'undefined' ? 1 : 0;
var $maxStatus =
typeof $this.data( 'max_status' ) !== 'undefined' ? 1 : 0;

$.post(
NSFP_OBJ.ajaxurl,
Expand All @@ -26,23 +27,25 @@
max_status: $maxStatus,
nonce: NSFP_OBJ.nonce,
},
function( data, status ) {
function ( data, status ) {
if ( 'success' === status ) {
if ( true === data.status ) {
$this.toggleClass( 'selected' );

if ( true === data.uno ) {
$table.find( '.ns_featured_posts_icon.selected' )
$table
.find( '.ns_featured_posts_icon.selected' )
.not( '[data-post_id="' + $postId + '"]' )
.each( function( i, el ) {
.each( function ( i, el ) {
$( el ).removeClass( 'selected' );
} );
}
} else {
alert( data.message );
}
}
} );
}
);
} );
} );
}( jQuery ) );
} )( jQuery );
81 changes: 44 additions & 37 deletions assets/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,74 @@
'use strict';

(function ($) {
$.fn.blogPosts = function (options) {
const settings = $.extend({
api: '',
action: 'blog_posts',
loading_text: 'Loading',
list_type: 'ul'
}, options);
( function ( $ ) {
$.fn.blogPosts = function ( options ) {
const settings = $.extend(
{
api: '',
action: 'blog_posts',
loading_text: 'Loading',
list_type: 'ul',
},
options
);

if ('' === settings.api) {
if ( '' === settings.api ) {
return this;
}

function generateList(data) {
function generateList( data ) {
let output = '';

if (0 === data.length) {
if ( 0 === data.length ) {
return output;
}

data.forEach(function (item) {
output += '<li><a href="' + item.url + '" target="_blank">' + item.title + '</a></li>';
});
return $('<' + settings.list_type + '/>').append(output);
data.forEach( function ( item ) {
output +=
'<li><a href="' +
item.url +
'" target="_blank">' +
item.title +
'</a></li>';
} );
return $( '<' + settings.list_type + '/>' ).append( output );
}

return this.each(function () {
if ($(this).length < 1) {
return this.each( function () {
if ( $( this ).length < 1 ) {
return;
}

const $wrapper = $(this);
$.ajax({
const $wrapper = $( this );
$.ajax( {
url: settings.api,
type: 'GET',
dataType: 'json',
data: {
action: settings.action
action: settings.action,
},

beforeSend() {
$wrapper.html(settings.loading_text);
$wrapper.html( settings.loading_text );
},

complete(jqXHR) {
const response = JSON.parse(jqXHR.responseText);
$wrapper.html('');
complete( jqXHR ) {
const response = JSON.parse( jqXHR.responseText );
$wrapper.html( '' );

if (true === response.success) {
const listMarkup = generateList(response.data);
$wrapper.append(listMarkup);
if ( true === response.success ) {
const listMarkup = generateList( response.data );
$wrapper.append( listMarkup );
}
}

});
});
},
} );
} );
};

$(document).ready(function () {
$('.ns-blog-list').blogPosts({
$( document ).ready( function () {
$( '.ns-blog-list' ).blogPosts( {
api: ajaxurl,
action: 'nsfp_nsbl_get_posts'
});
});
})(jQuery);
action: 'nsfp_nsbl_get_posts',
} );
} );
} )( jQuery );
Loading
Loading