php – Source link plugin – show just anchor / link

I implemented a small source link plugin on my WordPress website via the following codes.

Single.php:

                        <?php
global $post, $pages, $page;

$total = count( $pages );
// Link źródłowy
if ( $total < 2 || $page === $total ) :
    
    if ( $url = get_post_meta( $post->ID, '_source_link', true ) ) :
        $label = get_post_meta( $post->ID, '_source_link_label', true );
        $label = $label ? $label : $url;
    ?>
        <div class="source-link">
            <b>Źródło:</b> <a href="<?php echo esc_url( $url ); ?>" rel="nofollow" target="_blank"><?php  
              echo esc_html( $label ); ?></a>
        </div>
    <?php endif; 
endif; 
?>

Functions.php:

add_action( 'add_meta_boxes', 'wpse_source_link' );


add_action( 'save_post', 'wpse_source_link_save' );


function wpse_source_link() {

    add_meta_box(
        'source_link',
        __( 'Link źródłowy', 'myplugin_textdomain' ), 
        'wpse_source_meta_box',
        'post',
        'side'
    );
}


function wpse_source_meta_box( $post ) {

 
  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );

  
  echo '<label for="source-link">Link</label> ';
  echo '<input type="text" id="source-link"" name="source_link" value="'.
    get_post_meta( $post->ID, '_source_link', true ) .'" size="25" />';

  echo '<label for="source-link-label">Nazwa strony</label> ';
  echo '<input type="text" id="source-link-label"" name="source_link_label" value="'.
    get_post_meta( $post->ID, '_source_link_label', true ) .'" size="25" />';
}


function wpse_source_link_save( $post_id ) {

  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
      return;

  if ( ! wp_verify_nonce( $_POST('myplugin_noncename'), plugin_basename( __FILE__ ) ) )
      return;


  if ( current_user_can( 'edit_post', $post_id ) ) {

      update_post_meta( $post_id, '_source_link', sanitize_text_field( $_POST('source_link') ) );
      update_post_meta( $post_id, '_source_link_label', sanitize_text_field( $_POST('source_link_label') ) );

   }
}

As you can see there are two fields:
Link źródłowy (Source link) and Nazwa strony (website name – anchor). However, at this moment this plugin only works, when both fields have some text inside. Is there any way to make it work also with just anchor/link? I mean, if two fields are completed it should show anchor with link, but if just anchor has some text in it, then it should show only anchor. Same goes for link.

Does anyone know how to make it work like that? To be honest I’m a newbie and I have no idea.

php – Source link plugin – show just anchor/link

I implemented a small source link plugin on my WordPress website via the following codes:

add_action( 'add_meta_boxes', 'wpse_source_link' );


add_action( 'save_post', 'wpse_source_link_save' );


function wpse_source_link() {

    add_meta_box(
        'source_link',
        __( 'Link źródłowy', 'myplugin_textdomain' ), 
        'wpse_source_meta_box',
        'post',
        'side'
    );
}


function wpse_source_meta_box( $post ) {

 
  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );

  
  echo '<label for="source-link">Link</label> ';
  echo '<input type="text" id="source-link"" name="source_link" value="'.
    get_post_meta( $post->ID, '_source_link', true ) .'" size="25" />';

  echo '<label for="source-link-label">Nazwa strony</label> ';
  echo '<input type="text" id="source-link-label"" name="source_link_label" value="'.
    get_post_meta( $post->ID, '_source_link_label', true ) .'" size="25" />';
}


function wpse_source_link_save( $post_id ) {

  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
      return;

  if ( ! wp_verify_nonce( $_POST('myplugin_noncename'), plugin_basename( __FILE__ ) ) )
      return;


  if ( current_user_can( 'edit_post', $post_id ) ) {

      update_post_meta( $post_id, '_source_link', sanitize_text_field( $_POST('source_link') ) );
      update_post_meta( $post_id, '_source_link_label', sanitize_text_field( $_POST('source_link_label') ) );

   }
}
                        <?php
global $post, $pages, $page;

$total = count( $pages );
// Link źródłowy
if ( $total < 2 || $page === $total ) :
    
    if ( $url = get_post_meta( $post->ID, '_source_link', true ) ) :
        $label = get_post_meta( $post->ID, '_source_link_label', true );
        $label = $label ? $label : $url;
    ?>
        <div class="source-link">
            <b>Źródło:</b> <a href="<?php echo esc_url( $url ); ?>" rel="nofollow" target="_blank"><?php  
              echo esc_html( $label ); ?></a>
        </div>
    <?php endif; 
endif; 
?>

As you can see there are two fields:
Link źródłowy (Source link) and Nazwa strony (website name – anchor). However, at this moment this plugin only works, when both fields have some text inside. Is there any way to make it work also with just anchor/link? I mean, if two fields are completed it should show anchor with link, but if just anchor has some text in it, then it should show only anchor. Same goes for link.

Compilation from source: LESS file is empty: order email sent without css and an warning

