I have custom post type named soto_property in which I have added three wp_editor as post meta, using this code -
wp_editor( htmlspecialchars_decode($valueeee1),
'propertyEditor1',
$settings = array('textarea_name'=>'detail',
'editor_class'=>'propertyEditor')
);
wp_editor( htmlspecialchars_decode($valueeee2),
'propertyEditor2',
$settings = array('textarea_name'=>'features',
'editor_class'=>'propertyEditor')
);
wp_editor( htmlspecialchars_decode($valueeee3),
'propertyEditor3',
$settings = array('textarea_name'=>'text_to_pdf',
'editor_class'=>'propertyEditor')
);
Now I have installed qtranslate plugin to make my site Multilingual. This plugin automaticaly add Language tab in its default content editor. I want to add these languages tabs in my custom editor also, so it can save content in defined languages.
How can I do this.? Please help me.
add_filter('soto_property','qtrans_convertURL');
I guess you need to define translatable strings. Check this page in codex for more details.
Updated code should look like this:
$settings = array('textarea_name'=>__('detail', 'your-text-domain'),
'editor_class'=>'propertyEditor')
If it won't work for you, try the following trick.
Here's a code snippet from the last link:
if ( is_admin() && function_exists("qtrans_getSortedLanguages") ) {
add_action('admin_menu', 'enable_qTranslate_Meta');
}
function enable_qTranslate_Meta() {
global $qtransMETA;
$post_types = get_post_types();
/* post and page types are already processed by the plugin */
$disabled_types = array( 'post', 'page', 'attachment', 'revision', 'nav_menu_item' );
$enabled_types = array_diff( $post_types, $disabled_types );
if ( $enabled_types ) {
foreach( $enabled_types as $enabled_type ) {
add_meta_box(
'qtrans_meta_meta_box', //HTML id
__('Multilingual META', 'qtranslate-meta'), //title
array(&$qtransMETA, 'meta_box_generate'), //callback
$enabled_type, //type
'normal', //context - normal, advanced, side
'high' //priority - high, low
);
}
}
}
Solved!
I have used qranslate-x plugin which makes my custom wp_editor translatable on my custom post type page.
Related
I develop my first plugin, which creates some pages programatically by this method:
$page_id = wp_insert_post(
array(
'comment_status' => 'close',
'ping_status' => 'close',
'post_author' => 1,
'post_title' => 'HSN Form',
'post_name' => strtolower(str_replace(' ', '-', trim('hsn-form'))),
'post_status' => 'publish',
'post_type' => 'page',
)
);
And I set template file for it:
add_filter( 'page_template', 'hsn_service_form_page_template', 10, 1 );
function hsn_service_form_page_template( $page_template ){
if ( is_page( 'hsn-form' ) ) {
$page_template = plugin_dir_path(__DIR__) . 'service-form/form-template.php';
}
return $page_template;
}
After I would like to hide it completely from wordpress dashboard, but those have to available following way:
wwww.example.com/hsn-form.
I can hide it following code from Pages menu:
add_filter( 'parse_query', 'ts_hide_pages_in_wp_admin' );
function ts_hide_pages_in_wp_admin($query) {
global $pagenow,$post_type;
$page = get_page_by_path('hsn-form');
if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
$query->query_vars['post__not_in'] = array($page->ID);
}
}
It's ok, but it's still available in Appereance->Menu, where you can create nav menus.
I searched for it, but I can't find complete solution for my problem:
My plugin has to create some pages which are available this way: www.example.com/hsn-form
I need to hide this pages completely from admin dashboard
I would like to apply templates for these pages to add some custom php code.
So If somebody should know a complete solution for it, that should be great.
Thank you in advance!
change parse_query to pre_get_posts
In order to remove a page from the admin nav menu, you can hook into the admin_menu action, then manipulate the global $submenu variable.
add_action('admin_menu', function(){
global $submenu;
array_walk($submenu, function(&$child, $parent){
if( $parent != 'edit.php' )
return;
foreach($child as $key=>$submenu){
if( $submenu[2] == 'post-new.php' ) {
unset($child[$key]);
break;
}
}
});
});
In that example, we are looking for a subpage with the slug of post-new.php
underneath the top level page with the slug edit.php. If found, it gets altogether removed from the navigation menu.
The $submenu[2] part is looking for the slug element in the array. If you want to match by the submenu name instead, you can replace it with $submenu[0].
I'm trying to remove a custom metabox that I've created for my plugin using PHP code. It should be removed from all the posts on click of a button.
Here is my code:
<?php
if(isset($_REQUEST['submit_btn']))
{
function remove_custom_metabox()
{
remove_meta_box( 'my-meta-box-id' , 'post' , 'normal' );
}
add_action( 'add_meta_boxes', 'remove_custom_metabox');
}
?>
Why is it not working? And is there any way to do this for multi-post custom meta-box as well? Thanks!
EDIT 1: Just to get more clear idea of what I'm doing, here is how I'm creating the custom meta-box in the main plugin file:
function cd_meta_box_add()
{
add_meta_box(
'my-meta-box-id', //id
'Contributors', //title
'cd_meta_box_cb', //callback
'post', //post type
'normal', //position
'high' //priority
);
}
add_action('add_meta_boxes', 'cd_meta_box_add');
According to documentation you should use the admin_menu hook
To remove custom meta box use action hook admin_menu or do_meta_boxes
/**
* Remove Custom Fields meta box
*/
function wpdocs_remove_post_custom_fields() {
remove_meta_box( 'postcustom' , 'post' , 'normal' );
}
add_action( 'admin_menu' , 'wpdocs_remove_post_custom_fields' );
add_action( 'do_meta_boxes', 'wpdocs_remove_post_custom_fields' );
For more help see this link : click here
I am using WP REST API to retrieve data from my website, for example, from this http: http://localhost:8888/wordpress/wp-json/wp/v2/posts/42 I can the the info of the post 42, but inside the content section, it shows like this
the actual post is in the format:
this is a test blog +[image]+this is a test blog+[image]
all I want from the content section is just the word, not the image's information, what can I do to achieve this?
and what kind of format WP REST API returned for this content section? I read from the website, it said it's "object". I am new to WP.
You need to hook in to rest_api_init and modify how you need the content to be.
add_action( 'rest_api_init', function ()
{
register_rest_field(
'post',
'content',
array(
'get_callback' => 'do_raw_shortcodes',
'update_callback' => null,
'schema' => null,
)
);
});
function do_raw_shortcodes( $object, $field_name, $request )
{
global $post;
$post = get_post ($object['id']);
// This is what we currently have...
$output['rendered'] = apply_filters( 'the_content', $post->post_content);
// This includes the shortcodes
$output['_raw'] = $post->post_content;
// Add something custom
$output['foo'] = 'bar';
return $output;
}
You should then see the extra data in the JSON.
I have a review plugin that overrides the comment form in a specific posttype.
Now I'm trying to seperate the reviews and comments.
My first step is to remove the filter that modifies the current comment template and use that filter inside a second comment form.
The plugin uses this code (simplified)
final class DM_Reviews {
public function hooks() {
do_action_ref_array( 'dm_reviews_before_setup_actions', array( &$this ) );
add_filter( 'comment_form_defaults', array( $this, 'reviews_form' ) );
do_action_ref_array( 'dm_reviews_after_setup_actions', array( &$this ) );
}
public function review_form( $args ) {
$form = 'plugin code to modify form';
return wp_parse_args( $form, $args );
}
}
In my child theme's function.php file, I tried to use this but it didn't worked.
global $DM_Reviews;
remove_filter( 'comment_form_defaults', array($DM_Reviews, 'reviews_form'),1 );
WP Codex
If someone can put me in the right direction on how to solve it, it would help me a lot.
I think you can achieve this goal, using one of the following solutions depending on the way this plugin instantiates the class:
if( class_exists('DM_Reviews' ) ){
//This should work in whatever case, not tested
remove_filter('comment_form_defaults', array( 'DM_Reviews', 'reviews_form'));
//or Instantiating a new instance, not tested
remove_filter('comment_form_defaults', array( new DM_Reviews(), 'reviews_form'));
//or Targeting the specific instance, not tested
remove_filter('comment_form_defaults', array( DM_Reviews::get_instance(), 'reviews_form'));
}
Hope it helps, let me know if you get stuck.
for me remove_filter didn't work from function.php i wanted to remove a specific behavior of a plugin so what i did :
add_action( 'init', 'remove_filters' );
function remove_filters(){
global $wp_filter;
unset( $wp_filter["_filter_name"]);
}
Try this :
$instance = DM_Reviews::this();
remove_filter('comment_form_defaults', array( $instance, 'reviews_form'));
Insert HTML Input to a themes template file?
My question is this:
Currently with my code, I can have whatever I've set in my custom settings page appear on
the end of every post using, of course, a WordPress filter.
The only thing is, I don't want what I input to go anywhere within a post. What I am trying to
achieve, is to have my input injected into the current themes home.php template file, within a <div></div> tag that's contained within that template file. The <div> in question has an ID attached, which is <div id="category-inner">, so is there any way use it's ID to target it in my plugin?
I've successfully managed to do it, by editing the actual home.php template file and inserting a bit of php directly there to show the user input, but that totally goes against what I'm trying to do, which is to not have to edit the source code of the template file and only have to use my plugin to insert the users inputted text in that specific location (the <div> mentioned above).
My plugin is only ever going to be adding user input in one place on the site, and it will never change. And the place it will always go in, is where I mentioned above.
Below is my plugin code:
<?php
/*/
Plugin Name: Custom Text Adder
Plugin URI: N/A
Description: Demonstrates how rubbish I am at pretty much everything I want to do
Version: 101
Author: JD
Author URI: N/A
/*/
// insert custom plugin settings menu
add_action('admin_menu', 'custom_create_menu');
add_filter('the_content', 'customhead_the_content');
function customhead_the_content($content) {
$output = $content;
$output .= '<div id="category-inner">';
$output .= get_option('post_text');
$output .= '</div>';
return $output;
}
// Add Font-Size to WYSIWYG Editor
function wp_editor_fontsize_filter( $options ) {
array_shift( $options );
array_unshift( $options, 'fontsizeselect');
array_unshift( $options, 'formatselect');
return $options;
}
add_filter('mce_buttons_2', 'wp_editor_fontsize_filter');
// Create Custom Menu
function custom_create_menu() {
//create new top-level menu
add_menu_page('Custom Plugin Settings', 'Custom Settings', 'administrator', __FILE__, 'custom_settings_page',plugins_url('/img/icon.png', __FILE__));
//call register settings function
add_action( 'admin_init', 'register_mysettings' );
}
// Register our settings
function register_mysettings() {
register_setting( 'custom-settings-group', 'new_option_name' );
register_setting( 'custom-settings-group', 'some_other_option' );
register_setting( 'custom-settings-group', 'option_etc' );
register_setting( 'custom-settings-group', 'font_size' );
register_setting( 'custom-settings-group', 'post_text' );
}
function custom_settings_page() {
?>
<!-- Custom Settings Page Container -->
<div class="wrap">
<h2>Custom Text</h2>
<form method="post" action="options.php">
<?php settings_fields( 'custom-settings-group' ); ?>
<table class="form-table">
<?php /* Bring the editor onto the page */
wp_editor( '', 'post_text', $settings = array() );
// 4.
// Custom buttons for the editor.
// This is a list separated with a comma after each feature
// eg. link, unlink, bold, ...
$settings = array(
'textarea_name' => 'post_text',
'media_buttons' => true,
'tinymce' => array(
'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
'bullist,blockquote,|,justifyleft,justifycenter' .
',justifyright,justifyfull,|,link,unlink,|' .
',spellchecker,wp_fullscreen,wp_adv'
)
);
submit_button( 'Save everything', 'primary', 'submit' ); ?>
</table>
</form>
</div>
<?php }; ?>
Here is the screenshot which will be able to explain this in the most concise way possible:
http://i.imgur.com/hiEjEsA.jpg
Again, any and all help is hugely appreciated and will hopefully stop my brain from hurting!
You all rock,
Casey. :)
I'm not sure if you want this to be a pure PHP solution, but since you have the ID of the div you could target it with jQuery and insert the text into the div on page load (or form submit) with something like this:
$(document).ready(function() {
var userText = $('#input-id').val();
$('#category-inner').html(userText);
})