forked from cleverness/widget-css-classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget-css-classes.php
executable file
·100 lines (84 loc) · 3.3 KB
/
widget-css-classes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Plugin Name: Widget CSS Classes
* Version: 1.5.4.1
* Description: Add custom, first, last, even, odd, and numbered classes to your widgets.
* Author: Jory Hogeveen
* Author URI: https://www.keraweb.nl
* Plugin URI: https://wordpress.org/plugins/widget-css-classes/
* Text Domain: widget-css-classes
*/
add_action( 'init', 'widget_css_classes_loader' );
add_action( 'wp_loaded', 'widget_css_classes_frontend_hook' );
/**
* Define constants and load the plugin
* @since 1.0
*/
function widget_css_classes_loader() {
$languages_path = plugin_basename( dirname( __FILE__ ) . '/languages' );
load_plugin_textdomain( 'widget-css-classes', false, $languages_path );
// Load plugin settings
include_once 'includes/widget-css-classes-library.class.php';
WCSSC_Lib::set_settings( get_option( WCSSC_Lib::$settings_key ) );
if ( is_admin() ) {
if ( ! defined( 'WCSSC_PLUGIN_VERSION' ) ) define( 'WCSSC_PLUGIN_VERSION', '1.5.4' );
if ( ! defined( 'WCSSC_FILE' ) ) define( 'WCSSC_FILE', __FILE__ );
if ( ! defined( 'WCSSC_BASENAME' ) ) define( 'WCSSC_BASENAME', plugin_basename( __FILE__ ) );
if ( ! defined( 'WCSSC_PLUGIN_DIR' ) ) define( 'WCSSC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
if ( ! defined( 'WCSSC_PLUGIN_URL' ) ) define( 'WCSSC_PLUGIN_URL', plugins_url( '', __FILE__ ) );
include_once 'includes/widget-css-classes-loader.class.php';
WCSSC_Loader::init();
}
}
/**
* Call the following hook at wp_loaded
* It must be added after register_sidebars is called
*/
function widget_css_classes_frontend_hook() {
if ( ! is_admin() ) {
include_once 'includes/widget-css-classes.class.php';
WCSSC::init_front();
add_filter( 'dynamic_sidebar_params', array( 'WCSSC', 'add_widget_classes' ) );
}
}
/**
* Install plugin
*/
function widget_css_classes_activation() {
global $wp_version;
if ( version_compare( $wp_version, '3.3', '<' ) ) {
// Add admin notice.
add_action( 'admin_notices', 'widget_css_classes_notice_wp_version' );
// Deactivate.
require_once ABSPATH . 'wp-admin/includes/plugin.php';
deactivate_plugins( plugin_basename( __FILE__ ) );
return;
}
if ( ! defined( 'WCSSC_BASENAME' ) ) define( 'WCSSC_BASENAME', plugin_basename( __FILE__ ) );
if ( ! defined( 'WCSSC_DB_VERSION' ) ) define( 'WCSSC_DB_VERSION', '1.5.4' );
if ( ! defined( 'WCSSC_FILE' ) ) define( 'WCSSC_FILE', __FILE__ );
include_once 'includes/widget-css-classes-library.class.php';
if ( get_option( 'WCSSC_db_version' ) ) {
$installed_ver = get_option( 'WCSSC_db_version' );
} else {
$installed_ver = 0;
}
// if the installed version is not the same as the current version, run the install function
if ( (string) WCSSC_DB_VERSION !== (string) $installed_ver ) {
WCSSC_Lib::install_plugin();
}
}
register_activation_hook( __FILE__, 'widget_css_classes_activation' );
/**
* Wrong WP version admin notice.
*/
function widget_css_classes_notice_wp_version() {
echo '<div class="notice notice-error is-dismissible"><p>';
echo sprintf(
// Translators: %1$s stands for the WP version and %2$s stands for "Please update" (a link).
esc_html__( 'Widget CSS Classes requires WordPress %1$s or newer. %2$s', 'widget-css-classes' ),
'3.3',
'<a target="_blank" href="http://codex.wordpress.org/Upgrading_WordPress">' . esc_html__( 'Please update', 'widget-css-classes' ) . '.</a>'
);
echo '</p></div>';
}