Getting this error while sending order emails.Compilation from source: LESS file is empty: order email sent without css and an warning

8 – How to unpublish nodes which are missing in migration source?

I have a CSV file with two rows. I executed the migration and two nodes are imported.

Now I deleted one row from the CSV and execute the migration again.

I now want to unpublish the node which is missing in the CSV.

Is it possible? How will I do that?

android source – which of these Folder I will use

I work on Ubuntu 14 and Download Android source code Marshmallow (AOSP 6) this the files Downloaded,Now which of these Folders should be used to show notification to the user about his apps uses the camera on mobile. or read and extract permission on my own File and notify the user what “package name and has permission to access camera” like”messenger use camera” and so on I know this can be done by apps but I want to do this in AOSP for scientific goals.can you help me about where I will start the modification and how ? or the books can help me about How to read Folders and modify the AOSP ?

Custom migrate source plugin, extends FieldableEntity class, has migrate status of [error] No migrations found. Why?

I’m writing a migrate source plugin for migrating D7 entityform (entityform module) submissions. If anyone has done this or knows an existing plugin, please let me know.

I am trying to extend the FieldableEntity base class from Drupalmigrate_drupalPluginmigratesourced7FieldableEntity; because I want to use its getFields() and getFieldValues() methods when I override prepareRow() to include custom fields from my D7 entityform.

My problem is that when my source plugin extends FieldableEntity, drush reports (error) No migrations found. for my migration. Importantly, however, if my source plugin instead uses the SqlBase class from DrupalmigratePluginmigratesourceSqlBase, then drush can import all of my entityforms from D7 into D9 contact forms no problem. So it would seem that I am missing something when I try to implement FieldableEntity preventing it from retrieving data for the migration.

Here is my plugin, which shows up fine in drush ms:

<?php

namespace Drupalmymodule_migratePluginmigratesource;

use DrupalmigrateRow;
use Drupalmigrate_drupalPluginmigratesourced7FieldableEntity;

/**
 * The 'mymodule_migrate_entityform' source plugin.
 *
 * @MigrateSource(
 *   id = "mymodule_migrate_entityform",
 *   source_module = "mymodule_migrate"
 * )
 */
class Entityform extends FieldableEntity {

  /**
   * {@inheritdoc}
   */
  public function query() {
    $query = $this->select('entityform', 'e')
      ->fields('e', (
        'entityform_id',
        'type',
        'created',
        'changed',
        'uid'
      ));
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    return array(
      'entityform_id' => $this->t('The ID of the entityform submission.'),
      'type' => $this->t('The entityform type.'),
      'created' => $this->t('The time that the entityform was submitted.'),
      'changed' => $this->t('Last updated time.'),
      'uid' => $this->t('The {users}.uid who submitted the entityform. If set to 0, this entityform was submitted by an anonymous user.'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids('entityform_id')('type') = 'integer';
    $ids('entityform_id')('alias') = 'e';
    return $ids;
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    $entityform_id = $row->getSourceProperty('entityform_id');
    // Get Field API field values.
    foreach ($this->getFields('entityform', 'BUNDLE_MACHINE_NAME') as $field_name => $field) {
      $row->setSourceProperty($field_name, $this->getFieldValues('entityform', $field_name, $entityform_id));
    }
    return parent::prepareRow($row);
  }

}

I use this yml migration definition. My migrate destination is D8/D9 contact_message entity.

id: mymodule_contact_message
label: D8 Contact message migration from D7 entityform submission
source:
  plugin: mymodule_migrate_entityform
process:
  id: entityform_id
  langcode:
    plugin: default_value
    source: language
    default_value: "und"
  created: created
  changed: changed
destination:
  plugin: entity:contact_message
  default_bundle: MY_DESTINATION_BUNDLE

As stated above, all of this works great when I use SqlBase in my plugin. But with FieldableEntity drush comes back with (error) No migrations found.

how can I analyze my website's source code?

Hi! I think there is a destructive code in my website's source code. how can I analyze it? Is there any tools?

open source alternative of some online designer like "cloudcraft"

https://app.cloudcraft.co/ is a nice place for you to design cloud architecture.

I would like to know is there any open-source project that could let you drag some objects to the grid and connect them and visualize them.

what to choose open source or closed source?

The release of open source software has become one of the most important IT directions. But as the popularity of open systems grows, the issues of their reliability and security are becoming more acute.
So what can be considered more reliable and forward-looking: open source or still closed source?

What are your opinions?

database – How to read source code for big projects?

I was trying to read source code for redis db and I could understand the code but there were too many files, and thousands of lines of code which got me confused. I tried reading flockdb which is considerably smaller but it’s written in scala which I don’t know if it’s worth learning. So how should I try going about this? How am I supposed to traverse through the thousands of lines and the file system? Also I don’t need to only understand big projects or even databases for that matter, if there’s any other suggestions of smaller projects that I would be better off starting with I’d appreciate it. The type of open source projects I am trying to study are ones like VPNs, antivirus software and the kind.