-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-social-images.php
114 lines (81 loc) · 3.24 KB
/
simple-social-images.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Plugin Name: Simple Social Images
* Plugin URI: https://simplesocialimages.com
* Description: Create automated, beautiful and branded images for posts in WordPress shared on social media channels. This plugin requires a license for <a href="https://simplesocialimages.com">Simple Social Images</a>.
* Version: 1.0
* Author: Highrise Digital
* Author URI: https://highrise.digital/
* Text Domain: simple-social-images
* Domain Path: /languages/
* License: GPL2+
*/
// define variable for path to this plugin file.
define( 'HD_SSI_LOCATION', dirname( __FILE__ ) );
define( 'HD_SSI_LOCATION_URL', plugins_url( '', __FILE__ ) );
define( 'HD_SSI_VERSION', '1.0' );
/**
* Function to run on plugins load.
*/
function hd_ssi_wpjm_plugins_loaded() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'simple-social-images' );
load_textdomain( 'simple-social-images', WP_LANG_DIR . '/simple-social-images/simple-social-images-' . $locale . '.mo' );
load_plugin_textdomain( 'simple-social-images', false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'hd_ssi_wpjm_plugins_loaded' );
// load in the loader file which loads everything up.
require_once( dirname( __FILE__ ) . '/inc/loader.php' );
/**
* Function to run when the plugin is activated.
* Sets up some options and flushes rewtire rules for the generate endpoint.
*/
function hd_ssi_on_activation() {
// store the plugin version number on activation.
update_option( 'hd_ssi_version', HD_SSI_VERSION );
// add the option to redirect the user to settings.
update_option( 'hd_ssi_activation_redirection', true );
// add the option to force a permalink refresh.
update_option( 'hd_ssi_plugin_permalinks_flushed', 0 );
// get all of the registered settings.
$settings = hd_ssi_get_settings();
// if we have settings.
if ( ! empty( $settings ) ) {
// loop through each settings.
foreach ( $settings as $setting ) {
// if this setting does not have a default value.
if ( ! isset( $setting['default_value'] ) ) {
continue;
}
// create the default value.
update_option( $setting['option_name'], $setting['default_value'] );
}
}
}
register_activation_hook( __FILE__, 'hd_ssi_on_activation' );
/**
* Redirects the users to the settings screen, when the plugin is activated.
*/
function hd_ssi_redirect_to_settings_on_activation() {
// if the plugin has just be activated.
if ( get_option( 'hd_ssi_activation_redirection', false ) ) {
// remove the activation option.
delete_option( 'hd_ssi_activation_redirection' );
// redirect the user to the settings page.
wp_redirect( admin_url( 'options-general.php?page=hd-ssi-settings' ) );
exit;
}
}
add_action( 'admin_init', 'hd_ssi_redirect_to_settings_on_activation' );
/**
* Flushes the redirect rules if the plugin is just activated.
*/
function hd_ssi_maybe_flush_rewrite_rules() {
// if the rewrite rules have not been flushed.
if ( 0 === absint( get_option( 'hd_ssi_plugin_permalinks_flushed', 1 ) ) ) {
// flush the sites redirect rules.
flush_rewrite_rules();
// set the marker indicating that rewrite rules have been flushed.
update_option( 'hd_ssi_plugin_permalinks_flushed', 1 );
}
}
add_action( 'init', 'hd_ssi_maybe_flush_rewrite_rules', 99 );