wrap visual composer element(s) in a shortcode - wordpress

I have some content created with visual composer and I want to wrap some of it in a shortcode like
visual composer elements
[is_mobile]visual composer elements wrapped in shortcode[/is_mobile]
other visual composer elements
please how can it be done? thanks

I believe you need to "register" your shortcodes with Visual Composer. Having unregistered shortcodes confuses Visual Composer; it doesn't really know what to do with them, so it ignores them or does weird things with them (in my case, the content I was trying to wrap in an unregistered shortcode ended up at the top of the page).
So in the following:
name shows in the grid of Visual Composer elements when you are editing a page. You also use it to add your shortcode to the VC Container class (WPBakeryShortCodesContainer).
base is your shortcode's name -- in your example that is is_mobile
as_parent indicates which shortcodes your container can accept as children. I have it set to "except" nothing -- meaning it accepts all Visual Composer shortcodes as children. You can also set it to "only" and list out specific shortcodes you'd like to allow as children (for example if you only wanted to allow people to show or hide an image gallery).
And stuff that didn't matter for me: I'm not really sure why, but I was able to use is_container as true OR false. It made no difference in my situation. show_settings_on_create and content_element are probably irrelevant to your purposes but if you want to know more, they are explained here on VC documentation for vc_map.
This registers your shortcode with Visual Composer:
vc_map( array(
"name" => __("Is Mobile", "my-text-domain"),
"base" => "is_mobile", // your shortcode name
"as_parent" => array('except' => ''), // Use only|except attributes to limit child shortcodes (separate multiple values with comma)
"content_element" => true,
"show_settings_on_create" => false,
"is_container" => true,
"params" => array(
// you can add params same as with any other content element
// i didn't have any options to add onto my element; i was just trying
// to show or hide content based on WP conditions irrelevant to VC
),
"js_view" => 'VcColumnView'
) );
And this makes your shortcode act as a container (i.e., accept other VC elements as children) by extending the default VC container shortcode class. It seems to use the name from the above snippet as the connection.
if ( class_exists( 'WPBakeryShortCodesContainer' ) ) {
class WPBakeryShortCode_Is_Mobile extends WPBakeryShortCodesContainer {
}
}
This page on VC documentation helped me figure this out, though it's fairly sparse.

Related

WordPress Gutenberg, update post content programmatically

I have been starting to testing out Gutenberg editor with both ACF and custom blocks. And I have been looking around to solve my problem but I couldn't find anything about this topic (Maybe my google skills is not good enought)
But my case is this:
I have a custom post type where I want to set a template so they can't move around the blocks and add other blocks and so on. And on this post type around 70% is created by code. Because it is fetching all the information from an API.
Test 1: I have created an ACF block with all the fields I need, and it is working as it should when I create a new post from WP admin. But when I run the update_field function it is saving it to post_meta table as it did before. So my question here is how do I update a field so it saves it to post_content and not to post_meta table.
Test 2: I created custom blocks for all of the fields (convert each ACF field to and block) and set up the template to use these blocks only.
But here I have no idea how update update post_content with PHP or Javascript.
I hope you can help me out with this :) If anything is unclear tell, and I will try to explain it
ACF has an ability to pre-init fields before post will be visible to user on post creation page. You can try to use this function to set desired content to fields.
You can read about this here:
https://www.advancedcustomfields.com/resources/acf-prepare_field/
As of Wordpress 5.0.0
You can use template and template_lock arguments upon registering your custom post type.
Source # https://developer.wordpress.org/reference/functions/register_post_type/#changelog
You can then set an array of specific blocks to use and you can chose to restrict users from adding new blocks or removing them.
Attribute
Description
template
(array) Array of blocks to use as the default initial state for an editor session. Each item should be an array containing block name and optional attributes.
template_lock
(string/false) Whether the block template should be locked if $template is set. If set to 'all', the user is unable to insert new blocks, move existing blocks and delete blocks. If set to 'insert', the user is able to move existing blocks but is unable to insert new blocks and delete blocks. Default false.
A short example would be something along the lines of...
<?php
$args = [
//...
'template_lock' => 'all',
'template' => [
[ 'core/paragraph' ],
[ 'core/file' ],
//...
],
//...
];
register_post_type( $post_type, $args );
?>
Currently, Gutenberg documentation is scarced, you can find a complete list of blocks & parameters # https://github.com/WordPress/gutenberg/tree/master/packages/block-library/src
Gutenberg is still in development, some features don't act as they should.

