| 1 |
<?php |
| 2 |
/** |
| 3 |
* The plugin bootstrap file |
| 4 |
* |
| 5 |
* This file is read by WordPress to generate the plugin information in the plugin |
| 6 |
* admin area. This file also includes all of the dependencies used by the plugin, |
| 7 |
* registers the activation and deactivation functions, and defines a function |
| 8 |
* that starts the plugin. |
| 9 |
* |
| 10 |
* @link https://mohsinrafique.com |
| 11 |
* @since 1.0.0 |
| 12 |
* @package Amp_WP |
| 13 |
* |
| 14 |
* @wordpress-plugin |
| 15 |
* Plugin Name: AMP WP |
| 16 |
* Plugin URI: https://wordpress.org/plugins/amp-wp |
| 17 |
* Description: Automagically add Google AMP functionality to your site. Tons of Premium Features for FREE. Enable/Disable Post Types, Categories, and Tags. |
| 18 |
* Version: 1.8.3 |
| 19 |
* Author: Mohsin Rafique, Pixelative |
| 20 |
* Author URI: https://mohsinrafique.com |
| 21 |
* License: GPL-2.0+ |
| 22 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 23 |
* Text Domain: amp-wp |
| 24 |
* Domain Path: /languages |
| 25 |
*/ |
| 26 |
|
| 27 |
// If this file is called directly, abort. |
| 28 |
if ( ! defined( 'WPINC' ) ) { |
| 29 |
die; |
| 30 |
} |
| 31 |
|
| 32 |
define( 'AMP_WP_DEV_MODE', false ); |
| 33 |
define( 'AMP_WP_TEMPLATE_DIR', plugin_dir_path( __FILE__ ) . 'public/partials/' ); |
| 34 |
define( 'AMP_WP_TEMPLATE_DIR_CSS', '../../css/' ); |
| 35 |
define( 'AMP_WP_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 36 |
define( 'AMP_WP_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 37 |
define( 'AMP_WP_AJAX_URL', esc_js( admin_url( 'admin-ajax.php' ) ) ); |
| 38 |
|
| 39 |
define( 'AMP_WP_OVERRIDE_TPL_DIR', 'amp-wp' ); |
| 40 |
define( 'AMP_WP_SLOGAN', 'Google AMP For WordPress' ); |
| 41 |
|
| 42 |
$amp_wp_general_settings = get_option( 'amp_wp_general_settings', array() ); |
| 43 |
$theme_name = ( isset( $amp_wp_general_settings['theme_name'] ) && ! empty( $amp_wp_general_settings['theme_name'] ) ) ? esc_attr( $amp_wp_general_settings['theme_name'] ) : 'tez'; |
| 44 |
|
| 45 |
if ( $theme_name ) { |
| 46 |
define( 'AMP_WP_THEME_NAME', $theme_name ); |
| 47 |
} else { |
| 48 |
define( 'AMP_WP_THEME_NAME', 'tez' ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Currently plugin version. |
| 53 |
* Start at version 1.0.0 and use SemVer - https://semver.org |
| 54 |
* Rename this for your plugin and update it as you release new versions. |
| 55 |
*/ |
| 56 |
define( 'AMP_WP_VERSION', '1.8.3' ); |
| 57 |
|
| 58 |
/** |
| 59 |
* Display a branded upgrade notice in the Plugins list update row. |
| 60 |
* |
| 61 |
* Renders a visually distinct, AMP WP-branded notice below the default |
| 62 |
* "There is a new version available" line. The notice includes the target |
| 63 |
* version badge, the upgrade_notice text from readme.txt, and a clear |
| 64 |
* call-to-action. All styles are scoped via `.amp-wp-update-notice` to |
| 65 |
* avoid leaking into the rest of wp-admin. |
| 66 |
* |
| 67 |
* @since 1.0.3 |
| 68 |
* @since 1.8.1 Redesigned with branded inline styles. |
| 69 |
* |
| 70 |
* @param array $data Plugin metadata from the update transient. Keys |
| 71 |
* include `new_version`, `upgrade_notice`, `url`, |
| 72 |
* `package`, `slug`, etc. |
| 73 |
* @param array $response Full API response object (unused but required by |
| 74 |
* the hook signature). |
| 75 |
*/ |
| 76 |
function amp_wp_plugin_update_message( $data, $response ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- $response required by the in_plugin_update_message hook signature. |
| 77 |
$notice = isset( $data['upgrade_notice'] ) ? trim( $data['upgrade_notice'] ) : ''; |
| 78 |
if ( '' === $notice ) { |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
$new_version = isset( $data['new_version'] ) ? $data['new_version'] : ''; |
| 83 |
?> |
| 84 |
<style> |
| 85 |
.amp-wp-update-notice { |
| 86 |
margin: 12px 0 4px; |
| 87 |
padding: 14px 18px; |
| 88 |
background: linear-gradient(135deg, #f0f6ff 0%, #e8f0fe 100%); |
| 89 |
border-left: 4px solid #0073aa; |
| 90 |
border-radius: 4px; |
| 91 |
font-size: 13px; |
| 92 |
line-height: 1.6; |
| 93 |
color: #1d2327; |
| 94 |
} |
| 95 |
.amp-wp-update-notice__header { |
| 96 |
display: flex; |
| 97 |
align-items: center; |
| 98 |
gap: 8px; |
| 99 |
margin-bottom: 8px; |
| 100 |
font-weight: 600; |
| 101 |
font-size: 13px; |
| 102 |
color: #0073aa; |
| 103 |
} |
| 104 |
.amp-wp-update-notice__icon { |
| 105 |
display: inline-flex; |
| 106 |
align-items: center; |
| 107 |
justify-content: center; |
| 108 |
width: 22px; |
| 109 |
height: 22px; |
| 110 |
background: #0073aa; |
| 111 |
color: #fff; |
| 112 |
border-radius: 50%; |
| 113 |
font-size: 12px; |
| 114 |
font-weight: 700; |
| 115 |
flex-shrink: 0; |
| 116 |
} |
| 117 |
.amp-wp-update-notice__badge { |
| 118 |
display: inline-block; |
| 119 |
padding: 1px 8px; |
| 120 |
background: #0073aa; |
| 121 |
color: #fff; |
| 122 |
border-radius: 3px; |
| 123 |
font-size: 11px; |
| 124 |
font-weight: 600; |
| 125 |
letter-spacing: 0.3px; |
| 126 |
vertical-align: middle; |
| 127 |
} |
| 128 |
.amp-wp-update-notice__body { |
| 129 |
margin: 0; |
| 130 |
color: #3c434a; |
| 131 |
} |
| 132 |
.amp-wp-update-notice__body p { |
| 133 |
margin: 0; |
| 134 |
} |
| 135 |
.amp-wp-update-notice__body ul { |
| 136 |
margin: 0; |
| 137 |
padding: 0; |
| 138 |
list-style: none; |
| 139 |
} |
| 140 |
.amp-wp-update-notice__body ul li { |
| 141 |
position: relative; |
| 142 |
padding-left: 18px; |
| 143 |
margin-bottom: 4px; |
| 144 |
} |
| 145 |
.amp-wp-update-notice__body ul li:last-child { |
| 146 |
margin-bottom: 0; |
| 147 |
} |
| 148 |
.amp-wp-update-notice__body ul li::before { |
| 149 |
content: "\2713"; |
| 150 |
position: absolute; |
| 151 |
left: 0; |
| 152 |
color: #0073aa; |
| 153 |
font-weight: 700; |
| 154 |
} |
| 155 |
</style> |
| 156 |
<div class="amp-wp-update-notice"> |
| 157 |
<div class="amp-wp-update-notice__header"> |
| 158 |
<span class="amp-wp-update-notice__icon" aria-hidden="true">⚡</span> |
| 159 |
<?php |
| 160 |
echo wp_kses_post( |
| 161 |
sprintf( |
| 162 |
/* translators: %s: version badge HTML. */ |
| 163 |
__( 'AMP WP %s — Upgrade Notice', 'amp-wp' ), |
| 164 |
$new_version ? '<span class="amp-wp-update-notice__badge">v' . esc_html( $new_version ) . '</span>' : '' |
| 165 |
) |
| 166 |
); |
| 167 |
?> |
| 168 |
</div> |
| 169 |
<div class="amp-wp-update-notice__body"> |
| 170 |
<?php echo wp_kses_post( amp_wp_format_upgrade_notice( $notice ) ); ?> |
| 171 |
</div> |
| 172 |
</div> |
| 173 |
<?php |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Convert upgrade notice text into HTML, turning `* ` bullet lines into |
| 178 |
* a `<ul>` list and wrapping remaining lines in `<p>` tags. |
| 179 |
* |
| 180 |
* @since 1.8.1 |
| 181 |
* @param string $text Raw upgrade notice from readme.txt. |
| 182 |
* @return string HTML markup. |
| 183 |
*/ |
| 184 |
function amp_wp_format_upgrade_notice( $text ) { |
| 185 |
$lines = preg_split( '/\r?\n/', trim( $text ) ); |
| 186 |
$html = ''; |
| 187 |
$in_list = false; |
| 188 |
|
| 189 |
foreach ( $lines as $line ) { |
| 190 |
$line = trim( $line ); |
| 191 |
if ( '' === $line ) { |
| 192 |
if ( $in_list ) { |
| 193 |
$html .= '</ul>'; |
| 194 |
$in_list = false; |
| 195 |
} |
| 196 |
continue; |
| 197 |
} |
| 198 |
|
| 199 |
if ( preg_match( '/^\*\s+(.+)$/', $line, $m ) ) { |
| 200 |
if ( ! $in_list ) { |
| 201 |
$html .= '<ul>'; |
| 202 |
$in_list = true; |
| 203 |
} |
| 204 |
$html .= '<li>' . $m[1] . '</li>'; |
| 205 |
} else { |
| 206 |
if ( $in_list ) { |
| 207 |
$html .= '</ul>'; |
| 208 |
$in_list = false; |
| 209 |
} |
| 210 |
$html .= '<p>' . $line . '</p>'; |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
if ( $in_list ) { |
| 215 |
$html .= '</ul>'; |
| 216 |
} |
| 217 |
|
| 218 |
return $html; |
| 219 |
} |
| 220 |
|
| 221 |
// Hook to display a message in the plugins list. |
| 222 |
add_action( 'in_plugin_update_message-amp-wp/amp-wp.php', 'amp_wp_plugin_update_message', 10, 2 ); |
| 223 |
|
| 224 |
|
| 225 |
/** |
| 226 |
* The code that runs during plugin activation. |
| 227 |
* This action is documented in includes/class-amp-wp-activator.php |
| 228 |
*/ |
| 229 |
function activate_amp_wp() { |
| 230 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-amp-wp-activator.php'; |
| 231 |
Amp_WP_Activator::activate(); |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* The code that runs during plugin deactivation. |
| 236 |
* This action is documented in includes/class-amp-wp-deactivator.php |
| 237 |
*/ |
| 238 |
function deactivate_amp_wp() { |
| 239 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-amp-wp-deactivator.php'; |
| 240 |
Amp_WP_Deactivator::deactivate(); |
| 241 |
} |
| 242 |
|
| 243 |
register_activation_hook( __FILE__, 'activate_amp_wp' ); |
| 244 |
register_deactivation_hook( __FILE__, 'deactivate_amp_wp' ); |
| 245 |
|
| 246 |
/** |
| 247 |
* The core plugin class that is used to define internationalization, |
| 248 |
* admin-specific hooks, and public-facing site hooks. |
| 249 |
*/ |
| 250 |
require plugin_dir_path( __FILE__ ) . 'includes/class-amp-wp.php'; |
| 251 |
|
| 252 |
/** |
| 253 |
* Begins execution of the plugin. |
| 254 |
* |
| 255 |
* Since everything within the plugin is registered via hooks, |
| 256 |
* then kicking off the plugin from this point in the file does |
| 257 |
* not affect the page life cycle. |
| 258 |
* |
| 259 |
* @since 1.0.0 |
| 260 |
*/ |
| 261 |
function run_amp_wp() { |
| 262 |
$plugin = new Amp_WP(); |
| 263 |
$plugin->run(); |
| 264 |
} |
| 265 |
run_amp_wp(); |
| 266 |
|