Skip to content

Commit

Permalink
Apply code style fix regarding WordPress rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
shulard committed May 6, 2017
1 parent 6ddb41e commit bc53103
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 20 deletions.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
// Silence is golden
// Silence is golden.
36 changes: 30 additions & 6 deletions options.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
<?php
/**
* Option page definition
*
* @package wpmautic
*/

// Prevent direct access to this file.
if ( ! defined( 'ABSPATH' ) ) {
header( 'HTTP/1.0 403 Forbidden' );
echo 'This file should not be accessed directly!';
exit; // Exit if accessed directly
exit; // Exit if accessed directly.
}

/**
* HTML for the Mautic option page
*/
function wpmautic_options_page() {
?>
<div>
<h2>WP Mautic</h2>
<p>Enable Base URL for Mautic Integration.</p>
<form action="options.php" method="post">
<?php settings_fields('wpmautic_options'); ?>
<?php do_settings_sections('wpmautic'); ?>
<?php settings_fields( 'wpmautic_options' ); ?>
<?php do_settings_sections( 'wpmautic' ); ?>
<?php submit_button(); ?>
</form>
<h3>Shortcode Examples:</h3>
Expand Down Expand Up @@ -44,22 +52,38 @@ function wpmautic_options_page() {
<?php
}

add_action( 'admin_init', 'wpmautic_admin_init' );

/**
* Define admin_init hook logic
*/
function wpmautic_admin_init() {
register_setting( 'wpmautic_options', 'wpmautic_options', 'wpmautic_options_validate' );
add_settings_section( 'wpmautic_main', 'Main Settings', 'wpmautic_section_text', 'wpmautic' );
add_settings_field( 'wpmautic_base_url', 'Mautic Base URL', 'wpmautic_base_url', 'wpmautic', 'wpmautic_main' );
}
add_action( 'admin_init', 'wpmautic_admin_init' );

/**
* Section text
*/
function wpmautic_section_text() {
}

/**
* Define the input field for Mautic base URL
*/
function wpmautic_base_url() {
$options = get_option( 'wpmautic_options' );
echo "<input id='wpmautic_base_url' name='wpmautic_options[base_url]' size='40' type='text' placeholder='http://...' value='{$options['base_url']}' />";
?>
<input id="wpmautic_base_url" name="wpmautic_options[base_url]" size="40" type="text" placeholder="http://..." value="<?php echo esc_url_raw( $options['base_url'], array( 'http', 'https' ) ); ?>" />
<?php
}

/**
* Validate base URL input value
*
* @param array $input Input data.
* @return array
*/
function wpmautic_options_validate( $input ) {
$options = get_option( 'wpmautic_options' );
$options['base_url'] = trim( $input['base_url'] );
Expand Down
11 changes: 11 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@
<arg name="extensions" value="php" />

<rule ref="WordPress" />

<!-- exclude the 'empty' index files from some documentation checks -->
<rule ref="Squiz.Commenting.FileComment">
<exclude-pattern>*/index.php</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.InlineComment">
<exclude-pattern>*/index.php</exclude-pattern>
</rule>
<rule ref="WordPress.WP.EnqueuedResources">
<exclude-pattern>*/wpmautic.php</exclude-pattern>
</rule>
</ruleset>
56 changes: 43 additions & 13 deletions wpmautic.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,47 @@
* Author: Mautic community
* Author URI: http://mautic.org
* License: GPL2
*
* @package wpmautic
*/

// Prevent direct access to this file.
if ( ! defined( 'ABSPATH' ) ) {
header( 'HTTP/1.0 403 Forbidden' );
echo 'This file should not be accessed directly!';
exit; // Exit if accessed directly
exit; // Exit if accessed directly.
}

// Store plugin directory
// Store plugin directory.
define( 'VPMAUTIC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
// Store plugin main file path
// Store plugin main file path.
define( 'VPMAUTIC_PLUGIN_FILE', __FILE__ );

add_action( 'admin_menu', 'wpmautic_settings' );
add_action( 'wp_head', 'wpmautic_function' );
add_shortcode( 'mautic', 'wpmautic_shortcode' );
add_shortcode( 'mauticform', 'wpmautic_form_shortcode' );

/**
* Declare option page
*/
function wpmautic_settings() {
include_once( dirname( __FILE__ ) . '/options.php' );
add_options_page( 'WP Mautic Settings', 'WPMautic', 'manage_options', 'wpmautic', 'wpmautic_options_page' );
}

/**
* Settings Link in the ``Installed Plugins`` page
*
* @param array $links array of plugin action links.
* @param string $file Path to the plugin file relative to the plugins directory.
*
* @return array
*/
function wpmautic_plugin_actions( $links, $file ) {
if ( $file == plugin_basename( VPMAUTIC_PLUGIN_FILE ) && function_exists( 'admin_url' ) ) {
if ( plugin_basename( VPMAUTIC_PLUGIN_FILE ) === $file && function_exists( 'admin_url' ) ) {
$settings_link = '<a href="' . admin_url( 'options-general.php?page=wpmautic' ) . '">' . __( 'Settings' ) . '</a>';
// Add the settings link before other links
// Add the settings link before other links.
array_unshift( $links, $settings_link );
}
return $links;
Expand All @@ -51,7 +61,7 @@ function wpmautic_function() {
$options = get_option( 'wpmautic_options' );
$base_url = trim( $options['base_url'], " \t\n\r\0\x0B/" );

$mauticTrackingJS = <<<JS
$javascript = <<<HTML
<script>
(function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n;
w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t),
Expand All @@ -60,9 +70,9 @@ function wpmautic_function() {
mt('send', 'pageview');
</script>
JS;
HTML;

echo $mauticTrackingJS;
echo esc_js( $javascript );
}

/**
Expand All @@ -74,8 +84,8 @@ function wpmautic_function() {
* example: [mautic type="content" slot="slot_name"]Default Content[/mautic]
* example: [mautic type="video" gate-time="15" form-id="1" src="https://www.youtube.com/watch?v=QT6169rdMdk"]
*
* @param $atts
* @param null $content
* @param array $atts Shortcode attributes.
* @param string|null $content Default content to be displayed.
*
* @return string
*/
Expand Down Expand Up @@ -107,7 +117,8 @@ function wpmautic_shortcode( $atts, $content = null ) {
* Handle mauticform shortcode
* example: [mauticform id="1"]
*
* @param array $atts
* @param array $atts Shortcode attributes.
*
* @return string
*/
function wpmautic_form_shortcode( $atts ) {
Expand All @@ -124,6 +135,14 @@ function wpmautic_form_shortcode( $atts ) {
return '<script type="text/javascript" src="' . $base_url . '/form/generate.js?id=' . $atts['id'] . '"></script>';
}

/**
* Dynamic content shortcode handling
*
* @param array $atts Shortcode attributes.
* @param string|null $content Default content to be displayed.
*
* @return string
*/
function wpmautic_dwc_shortcode( $atts, $content = null ) {
$options = get_option( 'wpmautic_options' );
$base_url = trim( $options['base_url'], " \t\n\r\0\x0B/" );
Expand All @@ -134,6 +153,13 @@ function wpmautic_dwc_shortcode( $atts, $content = null ) {
return '<div class="mautic-slot" data-slot-name="' . $atts['slot'] . '">' . $content . '</div>';
}

/**
* Video shortcode handling
*
* @param array $atts Shortcode attributes.
*
* @return string
*/
function wpmautic_video_shortcode( $atts ) {
$video_type = '';
$atts = shortcode_atts(array(
Expand Down Expand Up @@ -176,8 +202,9 @@ function wpmautic_video_shortcode( $atts ) {
* Creates a nicely formatted and more specific title element text
* for output in head of document, based on current view.
*
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
*
* @return string Filtered title.
*/
function wpmautic_wp_title( $title = '', $sep = '' ) {
Expand All @@ -192,6 +219,9 @@ function wpmautic_wp_title( $title = '', $sep = '' ) {

// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 ) {
/*
* translators: Pagination number
*/
$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
}

Expand Down

0 comments on commit bc53103

Please sign in to comment.