Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

mikeashi on "str_replace proplem"

0
0

I am useing woocommerce and in the Product Short Description I have Visual Composer code and I am trying to remove the code by useing str_replace

the code look like this :

$text = $post->post_excerpt;
														$text  = str_replace('[vc_row][vc_column][vc_column_text css_animation="left-to-right"]', "", $text );
											$shds = str_replace('[/vc_column_text][/vc_column][/vc_row]', "", $text);
										echo $shds;

now the str_replace is working fine but it's adding some html code which mess up my style

<div class="text">
<p class="bodytext">The FC 350 shares much of its engine architecture with the smaller FC 250, therefore combining compact dimensions, light weight and 450-rivalling power. All the packaging benefits of the new DOHC engine are matched to the most advanced electronics. Standard launch control, switchable engine maps and a faster, more powerful engine management system, guarantee that all the 58 horsepower is put to the ground in total control.</p>

</div>

now I just want to know where are this <div class="text">
<p class="bodytext"> comming frome


_PABLO on "how to add a menu page with elements wordpress?"

0
0

Hello, I have this example plugin for creating a page in the admin panel:

add_action( 'admin_menu', 'register_my_custom_menu_page' );

function register_my_custom_menu_page(){
	add_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'custompage', 'my_custom_menu_page', plugins_url( 'myplugin/images/icon.png' ), 6 );
}

function my_custom_menu_page(){
	echo "Admin Page Test";
}

All working, but I don't know how place elements of wordpress.
I would like to have on the new page function: edit header, edit title and description website. For all the answers, thank you.

sirflex10 on "How to create drop down options that dynamically change if a user selects one"

0
0

How can I create a form with a drop down list that dynamically changes and removes an option from the list each time it is selected? For example I want to run a fantasy football league.. I'd like a form that list 30 teams...each time a user completes the form and selects the team i'd like for that team to be removed from the list. Is this possible? Thank you.

Bilal Akil on "SSH for committing to plugin repository (SVN)?"

0
0

I'm the core maintainer of a plugin named Formataway, and I've a deployment script so I can keep using my Git repository without worrying about all the SVN stuff that I need to do to get my updates onto the plugin repository.

I found this very useful so I wrote a guide on it to help others.

However after some time I've become rather uncomfortable with having to keep variables like $SVN_PASSWORD online for such deployment scripts to operate. In a collaborative situation, that passport will be visible to all team members, and that's not good. So comes my question:

Is there some form of SSH keying with the WordPress plugin repository that I can use to give a server permission to push commits without needing to store and communicate a password?

GitHub for instance allows you to specify a list of publish SSH keys which can then communicate over that protocol instead of with HTTP authentication. The SSH keys look something like:

ssh-rsa [ REDACTED ]

larnoult on "Changing wp-admin menu label for a plugin"

0
0

Hey there,
I successfully figured out how to change wp-admin menu labels for built-in labels, following this post for exemple.

function change_post_menu_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'Contacts';
    $submenu['edit.php'][5][0] = 'Contacts';
    $submenu['edit.php'][10][0] = 'Add Contacts';
    $submenu['edit.php'][15][0] = 'Status'; // Change name for categories
    $submenu['edit.php'][16][0] = 'Labels'; // Change name for tags
    echo '';
}

function change_post_object_label() {
        global $wp_post_types;
        $labels = &$wp_post_types['post']->labels;
        $labels->name = 'Contacts';
        $labels->singular_name = 'Contact';
        $labels->add_new = 'Add Contact';
        $labels->add_new_item = 'Add Contact';
        $labels->edit_item = 'Edit Contacts';
        $labels->new_item = 'Contact';
        $labels->view_item = 'View Contact';
        $labels->search_items = 'Search Contacts';
        $labels->not_found = 'No Contacts found';
        $labels->not_found_in_trash = 'No Contacts found in Trash';
    }
    add_action( 'init', 'change_post_object_label' );
    add_action( 'admin_menu', 'change_post_menu_label' );

Yet, how should I do when I don't know the position in the $menu array of the plugin I want to change the label of?
Is there a way to display somewhere the position of each plugin label in the menu?

Thx for your help!