Wordpress wp_editor won't add image

I have the following code inside a plugin in a loop, so there are multiple WYSIWYG editors:
<?php wp_editor( stripslashes($arr['item-content']), $key.'-item-content', array(
'editor_class' => 'tsort-contarea',
'media_buttons' => true,
'editor_height' => 360,
) ); ?>
When adding an image, the XHR request labelled send-attachment-to-editor inside wp-includes/js/media-editor.js has a wp.media.view.settings.post.id of 0. Also, wp.media.view.settings.nonce.sendToEditor is always this value: e8b2eea867
return wp.media.post( 'send-attachment-to-editor', {
nonce: wp.media.view.settings.nonce.sendToEditor,
attachment: options,
html: html,
post_id: wp.media.view.settings.post.id
});
The xhr request fires off fine, but doesn't add to any of the WYSIWYG. I'm sure that's because the post_id isn't set or because the nonce is not unique. What can I do to make this work? The Media Manager works absolutely fine on content pages.
Source file: http://pastebin.com/BhvqBLGB
From Codex:
Note that the ID that is passed to the wp_editor() function can only
be composed of lower-case letters. No underscores, no hyphens.
Anything else will cause the WYSIWYG editor to malfunction. (As of
3.6.1 you can use underscores in the ID.)
From what I see you are currently using a dash. Try changing that, and see how that works.
You should check thoroughly for the wp.media.view.settings.post.id is 0 part, as I tried to reproduce the bug in metabox with multiple editors and I get post-id for the new post equal to non-zero (which is actually an auto-draft record in wp_posts table), image assignment is working properly for this case.
I believe there is something wrong with saving new post as auto-draft in your instance of WordPress (might be because of some plugin/theme)

How to add id to an element in visual composer

I've been trying to figure out how to add an ID to a visual composer element, but I can't figure out how to do so. I've tried editing the row, but the only options I have are Custom CSS Class, Parallax, Full Width and Font Color, but no ID everywhere. I've tried putting id="something" and Id="something" into the shortcode with no good luck.
I need to do this in order to make links to some rows within the same page. If there's another workaround to that, I'm eager to know.
Thanks in advance for any response.
el_id
Use el_id='something'.
Shortcode example:
[vc_row el_id='something'] CONTENT [/vc_row]
It wil be generated like this into the DOM:
<div id="something" class="vc_row wpb_row vc_row-fluid">
I had to solve it also, what I did was to create an "Raw html" module, and add the ID on it:
<div id="section"><div>
and place it above the section you want to link to.
Hope it helps!
This work for me: for add a id to row you can aloso add this code in your function.php theme file:
$attributes = array(
'type' => 'textfield',
'heading' => "HTML ID",
'param_name' => 'element_id',
'value' => '',
'description' => __( "Assign an ID to the row", "discprofile" )
);
vc_add_param( 'vc_row', $attributes );
After if you edit a row you find a new input element titled Html ID.
Source: https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524335
Visual Composer now has a Row ID field. Since v4.5 I believe.
If you are using theme or plugin-specific shortcodes to display content, you are at the mercy of the developer as to whether you can specify an ID. If there's no option for it, there's no good way to add one without modifying the functions of the theme or shortcode.
One workaround could be to do the following:
Set up the shortcode like usual, with all the correct settings other than the ID you want.
View the page. View the source of the page and find the element that was generated by that shortcode.
Copy and paste the rendered code into the TEXT editor in the backend. Add an ID to the element manually. Remove the old shortcode to prevent duplicate data.
You won't be able to easily change shortcode settings, but in a pinch it should work!
This feature is present in some themes like JUPITER but absent in most.
A quick way to achieve this is to use the RAW HTML visual composer element instead of the shortcode options box you were using.
Is verry easy if you want to add with php, for example:
we can do in vc_map function this:
array(
'type' => 'textfield',
'heading' => __( 'ID', 'ezrapp_tech_widget' ),
'param_name' => 'id_item',
'value' => uniqid(),
)
and now have generated uniquie id, but not this was my question.

