Initial commit

parents
Pipeline #74 failed with stage
in 0 seconds
# A set of files you probably don't want in your WordPress.org distribution
.distignore
.editorconfig
.git
.gitignore
.gitlab-ci.yml
.travis.yml
.DS_Store
Thumbs.db
behat.yml
bin
circle.yml
composer.json
composer.lock
Gruntfile.js
package.json
package-lock.json
phpunit.xml
phpunit.xml.dist
multisite.xml
multisite.xml.dist
phpcs.xml
phpcs.xml.dist
README.md
wp-cli.local.yml
yarn.lock
tests
vendor
node_modules
*.sql
*.tar.gz
*.zip
# 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
indent_size = 4
[{.jshintrc,*.json,*.yml}]
indent_style = space
indent_size = 2
[{*.txt,wp-config-sample.php}]
end_of_line = crlf
.DS_Store
Thumbs.db
wp-cli.local.yml
node_modules/
*.sql
*.tar.gz
*.zip
*.bak
variables:
# Configure mysql service (https://hub.docker.com/_/mysql/)
MYSQL_DATABASE: wordpress_tests
MYSQL_ROOT_PASSWORD: mysql
before_script:
# Install dependencies
# update the docker
- apt-get clean
- apt-get -yqq update
# instll the required packages for the running CI tests
- apt-get -yqqf install zip unzip subversion mysql-client libmysqlclient-dev --fix-missing
# PHP extensions
- docker-php-ext-enable mbstring mcrypt mysqli pdo_mysql intl gd zip bz2
# Set up WordPress tests
- bash bin/install-wp-tests.sh wordpress_tests root mysql mysql latest true
# Install PHPCS and WPCS
- composer global require "squizlabs/php_codesniffer=*"
- composer global require "wp-coding-standards/wpcs"
- phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
PHPunit:PHP5.3:MySQL:
image: tetraweb/php:5.3
services:
- mysql:5.6
script:
- phpcs
- phpunit
PHPunit:PHP5.6:MySQL:
image: tetraweb/php:5.6
services:
- mysql:5.6
script:
- phpcs
- phpunit
PHPunit:PHP7.0:MySQL:
image: tetraweb/php:7.0
services:
- mysql:5.6
script:
- phpcs
- phpunit
PHPunit:PHP7.1:MySQL:
image: tetraweb/php:7.1
services:
- mysql:5.6
script:
- phpcs
- phpunit
module.exports = function( grunt ) {
'use strict';
// Project configuration
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
addtextdomain: {
options: {
textdomain: 'codeup-advent-calendar',
},
update_all_domains: {
options: {
updateDomains: true
},
src: [ '*.php', '**/*.php', '!\.git/**/*', '!bin/**/*', '!node_modules/**/*', '!tests/**/*' ]
}
},
wp_readme_to_markdown: {
your_target: {
files: {
'README.md': 'readme.txt'
}
},
},
makepot: {
target: {
options: {
domainPath: '/languages',
exclude: [ '\.git/*', 'bin/*', 'node_modules/*', 'tests/*' ],
mainFile: 'codeup-advent-calendar.php',
potFilename: 'codeup-advent-calendar.pot',
potHeaders: {
poedit: true,
'x-poedit-keywordslist': true
},
type: 'wp-plugin',
updateTimestamp: true
}
}
},
} );
grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );
grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] );
grunt.registerTask( 'readme', ['wp_readme_to_markdown'] );
grunt.util.linefeed = '\n';
};
#!/usr/bin/env bash
if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
exit 1
fi
DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
WP_TESTS_TAG="tags/${WP_VERSION%??}"
else
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
if [[ -z "$LATEST_VERSION" ]]; then
echo "Latest WordPress version could not be found"
exit 1
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi
set -ex
install_wp() {
if [ -d $WP_CORE_DIR ]; then
return;
fi
mkdir -p $WP_CORE_DIR
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p $TMPDIR/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
# https serves multiple offers, whereas http serves single.
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
LATEST_VERSION=${WP_VERSION%??}
else
# otherwise, scan the releases and get the most up to date minor version of the major release
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
fi
if [[ -z "$LATEST_VERSION" ]]; then
local ARCHIVE_NAME="wordpress-$WP_VERSION"
else
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
fi
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}
install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi
# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi
if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi
}
install_db() {
if [ ${SKIP_DB_CREATE} = "true" ]; then
return 0
fi
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""
if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi
# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}
install_wp
install_test_suite
install_db
<?php
/**
* Plugin Name: Codeup Advent Calendar
* Plugin URI: https://zed1.com/
* Description: PLUGIN DESCRIPTION HERE
* Author: Mike Little
* Author URI: https://mikelittle.org
* Text Domain: codeup-advent-calendar
* Domain Path: /languages
* Version: 0.1.0
*
* @package Codeup_Advent_Calendar
*/
require_once __DIR__ . '/inc/class-codeup-advent-calendar.php';
require_once __DIR__ . '/inc/class-advent-calendar-settings-page.php';
add_action( 'plugins_loaded', function () {
Codeup_Advent_Calendar::get_instance()->bootstrap();
} );
<?php
/**
* Class Advent_Calendar_Settings_Page
*/
class Advent_Calendar_Settings_Page {
/**
* Store the singleton instance
*
* @var Advent_Calendar_Settings_Page
*/
protected static $instance;
/**
* Create singleton instance.
*
* @return Advent_Calendar_Settings_Page
*/
public static function get_instance() : Advent_Calendar_Settings_Page {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Advent_Calendar_Settings_Page constructor.
*/
public function __construct() {
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
add_action( 'admin_init', array( $this, 'init_settings' ) );
}
/**
* Add our settings page under the Advent Calendar menu
*/
public function add_admin_menu() {
add_submenu_page(
'edit.php?post_type=advent_day',
esc_html__( 'Advent Calendar Settings', 'codeup-advent-calendar' ),
esc_html__( 'Calendar Settings', 'codeup-advent-calendar' ),
'manage_options',
'cac-settings-slug',
array( $this, 'page_layout' )
);
}
/**
* Register our settings, sections and fields.
*/
public function init_settings() {
register_setting(
'cac_settings_group',
'cac_settings_name',
[
'type' => 'string',
'description' => 'Advent Calendar settings',
'sanitize_callback' => [ $this, 'sanitize_cb' ],
]
);
add_settings_section(
'cac_settings_name_section',
'',
'__return_empty_string',
'cac_settings_name'
);
add_settings_field(
'cac-calendar_title',
__( 'Calendar Title', 'codeup-advent-calendar' ),
array( $this, 'render_cac_calendar_title_field' ),
'cac_settings_name',
'cac_settings_name_section'
);
add_settings_field(
'cac-create_days_checkbox',
__( 'Create default days?', 'codeup-advent-calendar' ),
array( $this, 'render_cac_create_days_checkbox_field' ),
'cac_settings_name',
'cac_settings_name_section'
);
}
/**
* Render the calendar settings page.
*/
public function page_layout() {
// Check required user capability
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'codeup-advent-calendar' ) );
}
// Admin Page Layout
echo '<div class="wrap">' . "\n";
echo ' <h1>' . get_admin_page_title() . '</h1>' . "\n";
echo ' <form action="options.php" method="post">' . "\n";
settings_fields( 'cac_settings_group' );
do_settings_sections( 'cac_settings_name' );
submit_button();
echo ' </form>' . "\n";
echo '</div>' . "\n";
}
/**
* Render the calendar title text field.
*/
function render_cac_calendar_title_field() {
// Retrieve data from the database.
$options = get_option( 'cac_settings_name' );
// Set default value.
$value = isset( $options['cac-calendar_title'] ) ? $options['cac-calendar_title'] : '';
// Field output.
echo '<input type="text" name="cac_settings_name[cac-calendar_title]" class="regular-text cac-calendar_title_field" placeholder="' . esc_attr__( '',
'codeup-advent-calendar' ) . '" value="' . esc_attr( $value ) . '">';
echo '<p class="description">' . __( 'Enter the title for the calendar page', 'codeup-advent-calendar' ) . '</p>';
}
/**
* Render the create days and delete old check boxes. Note these do not retain their settings. They trigger an action.
* So there is no need to retrieve them from stored options.
*/
function render_cac_create_days_checkbox_field() {
// Field output.
echo '<input type="checkbox" name="cac_settings_name[cac-create_days_checkbox][]" class="cac-create_days_checkbox_field" value="' . esc_attr( 'create' ) . '" > ' .
__( 'Create days', 'codeup-advent-calendar' ) . '<br>';
echo '<input type="checkbox" name="cac_settings_name[cac-create_days_checkbox][]" class="cac-create_days_checkbox_field" value="' . esc_attr( 'delete_current' ) . '" > ' .
__( 'Delete current', 'codeup-advent-calendar' ) . '<br>';
echo '<p class="description">' . __( 'Checking the second box will DELETE any existing days', 'codeup-advent-calendar' ) . '</p>';
}
/**
* Validate input and convert to comma separated list.
*
* @param array $input The POST-ed values.
*
* @return array The sanitized input.
*/
function sanitize_cb( array $input ) : array {
if ( isset( $input['cac-calendar_title'] ) ) {
$input['cac-calendar_title'] = wp_strip_all_tags( $input['cac-calendar_title'] );
}
if ( ! isset( $input['cac-create_days_checkbox'] ) ) {
return $input;
}
if ( in_array( 'create', $input['cac-create_days_checkbox'] ) ) {
if ( in_array( 'delete_current', $input['cac-create_days_checkbox'] ) ) {
Codeup_Advent_Calendar::get_instance()->delete_default_pages();
}
Codeup_Advent_Calendar::get_instance()->create_default_pages();
}
unset( $input['cac-create_days_checkbox'] );
return $input;
}
}
<?php
/**
* Part of the Codeup advent Calendar plugin.
* User: mikelittle
* Date: 31/10/2018
* Time: 17:55
*/
define( 'CAC_ADVENT_DAY_TYPE', 'advent_day' );
class Codeup_Advent_Calendar {
/**
* Store the singleton instance
*
* @var Codeup_Advent_Calendar
*/
protected static $instance;
/**
* Create singleton instance.
*
* @return Codeup_Advent_Calendar
*/
public static function get_instance() : Codeup_Advent_Calendar {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Bootstrap the plugin. Set up hooks. Create types, etc.
*/
public function bootstrap() {
if ( is_admin() ) {
Advent_Calendar_Settings_Page::get_instance();
add_action( 'pre_get_posts', [ $this, 'sort_by_day' ] );
}
}
/**
* Create all 25 default pages. Setting the title and slug.
*/
public function create_default_pages() {
for ( $d = 25; $d > 0; --$d ) {
wp_insert_post(
[
'post_type' => CAC_ADVENT_DAY_TYPE,
'post_title' => sprintf( __( 'Day %d', 'cac-advent-calendar' ), $d ),
'post_name' => sprintf( __( 'day-%02d', 'cac-advent-calendar' ), $d ),
'status' => 'draft',
]
);
}
}
/**
* Delete (trash) all the pages.
*/
public function delete_default_pages() {
// get all the days
$my_query = new WP_Query( [
'post_type' => CAC_ADVENT_DAY_TYPE,
'status' => 'all',
'fields' => 'ids',
'posts_per_page' => -1,
] );
$days = $my_query->get_posts();
foreach ( $days as $day ) {
wp_trash_post( $day );
}
}
/**
* Sort the days by the day number (same as slug). But only if not already sorted.
*
* @param WP_Query $wp_query The current query.
*/
public function sort_by_day( WP_Query $wp_query ) {
if ( CAC_ADVENT_DAY_TYPE === $wp_query->get( 'post_type' ) ) {
$orderby = $wp_query->get( 'orderby' );
if ( empty( $orderby ) ) {
$wp_query->set( 'orderby', 'post_name' );
$wp_query->set( 'order', 'ASC' );
}
}
}
}
{
"name": "codeup-advent-calendar",
"version": "0.1.0",
"main": "Gruntfile.js",
"author": "Mike Little",
"devDependencies": {
"grunt": "^1.0.3",
"grunt-wp-i18n": "^1.0.2",
"grunt-wp-readme-to-markdown": "~1.0.0"
}
}
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">
<description>Generally-applicable sniffs for WordPress plugins</description>
<rule ref="WordPress-Core" />
<rule ref="WordPress-Docs" />
<!-- Check all PHP files in directory tree by default. -->
<arg name="extensions" value="php"/>
<file>.</file>
<!-- Show progress and sniff codes in all reports -->
<arg value="ps"/>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
</ruleset>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
=== Codeup Advent Calendar ===
Contributors: (this should be a list of wordpress.org userid's)
Donate link: https://example.com/
Tags: comments, spam
Requires at least: 4.4
Tested up to: 4.9.8
Stable tag: 0.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Here is a short description of the plugin. This should be no more than 150 characters. No markup here.
== Description ==
This is the long description. No limit, and you can use Markdown (as well as in the following sections).
For backwards compatibility, if this section is missing, the full length of the short description will be used, and
Markdown parsed.
A few notes about the sections above:
* "Contributors" is a comma separated list of wp.org/wp-plugins.org usernames
* "Tags" is a comma separated list of tags that apply to the plugin
* "Requires at least" is the lowest version that the plugin will work on
* "Tested up to" is the highest version that you've *successfully used to test the plugin*. Note that it might work on
higher versions... this is just the highest one you've verified.
* Stable tag should indicate the Subversion "tag" of the latest stable version, or "trunk," if you use `/trunk/` for
stable.
Note that the `readme.txt` of the stable tag is the one that is considered the defining one for the plugin, so
if the `/trunk/readme.txt` file says that the stable tag is `4.3`, then it is `/tags/4.3/readme.txt` that'll be used
for displaying information about the plugin. In this situation, the only thing considered from the trunk `readme.txt`
is the stable tag pointer. Thus, if you develop in trunk, you can update the trunk `readme.txt` to reflect changes in
your in-development version, without having that information incorrectly disclosed about the current stable version
that lacks those changes -- as long as the trunk's `readme.txt` points to the correct stable tag.
If no stable tag is provided, it is assumed that trunk is stable, but you should specify "trunk" if that's where
you put the stable version, in order to eliminate any doubt.
== Installation ==
This section describes how to install the plugin and get it working.
e.g.
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
1. Place `<?php do_action('plugin_name_hook'); ?>` in your templates
== Frequently Asked Questions ==
= A question that someone might have =
An answer to that question.
= What about foo bar? =
Answer to foo bar dilemma.
== Screenshots ==
1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
(or jpg, jpeg, gif).
2. This is the second screen shot
== Changelog ==
= 1.0 =
* A change since the previous version.
* Another change.
= 0.5 =