youngnawab on "All Posts loading Unknown Script"

0
0

hi there,my all posts are loading a unknown script : http://rankboostup.com/plugin/content.js .
Is it malware or something.i am not familiar with this script.i Deactivated all plugins but still loading that script,i can not find injected script in my functions.php or single.php files,how to detect exact location and remove this script from my site. my site url is lyricsraag.com

Guido on "Form Allowed Tags are gone"

0
0

Hi,

I notice the so called Form Allowed Tags are not displayed underneath the comments form anymore.

But they still are present in core (file comment-template): 'comment_notes_after'

So am I missing something?

Guido

I like screenshots on "How would I automatically append/suffix the post title with post ID"

0
0

How would I automatically append/suffix the post title with post ID?

e.g.
If I publish my post with the title "How to make a widget" when I use the <?php the_title(); ?> tag, the post title is displayed as "How to make a widget - 34" (assuming the post ID is 34.


zaydB on "post_not_in"

0
0

Hey guys,

Trying to get the post_not_in to work on a page that utilises related posts. So i can get the related posts displayed according to specific tags from the original post, it appears to work with the code I have, but I run into the into the issue of having the original post in the related posts section. Here is my code for displaying a single post:

<?php
/*
Single Post Template: event
*/
?>
<?php get_header(); ?>

<?php
global $post;

 if ( have_posts()) : while(have_posts()) : the_post();

 $link= get_post_meta(get_the_ID(),'Company Link',true);
 //$tags=wp_get_post_tags(the_post()->ID);//get array of tags
$tags = get_the_tags();

?>

<h2 class="page-title"><?php the_title();?></h2>
          <div id="post_content" class="post_content" role="main">
            <article class="type-post hentry">
              <div class="post-info">
                <div class="post_date">From: <?php echo get_post_meta(get_the_ID(),'Event Day Start',true);?> <?php echo get_post_meta(get_the_ID(),'Event Month Start',true);?> <?php echo get_post_meta(get_the_ID(),'Event Year Start',true);?> to <?php echo get_post_meta(get_the_ID(),'Event Day End',true);?> <?php echo get_post_meta(get_the_ID(),'Event Month End',true);?> <?php echo get_post_meta(get_the_ID(),'Event Year End',true);?></div>
               <a href="post-standart.html" class="post_format"></a> <a href="<?php echo get_post_meta(get_the_ID(),'Comapny Link',true);?>" class="comments_count"><?php echo get_post_meta(get_the_ID(),'Comapny Link',true);?></a>
              <div class="post_views"></div>
              </div>
              <div class="pic post_thumb"> <?php the_post_thumbnail(); ?> </div>
              <div class="post_content">
                <?php the_content(); ?>
              </div>
            </article>
            <div id="post_author">
              <h3>Location: <span style="font-weight:normal;"><?php echo get_post_meta(get_the_ID(),'Event Location',true); ?> </span></h3>
              <div class="photo"><img alt="" src="<?php print IMAGES; ?>/Link.jpg"/> </div>
              <div class="extra_wrap">
                <h4><a href="<?php echo $link; ?>" target="_blank"><?php echo $link; ?></h4></a>
                <div class="description"></div>
              </div>
            </div>

			<div id="recent_posts">
              <h3 class="section_title"> Related Articles </h3>
               <?php include(locate_template('related-posts.php'));//pass tags into related posts ?>

            </div>

				<?php endwhile;//Mainloop while end
					endif;//Mainloop if end
             wp_reset_postdata(); //
          ?>

	</div>

	</div>
</div>

<?php get_footer();
?>

and here is my related posts template. Note that i used:
include(locate_template('related-posts.php')); in order to use all variables available in the single post.

Related Posts:

<?php           $args=array('tag_in'=>$tags,
							'post_not_in'=>$post->ID,
							'post_per_page'=> 4,
							'ignore_sticky_posts'=>1,
							'post_type'=>array('events','news_article','opinions'));
				$rel_pst=get_posts($args);
				$count = 0;
				if($tags){
				foreach($rel_pst as $rel):setup_postdata($rel);//Loop through and find related posts
				if($count==4)
				{
					break;
				}
				$image = wp_get_attachment_image(get_post_thumbnail_id($rel->ID),'related-posts');
				//$tagy=$tags[$count];
				//Counts iterations to place aricles on seperate sides

				 if (($count  == 0)||($count == 2)){// first article start
					echo '<div class="posts_wrapper">';
					echo '<article class="item_left">';
				}
				if(($count == 1)||($count == 3)){// second article start
				 	echo'<article class="item_right">';
				 	}
				 ?>
                  <div class="pic"> <a href="<?php echo get_permalink($rel); ?>" class="w_hover img-link img-wrap"> <?php echo $image; ?></a> </div>
                  <h3><a href="<?php echo get_permalink($rel);?>"><?php echo substr(get_the_title($rel),0,12); ?></a></h3>
                  <div class="post-info"> <a href="<?php echo get_permalink($rel);?>" class="post_date"><?php echo get_the_tags($post->ID) ?></a> <a href="<?php echo get_permalink($rel); ?>" class="comments_count"></a> </div>
                </article>
                <?php if(($count == 1)||($count == 3)){//second article/4th end
                	echo '</div>';
              		  }
               $count ++;
                endforeach;
 				}

Please let me know if my approach was done correctly and what I can do to improve this.

Thanks :)

