@@ -13,31 +13,31 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | // Prevent direct access to this file. |
| 16 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 17 | - header( 'HTTP/1.0 403 Forbidden' ); |
|
| 16 | +if ( ! defined('ABSPATH')) { |
|
| 17 | + header('HTTP/1.0 403 Forbidden'); |
|
| 18 | 18 | echo 'This file should not be accessed directly!'; |
| 19 | 19 | exit; // Exit if accessed directly. |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Store plugin directory. |
| 23 | -define( 'VPMAUTIC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
|
| 23 | +define('VPMAUTIC_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
|
| 24 | 24 | // Store plugin main file path. |
| 25 | -define( 'VPMAUTIC_PLUGIN_FILE', __FILE__ ); |
|
| 25 | +define('VPMAUTIC_PLUGIN_FILE', __FILE__); |
|
| 26 | 26 | |
| 27 | -add_action( 'admin_menu', 'wpmautic_settings' ); |
|
| 28 | -add_action( 'plugins_loaded', 'wpmautic_injector' ); |
|
| 27 | +add_action('admin_menu', 'wpmautic_settings'); |
|
| 28 | +add_action('plugins_loaded', 'wpmautic_injector'); |
|
| 29 | 29 | |
| 30 | -include_once( VPMAUTIC_PLUGIN_DIR . '/shortcodes.php' ); |
|
| 30 | +include_once(VPMAUTIC_PLUGIN_DIR . '/shortcodes.php'); |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Declare option page |
| 34 | 34 | */ |
| 35 | 35 | function wpmautic_settings() { |
| 36 | - include_once( VPMAUTIC_PLUGIN_DIR . '/options.php' ); |
|
| 36 | + include_once(VPMAUTIC_PLUGIN_DIR . '/options.php'); |
|
| 37 | 37 | |
| 38 | 38 | add_options_page( |
| 39 | - __( 'WP Mautic Settings', 'wp-mautic' ), |
|
| 40 | - __( 'WPMautic', 'wp-mautic' ), |
|
| 39 | + __('WP Mautic Settings', 'wp-mautic'), |
|
| 40 | + __('WPMautic', 'wp-mautic'), |
|
| 41 | 41 | 'manage_options', |
| 42 | 42 | 'wpmautic', |
| 43 | 43 | 'wpmautic_options_page' |
@@ -52,19 +52,19 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | -function wpmautic_plugin_actions( $links, $file ) { |
|
| 56 | - if ( plugin_basename( VPMAUTIC_PLUGIN_FILE ) === $file && function_exists( 'admin_url' ) ) { |
|
| 55 | +function wpmautic_plugin_actions($links, $file) { |
|
| 56 | + if (plugin_basename(VPMAUTIC_PLUGIN_FILE) === $file && function_exists('admin_url')) { |
|
| 57 | 57 | $settings_link = sprintf( |
| 58 | 58 | '<a href="%s">%s</a>', |
| 59 | - admin_url( 'options-general.php?page=wpmautic' ), |
|
| 60 | - __( 'Settings' ) |
|
| 59 | + admin_url('options-general.php?page=wpmautic'), |
|
| 60 | + __('Settings') |
|
| 61 | 61 | ); |
| 62 | 62 | // Add the settings link before other links. |
| 63 | - array_unshift( $links, $settings_link ); |
|
| 63 | + array_unshift($links, $settings_link); |
|
| 64 | 64 | } |
| 65 | 65 | return $links; |
| 66 | 66 | } |
| 67 | -add_filter( 'plugin_action_links', 'wpmautic_plugin_actions', 10, 2 ); |
|
| 67 | +add_filter('plugin_action_links', 'wpmautic_plugin_actions', 10, 2); |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Retrieve one of the wpmautic options but sanitized |
@@ -76,24 +76,24 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @throws InvalidArgumentException Thrown when the option name is not given. |
| 78 | 78 | */ |
| 79 | -function wpmautic_option( $option, $default = null ) { |
|
| 80 | - $options = get_option( 'wpmautic_options' ); |
|
| 79 | +function wpmautic_option($option, $default = null) { |
|
| 80 | + $options = get_option('wpmautic_options'); |
|
| 81 | 81 | |
| 82 | - switch ( $option ) { |
|
| 82 | + switch ($option) { |
|
| 83 | 83 | case 'script_location': |
| 84 | - return ! isset( $options[ $option ] ) ? 'header' : $options[ $option ]; |
|
| 84 | + return ! isset($options[$option]) ? 'header' : $options[$option]; |
|
| 85 | 85 | case 'fallback_activated': |
| 86 | - return isset( $options[ $option ] ) ? (bool) $options[ $option ] : true; |
|
| 86 | + return isset($options[$option]) ? (bool) $options[$option] : true; |
|
| 87 | 87 | default: |
| 88 | - if ( ! isset( $options[ $option ] ) ) { |
|
| 89 | - if ( isset( $default ) ) { |
|
| 88 | + if ( ! isset($options[$option])) { |
|
| 89 | + if (isset($default)) { |
|
| 90 | 90 | return $default; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - throw new InvalidArgumentException( 'You must give a valid option name !' ); |
|
| 93 | + throw new InvalidArgumentException('You must give a valid option name !'); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - return $options[ $option ]; |
|
| 96 | + return $options[$option]; |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
@@ -103,15 +103,15 @@ discard block |
||
| 103 | 103 | * @return void |
| 104 | 104 | */ |
| 105 | 105 | function wpmautic_injector() { |
| 106 | - $script_location = wpmautic_option( 'script_location' ); |
|
| 107 | - if ( 'header' === $script_location ) { |
|
| 108 | - add_action( 'wp_head', 'wpmautic_inject_script' ); |
|
| 106 | + $script_location = wpmautic_option('script_location'); |
|
| 107 | + if ('header' === $script_location) { |
|
| 108 | + add_action('wp_head', 'wpmautic_inject_script'); |
|
| 109 | 109 | } else { |
| 110 | - add_action( 'wp_footer', 'wpmautic_inject_script' ); |
|
| 110 | + add_action('wp_footer', 'wpmautic_inject_script'); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if ( true === wpmautic_option( 'fallback_activated', false ) ) { |
|
| 114 | - add_action( 'wp_footer', 'wpmautic_inject_noscript' ); |
|
| 113 | + if (true === wpmautic_option('fallback_activated', false)) { |
|
| 114 | + add_action('wp_footer', 'wpmautic_inject_noscript'); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | * @return void |
| 122 | 122 | */ |
| 123 | 123 | function wpmautic_inject_script() { |
| 124 | - $base_url = wpmautic_option( 'base_url', '' ); |
|
| 125 | - if ( empty( $base_url ) ) { |
|
| 124 | + $base_url = wpmautic_option('base_url', ''); |
|
| 125 | + if (empty($base_url)) { |
|
| 126 | 126 | return; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | (function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n; |
| 131 | 131 | w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t), |
| 132 | 132 | m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m) |
| 133 | - })(window,document,'script','<?php echo esc_url( $base_url ); ?>/mtc.js','mt'); |
|
| 133 | + })(window,document,'script','<?php echo esc_url($base_url); ?>/mtc.js','mt'); |
|
| 134 | 134 | |
| 135 | 135 | mt('send', 'pageview'); |
| 136 | 136 | </script> |
@@ -144,18 +144,18 @@ discard block |
||
| 144 | 144 | * @return void |
| 145 | 145 | */ |
| 146 | 146 | function wpmautic_inject_noscript() { |
| 147 | - $base_url = wpmautic_option( 'base_url', '' ); |
|
| 148 | - if ( empty( $base_url ) ) { |
|
| 147 | + $base_url = wpmautic_option('base_url', ''); |
|
| 148 | + if (empty($base_url)) { |
|
| 149 | 149 | return; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | global $wp; |
| 153 | 153 | |
| 154 | 154 | $url_query = wpmautic_get_url_query(); |
| 155 | - $payload = rawurlencode( base64_encode( serialize( $url_query ) ) ); |
|
| 155 | + $payload = rawurlencode(base64_encode(serialize($url_query))); |
|
| 156 | 156 | ?> |
| 157 | 157 | <noscript> |
| 158 | - <img src="<?php echo esc_url( $base_url ); ?>/mtracking.gif?d=<?php echo esc_attr( $payload ); ?>" style="display:none;" alt="" /> |
|
| 158 | + <img src="<?php echo esc_url($base_url); ?>/mtracking.gif?d=<?php echo esc_attr($payload); ?>" style="display:none;" alt="" /> |
|
| 159 | 159 | </noscript> |
| 160 | 160 | <?php |
| 161 | 161 | } |
@@ -167,18 +167,18 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | function wpmautic_get_url_query() { |
| 169 | 169 | global $wp; |
| 170 | - $current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) ); |
|
| 170 | + $current_url = add_query_arg($wp->query_string, '', home_url($wp->request)); |
|
| 171 | 171 | |
| 172 | 172 | $attrs = array(); |
| 173 | 173 | $attrs['page_url'] = $current_url; |
| 174 | - $attrs['page_title'] = function_exists( 'wp_get_document_title' ) |
|
| 174 | + $attrs['page_title'] = function_exists('wp_get_document_title') |
|
| 175 | 175 | ? wp_get_document_title() |
| 176 | - : wp_title( '»', false ); |
|
| 176 | + : wp_title('»', false); |
|
| 177 | 177 | $attrs['language'] = get_locale(); |
| 178 | - $attrs['referrer'] = function_exists( 'wp_get_raw_referer' ) |
|
| 178 | + $attrs['referrer'] = function_exists('wp_get_raw_referer') |
|
| 179 | 179 | ? wp_get_raw_referer() |
| 180 | 180 | : null; |
| 181 | - if ( false === $attrs['referrer'] ) { |
|
| 181 | + if (false === $attrs['referrer']) { |
|
| 182 | 182 | $attrs['referrer'] = $current_url; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -6,8 +6,8 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | // Prevent direct access to this file. |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 10 | - header( 'HTTP/1.0 403 Forbidden' ); |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | + header('HTTP/1.0 403 Forbidden'); |
|
| 11 | 11 | echo 'This file should not be accessed directly!'; |
| 12 | 12 | exit; // Exit if accessed directly. |
| 13 | 13 | } |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | <h2>WP Mautic</h2> |
| 22 | 22 | <p>Enable Base URL for Mautic Integration.</p> |
| 23 | 23 | <form action="options.php" method="post"> |
| 24 | - <?php settings_fields( 'wpmautic' ); ?> |
|
| 25 | - <?php do_settings_sections( 'wpmautic' ); ?> |
|
| 24 | + <?php settings_fields('wpmautic'); ?> |
|
| 25 | + <?php do_settings_sections('wpmautic'); ?> |
|
| 26 | 26 | <?php submit_button(); ?> |
| 27 | 27 | </form> |
| 28 | 28 | <h3>Shortcode Examples:</h3> |
@@ -56,38 +56,38 @@ discard block |
||
| 56 | 56 | * Define admin_init hook logic |
| 57 | 57 | */ |
| 58 | 58 | function wpmautic_admin_init() { |
| 59 | - register_setting( 'wpmautic', 'wpmautic_options', 'wpmautic_options_validate' ); |
|
| 59 | + register_setting('wpmautic', 'wpmautic_options', 'wpmautic_options_validate'); |
|
| 60 | 60 | |
| 61 | 61 | add_settings_section( |
| 62 | 62 | 'wpmautic_main', |
| 63 | - __( 'Main Settings', 'wp-mautic' ), |
|
| 63 | + __('Main Settings', 'wp-mautic'), |
|
| 64 | 64 | 'wpmautic_section_text', |
| 65 | 65 | 'wpmautic' |
| 66 | 66 | ); |
| 67 | 67 | |
| 68 | 68 | add_settings_field( |
| 69 | 69 | 'wpmautic_base_url', |
| 70 | - __( 'Mautic Base URL', 'wp-mautic' ), |
|
| 70 | + __('Mautic Base URL', 'wp-mautic'), |
|
| 71 | 71 | 'wpmautic_base_url', |
| 72 | 72 | 'wpmautic', |
| 73 | 73 | 'wpmautic_main' |
| 74 | 74 | ); |
| 75 | 75 | add_settings_field( |
| 76 | 76 | 'wpmautic_script_location', |
| 77 | - __( 'Tracking script location', 'wp-mautic' ), |
|
| 77 | + __('Tracking script location', 'wp-mautic'), |
|
| 78 | 78 | 'wpmautic_script_location', |
| 79 | 79 | 'wpmautic', |
| 80 | 80 | 'wpmautic_main' |
| 81 | 81 | ); |
| 82 | 82 | add_settings_field( |
| 83 | 83 | 'wpmautic_fallback_activated', |
| 84 | - __( 'Fallback image', 'wp-mautic' ), |
|
| 84 | + __('Fallback image', 'wp-mautic'), |
|
| 85 | 85 | 'wpmautic_fallback_activated', |
| 86 | 86 | 'wpmautic', |
| 87 | 87 | 'wpmautic_main' |
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | -add_action( 'admin_init', 'wpmautic_admin_init' ); |
|
| 90 | +add_action('admin_init', 'wpmautic_admin_init'); |
|
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * Section text |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * Define the input field for Mautic base URL |
| 100 | 100 | */ |
| 101 | 101 | function wpmautic_base_url() { |
| 102 | - $url = wpmautic_option( 'base_url', '' ); |
|
| 102 | + $url = wpmautic_option('base_url', ''); |
|
| 103 | 103 | |
| 104 | 104 | ?> |
| 105 | 105 | <input |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | size="40" |
| 109 | 109 | type="text" |
| 110 | 110 | placeholder="http://..." |
| 111 | - value="<?php echo esc_url_raw( $url, array( 'http', 'https' ) ); ?>" |
|
| 111 | + value="<?php echo esc_url_raw($url, array('http', 'https')); ?>" |
|
| 112 | 112 | /> |
| 113 | 113 | <?php |
| 114 | 114 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * Define the input field for Mautic script location |
| 118 | 118 | */ |
| 119 | 119 | function wpmautic_script_location() { |
| 120 | - $position = wpmautic_option( 'script_location', '' ); |
|
| 120 | + $position = wpmautic_option('script_location', ''); |
|
| 121 | 121 | |
| 122 | 122 | ?> |
| 123 | 123 | <fieldset id="wpmautic_script_location"> |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | type="radio" |
| 127 | 127 | name="wpmautic_options[script_location]" |
| 128 | 128 | value="header" |
| 129 | - <?php if ( 'footer' !== $position ) : ?>checked<?php endif; ?> |
|
| 129 | + <?php if ('footer' !== $position) : ?>checked<?php endif; ?> |
|
| 130 | 130 | /> |
| 131 | - <?php esc_html_e( 'Embedded within the `wp_head` hook', 'wp-mautic' ); ?> |
|
| 131 | + <?php esc_html_e('Embedded within the `wp_head` hook', 'wp-mautic'); ?> |
|
| 132 | 132 | </label> |
| 133 | 133 | <br/> |
| 134 | 134 | <label> |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | type="radio" |
| 137 | 137 | name="wpmautic_options[script_location]" |
| 138 | 138 | value="footer" |
| 139 | - <?php if ( 'footer' === $position ) : ?>checked<?php endif; ?> |
|
| 139 | + <?php if ('footer' === $position) : ?>checked<?php endif; ?> |
|
| 140 | 140 | /> |
| 141 | - <?php esc_html_e( 'Embedded within the `wp_footer` hook', 'wp-mautic' ); ?> |
|
| 141 | + <?php esc_html_e('Embedded within the `wp_footer` hook', 'wp-mautic'); ?> |
|
| 142 | 142 | </label> |
| 143 | 143 | </fieldset> |
| 144 | 144 | <?php |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * Define the input field for Mautic fallback flag |
| 149 | 149 | */ |
| 150 | 150 | function wpmautic_fallback_activated() { |
| 151 | - $flag = wpmautic_option( 'fallback_activated', false ); |
|
| 151 | + $flag = wpmautic_option('fallback_activated', false); |
|
| 152 | 152 | |
| 153 | 153 | ?> |
| 154 | 154 | <input |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | name="wpmautic_options[fallback_activated]" |
| 157 | 157 | type="checkbox" |
| 158 | 158 | value="1" |
| 159 | - <?php if ( true === $flag ) : ?>checked<?php endif; ?> |
|
| 159 | + <?php if (true === $flag) : ?>checked<?php endif; ?> |
|
| 160 | 160 | /> |
| 161 | 161 | <label for="wpmautic_fallback_activated"> |
| 162 | - <?php esc_html_e( 'Activate it when JavaScript is disabled ?', 'wp-mautic' ); ?> |
|
| 162 | + <?php esc_html_e('Activate it when JavaScript is disabled ?', 'wp-mautic'); ?> |
|
| 163 | 163 | </label> |
| 164 | 164 | <?php |
| 165 | 165 | } |
@@ -170,22 +170,22 @@ discard block |
||
| 170 | 170 | * @param array $input Input data. |
| 171 | 171 | * @return array |
| 172 | 172 | */ |
| 173 | -function wpmautic_options_validate( $input ) { |
|
| 174 | - $options = get_option( 'wpmautic_options' ); |
|
| 173 | +function wpmautic_options_validate($input) { |
|
| 174 | + $options = get_option('wpmautic_options'); |
|
| 175 | 175 | |
| 176 | - $input['base_url'] = isset( $input['base_url'] ) |
|
| 177 | - ? trim( $input['base_url'], " \t\n\r\0\x0B/" ) |
|
| 176 | + $input['base_url'] = isset($input['base_url']) |
|
| 177 | + ? trim($input['base_url'], " \t\n\r\0\x0B/") |
|
| 178 | 178 | : ''; |
| 179 | 179 | |
| 180 | - $options['base_url'] = esc_url_raw( trim( $input['base_url'], " \t\n\r\0\x0B/" ) ); |
|
| 181 | - $options['script_location'] = isset( $input['script_location'] ) |
|
| 182 | - ? trim( $input['script_location'] ) |
|
| 180 | + $options['base_url'] = esc_url_raw(trim($input['base_url'], " \t\n\r\0\x0B/")); |
|
| 181 | + $options['script_location'] = isset($input['script_location']) |
|
| 182 | + ? trim($input['script_location']) |
|
| 183 | 183 | : 'header'; |
| 184 | - if ( ! in_array( $options['script_location'], array( 'header', 'footer' ), true ) ) { |
|
| 184 | + if ( ! in_array($options['script_location'], array('header', 'footer'), true)) { |
|
| 185 | 185 | $options['script_location'] = 'header'; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - $options['fallback_activated'] = isset( $input['fallback_activated'] ) && '1' === $input['fallback_activated'] |
|
| 188 | + $options['fallback_activated'] = isset($input['fallback_activated']) && '1' === $input['fallback_activated'] |
|
| 189 | 189 | ? true |
| 190 | 190 | : false; |
| 191 | 191 | |