Posts inserted with wp_insert_posts aren't showing up in admin - ajax

I have a particular issue with inserting custom posts with wp_insert_posts.
Circumstances:
WPML
Multisite enabled
Custom post type with name order
Post creation triggered through Ajax from frontend
The post is inserted in the original language, no translations
What have I tried so far
Checked the post type register code to see if it contains any incompatible settings, tried all combinations -> noting. This is what is the closest thing to my problem: wp_insert_post entries not showing in admin content list
The resolution there is not applicable to me, as I execute it through Ajax, and WP is already initialized at the Ajax hook
Went through WPML forums with all their posts related to similar issues, tried the steps provided there (although most of them talk about adding translations)
Tried various other solutions
Post insert code:
$post_id = wp_insert_post([
"post_type" => "order",
"post_content" => "",
"post_title" => $order->Name() . '<' . $order->Email() . '>',
"post_status" => "publish",
"post_author" => 1
]);
update_post_meta($post_id, 'order_details', '{"some":"json here"}');
The post gets inserted in the table, and the listing page in admin shows it in the total counts, but the post doesn't show up in the list itself.
Post type register code
if ( ! function_exists('ls_so_order') ) {
// Register Custom Post Type
function ls_so_order() {
$labels = array(
'name' => _x( 'Orders', 'Post Type General Name', 'ls-simple-order' ),
'singular_name' => _x( 'Order', 'Post Type Singular Name', 'ls-simple-order' ),
'menu_name' => __( 'Orders', 'ls-simple-order' ),
'name_admin_bar' => __( 'ProductOrder', 'ls-simple-order' ),
'archives' => __( 'Order Archives', 'ls-simple-order' ),
'attributes' => __( 'Order Attributes', 'ls-simple-order' ),
'parent_item_colon' => __( 'Parent Order:', 'ls-simple-order' ),
'all_items' => __( 'All Orders', 'ls-simple-order' ),
'add_new_item' => __( 'Add New Order', 'ls-simple-order' ),
'add_new' => __( 'Add New', 'ls-simple-order' ),
'new_item' => __( 'New Order', 'ls-simple-order' ),
'edit_item' => __( 'Edit Order', 'ls-simple-order' ),
'update_item' => __( 'Update Order', 'ls-simple-order' ),
'view_item' => __( 'View Order', 'ls-simple-order' ),
'view_items' => __( 'View Orders', 'ls-simple-order' ),
'search_items' => __( 'Search Order', 'ls-simple-order' ),
'not_found' => __( 'Not found', 'ls-simple-order' ),
'not_found_in_trash' => __( 'Not found in Trash', 'ls-simple-order' ),
'featured_image' => __( 'Featured Image', 'ls-simple-order' ),
'set_featured_image' => __( 'Set featured image', 'ls-simple-order' ),
'remove_featured_image' => __( 'Remove featured image', 'ls-simple-order' ),
'use_featured_image' => __( 'Use as featured image', 'ls-simple-order' ),
'insert_into_item' => __( 'Insert into order', 'ls-simple-order' ),
'uploaded_to_this_item' => __( 'Uploaded to this order', 'ls-simple-order' ),
'items_list' => __( 'Orders list', 'ls-simple-order' ),
'items_list_navigation' => __( 'Orders list navigation', 'ls-simple-order' ),
'filter_items_list' => __( 'Filter orders list', 'ls-simple-order' ),
);
$args = array(
'label' => __( 'Order', 'ls-simple-order' ),
'description' => __( 'Simple Order Orders', 'ls-simple-order' ),
'labels' => $labels,
'supports' => array( 'title', 'thumbnail', 'custom-fields' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-cart',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'capability_type' => 'page',
);
register_post_type( 'order', $args );
}
add_action( 'init', 'ls_so_order', 0 );
}

Can you try doing this?
$post_data = array(
'post_title' => 'Test regex',
'post_content' => $order->Name() . '<' . $order->Email() . '>',
'post_type' => 'post',
'post_status' => 'publish',
'post_author' => 1,
);
$post_id = wp_insert_post($post_data);
update_post_meta($post_id, 'order_details', '{"some":"json here"}');

After going back and forth in every forum I could find, and tinkering with #miguelcalderons answer, I found the culprit, and it is a very simple, although quiet hidden thing.
WordPress Reserved Terms
WordPress has a quiet long list of reserved terms, and order being one of them.
After replacing the custom post type slug with a different string, it started working immediately.

Related

Sub CPT taxonomy 404 page

I have a problem with my sub taxonomies.
my-cpt/chapitres archive is working. I made a redirection to a page
from the tax-template.
my-cpt/chapitres/sub-term --> 404
my-cpt/chapitres/sub-term/post --> working
This is my code :
cpt
function custom_cpt() {
$labels = array(
'name' => __( 'Mon cpt' ),
'singular_name' => __( 'Mon cpt'),
'menu_name' => __( 'Mon cpt'),
'parent_item_colon' => __( 'Parent Mon cpt'),
// Paramétrages
'all_items' => __( 'Mon cpt'),
'view_item' => __( 'Voir'),
'add_new_item' => __( 'Ajouter du contenu'),
'add_new' => __( 'Ajout contenu'),
'edit_item' => __( 'Modifier'),
'update_item' => __( 'Mettre à jour'),
'search_items' => __( 'Rechercher'),
'not_found' => __( 'Non trouvé'),
'not_found_in_trash' => __( 'Non trouvé dans la corbeille'),
);
$args = array(
'label' => __( 'my-cpt'), // label
'description' => __( 'Mon cpt'),
'labels' => $labels,
'menu_icon' => 'dashicons-book-alt',
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail'),
'public' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'my-cpt/%chapitres%', 'with_front' => false),
'show_in_rest' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => false,
'can_export' => true,
'query_var' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'menu_position' => 5,
);
register_post_type( 'my-cpt', $args );
}
add_action( 'init', 'custom_cpt', 0 );
Taxonomy:
add_action( 'init', 'custom_cpt_taxonomies', 0 );
function custom_cpt_taxonomies() {
$labels = array(
'name' => _x( 'Chapitres', 'taxonomy general name' ),
'singular_name' => _x( 'Chapitre', 'taxonomy singular name' ),
'search_items' => __( 'Rechercher un chapitre' ),
'all_items' => __( 'Tous les chapitres' ),
'parent_item' => __( 'Chapitres Parents' ),
'parent_item_colon' => __( 'Chapitre Parent:' ),
'edit_item' => __( 'Modifier' ),
'update_item' => __( 'Mettre à jour' ),
'add_new_item' => __( 'Ajouter un chapitre' ),
'new_item_name' => __( 'Nouveau chapitre' ),
'menu_name' => __( 'Chapitres' ),
'has_archive' => false,
);
register_taxonomy('chapitres',array('my-cpt'), array(
"labels" => $labels,
"hierarchical" => true,
"public" => true,
"show_ui" => true,
"show_admin_column" => true,
"show_in_nav_menus" => true,
"show_tagcloud" => true,
"show_in_rest" => true,
'rewrite' => array('hierarchical' => true, 'with_front' => false ),
));
}
I found this for the rewrite rules
function rewrite_permalink_cpt($link, $post){
if ($post->post_type != 'my-cpt')
return $link;
if ($cats = get_the_terms($post->ID, 'chapitres')){
$link = str_replace('%chapitres%', get_taxonomy_parents(array_pop($cats)->term_id, 'chapitres', false, '/', true), $link);
}
return $link;
}
add_filter('post_type_link', 'rewrite_permalink_cpt', 10, 2);
add_filter('rewrite_rules_array', 'rewrite_rules_permalink_cpt');
function rewrite_rules_permalink_cpt($rules){
$cpt = array();
$cpt['my-cpt/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?my-cpt=$matches[4]';
$newRules['my-cpt/(.+)/(.+)/?$'] = 'index.php?my-cpt=$matches[1]';
return array_merge($cpt, $rules);
}
function get_taxonomy_parents($id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array()) {
$chain = '';
$parentref = get_term($id, $taxonomy);
$parent = &$parentref;
if (is_wp_error($parent)) {
return $parent;
}
if ($nicename)
$name = $parent->slug;
else
$name = $parent->name;
if($parent!=0){
if ($parent->parent && ($parent->parent != $parent->term_id) && !in_array($parent->parent, $visited)) {
$visited[] = $parent->parent;
$chain .= get_taxonomy_parents($parent -> parent, $taxonomy, $link, $nicename, $visited);
$chain .= "/";
}
if ($link) {
// nothing, can't get this working :(
} else
$chain .= $name;
return $chain;
}
}
I think the problem is come from the rewrite rules, but I don't know what is wrong...
It would be appreciate if someone has an idea

Modify Custom Taxonomy slug with CPT slug

Hi please check my requirement bellow.
First of all, I have registered a CPT "directory" with a slug name "directory". Also, I have registered a custom taxonomy "business_category". I want to below permalink structure.
CPT Archive link: www.domain.com/directory/
Taxonomy link: www.domain.com/directory/category/TAXONOMY_NAME/
CPT Single Page: www.domain.com/directory/POST_NAME
So, I have used the Below code.
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->PT = 'cc-directory';
$this->name = 'Directory';
$this->singular_name = 'Directory';
$this->slug = 'directory';
}
public function register_post_type() {
// Get supported features for Directory post type
$supports = apply_filters('cc_directory_supports', array('editor', 'title','thumbnail'));
$labels = array(
'name' => $this->name,
'singular_name' => $this->singular_name,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $this->singular_name,
'edit_item' => 'Edit ' . $this->singular_name,
'new_item' => 'New ' . $this->singular_name,
'all_items' => 'All ' . $this->name,
'view_item' => 'View ' . $this->name,
'search_items' => 'Search ' . $this->name,
'not_found' => 'No ' . strtolower($this->name) . ' found',
'not_found_in_trash' => 'No ' . strtolower($this->name) . ' found in Trash',
'parent_item_colon' => '',
'menu_name' => $this->name
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => $this->slug ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => 11,
'menu_icon' => 'dashicons-book',
'supports' => $supports,
'yarpp_support' => true
);
register_post_type( $this->PT, $args );
$plural_label = 'Categories';
$singular_label = 'Category';
register_taxonomy(
'business_category',
$this->PT,
array(
'label' => $plural_label,
'labels' => array(
'name' => $plural_label,
'singular_name' => $singular_label,
'all_items' => sprintf(__('All %s', 'claritycloud-directory'), $plural_label),
'edit_item' => sprintf(__('Edit %s', 'claritycloud-directory'), $singular_label),
'view_item' => sprintf(__('View %s', 'claritycloud-directory'), $singular_label),
'update_item' => sprintf(__('Update %s', 'claritycloud-directory'), $singular_label),
'add_new_item' => sprintf(__('Add New %s', 'claritycloud-directory'), $singular_label),
'new_item_name' => sprintf(__('New %s Name', 'claritycloud-directory'), $singular_label),
'popular_items' => sprintf(__('Popular %s', 'claritycloud-directory'), $plural_label),
'search_items' => sprintf(__('Search %s', 'claritycloud-directory'), $plural_label),
),
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'hierarchical' => true,
'rewrite' => array('slug' => 'business-category'),
)
);
}
Right now my URLs are :
http://localhost/demo-project/directory/
http://localhost/demo-project/business-category/antiques/
http://localhost/demo-project/directory/a-lil-bit-of-sas/
It will be like below:
http://localhost/demo-project/directory/
http://localhost/demo-project/directory/category/antiques/
http://localhost/demo-project/directory/a-lil-bit-of-sas/
Just need to modify the above 2nd URL.
Can anyone please advise me?
Thanks,
Subhankar
Finally, I got the solution here:
add_action('init', 'cpt_resources');
function cpt_resources() {
$labels = array(
'name' => _x('Resources', 'snt'),
'singular_name' => _x('Resource', 'snt'),
'add_new' => _x('Add Resource', 'snt'),
'add_new_item' => __('Add Resource'),
'edit_item' => __('Edit Resource'),
'new_item' => __('New Resource'),
'view_item' => __('View Resource'),
'search_items' => __('Search Resources'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'taxonomies' => array('resource_type'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'resources' ),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','thumbnail', 'editor' ),
);
register_post_type( 'resources_post_type' , $args );
}
function resource_type() {
$labels = array(
'name' => _x( 'Resource Types', 'Taxonomy General Name', 'snt' ),
'singular_name' => _x( 'Resource Type', 'Taxonomy Singular Name', 'snt' ),
'menu_name' => __( 'Resource Types', 'snt' ),
'all_items' => __( 'All Items', 'snt' ),
'parent_item' => __( 'Parent Item', 'snt' ),
'parent_item_colon' => __( 'Parent Item:', 'snt' ),
'new_item_name' => __( 'New Item Name', 'snt' ),
'add_new_item' => __( 'Add New Item', 'snt' ),
'edit_item' => __( 'Edit Item', 'snt' ),
'update_item' => __( 'Update Item', 'snt' ),
'view_item' => __( 'View Item', 'snt' ),
'separate_items_with_commas' => __( 'Separate items with commas', 'snt' ),
'add_or_remove_items' => __( 'Add or remove items', 'snt' ),
'choose_from_most_used' => __( 'Choose from the most used', 'snt' ),
'popular_items' => __( 'Popular Items', 'snt' ),
'search_items' => __( 'Search Items', 'snt' ),
'not_found' => __( 'Not Found', 'snt' ),
'no_terms' => __( 'No items', 'snt' ),
'items_list' => __( 'Items list', 'snt' ),
'items_list_navigation' => __( 'Items list navigation', 'snt' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => array('slug' => 'resources/category')
);
register_taxonomy( 'resource_type', array( 'resources_post_type' ), $args );
}
add_action( 'init', 'resource_type', 0 );
function resources_cpt_generating_rule($wp_rewrite) {
$rules = array();
$terms = get_terms( array(
'taxonomy' => 'resource_type',
'hide_empty' => false,
) );
$post_type = 'resources_post_type';
foreach ($terms as $term) {
$rules['resources/category/' . $term->slug . '/([^/]*)$'] = 'index.php?post_type=' . $post_type. '&resources_post_type=$matches[1]&name=$matches[1]';
}
// merge with global rules
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'resources_cpt_generating_rule');
Result :
http://localhost/demo-wp/resources/
http://localhost/demo-wp/resources/category/test-resources/
http://localhost/demo-wp/resources/final-check/

TYPO3 9.5 URL Routes

I have an old real_url.conf (from RealURL TYPO3 7.6). Now I have updated the system to TYPO3 9.5 and I need again the speaking URLs for my extension.
Unfortunately, I don't have that yet, that's why I ask for advice here.
'postVarSets' => array(
'_DEFAULT' => array (
"in" => array(
array(
'GETvar' => 'pm_zahnarztprofiles[ort]'
),
array(
'GETvar' => 'pm_zahnarztprofiles[stadtteil]'
),
array(
'GETvar' => 'pm_zahnarztprofiles[name]'
),
array(
'GETvar' => 'pm_zahnarztprofiles[id]'
),
),
"page" => array(
array(
'GETvar' => 'pm_zahnarztprofiles[page]'
)
),
"sitemap" => array(
array(
'GETvar' => 'pm_zahnarztprofiles[sitemap]'
)
),
"html_sitemap" => array(
array(
'GETvar' => 'pm_zahnarztprofiles[html_sitemap]'
)
),
"search" => array(
array(
'GETvar' => 'pm_zahnarztprofiles[search]'
),
array(
'GETvar' => 'pm_zahnarztprofiles[page]'
)
)
)
)

How to Make a Status Field Bydefault Enable in Magento Form?

Following is my Form Field Code.
$fieldset->addField('status','select',
array(
'label' => Mage::helper('synclogin')->__('Eshot Status'),
'name' => 'status',
'values' => array(
array(
'value' => 0,
'label' => Mage::helper('synclogin')->__('Disabled'),
),
array(
'value' => 1,
'label' => Mage::helper('synclogin')->__('Enabled'),
),
),
)
);
How to Make a Status Field Bydefault Enable in Magento Form?
$fieldset->addField('status','select',
array(
'label' => Mage::helper('synclogin')->__('Eshot Status'),
'name' => 'status',
'value' => '1',
'values' => array(
array(
'value' => 0,
'label' => Mage::helper('synclogin')->__('Disabled'),
),
array(
'value' => 1,
'label' => Mage::helper('synclogin')->__('Enabled'),
),
),
)
);

Divi image gallery sorting

Hope someone could help me with this one! I've already asked for their support but "it goes beyond their support level" and they even adviced me to ask it here..
So I'm using the Divi image gallery for my wordpress catalog, which contains lots of images.
Now I'm looking for a way that the images in the gallery are standard sorted by filename.
Any guidelines how to do change this in their code?
Thanks a lot!!
File names for attachments are stored in the 'post_name' column of the posts table. Therefore, this simple change should do the trick.
The simple answer to your question is:
Locate the file divi/includes/builder/main-modules.php
Search for function get_galleryin the file
From there, scroll down slightly to find $attachments_args
Change 'orderby' => 'post__in' to 'orderby' => 'post_name'
The bad news...
Making a change to main-modules.php means either you can no longer do updates or when you do update you'll have to apply the hack again.
Michael is right BUT:
The good news
You you can insert it into your Child Theme and everything is save
The better answer to your question is:
Locate the file divi/includes/builder/main-modules.php
Copy the ET_Builder_Module_Gallery
Insert into your functions.php, wrap and modify like Michael said
Complete code for this
function divi_child_theme_setup() {
if ( class_exists('ET_Builder_Module')) {
class CHILD_ET_Builder_Module_Gallery extends ET_Builder_Module {
function init() {
$this->name = esc_html__( 'Gallery', 'et_builder' );
$this->slug = 'et_pb_gallery';
$this->fb_support = true;
$this->whitelisted_fields = array(
'src',
'gallery_ids',
'gallery_orderby',
'fullwidth',
'posts_number',
'show_title_and_caption',
'show_pagination',
'background_layout',
'auto',
'auto_speed',
'admin_label',
'module_id',
'module_class',
'zoom_icon_color',
'hover_overlay_color',
'hover_icon',
'orientation',
);
$this->fields_defaults = array(
'fullwidth' => array( 'off' ),
'posts_number' => array( 4, 'add_default_setting' ),
'show_title_and_caption' => array( 'on' ),
'show_pagination' => array( 'on' ),
'background_layout' => array( 'light' ),
'auto' => array( 'off' ),
'auto_speed' => array( '7000' ),
'orientation' => array( 'landscape' ),
);
$this->options_toggles = array(
'general' => array(
'toggles' => array(
'main_content' => esc_html__( 'Images', 'et_builder' ),
'elements' => esc_html__( 'Elements', 'et_builder' ),
),
),
'advanced' => array(
'toggles' => array(
'layout' => esc_html__( 'Layout', 'et_builder' ),
'overlay' => esc_html__( 'Overlay', 'et_builder' ),
'text' => array(
'title' => esc_html__( 'Text', 'et_builder' ),
'priority' => 49,
),
),
),
'custom_css' => array(
'toggles' => array(
'animation' => array(
'title' => esc_html__( 'Animation', 'et_builder' ),
'priority' => 90,
),
),
),
);
$this->main_css_element = '%%order_class%%.et_pb_gallery';
$this->advanced_options = array(
'fonts' => array(
'title' => array(
'label' => esc_html__( 'Title', 'et_builder' ),
'css' => array(
'main' => "{$this->main_css_element} .et_pb_gallery_title",
),
),
'caption' => array(
'label' => esc_html__( 'Caption', 'et_builder' ),
'use_all_caps' => true,
'css' => array(
'main' => "{$this->main_css_element} .mfp-title, {$this->main_css_element} .et_pb_gallery_caption",
),
'line_height' => array(
'range_settings' => array(
'min' => '1',
'max' => '100',
'step' => '1',
),
),
'depends_show_if' => 'off'
),
),
'border' => array(
'css' => array(
'main' => "{$this->main_css_element} .et_pb_gallery_item",
),
),
);
$this->custom_css_options = array(
'gallery_item' => array(
'label' => esc_html__( 'Gallery Item', 'et_builder' ),
'selector' => '.et_pb_gallery_item',
),
'overlay' => array(
'label' => esc_html__( 'Overlay', 'et_builder' ),
'selector' => '.et_overlay',
),
'overlay_icon' => array(
'label' => esc_html__( 'Overlay Icon', 'et_builder' ),
'selector' => '.et_overlay:before',
),
'gallery_item_title' => array(
'label' => esc_html__( 'Gallery Item Title', 'et_builder' ),
'selector' => '.et_pb_gallery_title',
),
'gallery_item_caption' => array(
'label' => esc_html__( 'Gallery Item Caption', 'et_builder' ),
'selector' => '.et_pb_gallery_caption',
),
'gallery_pagination' => array(
'label' => esc_html__( 'Gallery Pagination', 'et_builder' ),
'selector' => '.et_pb_gallery_pagination',
),
'gallery_pagination_active' => array(
'label' => esc_html__( 'Pagination Active Page', 'et_builder' ),
'selector' => '.et_pb_gallery_pagination a.active',
),
);
}
function get_fields() {
$fields = array(
'src' => array(
'label' => esc_html__( 'Gallery Images', 'et_builder' ),
'renderer' => 'et_builder_get_gallery_settings',
'option_category' => 'basic_option',
'overwrite' => array(
'ids' => 'gallery_ids',
'orderby' => 'gallery_orderby',
),
'toggle_slug' => 'main_content',
),
'gallery_ids' => array(
'type' => 'hidden',
'class' => array( 'et-pb-gallery-ids-field' ),
'computed_affects' => array(
'__gallery',
),
),
'gallery_orderby' => array(
'label' => esc_html__( 'Gallery Images', 'et_builder' ),
'type' => 'hidden',
'class' => array( 'et-pb-gallery-ids-field' ),
'computed_affects' => array(
'__gallery',
),
'toggle_slug' => 'main_content',
),
'fullwidth' => array(
'label' => esc_html__( 'Layout', 'et_builder' ),
'type' => 'select',
'option_category' => 'layout',
'options' => array(
'off' => esc_html__( 'Grid', 'et_builder' ),
'on' => esc_html__( 'Slider', 'et_builder' ),
),
'description' => esc_html__( 'Toggle between the various blog layout types.', 'et_builder' ),
'affects' => array(
'zoom_icon_color',
'caption_font',
'caption_text_color',
'caption_line_height',
'caption_font_size',
'caption_all_caps',
'caption_letter_spacing',
'hover_overlay_color',
'auto',
'posts_number',
'show_title_and_caption',
'orientation'
),
'computed_affects' => array(
'__gallery',
),
'tab_slug' => 'advanced',
'toggle_slug' => 'layout',
),
'posts_number' => array(
'label' => esc_html__( 'Images Number', 'et_builder' ),
'type' => 'text',
'option_category' => 'configuration',
'description' => esc_html__( 'Define the number of images that should be displayed per page.', 'et_builder' ),
'depends_show_if' => 'off',
'toggle_slug' => 'main_content',
),
'orientation' => array(
'label' => esc_html__( 'Thumbnail Orientation', 'et_builder' ),
'type' => 'select',
'options_category' => 'configuration',
'options' => array(
'landscape' => esc_html__( 'Landscape', 'et_builder' ),
'portrait' => esc_html__( 'Portrait', 'et_builder' )
),
'description' => sprintf(
'%1$s<br><small><em><strong>%2$s:</strong> %3$s %4$s.</em></small>',
esc_html__( 'Choose the orientation of the gallery thumbnails.', 'et_builder' ),
esc_html__( 'Note', 'et_builder' ),
esc_html__( 'If this option appears to have no effect, you might need to', 'et_builder' ),
esc_html__( 'regenerate your thumbnails', 'et_builder')
),
'depends_show_if' => 'off',
'computed_affects' => array(
'__gallery',
),
'tab_slug' => 'advanced',
'toggle_slug' => 'layout',
),
'show_title_and_caption' => array(
'label' => esc_html__( 'Show Title and Caption', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'configuration',
'options' => array(
'on' => esc_html__( 'Yes', 'et_builder' ),
'off' => esc_html__( 'No', 'et_builder' ),
),
'description' => esc_html__( 'Whether or not to show the title and caption for images (if available).', 'et_builder' ),
'depends_show_if' => 'off',
'toggle_slug' => 'elements',
),
'show_pagination' => array(
'label' => esc_html__( 'Show Pagination', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'configuration',
'options' => array(
'on' => esc_html__( 'Yes', 'et_builder' ),
'off' => esc_html__( 'No', 'et_builder' ),
),
'toggle_slug' => 'elements',
'description' => esc_html__( 'Enable or disable pagination for this feed.', 'et_builder' ),
),
'background_layout' => array(
'label' => esc_html__( 'Text Color', 'et_builder' ),
'type' => 'select',
'option_category' => 'color_option',
'options' => array(
'light' => esc_html__( 'Dark', 'et_builder' ),
'dark' => esc_html__( 'Light', 'et_builder' ),
),
'tab_slug' => 'advanced',
'toggle_slug' => 'text',
'description' => esc_html__( 'Here you can choose whether your text should be light or dark. If you are working with a dark background, then your text should be light. If your background is light, then your text should be set to dark.', 'et_builder' ),
),
'auto' => array(
'label' => esc_html__( 'Automatic Animation', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'configuration',
'options' => array(
'off' => esc_html__( 'Off', 'et_builder' ),
'on' => esc_html__( 'On', 'et_builder' ),
),
'affects' => array(
'auto_speed',
),
'depends_show_if' => 'on',
'depends_to' => array(
'fullwidth',
),
'tab_slug' => 'custom_css',
'toggle_slug' => 'animation',
'description' => esc_html__( 'If you would like the slider to slide automatically, without the visitor having to click the next button, enable this option and then adjust the rotation speed below if desired.', 'et_builder' ),
),
'auto_speed' => array(
'label' => esc_html__( 'Automatic Animation Speed (in ms)', 'et_builder' ),
'type' => 'text',
'option_category' => 'configuration',
'depends_default' => true,
'tab_slug' => 'custom_css',
'toggle_slug' => 'animation',
'description' => esc_html__( "Here you can designate how fast the slider fades between each slide, if 'Automatic Animation' option is enabled above. The higher the number the longer the pause between each rotation.", 'et_builder' ),
),
'zoom_icon_color' => array(
'label' => esc_html__( 'Zoom Icon Color', 'et_builder' ),
'type' => 'color-alpha',
'custom_color' => true,
'depends_show_if' => 'off',
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
),
'hover_overlay_color' => array(
'label' => esc_html__( 'Hover Overlay Color', 'et_builder' ),
'type' => 'color-alpha',
'custom_color' => true,
'depends_show_if' => 'off',
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
),
'hover_icon' => array(
'label' => esc_html__( 'Hover Icon Picker', 'et_builder' ),
'type' => 'text',
'option_category' => 'configuration',
'class' => array( 'et-pb-font-icon' ),
'renderer' => 'et_pb_get_font_icon_list',
'renderer_with_field' => true,
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
),
'disabled_on' => array(
'label' => esc_html__( 'Disable on', 'et_builder' ),
'type' => 'multiple_checkboxes',
'options' => array(
'phone' => esc_html__( 'Phone', 'et_builder' ),
'tablet' => esc_html__( 'Tablet', 'et_builder' ),
'desktop' => esc_html__( 'Desktop', 'et_builder' ),
),
'additional_att' => 'disable_on',
'option_category' => 'configuration',
'description' => esc_html__( 'This will disable the module on selected devices', 'et_builder' ),
'tab_slug' => 'custom_css',
'toggle_slug' => 'visibility',
),
'admin_label' => array(
'label' => esc_html__( 'Admin Label', 'et_builder' ),
'type' => 'text',
'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ),
'toggle_slug' => 'admin_label',
),
'module_id' => array(
'label' => esc_html__( 'CSS ID', 'et_builder' ),
'type' => 'text',
'option_category' => 'configuration',
'tab_slug' => 'custom_css',
'toggle_slug' => 'classes',
'option_class' => 'et_pb_custom_css_regular',
),
'module_class' => array(
'label' => esc_html__( 'CSS Class', 'et_builder' ),
'type' => 'text',
'option_category' => 'configuration',
'tab_slug' => 'custom_css',
'toggle_slug' => 'classes',
'option_class' => 'et_pb_custom_css_regular',
),
'__gallery' => array(
'type' => 'computed',
'computed_callback' => array( 'ET_Builder_Module_Gallery', 'get_gallery' ),
'computed_depends_on' => array(
'gallery_ids',
'gallery_orderby',
'fullwidth',
'orientation',
),
),
);
return $fields;
}
/**
* Get attachment data for gallery module
*
* #param array $args {
* Gallery Options
*
* #type array $gallery_ids Attachment Ids of images to be included in gallery.
* #type string $gallery_orderby `orderby` arg for query. Optional.
* #type string $fullwidth on|off to determine grid / slider layout
* #type string $orientation Orientation of thumbnails (landscape|portrait).
* }
* #param array $conditional_tags
* #param array $current_page
*
* #return array Attachments data
*/
static function get_gallery( $args = array(), $conditional_tags = array(), $current_page = array() ) {
$attachments = array();
$defaults = array(
'gallery_ids' => array(),
'gallery_orderby' => '',
'fullwidth' => 'off',
'orientation' => 'landscape',
);
$args = wp_parse_args( $args, $defaults );
$attachments_args = array(
'include' => $args['gallery_ids'],
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'post_name',
);
if ( 'rand' === $args['gallery_orderby'] ) {
$attachments_args['orderby'] = 'rand';
}
if ( 'on' === $args['fullwidth'] ) {
$width = 1080;
$height = 9999;
} else {
$width = 400;
$height = ( 'landscape' === $args['orientation'] ) ? 284 : 516;
}
$width = (int) apply_filters( 'et_pb_gallery_image_width', $width );
$height = (int) apply_filters( 'et_pb_gallery_image_height', $height );
$_attachments = get_posts( $attachments_args );
foreach ( $_attachments as $key => $val ) {
$attachments[$key] = $_attachments[$key];
$attachments[$key]->image_src_full = wp_get_attachment_image_src( $val->ID, 'full' );
$attachments[$key]->image_src_thumb = wp_get_attachment_image_src( $val->ID, array( $width, $height ) );
}
return $attachments;
}
function shortcode_callback( $atts, $content = null, $function_name ) {
$module_id = $this->shortcode_atts['module_id'];
$module_class = $this->shortcode_atts['module_class'];
$gallery_ids = $this->shortcode_atts['gallery_ids'];
$fullwidth = $this->shortcode_atts['fullwidth'];
$show_title_and_caption = $this->shortcode_atts['show_title_and_caption'];
$background_layout = $this->shortcode_atts['background_layout'];
$posts_number = $this->shortcode_atts['posts_number'];
$show_pagination = $this->shortcode_atts['show_pagination'];
$gallery_orderby = $this->shortcode_atts['gallery_orderby'];
$zoom_icon_color = $this->shortcode_atts['zoom_icon_color'];
$hover_overlay_color = $this->shortcode_atts['hover_overlay_color'];
$hover_icon = $this->shortcode_atts['hover_icon'];
$auto = $this->shortcode_atts['auto'];
$auto_speed = $this->shortcode_atts['auto_speed'];
$orientation = $this->shortcode_atts['orientation'];
$module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name );
if ( '' !== $zoom_icon_color ) {
ET_Builder_Element::set_style( $function_name, array(
'selector' => '%%order_class%% .et_overlay:before',
'declaration' => sprintf(
'color: %1$s !important;',
esc_html( $zoom_icon_color )
),
) );
}
if ( '' !== $hover_overlay_color ) {
ET_Builder_Element::set_style( $function_name, array(
'selector' => '%%order_class%% .et_overlay',
'declaration' => sprintf(
'background-color: %1$s;
border-color: %1$s;',
esc_html( $hover_overlay_color )
),
) );
}
// Get gallery item data
$attachments = self::get_gallery( array(
'gallery_ids' => $gallery_ids,
'gallery_orderby' => $gallery_orderby,
'fullwidth' => $fullwidth,
'orientation' => $orientation,
) );
if ( empty( $attachments ) ) {
return '';
}
wp_enqueue_script( 'hashchange' );
$fullwidth_class = 'on' === $fullwidth ? ' et_pb_slider et_pb_gallery_fullwidth' : ' et_pb_gallery_grid';
$background_class = " et_pb_bg_layout_{$background_layout}";
$module_class .= 'on' === $auto && 'on' === $fullwidth ? ' et_slider_auto et_slider_speed_' . esc_attr( $auto_speed ) : '';
$posts_number = 0 === intval( $posts_number ) ? 4 : intval( $posts_number );
$output = sprintf(
'<div%1$s class="et_pb_module et_pb_gallery%2$s%3$s%4$s clearfix">
<div class="et_pb_gallery_items et_post_gallery" data-per_page="%5$d">',
( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ),
( '' !== $module_class ? sprintf( ' %1$s', esc_attr( ltrim( $module_class ) ) ) : '' ),
esc_attr( $fullwidth_class ),
esc_attr( $background_class ),
esc_attr( $posts_number )
);
foreach ( $attachments as $id => $attachment ) {
$data_icon = '' !== $hover_icon
? sprintf(
' data-icon="%1$s"',
esc_attr( et_pb_process_font_icon( $hover_icon ) )
)
: '';
$image_output = sprintf(
'<a href="%1$s" title="%2$s">
<img src="%3$s" alt="%2$s" />
<span class="et_overlay%4$s"%5$s></span>
</a>',
esc_url( $attachment->image_src_full[0] ),
esc_attr( $attachment->post_title ),
esc_url( $attachment->image_src_thumb[0] ),
( '' !== $hover_icon ? ' et_pb_inline_icon' : '' ),
$data_icon
);
$output .= sprintf(
'<div class="et_pb_gallery_item%2$s%1$s">',
esc_attr( $background_class ),
( 'on' !== $fullwidth ? ' et_pb_grid_item' : '' )
);
$output .= "
<div class='et_pb_gallery_image {$orientation}'>
$image_output
</div>";
if ( 'on' !== $fullwidth && 'on' === $show_title_and_caption ) {
if ( trim($attachment->post_title) ) {
$output .= "
<h3 class='et_pb_gallery_title'>
" . wptexturize($attachment->post_title) . "
</h3>";
}
if ( trim($attachment->post_excerpt) ) {
$output .= "
<p class='et_pb_gallery_caption'>
" . wptexturize($attachment->post_excerpt) . "
</p>";
}
}
$output .= "</div>";
}
$output .= "</div><!-- .et_pb_gallery_items -->";
if ( 'on' !== $fullwidth && 'on' === $show_pagination ) {
$output .= "<div class='et_pb_gallery_pagination'></div>";
}
$output .= "</div><!-- .et_pb_gallery -->";
return $output;
}
}
$cgm = new CHILD_ET_Builder_Module_Gallery();
remove_shortcode( 'et_pb_gallery' );
add_shortcode( 'et_pb_gallery', array($cgm, '_shortcode_callback') );
}
}
add_action('wp', 'divi_child_theme_setup', 9999);
I used code from Divi 3.0.51. have fun

Resources