Disabling some buttons from wp_editor

I use tinyMce editor in meta boxes of Wordpress by the following line of code, I want to remove some buttons when I use there. I don't want to affect the main editor. I know how to remove some buttons, which is told here.
My question is, is it possible to disable some buttons (e.g. more) when I call editor with wp_editor. I checked its manual, arguments doesn't seem to support this.
wp_editor( $careers_settings["description"], "editor", array("media_buttons"=>FALSE, "textarea_name"=>"description", "textarea_rows"=>5) );
Thank you.
I guess it's a bit late to answer but in case it might be useful for someone. Since Tinymce 4, "toolbar1" must be used and "teeny" must be set as false to modify buttons :
wp_editor(
'id',
'value',
array(
'teeny'=>false,
'media_buttons'=>false,
'tinymce' => array(
'toolbar1' => 'bold, italic, underline,|,fontsizeselect',
'toolbar2'=>false
),
)
);
Also I added "toolbar2" to the array. I realized that although I only set toolbar1, additional buttons still appear in some cases. Setting toolbar2 as false will remove default buttons on the second buttons row.
You should check the referenced manual again - it's possible to have tinymce as parameter and pass an array of configuration options, e.g. like
wp_editor($value, "input...", array(
'tinymce' => array( .. //tinymce configuration options here )
))
Haven't tried it out, but it should work like that.

Anyone know how to add a field or column to the /ADMIN/CONTENT listing page? DRUPAL 7

I would like to add a field / column to the Content Administration Overview page but it appears the easiest theme override to do this has been deprecated with D7.
In D6 I could just override the method:
theme_node_admin_nodes($form)
But this method no longer exists for D7. What's the equivalent replacement or do I actually need to hook into node_admin_nodes() now and modify the form directly?
For me it was super easy with these two modules:
views bulk operations (VBO)
administration views (needs VBO)
As soon as both modules are installed and activated you can go to your views (admin/structure/views) where now 3 additional views appear (Administration comments, Administration nodes, Administration users). You then just need to edit the view "Administration nodes", where you can add and arrange everything you want as usually with views.
I wanted to add a column displaying all content's nids. Worked super well!
You'll have to hook into the form, the theme element has been completely removed node_admin_nodes() in Drupal 7.
It's actually node_admin_content() that you'll need to hook into as node_admin_nodes() is no longer a form function, it just builds up elements that are used by node_admin_content().
Fortunately the elements in node_admin_nodes() and node_filter_form() (the two functions used in node_admin_content() to build up the page) are nicely structured and will be very easy to override.
I've been able to add an element to the bottom of the table. Although I am unsure how you ADD a coloumn into the body of the table?
function seven_form_alter(&$form, &$form_state, $form_id) {
drupal_set_message("Form ID is : " . $form_id);
//get node_admin_content
//$nodeAdmin = drupal_get_form("node_admin_content");
// Add a checkbox to registration form about agreeing to terms of use.
$form['node_admin_content']['poland'] = array(
'#type' => 'checkbox',
'#title' => t("I agree with the website's terms and conditions."),
'#required' => TRUE,
);
}
The Administration Views module replaces a lot of admin listings with real views (as in Views module) that you can edit and configure any way you want it.

Resources