saNNNy on "Export post types with custom status for static HTML"

0
0

Hello,

I created two custom post statuses, one is public, one private. In WordPress, all works fine. The statuses are added to a custom post type.

But I want to export my website to static HTML (with WinHTTrack). Only 'published' posts are exported. The posts with a custom status are missing.

If I add the statuses to 'post' all posts are exported with my custom statuses. But not the posts of the custom post type.

I register my custom statuses in following code:

function custom_post_status()
{
	register_post_status('redaktion', array(
		'label' => _x('Redigiert', 'snippet'),
		'private' => true,
		'exclude_from_search'=> false,
		'show_in_admin_all_list' => true,
		'show_in_admin_status_list' => true,
		'label_count' => _n_noop( 'Redaktion <span class="count">(%s)</span>', 'Redigiert <span class="count">(%s)</span>')
	));

	register_post_status('testpublish', array(
		'label'	=> _x('Testveröffentlicht', 'snippet'),
		'public' => true,
		'exclude_from_search' => false,
		'show_in_admin_all_list' => true,
		'show_in_admin_status_list' => true,
		'post_type_support' => true,
		'label_count' => _n_noop( 'Testveröffentlicht <span class="count">(%s)</span>', 'Testveröffentlichte <span class="count">(%s)</span>')
	));
}
add_action('init', 'custom_post_status', 1);

The custom post type is registered in the next code snippet.

