Drupal hook before or after render() function - drupal

I have a problem with my drupal page. We use the opigno tool (its a module to that allows to create course - nodes which can be bought).
Now we have a problem with the view of the course-node. Everything works fine until a user bought the course and the drupal commerce status is on "pending". The problem now is that the node is showing nothing except the title of the course.
I began to think whats going on and took a look to the view settings for the course-view. Nothing (no Permission was set, no filter criteria ...)
Then I took a look at the template override of the course-view. And then I saw smth ...
print render($content['body']);
Ah! A render function to render the content of the view. So I asked myself: What is in content ?
After printing out the $content variable I saw this:
Array
(
[body] => Array
(
[#theme] => field
[#weight] => 1
[#title] => Description
[#access] =>
[#label_display] => hidden
[#view_mode] => full
[#language] => und
[#field_name] => body
[#field_type] => text_with_summary
[#field_translatable] => 0
[#entity_type] => node
[#bundle] => course
[#object] => stdClass Object
(
[vid] => 185
[uid] => 60
[title] => Demo Course
[log] =>
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[vuuid] => 16e7999b-28bb-4f3e-8bed-54a21b17f398
[nid] => 176
[type] => course
[language] => und
[created] => 1406897520
[changed] => 1407145285
[tnid] => 0
[translate] => 0
[uuid] => 22baf19a-dc32-4137-b698-89f1bb4adc59
[revision_timestamp] => 1407145285
[revision_uid] => 1
[body] => Array
(
[und] => Array
(
[0] => Array
(
[value] =>
This is a sample course for beta testers, it will show you the structure of the courses.
Here usually is displayed the description of the course.
Please "enroll" if you want to see the contents of this demo course.
[summary] => This is a sample course for beta testers to help you see the structure of a course. Please have a look on it!
[format] => html
[safe_value] =>
This is a sample course for beta testers, it will show you the structure of the courses.
Here usually is displayed the description of the course.
Please "enroll" if you want to see the contents of this demo course.
[safe_summary] => This is a sample course for beta testers to help you see the structure of a course. Please have a look on it!
)
)
)
)
Aaah! So $content has the content, but its not printed out with render()! But why ?
I searched in google for a hook which are able to "override" the render function and maybe deny the output when the user is on "pending". But... nothing.
I found this hook:
{hook}_node_view()
I searched for a using of this hook in all modules but when deleteing these functions from the modules did not changed anything. Are there other options to "override" the render() function ? Another hooks I can search for ? Or maybe you had the same problem with opigno ?

I am sorry - the problem was the Opigno Field Access Module. I deactivated it and it works like a charm.

Related

get_the_category() wordpress function stopped working after updating core version

As the title says - i have a single.php template which gets the category of the current post assigned.
$cat_post = get_the_category();
That function returns the category which is assigned to the post. After upgrading from 4.0.24 to 4.9.7 it stopped working. The only thing that comes to my mind is that the function is not supported but i haven't found something about this.
Any ideas?
you can use this
//get category
$category = get_the_category(get_the_ID());
//the above code will return an Array
Array
(
[0] => WP_Term Object
(
[term_id] => 2
[name] => video
[slug] => video
[term_group] => 0
[term_taxonomy_id] => 2
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 1
[filter] => raw
[cat_ID] => 2
[category_count] => 1
[category_description] =>
[cat_name] => video
[category_nicename] => video
[category_parent] => 0
)
)
// you can access this array like this
$catID = $category[0]->term_id;
//for term id
$catName = $category[0]->name;
//for category name
I think you are trying to get a category from the current post which is the custom post type.
As per the documentation of the following function, it doesn't work for the custom post type. You can see it on the link below.
Click here to see the Code Reference
For custom post type, you can use get_the_terms() method. Here is the link of the Code Reference of the function.

Custom Taxonomy Template won't show any menus

This is how I can start describing this, it's a very strange error that maybe something else but this is the first symptom I have.
I have a custom template[taxonomy-location_types.php] that shows, a custom post type [locations] by it's custom taxonomy[location-types].
If you visit the home page you will see a menu editorial, travel, etc.
Now if you look here on this taxonomy page
The menu is gone, there are other queries that aren't firing but I'm focussing on this as a primary issue.
I have generated output from nav-menu-template.php like so:
if ( $menu && !is_wp_error($menu) && !isset($menu_items) )
{
write_log($menu);
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
write_log($menu_items);
}
and I get this:
[31-Aug-2017 15:27:52 UTC] WP_Term Object
(
[term_id] => 2
[name] => Header Menu
[slug] => header-menu
[term_group] => 0
[term_taxonomy_id] => 2
[taxonomy] => nav_menu
[description] =>
[parent] => 0
[count] => 6
[filter] => raw
)
[31-Aug-2017 15:27:52 UTC] Array
(
)
[31-Aug-2017 15:27:52 UTC] WP_Term Object
(
[term_id] => 3
[name] => Footer One
[slug] => footer-one
[term_group] => 0
[term_taxonomy_id] => 3
[taxonomy] => nav_menu
[description] =>
[parent] => 0
[count] => 5
[filter] => raw
)
[31-Aug-2017 15:27:52 UTC] Array
(
)
So it sees the menu but for some reason return no items in either menu.
I have turned off all plugins and still get the same result, I have also eliminated all other queries on this page to see if there was conflict and this still this happens.
Any insight on this one would be great not sure where to look next for issues.
Chalk another one up for RTFM, I had a pre_get_posts hook altering the query and I didn't ensure that the query it was altering was just the $query->is_main_query() because strangely enough this alteration was getting into the nav_menu query.
query monitor is now my new best friend.

WooCommerce API, Variant Sku breaks import

I am importing products with Variations and each variation having its own SKU. However if I include a 'sku' with a Variation, it does not add them, it adds one Variation as 'default value' and not the individual ones. If I exclude the 'sku' field then it works as expected. Yet WooCommerce documentation shows that Variants have a field of 'sku'.
This is what I am sending (With the PHP api handler):
[0] => Array
(
[sku] => BH2057A
[regular_price] => 2.99
[stock_quantity] => 29
[in_stock] => 1
[managing_stock] => 1
[attributes] => Array
(
[0] => Array
(
[name] => Alphabet
[option] => A
)
)
)
This is the variant for 'A', it goes to 'Z'. The attribute is added on the product fine. As I say this works when I do not include the sku line, but breaks when I include it.
Anyone know whats wrong?

How are Wordpress Dynamic Sidebar Widgets rendered?

I have been reading through the Wordpress Source, trying to get a better understanding of how dynamic sidebars are rendered.
However, I am hitting a sticking point...
894 | do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] );
I can't find where add_action('dynamic_sidebar', ... ) is defined. Without that part, I am sort of lost in what happens.
See the code here:
https://github.com/WordPress/WordPress/blob/b7c13e27c255e1fc1f03ab2ab432f1652a0ac212/wp-includes/widgets.php#L894
And to give more context, I am trying to figure out how to grab an array of widgets from a specific sidebar, and from there, I need to know how would you render each widget within that array.
I need finer control than dynamic_sidebar(...); gives me
Well, that specific line permits you to access each registered Widget properties, and it's used like:
<?php
/* Plugin Name: Test registered widgets */
add_action( 'dynamic_sidebar', 'sidebar_widgets_so_18666065' );
/**
* As this is an action hook, we don't return nothing
* use the passed values to do your stuff
*/
function sidebar_widgets_so_18666065( $registered_widget )
{
# Each registered widget passes the following array
/*
$registered_widget = Array
(
[name] => Meta
[id] => meta-2
[callback] => Array
(
[0] => WP_Widget_Meta Object
(
[id_base] => meta
[name] => Meta
[widget_options] => Array
(
[classname] => widget_meta
[description] => Log in/out, admin, feed and WordPress links
)
[control_options] => Array
(
[id_base] => meta
)
[number] => 2
[id] => meta-2
[updated] =>
[option_name] => widget_meta
)
[1] => display_callback
)
[params] => Array
(
[0] => Array
(
[number] => 2
)
)
[classname] => widget_meta
[description] => Log in/out, admin, feed and WordPress links
)
*/
}
Relevant search query at WordPress Answers.

how to render youtube video in drupal

How can I render a YouTube source in Drupal? The field which contains the informations contains this:
[fid] => 59
[display] => 1
[description] =>
[uid] => 1
[filename] => Retarded running giraffe
[uri] => youtube://v/Cn59jVAHLTs
[filemime] => video/youtube
[filesize] => 0
[status] => 1
[timestamp] => 1340129371
[type] => video
[rdf_mapping] => Array
Is there any way to render this information to a YouTube-Video embed code ? Something like this:
drupal_render_youtube('youtube://v/Cn59jVAHLTs');
Is there any solution to solve this without writing the hole embed code by my self ?
These will help...
How to render a Youtube thumbnail in a template in Drupal 7
http://drupal.org/project/mediaelement
Or someting like this:
<?php print render($variables['content']['field_url']['#object']->content['field_video']);?>

Resources