Using jQuery thickbox built in Wordpress
Рубрики: Javascript, PHP, Wordpress, jQuery on Oct.17, 2008
To cite an example of how to use the built-in thickbox wordpress when you write a plug-in.
First step: Create a folder “wp_plugin” in the folder “plugins”
Second step: Create a file with the following code ajax.php
- <?php
- define("VP","wp_plugin");
- define("ABSPATH", str_replace("wp-content/plugins/".VP, "", dirname(__FILE__)));
- //The inclusion of these files allows full use of all functions of wordpress
- require_once(ABSPATH.'wp-load.php');
- require_once(ABSPATH.'wp-admin/includes/admin.php');
- if($_GET['options'])
- {
- echo $_GET['options'];
- }
- ?>
Go next step
Third step: Create a file with the following code plugin_example.php
- <?php
- /*
- Plugin Name: WP plugin example
- Plugin URI: http://www.sakrist.com
- Description: Example using thickbox
- Author: www.sakrist.com
- Version: 0.1
- Author URI: Vladimir Boichentsov
- */
- define("VP","wp_plugin");
- define("VP_URL", get_option('home')."/wp-content/plugins/".VP );
- include_js();
- add_action('admin_menu', 'wp_add_page');
- //Add page to menu
- function wp_add_page() {
- add_options_page('Admin Menu', 'Plugin', 'manage_options', VP, 'wp_vp_adminmenu_options_page_includes');
- }
- //Include javascript
- function include_js()
- {
- if($_GET["page"] == VP)
- {
- wp_enqueue_script( 'thickbox', get_option('home').'/wp-includes/js/thickbox/thickbox.js', array ('thickbox'), '3.1-20080430' );
- add_action( 'admin_head', 'helperCSS');
- }
- }
- // CSS style for thickbox
- function helperCSS()
- {
- echo "<link rel='stylesheet' href='".get_option('home')."/wp-includes/js/thickbox/thickbox.css?ver=20080613' type='text/css' media='all' />\n";
- }
- //Main function
- function wp_vp_adminmenu_options_page_includes()
- {
- echo "<a href=\"".VP_URL."/ajax.php?options=ok&type=image&TB_iframe=true\" class=\"thickbox\" title='Example'>Example</a>";
- }
- ?>
It’s easy:)
P.S.: Пишу статью на английском т.к. сам не ищу помощи на русских сайтах, а если нахожу, то в основном все на английском :) Заранее извиняюсь за свой english.

October 18th, 2008 on 2:47 am
Ты наверное хотел сказать “заранее извиняюсь” а не
За ранние извиняюсь?