public static function register()
{
	$post_type_args = array
	(
		'public'  => TRUE,
		'show_ui' => TRUE,
		'exclude_from_search' => TRUE,
		'show_in_nav_menus' => FALSE,
		'rewrite' => array('slug' => 'snippet', 'with_front' => FALSE),
		'supports' => array('title', 'editor', 'author', 'revisions'),
	);
	register_post_type('snippet', $post_type_args);

Hopefully, someone can help me.
Thanks already.

lup0z on "delete_attachment isn't fired"

0
0

Hi,
I'm developing a custom gallery which uses an XML DB for the purpose.
Now I would like to synchronize the XML with the Media Library: when deleting an image from the Media Library, the ID of the image stored in the XML file will be deleted too, so:

function onWpDelete( $targetID ){

    $filePath = '../wp-content/plugins/the-plugin/gallery.xml';
    if( file_exists( $filePath ) ){
        $doc = new DOMDocument();
        $doc->load($filename);
        $doc->preserveWhiteSpace = false;
        $doc->formatOutput = true;

        $ids = $doc->getElementsByTagName('ID');
        foreach( $ids as $id ){
            if( $id->nodeValue == $targetID ){

                try{
                    $id->parentNode->removeChild($id);
                } catch(Exception $e){
                    wp_die('DOMDocument: ' . $e->getmessage() );
                }//try - catch

                break;
            }//if
        }//foreach
    }//if
}//onWpDelete
add_action('delete_attachment', 'onWpDelete');

but I can't get the delete_attachment hook fired when I delete an image from the Media Library and can't make it working.
I even tried:

add_action('delete_attachment', 'onWpDelete', 1', 1);

because of the $postid parameter for the hook but it doesn't work.

What's the correct way to do that?

Thank you

rblakstad on "Isotope - Filter child categories based on ACF parent category"

0
0

Hi,

I want to list child cateogories in my Isotope-filtering. The child categories should be based on the chosen parent category in admin (ACF). Right now it fetches ALL categories there is.

How can I solve this? This is my code so far:

<ul id="filters">
    <a href="#" data-filter="*" class="selected button"><?php _e('Alla'); ?></a>
	<?php
		$terms = get_terms("category");
		$count = count($terms);
		if ( $count > 0 ){
			foreach ( $terms as $term ) {
				echo "<a href='#' class='button' data-filter='.".$term->slug."'>" . $term->name . "</a>\n";
			}
		}
	?>
</ul>

<?php $the_query = new WP_Query( array(
     'posts_per_page'	=> -1,
     'cat'			    => get_field('isotope_cat')
));
?>
<?php if ( $the_query->have_posts() ) : ?>

        <div id="isotope-list" style="margin-left:20px">

            <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

            <div class="item col_6 last sub">
	        <?php if ( has_post_thumbnail() ) { ?>
        <a href="<?php the_permalink(); ?>">
                     <?php the_post_thumbnail(); ?>
        </a>
         <?php } ?>

        <div class="sub-content">
            <h3><?php the_category(', '); ?></h3>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php echo get_excerpt(50); ?>
        </div>
	</div><!-- end item -->
    <?php endwhile;  ?>
    </div>

    <!-- end isotope-list -->
<?php endif; ?>

Thank you

_Lui_ on "before_delete_post - problems?!"

0
0

Hey guys,

i made myself a plugin. It inserts/edits/deletes WP-Posts into another database. But i want to have an error message if the DB-Connection fails. If i dont "stop" inserting/editing/deleting if the connection is not established, it is going to get really annyoing.

This is my code (just getting started coding with WP :) )

--------------------------------------------
function project_insertDB(){
//insert post
}

function project_deleteDB(){
//delete post
}

function project_editDB()<7
//edit post
}

add_action('publish_project', 'project_insertDB');
add_action('before_delete_post', 'project_deleteDB');
add_action('edit_post', 'project_editDB');
--------------------------------------------------------

I thought about a simple

if(!$connection){
exit("No database connection")
}

inside each function with different messages. The problem is, it fires the "project_insertDB" even if i am just editing and it doesnt prevent WP from f.e. deleting an already existing post if you want to put it into the trash. It shows the error message, but didnt stop putting it into the trash. Is there a way to, lets say, stop WP from doing someting? And to net let fire "project_insertDB" if i am just editing a post?

I am not a native speaker, so i hope that makes sense ;P

Thanks in advance,
Lui

Howdy_McGee on "Undefined Index HTTP_HOST - canonical / nav-menu-template"

0
0

On of my popular WordPress installs is getting its debug.log blasted with two errors:

PHP Notice:  Undefined index: HTTP_HOST in /wp-includes/canonical.php on line 63
PHP Notice:  Undefined index: HTTP_HOST in /wp-includes/nav-menu-template.php on line 549

The following lines show:

canonical.php

$requested_url .= $_SERVER['HTTP_HOST'];

nav-menu-template

$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );

This seems like an issue with WordPress generated by bots visiting the site. Do I make a ticket about this? I'm not entirely sure how to replicate the issue but it's becoming a problem as I usually like having my debug.log on incase a real issues occurs.

Anybody else have this issue / can replicate the issue?

wp_chats2 on "Adding username as variable in a url redirect"

0
0

Ok, first off, if this has been answered, or is the wrong forum, i sincerely apologize, and for what its worth, ive spent hours scouring google, etc. trying to patch this together myself. I have very little, to no experience with php, and im assuming thats where the answer to this lies, so again, i apoligize, and pretend youre explaining it to your 5 year old lol. ok... I want to call a url in an iframe on a page (in WP obv) and want to call the username as a variable in that url. So something like
//
<iframe src="http://example.com/whatever.php?part=$variable_here"> </iframe>

