| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: oik base plugin |
| 4 |
Plugin URI: http://www.oik-plugins.com/oik-plugins/oik |
| 5 |
Description: OIK Information Kit - Over 80 lazy smart shortcodes for displaying WordPress content |
| 6 |
Version: 2.3 |
| 7 |
Author: bobbingwide |
| 8 |
Author URI: http://www.oik-plugins.com/author/bobbingwide |
| 9 |
Text Domain: oik |
| 10 |
Domain Path: /languages/ |
| 11 |
License: GPLv2 or later |
| 12 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 13 |
|
| 14 |
Copyright 2010-2014 Bobbing Wide (email : herb@bobbingwide.com ) |
| 15 |
|
| 16 |
This program is free software; you can redistribute it and/or modify |
| 17 |
it under the terms of the GNU General Public License version 2, |
| 18 |
as published by the Free Software Foundation. |
| 19 |
|
| 20 |
You may NOT assume that you can use any other version of the GPL. |
| 21 |
|
| 22 |
This program is distributed in the hope that it will be useful, |
| 23 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 |
GNU General Public License for more details. |
| 26 |
|
| 27 |
The license for this software can likely be found here: |
| 28 |
http://www.gnu.org/licenses/gpl-2.0.html |
| 29 |
|
| 30 |
*/ |
| 31 |
|
| 32 |
/** |
| 33 |
* Return the oik_version |
| 34 |
* |
| 35 |
* @returns string oik base plugin version number - from the WordPress plugin template |
| 36 |
*/ |
| 37 |
function oik_version() { |
| 38 |
return bw_oik_version(); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Function to invoke when the file has been loaded |
| 43 |
* |
| 44 |
* All of the oik plugins and many of the common functions, include calls to bw_trace(), bw_trace2() or bw_backtrace() so we need to include bwtrace.inc |
| 45 |
* As of oik v2.3 the "init" action is invoked after most other plugins. |
| 46 |
* This allows oik-fields and oik-types to define overrides to registered post types and taxonomies. |
| 47 |
*/ |
| 48 |
function oik_plugin_file_loaded() { |
| 49 |
require_once( "oik_boot.inc" ); |
| 50 |
require_once( 'bwtrace.inc' ); |
| 51 |
require_once( "bobbfunc.inc" ); |
| 52 |
//require_once( "bobbcomp.inc" ); |
| 53 |
require_once( "oik-add-shortcodes.php" ); |
| 54 |
add_action('wp_enqueue_scripts', 'oik_enqueue_stylesheets', 11); |
| 55 |
add_action('init', 'oik_main_init', 11 ); |
| 56 |
|
| 57 |
if ( defined('DOING_AJAX') && DOING_AJAX ) { |
| 58 |
oik_require( "includes/oik-ajax.php" ); |
| 59 |
oik_ajax_lazy_init(); |
| 60 |
} |
| 61 |
add_filter( "attachment_fields_to_edit", "oik_attachment_fields_to_edit", null, 2 ); |
| 62 |
add_filter( "attachment_fields_to_save", "oik_attachment_fields_to_save", null, 2 ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Implement 'wp_enqueue_scripts' action enqueue the oik.css and $customCSS stylesheets as required |
| 67 |
* |
| 68 |
* oik.css contains styles for oik shortcodes. It is embedded if not specifically excluded. |
| 69 |
* $customCSS is embedded only if selected on oik options |
| 70 |
* If you want some of oik.css then copy the contents into custom.css and exclude oik.css |
| 71 |
* |
| 72 |
* Note: bwlink.css contains styles for the bobbingwide and oik branding colours |
| 73 |
* It is now only enqueued by the oik-bob-bing-wide plugin |
| 74 |
* |
| 75 |
*/ |
| 76 |
function oik_enqueue_stylesheets() { |
| 77 |
$oikCSS = bw_get_option( 'oikCSS' ); |
| 78 |
// bw_trace2( $oikCSS, "oikCSS" ); |
| 79 |
if ( !$oikCSS ) { |
| 80 |
wp_enqueue_style( 'oikCSS', WP_PLUGIN_URL . '/oik/oik.css' ); |
| 81 |
} |
| 82 |
$customCSS = bw_get_option( 'customCSS' ); |
| 83 |
if ( !empty( $customCSS) ) { |
| 84 |
$customCSSurl = get_stylesheet_directory_uri() . '/' . $customCSS; |
| 85 |
// bw_trace( $customCSSurl, __FUNCTION__, __LINE__, __FILE__, "customCSSurl"); |
| 86 |
wp_register_style( 'customCSS', $customCSSurl ); |
| 87 |
wp_enqueue_style( 'customCSS' ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Implement the 'init' action |
| 93 |
* |
| 94 |
* start oik and let oik dependent plugins know it's OK to use the oik API |
| 95 |
*/ |
| 96 |
function oik_main_init() { |
| 97 |
add_action( 'admin_menu', 'oik_admin_menu' ); |
| 98 |
add_action( "activate_plugin", "oik_load_plugins" ); |
| 99 |
add_action( 'network_admin_menu', "oik_network_admin_menu" ); |
| 100 |
add_action( "network_admin_notices", "oik_network_admin_menu" ); |
| 101 |
add_action( "admin_bar_menu", "oik_admin_bar_menu", 20 ); |
| 102 |
add_action( 'login_head', 'oik_login_head'); |
| 103 |
bw_load_plugin_textdomain(); |
| 104 |
/** |
| 105 |
* Tell plugins that oik has been loaded. |
| 106 |
* |
| 107 |
* This allows plugins which are dependent upon oik to start using the oik APIs |
| 108 |
* It doesn't mean that all the APIs are available. |
| 109 |
*/ |
| 110 |
do_action( 'oik_loaded' ); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Implement the 'admin_menu' action |
| 115 |
* |
| 116 |
* Note: This action comes before 'admin_init' and after '_admin_menu' |
| 117 |
*/ |
| 118 |
function oik_admin_menu() { |
| 119 |
require_once( 'admin/oik-admin.inc' ); |
| 120 |
oik_options_add_page(); |
| 121 |
add_action('admin_init', 'oik_admin_init' ); |
| 122 |
do_action( 'oik_admin_menu' ); |
| 123 |
add_action('admin_enqueue_scripts', 'oik_enqueue_stylesheets', 11 ); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Implement the 'network_admin_menu'/'network_admin_notices' action for multisite |
| 128 |
* |
| 129 |
* network_admin_menu is used to determine if plugins need updating |
| 130 |
* network_admin_notices is used in plugin dependency checking |
| 131 |
*/ |
| 132 |
function oik_network_admin_menu() { |
| 133 |
static $actioned = null; |
| 134 |
if ( !$actioned ) { |
| 135 |
$actioned = current_filter(); |
| 136 |
require_once( 'admin/oik-admin.inc' ); |
| 137 |
oik_options_add_page(); |
| 138 |
add_action('admin_init', 'oik_admin_init' ); |
| 139 |
do_action( 'oik_admin_menu' ); |
| 140 |
} else { |
| 141 |
bw_trace2( $actioned, "actioned" ); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Implement 'admin_init' action |
| 147 |
*/ |
| 148 |
function oik_admin_init() { |
| 149 |
oik_options_init(); |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Add the custom image link using the same method as the Portfolio slideshow plugin which used the method documented here: |
| 154 |
* @link http://wpengineer.com/2076/add-custom-field-attachment-in-wordpress/ |
| 155 |
* |
| 156 |
* This is the method that adds fields to the form. Paired with 'attachment_fields_to_save' |
| 157 |
* |
| 158 |
* Note: Although this filter is only invoked during image editing |
| 159 |
* ( in admin processing ) it can't be registered during admin_init / admin_menu |
| 160 |
* since it's not invoked that way |
| 161 |
* i.e. Don't move the add_filter() logic for this filter. |
| 162 |
*/ |
| 163 |
function oik_attachment_fields_to_edit( $form_fields, $post) { |
| 164 |
$form_fields['bw_image_link'] = array( |
| 165 |
"label" => __( "oik custom image link URL", "oik" ), |
| 166 |
"input" => "text", |
| 167 |
"value" => get_post_meta( $post->ID, "_bw_image_link", true ) |
| 168 |
); |
| 169 |
// This doesn't work since the url uses the [html] field instead of [value] |
| 170 |
// $form_fields['url']['value'] = get_post_meta( $post->ID, "_oik_nivo_image_link", true ); |
| 171 |
return $form_fields; |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Save the "oik custom image link URL" |
| 176 |
* |
| 177 |
* We save the value even if it's blanked out. |
| 178 |
* Note: The custom meta field is prefixed with an underscore but the field name is not. |
| 179 |
* Paired with 'attachment_fields_to_edit' |
| 180 |
* |
| 181 |
* See also comments for oik_attachment_fields_to_edit() |
| 182 |
*/ |
| 183 |
function oik_attachment_fields_to_save( $post, $attachment) { |
| 184 |
$link = bw_array_get( $attachment, "bw_image_link", null ) ; |
| 185 |
update_post_meta( $post['ID'], '_bw_image_link', $link ); |
| 186 |
return $post; |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Implement "admin_bar_menu" action for oik |
| 191 |
* |
| 192 |
* We implement this first for the whole site... |
| 193 |
* @TODO but allow each user to override it in oik-user? |
| 194 |
* |
| 195 |
* This action hook runs after other action hooks to alter the "Howdy," prefix for 'my-account' |
| 196 |
* Most howdy replace plugins look for the string "Howdy," so the code won't work if the string has already been translated |
| 197 |
* We look for the translated version, which includes the user's display name. |
| 198 |
* So this logic should work localized versions. |
| 199 |
* |
| 200 |
* The structure we're changing is the node for 'my-account' |
| 201 |
* e.g. |
| 202 |
[id] => my-account |
| 203 |
[parent] => top-secondary |
| 204 |
[title] => Howdy, vsgloik<img alt='' onerror='this.src="http://qw/wordpress/wp-content/themes/rngs0721/images/no-avatar.jpg"' src='http://1.gravatar.com/avatar/1c32865f0cfb495334dacb5680181f2d?s=26&d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D26&r=G' class='avatar avatar-26 photo' height='26' width='26' /> |
| 205 |
[href] => http://qw/wordpress/wp-admin/profile.php |
| 206 |
[meta] => Array |
| 207 |
( |
| 208 |
[class] => with-avatar |
| 209 |
[title] => My Account |
| 210 |
) |
| 211 |
* |
| 212 |
* @param WP_Admin_Bar $wp_admin_bar - the WP_Admin_Bar object |
| 213 |
* |
| 214 |
*/ |
| 215 |
function oik_admin_bar_menu( &$wp_admin_bar ) { |
| 216 |
$replace = bw_get_option( "howdy" ); |
| 217 |
if ( $replace ) { |
| 218 |
$node = $wp_admin_bar->get_node( 'my-account' ); |
| 219 |
$current_user = wp_get_current_user(); |
| 220 |
$howdy = sprintf( __('Howdy, %1$s'), $current_user->display_name ); |
| 221 |
//bw_trace2( $node, "node" ); |
| 222 |
$replace = $replace . " " . $current_user->display_name; |
| 223 |
$node->title = str_replace( $howdy, $replace, $node->title ); |
| 224 |
$wp_admin_bar->add_node( $node ); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Implement "login_head" action for oik |
| 230 |
* |
| 231 |
* Will use the user defined logo image as the login logo, if required |
| 232 |
* |
| 233 |
*/ |
| 234 |
function oik_login_head() { |
| 235 |
oik_require( "shortcodes/oik-logo.php" ); |
| 236 |
oik_lazy_login_head(); |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* Initiate oik processing |
| 241 |
*/ |
| 242 |
oik_plugin_file_loaded(); |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|