remove_action is not working I have tried to remove acf_woocommerce_add_fields_to_order using following code
remove remove_action( 'acf_woocommerce_add_fields_to_order', array( ACF_Woo_API::get_instance(), 'acf_woocommerce_add_fields_to_order' ) );
But this is not working kindly help.
The function that I would like to remove from the plugin is as following
public function acf_woocommerce_add_fields_to_order() {
$api = ACF_Woo_API::get_instance();
$group_keys = wp_list_pluck($api->get_field_groups(), $api->acf_id_case_sensitive());
foreach ($group_keys as $group_key => $key) {
$fields = $api->get_field_group_fields($key);
foreach ($fields as $field => $value) {
$field_label = $value['label'];
$raw_meta = base64_decode(get_post_meta(get_the_ID(), $value['key'], true));
$meta = unserialize($raw_meta);
if (is_array($meta)) {
//handle repeater, flexible content
if (is_array(reset($meta))) {
echo '<table style="border-collapse: collapse; width: 100%">';
foreach ($meta as $row) {
echo '<tr>';
foreach ($row as $column) {
echo "<td style='border: 1px solid black;'>$column</td>";
}
echo '</tr>';
}
echo '</table>';
} //handle choice and select
else {
echo '<p><strong>' . $field_label . ': </strong>' . implode('; ', $meta) . '</p>';
}
} else {
$meta = stripcslashes($meta);
echo '<p><strong>' . $field_label . ': </strong>' . $meta . '</p>';
}
}
}
}
Was trying
remove_action( 'acf_woocommerce_add_fields_to_order', array( ACF_Woo_API::get_instance(), 'acf_woocommerce_add_fields_to_order' ) );
but unable to do it.
Hoping to learn more. Thanks!
Related
I want to place ads after second paragraph of the posts located under a specific category. For this I am trying to run the following piece of codes but it is not working. Kindly help me out.
//Insert ads after second paragraph of single post content.
$catarray = get_the_category( $post->ID );
foreach ($catarray as $cat) {
$catid = $cat->term_id;
if ($catid == 124);
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Insert Ad code here</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
}
return $content;
}
// Parent Function that makes the magic happen
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $insertion;
}
}
return implode( '', $paragraphs );
}
you can use this code for it
add_filter('the_content', 'ak_the_content_filter', 10, 1);
function ak_the_content_filter($content)
{
$catarray = get_the_category( $post->ID );
foreach ($catarray as $cat) {
$catid = $cat->term_id;
if ($catid != 124) { return $content; }
else{
$parags = explode('</p>', $content);
$parags[1] .= '<br>'.do_shortcode('[SHORTCODE HERE]');// add whatever you want after first paragraph
$content_new = '';
foreach ($parags as $parag) {
$content_new .= $parag;
}
return $content_new;
}
}
}
With custom post type, i need to use category slug for my class (css).
<?php
global $post;
$terms = wp_get_post_terms($post->ID, 'typeresources');
if ($terms) {
$output = array();
foreach ($terms as $term) {
if ($term->term_id != 14)
{
$output[] = '<div class="cat-resources">' .$term->name .'</div>';
}
}
echo join( ' ', $output );
};
?>
Would like to add at my "cat-resources class" the categroy slug
How can i do that ?
There you go.
global $post;
$terms = wp_get_post_terms($post->ID, 'typeresources');
if ($terms) {
$output = array();
foreach ($terms as $term) {
if ($term->term_id != 14) {
$output[] = '<div class="cat-resources '.$term->slug.'">' .$term->name .'</div>';
}
}
echo join( ' ', $output );
};
This code perfectly doing listing users, and remove users with short code. But i have an author directory plugin, and i can list my user with additional meta data. So i want to remove user on my author directory plugin. At the bellow, there is my author directory plugins codes, how can i combine this funciton.
add_action( 'wp_head', 'my_action_javascript' );
function my_action_javascript() {
?>
<script type="text/javascript" >
jQuery(document).ready(function() {
jQuery(".delete_user").click(function() {
var current_element_var = jQuery(this);
var data = {
'action': 'delete_user_action',
'user_id': current_element_var.attr('delete-user-id'),
'security': '<?php echo wp_create_nonce( "security-special-string" ) ?>'
};
jQuery.post('<?php echo admin_url( 'admin-ajax.php' ) ?>', data, function(response) {
if (response == 'deleted_successfully') {
current_element_var.hide();
current_element_var.after('<span> User Deleted Successfully </span>');
current_element_var.remove();
}
});
return false;
});
});
</script>
<?php
}
add_action( 'wp_ajax_delete_user_action', 'delete_user_action_callback' );
add_action( 'wp_ajax_nopriv_delete_user_action', 'delete_user_action_callback' );
function delete_user_action_callback() {
check_ajax_referer( 'security-special-string', 'security' );
wp_delete_user( $_POST['user_id'] );
echo 'deleted_successfully';
die();
}
add_shortcode('listuser', 'listsubscriber');
function listsubscriber() {
$blogusers = get_users( array( 'fields' => array('display_name','ID' )) );
echo '<ul>';
foreach ( $blogusers as $user ) {
echo '<li>' . esc_html( $user->display_name ) . '|' . esc_html( $user->ID ) . '<a class="delete_user" delete-user-id="' . $user->ID . '" href="#">Delete User</a></li>';
}
echo '</ul>';
}
Author list plugin codes at here.
require_once("rules/useroles.php");
require_once("admin/admin.php");
function member_directory_loader_scripts()
{
wp_register_style( 'directorycss', plugin_dir_url( __FILE__ ).'asset/js/jdirectory/directory.css');
wp_enqueue_style( 'directorycss' );
wp_register_script( 'directoryjs', plugin_dir_url( __FILE__ ).'asset/js/jdirectory/jquery.directory.js', array('jquery'));
wp_enqueue_script( 'directoryjs' );
}
add_action( 'wp_enqueue_scripts', 'member_directory_loader_scripts' );
function member_directory_shortcode($atts)
{
global $table_prefix,$wpdb,$post;
$return_content = '';
$return_content .= '<div class="member_directory_table">';
$results = get_users();
if ((!(empty($results))) && (is_array($results)) && (count($results) >0))
{
$m_single = array();
foreach ($results as $single)
{
$user_allowed_listed = true;
$memberDirectoryUserRoleSelect = get_option('memberDirectoryUserRoleSelect');
if (empty($memberDirectoryUserRoleSelect))
{
}
else
{
$user_allowed_listed = check_user_role_allowed($single);
if ($user_allowed_listed == false)
{
continue;
}
}
$return_content .= '<div class="tooltips_list">';
$return_content .= '<span class="tooltips_table_items">';
$return_content .= '<div class="tooltips_table">';
$return_content .= '<div class="tooltips_table_title">';
$enabGlossaryIndexPage = get_option("enabGlossaryIndexPage");
$return_content .= $single->display_name;
$return_content .='</div>';
$return_content .= '<div class="billing">';
$return_content .= $single->billing_address_1;
$return_content .='</div>';
***** i want to at there remove user link with ajax ******
$return_content .= '<div class="billing2">';
$return_content .= $single->billing_company;
$return_content .='</div>';
$return_content .= '<div class="billing3">';
$return_content .= $single->ID;
$return_content .='</div>';
$return_content .= '<div class="tooltips_table_content">';
// old $m_content = $single->user_email;
// 1.3.1
$m_content = '';
$m_content_user_email = $single->user_email;
$m_content_user_bio_in_wp = get_the_author_meta('description',$single->ID);
$m_content .= "<div class = 'member_content_user_email'>";
$m_content .= $m_content_user_email;
$m_content .= "</div>";
$m_content .= "<div class = 'member_content_user_description'>";
$m_content .= $m_content_user_bio_in_wp;
$m_content .= "</div>";
$return_content .= $m_content;
$return_content .='</div>';
$return_content .='</div>';
$return_content .='</span>';
$return_content .='</div>';
}
}
$return_content .= '</div>';
return $return_content;
}
add_shortcode( 'member_directory', 'member_directory_shortcode',10 );
function member_directory_load_footer_js()
{
global $post;
?>
<script type="text/javascript">
var inboxs = new Array();
inboxs['hidezeronumberitem'] = "yes";
inboxs['selectors'] = '.tooltips_list > span';
<?php
$glossaryNavItemFontSize = '12px';
$glossarySelectedNavItemFontSize = get_option("glossarySelectedNavItemFontSize");
$glossarySelectedNavItemFontSize = '14px';
$glossaryNavItemFontSize = '12px';
?>
inboxs['navitemdefaultsize'] = '<?php echo $glossaryNavItemFontSize; ?>';
inboxs['navitemselectedsize'] = '<?php echo $glossarySelectedNavItemFontSize; ?>';
<?php
$glossaryNumbersOrNot = 'no';
if ($choseLanguageForGlossary == 'custom')
{
$glossaryLanguageCustomNavLetters = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z';
?>
inboxs['alphabetletters'] = "<?php echo $glossaryLanguageCustomNavLetters; ?>";
<?php
}
?>
inboxs['number'] = "no";
jQuery(document).ready(function () {
jQuery('.member_directory_table').directory(inboxs);
jQuery('.navitem').css('font-size','<?php echo $glossaryNavItemFontSize; ?>');
})
</script>
<?php
}
add_action('wp_footer','member_directory_load_footer_js');
function check_user_role_allowed($checkuser)
{
$memberDirectoryUserRoleSelect = get_option('memberDirectoryUserRoleSelect');
$saved_allowed_user_roles_in_member_directory = get_option('saved_allowed_user_roles_in_member_directory');
if (empty($memberDirectoryUserRoleSelect))
{
return true;
}
else
{
if ('enableMemberDirectoryUserRolesOption' == $memberDirectoryUserRoleSelect)
{
$can_listed = false;
$checking_user_roles = $checkuser->roles;
if (empty($checking_user_roles))
{
return false ;
}
else
{
foreach ($checking_user_roles as $checking_user_role)
{
if (in_array(strtolower($checking_user_role), $saved_allowed_user_roles_in_member_directory) )
{
$can_listed = true;
return true;
}
}
}
}
if ('disableMemberDirectoryUserRolesOption' == $memberDirectoryUserRoleSelect)
{
$can_listed = true;
$checking_user_roles = $checkuser->roles;
if (empty($checking_user_roles))
{
return false ;
}
else
{
foreach ($checking_user_roles as $checking_user_role)
{
if (in_array(strtolower($checking_user_role), $saved_allowed_user_roles_in_member_directory) )
{
$can_listed = false;
return false;
}
}
}
}
return $can_listed;
}
}
like so
Am guessing that $single->ID contains the User ID. If so, in that place where you marked in code, you could add the delete button.
It would be something like this:
$return_content .= '<div class="billing">';
$return_content .= $single->billing_address_1;
$return_content .='</div>';
/***** i want to at there remove user link with ajax ******/
/*--------- delete button ------------*/
$return_content .= '<button class="delete_user" delete-user-id="'. $single->ID .'">Delete</button>';
/*--------- /delete button ------------*/
$return_content .= '<div class="billing2">';
$return_content .= $single->billing_company;
$return_content .='</div>';
You are already listening to the click event of the class delete_user. And inside it, you are expecting the delete-user-id to have the user_id of the User whom you want to delete! Hence we are using both in our button.
One thing I noticed in code is the add_action( 'wp_ajax_nopriv_delete_user_action', 'delete_user_action_callback' ); This will allow non-logged in users to perform this delete operation because of the wp_ajax_nopriv_*
This hook is functionally the same as wp_ajax_{$action}, except the
“nopriv” variant is used for handling AJAX requests from
unauthenticated users, i.e. when is_user_logged_in() returns false.
My WordPress page shows shortcodes like [vc_row][vc_column][vc_column_text] .
Help me identify the root cause.
I have migrated the wordpress sql files from one host to another.
You could modify this Utility Script Runner script to remove shortcodes that no longer exist but are in your page content. Definitely do this on staging before you do it on live. high likelyhood of wrecking up the place. This script has been sitting for close to a year and I honestly can't remember if any of it doesn't work as expected. test a lot on staging before running this on anything you really care about.
<?php if(!defined('ABSPATH')) { die(); }
/**
* Utility Name: Remove and Flatten Shortcodes
* Description: Strip Shortcodes from all posts, with several processing options
* Supports: input
* Version: 0.0.2
**/
if (!class_exists('StripShortcodes')) {
class StripShortcodes {
var $wrappers = array(),
$swaps = array();
public static function Instance() {
static $instance = null;
if ($instance === null) {
$instance = new self();
}
return $instance;
}
public function __construct() {
add_filter('wp_util_script', array($this, 'strip_shortcodes_run'), 10, 3);
add_filter('wp_util_input_html', array($this, 'strip_shortcodes_input_html'));
}
public function strip_shortcodes_input_html( $html ) {
global $shortcode_tags;
$post_types = get_post_types( array(
'exclude_from_search' => false
), 'names' );
$post_types = array_diff( $post_types, array( 'revision', 'attachment' ) );
?>
<p>
<strong>WARNING! DO NOT RUN THIS ON A LIVE SITE!</strong><br>
This utility may cause data loss. Even restoring a backup may wipe out any changes since the last run of this utility.
</p>
<label>
<input type="checkbox" name="restore" value="restore"/>
<span>Restore From Backup</span>
</label>
<label>
<span>Post Types to Process</span>
<select name="post_types[]" multiple="multiple">
<option value="none" selected="selected">none</option>
<option value="any">all</option>
<?php
foreach( $post_types as $post_type ) {
echo '<option value="' . esc_attr( $post_type ) . '">' . $post_type . '</option>';
}
?>
</select>
</label>
<hr/>
<p>
Select what you would like to do with each shortcode.
</p>
<?php
if( !empty( $shortcode_tags ) ) {
foreach( $shortcode_tags as $tag => $callable ) {
?>
<div class="shortcode-options-wrapper">
<label>
<span>[<?php echo $tag; ?>]</span>
<select class="shortcode-select" name="shortcodes[<?php echo esc_attr( $tag ); ?>]"/>
<option value="skip">Skip (do not process)</option>
<option value="strip">Remove (deletes shortcode content)</option>
<option value="unwrap">Unwrap Content</option>
<option value="parse">Flatten (parses to HTML)</option>
<option value="swap">Swap (Replace with another shortcode)</option>
</select>
</label>
</div>
<?php
}
}
echo $this->build_form_script();
return ob_get_clean();
}
private function build_form_script () {
global $shortcode_tags;
ob_start(); ?>
<script type="text/javascript">
(jQuery)(function($) {
'use strict';
var unwrap = '<div class="wrap-wrapper"><p>Wrapper for content (use "sprintf()" formatting, including the %s for the content)</p><label>Wrapper<input class="shortcode-wrap"></label></div>';
var swap = '<div class="swap-wrapper"><select class="shortcode-swap"><?php foreach ($shortcode_tags as $tag => $callable) { echo '<option value="' . $tag . '">' . esc_attr($tag) . '</option>'; }?></select></div>'
$(document).on('change', '.shortcode-select', function () {
var $this = $(this);
var name = $this.attr('name');
if ($this.val() == 'unwrap') {
$this.closest('.shortcode-options-wrapper').append(unwrap);
$this.closest('.shortcode-options-wrapper').find('.shortcode-wrap').attr('name', 'wrap_' + name);
$this.closest('.shortcode-options-wrapper').find('.swap-wrapper').remove();
}
else if ($this.val() == 'swap') {
$this.closest('.shortcode-options-wrapper').append(swap);
$this.closest('.shortcode-options-wrapper').find('.shortcode-swap').attr('name', 'swap_' + name);
$this.closest('.shortcode-options-wrapper').find('.wrap-wrapper').remove();
} else {
$this.closest('.shortcode-options-wrapper').find('.wrap-wrapper').remove();
$this.closest('.shortcode-options-wrapper').find('.swap-wrapper').remove();
}
})
});
</script>
<?php return ob_get_clean();
}
public function strip_shortcodes_run( $legacy, $state, $atts ) {
$batch = 10;
$offset = 0;
if( !empty( $state['offset'] ) ) {
$offset = $state['offset'];
}
$result = array(
'state' => 'error',
'message' => 'an unknown error has occurred',
);
$post_types = 'none';
if( !empty( $atts['post_types'] ) && !in_array( 'none', $atts['post_types'] ) ) {
$post_types = $atts['post_types'];
}
$shortcode_settings = array();
if( !empty( $atts['shortcodes'] ) ) {
$shortcode_settings['core'] = $atts['shortcodes'];
$shortcode_settings['wrap'] = $atts['wrap_shortcodes'];
$shortcode_settings['swap'] = $atts['swap_shortcodes'];
}
$restore = true;
if( empty( $atts['restore'] ) ) {
$this->replace_shortcode_functions( $shortcode_settings );
$restore = false;
}
$query = new WP_Query( array(
'posts_per_page' => $batch,
'offset' => $offset,
'post_type' => $post_types
) );
if( !$query->have_posts() ) {
$result = array(
'state' => 'complete',
'message' => 'successfully processed all posts'
);
} else {
$offset += $query->post_count;
while( $query->have_posts() ) {
$query->the_post();
$post = get_post();
$backup = get_post_meta( $post->ID, 'flatten_shortcodes_backup', true );
if( $restore ) {
if( $backup ) {
$post->post_content = $backup;
wp_update_post( $post );
delete_post_meta( $post->ID, 'flatten_shortcodes_backup' );
}
} else {
if( !$backup ) {
update_post_meta( $post->ID, 'flatten_shortcodes_backup', $post->post_content );
}
$post->post_content = do_shortcode( $post->post_content );
wp_update_post( $post );
}
}
$result = array(
'state' => array(
'offset' => $offset
),
'message' => $offset . ' posts processed'
);
}
return $result;
}
private function replace_shortcode_functions( $settings = array() ) {
global $shortcode_tags;
foreach( $shortcode_tags as $tag => $callable ) {
$setting = 'skip';
if( !empty( $settings['core'][$tag] ) ) {
$setting = $settings['core'][$tag];
}
switch( $setting ) {
case 'strip' :
$shortcode_tags[$tag] = "__return_empty_string";
break;
case 'unwrap':
$shortcode_tags[$tag] = array($this, 'replace_shortcode_unwrap');
$this->wrappers[$tag] = $settings['wrap'][$tag];
break;
case 'parse' :
// nothing needed
break;
case 'swap' :
$shortcode_tags[$tag] = array($this, 'swap_shortcode');
$this->swaps[$tag] = $settings['swap'][$tag];
break;
case 'skip' :
default :
unset( $shortcode_tags[$tag] );
}
}
}
public function replace_shortcode_unwrap( $atts=array(), $content='', $tag ) {
return sprintf($this->wrappers[$tag], $content);
}
public function swap_shortcode( $atts=array(), $content='', $tag ) {
$attString = '';
$newTag = $this->swaps[$tag];
if (!empty($atts)) {
foreach ($atts as $key => $att) {
$attString .= ' ' . $key . '="' . $att . '"';
}
}
$output = '[' . $newTag . $attString . ']';
if ($content) {
$output .= $content . '[/' . $newTag . ']';
}
return $output;
}
}
StripShortcodes::Instance();
}
I have got same result. My theme is wp baker. I activated edge core plugin and other required plug ins and it was solved.
I have a vocabulary which displays the terms in the hierarchies order like the following.
parent1
child1
child2
parent2
child1
parent3
parent4
child1
child2
child3
This displays in taxonomy manager.
I want to create a page on which I call a function and pass the vid and displays the taxonomy terms of that vocabulary in hierarchies order just like in taxonomy manager.
I used the following code but it displays only the taxonomy terms not in a tree order.
$vid = 26;
$tree = taxonomy_get_tree($vid);
foreach($tree as $term) {
$output = l($term->name, taxonomy_term_path($term));
if ($term->children) {
$output .= theme('illogica_category_tree', $term->children);
}
}
print $output;
Any idea about this?
I use this:
$tree = extranet_get_nested_tree((int)$vid, null, $tid);
With this:
function extranet_get_nested_tree($terms = array(), $max_depth = NULL, $parent = 0, $parents_index = array(), $depth = 0) {
if (is_int($terms)) {
$terms = taxonomy_get_tree($terms);
}
foreach($terms as $term) {
foreach($term->parents as $term_parent) {
if ($term_parent == $parent) {
$return[$term->tid] = $term;
}
else {
$parents_index[$term_parent][$term->tid] = $term;
}
}
}
foreach($return as &$term) {
if (isset($parents_index[$term->tid]) && (is_null($max_depth) || $depth < $max_depth)) {
$term->children = extranet_get_nested_tree($parents_index[$term->tid], $max_depth, $term->tid, $parents_index, $depth + 1);
}
}
return $return;
}
And to print it out:
function extranet_output_nested_tree($tree) {
if (count($tree)) {
$output = '<ul class="nested-taxonomy-tree">';
foreach ($tree as $term) {
$output .= '<li class="taxonomy-term">';
$output .= t($term->name); //, taxonomy_term_path($term));
if ($term->children) {
$output .= extranet_output_nested_tree( $term->children);
}
$output .= '</li>';
}
$output .= '</ul>';
}
return $output;
}
Enjoy!
taxonomy_get_tree() should return the terms in the correct order, but the array is flat rather than nested. See taxonomy_get_tree() for more information and some sample functions to get a nested array.
Here is the solution `
foreach($terms as $term) {
foreach($term->parents as $term_parent) {
if ($term_parent == $parent) {
$return[$term->tid] = $term;
}
else {
$parents_index[$term_parent][$term->tid] = $term;
}
}
}
foreach($return as &$term) {
if (isset($parents_index[$term->tid]) && (is_null($max_depth) || $depth < $max_depth)) {
$term->children = taxonomy_get_nested_tree($parents_index[$term->tid], $max_depth, $term->tid, $parents_index, $depth + 1);
}
}
return $return;
}
function output_taxonomy_nested_tree($tree) {
if (count($tree)) {
$output = '<ul class="nav navbar-nav">';
foreach ($tree as $term) {
$output .= '<li class="taxonomy-term">' . l($term->name, "taxonomy/term/". $term->tid);
if ($term->children) {
$output .= output_taxonomy_nested_tree($term->children);
}
$output .= '</li>';
}
$output .= '</ul>';
}
return $output;
}
$tree= taxonomy_get_nested_tree(2,10);
$output=output_taxonomy_nested_tree($tree);
echo $output;`
If you want to print it in the specific region you needed just assign the output to a variable in preprocessor function and print the variable in the page tpl file.
$output=output_taxonomy_nested_tree($tree);
echo $output;`
to
$variables['output'] .=output_taxonomy_nested_tree($tree);
place the line
<?php print $output;?>
in your page tpl file