so from what ive gathered, i can call wp_get_current_user into a variable named $variable_here and that should work. However, where im lost is, the very little background I have is in straight oldschool html, and WP, and this is completely layman's, is all php/css based? So is it possible to call that within a page? Can I edit/create a php file in dreamweaver to do this, and then call that within a page? Can it just be done from within wordpress? Am i completely lost? lol.. any help, even just a nudge in the right direction would be beyond appreciated. Thanks so much!


n00bie12 on "DB insert row working, but still getting "WordPress database error: []""

0
0

Coding my first official plugin and boy has it been fun. ;) Woot, woot.

Inserting table row in db from form processor seems to be working, as desired, based on what I see in phpMyAdmin. However, I still get the following error:
WordPress database error: []
INSERT INTO wp_attendance_intent (wp_user_id, attendance_type, date) VALUES (1, 'Present', '2015-10-04 00:00:00')

The err msg is so cryptic: not sure what I'm doing wrong, especially since the db table seems to have the right info added in a new row, as desired. Any thoughts or suggestions?

Simplified processor script is as follows...

<?php
require_once("../../../../wp-load.php");
get_header();

if($_POST['formSubmit'] == "Submit") {	//If form submit button clicked, then store submitted form values in vars.
	$form_user = $_POST['user'];
	$form_date = $_POST['date'];
	$form_attendance_type = $_POST['attendance_type'];
	$form_date = strtotime( $form_date );	//Convert date string to unix date for PHP manipulation.
	$form_date = date( 'Y-m-d H:i:s', $form_date );	//Format date for storage in SQL DB.

	global $wpdb;
		$wpdb->show_errors();
		$table_name = $wpdb->prefix . 'attendance_intent';

		$data = array(
			'wp_user_id' => $form_user,
			'attendance_type' => $form_attendance_type,
			'date' => $form_date
		);
		$format = array(
			'%d',
			'%s',
			'%s'
		);
		$wpdb->insert( $table_name, $data, $format );
		$wpdb->print_error();

	}
}

get_footer(); //Insert footer.

Knappers on "Menu dropdown is behind content"

0
0

My menu on Twenty Twelve theme is dropping down behind content on my page.

It only seems to do it on one page that has a slider on it but i am unable to find the correct z-index to change.

is there a hack to stop this from happening.

This is the page i am having problems with.
My Offending page

Many Thanks

thorm on "Customize wordpress translation"

0
0

I have a custom wordpress translation .mo file

How can i avoid loose it after a wp update?

dawgawel on "wp.media.query multiple types"

0
0

Is it possible (and how) to create js media collection using multiple (but not all) media types, for example 'image' and 'video'?

For example:

if ( ! this.get('library') ) {
    this.set( 'library', wp.media.query( { type: 'image|video' } ) );
}

bradym24 on "Advanced searching - Query (please help! :))"

0
0

Hi,

Any help here is much appreciated, this won't be very straight-forward

I'm about to get started on my WP site but before I can do this I need to ensure a crucial function that will practically be the foundation of the website, is possible to build in wordpress.

Essentially I am going to have a blog that includes information of a specific type (manually entered) that is shown on my website in the form of blog type-updates (an example that I'm not doing in the website, but we will use for discussion purposes is windows updates).

I want to build an advanced search feature where when the user clicks on a category button or types in a category (eg. security, or "windows media player" or something similar) and when doing so, the page that appears will have queried all previously entered data on the website and will have sorted all of the security updates or windows media player updates (from the beginning of time) in Date order, with the release date hanging off the side of each update.

So instead of just displaying all previous posts that "contained" information that I'm searching for and you have to click and search through, have it actually display all of the individual strings all on the same page.

(eg. Windowsupdate#1 1/1/2010
Windowsupdate#2 2/2/2020
Windowsupdate#3 3/3/2030
)

This means I may have to create some form of code that I can place next to each line of text in my manual updates that adds them to these "categories" also.

Basically I just need to know if this is even possible, complicated or not. Before I go spending any money on resources for getting the website up and going via wordpress :)

Thanks so much, apologies if this doesn't make sense

Viewing all 8245 articles
Browse latest View live




Latest Images