-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d3cdf65
Showing
9 changed files
with
1,201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# A set of files you probably don't want in your WordPress.org distribution | ||
.babelrc | ||
.deployignore | ||
.distignore | ||
.editorconfig | ||
.eslintignore | ||
.eslintrc | ||
.git | ||
.gitignore | ||
.gitlab-ci.yml | ||
.travis.yml | ||
.DS_Store | ||
Thumbs.db | ||
behat.yml | ||
bitbucket-pipelines.yml | ||
bin | ||
.circleci/config.yml | ||
composer.json | ||
composer.lock | ||
dependencies.yml | ||
Gruntfile.js | ||
package.json | ||
package-lock.json | ||
phpunit.xml | ||
phpunit.xml.dist | ||
multisite.xml | ||
multisite.xml.dist | ||
.phpcs.xml | ||
phpcs.xml | ||
.phpcs.xml.dist | ||
phpcs.xml.dist | ||
README.md | ||
webpack.config.js | ||
wp-cli.local.yml | ||
yarn.lock | ||
tests | ||
vendor | ||
node_modules | ||
*.sql | ||
*.tar.gz | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
phpcs.xml | ||
phpunit.xml | ||
Thumbs.db | ||
wp-cli.local.yml | ||
node_modules/ | ||
*.sql | ||
*.tar.gz | ||
*.zip |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/** | ||
* Plugin Name | ||
* | ||
* @package Ackee_WP | ||
* @author Brooke. | ||
* @copyright 2020 Brooke. | ||
* @license GPL-3.0-or-later | ||
* | ||
* @wordpress-plugin | ||
* Plugin Name: Ackee WP | ||
* Plugin URI: https://brooke.codes/plugins/ackee-wp | ||
* Description: Adds the Ackee JavaScript to your WordPress site. | ||
* Version: 0.1.0 | ||
* Requires at least: 4.5 | ||
* Requires PHP: 7.0 | ||
* Author: Brooke. | ||
* Author URI: https://broo.ke | ||
* Text Domain: ackeewp | ||
* Domain Path: /languages | ||
* License: GPL v3 or later | ||
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt | ||
* Ackee WP is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* Ackee WP is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Ackee WP. If not, see https://www.gnu.org/licenses/gpl-3.0.en.html. | ||
*/ | ||
|
||
|
||
if (! defined('ABSPATH') ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* Main AckeeWP class. | ||
*/ | ||
class AckeeWP | ||
{ | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
// Ackee WP constants. | ||
define('ACKEE_WP_FILE', __FILE__); | ||
define('ACKEE_WP_DIR', trailingslashit(dirname(__FILE__))); | ||
define('ACKEE_WP_VERSION', '1.0.0'); | ||
|
||
register_activation_hook(basename(ACKEE_WP_DIR) . '/' . basename(ACKEE_WP_FILE), array( $this, 'activate' )); | ||
|
||
add_action('init', array( $this, 'load_plugin_textdomain' )); | ||
add_action('plugins_loaded', array( $this, 'includes' )); | ||
register_uninstall_hook(ACKEE_WP_FILE, 'uninstall'); | ||
} | ||
/** | ||
* Textdomain. | ||
*/ | ||
public function load_plugin_textdomain() | ||
{ | ||
load_plugin_textdomain('ackeewp', false, dirname(plugin_basename(ACKEE_WP_FILE)) . '/languages/'); | ||
} | ||
|
||
/** | ||
* Includes. | ||
*/ | ||
public function includes() | ||
{ | ||
include_once ACKEE_WP_DIR . 'includes/class-admin-settings.php'; | ||
include_once ACKEE_WP_DIR . 'includes/class-frontend.php'; | ||
} | ||
|
||
/** | ||
* Remove option at uninstall | ||
*/ | ||
private static function uninstall() | ||
{ | ||
|
||
|
||
if (! defined('WP_UNINSTALL_PLUGIN') ) { | ||
die; | ||
} | ||
|
||
$option_name = 'ackeewp'; | ||
|
||
delete_option($option_name); | ||
delete_site_option($option_name); | ||
} | ||
} | ||
|
||
new AckeeWP(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
/** | ||
* Admin Settings | ||
* | ||
* This file registers and outputs the admin page dispalyed WP Admin. | ||
* | ||
* @package Ackee_WP | ||
* @author Brooke. | ||
* @copyright 2020 Brooke. | ||
* @license GPL-3.0-or-later | ||
* @link https://brooke.codes/plugins/ackee-wp | ||
*/ | ||
|
||
namespace AckeeWP; | ||
|
||
/** | ||
* Adds the WordPress settings page | ||
*/ | ||
if (! class_exists('AckeeWP_Admin_Settings') ) : | ||
class AckeeWP_Settings | ||
{ | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
add_action('admin_menu', array( $this, 'ackeewp_settings_page' )); | ||
add_action('admin_init', array( $this, 'ackeewp_register_settings' )); | ||
} | ||
|
||
/** | ||
* Registers the Ackee settings page under Settings. | ||
* | ||
* @since 0.1.0 | ||
* @access public | ||
* @link https://developer.wordpress.org/reference/functions/add_options_page/ | ||
*/ | ||
|
||
public function ackeewp_settings_page() | ||
{ | ||
add_options_page(__('Ackee WP Settings', 'ackeewp'), __('Ackee WP', 'ackeewp'), 'manage_options', 'ackee-wp', array( $this, 'ackeewp_settings_display' )); | ||
} | ||
|
||
/** | ||
* Saves the Ackee settings into the ackeewp_settings option. | ||
* | ||
* @since 0.1.0 | ||
* @access public | ||
* @link https://developer.wordpress.org/reference/functions/register_setting/ | ||
*/ | ||
|
||
public function ackeewp_register_settings() | ||
{ | ||
$args = array( | ||
'type' => 'array', | ||
'sanitize_callback' => array( $this, 'ackeewp_validate_settings' ), | ||
'default' => array( | ||
'instance_url' => '', | ||
'tracking_script' => 'tracking.js', | ||
'domain_id' => '', | ||
), | ||
); | ||
register_setting('ackeewp_settings_group', 'ackeewp_settings', $args); | ||
} | ||
|
||
/** | ||
* Sanatizes the user input to make sure we are saving what we are expecting into the database. | ||
* | ||
* @since 0.1.0 | ||
* @access public | ||
*/ | ||
public function ackeewp_validate_settings( $settings ) | ||
{ | ||
|
||
// If Nonce is invalid don't update the option data | ||
if (! isset($_POST['ackeewp_settings_options_nonce']) || ! wp_verify_nonce($_POST['ackeewp_settings_options_nonce'], 'ackeewp_settings_save_nonce') ) { | ||
return; | ||
} | ||
$ackeewp_settings = $settings; | ||
$ackeewp_settings['instance_url'] = esc_url_raw($settings['instance_url']); | ||
$ackeewp_settings['tracking_script'] = sanitize_text_field($settings['tracking_script']); | ||
$ackeewp_settings['domain_id'] = sanitize_text_field($settings['domain_id']); | ||
|
||
if(isset($settings['exclude_logged_in']) && 1 === $settings['exclude_logged_in'] ) { | ||
$ackeewp_settings['exclude_logged_in'] = 1; | ||
} | ||
|
||
return $ackeewp_settings; | ||
} | ||
|
||
|
||
/** | ||
* Settings page display callback. | ||
* | ||
* @since 0.1.0 | ||
* @access public | ||
*/ | ||
public function ackeewp_settings_display() | ||
{ | ||
$ackeewp_settings = get_option('ackeewp_settings'); | ||
$exclude_logged_in = ( isset($ackeewp_settings['exclude_logged_in']) ) ? 1 : 0; | ||
?> | ||
|
||
<div class="wrap"> | ||
<h1><?php _e('Ackee WP Settings', 'ackeewp'); ?></h1> | ||
<table class="form-table" role="presentation"> | ||
<form method="post" action="options.php"> | ||
<?php settings_fields('ackeewp_settings_group'); ?> | ||
<tbody> | ||
<tr> | ||
<th scope="row"><label for="ackeewp_instance_url"><?php _e('Ackee Install URL', 'ackeewp'); ?></label></th> | ||
<td> | ||
<input name="ackeewp_settings[instance_url]" type="url" id="ackeewp_instance_url" value="<?php echo ( esc_url($ackeewp_settings['instance_url']) ); ?>" class="regular-text" placeholder="Ackee Install URL" required> | ||
<p class="description" id="ackeewp-tracking-script-description"> | ||
<?php _e('The base URL for your Ackee install.', 'ackeewp') ?> | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th scope="row"><label for="ackeewp_tracker"><?php _e('Ackee Tracker', 'ackeewp'); ?> </label></th> | ||
<td> | ||
<input name="ackeewp_settings[tracking_script]" type="text" id="ackeewp_tracking_script" value="<?php echo ( esc_attr($ackeewp_settings['tracking_script']) ); ?>" placeholder="tracking.js" class="regular-text ltr" required> | ||
<?php esc_html( | ||
sprintf( | ||
esc_html('The name of your <a href="%s">Ackee Tracker</a>. The default is %stracking.js%s.</strong></p>', 'ackeewp'), | ||
'https://github.com/electerious/Ackee#tracker', '<code>', '</code>' | ||
) | ||
);?> | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th scope="row"><label for="ackeewp_domain_id"><?php _e('Ackee Domain ID', 'ackeewp'); ?></label></th> | ||
<td> | ||
<input name="ackeewp_settings[domain_id]" type="text" id="ackeewp_domain_id" value="<?php echo ( esc_attr($ackeewp_settings['domain_id']) ); ?>" placeholder="Domain ID" class="regular-text" required> | ||
<p class="description" id="ackeewp_domain_id-description"> | ||
<?php esc_html(sprintf(__('The unique domain ID for %s.', 'ackeewp'), esc_url_raw(home_url()))); ?> | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th scope="row"><?php _e('Exclude Logged In', 'ackeewp'); ?></th> | ||
<td><label for="ackeewp_exclude_logged_in"><input name="ackeewp_settings[exclude_logged_in]" type="checkbox" id="ackeewp_exclude_logged_in" value="1" <?php checked($exclude_logged_in, 1); ?> > | ||
<?php _e('If checked, the tracking code won\'t be output for logged in visits.', 'ackeewp'); ?></label></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<?php echo ( wp_nonce_field('ackeewp_settings_save_nonce', 'ackeewp_settings_options_nonce') ); ?> | ||
<?php echo submit_button(); ?> | ||
</form> | ||
<?php | ||
} //end of admin page settings | ||
} //end of class | ||
|
||
new AckeeWP_Admin_Settings(); | ||
endif; | ||
|
Oops, something went wrong.