Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../src/Forms
File: Locator.php
}
[500] Fix | Delete
[501] Fix | Delete
$sidebar_name = $this->get_widget_sidebar_name( $form_location['id'] );
[502] Fix | Delete
[503] Fix | Delete
if ( ! $sidebar_name ) {
[504] Fix | Delete
// The widget is not found.
[505] Fix | Delete
return '';
[506] Fix | Delete
}
[507] Fix | Delete
[508] Fix | Delete
$title = $form_location['title'];
[509] Fix | Delete
[510] Fix | Delete
if ( ! $title ) {
[511] Fix | Delete
if ( strpos( $form_location['id'], self::WPFORMS_WIDGET_PREFIX ) === 0 ) {
[512] Fix | Delete
$title = $this->wpforms_widget_title;
[513] Fix | Delete
}
[514] Fix | Delete
[515] Fix | Delete
if ( strpos( $form_location['id'], 'text-' ) === 0 ) {
[516] Fix | Delete
$title = $this->text_widget_title;
[517] Fix | Delete
}
[518] Fix | Delete
}
[519] Fix | Delete
[520] Fix | Delete
return $sidebar_name . ': ' . $title;
[521] Fix | Delete
}
[522] Fix | Delete
[523] Fix | Delete
/**
[524] Fix | Delete
* Get location url.
[525] Fix | Delete
*
[526] Fix | Delete
* @since 1.7.4
[527] Fix | Delete
*
[528] Fix | Delete
* @param array $form_location Form location.
[529] Fix | Delete
*
[530] Fix | Delete
* @return string
[531] Fix | Delete
*/
[532] Fix | Delete
private function get_location_url( $form_location ) {
[533] Fix | Delete
[534] Fix | Delete
// Get widget or wp_template url.
[535] Fix | Delete
if ( $form_location['type'] === self::WIDGET || $this->is_wp_template( $form_location['type'] ) ) {
[536] Fix | Delete
return '';
[537] Fix | Delete
}
[538] Fix | Delete
[539] Fix | Delete
// Get standalone url.
[540] Fix | Delete
if ( $this->is_standalone( $form_location['type'] ) ) {
[541] Fix | Delete
return $form_location['url'];
[542] Fix | Delete
}
[543] Fix | Delete
[544] Fix | Delete
// Get post url.
[545] Fix | Delete
if ( ! $this->is_post_visible( $form_location ) ) {
[546] Fix | Delete
return '';
[547] Fix | Delete
}
[548] Fix | Delete
[549] Fix | Delete
return $form_location['url'];
[550] Fix | Delete
}
[551] Fix | Delete
[552] Fix | Delete
/**
[553] Fix | Delete
* Get location edit url.
[554] Fix | Delete
*
[555] Fix | Delete
* @since 1.7.4
[556] Fix | Delete
*
[557] Fix | Delete
* @param array $form_location Form location.
[558] Fix | Delete
*
[559] Fix | Delete
* @return string
[560] Fix | Delete
*/
[561] Fix | Delete
private function get_location_edit_url( array $form_location ): string {
[562] Fix | Delete
[563] Fix | Delete
// Get widget url.
[564] Fix | Delete
if ( $form_location['type'] === self::WIDGET ) {
[565] Fix | Delete
return current_user_can( 'edit_theme_options' ) ? admin_url( 'widgets.php' ) : '';
[566] Fix | Delete
}
[567] Fix | Delete
[568] Fix | Delete
// Get standalone url.
[569] Fix | Delete
if ( $this->is_standalone( $form_location['type'] ) ) {
[570] Fix | Delete
return add_query_arg(
[571] Fix | Delete
[
[572] Fix | Delete
'page' => 'wpforms-builder',
[573] Fix | Delete
'view' => 'settings',
[574] Fix | Delete
'form_id' => $form_location['form_id'],
[575] Fix | Delete
],
[576] Fix | Delete
admin_url( 'admin.php' )
[577] Fix | Delete
);
[578] Fix | Delete
}
[579] Fix | Delete
[580] Fix | Delete
// Get post url.
[581] Fix | Delete
if ( ! $this->is_post_visible( $form_location ) ) {
[582] Fix | Delete
return '';
[583] Fix | Delete
}
[584] Fix | Delete
[585] Fix | Delete
if ( $this->is_wp_template( $form_location['type'] ) ) {
[586] Fix | Delete
return add_query_arg(
[587] Fix | Delete
[
[588] Fix | Delete
'postType' => $form_location['type'],
[589] Fix | Delete
'postId' => get_stylesheet() . '//' . str_replace( '/', '', $form_location['url'] ),
[590] Fix | Delete
],
[591] Fix | Delete
admin_url( 'site-editor.php' )
[592] Fix | Delete
);
[593] Fix | Delete
}
[594] Fix | Delete
[595] Fix | Delete
return (string) get_edit_post_link( $form_location['id'], '' );
[596] Fix | Delete
}
[597] Fix | Delete
[598] Fix | Delete
[599] Fix | Delete
/**
[600] Fix | Delete
* Get location information to output as a row in the location pane.
[601] Fix | Delete
*
[602] Fix | Delete
* @since 1.7.4
[603] Fix | Delete
*
[604] Fix | Delete
* @param array $form_location Form location.
[605] Fix | Delete
*
[606] Fix | Delete
* @return string
[607] Fix | Delete
* @noinspection PhpTernaryExpressionCanBeReducedToShortVersionInspection
[608] Fix | Delete
* @noinspection ElvisOperatorCanBeUsedInspection
[609] Fix | Delete
*/
[610] Fix | Delete
private function get_location_row( $form_location ) {
[611] Fix | Delete
[612] Fix | Delete
$title = $this->get_location_title( $form_location );
[613] Fix | Delete
[614] Fix | Delete
$title = $title ? $title : __( '(no title)', 'wpforms-lite' );
[615] Fix | Delete
[616] Fix | Delete
$location_url = $this->get_location_url( $form_location );
[617] Fix | Delete
$location_link = '';
[618] Fix | Delete
[619] Fix | Delete
if ( $location_url ) {
[620] Fix | Delete
$location_full_url = $this->home_url . $location_url;
[621] Fix | Delete
[622] Fix | Delete
// phpcs:ignore Generic.Commenting.DocComment.MissingShort
[623] Fix | Delete
/** @noinspection HtmlUnknownTarget */
[624] Fix | Delete
$location_link = sprintf(
[625] Fix | Delete
' <a href="%1$s" target="_blank" class="wpforms-locations-link">%2$s <i class="fa fa-external-link" aria-hidden="true"></i></a>',
[626] Fix | Delete
esc_url( $location_full_url ),
[627] Fix | Delete
esc_url( $location_url )
[628] Fix | Delete
);
[629] Fix | Delete
}
[630] Fix | Delete
[631] Fix | Delete
$location_edit_url = $this->get_location_edit_url( $form_location );
[632] Fix | Delete
$location_edit_url = $location_edit_url ? $location_edit_url : '#';
[633] Fix | Delete
[634] Fix | Delete
// phpcs:ignore Generic.Commenting.DocComment.MissingShort
[635] Fix | Delete
/** @noinspection HtmlUnknownTarget */
[636] Fix | Delete
$location_edit_link = sprintf(
[637] Fix | Delete
'<a href="%1$s">%2$s</a>',
[638] Fix | Delete
esc_url( $location_edit_url ),
[639] Fix | Delete
esc_html( $title )
[640] Fix | Delete
);
[641] Fix | Delete
[642] Fix | Delete
// Escaped above.
[643] Fix | Delete
return sprintf(
[644] Fix | Delete
'<span class="wpforms-locations-list-item">%s</span>',
[645] Fix | Delete
$location_edit_link . wp_kses_post( urldecode( $location_link ) )
[646] Fix | Delete
);
[647] Fix | Delete
}
[648] Fix | Delete
[649] Fix | Delete
/**
[650] Fix | Delete
* Get location information to output as rows in the location pane.
[651] Fix | Delete
*
[652] Fix | Delete
* @since 1.7.4
[653] Fix | Delete
*
[654] Fix | Delete
* @param array $form_locations Form locations.
[655] Fix | Delete
*
[656] Fix | Delete
* @return array
[657] Fix | Delete
*/
[658] Fix | Delete
private function get_location_rows( $form_locations ) {
[659] Fix | Delete
[660] Fix | Delete
$rows = [];
[661] Fix | Delete
[662] Fix | Delete
foreach ( $form_locations as $form_location ) {
[663] Fix | Delete
$rows[] = $this->get_location_row( $form_location );
[664] Fix | Delete
}
[665] Fix | Delete
[666] Fix | Delete
$rows = array_unique( array_filter( $rows ) );
[667] Fix | Delete
[668] Fix | Delete
uasort(
[669] Fix | Delete
$rows,
[670] Fix | Delete
static function ( $a, $b ) {
[671] Fix | Delete
$pattern = '/href=".+widgets.php">(.+?)</i';
[672] Fix | Delete
[673] Fix | Delete
$widget_title_a = preg_match( $pattern, $a, $ma ) ? $ma[1] : '';
[674] Fix | Delete
$widget_title_b = preg_match( $pattern, $b, $mb ) ? $mb[1] : '';
[675] Fix | Delete
[676] Fix | Delete
return strcmp( $widget_title_a, $widget_title_b );
[677] Fix | Delete
}
[678] Fix | Delete
);
[679] Fix | Delete
[680] Fix | Delete
return $rows;
[681] Fix | Delete
}
[682] Fix | Delete
[683] Fix | Delete
/**
[684] Fix | Delete
* Update form location on save_post action.
[685] Fix | Delete
*
[686] Fix | Delete
* @since 1.7.4
[687] Fix | Delete
*
[688] Fix | Delete
* @param int $post_ID Post ID.
[689] Fix | Delete
* @param WP_Post $post Post object.
[690] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[691] Fix | Delete
*
[692] Fix | Delete
* @noinspection PhpUnusedParameterInspection
[693] Fix | Delete
*/
[694] Fix | Delete
public function save_post( $post_ID, $post, $update ) {
[695] Fix | Delete
[696] Fix | Delete
if (
[697] Fix | Delete
$update ||
[698] Fix | Delete
! in_array( $post->post_type, $this->get_post_types(), true ) ||
[699] Fix | Delete
! in_array( $post->post_status, $this->get_post_statuses(), true )
[700] Fix | Delete
) {
[701] Fix | Delete
return;
[702] Fix | Delete
}
[703] Fix | Delete
[704] Fix | Delete
$form_ids = $this->get_form_ids( $post->post_content );
[705] Fix | Delete
[706] Fix | Delete
$this->update_form_locations_metas( null, $post, [], $form_ids );
[707] Fix | Delete
}
[708] Fix | Delete
[709] Fix | Delete
/**
[710] Fix | Delete
* Update form location on post_updated action.
[711] Fix | Delete
*
[712] Fix | Delete
* @since 1.7.4
[713] Fix | Delete
*
[714] Fix | Delete
* @param int $post_id Post id.
[715] Fix | Delete
* @param WP_Post $post_after Post after the update.
[716] Fix | Delete
* @param WP_Post $post_before Post before the update.
[717] Fix | Delete
*
[718] Fix | Delete
* @noinspection PhpUnusedParameterInspection
[719] Fix | Delete
*/
[720] Fix | Delete
public function post_updated( $post_id, $post_after, $post_before ) {
[721] Fix | Delete
[722] Fix | Delete
if (
[723] Fix | Delete
! in_array( $post_after->post_type, $this->get_post_types(), true ) ||
[724] Fix | Delete
! in_array( $post_after->post_status, $this->get_post_statuses(), true )
[725] Fix | Delete
) {
[726] Fix | Delete
return;
[727] Fix | Delete
}
[728] Fix | Delete
[729] Fix | Delete
$form_ids_before = $this->get_form_ids( $post_before->post_content );
[730] Fix | Delete
$form_ids_after = $this->get_form_ids( $post_after->post_content );
[731] Fix | Delete
[732] Fix | Delete
$this->update_form_locations_metas( $post_before, $post_after, $form_ids_before, $form_ids_after );
[733] Fix | Delete
}
[734] Fix | Delete
[735] Fix | Delete
/**
[736] Fix | Delete
* Update form locations on trash_post action.
[737] Fix | Delete
*
[738] Fix | Delete
* @since 1.7.4
[739] Fix | Delete
*
[740] Fix | Delete
* @param int $post_id Post id.
[741] Fix | Delete
*/
[742] Fix | Delete
public function trash_post( $post_id ) {
[743] Fix | Delete
[744] Fix | Delete
$post = get_post( $post_id );
[745] Fix | Delete
$form_ids_before = $this->get_form_ids( $post->post_content );
[746] Fix | Delete
$form_ids_after = [];
[747] Fix | Delete
[748] Fix | Delete
$this->update_form_locations_metas( null, $post, $form_ids_before, $form_ids_after );
[749] Fix | Delete
}
[750] Fix | Delete
[751] Fix | Delete
/**
[752] Fix | Delete
* Update form locations on untrash_post action.
[753] Fix | Delete
*
[754] Fix | Delete
* @since 1.7.4
[755] Fix | Delete
*
[756] Fix | Delete
* @param int $post_id Post id.
[757] Fix | Delete
*/
[758] Fix | Delete
public function untrash_post( $post_id ) {
[759] Fix | Delete
[760] Fix | Delete
$post = get_post( $post_id );
[761] Fix | Delete
$form_ids_before = [];
[762] Fix | Delete
$form_ids_after = $this->get_form_ids( $post->post_content );
[763] Fix | Delete
[764] Fix | Delete
$this->update_form_locations_metas( null, $post, $form_ids_before, $form_ids_after );
[765] Fix | Delete
}
[766] Fix | Delete
[767] Fix | Delete
/**
[768] Fix | Delete
* Prepare widgets for further search.
[769] Fix | Delete
*
[770] Fix | Delete
* @since 1.7.4
[771] Fix | Delete
*
[772] Fix | Delete
* @param array|null $widgets Widgets.
[773] Fix | Delete
* @param string $type Widget type.
[774] Fix | Delete
*
[775] Fix | Delete
* @return array
[776] Fix | Delete
*/
[777] Fix | Delete
private function prepare_widgets( $widgets, $type ) {
[778] Fix | Delete
[779] Fix | Delete
$params = [
[780] Fix | Delete
'wpforms' => [
[781] Fix | Delete
'option' => self::WPFORMS_WIDGET_OPTION,
[782] Fix | Delete
'content' => 'form_id',
[783] Fix | Delete
],
[784] Fix | Delete
'text' => [
[785] Fix | Delete
'option' => self::TEXT_WIDGET_OPTION,
[786] Fix | Delete
'content' => 'text',
[787] Fix | Delete
],
[788] Fix | Delete
'block' => [
[789] Fix | Delete
'option' => self::BLOCK_WIDGET_OPTION,
[790] Fix | Delete
'content' => 'content',
[791] Fix | Delete
],
[792] Fix | Delete
];
[793] Fix | Delete
[794] Fix | Delete
if ( ! array_key_exists( $type, $params ) ) {
[795] Fix | Delete
return [];
[796] Fix | Delete
}
[797] Fix | Delete
[798] Fix | Delete
$option = $params[ $type ]['option'];
[799] Fix | Delete
$content = $params[ $type ]['content'];
[800] Fix | Delete
[801] Fix | Delete
$widgets = $widgets ?? (array) get_option( $option, [] );
[802] Fix | Delete
[803] Fix | Delete
return array_filter(
[804] Fix | Delete
$widgets,
[805] Fix | Delete
static function ( $widget ) use ( $content ) {
[806] Fix | Delete
[807] Fix | Delete
return isset( $widget[ $content ] );
[808] Fix | Delete
}
[809] Fix | Delete
);
[810] Fix | Delete
}
[811] Fix | Delete
[812] Fix | Delete
/**
[813] Fix | Delete
* Search forms in WPForms widgets.
[814] Fix | Delete
*
[815] Fix | Delete
* @since 1.7.4
[816] Fix | Delete
*
[817] Fix | Delete
* @param array $widgets Widgets.
[818] Fix | Delete
*
[819] Fix | Delete
* @return array
[820] Fix | Delete
*/
[821] Fix | Delete
private function search_in_wpforms_widgets( $widgets = null ) {
[822] Fix | Delete
[823] Fix | Delete
$widgets = $this->prepare_widgets( $widgets, 'wpforms' );
[824] Fix | Delete
[825] Fix | Delete
$locations = [];
[826] Fix | Delete
[827] Fix | Delete
foreach ( $widgets as $id => $widget ) {
[828] Fix | Delete
$locations[] = [
[829] Fix | Delete
'type' => self::WIDGET,
[830] Fix | Delete
'title' => $widget['title'],
[831] Fix | Delete
'form_id' => $widget['form_id'],
[832] Fix | Delete
'id' => self::WPFORMS_WIDGET_PREFIX . $id,
[833] Fix | Delete
];
[834] Fix | Delete
}
[835] Fix | Delete
[836] Fix | Delete
return $locations;
[837] Fix | Delete
}
[838] Fix | Delete
[839] Fix | Delete
/**
[840] Fix | Delete
* Search forms in text widgets.
[841] Fix | Delete
*
[842] Fix | Delete
* @since 1.7.4
[843] Fix | Delete
*
[844] Fix | Delete
* @param array $widgets Widgets.
[845] Fix | Delete
*
[846] Fix | Delete
* @return array
[847] Fix | Delete
*/
[848] Fix | Delete
private function search_in_text_widgets( $widgets = null ) {
[849] Fix | Delete
[850] Fix | Delete
$widgets = $this->prepare_widgets( $widgets, 'text' );
[851] Fix | Delete
[852] Fix | Delete
$locations = [];
[853] Fix | Delete
[854] Fix | Delete
foreach ( $widgets as $id => $widget ) {
[855] Fix | Delete
$form_ids = $this->get_form_ids( $widget['text'] );
[856] Fix | Delete
[857] Fix | Delete
foreach ( $form_ids as $form_id ) {
[858] Fix | Delete
$locations[] = [
[859] Fix | Delete
'type' => self::WIDGET,
[860] Fix | Delete
'title' => $widget['title'],
[861] Fix | Delete
'form_id' => $form_id,
[862] Fix | Delete
'id' => self::TEXT_WIDGET_PREFIX . $id,
[863] Fix | Delete
];
[864] Fix | Delete
}
[865] Fix | Delete
}
[866] Fix | Delete
[867] Fix | Delete
return $locations;
[868] Fix | Delete
}
[869] Fix | Delete
[870] Fix | Delete
/**
[871] Fix | Delete
* Search forms in block widgets.
[872] Fix | Delete
*
[873] Fix | Delete
* @since 1.7.4
[874] Fix | Delete
*
[875] Fix | Delete
* @param array $widgets Widgets.
[876] Fix | Delete
*
[877] Fix | Delete
* @return array
[878] Fix | Delete
*/
[879] Fix | Delete
private function search_in_block_widgets( $widgets = null ) {
[880] Fix | Delete
[881] Fix | Delete
$widgets = $this->prepare_widgets( $widgets, 'block' );
[882] Fix | Delete
[883] Fix | Delete
$locations = [];
[884] Fix | Delete
[885] Fix | Delete
foreach ( $widgets as $id => $widget ) {
[886] Fix | Delete
$form_ids = $this->get_form_ids( $widget['content'] );
[887] Fix | Delete
[888] Fix | Delete
foreach ( $form_ids as $form_id ) {
[889] Fix | Delete
$locations[] = [
[890] Fix | Delete
'type' => self::WIDGET,
[891] Fix | Delete
'title' => $this->block_widget_title,
[892] Fix | Delete
'form_id' => $form_id,
[893] Fix | Delete
'id' => self::BLOCK_WIDGET_PREFIX . $id,
[894] Fix | Delete
];
[895] Fix | Delete
}
[896] Fix | Delete
}
[897] Fix | Delete
[898] Fix | Delete
return $locations;
[899] Fix | Delete
}
[900] Fix | Delete
[901] Fix | Delete
/**
[902] Fix | Delete
* Search forms in widgets.
[903] Fix | Delete
*
[904] Fix | Delete
* @since 1.7.4
[905] Fix | Delete
*
[906] Fix | Delete
* @return array
[907] Fix | Delete
*/
[908] Fix | Delete
public function search_in_widgets() {
[909] Fix | Delete
[910] Fix | Delete
return array_merge(
[911] Fix | Delete
$this->search_in_wpforms_widgets(),
[912] Fix | Delete
$this->search_in_text_widgets(),
[913] Fix | Delete
$this->search_in_block_widgets()
[914] Fix | Delete
);
[915] Fix | Delete
}
[916] Fix | Delete
[917] Fix | Delete
/**
[918] Fix | Delete
* Get the difference of two arrays containing locations.
[919] Fix | Delete
*
[920] Fix | Delete
* @since 1.7.4
[921] Fix | Delete
*
[922] Fix | Delete
* @param array $locations1 Locations to subtract from.
[923] Fix | Delete
* @param array $locations2 Locations to subtract.
[924] Fix | Delete
*
[925] Fix | Delete
* @return array
[926] Fix | Delete
*/
[927] Fix | Delete
private function array_udiff( $locations1, $locations2 ) {
[928] Fix | Delete
[929] Fix | Delete
return array_udiff(
[930] Fix | Delete
$locations1,
[931] Fix | Delete
$locations2,
[932] Fix | Delete
static function ( $a, $b ) {
[933] Fix | Delete
[934] Fix | Delete
return ( $a === $b ) ? 0 : - 1;
[935] Fix | Delete
}
[936] Fix | Delete
);
[937] Fix | Delete
}
[938] Fix | Delete
[939] Fix | Delete
/**
[940] Fix | Delete
* Remove locations from metas.
[941] Fix | Delete
*
[942] Fix | Delete
* @since 1.7.4
[943] Fix | Delete
*
[944] Fix | Delete
* @param array $locations_to_remove Locations to remove.
[945] Fix | Delete
*
[946] Fix | Delete
* @return void
[947] Fix | Delete
*/
[948] Fix | Delete
private function remove_locations( $locations_to_remove ) {
[949] Fix | Delete
[950] Fix | Delete
foreach ( $locations_to_remove as $location_to_remove ) {
[951] Fix | Delete
$locations = get_post_meta( $location_to_remove['form_id'], self::LOCATIONS_META, true );
[952] Fix | Delete
[953] Fix | Delete
if ( ! $locations ) {
[954] Fix | Delete
continue;
[955] Fix | Delete
}
[956] Fix | Delete
[957] Fix | Delete
foreach ( $locations as $key => $location ) {
[958] Fix | Delete
if ( $location['id'] === $location_to_remove['id'] ) {
[959] Fix | Delete
unset( $locations[ $key ] );
[960] Fix | Delete
}
[961] Fix | Delete
}
[962] Fix | Delete
[963] Fix | Delete
update_post_meta( $location_to_remove['form_id'], self::LOCATIONS_META, $locations );
[964] Fix | Delete
}
[965] Fix | Delete
}
[966] Fix | Delete
[967] Fix | Delete
/**
[968] Fix | Delete
* Add locations to metas.
[969] Fix | Delete
*
[970] Fix | Delete
* @since 1.7.4
[971] Fix | Delete
*
[972] Fix | Delete
* @param array $locations_to_add Locations to add.
[973] Fix | Delete
*
[974] Fix | Delete
* @return void
[975] Fix | Delete
*/
[976] Fix | Delete
private function add_locations( $locations_to_add ) {
[977] Fix | Delete
[978] Fix | Delete
foreach ( $locations_to_add as $location_to_add ) {
[979] Fix | Delete
$locations = get_post_meta( $location_to_add['form_id'], self::LOCATIONS_META, true );
[980] Fix | Delete
[981] Fix | Delete
if ( ! $locations ) {
[982] Fix | Delete
$locations = [];
[983] Fix | Delete
}
[984] Fix | Delete
[985] Fix | Delete
$locations[] = $location_to_add;
[986] Fix | Delete
[987] Fix | Delete
update_post_meta( $location_to_add['form_id'], self::LOCATIONS_META, $locations );
[988] Fix | Delete
}
[989] Fix | Delete
}
[990] Fix | Delete
[991] Fix | Delete
/**
[992] Fix | Delete
* Update form locations on widget update.
[993] Fix | Delete
*
[994] Fix | Delete
* @since 1.7.4
[995] Fix | Delete
*
[996] Fix | Delete
* @param mixed $old_value The old option value.
[997] Fix | Delete
* @param mixed $value The new option value.
[998] Fix | Delete
* @param string $option Option name.
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function