I want to integrate Option Tree framework with Wordpress theme without installing and activating plugin then how to do it ?
Since version 2.0 the plugin developer has included a number of filters that can be used in your functions.php. These include Theme Mode, and the comments within ot-loader.php state;
* For developers: Theme mode.
*
* Run a filter and set to true to enable OptionTree theme mode.
* You must have this files parent directory inside of
* your themes root directory. As well, you must include
* a reference to this file in your themes functions.php.
* #since 2.0
*/
define( 'OT_THEME_MODE', apply_filters( 'ot_theme_mode', false ) );
To activate Options Tree in your theme rather than as a plugin you include all the plugin files in the theme's root directory, ie
/wp-content/themes/my-awesome-theme/options-tree
and in functions.php you'd run this filter and then include the ot-loader.php file. I've shown this below, and I have also shown the show_pages filter;
add_filter( 'ot_theme_mode', '__return_true' );
add_filter( 'ot_show_pages', '__return_true' );
require_once ('option-tree/ot-loader.php');
The show_pages filter is useful because after you have set up your theme and your options you would then go in and set it to false so the client isn't given the main Options Tree admin menu and therefore can't start 'tinkering' and trash everything. You change it to;
add_filter( 'ot_show_pages', '__return_false' );
For anyone using a child theme and getting "failed to open stream" errors when using the OptionTree plugin in Theme Mode, do the following:
ot-loader.php, around line 128, change this:
if ( false == OT_THEME_MODE ) {
define( 'OT_DIR', plugin_dir_path( __FILE__ ) );
define( 'OT_URL', plugin_dir_url( __FILE__ ) );
} else {
define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
}
To this:
if ( false == OT_THEME_MODE ) {
define( 'OT_DIR', plugin_dir_path( __FILE__ ) );
define( 'OT_URL', plugin_dir_url( __FILE__ ) );
} elseif ( is_child_theme() ) {
define( 'OT_DIR', trailingslashit( get_stylesheet_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_stylesheet_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
} else {
define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
}
The code checks if the theme in use is a child theme ( is_child_theme() ) and sets the dir and url using get_stylesheet_directory() and get_stylesheet_directory_uri().
Hope this helps out anyone else running into this issue.
It's really easy to integrate option tree :
Visit link below if you like to use it using same plugin slug:
Using same plugin slug
Or you can ingrate it in custom folder on your WordPress theme:
Using custom folder
Video Guide here (3:44 Sec):
Video Guide
add_filter('ot_show_pages','__return_false');
include_once('inc/theme-options.php');
Export setting in theme-options.php file.
add_filter('ot_theme_mode','__return_true');
require( trailingslashit( get_template_directory() ) . 'theme-option/ot-loader.php' );
add_filter('ot_show_new_layout','__return_false');
Related
I am applying specific styles in Worpdress when I access a certain URL, for example:
misiito.com/?mobile
When I enter there I hide the header and footer. My code is the following:
if ( isset( $_GET['mobile'] ) ) {
wp_enqueue_style( 'adaptabilidad', plugins_url( 'css/mobile.css', __FILE__ ), array(), '1.0.0' );
}
if ( isset( $_GET['totem'] ) ) {
wp_enqueue_style( 'adaptabilidad', plugins_url( 'css/totems.css', __FILE__ ), array(), '1.0.0' );
}
My problem is that it doesn't change the links and places the /?mobile, please help me, how can I do it?
That is, I want all the buttons at the end to have /?mobile
I tried this, but it's obviously a bug:
add_filter( 'the_content', 'adaptabilidad_nattule_add_mobile_url' );
function adaptabilidad_nattule_add_mobile_url( $content ) {
$content = str_replace( 'href="', 'href="?mobile', $content );
return $content;
}
It's just a suggestion, but have you thought of creating duplicate pages (for each styles) with different URL slugs and simply using a plugin like "Simple 301 Redirects" to associate them with a "/something"?
Example:
yousite.com/page1-style2
yousite.com/page1-style27
I have developed 2 Wordpress plugins and I'm trying to load the needed css and js files in admin only where I need them.
I have written a function:
function ds_shortcodes_enqueue() {
$shortcodes_pages = array(
"shortcodes_plugin",
"add_shortcode",
"edit_shortcode"
);
$the_page = isset($_GET['page']);
if(in_array($the_page,$shortcodes_pages)){
// enqueue all our scripts
wp_enqueue_style( 'ds-shortcodes-style', plugins_url( '/admin/css/shortcodes-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-shortcodes-script', plugins_url( '/admin/js/shortcodes-scripts.js', __FILE__ ) );
}
}
add_action( 'admin_enqueue_scripts', 'ds_shortcodes_enqueue' );
The function shoud load the files only on the pages with the slugs mentioned in the array.
Then, I have written a second plugin. Different name, different text domain, different functionality and I have used the same function:
function ds_videos_enqueue() {
$videos_pages = array(
"videos_plugin",
"add_video",
"edit_video",
"edit_video_category",
"video_categories",
"edit_video_level",
"video_levels",
"video_shortcode"
);
$current_page = isset($_GET['page']);
if(in_array($current_page,$videos_pages)){
wp_enqueue_style( 'ds-videos-style', plugins_url( '/admin/css/videos-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-videos-script', plugins_url( '/admin/js/videos-scripts.js', __FILE__ ) );
}
}
add_action( 'admin_enqueue_scripts', 'ds_videos_enqueue' );
Now here's the problem.
They load the files from both plugins on any plugin page in admin.
I just don't get it.
I couldn't find any way to fix this.
It seems in_array() returns always true.
I hope you can help.
Thank you.
admin_enqueue_scripts passes a page hook to the callback function.
So, you can do something like this,
function ds_shortcodes_enqueue($hook) {
if($hook != 'page_where_you_want_scripts') {
return;
}
wp_enqueue_style( 'ds-shortcodes-style', plugins_url( '/admin/css/shortcodes-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-shortcodes-script', plugins_url( '/admin/js/shortcodes-scripts.js', __FILE__ ) );
}
add_action( 'admin_enqueue_scripts', 'ds_shortcodes_enqueue' );
Reference
I have also tried this but the in_array doesn't seem to work.
function ds_shortcodes_enqueue() {
$shortcodes_pages = array(
"shortcodes_plugin",
"add_shortcode",
"edit_shortcode"
);
if(in_array("shortcodes_plugin", $shortcodes_pages)){
// enqueue all our scripts
wp_enqueue_style( 'ds-shortcodes-style', plugins_url( '/admin/css/shortcodes-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-shortcodes-script', plugins_url( '/admin/js/shortcodes-scripts.js', __FILE__ ) );
}
add_action( 'admin_enqueue_scripts', 'ds_shortcodes_enqueue' );
It should enqueue the 2 files only on the page with the slug "shortcodes_plugin". It loads the files everywhere.
There is a global variable in wp-admin called $pagenow which holds name of the current page, ie edit.php, post.php, etc.
You can also check the $_GET request to narrow your location down further, for example:
function ds_shortcodes_enqueue() {
$shortcodes_pages = array(
"shortcodes_plugin",
"add_shortcode",
"edit_shortcode"
);
if ( isset($_GET['page']) ) {
global $pagenow;
if(in_array($pagenow,$shortcodes_pages)){
// enqueue all our scripts
wp_enqueue_style( 'ds-shortcodes-style', plugins_url( '/admin/css/shortcodes-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-shortcodes-script', plugins_url( '/admin/js/shortcodes-scripts.js', __FILE__ ) );
}
}
}
add_action( 'admin_enqueue_scripts', 'ds_shortcodes_enqueue' );
function ds_videos_enqueue() {
$videos_pages = array(
"videos_plugin",
"add_video",
"edit_video",
"edit_video_category",
"video_categories",
"edit_video_level",
"video_levels",
"video_shortcode"
);
if ( isset($_GET['page']) ) {
global $pagenow;
if(in_array($pagenow,$videos_pages)){
wp_enqueue_style( 'ds-videos-style', plugins_url( '/admin/css/videos-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-videos-script', plugins_url( '/admin/js/videos-scripts.js', __FILE__ ) );
}
}
}
add_action( 'admin_enqueue_scripts', 'ds_videos_enqueue' );
It seems in_array() returns always true.
<?php
$videos_pages = array(
'videos_plugin',
'add_video',
'edit_video',
'edit_video_category',
'video_categories',
'edit_video_level',
'video_levels',
'video_shortcode'
);
$current_page = isset($_GET['page']);
if(in_array($current_page,$videos_pages,true)){
echo 'I am debug point';
}else{
echo 'I am debug point 2';
}
exit;
?>
My plugin name is eventcal.Textdomain is eventcal. I have a language pack in /languages/ folder - eventcal-pt_BR.po and eventcal-pt_BR.mo. I have added plugin textdomain function
public static function eventcalLoadTextdomain() {
load_plugin_textdomain( 'eventcal', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
// in __constructor()
add_action( 'init', array(self::getInstance(), 'eventcalLoadTextdomain' ));
but its not working when i am changing my site language to portugese( Brazil )
Nothing is changing.everything is in english. How can i check plugin textdomain is working or not??
I also tried get_plugin_data( __FILE__ ); but not working
How do I load the .mo translate file to the back end of the plugin?
This only for front end:
function my_plugin_load_plugin_textdomain()
{
load_plugin_textdomain( 'my_plgin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'my_plugin_load_plugin_textdomain' );
I have a WordPress site that I am moving to a Media Temple Grid Server from another provider. I have WordPress in its own 'wp' directory so I can update it independent of the rest of my codebase.
After uploading all the files, I went to my site's URL, expecting that WordPress would start its install process, but instead, it redirects from http://example.com to http://example.com/wp-admin/install.php, and the browser gives me a "too many redirects" error message.
Other things:
The database is created
The .htaccess file has all the WordPress rules
Here's my wp-config.php:
<?php
// ===================================================
// Load database info and local development parameters
// ===================================================
if ( file_exists( dirname( __FILE__ ) . '/wp-config-local.php' ) ) {
define( 'WP_LOCAL_DEV', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
require( 'wp-config-local.php' );
} elseif ( file_exists( dirname( __FILE__ ) . '/wp-config-staging.php' ) ) {
define( 'WP_LOCAL_DEV', false );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
require( 'wp-config-staging.php' );
} elseif ( file_exists( dirname( __FILE__ ) . '/wp-config-production.php' ) ) {
define( 'WP_LOCAL_DEV', false );
define( 'WP_DEBUG', false );
require( 'wp-config-production.php' );
}
// ========================
// Custom Content Directory
// ========================
define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );
// ================================================
// You almost certainly do not want to change these
// ================================================
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
// ==============================================================
// Salts, for security
// Grab these from: https://api.wordpress.org/secret-key/1.1/salt
// ==============================================================
define('AUTH_KEY', '+jw|C|KUKW4.&062<MjcDr/a95AOdg$tH5N^7-arnWXWD$V=5+RUUe-#YNW<~INo');
define('SECURE_AUTH_KEY', 'Tu?%#u{.<-9^8Qi+wtB-X;5`-b!(4U)#:B`4?~-R,.,H~kTyCRX#b[Rf#V9m/,DW');
define('LOGGED_IN_KEY', 'Kf_!-|N|kII`+:j7x2~QBQR_nVQ/ uvCPif/$|wk})lm YR{Y^8qji/X![jljpE]');
define('NONCE_KEY', 'YA+GiHY&N<)Gh`f-KR 0+BF4I]jP-Tn.b+V-Z1+}/P!B+:Lfr~(qB(u$_QCaUFM6');
define('AUTH_SALT', 'U96${|%&HN-l)aP.*.#ZK2&nIp#l~3X0-{Rx$Fgll4oY&-YM/UVw9bf<Tyk=S#v>');
define('SECURE_AUTH_SALT', '>f-^11d$V|M#bm2K.Rzk1i=H+Ykpv`9lVgsBd+}W5&#rS_!k=EZsy0-]&S3!sNk[');
define('LOGGED_IN_SALT', '#2iH05hI2h87P:a!}`jsqH3>E#q0g)|Ns9g{T;($S%,n>+dP)W-l9{#whhnib:1Q');
define('NONCE_SALT', '_I90W[ST<|bmKC<i*J.-tq+R+wqyAkUd-~33*E?k!:%O3)rRZ~yc-PpVA<R+OcTR');
// ==============================================================
// Table prefix
// Change this if you have multiple installs in the same database
// ==============================================================
$table_prefix = 'wp_';
// ================================
// Language
// Leave blank for American English
// ================================
define( 'WPLANG', '' );
// ===========
// Hide errors
// ===========
ini_set( 'display_errors', 0 );
define( 'WP_DEBUG_DISPLAY', false );
// =================================================================
// Debug mode
// Debugging? Enable these. Can also enable them in local-config.php
// =================================================================
// define( 'SAVEQUERIES', true );
// define( 'WP_DEBUG', true );
// ======================================
// Load a Memcached config if we have one
// ======================================
if ( file_exists( dirname( __FILE__ ) . '/memcached.php' ) )
$memcached_servers = include( dirname( __FILE__ ) . '/memcached.php' );
// ===========================================================================================
// This can be used to programatically set the stage when deploying (e.g. production, staging)
// ===========================================================================================
define( 'WP_STAGE', '%%WP_STAGE%%' );
define( 'STAGING_DOMAIN', '%%WP_STAGING_DOMAIN%%' ); // Does magic in WP Stack to handle staging domain rewriting
// ===================
// Bootstrap WordPress
// ===================
if ( !defined( 'ABSPATH' ) )
define( 'ABSPATH', dirname( __FILE__ ) . '/wp/' );
require_once( ABSPATH . 'wp-settings.php' );
And here's wp-config-production.php:
<?php
/*
This is a sample local-config.php file
In it, you *must* include the four main database defines
You may include other settings here that you only want enabled on your local development checkouts
*/
define( 'DB_NAME', 'db000000_wordpress' );
define( 'DB_USER', 'db000000' );
define( 'DB_PASSWORD', 'some_password' );
define( 'DB_HOST', 'internal-db.s000000.gridserver.com' ); // Probably 'localhost'
Any thoughts on what I'm doing wrong?
Solved this--turns out I had uploaded an .htaccess file from my previous install, and this file was doing some rewriting that was causing the redirect issue.